Skip to content

Commit

Permalink
Add docs; Update function to return error instead of throwing; Format…
Browse files Browse the repository at this point in the history
…ting;
  • Loading branch information
jeremyfelder committed Dec 30, 2024
1 parent e61b6c6 commit b6246a0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
15 changes: 15 additions & 0 deletions docs/docs/icicle/programmers_guide/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ eIcicleError result = icicle_set_device(device);
eIcicleError result = icicle_get_active_device(device);
```
### Setting and Getting the Default Device
You can set the default device for all threads:
```cpp
icicle::Device device = {"CUDA", 0}; // or other
eIcicleError result = icicle_set_default_device(device);
```

:::caution

Setting a default device should be done **once** from the main thread of the application. If another device or backend is needed for a specific thread [icicle_set_device](#setting-and-getting-active-device) should be used instead.

:::

### Querying Device Information

Retrieve the number of available devices and check if a pointer is allocated on the host or on the active device:
Expand Down
1 change: 1 addition & 0 deletions docs/docs/icicle/programmers_guide/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ICICLE provides a device abstraction layer that allows you to interact with diff

- **Loading Backends**: Backends are loaded dynamically based on the environment configuration or a specified path.
- **Setting Active Device**: The active device for a thread can be set, allowing for targeted computation on a specific device.
- **Setting Default Device**: The default device for any thread without an active device can be set, removing the need to specify an alternative device on each thread. This is especially useful when running on a backend that is not the built-in CPU backend which is the default device to start.

## Streams

Expand Down
17 changes: 16 additions & 1 deletion docs/docs/icicle/programmers_guide/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ result := runtime.LoadBackend("/path/to/backend/installdir", true)
You can set the active device for the current thread and retrieve it when needed:

```go
device = runtime.CreateDevice("CUDA", 0) // or other
device := runtime.CreateDevice("CUDA", 0) // or other
result := runtime.SetDevice(device)
// or query current (thread) device
activeDevice := runtime.GetActiveDevice()
```

### Setting and Getting the Default Device

You can set the default device for all threads:

```go
device := runtime.CreateDevice("CUDA", 0) // or other
defaultDevice := runtime.SetDefaultDevice(device);
```

:::caution

Setting a default device should be done **once** from the main thread of the application. If another device or backend is needed for a specific thread [runtime.SetDevice](#setting-and-getting-active-device) should be used instead.

:::

### Querying Device Information

Retrieve the number of available devices and check if a pointer is allocated on the host or on the active device:
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/icicle/programmers_guide/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ icicle_runtime::set_device(&device).unwrap();
let active_device = icicle_runtime::get_active_device().unwrap();
```
### Setting and Getting the Default Device
You can set the default device for all threads:
```caution
let device = Device::new("CUDA", 0); // or other
let default_device = icicle_runtime::set_default_device(device);
```
:::note
Setting a default device should be done **once** from the main thread of the application. If another device or backend is needed for a specific thread [icicle_runtime::set_device](#setting-and-getting-active-device) should be used instead.
:::
### Querying Device Information
Retrieve the number of available devices and check if a pointer is allocated on the host or on the active device:
Expand Down
4 changes: 2 additions & 2 deletions examples/c++/best-practice-ntt/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ int main(int argc, char* argv[])
// Clean-up
for (int i = 0; i < 2; i++) {
ICICLE_CHECK(icicle_free(d_vec[i]));
delete[](h_inp[i]);
delete[](h_out[i]);
delete[] (h_inp[i]);
delete[] (h_out[i]);
}
ICICLE_CHECK(icicle_destroy_stream(stream_compute));
ICICLE_CHECK(icicle_destroy_stream(stream_d2h));
Expand Down
5 changes: 3 additions & 2 deletions icicle/src/device_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ namespace icicle {
eIcicleError set_default_device(const Device& dev)
{
if (!is_device_registered(dev.type)) {
THROW_ICICLE_ERR(
eIcicleError::INVALID_DEVICE, "Device type " + std::string(dev.type) + " has not been registered");
ICICLE_LOG_ERROR << "Device type " + std::string(dev.type) + " is not valid as it has not been registered";
return eIcicleError::INVALID_DEVICE;
}

m_default_device = dev;
return eIcicleError::SUCCESS;
}
Expand Down

0 comments on commit b6246a0

Please sign in to comment.