Ask Your Question

cudaMem in CPU functions

asked 2012-12-19 05:33:45 -0500

I am trying to improve the performance of a few of my functions to take advantage of async memory copies. I have a Mat that I apply a number of operations to on the CPU and then I upload it to a GpuMat. If I create it as a cv::gpu::cudaMem rather than a cv::Mat the CPU functions stop working as they are expecting a cv::Mat. Is there a way of using cudaMems as inputs into normal CPU functions which will then allow me to copy the results asynchronously to the GPU when required. I know I could do an intermediate memcopy from to but this seems like a less efficient way to work.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2012-12-19 05:41:12 -0500

Vladislav Vinogradov gravatar image

CudaMem has can be implicitly converted to Mat object

CudaMem cm(100, 100, CV_8UC1);
Mat mat_hdr = cm;

This operation doesn't copy data, it just create Mat header for CudaMem data.

edit flag offensive delete link more


Superb. Thank you.

iaincarrie gravatar imageiaincarrie ( 2012-12-19 11:26:57 -0500 )edit

answered 2013-01-30 11:04:51 -0500

Ikarus79 gravatar image

updated 2013-01-30 11:05:58 -0500

Hello guys,

I'm quite new in Cuda programming as well. For me it's still quite unclear how to use the CudaMem class. for example how I can do following using page_locked or even zero_copy memory:

Mat srcCpu3ChImg;
Mat outCpu4ChImg;

GpuMat srcGpu3ChImg;
GpuMat outGpu4ChImg;

// load srcCpu3ChImg

cv::gpu::cvtColor(srcGpu3ChImg, outGpu4ChImg, CV_BGR2BGRA);;

thank you a lot in advance cheers greg

edit flag offensive delete link more

Question Tools


Asked: 2012-12-19 05:33:45 -0500

Seen: 861 times

Last updated: Jan 30 '13