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 | |
InlineOptionalDeviceGuard & | operator= (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< Device > | original_device () const |
Returns the device that was set immediately prior to initialization of the, guard, or nullopt if the guard is uninitialized. More... | |
optional< Device > | current_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. | |
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.
|
inlineexplicit |
All constructors of DeviceGuard are valid for OptionalDeviceGuard and result in initialized OptionalDeviceGuard.
Definition at line 227 of file InlineDeviceGuard.h.
|
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.
|
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.
|
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.
|
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.
|
inline |
Sets the device to the given one.
Initializes OptionalDeviceGuard if it is not already initialized.
Definition at line 321 of file InlineDeviceGuard.h.
|
inline |
Sets the device index to the given one.
The device type is statically known.
Definition at line 361 of file InlineDeviceGuard.h.