From b6246a0b4f0ee81aff187b9cb8b98aa6a3278a0a Mon Sep 17 00:00:00 2001 From: Jeremy Felder Date: Mon, 30 Dec 2024 15:32:58 +0200 Subject: [PATCH] Add docs; Update function to return error instead of throwing; Formatting; --- docs/docs/icicle/programmers_guide/cpp.md | 15 +++++++++++++++ docs/docs/icicle/programmers_guide/general.md | 1 + docs/docs/icicle/programmers_guide/go.md | 17 ++++++++++++++++- docs/docs/icicle/programmers_guide/rust.md | 15 +++++++++++++++ examples/c++/best-practice-ntt/example.cpp | 4 ++-- icicle/src/device_api.cpp | 5 +++-- 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/docs/docs/icicle/programmers_guide/cpp.md b/docs/docs/icicle/programmers_guide/cpp.md index b8f1f285f..cff576571 100644 --- a/docs/docs/icicle/programmers_guide/cpp.md +++ b/docs/docs/icicle/programmers_guide/cpp.md @@ -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: diff --git a/docs/docs/icicle/programmers_guide/general.md b/docs/docs/icicle/programmers_guide/general.md index 0bef2b850..0405cf35c 100644 --- a/docs/docs/icicle/programmers_guide/general.md +++ b/docs/docs/icicle/programmers_guide/general.md @@ -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 diff --git a/docs/docs/icicle/programmers_guide/go.md b/docs/docs/icicle/programmers_guide/go.md index 92df226f9..03f7932c1 100644 --- a/docs/docs/icicle/programmers_guide/go.md +++ b/docs/docs/icicle/programmers_guide/go.md @@ -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: diff --git a/docs/docs/icicle/programmers_guide/rust.md b/docs/docs/icicle/programmers_guide/rust.md index af5caa5a8..55188cfe2 100644 --- a/docs/docs/icicle/programmers_guide/rust.md +++ b/docs/docs/icicle/programmers_guide/rust.md @@ -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: diff --git a/examples/c++/best-practice-ntt/example.cpp b/examples/c++/best-practice-ntt/example.cpp index 7db88aa35..7f4bc974d 100644 --- a/examples/c++/best-practice-ntt/example.cpp +++ b/examples/c++/best-practice-ntt/example.cpp @@ -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)); diff --git a/icicle/src/device_api.cpp b/icicle/src/device_api.cpp index 534758943..25ecc9c96 100644 --- a/icicle/src/device_api.cpp +++ b/icicle/src/device_api.cpp @@ -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; }