holoscan::CudaObjectHandler

Beta
View as Markdown

Pure virtual base class for handling CUDA streams in operators.

This class defines the interface for managing CUDA streams in Holoscan operators. It provides methods for stream synchronization, allocation, and management.

#include <holoscan/cuda_object_handler.hpp>

Constructors

Destructor

~CudaObjectHandler

virtual holoscan::CudaObjectHandler::~CudaObjectHandler() = default

Methods

init_from_operator

virtual void holoscan::CudaObjectHandler::init_from_operator(
Operator *op
)

Initialize the handler from an operator.

Parameters

op
Operator *

The operator this instance is attached to.

add_stream

virtual int holoscan::CudaObjectHandler::add_stream(
const cudaStream_t stream,
const std::string &output_port_name
)

Add a CUDA stream to an output port.

Returns: 0 if successful, otherwise an error code

Parameters

stream
const cudaStream_t

The stream to add

output_port_name
const std::string &

The name of the output port

get_cuda_stream

virtual cudaStream_t holoscan::CudaObjectHandler::get_cuda_stream(
void *context,
const std::string &input_port_name,
bool allocate = false,
bool sync_to_default = true
)

Get the CUDA stream for a given input port.

Returns: The CUDA stream to use

Parameters

context
void *

Context object (e.g. gxf_context_t for the GXF backend)

input_port_name
const std::string &

The name of the input port

allocate
boolDefaults to false

If true, allocate a new stream if none exists

sync_to_default
boolDefaults to true

If true, synchronize to default stream

get_cuda_streams

virtual std::vector<std::optional<cudaStream_t>> holoscan::CudaObjectHandler::get_cuda_streams(
void *context,
const std::string &input_port_name
)

Get all CUDA streams for a given input port.

Returns: Vector of optional CUDA streams (one per message)

Parameters

context
void *

Context object (e.g. gxf_context_t for the GXF backend)

input_port_name
const std::string &

The name of the input port

synchronize_streams

virtual int holoscan::CudaObjectHandler::synchronize_streams(
std::vector<cudaStream_t> cuda_streams,
cudaStream_t target_stream,
bool sync_to_default_stream = true
)

Synchronize streams with a target stream.

Returns: 0 if successful, error code otherwise

Parameters

cuda_streams
std::vector<cudaStream_t>

The streams to synchronize

target_stream
cudaStream_t

The stream to synchronize to

sync_to_default_stream
boolDefaults to true

If true, also sync to default stream

release_internal_streams

virtual int holoscan::CudaObjectHandler::release_internal_streams(
void *context
)

Release all internally allocated CUDA streams.

Returns: 0 if successful, error code otherwise

Parameters

context
void *

Context object (e.g. gxf_context_t for the GXF backend)

clear_received_streams

virtual void holoscan::CudaObjectHandler::clear_received_streams()

Clear all received streams.

This is used to refresh the state before each compute call.

is_gpu_available

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

Check if GPU capability is present on the system.

Returns: true if GPU(s) are available, false if no GPU is present