Ask Your Question
0

cudaMem in CPU functions

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

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 Mat.data to cudaMem.data 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
0

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

Vladislav Vinogradov gravatar image

CudaMem has can be implicitly converted to Mat object

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

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

edit flag offensive delete link more

Comments

Superb. Thank you.

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

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

Ikarus79 gravatar image

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

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

srcGpu3ChImg.upload(srcCpu3ChImg);
cv::gpu::cvtColor(srcGpu3ChImg, outGpu4ChImg, CV_BGR2BGRA);
outGpu4ChImg.download(outCpu4ChImg);

thank you a lot in advance cheers greg

edit flag offensive delete link more

Question Tools

Stats

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

Seen: 1,099 times

Last updated: Jan 30 '13