Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
c10::impl::InlineOptionalDeviceGuard< T > Class Template Reference

A OptionalDeviceGuard is an RAII class that sets a device to some value on initialization, and resets the device to its original value on destruction. More...

#include <InlineDeviceGuard.h>

Public Member Functions

 InlineOptionalDeviceGuard ()
 Creates an uninitialized OptionalDeviceGuard.
 
 InlineOptionalDeviceGuard (optional< Device > device_opt)
 Set the current device to the passed Device, if it is not nullopt.
 
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value>::type>
 InlineOptionalDeviceGuard (optional< DeviceIndex > device_index_opt)
 Set the current device to the passed DeviceIndex, if it is not nullopt.
 
template<typename... Args>
 InlineOptionalDeviceGuard (Args &&...args)
 All constructors of DeviceGuard are valid for OptionalDeviceGuard and result in initialized OptionalDeviceGuard. More...
 
 InlineOptionalDeviceGuard (InlineOptionalDeviceGuard< T > &&other)=delete
 
InlineOptionalDeviceGuardoperator= (InlineOptionalDeviceGuard &&other)=delete
 
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value>::type>
void set_device (at::Device device)
 Sets the device to the given one. More...
 
template<typename U = T, typename = typename std::enable_if<std::is_same<U, VirtualGuardImpl>::value>::type>
void reset_device (at::Device device, const DeviceGuardImplInterface *impl=nullptr)
 Resets the currently set device to its original device, and then sets the current device to the passed device (for a possibly different device type). More...
 
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value>::type>
void reset_device (at::Device device)
 Resets the currently set device to its original device, and then sets the current device to the passed device. More...
 
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value >::type>
void set_index (DeviceIndex index)
 Sets the device index to the given one. 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 device, resetting this guard to uninitialized state.
 

Detailed Description

template<typename T>
class c10::impl::InlineOptionalDeviceGuard< T >

A OptionalDeviceGuard is an RAII class that sets a device to some value on initialization, and resets the device to its original value on destruction.

InlineOptionalDeviceGuard is a helper class for implementing OptionalDeviceGuards. See guidance in InlineDeviceGuard on how to use this. See OptionalDeviceGuard for user-oriented usage notes.

Definition at line 195 of file InlineDeviceGuard.h.

Constructor & Destructor Documentation

template<typename T>
template<typename... Args>
c10::impl::InlineOptionalDeviceGuard< T >::InlineOptionalDeviceGuard ( Args &&...  args)
inlineexplicit

All constructors of DeviceGuard are valid for OptionalDeviceGuard and result in initialized OptionalDeviceGuard.

Definition at line 227 of file InlineDeviceGuard.h.

Member Function Documentation

template<typename T>
optional<Device> c10::impl::InlineOptionalDeviceGuard< T >::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.

Definition at line 378 of file InlineDeviceGuard.h.

template<typename T>
optional<Device> c10::impl::InlineOptionalDeviceGuard< T >::original_device ( ) const
inline

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

Definition at line 371 of file InlineDeviceGuard.h.

template<typename T>
template<typename U = T, typename = typename std::enable_if<std::is_same<U, VirtualGuardImpl>::value>::type>
void c10::impl::InlineOptionalDeviceGuard< T >::reset_device ( at::Device  device,
const DeviceGuardImplInterface impl = nullptr 
)
inline

Resets the currently set device to its original device, and then sets the current device to the passed device (for a possibly different device type).

Initializes OptionalDeviceGuard if it is not already initialized.

See notes on why this is called reset_device on InlineDeviceGuard.

Optional argument is for testing only.

Definition at line 337 of file InlineDeviceGuard.h.

template<typename T>
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value>::type>
void c10::impl::InlineOptionalDeviceGuard< T >::reset_device ( at::Device  device)
inline

Resets the currently set device to its original device, and then sets the current device to the passed device.

Initializes the guard if it is not already initialized. This is effectively equivalent to set_device when a guard supports only a single device type.

Definition at line 350 of file InlineDeviceGuard.h.

template<typename T>
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value>::type>
void c10::impl::InlineOptionalDeviceGuard< T >::set_device ( at::Device  device)
inline

Sets the device to the given one.

Initializes OptionalDeviceGuard if it is not already initialized.

Definition at line 321 of file InlineDeviceGuard.h.

template<typename T>
template<typename U = T, typename = typename std::enable_if<!std::is_same<U, VirtualGuardImpl>::value >::type>
void c10::impl::InlineOptionalDeviceGuard< T >::set_index ( DeviceIndex  index)
inline

Sets the device index to the given one.

The device type is statically known.

Definition at line 361 of file InlineDeviceGuard.h.


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