holoscan::InputContext
holoscan::InputContext
Class to hold the input context.
This class provides the interface to receive the input data from the operator.
Constructors
InputContext
Construct a new InputContext object (with inputs)
Construct a new InputContext object
Construct a new InputContext object.
Parameters
The pointer to the execution context.
The pointer to the operator that this context is associated with.
The references to the map of the input specs.
Destructor
~InputContext
Methods
execution_context
Get pointer to the execution context.
Returns: The pointer to the execution context.
op
Return the operator that this context is associated with.
Returns: The pointer to the operator.
inputs
Return the reference to the map of the input specs.
Returns: The reference to the map of the input specs.
empty
Return whether the input port has any data.
For parameters with std::vector<IOSpec*> type, if all the inputs are empty, it will return true. Otherwise, it will return false.
Returns: True, if it has no data, otherwise false.
Parameters
The name of the input port to check.
reset_acquisition_timestamps
Reset acquisition timestamp map values to std::nullopt for all input ports.
This method should be called before each compute call to reset the timestamp values while preserving the pre-initialized map structure for performance.
get_acquisition_timestamp
Get the acquisition timestamp for a given input port.
Returns: The acquisition timestamp. If no timestamp was published by the upstream operator, std::nullopt is returned.
Parameters
The name of the input port.
get_acquisition_timestamps
Get all acquisition timestamp for a given input port.
For a port with queue size not equal to one (e.g. an IOSpec::kAnySize connection) there may be multiple messages in a queue, each with its own acquisition timestamp. This method returns a vector of std::optional<int64_t> where the length of the vector is the same as the number of messages received on that port.
Returns: The acquisition timestamps. Values of std::nullopt in the vector indicate that the corresponding message did not contain a timestamp.
Parameters
The name of the input port.
receive
Receive a message from the input port with the given name.
If the operator has a single input port, the name of the input port can be omitted.
If the input port with the given name and type (DataT) is available, it will return the data from the input port. Otherwise, it will return an object of the holoscan::unexpected class which will contain the error message. The error message can be access by calling the what() method of the holoscan::unexpected object.
It throws an invalid argument exception if the operator attempts to receive non-vector data (op_input.receive<T>()) from an input port with a queue size of IOSpec::kAnySize.
Example:
Returns: The received data.
Template parameters
The type of the data to receive.
Parameters
The name of the input port to receive the data from.
Example
cuda_object_handler
Overload 1
Overload 2
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 receive_cuda_stream and receive_cuda_streams methods.
receive_cuda_stream
Get the operator’s internal CUDA stream, synchronizing any upstream streams to it.
This is the recommended method for stream handling in most operators. It performs several operations:
- Synchronizes upstream streams to the operator’s internal stream using non-blocking CUDA events (
cudaEventRecord/cudaStreamWaitEvent). This ensures upstream GPU work completes before this operator’s work begins, without blocking the CPU. - Sets the CUDA device (
cudaSetDevice) to match the internal stream’s device. - Configures all output ports to automatically emit the internal stream ID when
emit()is called. - Returns the internal cudaStream_t for use in kernels and async memory operations.
If no CudaStreamPool resource was available on the operator, the operator will not have an internal stream. In that case, the first stream received on the input port will be returned and any additional streams on the input will have been synchronized to it. If no streams were found on the input and no CudaStreamPool resource was available, cudaStreamDefault is returned.
The receive() method must be called for input_port_name before calling this method. The receive() call captures stream IDs from incoming messages.
Returns: The operator’s internal CUDA stream (reused across all compute() calls). Returns cudaStreamDefault if no stream pool was available and no stream was found on the input port.
Parameters
The name of the input port. Can be omitted if the operator only has a single input port.
Whether to allocate an internal stream if not already allocated. If false or no CudaStreamPool is available, the first received stream is used as the internal stream.
Whether to also synchronize the internal stream to cudaStreamDefault.
receive_cuda_streams
Retrieve the CUDA streams found on an input port (advanced use).
Unlike receive_cuda_stream, this method does not perform any synchronization, does not allocate an internal stream, does not set the CUDA device, and does not configure output ports. It simply returns the raw stream information found in the received messages.
This method is intended for advanced use cases where manual stream management is required. For most operators, use receive_cuda_stream instead.
The receive() method must be called for input_port_name before calling this method. The receive() call captures stream IDs from incoming messages.
Returns: Vector of (optional) cudaStream_t. In normal operation, the length of the vector matches the number of messages on the input port, with std::nullopt for messages without a stream. If stream handling is unavailable (e.g., CudaObjectHandler not initialized), an empty vector is returned.
Parameters
The name of the input port. Can be omitted if the operator only has a single input port.
empty_impl
The implementation of the empty method.
Returns: True if the input port is empty or by default. Otherwise, false.
Parameters
The name of the input port
receive_impl
The implementation of the receive method.
Depending on the type of the data, this method receives a message from the input port with the given name.
Returns: The data received from the input port.
Parameters
The name of the input port.
The input type (kGXFEntity or kAny).
Whether to print an error message when the input port is not found.
Whether any calls to log_backend_specific should be skipped. Currently used to avoid duplication of logging of TensorMap contents.
is_valid_param_type
any_size_param_count
should_fallback_to_direct_any_size_input
fill_input_vector_from_params
fill_input_vector_from_inputs
get_unique_id
log_tensor
log_tensormap
populate_tensor_map
process_received_value
handle_null_value
Overload 1
Overload 2
handle_bad_any_cast
receive_single_value
create_receive_error
prepopulate_acquisition_timestamp_map
get_first_stream_for_logging
Helper to extract the first received CUDA stream for logging.
Returns: The first CUDA stream if available, std::nullopt otherwise
Parameters
The name of the input port
Types
InputType
The input data type.