CUDA Device Management#
2026-10-26
1 min read time
- cuda_device_id get_current_cuda_device(
Returns a
cuda_device_idfor the current device.The current device is the device on which the calling thread executes device code.
- Returns:
cuda_device_idfor the current device
- int get_num_cuda_devices(
Returns the number of CUDA devices in the system.
- Returns:
Number of CUDA devices in the system
- std::pair<std::size_t, std::size_t> available_device_memory(
Returns the available and total device memory in bytes for the current device.
- Returns:
The available and total device memory in bytes for the current device as a std::pair.
- std::size_t percent_of_free_device_memory(
- int percent
Returns the approximate specified percent of available device memory on the current CUDA device, aligned (down) to the nearest CUDA allocation size.
- Parameters:
percent – The percent of free memory to return.
- Returns:
The recommended initial device memory pool size in bytes.
-
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 cuda_device_id(
Construct a
cuda_device_idfrom the current device.
- inline explicit constexpr cuda_device_id(
- value_type dev_id
Construct a
cuda_device_idfrom the specified integer value.- Parameters:
dev_id – The device’s integer identifier
- inline value_type value(
@briefreturn{The wrapped integer value}
-
using value_type = int#
-
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
- 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
- ~cuda_set_device_raii(
Reactivates the previous CUDA device.