Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions
c10::StreamGuard Struct 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 <StreamGuard.h>

Public Member Functions

 StreamGuard ()=delete
 No default constructor, see Note [Omitted default constructor from RAII].
 
 StreamGuard (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...
 
 StreamGuard (const StreamGuard &)=delete
 Copy is disallowed.
 
StreamGuardoperator= (const StreamGuard &)=delete
 
 StreamGuard (StreamGuard &&other)=delete
 Move is disallowed, as StreamGuard does not have an uninitialized state, which is required for moves on types with nontrivial destructors. More...
 
StreamGuardoperator= (StreamGuard &&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 that was set at the time the guard was constructed.
 
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

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.

Use of StreamGuard is HIGHLY discouraged in operator definitions. In a single operator, you probably don't know enough about the global state of the world to profitably decide how to set streams. Let the caller handle this appropriately, and just use the current stream in your operator code.

This StreamGuard does NOT have an uninitialized state; it is guaranteed to reset the stream and device on exit. If you are in a situation where you might want to setup a stream guard, see OptionalStreamGuard.

Definition at line 22 of file StreamGuard.h.

Constructor & Destructor Documentation

c10::StreamGuard::StreamGuard ( 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 28 of file StreamGuard.h.

c10::StreamGuard::StreamGuard ( StreamGuard &&  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

Device c10::StreamGuard::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 65 of file StreamGuard.h.

Stream c10::StreamGuard::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 59 of file StreamGuard.h.

Device c10::StreamGuard::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 69 of file StreamGuard.h.

void c10::StreamGuard::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 , use MultiStreamGuard instead.

Definition at line 50 of file StreamGuard.h.


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