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

> Class to hold the output context for a GXF Operator.

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

This class provides the interface to send data to the output ports of the operator using GXF.

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

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

---

## Constructors

### GXFOutputContext \[#gxfoutputcontext]

#### Construct a new \`GXFOutputContext\` object

```cpp showLineNumbers={false}
holoscan::gxf::GXFOutputContext::GXFOutputContext(
    ExecutionContext *execution_context,
    Operator *op
)
```

Construct a new `GXFOutputContext` object.

**Parameters**

**`execution_context`** `ExecutionContext *`

The pointer to the execution context.

---

**`op`** `Operator *`

The pointer to the GXFOperator object.

---

#### Construct a new \`GXFOutputContext\` object (with outputs)

```cpp showLineNumbers={false}
holoscan::gxf::GXFOutputContext::GXFOutputContext(
    ExecutionContext *execution_context,
    Operator *op,
    std::unordered_map<std::string, std::shared_ptr<IOSpec>> &outputs
)
```

Construct a new `GXFOutputContext` object.

**Parameters**

**`execution_context`** `ExecutionContext *`

The pointer to the execution context.

---

**`op`** `Operator *`

The pointer to the GXFOperator object.

---

**`outputs`** `std::unordered_map<std::string, std::shared_ptr<IOSpec>> &`

Outputs The references to the map of the output specs.

---

---

## Methods

### gxf\_context \[#gxfcontext]

```cpp showLineNumbers={false}
gxf_context_t holoscan::gxf::GXFOutputContext::gxf_context() const
```

Get pointer to the GXF execution runtime.

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

### set\_cuda\_stream \[#setcudastream]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFOutputContext::set_cuda_stream(
    const cudaStream_t stream,
    const char *output_port_name = nullptr
) override
```

Set a stream to be emitted on a given output port.

The actual creation of the stream component in the output message will occur on any subsequent [`emit`](../../../classes/outputcontext#emit) calls on this output port, so the call to this function should occur prior to the [`emit`](../../../classes/outputcontext#emit) call(s) for a given port.

**Parameters**

**`stream`** `const cudaStream_t`

The CUDA stream

---

**`output_port_name`** `const char *` — default: nullptr

The name of the output port.

---

### stream\_to\_emit \[#streamtoemit]

```cpp showLineNumbers={false}
std::optional<cudaStream_t> holoscan::gxf::GXFOutputContext::stream_to_emit(
    const char *output_port_name = nullptr
) override
```

Get the CUDA stream to be emitted on the specified output port.

**Returns:** Optional CUDA stream configured for this output port.

**Parameters**

**`output_port_name`** `const char *` — default: nullptr

The name of the output port.

---

### execution\_context \[#executioncontext]

```cpp showLineNumbers={false}
ExecutionContext * holoscan::gxf::GXFOutputContext::execution_context() const
```

Get pointer to the execution context.

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

### op \[#op]

```cpp showLineNumbers={false}
Operator * holoscan::gxf::GXFOutputContext::op() const
```

Return the operator that this context is associated with.

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

### outputs \[#outputs]

```cpp showLineNumbers={false}
std::unordered_map<std::string, std::shared_ptr<IOSpec>> & holoscan::gxf::GXFOutputContext::outputs() const
```

Return the reference to the map of the output specs.

**Returns:** The reference to the map of the output specs.

### emit \[#emit]

#### Single item (1)

inline

```cpp showLineNumbers={false}
template <typename DataT,
          typename = std::enable_if_t<holoscan::is_one_of_derived_v<DataT, nvidia::gxf::Entity>>>
void holoscan::gxf::GXFOutputContext::emit(
    DataT &data,
    const char *name = nullptr,
    const int64_t acq_timestamp = -1
)
```

Send message data (GXF Entity) to the output port with the given name.

This method is for interoperability with the GXF Codelet.

The object to be sent must be an object with [`holoscan::gxf::Entity`](entity) type and the output port with the given name must exist.

If the operator has a single output port, the output port name can be omitted.

Example:

**Template parameters**

**`DataT`** `typename`

The type of the data to send. It should be [`holoscan::gxf::Entity`](entity).

---

**Parameters**

**`data`** `DataT &`

The entity object to send ([`holoscan::gxf::Entity`](entity)).

---

**`name`** `const char *` — default: nullptr

The name of the output port.

---

**`acq_timestamp`** `const int64_t` — default: -1

The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.

---

**Example**

```cpp showLineNumbers={false}
class PingTxOp : public holoscan::ops::GXFOperator {
 public:
  HOLOSCAN_OPERATOR_FORWARD_ARGS_SUPER(PingTxOp, holoscan::ops::GXFOperator)

  PingTxOp() = default;

  void setup(OperatorSpec& spec) override {
    spec.input<holoscan::gxf::Entity>("in");
    spec.output<holoscan::gxf::Entity>("out");
  }

  void compute(InputContext& op_input, OutputContext& op_output,
               [[maybe_unused]] ExecutionContext& context) override
  {
    // The type of `in_message` is 'holoscan::gxf::Entity'.
    auto in_message = op_input.receive<holoscan::gxf::Entity>("in");
    // The type of `tensor` is 'std::shared_ptr<holoscan::Tensor>'.
    auto tensor = in_message.get<Tensor>();

    // Process with 'tensor' here.
    // ...

    // Create a new message (Entity)
    auto out_message = holoscan::gxf::Entity::New(&context);
    out_message.add(tensor, "tensor");

    // Send the processed message.
    op_output.emit(out_message, "out");
  }
};
```

#### Single item (2)

inline

```cpp showLineNumbers={false}
template <typename DataT,
          typename = std::enable_if_t<!holoscan::is_one_of_derived_v<DataT, nvidia::gxf::Entity>>>
void holoscan::gxf::GXFOutputContext::emit(
    DataT data,
    const char *name = nullptr,
    const int64_t acq_timestamp = -1
)
```

Send the message data (std::any) to the output port with the given name.

This method is for interoperability with arbitrary data types.

The object to be sent can be any type except GXF Entity ([holoscan::gxf::Entity](entity)), and the output port with the given name must exist.

If the operator has a single output port, the output port name can be omitted.

Example:

**Template parameters**

**`DataT`** `typename`

The type of the data to send. It can be any type except GXF Entity ([holoscan::gxf::Entity](entity)).

---

**Parameters**

**`data`** `DataT`

The entity object to send (as `std::any`).

---

**`name`** `const char *` — default: nullptr

The name of the output port.

---

**`acq_timestamp`** `const int64_t` — default: -1

The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.

---

**Example**

```cpp showLineNumbers={false}
class PingTxOp : public holoscan::ops::GXFOperator {
 public:
  HOLOSCAN_OPERATOR_FORWARD_ARGS_SUPER(PingTxOp, holoscan::ops::GXFOperator)

  PingTxOp() = default;

  void setup(OperatorSpec& spec) override {
    spec.input<holoscan::gxf::Entity>("in");
    spec.output<std::shared_ptr<holoscan::Tensor>>("out");
  }

  void compute(InputContext& op_input, OutputContext& op_output,
               [[maybe_unused]] ExecutionContext& context) override
  {
    // The type of `in_message` is 'holoscan::gxf::Entity'.
    auto in_message = op_input.receive<holoscan::gxf::Entity>("in");
    // The type of `tensor` is 'std::shared_ptr<holoscan::Tensor>'.
    auto tensor = in_message.get<Tensor>();  // type: std::shared_ptr<holoscan::Tensor>

    // Process with 'tensor' here.
    // ...

    // Send the processed tensor.
    op_output.emit(tensor, "out");
  }
};
```

#### Single item (3)

```cpp showLineNumbers={false}
void holoscan::gxf::GXFOutputContext::emit(
    holoscan::TensorMap &data,
    const char *name = nullptr,
    const int64_t acq_timestamp = -1
)
```

Send the message data ([holoscan::TensorMap](../../../classes/tensormap)) to the output port with the given name.

This method is for interoperability with [holoscan::TensorMap](../../../classes/tensormap) type.

The output port with the given name must exist.

**Parameters**

**`data`** `holoscan::TensorMap &`

The tensor map object to send (as [`holoscan::TensorMap`](../../../classes/tensormap)).

---

**`name`** `const char *` — default: nullptr

The name of the output port.

---

**`acq_timestamp`** `const int64_t` — default: -1

The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.

---

#### Single item (4)

```cpp showLineNumbers={false}
void holoscan::gxf::GXFOutputContext::emit(
    const std::shared_ptr<holoscan::Tensor> &data,
    const char *name = nullptr,
    const int64_t acq_timestamp = -1
)
```

Send the message data (std::shared\_ptr\<holoscan::Tensor>) to the output port with the given name.

This method does a conversion to std::shared\_ptr\<nvidia::gxf::Tensor> (without copying the tensor's data). Using nvidia::gxf::Tensor is necessary for serialization of tensors when sending a tensor between fragments of a distributed application.

The output port with the given name must exist.

**Parameters**

**`data`** `const std::shared_ptr<holoscan::Tensor> &`

Shared pointer to [holoscan::Tensor](../../../classes/tensor)

---

**`name`** `const char *` — default: nullptr

The name of the output port.

---

**`acq_timestamp`** `const int64_t` — default: -1

The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.

---

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

#### Overload 1

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

Get the CUDA stream/event handler used by this input context.

This [`CudaObjectHandler`](../../../classes/cudaobjecthandler) class is designed primarily for internal use and is not guaranteed to have a stable API. [Application](../../../classes/application) authors should instead rely on the public [`set_cuda_stream`](../../../classes/outputcontext#setcudastream) method.

#### Overload 2

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

Set the CUDA stream handler used by this output context.

### emit\_impl \[#emitimpl]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFOutputContext::emit_impl(
    std::any data,
    const char *name = nullptr,
    OutputType out_type = OutputType::kAny,
    const int64_t acq_timestamp = -1,
    bool omit_data_logging = false,
    bool skip_stream_propagation = false,
    bool is_new_entity = false
) override
```

The implementation of the [`emit`](../../../classes/outputcontext#emit) method.

Depending on the type of the data, this method wraps the data with a message and sends it to the output port with the given name.

**Parameters**

**`data`** `std::any`

The data to send.

---

**`name`** `const char *` — default: nullptr

The name of the output port.

---

**`out_type`** `OutputType` — default: OutputType::kAny

The type of the message data.

---

**`acq_timestamp`** `const int64_t` — default: -1

The timestamp to publish in the output message. The default value of -1 does not publish a timestamp.

---

**`omit_data_logging`** `bool` — default: false

If true, data will not be logged via the [DataLogger](../../../classes/datalogger) interface.

---

**`skip_stream_propagation`** `bool` — default: false

If true, skip propagating CUDA stream to entity memory buffers. Used when the caller has already set the stream on tensors.

---

**`is_new_entity`** `bool` — default: false

If true, the entity was just created (not forwarded), allowing optimizations like skipping checks for existing components.

---

### gxf\_cuda\_object\_handler \[#gxfcudaobjecthandler]

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

### log\_tensor \[#logtensor]

```cpp showLineNumbers={false}
bool holoscan::gxf::GXFOutputContext::log_tensor(
    const std::shared_ptr<Tensor> &tensor,
    const std::string &unique_id,
    const char *port_name
)
```

### log\_tensormap \[#logtensormap]

```cpp showLineNumbers={false}
bool holoscan::gxf::GXFOutputContext::log_tensormap(
    const holoscan::TensorMap &tensor_map,
    const std::string &unique_id,
    const char *port_name
)
```

### populate\_output\_metadata \[#populateoutputmetadata]

```cpp showLineNumbers={false}
void holoscan::gxf::GXFOutputContext::populate_output_metadata(
    nvidia::gxf::Handle<MetadataDictionary> metadata,
    const std::string &output_name
)
```

---

## Types

### OutputType

The output data type.

| Name         | Value | Description                               |
| ------------ | ----- | ----------------------------------------- |
| `kGXFEntity` |       | The message data to send is a GXF entity. |
| `kAny`       |       | The message data to send is a std::any.   |

---

## Member variables

| Name                   | Type                                                             | Description                                        |
| ---------------------- | ---------------------------------------------------------------- | -------------------------------------------------- |
| `execution_context_`   | `ExecutionContext *`                                             | The execution context that is associated with.     |
| `op_`                  | `Operator *`                                                     | The operator that this context is associated with. |
| `outputs_`             | `std::unordered_map< std::string, std::shared_ptr< IOSpec > > &` | The outputs.                                       |
| `cuda_object_handler_` | `std::shared_ptr< CudaObjectHandler >`                           |                                                    |