Shortcuts

Struct CUDAGuard

Page Contents

Struct Documentation

struct c10::cuda::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

CUDAGuard() = delete

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

CUDAGuard(DeviceIndex device_index)

Set the current CUDA device to the passed device index.

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
void set_device(Device device)

Sets the CUDA device to the given device.

Errors if the given device is not a CUDA device.

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).

void set_index(DeviceIndex device_index)

Sets the CUDA device to the given device index.

Device original_device() const

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

Device current_device() const

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

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources