holoscan::gxf::GXFOutputContext

Beta
View as Markdown

Class to hold the output context for a GXF Operator.

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

#include <holoscan/gxf/gxf_io_context.hpp>

Inherits from: holoscan::OutputContext (public)


Constructors

GXFOutputContext

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.


Methods

gxf_context

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

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 calls on this output port, so the call to this function should occur prior to the emit call(s) for a given port.

Parameters

stream
const cudaStream_t

The CUDA stream

output_port_name
const char *Defaults to nullptr

The name of the output port.

stream_to_emit

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 *Defaults to nullptr

The name of the output port.

execution_context

ExecutionContext * holoscan::gxf::GXFOutputContext::execution_context() const

Get pointer to the execution context.

Returns: The pointer to the execution context.

op

Operator * holoscan::gxf::GXFOutputContext::op() const

Return the operator that this context is associated with.

Returns: The pointer to the operator.

outputs

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

inline
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 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.

Parameters

data
DataT &

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

name
const char *Defaults to nullptr

The name of the output port.

acq_timestamp
const int64_tDefaults to -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

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");
}
};

cuda_object_handler

std::shared_ptr<CudaObjectHandler> holoscan::gxf::GXFOutputContext::cuda_object_handler()

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

This CudaObjectHandler class is designed primarily for internal use and is not guaranteed to have a stable API. Application authors should instead rely on the public set_cuda_stream method.

emit_impl

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 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 *Defaults to nullptr

The name of the output port.

out_type
OutputTypeDefaults to OutputType::kAny

The type of the message data.

acq_timestamp
const int64_tDefaults to -1

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

omit_data_logging
boolDefaults to false

If true, data will not be logged via the DataLogger interface.

skip_stream_propagation
boolDefaults to 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
boolDefaults to false

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

gxf_cuda_object_handler

std::shared_ptr<gxf::CudaObjectHandler> holoscan::gxf::GXFOutputContext::gxf_cuda_object_handler()

log_tensor

bool holoscan::gxf::GXFOutputContext::log_tensor(
const std::shared_ptr<Tensor> &tensor,
const std::string &unique_id,
const char *port_name
)

log_tensormap

bool holoscan::gxf::GXFOutputContext::log_tensormap(
const holoscan::TensorMap &tensor_map,
const std::string &unique_id,
const char *port_name
)

populate_output_metadata

void holoscan::gxf::GXFOutputContext::populate_output_metadata(
nvidia::gxf::Handle<MetadataDictionary> metadata,
const std::string &output_name
)

Types

OutputType

The output data type.

NameValueDescription
kGXFEntityThe message data to send is a GXF entity.
kAnyThe message data to send is a std::any.

Member variables

NameTypeDescription
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 >