holoscan::ExecutionContext

Beta
View as Markdown

Class to hold the execution context.

This class provides the execution context for the operator.

#include <holoscan/execution_context.hpp>

Constructors

ExecutionContext

holoscan::ExecutionContext::ExecutionContext() = defaultholoscan::ExecutionContext::ExecutionContext() = default

Construct a new Execution Context object.

Destructor

~ExecutionContext

virtual holoscan::ExecutionContext::~ExecutionContext() = defaultvirtual holoscan::ExecutionContext::~ExecutionContext() = default

Methods

input

std::shared_ptr<InputContext> holoscan::ExecutionContext::input() conststd::shared_ptr<InputContext> holoscan::ExecutionContext::input() const

Get the input context.

Returns: The shared pointer to the input context.

output

std::shared_ptr<OutputContext> holoscan::ExecutionContext::output() conststd::shared_ptr<OutputContext> holoscan::ExecutionContext::output() const

Get the output context.

Returns: The shared pointer to the output context.

context

void * holoscan::ExecutionContext::context() const

Get the context.

Returns: The pointer to the context.

allocate_cuda_stream

virtual expected<cudaStream_t, RuntimeError> holoscan::ExecutionContext::allocate_cuda_stream(virtual expected<cudaStream_t, RuntimeError> holoscan::ExecutionContext::allocate_cuda_stream(
const std::string &stream_name = ""
)

Allocate a CUDA stream from the operator’s CudaStreamPool.

Streams are cached by name — calling with the same name returns the same stream on subsequent calls within the same operator. This is useful for root operators that need to allocate a stream (rather than receiving one from upstream).

Streams allocated this way are not automatically emitted on output ports. Call OutputContext::set_cuda_stream() before emit() if you need to propagate the stream.

Returns: The allocated cudaStream_t, or an error if no CudaStreamPool is available.

Parameters

stream_name
const std::string &Defaults to ""

A name for the stream. The same name returns the same stream on subsequent calls. Defaults to an empty string.

synchronize_streams

virtual void holoscan::ExecutionContext::synchronize_streams(
const std::vector<std::optional<cudaStream_t>> &cuda_streams,
cudaStream_t target_cuda_stream
)

Synchronize multiple CUDA streams to a target stream (non-blocking).

Uses cudaEventRecord and cudaStreamWaitEvent to create GPU-side dependencies without blocking the CPU. This is the same mechanism used internally by receive_cuda_stream.

When using receive_cuda_stream, synchronization is handled automatically and this method is not needed. It is provided for advanced manual stream handling use cases.

Parameters

cuda_streams
const std::vector<std::optional<cudaStream_t>> &

Vector of streams to synchronize. std::nullopt elements are skipped.

target_cuda_stream
cudaStream_t

The stream that will wait for all other streams to complete.

device_from_stream

virtual expected<int, RuntimeError> holoscan::ExecutionContext::device_from_stream(virtual expected<int, RuntimeError> holoscan::ExecutionContext::device_from_stream(
cudaStream_t stream
)

Get the CUDA device ID for a given stream.

Only works with Holoscan-managed streams (those returned by receive_cuda_stream, receive_cuda_streams, or allocate_cuda_stream).

Returns: The device ID, or an error if the stream is not managed by Holoscan.

Parameters

stream
cudaStream_t

The CUDA stream to query.

is_gpu_available

virtual bool holoscan::ExecutionContext::is_gpu_available() const

check if GPU capability is present on the system

find_operator

virtual std::shared_ptr<Operator> holoscan::ExecutionContext::find_operator(virtual std::shared_ptr<Operator> holoscan::ExecutionContext::find_operator(
const std::string &op_name = ""
)

Find an operator by name.

If the operator name is not provided, the current operator is returned.

Returns: A shared pointer to the operator or nullptr if the operator is not found.

Parameters

op_name
const std::string &Defaults to ""

The name of the operator.

get_operator_status

virtual expected<holoscan::OperatorStatus, RuntimeError> holoscan::ExecutionContext::get_operator_status(virtual expected<holoscan::OperatorStatus, RuntimeError> holoscan::ExecutionContext::get_operator_status(
const std::string &op_name = ""
)

Get the status of the operator.

If the operator name is not provided, the status of the current operator is returned.

Returns: The status of the operator or an error if the operator is not found.

Parameters

op_name
const std::string &Defaults to ""

The name of the operator.


Member variables

NameTypeDescription
input_context_std::shared_ptr< InputContext >The input context.
output_context_std::shared_ptr< OutputContext >The output context.
context_void *The context.