Error in dowlaoding GpuMat to Mat

HI, I upload Mat to GpuMat and then change it by CUDA and the I download GpuMat to Mat. I do not have any problem with Mat up to size 1024x1024, but when my Mat is 2048x2048 I get a error after my CUDA code and in download GpuMat to Mat time!

error:

OpenCV(3.4.1) Error: Gpu API call (unspecified launch failure) in cv::cuda::GpuMat::download, file C:/OpenCV 3.4.1/opencv-3.4.1/modules/core/src/cuda/gpu_mat.cu, line 249

how can I solve it ?

Use standard CUDA debugging techniques.

Make sure you are not hitting a WDDM TDR.

Run your code with cuda-memcheck https://stackoverflow.com/questions/27277365/unspecified-launch-failure-on-memcpy/27278218#27278218

Use a cuda debugger appropriate for your platform.

Even though this occurs in some OpenCV code, the “download GpuMat to Mat” is occurring after your own kernel call, and the error is indicative of a problem in your kernel call, not in the OpenCV code. You may simply be hitting a wddm tdr.

Thank you so much.

this is my code :

GpuMat.upload(Mat);
MyCUDAKernel << <grid, block >> > ();
cudaDeviceSynchronize();
GpuMat.download(Mat);

The error is form GpuMat.download(Mat), because when I remove it the error not appear

Well, you didn’t do anything I suggested.

I have problem by visual studio cuda memcheck. I will do your suggestion. Thank you dear.

I did not get how I check cuda-memcheck in visual studio. But I think if I use cudaMemAllockPitch and cudaMemCpy2D for copy my Mat in Device and Host my problem will solved !

I think using cudaMemCpy2D solved my problem.

how can I copy a Mat to a GpuMat by cudaMemCpy2D ?

Thank you.