Class CudaStreamCondition
Defined in File cuda_stream.hpp
Base Type
public holoscan::Condition(Class Condition)
-
class CudaStreamCondition : public holoscan::Condition
Native condition class for CUDA stream synchronization with multi-message support.
This condition supports:
Multiple messages in the input queue (queue_size > 1)
Multiple CudaStreamId components per message
Multiple receiver ports (both regular and IOSpec::kAnySize multi-receiver inputs)
By default, this condition examines ALL messages in all receiver queues and waits for GPU work on ALL associated CUDA streams to complete before allowing the operator to execute. This behavior can be changed by setting
check_all_messagestofalse, which makes it check only the first message per receiver.The condition uses
cudaLaunchHostFunc()to register callbacks that fire when GPU work on each stream completes. It returnskWaitEventstatus while waiting for callbacks, then transitions tokReadywhen all callbacks have fired.Note: This condition does NOT consume messages - it only peeks at them. The operator’s compute() method is responsible for actually receiving the messages.
==Parameters==
receiver (std::string): DEPRECATED - Use
receiversinstead. Legacy API for a single input port to monitor. Cannot be used together withreceivers. Using this parameter will log a deprecation warning.receivers (std::string or std::vector<std::string>): Name(s) of input port(s) to monitor for CUDA streams. Can be a single string like “input” or a vector like {“input1”, “input2”}. Works with both:
Regular ports: specified by exact name (e.g., “input”)
Multi-receiver ports (IOSpec::kAnySize): specified by base name (e.g., “receivers”), which automatically expands to find all ports matching the pattern (“receivers:0”, “receivers:1”, etc.) Cannot be used together with
receiver.
check_all_messages (bool, default=true): If true, checks ALL messages in the queue(s) for CudaStreamId components and waits for all associated streams. If false, only checks the first message in each queue.
==Usage==
// Single regular input port (legacy API) auto stream_cond = make_condition<CudaStreamCondition>( "cuda_sync", Arg("receiver", "input")); // Single regular input port (new API) auto stream_cond = make_condition<CudaStreamCondition>( "cuda_sync", Arg("receivers", "input")); // Multiple regular input ports auto stream_cond_multi = make_condition<CudaStreamCondition>( "cuda_sync", Arg("receivers", std::vector<std::string>{"input1", "input2"})); // Multi-receiver port (e.g., HolovizOp's "receivers") auto stream_cond_any = make_condition<CudaStreamCondition>( "cuda_sync", Arg("receivers", "receivers")); // finds receivers:0, receivers:1, etc. // Check only first message per receiver auto stream_cond_first = make_condition<CudaStreamCondition>( "cuda_sync", Arg("receivers", "input"), Arg("check_all_messages", false)); auto my_op = make_operator<MyOperator>("my_op", stream_cond);
Public Functions
-
template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<::holoscan::Condition, std::decay_t<ArgT>> && (std::is_same_v<::holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<::holoscan::ArgList, std::decay_t<ArgT>>)>>
inline explicit CudaStreamCondition(ArgT &&arg, ArgsT&&... args)
-
CudaStreamCondition() = default
-
virtual void setup(ComponentSpec &spec) override
Define the condition specification.
- Parameters
spec – The reference to the component specification.
-
virtual void initialize() override
Initialize the component.
This method is called only once when the component is created for the first time, and use of light-weight initialization.
-
virtual void update_state(int64_t timestamp) override
Checks if the state of the condition can be updated and updates it.
- Parameters
timestamp – The current timestamp
-
virtual void check(int64_t timestamp, SchedulingStatusType *type, int64_t *target_timestamp) const override
Check the condition status before allowing execution.
If the condition is waiting for a time event ‘target_timestamp’ will contain the target timestamp.
- Parameters
timestamp – The current timestamp
status_type – The status of the condition
target_timestamp – The target timestamp (used if the term is waiting for a time event).
-
virtual void on_execute(int64_t timestamp) override
Called each time after the entity of this term was executed.
- Parameters
timestamp – The current timestamp
Set receiver for this condition (legacy single-port API)
-
inline std::shared_ptr<Receiver> receiver()
Get the receiver for this condition (nullptr if not set)
Set receivers for this condition (for all input ports to monitor)
-
inline std::vector<std::shared_ptr<Receiver>> receivers()
Get the receivers for this condition (empty vector if not set)
-
inline void check_all_messages(bool value)
Set whether to check all messages in the queue.
-
inline bool check_all_messages() const
Get whether to check all messages in the queue.