findContours call using Multi-threaded CUDA application

Hi Guys,

I am trying to use findContours on CUDA processed images. I am trying to achieve this in two separate threads running concurrently. When I try to do the same I am getting Segmentation fault. Please find the code below :

void functionCalledFirst(Mat &img)

void runCUDA(Mat &img)

	int fsize = 2048*1080;

	cudaMallocManaged(&m_dbuffer, fsize);

	cudaMallocManaged(&m_dcudaout, fsize);

	cudaMemcpy (m_dbuffer,(char * ),fsize,cudaMemcpyHostToDevice) 

	runCudaKernel(m_dcudaout , dbuffer); // binary output

	cv::Mat cudaOutMat = cv::Mat(img.rows,img.cols, CV_8UC1, (void *) m_dcudaout , 2048);

	findContours(cudaOutMat, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );


When I comment out findContours the code runs without crashing. Please help me figure out what the problem could be ?



Could you share the complete source for us checking?

From your code, guess that there is a concurrent access on unified memory.
Please check our document for details: