> 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::gxf::GXFExecutionContext

> Class to hold the execution context for GXF Operator.

Class to hold the execution context for GXF [Operator](../../../classes/operator).

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

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

**Inherits from:** `holoscan::ExecutionContext` (public)

***

## Constructors

### GXFExecutionContext \[#gxfexecutioncontext]

```cpp showLineNumbers={false}
holoscan::gxf::GXFExecutionContext::GXFExecutionContext() = default
```

```cpp showLineNumbers={false}
holoscan::gxf::GXFExecutionContext::GXFExecutionContext(
    gxf_context_t context,
    Operator *op
)
```

Construct a new `GXFExecutionContext` object.

**Parameters**

The pointer to the GXF context.

The pointer to the operator.

```cpp showLineNumbers={false}
holoscan::gxf::GXFExecutionContext::GXFExecutionContext(
    gxf_context_t context,
    std::shared_ptr<GXFInputContext> gxf_input_context,
    std::shared_ptr<GXFOutputContext> gxf_output_context
)
```

Construct a new `GXFExecutionContext` object.

**Parameters**

The pointer to the GXF context.

The shared pointer to the [GXFInputContext](gxfinputcontext) object.

The shared pointer to the [GXFOutputContext](gxfoutputcontext) object.

### Destructor \[#destructor]

### \~GXFExecutionContext

```cpp showLineNumbers={false}
holoscan::gxf::GXFExecutionContext::~GXFExecutionContext() override = default
```

***

## Methods

### gxf\_input \[#gxfinput]

```cpp showLineNumbers={false}
std::shared_ptr<GXFInputContext> holoscan::gxf::GXFExecutionContext::gxf_input()
```

Get the GXF input context.

**Returns:** The pointer to the [GXFInputContext](gxfinputcontext) object.

### gxf\_output \[#gxfoutput]

```cpp showLineNumbers={false}
std::shared_ptr<GXFOutputContext> holoscan::gxf::GXFExecutionContext::gxf_output()
```

Get the GXF output context.

**Returns:** The pointer to the [GXFOutputContext](gxfoutputcontext) object.

### allocate\_cuda\_stream \[#allocatecudastream]

```cpp showLineNumbers={false}
expected<cudaStream_t, RuntimeError> holoscan::gxf::GXFExecutionContext::allocate_cuda_stream(
    const std::string &stream_name
) override
```

allocate a new GXF [CudaStream](../typedefs/cudastream) object and return the cudaStream\_t corresponding to it

### synchronize\_streams \[#synchronizestreams]

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

[Vector](../../../typedefs/vector) of streams to synchronize. `std::nullopt` elements are skipped.

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

### device\_from\_stream \[#devicefromstream]

```cpp showLineNumbers={false}
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`](#allocatecudastream)).

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

**Parameters**

The CUDA stream to query.

### is\_gpu\_available \[#isgpuavailable]

```cpp showLineNumbers={false}
bool holoscan::gxf::GXFExecutionContext::is_gpu_available() const override
```

check if GPU capability is present on the system

### find\_operator \[#findoperator]

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

The name of the operator.

### get\_operator\_status \[#getoperatorstatus]

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

The name of the operator.

### stream\_handle\_from\_stream \[#streamhandlefromstream]

```cpp showLineNumbers={false}
expected<gxf::CudaStreamHandle, RuntimeError> holoscan::gxf::GXFExecutionContext::stream_handle_from_stream(
    cudaStream_t stream
)
```

Return the [CudaStreamHandle](../typedefs/cudastreamhandle) corresponding to a given cudaStream\_t.

This will only work with a cudaStream\_t that was allocated as a [CudaStream](../typedefs/cudastream) object by GXF. The stream should correspond to a [CudaStreamId](../typedefs/cudastreamid) that was received on one of the [Operator](../../../classes/operator)'s input ports or a stream that was allocated via [`allocate_cuda_stream`](#allocatecudastream).

**Returns:** The GXF [CudaStream](../typedefs/cudastream) handle if found, or unexpected if not found.

**Parameters**

A CUDA stream object.

### cuda\_object\_handler \[#cudaobjecthandler]

```cpp showLineNumbers={false}
std::shared_ptr<gxf::CudaObjectHandler> holoscan::gxf::GXFExecutionContext::cuda_object_handler()
```

### init\_cuda\_object\_handler \[#initcudaobjecthandler]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFExecutionContext::init_cuda_object_handler(
    Operator *op
)
```

initialize the [CudaObjectHandler](cudaobjecthandler) for the [Operator](../../../classes/operator)

### release\_internal\_cuda\_streams \[#releaseinternalcudastreams]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFExecutionContext::release_internal_cuda_streams()
```

release any internal stream objects allocated by the operator

### clear\_received\_streams \[#clearreceivedstreams]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFExecutionContext::clear_received_streams()
```

clear the handler's received stream mappings from a prior [`Operator::compute`](../../../classes/gpuresidentoperator#compute) call.

### input \[#input]

```cpp showLineNumbers={false}
std::shared_ptr<InputContext> holoscan::gxf::GXFExecutionContext::input() const
```

Get the input context.

**Returns:** The shared pointer to the input context.

### output \[#output]

```cpp showLineNumbers={false}
std::shared_ptr<OutputContext> holoscan::gxf::GXFExecutionContext::output() const
```

Get the output context.

**Returns:** The shared pointer to the output context.

### context \[#context]

```cpp showLineNumbers={false}
void * holoscan::gxf::GXFExecutionContext::context() const
```

Get the context.

**Returns:** The pointer to the context.

### allocate\_cuda\_stream\_handle \[#allocatecudastreamhandle]

```cpp showLineNumbers={false}
expected<CudaStreamHandle, RuntimeError> holoscan::gxf::GXFExecutionContext::allocate_cuda_stream_handle(
    const std::string &stream_name
)
```

allocate a new GXF [CudaStream](../typedefs/cudastream) object and return the GXF Handle to it

### get\_operator\_eid \[#getoperatoreid]

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

| Name                   | Type                                           | Description                        |
| ---------------------- | ---------------------------------------------- | ---------------------------------- |
| `op_`                  | `Operator *`                                   | The operator pointer.              |
| `eid_`                 | `gxf_uid_t`                                    | The 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.                       |