Extra delay when copying UMat to Mat

asked 2018-01-26 12:57:22 -0600

alex001 gravatar image

updated 2018-01-27 07:41:37 -0600

Hello,

I am trying to speed up my code using UMats and I encountered the following weird issue:

The Code:

Mat image = imread("/tmp/lenna_2048.png", IMREAD_COLOR);

UMat workMat2 = image.getUMat(ACCESS_READ);

UMat workMat = UMat::zeros(image.size(), CV_8UC1);


for (int i = 0; i < 10; i++) {

    cvtColor(workMat2, workMat, COLOR_RGB2GRAY);
}

auto start_time = std::chrono::high_resolution_clock::now();
Mat output;
workMat.copyTo(output);

double copy_time = static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count());
LOG4CXX_INFO(cwLogger, "copy_time " << copy_time);

The results:

Using lenna_2048.png (2048x2048):

i < 10; copy_time = 31ms

i < 20, copy_time = 52ms

i < 100, copy_time = 223ms

If using lenna_512.png (512x512):

i < 10; copy_time = 0ms

i < 20, copy_time = 0ms

i < 100, copy_time = 0ms

i < 1000, copy_time = 0ms


The GPU: 32-bit--Intel--Intel_R__HD_Graphics_Haswell_Ultrabook_GT2_Mobile--1_3 OpenCL: OpenCL C 1.2 beignet 1.3

I tried opencv version 3.4, 3.3.1, 3.2, etc. I tried different intel computer and even an nvidia machine and I get the same results.

It looks like the more I call the same operation, the bigger the time to copy the output (same size) takes. Am I misunderstanding something here ?


edit: removed unnecessary code from the example

edit retag flag offensive close merge delete

Comments

take a look at Transparent API samples and read the article OpenCV Transparent API

sturkmen gravatar imagesturkmen ( 2018-01-27 07:38:31 -0600 )edit