Rate this Page

Struct CUDAGuard#

Page Contents

Struct Documentation#

struct CUDAGuard#

A variant of DeviceGuard that is specialized for CUDA.

It accepts integer indices (interpreting them as CUDA devices) and is a little more efficient than DeviceGuard (it compiles to straight line cudaSetDevice/cudaGetDevice calls); however, it can only be used from code that links against CUDA directly.

Public Functions

explicit CUDAGuard() = delete#

No default constructor; see Note [Omitted default constructor from RAII].

inline explicit CUDAGuard(DeviceIndex device_index)#

Set the current CUDA device to the passed device index.

inline explicit CUDAGuard(Device device)#

Sets the current CUDA device to the passed device.

Errors if the passed device is not a CUDA device.

CUDAGuard(const CUDAGuard&) = delete#
CUDAGuard &operator=(const CUDAGuard&) = delete#
CUDAGuard(CUDAGuard &&other) = delete#
CUDAGuard &operator=(CUDAGuard &&other) = delete#
~CUDAGuard() = default#
inline void set_device(Device device)#

Sets the CUDA device to the given device.

Errors if the given device is not a CUDA device.

inline void reset_device(Device device)#

Sets the CUDA device to the given device.

Errors if the given device is not a CUDA device. (This method is provided for uniformity with DeviceGuard).

inline void set_index(DeviceIndex device_index)#

Sets the CUDA device to the given device index.

inline Device original_device() const#

Returns the device that was set upon construction of the guard.

inline Device current_device() const#

Returns the last device that was set via set_device, if any, otherwise the device passed during construction.