Ask Your Question
0

opencv performance in using opencl

asked 2017-01-11 15:46:34 -0600

babak12345 gravatar image

I'm programming in C++ using OpenCV 3.1.0. Also I'm new in OpenCV. I want to use OpenCL. Here is my code:

int _tmain(int argc, _TCHAR* argv[])
{
    clock_t t1, t2;
    Mat image;
    image = imread("...//myPic.jpg", CV_LOAD_IMAGE_GRAYSCALE);   // Read the file
    UMat u = image.getUMat(ACCESS_FAST);

    // calculating time with OpenCL
    cv::ocl::setUseOpenCL(true);
    t1 = clock();
    for (int i = 0; i < 1000; i++)
    {
        cv::Canny(u, u, 100, 50);
    }
    t2 = clock();

    // showing time with OpenCL
    double diff = ((double)t2 - (double)t1) / CLOCKS_PER_SEC;
    cout << "Running time with OpenCL: " << diff << endl;

    /////////////////////////////////////////////////////

    // calculating time with OpenCL
    cv::ocl::setUseOpenCL(false);
    t1 = clock();
    for (int i = 0; i < 1000; i++)
    {
        cv::Canny(u, u, 100, 50);
    }
    t2 = clock();

    // showing time with OpenCL
    diff = ((double)t2 - (double)t1) / CLOCKS_PER_SEC;
    cout << "Running time without OpenCL: " << diff << endl;

    getchar();

    return 0;
}

Here is the result of running code in my laptop.

Running time with OpenCL: 5.565
Running time without OpenCL: 2.441

As it is expected first value must be less than second one significantly but it is not. I test OpenCl technology using EmguCV 3.1 ( it is a wrapper for opencv) in C# and the result test show that it is 40 times faster than when I do not use OpenCl.

System info: Windows 8.1
Core i7 2.2GHz (2670QM)
Amd Radeon Graphic card (HD 6700M)
8GB RAM

Why the time with OpenCL is not what It should be expected?

edit retag flag offensive close merge delete

Comments

with your program my results are :

Running time with OpenCL: 2.066
Running time without OpenCL: 23.888
LBerger gravatar imageLBerger ( 2017-01-11 16:09:19 -0600 )edit

It is amazing! I get result like yours using EmguCV

babak12345 gravatar imagebabak12345 ( 2017-01-11 16:35:59 -0600 )edit

How can I check my environmental variables are set correctly?

babak12345 gravatar imagebabak12345 ( 2017-01-11 16:48:21 -0600 )edit

Did you compile OpenCV yourself or use an installer?

Tetragramm gravatar imageTetragramm ( 2017-01-11 20:22:11 -0600 )edit

Maybe the OpenCL code is runned on the Intel integrated GPU, if this CPU has one?

Eduardo gravatar imageEduardo ( 2017-01-12 15:41:36 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2017-01-12 10:58:40 -0600

pklab gravatar image

Questions/answer

  1. What if using 2 different UMat like Canny(u, v, 100, 50); (Optimize memory transfers and initialization) ?
  2. What if Canny is called once before t1 = clock(); (OpenCL kernels initialization) ?

Here my results (Win7x64/OCV3.1x64/AMD Radeon6370)

                            | Your code | +Point 1  | +Point 2 |
----------------------------+-----------+-----------+----------+
Running time with OpenCL:   |    9.936  |   1.011   |   0.141  |
Running time without OpenCL:|   13.819  |  25.906   |  11.143  |

finally, collect info about your OpenCV and OpenCL

//INFO ABOUT OpenCV BUILD
cout << getBuildInformation();
// INFO ABOUT OpenCL
cout << "OpenCL: " << endl;
std::vector<ocl::PlatformInfo> platform_info;
cv::ocl::getPlatfomsInfo(platform_info);
for (size_t i = 0; i < platform_info.size(); i++)
{
    cout
        << "\tName: " << platform_info[i].name() << endl
        << "\tVendor: " << platform_info[i].vendor() << endl
        << "\tVersion: " << platform_info[i].version() << endl
        << "\tDevice Number: " << platform_info[i].deviceNumber() << endl
        << endl;
}

and compare them with your EmguCV

edit flag offensive delete link more

Comments

And how to select particular opencl device that will be used by the opencv functions?

pi-null-mezon gravatar imagepi-null-mezon ( 2017-01-13 09:07:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-11 15:46:34 -0600

Seen: 2,904 times

Last updated: Jan 12 '17