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

A StreamGuard is an RAII class that changes the current device to the device corresponding to some stream, and changes the default stream on that device to be this stream. More...

#include <InlineStreamGuard.h>

Inheritance diagram for c10::impl::InlineStreamGuard< T >:
c10::impl::InlineDeviceGuard< T >

Public Member Functions

 InlineStreamGuard ()=delete
 No default constructor, see Note [Omitted default constructor from RAII].
 
 InlineStreamGuard (Stream stream)
 Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream. More...
 
template<typename U = T, typename = typename std::enable_if<std::is_same<U, VirtualGuardImpl>::value>::type>
 InlineStreamGuard (Stream stream, const DeviceGuardImplInterface *impl)
 This constructor exists purely for testing.
 
 InlineStreamGuard (const InlineStreamGuard< T > &)=delete
 Copy is disallowed.
 
InlineStreamGuard< T > & operator= (const InlineStreamGuard< T > &)=delete
 
 InlineStreamGuard (InlineStreamGuard< T > &&other)=delete
 Move is disallowed, as StreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors. More...
 
InlineStreamGuardoperator= (InlineStreamGuard< T > &&other)=delete
 
void reset_stream (Stream stream)
 Resets the currently set stream to the original stream and the currently set device to the original device. More...
 
Stream original_stream () const
 Returns the stream of the original device prior to this guard. More...
 
Stream current_stream () const
 Returns the most recent stream that was set using this device guard, either from construction, or via set_stream. More...
 
Device current_device () const
 Returns the most recent device that was set using this device guard, either from construction, or via set_device/reset_device/set_index. More...
 
Device original_device () const
 Returns the device that was set at the most recent reset_stream(), or otherwise the device at construction time. More...
 

Detailed Description

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

A StreamGuard is an RAII class that changes the current device to the device corresponding to some stream, and changes the default stream on that device to be this stream.

InlineStreamGuard is a helper class for implementing StreamGuards. See InlineDeviceGuard for guidance on how to use this class.

Definition at line 17 of file InlineStreamGuard.h.

Constructor & Destructor Documentation

template<typename T>
c10::impl::InlineStreamGuard< T >::InlineStreamGuard ( Stream  stream)
inlineexplicit

Set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream.

Definition at line 24 of file InlineStreamGuard.h.

template<typename T>
c10::impl::InlineStreamGuard< T >::InlineStreamGuard ( InlineStreamGuard< T > &&  other)
delete

Move is disallowed, as StreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors.

Member Function Documentation

template<typename T>
Device c10::impl::InlineStreamGuard< T >::current_device ( ) const
inline

Returns the most recent device that was set using this device guard, either from construction, or via set_device/reset_device/set_index.

Definition at line 102 of file InlineStreamGuard.h.

template<typename T>
Stream c10::impl::InlineStreamGuard< T >::current_stream ( ) const
inline

Returns the most recent stream that was set using this device guard, either from construction, or via set_stream.

Definition at line 96 of file InlineStreamGuard.h.

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

Returns the device that was set at the most recent reset_stream(), or otherwise the device at construction time.

Definition at line 108 of file InlineStreamGuard.h.

template<typename T>
Stream c10::impl::InlineStreamGuard< T >::original_stream ( ) const
inline

Returns the stream of the original device prior to this guard.

Subtly, the stream returned here is the original stream of the original device; i.e., it's the stream that your computation would have been put on, if it hadn't been for this meddling stream guard. This is usually what you want.

Definition at line 90 of file InlineStreamGuard.h.

template<typename T>
void c10::impl::InlineStreamGuard< T >::reset_stream ( Stream  stream)
inline

Resets the currently set stream to the original stream and the currently set device to the original device.

Then, set the current device to the device associated with the passed stream, and set the current stream on that device to the passed stream.

NOTE: this implementation may skip some stream/device setting if it can prove that it is unnecessary.

WARNING: reset_stream does NOT preserve previously set streams on different devices. If you need to set streams on multiple devices on CUDA, use CUDAMultiStreamGuard instead.

Definition at line 64 of file InlineStreamGuard.h.


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