0

I am using OpenCV 3.4 with cuda libraries to process video images. Image is grabbed and uploaded over the device using GpuMat::upload(). Afterward the image is thresholded twice to create 2 different binary images (Th1 and Th2). My first question is that: Can I use cuda streams in both threshold functions to run at the same time? Is that a problem since they are both using the same GpuMat as input.

After the thresholding I will be using both binary GpuMats to do more processing on them using other cv::cuda functions. The second question is: Should I use Stream::waitForCompletion() to wait for the thresholding streams to be finished before using Th1 and Th2 for further processing? or this data dependency is automatically detected? basically I am trying to process this 2 binary images from here in parallel, not to process first Th1 and then th2. They are going to be processed exactly with similar cuda functions but with different values..

I am using cuda 9.0. Is it still a problem if same operation is enqueued twice with different data to different streams?

an example of my code is shown below:

src.upload(IMG); //upload cv::Mat to device

//threashold src with different values and write them in dst0 and dst1
// Can I have 2 stream on the same functions that are both using src as input?
cv::cuda::threshold(src, dst0, 10, 1, THRESH_BINARY, s0); //Stream s0 
cv::cuda::threshold(src, dst1, 40, 1, THRESH_BINARY, s1); // Stream S1

s0.waitForCompletion();// I dont know if this is necessary 
cv::cuda::reduce(dst0, Vx0, 0, CV_REDUCE_SUM, CV_32S);


s1.waitForCompletion();// also this one
cv::cuda::reduce(dst1, Vx1, 0, CV_REDUCE_SUM, CV_32S);
talonmies
  • 70,661
  • 34
  • 192
  • 269
Ali Nouri
  • 67
  • 7
  • 1
    I'd say if input is read-only and outputs are separate images (does not share memory) it is safe. Also you can just use stream-per-image design. So for example if you process `dst0` do it always with `s0`. In your case just pass `s0` to your `reduce` call. – michelson Jan 17 '19 at 13:53
  • So any device process belonging to same stream (lets say s0 like your example) will be sequential? – Ali Nouri Jan 17 '19 at 14:20
  • Calls issued to the same stream are sequential - https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#streams – michelson Jan 17 '19 at 14:43

0 Answers0