CUDA Device Management

group cuda_device_management

Functions

inline cuda_device_id get_current_cuda_device()

Returns a cuda_device_id for the current device.

The current device is the device on which the calling thread executes device code.

Returns:

cuda_device_id for the current device

inline int get_num_cuda_devices()

Returns the number of CUDA devices in the system.

Returns:

Number of CUDA devices in the system

struct cuda_device_id
#include <cuda_device.hpp>

Strong type for a CUDA device identifier.

Public Types

using value_type = int

Integer type used for device identifier.

Public Functions

inline explicit constexpr cuda_device_id(value_type dev_id) noexcept

Construct a cuda_device_id from the specified integer value.

Parameters:

dev_id – The device’s integer identifier

inline constexpr value_type value() const noexcept

The wrapped integer value.

Returns:

The wrapped integer value

struct cuda_set_device_raii
#include <cuda_device.hpp>

RAII class that sets the current CUDA device to the specified device on construction and restores the previous device on destruction.

Public Functions

inline explicit cuda_set_device_raii(cuda_device_id dev_id)

Construct a new cuda_set_device_raii object and sets the current CUDA device to dev_id

Parameters:

dev_id – The device to set as the current CUDA device

inline ~cuda_set_device_raii() noexcept

Reactivates the previous CUDA device.