holoscan::gxf::GXFExecutionContext

Beta
View as Markdown

Class to hold the execution context for GXF Operator.

This class provides the execution context for the operator using GXF.

#include <holoscan/gxf/gxf_execution_context.hpp>

Inherits from: holoscan::ExecutionContext (public)


Constructors

GXFExecutionContext

holoscan::gxf::GXFExecutionContext::GXFExecutionContext() = default

Destructor

~GXFExecutionContext

holoscan::gxf::GXFExecutionContext::~GXFExecutionContext() override = default

Methods

gxf_input

std::shared_ptr<GXFInputContext> holoscan::gxf::GXFExecutionContext::gxf_input()

Get the GXF input context.

Returns: The pointer to the GXFInputContext object.

gxf_output

std::shared_ptr<GXFOutputContext> holoscan::gxf::GXFExecutionContext::gxf_output()

Get the GXF output context.

Returns: The pointer to the GXFOutputContext object.

allocate_cuda_stream

expected<cudaStream_t, RuntimeError> holoscan::gxf::GXFExecutionContext::allocate_cuda_stream(
const std::string &stream_name
) override

allocate a new GXF CudaStream object and return the cudaStream_t corresponding to it

synchronize_streams

void holoscan::gxf::GXFExecutionContext::synchronize_streams(
const std::vector<std::optional<cudaStream_t>> &cuda_streams,
cudaStream_t target_cuda_stream
) override

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

expected<int, RuntimeError> holoscan::gxf::GXFExecutionContext::device_from_stream(
cudaStream_t stream
) override

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

bool holoscan::gxf::GXFExecutionContext::is_gpu_available() const override

check if GPU capability is present on the system

find_operator

std::shared_ptr<Operator> holoscan::gxf::GXFExecutionContext::find_operator(
const std::string &op_name
) override

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 &

The name of the operator.

get_operator_status

expected<holoscan::OperatorStatus, RuntimeError> holoscan::gxf::GXFExecutionContext::get_operator_status(
const std::string &op_name
) override

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 &

The name of the operator.

stream_handle_from_stream

expected<gxf::CudaStreamHandle, RuntimeError> holoscan::gxf::GXFExecutionContext::stream_handle_from_stream(
cudaStream_t stream
)

Return the CudaStreamHandle corresponding to a given cudaStream_t.

This will only work with a cudaStream_t that was allocated as a CudaStream object by GXF. The stream should correspond to a CudaStreamId that was received on one of the Operator’s input ports or a stream that was allocated via allocate_cuda_stream.

Returns: The GXF CudaStream handle if found, or unexpected if not found.

Parameters

stream
cudaStream_t

A CUDA stream object.

cuda_object_handler

std::shared_ptr<gxf::CudaObjectHandler> holoscan::gxf::GXFExecutionContext::cuda_object_handler()

init_cuda_object_handler

void holoscan::gxf::GXFExecutionContext::init_cuda_object_handler(
Operator *op
)

initialize the CudaObjectHandler for the Operator

release_internal_cuda_streams

void holoscan::gxf::GXFExecutionContext::release_internal_cuda_streams()

release any internal stream objects allocated by the operator

clear_received_streams

void holoscan::gxf::GXFExecutionContext::clear_received_streams()

clear the handler’s received stream mappings from a prior Operator::compute call.

input

std::shared_ptr<InputContext> holoscan::gxf::GXFExecutionContext::input() const

Get the input context.

Returns: The shared pointer to the input context.

output

std::shared_ptr<OutputContext> holoscan::gxf::GXFExecutionContext::output() const

Get the output context.

Returns: The shared pointer to the output context.

context

void * holoscan::gxf::GXFExecutionContext::context() const

Get the context.

Returns: The pointer to the context.

allocate_cuda_stream_handle

expected<CudaStreamHandle, RuntimeError> holoscan::gxf::GXFExecutionContext::allocate_cuda_stream_handle(
const std::string &stream_name
)

allocate a new GXF CudaStream object and return the GXF Handle to it

get_operator_eid

expected<gxf_uid_t, RuntimeError> holoscan::gxf::GXFExecutionContext::get_operator_eid(
const std::string &op_name
)

get the GXF entity ID of the operator


Member variables

NameTypeDescription
op_Operator *The operator pointer.
eid_gxf_uid_tThe GXF entity ID of the operator.
gxf_input_context_std::shared_ptr< GXFInputContext >The GXF input context.
gxf_output_context_std::shared_ptr< GXFOutputContext >The GXF output context.
cuda_object_handler_std::shared_ptr< gxf::CudaObjectHandler >
operator_eid_cache_std::unordered_map< std::string, gxf_uid_t >Cache for operator EIDs.
input_context_std::shared_ptr< InputContext >The input context.
output_context_std::shared_ptr< OutputContext >The output context.
context_void *The context.