Ginkgo: gko::scoped_device_id_guard Class Reference

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
gko::scoped_device_id_guard Class Reference

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.
| scoped_device_id_guard (const OmpExecutor *exec, int device_id)
| Create a scoped device id from an OmpExecutor.
| scoped_device_id_guard (const CudaExecutor *exec, int device_id)
| Create a scoped device id from an CudaExecutor.
| scoped_device_id_guard (const HipExecutor *exec, int device_id)
| Create a scoped device id from an HipExecutor.
| scoped_device_id_guard (const DpcppExecutor *exec, int device_id)
| Create a scoped device id from an DpcppExecutor.
| 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

## Detailed Description

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:

{
scoped_device_id_guard g{static_cast<CudaExecutor>(nullptr), 1};
// now the device id is set to 1
}
// now the device id is reverted again
gko::CudaExecutor
This is the Executor subclass which represents the CUDA device.
Definition executor.hpp:1542
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const ReferenceExecutor *exec, int device_id)
Create a scoped device id from an Reference.

## Constructor & Destructor Documentation

## ◆ scoped_device_id_guard() [1/5]

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.

Parameters

  exec | Not used.
  device_id | Not used.

Referenced by scoped_device_id_guard().

## ◆ scoped_device_id_guard() [2/5]

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.

Parameters

  exec | Not used.
  device_id | Not used.

## ◆ scoped_device_id_guard() [3/5]

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.

Parameters

  exec | Not used.
  device_id | The device id to use within the scope.

## ◆ scoped_device_id_guard() [4/5]

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.

Parameters

  exec | Not used.
  device_id | The device id to use within the scope.

## ◆ scoped_device_id_guard() [5/5]

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.

Parameters

  exec | Not used.
  device_id | Not used.

References scoped_device_id_guard().

The documentation for this class was generated from the following file:

- ginkgo/core/base/scoped_device_id_guard.hpp