> 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::ExecutionContext

> Class to hold the execution context.

Class to hold the execution context.

This class provides the execution context for the operator.

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

---

## Constructors

### ExecutionContext \[#executioncontext]

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

Construct a new Execution Context object.

### Destructor \[#destructor]

### \~ExecutionContext

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

---

## Methods

### input \[#input]

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

Get the input context.

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

### output \[#output]

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

Get the output context.

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

### context \[#context]

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

Get the context.

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

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

```cpp showLineNumbers={false}
virtual expected<cudaStream_t, RuntimeError> holoscan::ExecutionContext::allocate_cuda_stream(
    const std::string &stream_name = ""
)
```

Allocate a CUDA stream from the operator's [CudaStreamPool](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](cudastreampool) is available.

**Parameters**

**`stream_name`** `const std::string &` — default: ""

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

---

### synchronize\_streams \[#synchronizestreams]

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

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

**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 \[#isgpuavailable]

```cpp showLineNumbers={false}
virtual bool holoscan::ExecutionContext::is_gpu_available() const
```

check if GPU capability is present on the system

### find\_operator \[#findoperator]

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

The name of the operator.

---

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

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

The name of the operator.

---

---

## Member variables

| Name              | Type                               | Description         |
| ----------------- | ---------------------------------- | ------------------- |
| `input_context_`  | `std::shared_ptr< InputContext >`  | The input context.  |
| `output_context_` | `std::shared_ptr< OutputContext >` | The output context. |
| `context_`        | `void *`                           | The context.        |