Skip to content

tenzr::execution::ExecutionStream

Serialized work queue backed by a worker thread, used to submit and synchronize device work.

#include <stream.h>

Inherits from std::enable_shared_from_this< ExecutionStream >

Public Functions

Name
ExecutionStream(int stream_id =0, int device_id =0)
~ExecutionStream()
Stop the worker, drain queued tasks, and join the thread.
ExecutionStream(const ExecutionStream & ) =delete
ExecutionStream & operator=(const ExecutionStream & ) =delete
int StreamId() const
Return the stream identifier.
int DeviceId() const
Return the owning device identifier.
void RecordEvent(StreamEvent & event)
Record an event capturing work queued so far.
void WaitEvent(const StreamEvent & event)
Make subsequent work wait for an event.
void Synchronize()
Block until all queued work finishes.
void Submit(std::function< void()> task)
Enqueue a task for serialized execution.
template <typename F >
auto
AsyncSubmit(F && task)
ExecutionStream & DefaultStream(int device_id =0)
Access the process-wide stream for a device.
std::shared_ptr< ExecutionStream > Create(int device_id =0)
Create a new heap-allocated stream for a device.

Public Functions Documentation

function ExecutionStream

explicit ExecutionStream(
    int stream_id =0,
    int device_id =0
)

Parameters:

  • stream_id Stream identifier.
  • device_id Device the stream targets.

Start a stream and its dedicated worker thread.

function ~ExecutionStream

~ExecutionStream()

Stop the worker, drain queued tasks, and join the thread.

function ExecutionStream

ExecutionStream(
    const ExecutionStream & 
) =delete

function operator=

ExecutionStream & operator=(
    const ExecutionStream & 
) =delete

function StreamId

inline int StreamId() const

Return the stream identifier.

function DeviceId

inline int DeviceId() const

Return the owning device identifier.

function RecordEvent

void RecordEvent(
    StreamEvent & event
)

Record an event capturing work queued so far.

Parameters:

  • event Event to mark complete.

Queue an event record on this stream.

function WaitEvent

void WaitEvent(
    const StreamEvent & event
)

Make subsequent work wait for an event.

Parameters:

  • event Event to wait for.

Queue a wait on event so subsequent tasks run after it completes.

function Synchronize

void Synchronize()

Block until all queued work finishes.

Block until all queued and in-flight tasks finish.

function Submit

void Submit(
    std::function< void()> task
)

Enqueue a task for serialized execution.

Parameters:

  • task Callable to run; must not be null.

Enqueue a task for asynchronous execution on the worker.

function AsyncSubmit

template <typename F >
inline auto AsyncSubmit(
    F && task
)

Parameters:

  • task Callable to run on the stream.

Return: Future that yields the callable's result.

Enqueue a task and return a future yielding its result.

function DefaultStream

static ExecutionStream & DefaultStream(
    int device_id =0
)

Access the process-wide stream for a device.

Parameters:

  • device_id Device the stream targets.

Return: Reference to the device's default stream.

Get (creating on first use) the shared default stream for a device.

function Create

static std::shared_ptr< ExecutionStream > Create(
    int device_id =0
)

Create a new heap-allocated stream for a device.

Parameters:

  • device_id Device the stream targets.

Return: Owning pointer to the new stream.

Create a new independent stream for a device.