Class OutputContext
Defined in File io_context.hpp
Derived Type
public holoscan::gxf::GXFOutputContext(Class GXFOutputContext)
- 
class OutputContext
 Class to hold the output context.
This class provides the interface to send data to the output ports of the operator.
Subclassed by holoscan::gxf::GXFOutputContext
Public Functions
- 
inline OutputContext(ExecutionContext *execution_context, Operator *op)
 Construct a new OutputContext object.
outputs for the OutputContext will be set to op->spec()->outputs()
- Parameters
 execution_context – The pointer to the execution context.
op – The pointer to the operator that this context is associated with.
Construct a new OutputContext object.
- Parameters
 execution_context – The pointer to the execution context.
op – The pointer to the operator that this context is associated with.
outputs – The references to the map of the output specs.
- 
virtual ~OutputContext() = default
 
- 
inline ExecutionContext *execution_context() const
 Get pointer to the execution context.
- Returns
 The pointer to the execution context.
- 
inline Operator *op() const
 Return the operator that this context is associated with.
- Returns
 The pointer to the operator.
- 
inline std::unordered_map<std::string, std::shared_ptr<IOSpec>> &outputs() const
 Return the reference to the map of the output specs.
- Returns
 The reference to the map of the output specs.
- 
template<typename DataT, typename = std::enable_if_t<holoscan::is_one_of_derived_v<DataT, nvidia::gxf::Entity>>>
inline void 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::Entitytype 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:
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"); } };
- Template Parameters
 DataT – The type of the data to send. It should be
holoscan::gxf::Entity.- Parameters
 data – The entity object to send (
holoscan::gxf::Entity).name – The name of the output port.
acq_timestamp – The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.
- 
template<typename DataT, typename = std::enable_if_t<!holoscan::is_one_of_derived_v<DataT, nvidia::gxf::Entity>>>
inline void 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), 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:
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"); } };
- Template Parameters
 DataT – The type of the data to send. It can be any type except GXF Entity (holoscan::gxf::Entity).
- Parameters
 data – The entity object to send (as
std::any).name – The name of the output port.
acq_timestamp – The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.
- 
inline void emit(holoscan::TensorMap &data, const char *name = nullptr, const int64_t acq_timestamp = -1)
 Send the message data (holoscan::TensorMap) to the output port with the given name.
This method is for interoperability with holoscan::TensorMap type.
The output port with the given name must exist.
- Parameters
 data – The tensor map object to send (as
holoscan::TensorMap).name – The name of the output port.
acq_timestamp – The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.
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 – shared pointer to holoscan::Tensor
name – The name of the output port.
acq_timestamp – The time when the message is acquired. For instance, this would generally be the timestamp of the camera when it captures an image.
- 
virtual void set_cuda_stream(const cudaStream_t stream, const char *output_port_name = nullptr) = 0
 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
emitcalls on this output port, so the call to this function should occur prior to theemitcall(s) for a given port.- Parameters
 stream – The CUDA stream
output_port_name – The name of the output port.
- 
inline std::shared_ptr<CudaObjectHandler> cuda_object_handler()
 Get the CUDA stream/event handler used by this input context.
This
CudaObjectHandlerclass is designed primarily for internal use and is not guaranteed to have a stable API. Application authors should instead rely on the publicset_cuda_streammethod.
Set the CUDA stream handler used by this output context.
Protected Types
- 
enum class OutputType
 The output data type.
Values:
- 
enumerator kGXFEntity
 The message data to send is a GXF entity.
- 
enumerator kAny
 The message data to send is a std::any.
- 
enumerator kGXFEntity
 
Protected Functions
- 
inline virtual void emit_impl(std::any data, const char *name = nullptr, OutputType out_type = OutputType::kAny, const int64_t acq_timestamp = -1)
 The implementation of the
emitmethod.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 – The data to send.
name – The name of the output port.
out_type – The type of the message data.
acq_timestamp – The timestamp to publish in the output message. The default value of -1 does not publish a timestamp.
Protected Attributes
- 
ExecutionContext *execution_context_ = nullptr
 The execution context that is associated with.
- 
Operator *op_ = nullptr
 The operator that this context is associated with.
- 
std::unordered_map<std::string, std::shared_ptr<IOSpec>> &outputs_
 The outputs.
- 
std::shared_ptr<CudaObjectHandler> cuda_object_handler_ = {}
 
- 
inline OutputContext(ExecutionContext *execution_context, Operator *op)