Why it's so slow in data exchanging between CPU and GPU memory?

asked 2015-03-22 22:12:37 -0600

rossi_lhf gravatar image

It's my first time using openCL on ARM(CPU:Qualcomm Snapdragon MSM8930, GPU:Adreno(TM)305).

I find using openCL is really very effective, but data exchanging between CPU and GPU takes too much time, as much as I can't imaging.

Here is an example:

cv::Mat mat(640,480,CV_8UC3,cv::Scalar(0,0,0));
cv::ocl::oclMat mat_ocl;

//cpu->gpu
mat_ocl.upload(mat);
//gpu->cpu
mat = (cv::Mat)mat_ocl;

Just a small image like this, the upload option takes 10ms, and download option takes 20ms! That takes too long.

Can anyone could tell me is this situation normal? Or something goes wrong here?

Thank you in advance!

edit retag flag offensive close merge delete

Comments

Did you test your code in a loop? Normally it takes some time to allocate memory on GPU. Once this is done it should be faster next time. So you should avoid reallocate the memory each time. I'm using OpenCV3 so I can't give you more help. Isn't there a funciton mat_ocl.download(mat) to transfer data back to CPU?

matman gravatar imagematman ( 2015-03-23 15:03:01 -0600 )edit

Yes, I test the time cost in loops. so the time is actually average time. And I found the 1st uploading costs almost the same time with the 2nd or 3rd uploading, I dont know why. "mat_ocl.download(mat) " is equal to "mat = (Mat)mat_ocl", they are the same operation.

rossi_lhf gravatar imagerossi_lhf ( 2015-03-23 20:56:41 -0600 )edit

@rossi_lhf: I see you struggled with OpenCL as reported here http://answers.opencv.org/question/25... but you already seem to be up and running here. May I ask you what was the problem and how did you solve it? I would like to get the Embedded profile running...

Kozuch gravatar imageKozuch ( 2015-04-23 05:45:14 -0600 )edit