Ginkgo
Generated from pipelines/1556235455 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
|
This move-only class uses RAII to set the device id within a scoped block, if necessary. More...
#include <ginkgo/core/base/scoped_device_id_guard.hpp>
Public Member Functions | |
scoped_device_id_guard (const ReferenceExecutor *exec, int device_id) | |
Create a scoped device id from an Reference. More... | |
scoped_device_id_guard (const OmpExecutor *exec, int device_id) | |
Create a scoped device id from an OmpExecutor. More... | |
scoped_device_id_guard (const CudaExecutor *exec, int device_id) | |
Create a scoped device id from an CudaExecutor. More... | |
scoped_device_id_guard (const HipExecutor *exec, int device_id) | |
Create a scoped device id from an HipExecutor. More... | |
scoped_device_id_guard (const DpcppExecutor *exec, int device_id) | |
Create a scoped device id from an DpcppExecutor. More... | |
scoped_device_id_guard (const scoped_device_id_guard &)=delete | |
scoped_device_id_guard (scoped_device_id_guard &&)=default | |
scoped_device_id_guard & | operator= (const scoped_device_id_guard &)=delete |
scoped_device_id_guard & | operator= (scoped_device_id_guard &&)=default |
This move-only class uses RAII to set the device id within a scoped block, if necessary.
The class behaves similar to std::scoped_lock. The scoped guard will make sure that the device code is run on the correct device within one scoped block, when run with multiple devices. Depending on the executor it will record the current device id and set the device id to the one being passed in. After the scope has been exited, the destructor sets the device_id back to the one before entering the scope. The OmpExecutor and DpcppExecutor don't require setting an device id, so in those cases, the class is a no-op.
The device id scope has to be constructed from a executor with concrete type (not plain Executor) and a device id. Only the type of the executor object is relevant, so the pointer will not be accessed, and may even be a nullptr. From the executor type the correct derived class of detail::generic_scoped_device_id_guard is picked. The following illustrates the usage of this class:
gko::scoped_device_id_guard::scoped_device_id_guard | ( | const ReferenceExecutor * | exec, |
int | device_id | ||
) |
Create a scoped device id from an Reference.
The resulting object will be a noop.
exec | Not used. |
device_id | Not used. |
gko::scoped_device_id_guard::scoped_device_id_guard | ( | const OmpExecutor * | exec, |
int | device_id | ||
) |
Create a scoped device id from an OmpExecutor.
The resulting object will be a noop.
exec | Not used. |
device_id | Not used. |
gko::scoped_device_id_guard::scoped_device_id_guard | ( | const CudaExecutor * | exec, |
int | device_id | ||
) |
Create a scoped device id from an CudaExecutor.
The resulting object will set the cuda device id accordingly.
exec | Not used. |
device_id | The device id to use within the scope. |
gko::scoped_device_id_guard::scoped_device_id_guard | ( | const HipExecutor * | exec, |
int | device_id | ||
) |
Create a scoped device id from an HipExecutor.
The resulting object will set the hip device id accordingly.
exec | Not used. |
device_id | The device id to use within the scope. |
gko::scoped_device_id_guard::scoped_device_id_guard | ( | const DpcppExecutor * | exec, |
int | device_id | ||
) |
Create a scoped device id from an DpcppExecutor.
The resulting object will be a noop.
exec | Not used. |
device_id | Not used. |