PyTorch
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | List of all members
c10::cuda::OptionalCUDAGuard Struct Reference

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

#include <CUDAGuard.h>

Public Member Functions

 OptionalCUDAGuard ()
 Create an uninitialized OptionalCUDAGuard. More...
 
 OptionalCUDAGuard (optional< Device > device_opt)
 Set the current CUDA device to the passed Device, if it is not nullopt. More...
 
 OptionalCUDAGuard (optional< DeviceIndex > device_index_opt)
 Set the current CUDA device to the passed device index, if it is not nullopt. More...
 
 OptionalCUDAGuard (const OptionalCUDAGuard &)=delete
 
OptionalCUDAGuardoperator= (const OptionalCUDAGuard &)=delete
 
 OptionalCUDAGuard (OptionalCUDAGuard &&other)=delete
 
OptionalCUDAGuardoperator= (OptionalCUDAGuard &&other)=delete
 
void set_device (Device device)
 Sets the CUDA device to the given device, initializing the guard if it is not already initialized. More...
 
void reset_device (Device device)
 Sets the CUDA device to the given device, initializing the guard if it is not already initialized. More...
 
void set_index (DeviceIndex device_index)
 Sets the CUDA device to the given device index, initializing the guard if it is not already initialized. More...
 
optional< Deviceoriginal_device () const
 Returns the device that was set immediately prior to initialization of the guard, or nullopt if the guard is uninitialized. More...
 
optional< Devicecurrent_device () const
 Returns the most recent device that was set using this device guard, either from construction, or via set_device, if the guard is initialized, or nullopt if the guard is uninitialized. More...
 
void reset ()
 Restore the original CUDA device, resetting this guard to uninitialized state. More...
 

Detailed Description

A variant of OptionalDeviceGuard that is specialized for CUDA.

See CUDAGuard for when you can use this.

Constructor & Destructor Documentation

◆ OptionalCUDAGuard() [1/5]

c10::cuda::OptionalCUDAGuard::OptionalCUDAGuard ( )
inlineexplicit

Create an uninitialized OptionalCUDAGuard.

◆ OptionalCUDAGuard() [2/5]

c10::cuda::OptionalCUDAGuard::OptionalCUDAGuard ( optional< Device device_opt)
inlineexplicit

Set the current CUDA device to the passed Device, if it is not nullopt.

◆ OptionalCUDAGuard() [3/5]

c10::cuda::OptionalCUDAGuard::OptionalCUDAGuard ( optional< DeviceIndex device_index_opt)
inlineexplicit

Set the current CUDA device to the passed device index, if it is not nullopt.

◆ OptionalCUDAGuard() [4/5]

c10::cuda::OptionalCUDAGuard::OptionalCUDAGuard ( const OptionalCUDAGuard )
delete

◆ OptionalCUDAGuard() [5/5]

c10::cuda::OptionalCUDAGuard::OptionalCUDAGuard ( OptionalCUDAGuard &&  other)
delete

Member Function Documentation

◆ current_device()

optional< Device > c10::cuda::OptionalCUDAGuard::current_device ( ) const
inline

Returns the most recent device that was set using this device guard, either from construction, or via set_device, if the guard is initialized, or nullopt if the guard is uninitialized.

◆ operator=() [1/2]

OptionalCUDAGuard & c10::cuda::OptionalCUDAGuard::operator= ( const OptionalCUDAGuard )
delete

◆ operator=() [2/2]

OptionalCUDAGuard & c10::cuda::OptionalCUDAGuard::operator= ( OptionalCUDAGuard &&  other)
delete

◆ original_device()

optional< Device > c10::cuda::OptionalCUDAGuard::original_device ( ) const
inline

Returns the device that was set immediately prior to initialization of the guard, or nullopt if the guard is uninitialized.

◆ reset()

void c10::cuda::OptionalCUDAGuard::reset ( )
inline

Restore the original CUDA device, resetting this guard to uninitialized state.

◆ reset_device()

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

Sets the CUDA device to the given device, initializing the guard if it is not already initialized.

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

◆ set_device()

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

Sets the CUDA device to the given device, initializing the guard if it is not already initialized.

Errors if the given device is not a CUDA device.

◆ set_index()

void c10::cuda::OptionalCUDAGuard::set_index ( DeviceIndex  device_index)
inline

Sets the CUDA device to the given device index, initializing the guard if it is not already initialized.


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