OpenCVs OpenCL doesn´t find any device but the code executed with UMAT runs faster

asked 2017-04-28 00:33:50 -0600

TADRIAN gravatar image

updated 2017-04-28 00:35:45 -0600

Hello together,

I recently started trying to use OpenCVs OpenCL. By executing following code but i´m not able to find any device (cv::ocl::haveOpenCL() returns true).

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;
}

So I thought OpenCL isn´t set-up correctly so I tried it with the "normal OpenCL" with following lines of code, which outputs the devices and platforms as expected: Output: http://img5.fotos-hochladen.net/uploa...

std::vector<cl::Platform> all_platforms;
cl::Platform::get(&all_platforms);
if (all_platforms.size() == 0) {
    std::cout << " No platforms found. Check OpenCL installation!\n";
}
else
{
    std::cout << "################################################################" << endl;
    std::cout << "################## Verfuegbare Hardware ########################" << endl;
    std::cout << "################################################################" << endl;
    for (int i = 0; i < all_platforms.size(); i++)
    {
        std::cout << "Platform " << i+1 << ": " << all_platforms[i].getInfo<CL_PLATFORM_NAME>() << "\n";
        std::cout << "Platform version: " << all_platforms[i].getInfo<CL_PLATFORM_VERSION>() << "\n";

        //get default device of the default platform
        std::vector<cl::Device> all_devices;
        all_platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
        if (all_devices.size() == 0) {
            std::cout << " No devices found. Check OpenCL installation!\n";
        }
        else
        {
            for (int j = 0; j < all_devices.size(); j++)
            {
                cl::Device default_device = all_devices[j];
                std::cout << "Device " << j+1 << ": " << default_device.getInfo<CL_DEVICE_NAME>() << "\n";
            }
        }
        std::cout << "___________________________________________" << endl;
    }
}

After that I tried to use the OpenCVs OpenCL nevertheless by executing a comparison between UMat Canny and Mat Canny, the UMat Canny runs much faster. Now i´m quite confused why it works and on which device and platform it runs? I hope someone can clarify whats going on :D

i appreciate your help. Thanks

edit retag flag offensive close merge delete

Comments

"I thought OpenCL isn´t set-up" No if my memory is good opencl is initialized at first function call. When you run first code there is no call to opencl function like blur add.....

About canny now source code is optimized read this post. It is important to understand that opencl is better than CPU if image size is larger. What is image size?

You can try this code too to test opencl

LBerger gravatar imageLBerger ( 2017-04-28 02:08:33 -0600 )edit

I think the Canny-function I used with Umat runs on the GPU (excecution time went down and the CPU workload went down in comparison to the Mat Canny call) But i´m quite confused why, because running the codeexample 1 from my post outputs no devices. When trying your Codeexample i got following error at the code part: error: http://img5.fotos-hochladen.net/uploa... codepart:
case (1 << 2): cout << " GPU device\n"; if (context.create(deviceType)) // <--- errors

Thanks for your help

TADRIAN gravatar imageTADRIAN ( 2017-04-28 04:17:10 -0600 )edit

Im observing a similar behavior as well: If I use the nVidia-Tool for detecting OpenCL devices, three devices are shown on my laptop: CPU, Intel GPU and nVidia GPU. If I use the device search of OpenCV only the Intel GPU shows up on my work laptop and only the nVidia GPU shows up on my private laptop. Both laptops have nearly identical setups (i7-6820HQ with Quadro M100M and i7-4720HQ with GTX960M).

theaniolad gravatar imagetheaniolad ( 2017-04-28 04:29:21 -0600 )edit

Have you build opencv with cuda?

LBerger gravatar imageLBerger ( 2017-04-28 04:55:44 -0600 )edit

No, I disbaled "with_cuda" in CMAKE

TADRIAN gravatar imageTADRIAN ( 2017-04-28 05:06:52 -0600 )edit

I have both a CUDA and a non-CUDA build and the same behavior and problems with both builds.

theaniolad gravatar imagetheaniolad ( 2017-04-28 08:44:26 -0600 )edit