Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
c10::cuda::CUDAGuard Struct Reference

A variant of DeviceGuard that is specialized for CUDA. More...

#include <CUDAGuard.h>

Public Member 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. More...
 
 CUDAGuard (const CUDAGuard &)=delete
 
CUDAGuardoperator= (const CUDAGuard &)=delete
 
 CUDAGuard (CUDAGuard &&other)=delete
 
CUDAGuardoperator= (CUDAGuard &&other)=delete
 
void set_device (Device device)
 Sets the CUDA device to the given device. More...
 
void reset_device (Device device)
 Sets the CUDA device to the given device. More...
 
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. More...
 

Detailed Description

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.

Definition at line 20 of file CUDAGuard.h.

Constructor & Destructor Documentation

c10::cuda::CUDAGuard::CUDAGuard ( Device  device)
inlineexplicit

Sets the current CUDA device to the passed device.

Errors if the passed device is not a CUDA device.

Definition at line 29 of file CUDAGuard.h.

Member Function Documentation

Device c10::cuda::CUDAGuard::current_device ( ) const
inline

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

Definition at line 56 of file CUDAGuard.h.

void c10::cuda::CUDAGuard::reset_device ( Device  device)
inline

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

Definition at line 46 of file CUDAGuard.h.

void c10::cuda::CUDAGuard::set_device ( Device  device)
inline

Sets the CUDA device to the given device.

Errors if the given device is not a CUDA device.

Definition at line 41 of file CUDAGuard.h.


The documentation for this struct was generated from the following file: