> This page is for version 4.3.
> For other versions, use one of these documentation indexes:
> - 4.6 (Latest) (default): https://docs.nvidia.com/holoscan/sdk-user-guide/4-6-latest/llms.txt
> - ltsb-2.0: https://docs.nvidia.com/holoscan/sdk-user-guide/ltsb-2-0/llms.txt
> - 4.5: https://docs.nvidia.com/holoscan/sdk-user-guide/4-5/llms.txt
> - 4.4: https://docs.nvidia.com/holoscan/sdk-user-guide/4-4/llms.txt
> - 4.3: https://docs.nvidia.com/holoscan/sdk-user-guide/4-3/llms.txt
> - Archives: https://docs.nvidia.com/holoscan/sdk-user-guide/archives/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::CudaObjectHandler

> Pure virtual base class for handling CUDA streams in operators.

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.

```cpp showLineNumbers={false}
#include <holoscan/cuda_object_handler.hpp>
```

---

## Constructors

### Destructor \[#destructor]

### \~CudaObjectHandler

```cpp showLineNumbers={false}
virtual holoscan::CudaObjectHandler::~CudaObjectHandler() = default
```

---

## Methods

### init\_from\_operator \[#initfromoperator]

```cpp showLineNumbers={false}
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 \[#addstream]

```cpp showLineNumbers={false}
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 \[#getcudastream]

```cpp showLineNumbers={false}
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`** `bool` — default: false

If true, allocate a new stream if none exists

---

**`sync_to_default`** `bool` — default: true

If true, synchronize to default stream

---

### get\_cuda\_streams \[#getcudastreams]

```cpp showLineNumbers={false}
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](../typedefs/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 \[#synchronizestreams]

```cpp showLineNumbers={false}
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`** `bool` — default: true

If true, also sync to default stream

---

### release\_internal\_streams \[#releaseinternalstreams]

```cpp showLineNumbers={false}
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 \[#clearreceivedstreams]

```cpp showLineNumbers={false}
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 \[#isgpuavailable]

```cpp showLineNumbers={false}
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