OpenCL: is it actually enabled?

asked 2017-04-27 14:45:15 -0600

mattyfog gravatar image

I'm trying to speed up the research of features of stitching algorithm using OpenCL. I'm using the code of the example provided here: https ://github.com/opencv/opencv/blob/master/samples/cpp/stitching_detailed.cpp I read online that the only thing I have to do is change Mat to Umat. I did it.

However I am not sure my code is actually using OpenCL.

  • First: I'm working on an Ubuntu 16.04 Virtual Machine using Parallels Desktop on a Macbook Pro. Therefore the only device supported by OpenCL will be the CPU (no GPU). I installed the correct drivers, sdk, etc and CPU should work correctly. You can see the result of command "clinfo" in Ubuntu shell below. Working with a CPU, I do not expect performance improvement. My plan is just to work my virtual machine and than deploy the code on a real Ubuntu machine.
  • Second: the code has no improvement (as expected, see above). Actually the required time seems to be the same. Is it right? I mean, I know I am working still on the CPU, but I expected to be some differences. Moreover looking at the call graph profiled with grof and gprof2dot there no differences (for ones who have never heard about gprof, it is simply a code profiler that can generate a call graph showing all calls among functions: which function calls what other function, and so on). Is it possible? OpenCV with and without OpenCL should call exactly the same function?

How can I be sure the code is actually working with OpenCL? I read online there were some bugs in features finding on OpenCL and therefore I would like to check myself. Moreover, obviously, I would like to work and edit the code, this is just the beginning.

I'm using this code to check if OpenCL is working:

void checkOpenCL() {

    if (!cv::ocl::haveOpenCL())
    {
        cout << "OpenCL is not available..." << endl;
        //return;
    }

    cv::ocl::Context context;
    if (!context.create(cv::ocl::Device::TYPE_ALL))
    {
        cout << "Failed creating the context..." << endl;
        //return;
    }

    cout << context.ndevices() << " CPU devices are detected." << endl; //This bit provides an overview of the OpenCL devices you have in your computer
    for (int i = 0; i < context.ndevices(); i++)
    {
        cv::ocl::Device device = context.device(i);
        cout << "name:              " << device.name() << endl;
        cout << "available:         " << device.available() << endl;
        cout << "imageSupport:      " << device.imageSupport() << endl;
        cout << "OpenCL_C_Version:  " << device.OpenCL_C_Version() << endl;
        cout << endl;
    }

    cv::ocl::Device(context.device(0)); //Here is where you change which GPU to use (e.g. 0 or 1)

}

And it prints:

1 CPU devices are detected.
name:              Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 1.2

Running clinfo in Ubuntu shell report

Number of platforms                               1
  Platform Name                                   Intel(R) OpenCL
  Platform Vendor                                 Intel(R) Corporation
  Platform Version                                OpenCL 1.2 LINUX
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_3d_image_writes cl_intel_exec_by_local_thread cl_khr_spir cl_khr_fp64 
  Platform Extensions function suffix             INTEL

  Platform Name                                   Intel(R) OpenCL
Number ...
(more)
edit retag flag offensive close merge delete

Comments

"I expected to be some differences" why ? you don't add any ressource on your system.

Try to setNumThreads to 1. disable opencl and measure time. Next enable opencl and measure time .

LBerger gravatar imageLBerger ( 2017-04-27 15:04:09 -0600 )edit

So also functions calls should be exactly the same? I speaking of the function used by OpenCV library, not about my functions

mattyfog gravatar imagemattyfog ( 2017-04-27 15:07:41 -0600 )edit

Yes functions are exactly same. But if you use UMat data are stored on GPU if GPU is activated. In your system I don't think it will make any difference (it could be worst).

LBerger gravatar imageLBerger ( 2017-04-27 15:16:18 -0600 )edit

Setting number of threads to 1 doubles the time both with using cv::ocl::setUseOpenCL() true or false. Any idea? Should it interfere with OpenCL too?

mattyfog gravatar imagemattyfog ( 2017-04-27 15:25:42 -0600 )edit

"doubles the time both" your processor is dual core?

May be my idea is wrong to test your configuration.

LBerger gravatar imageLBerger ( 2017-04-27 15:30:51 -0600 )edit

8 cores but I'm giving just 4 cores to the virtual machine. Actually it is not exactly the double, seems like 2.5x or 3x slower. However it happens both enabling / disabling opencl.

mattyfog gravatar imagemattyfog ( 2017-04-27 15:57:17 -0600 )edit