Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Types | Public Member Functions | Static Public Member Functions
c10::Stream Class Referencefinal

A stream is a software mechanism used to synchronize launched kernels without requiring explicit synchronizations between kernels. More...

#include <Stream.h>

Public Types

enum  Unsafe { UNSAFE }
 
enum  Default { DEFAULT }
 

Public Member Functions

 Stream (Unsafe, Device device, StreamId id)
 Unsafely construct a stream from a Device and a StreamId. More...
 
 Stream (Default, Device device)
 Construct the default stream of a Device. More...
 
bool operator== (const Stream &other) const noexcept
 
bool operator!= (const Stream &other) const noexcept
 
Device device () const noexcept
 
DeviceType device_type () const noexcept
 
DeviceIndex device_index () const noexcept
 
StreamId id () const noexcept
 
uint64_t pack () const noexcept
 

Static Public Member Functions

static Stream unpack (uint64_t bits)
 

Detailed Description

A stream is a software mechanism used to synchronize launched kernels without requiring explicit synchronizations between kernels.

The basic model is that every kernel launch is associated with a stream: every kernel on the same stream is implicitly synchronized so that if I launch kernels A and B on the same stream, A is guaranteed to finish before B launches. If I want B to run concurrently with A, I must schedule it on a different stream.

The Stream class is a backend agnostic value class representing a stream which I may schedule a kernel on. Every stream is associated with a device, which is recorded in stream, which is used to avoid confusion about which device a stream refers to.

Streams are explicitly thread-safe, in the sense that it is OK to pass a Stream from one thread to another, and kernels queued from two different threads will still get serialized appropriately. (Of course, the time when the kernels get queued is undetermined unless you synchronize host side ;)

Stream does NOT have a default constructor. Streams are for expert users; if you want to use Streams, we're going to assume you know how to deal with C++ template error messages if you try to resize() a vector of Streams.

Known instances of streams in backends:

Because this class is device agnostic, it cannot provide backend-specific functionality (e.g., get the cudaStream_t of a CUDA stream.) There are wrapper classes which provide this functionality, e.g., CUDAStream.

Definition at line 57 of file Stream.h.

Constructor & Destructor Documentation

c10::Stream::Stream ( Unsafe  ,
Device  device,
StreamId  id 
)
inlineexplicit

Unsafely construct a stream from a Device and a StreamId.

In general, only specific implementations of streams for a backend should manufacture Stream directly in this way; other users should use the provided APIs to get a stream. In particular, we don't require backends to give any guarantees about non-zero StreamIds; they are welcome to allocate in whatever way they like.

Definition at line 71 of file Stream.h.

c10::Stream::Stream ( Default  ,
Device  device 
)
inlineexplicit

Construct the default stream of a Device.

The default stream is NOT the same as the current stream; default stream is a fixed stream that never changes, whereas the current stream may be changed by StreamGuard.

Definition at line 79 of file Stream.h.


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