Skip to content

Commit

Permalink
Update the CUDA stream handler includes and function names. (nvidia-h…
Browse files Browse the repository at this point in the history
…oloscan#266)

We don't update the method names in:
   gxf_extensions/utils/cuda_stream_handler.hpp

This is because the method names are used in codelets
(under 'gxf_extensions') and GXF is using camel case for
method names.

Signed-off-by: Gigon Bae <gbae@nvidia.com>
Signed-off-by: Rony Rado <rrado@nvidia.com>
  • Loading branch information
gigony authored Aug 15, 2024
1 parent 2f2ef5b commit 587dbc1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
8 changes: 4 additions & 4 deletions operators/npp_filter/npp_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void NppFilterOp::setup(OperatorSpec& spec) {
spec.input<holoscan::gxf::Entity>("input");
spec.output<holoscan::gxf::Entity>("output");

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);
}

void NppFilterOp::compute(InputContext& op_input, OutputContext& op_output,
Expand All @@ -86,13 +86,13 @@ void NppFilterOp::compute(InputContext& op_input, OutputContext& op_output,
auto& entity = static_cast<nvidia::gxf::Entity&>(maybe_entity.value());

// get the CUDA stream from the input message
gxf_result_t stream_handler_result = cuda_stream_handler_.fromMessage(context.context(), entity);
gxf_result_t stream_handler_result = cuda_stream_handler_.from_message(context.context(), entity);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}

// assign the CUDA stream to the NPP stream context
npp_stream_ctx_->hStream = cuda_stream_handler_.getCudaStream(context.context());
npp_stream_ctx_->hStream = cuda_stream_handler_.get_cuda_stream(context.context());

nvidia::gxf::VideoBufferInfo in_video_buffer_info{};
void* in_pointer;
Expand Down Expand Up @@ -286,7 +286,7 @@ void NppFilterOp::compute(InputContext& op_input, OutputContext& op_output,
}

// pass the CUDA stream to the output message
stream_handler_result = cuda_stream_handler_.toMessage(out_message);
stream_handler_result = cuda_stream_handler_.to_message(out_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to add the CUDA stream to the outgoing messages");
}
Expand Down
8 changes: 4 additions & 4 deletions operators/orsi/orsi_format_converter/format_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ void FormatConverterOp::compute(InputContext& op_input, OutputContext& op_output

// get the CUDA stream from the input message
gxf_result_t stream_handler_result =
cuda_stream_handler_.fromMessage(context.context(), in_message);
cuda_stream_handler_.from_message(context.context(), in_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}

// assign the CUDA stream to the NPP stream context
npp_stream_ctx_.hStream = cuda_stream_handler_.getCudaStream(context.context());
npp_stream_ctx_.hStream = cuda_stream_handler_.get_cuda_stream(context.context());

nvidia::gxf::Shape out_shape{0, 0, 0};
void* in_tensor_data = nullptr;
Expand Down Expand Up @@ -479,7 +479,7 @@ void FormatConverterOp::compute(InputContext& op_input, OutputContext& op_output
}

// pass the CUDA stream to the output message
stream_handler_result = cuda_stream_handler_.toMessage(out_message);
stream_handler_result = cuda_stream_handler_.to_message(out_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to add the CUDA stream to the outgoing messages");
}
Expand Down Expand Up @@ -934,7 +934,7 @@ void FormatConverterOp::setup(OperatorSpec& spec) {

spec.param(allocator_, "allocator", "Allocator", "Output Allocator");

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);

// TODO (gbae): spec object holds an information about errors
// TODO (gbae): incorporate std::expected to not throw exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void SegmentationPostprocessorOp::setup(OperatorSpec& spec) {
"Output image size after resize",
"Output image size [ width, height ] after resize");

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);

// TODO (gbae): spec object holds an information about errors
// TODO (gbae): incorporate std::expected to not throw exceptions
Expand Down Expand Up @@ -115,7 +115,7 @@ void SegmentationPostprocessorOp::compute(InputContext& op_input, OutputContext&

// get the CUDA stream from the input message
gxf_result_t stream_handler_result =
cuda_stream_handler_.fromMessage(context.context(), in_message);
cuda_stream_handler_.from_message(context.context(), in_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}
Expand Down Expand Up @@ -213,7 +213,7 @@ void SegmentationPostprocessorOp::compute(InputContext& op_input, OutputContext&
shape,
in_tensor_data,
post_process_output_buffer,
cuda_stream_handler_.getCudaStream(context.context()));
cuda_stream_handler_.get_cuda_stream(context.context()));

if (roi_enabled) {
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -264,7 +264,7 @@ void SegmentationPostprocessorOp::compute(InputContext& op_input, OutputContext&
}

// pass the CUDA stream to the output message
stream_handler_result = cuda_stream_handler_.toMessage(out_message);
stream_handler_result = cuda_stream_handler_.to_message(out_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to add the CUDA stream to the outgoing messages");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void SegmentationPreprocessorOp::setup(OperatorSpec& spec) {

spec.param(allocator_, "allocator", "Allocator", "Output Allocator");

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);

// TODO (gbae): spec object holds an information about errors
// TODO (gbae): incorporate std::expected to not throw exceptions
Expand All @@ -133,7 +133,7 @@ void SegmentationPreprocessorOp::compute(InputContext& op_input, OutputContext&
auto in_tensor = getTensorByName(in_message, in_tensor_name);
// get the CUDA stream from the input message
gxf_result_t stream_handler_result =
cuda_stream_handler_.fromMessage(context.context(), in_message);
cuda_stream_handler_.from_message(context.context(), in_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}
Expand Down Expand Up @@ -190,7 +190,7 @@ void SegmentationPreprocessorOp::compute(InputContext& op_input, OutputContext&
stds_cuda_);

// pass the CUDA stream to the output message
stream_handler_result = cuda_stream_handler_.toMessage(out_message);
stream_handler_result = cuda_stream_handler_.to_message(out_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to add the CUDA stream to the outgoing messages");
}
Expand Down
4 changes: 2 additions & 2 deletions operators/orsi/orsi_visualizer/orsi_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void OrsiVisualizationOp::setup(OperatorSpec& spec) {

pimpl_->setup(spec);

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);
}

void OrsiVisualizationOp::initialize() {
Expand Down Expand Up @@ -251,7 +251,7 @@ void OrsiVisualizationOp::compute(InputContext& op_input, OutputContext& op_outp
}

// get the CUDA stream from the input message
const gxf_result_t result = cuda_stream_handler_.fromMessages(context.context(), messages);
const gxf_result_t result = cuda_stream_handler_.from_messages(context.context(), messages);
if (result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}
Expand Down
11 changes: 6 additions & 5 deletions operators/qt_video/qt_video_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void QtVideoOp::setup(holoscan::OperatorSpec& spec) {
"Pointer to the QtHoloscanVideo object.",
(QtHoloscanVideo*)nullptr);

cuda_stream_handler_.defineParams(spec);
cuda_stream_handler_.define_params(spec);
}

void QtVideoOp::start() {
Expand All @@ -98,13 +98,13 @@ void QtVideoOp::compute(holoscan::InputContext& op_input, holoscan::OutputContex
auto& entity = static_cast<nvidia::gxf::Entity&>(maybe_entity.value());

// get the CUDA stream from the input message
gxf_result_t stream_handler_result = cuda_stream_handler_.fromMessage(context.context(), entity);
gxf_result_t stream_handler_result = cuda_stream_handler_.from_message(context.context(), entity);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}

// record a CUDA event, the render later will synchronize the rendering using that event
CUDA_TRY(cudaEventRecord(cuda_event_, cuda_stream_handler_.getCudaStream(context.context())));
CUDA_TRY(cudaEventRecord(cuda_event_, cuda_stream_handler_.get_cuda_stream(context.context())));

// Get the input data, both VideoBuffer and Tensor is supported. We collect the buffer info
// in the `video_buffer_info` structure
Expand Down Expand Up @@ -182,15 +182,16 @@ void QtVideoOp::compute(holoscan::InputContext& op_input, holoscan::OutputContex
qt_holoscan_video_->processBuffer(pointer, video_buffer_info, cuda_event_);

// Synchronize with the event recorded by the renderer
CUDA_TRY(cudaStreamWaitEvent(cuda_stream_handler_.getCudaStream(context.context()), cuda_event_));
CUDA_TRY(
cudaStreamWaitEvent(cuda_stream_handler_.get_cuda_stream(context.context()), cuda_event_));

// Add the CUDA stream we used to the event to allow synchrinization when freeing the memory
const auto maybe_stream_id = entity.add<nvidia::gxf::CudaStreamId>();
if (!maybe_stream_id) {
throw std::runtime_error("Failed to add CUDA stream id to output message.");
}
maybe_stream_id.value()->stream_cid =
cuda_stream_handler_.getStreamHandle(context.context()).cid();
cuda_stream_handler_.get_stream_handle(context.context()).cid();
}

} // namespace holoscan::ops
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ToolTrackingPostprocessorOp::compute(InputContext& op_input, OutputContext&

// get the CUDA stream from the input message
gxf_result_t stream_handler_result =
cuda_stream_handler_.fromMessage(context.context(), in_message);
cuda_stream_handler_.from_message(context.context(), in_message);
if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to get the CUDA stream from incoming messages");
}
Expand All @@ -114,7 +114,7 @@ void ToolTrackingPostprocessorOp::compute(InputContext& op_input, OutputContext&
probs_tensor->data(),
probs_tensor->nbytes(),
cudaMemcpyDeviceToHost,
cuda_stream_handler_.getCudaStream(context.context())));
cuda_stream_handler_.get_cuda_stream(context.context())));

maybe_tensor = in_message.get<Tensor>("scaled_coords");
if (!maybe_tensor) { throw std::runtime_error("Tensor 'scaled_coords' not found in message."); }
Expand All @@ -125,7 +125,7 @@ void ToolTrackingPostprocessorOp::compute(InputContext& op_input, OutputContext&
scaled_coords_tensor->data(),
scaled_coords_tensor->nbytes(),
cudaMemcpyDeviceToHost,
cuda_stream_handler_.getCudaStream(context.context())));
cuda_stream_handler_.get_cuda_stream(context.context())));

maybe_tensor = in_message.get<Tensor>("binary_masks");
if (!maybe_tensor) { throw std::runtime_error("Tensor 'binary_masks' not found in message."); }
Expand All @@ -138,7 +138,7 @@ void ToolTrackingPostprocessorOp::compute(InputContext& op_input, OutputContext&
std::vector<uint32_t> visible_classes;
{
// wait for the CUDA memory copy to finish
CUDA_TRY(cudaStreamSynchronize(cuda_stream_handler_.getCudaStream(context.context())));
CUDA_TRY(cudaStreamSynchronize(cuda_stream_handler_.get_cuda_stream(context.context())));

std::vector<float> filtered_scaled_coords;
for (size_t index = 0; index < probs.size(); ++index) {
Expand Down Expand Up @@ -207,13 +207,14 @@ void ToolTrackingPostprocessorOp::compute(InputContext& op_input, OutputContext&
first,
static_cast<float*>(binary_masks_tensor->data()) + index * layer_size,
reinterpret_cast<float4*>(out_data),
cuda_stream_handler_.getCudaStream(context.context()));
cuda_stream_handler_.get_cuda_stream(context.context()));
first = false;
}
}

// pass the CUDA stream to the output message
stream_handler_result = cuda_stream_handler_.toMessage(out_message_device);
stream_handler_result = cuda_stream_handler_.to_message(out_message_device);

if (stream_handler_result != GXF_SUCCESS) {
throw std::runtime_error("Failed to add the CUDA stream to the outgoing messages");
}
Expand Down

0 comments on commit 587dbc1

Please sign in to comment.