Program Listing for File cuda_stream_handler.hpp
↰ Return to documentation for file (include/holoscan/utils/cuda_stream_handler.hpp
)
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2024 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 INCLUDE_HOLOSCAN_UTILS_CUDA_STREAM_HANDLER_HPP
#define INCLUDE_HOLOSCAN_UTILS_CUDA_STREAM_HANDLER_HPP
#include <memory>
#include <vector>
#include "../core/operator_spec.hpp"
#include "../core/parameter.hpp"
#include "../core/resources/gxf/cuda_stream_pool.hpp"
#include "gxf/cuda/cuda_stream.hpp"
// keep the following two gxf/cuda imports in the header for backwards compatibility with 1.0
#include "gxf/cuda/cuda_stream_id.hpp"
#include "gxf/cuda/cuda_stream_pool.hpp"
namespace holoscan {
class CudaStreamHandler {
public:
~CudaStreamHandler();
void define_params(OperatorSpec& spec, bool required = false);
void defineParams(OperatorSpec& spec, bool required = false);
gxf_result_t from_message(gxf_context_t context,
const nvidia::gxf::Expected<nvidia::gxf::Entity>& message);
gxf_result_t fromMessage(gxf_context_t context,
const nvidia::gxf::Expected<nvidia::gxf::Entity>& message);
gxf_result_t from_messages(gxf_context_t context,
const std::vector<holoscan::gxf::Entity>& messages);
gxf_result_t from_messages(gxf_context_t context,
const std::vector<nvidia::gxf::Entity>& messages);
gxf_result_t fromMessages(gxf_context_t context,
const std::vector<nvidia::gxf::Entity>& messages);
gxf_result_t to_message(nvidia::gxf::Expected<nvidia::gxf::Entity>& message);
gxf_result_t toMessage(nvidia::gxf::Expected<nvidia::gxf::Entity>& message);
nvidia::gxf::Handle<nvidia::gxf::CudaStream> get_stream_handle(gxf_context_t context);
nvidia::gxf::Handle<nvidia::gxf::CudaStream> getStreamHandle(gxf_context_t context);
cudaStream_t get_cuda_stream(gxf_context_t context);
cudaStream_t getCudaStream(gxf_context_t context);
private:
gxf_result_t allocate_internal_stream(gxf_context_t context);
gxf_result_t from_messages(gxf_context_t context, size_t message_count,
const nvidia::gxf::Entity* messages);
bool cuda_stream_pool_required_ = false;
Parameter<std::shared_ptr<CudaStreamPool>> cuda_stream_pool_;
bool default_stream_warning_ = false;
std::vector<cudaEvent_t> cuda_events_;
nvidia::gxf::Handle<nvidia::gxf::CudaStream> message_cuda_stream_handle_;
nvidia::gxf::Handle<nvidia::gxf::CudaStream> cuda_stream_handle_;
};
} // namespace holoscan
#endif/* INCLUDE_HOLOSCAN_UTILS_CUDA_STREAM_HANDLER_HPP */