Holoscan SDK v4.0.0

Program Listing for File cuda_stream.hpp

Return to documentation for file (include/holoscan/core/conditions/gxf/cuda_stream.hpp)

Copy
Copied!
            

/* * SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HOLOSCAN_CORE_CONDITIONS_GXF_CUDA_STREAM_HPP #define HOLOSCAN_CORE_CONDITIONS_GXF_CUDA_STREAM_HPP #include <cuda_runtime_api.h> #include <gxf/core/gxf.h> #include <atomic> #include <memory> #include <string> #include <utility> #include <vector> #include <gxf/std/receiver.hpp> #include "../../component_spec.hpp" #include "../../condition.hpp" #include "../../resources/gxf/receiver.hpp" namespace holoscan { class CudaStreamCondition : public Condition { public: HOLOSCAN_CONDITION_FORWARD_ARGS(CudaStreamCondition) CudaStreamCondition() = default; void setup(ComponentSpec& spec) override; void initialize() override; void update_state(int64_t timestamp) override; void check(int64_t timestamp, SchedulingStatusType* type, int64_t* target_timestamp) const override; void on_execute(int64_t timestamp) override; void receiver(std::shared_ptr<Receiver> receiver) { receiver_ = std::move(receiver); } std::shared_ptr<Receiver> receiver() { return receiver_.has_value() ? receiver_.get() : nullptr; } void receivers(std::vector<std::shared_ptr<Receiver>> receivers) { receivers_ = std::move(receivers); } std::vector<std::shared_ptr<Receiver>> receivers() { return receivers_.has_value() ? receivers_.get() : std::vector<std::shared_ptr<Receiver>>{}; } void check_all_messages(bool value) { check_all_messages_ = value; } bool check_all_messages() const { return check_all_messages_.get(); } private: enum class State { UNSET, CALLBACKS_REGISTERED, DATA_AVAILABLE }; struct CallbackData { CudaStreamCondition* condition; }; static void CUDART_CB cuda_host_callback(void* user_data); void register_callbacks_for_receivers(); void register_callbacks_for_single_receiver(nvidia::gxf::Receiver* gxf_recv, gxf_context_t gxf_context, size_t& streams_found); void* get_gxf_context() const; std::vector<std::shared_ptr<Receiver>> get_all_receivers() const; Parameter<std::shared_ptr<Receiver>> receiver_; Parameter<std::vector<std::shared_ptr<Receiver>>> receivers_; Parameter<bool> check_all_messages_; std::atomic<State> state_{State::UNSET}; std::atomic<size_t> pending_callbacks_{0}; int64_t last_state_change_{0}; }; } // namespace holoscan #endif/* HOLOSCAN_CORE_CONDITIONS_GXF_CUDA_STREAM_HPP */

© Copyright 2022-2026, NVIDIA. Last updated on Apr 1, 2026