create git commit message "diff --git a/segmentationtrt/src/segmentator.cpp…
- User
create git commit message "diff --git a/segmentation_trt/src/segmentator.cpp b/segmentation_trt/src/segmentator.cpp index 887c91ed..8e4651dc 100644 --- a/segmentation_trt/src/segmentator.cpp +++ b/segmentation_trt/src/segmentator.cpp @@ -125,6 +125,7 @@ void Segmentator::initialize(const vision::Parameters ¶ms) cv::Scalar(4, 0, 128), //red (solid) cv::Scalar(0, 0, 64)}; //red (double solid) memoryAlloc();
- getDevicePointer(); }
std::vectorcv::Mat Segmentator::process(std::vectorcv::Mat &frames) @@ -132,11 +133,21 @@ std::vectorcv::Mat Segmentator::process(std::vectorcv::Mat &frames) std::vectorcv::Mat masksOut; masksOut.reserve(frames.size()); int imgNum {0};
- //enable mapped memory support
- cudaSetDeviceFlags(cudaDeviceMapHost);
- cudaStream_t stream;
- NV_CUDA_CHECK(cudaStreamCreate(&stream));
- //creating CUDA Events
- cudaEvent_t startEvent, stopEvent;
- NV_CUDA_CHECK(cudaEventCreate(&startEvent));
- NV_CUDA_CHECK(cudaEventCreate(&stopEvent));
- for(cv::Mat& image : frames) {
-
code
cudaStream_t stream; //resize input image to the size required by neural net -
code
cv::Mat image_resized(h_, w_, CV_8UC3, input_);
-
code
cv::Mat image_resized(h_, w_, CV_8UC3, deviceInput_); if (up_crop_ != 0) { std::int16_t cropRows = image.rows - up_crop_;
@@ -149,31 +160,34 @@ std::vectorcv::Mat Segmentator::process(std::vectorcv::Mat &frames) cv::resize(image, image_resized, cv::Size(w_, h_)); }
-
code
NV_CUDA_CHECK(cudaStreamCreate(&stream));
-
code
- Assistant
Add zero-copy GPU memory mapping and CUDA event timing in Segmentator
- Enabled CUDA mapped memory support with
cudaSetDeviceFlags(cudaDeviceMapHost) - Added
getDevicePointer()method to obtain device pointers for host memory buffers - Updated buffer pointers to use device pointers (
deviceInput_,deviceInputCf_,deviceOutputRaw_,deviceOutputMask_) - Created a single CUDA stream and CUDA events (
startEvent,stopEvent) to measure kernel + zero-copy processing time - Inserted CUDA event recording before and after GPU processing calls, and printed elapsed time in milliseconds
- Ensured proper destruction of CUDA events and stream after processing
- Replaced multiple stream creations/destructions with streamlined single stream usage
This improves memory handling by leveraging zero-copy mapped memory for GPU processing and adds detailed timing instrumentation.
- Enabled CUDA mapped memory support with
- User
- Assistant