DeviceGuard#

Fully qualified name: isaacsim::common::array::DeviceGuard

class DeviceGuard#

RAII guard that temporarily sets the active CUDA device and restores it on destruction.

On construction, sets the current CUDA device to the specified ordinal. On destruction, restores the device that was active before the guard was created.

DeviceGuard is non-copyable and non-movable to prevent accidental reuse or duplication of the saved device state.

Note

Has no effect when the target device is the CPU (ordinal -1).

Public Functions

explicit DeviceGuard(const Device &device)#

Sets the active CUDA device to the device represented by device.

Parameters:

device – [in] The Device to activate.

explicit DeviceGuard(int32_t ordinal)#

Sets the active CUDA device to the given ordinal.

Parameters:

ordinal – [in] Non-negative CUDA device index, or -1 to target the CPU (no-op).

~DeviceGuard()#

Restores the previously active CUDA device.

DeviceGuard(const DeviceGuard&) = delete#
DeviceGuard &operator=(const DeviceGuard&) = delete#
DeviceGuard(DeviceGuard&&) = delete#
DeviceGuard &operator=(DeviceGuard&&) = delete#