Ask Your Question

OpenCL can not detect my nVidia GPU via OpenCV

asked 2016-10-30 10:15:19 -0600

Humam Helfawi gravatar image

I have two GPUs : Intel HD and nVidia Quadro. Using GPU Caps Viewer, I can detect my both GPUs in the OpenCL tab. However, by executing this code I am only getting the Intel one:

if (!cv::ocl::haveOpenCL()) {
    std::cout << "OpenCL is not available..." << std::endl;
cv::ocl::Context context;
if (!context.create(cv::ocl::Device::TYPE_ALL)) {
    std::cout << "Failed creating the context..." << std::endl;
std::cout << context.ndevices() << " GPU devices are detected." << std::endl; 
for (int i = 0; i < context.ndevices(); i++) {
    cv::ocl::Device device = context.device(i);
    std::cout << "name:              " << << std::endl;
    std::cout << "available:         " << device.available() << std::endl;
    std::cout << "imageSupport:      " << device.imageSupport() << std::endl;
    std::cout << "OpenCL_C_Version:  " << device.OpenCL_C_Version() << std::endl;
    std::cout << std::endl;


1 GPU devices are detected.
name:              Intel(R) HD Graphics P530
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 2.0


  1. Windows 10
  2. OpenCV 3.1
  3. Visual studio 2013
  4. nVidia Quadro M4000M


  1. I am able to call my nVidia GPU directly using the OpenCV Cuda Interface
  2. I have just installed the latest driver from nVidia website.
edit retag flag offensive close merge delete


Does it make a difference if you call context.create(cv::ocl::Device::TYPE_GPU) instead of TYPE_ALL?

Tetragramm gravatar imageTetragramm ( 2016-10-30 15:24:32 -0600 )edit

I tried it. Same results

Humam Helfawi gravatar imageHumam Helfawi ( 2016-10-31 01:47:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-31 04:39:57 -0600

LBerger gravatar image

updated 2016-10-31 05:25:18 -0600

I think it's not possible in current implementation because nd= 1;

in function Impl(int dtype0) called by ocl::createContext

and opencv detect first one

[Try with] to check device in your system ( :

std::vector<cv::ocl::PlatformInfo> platforms;

//OpenCL Platforms
for (size_t i = 0; i < platforms.size(); i++)

//Access to Platform
const cv::ocl::PlatformInfo* platform = &platforms[i];

//Platform Name
std::cout << "Platform Name: " << platform->name().c_str() << "\n";

//Access Device within Platform
cv::ocl::Device current_device;
for (int j = 0; j < platform->deviceNumber(); j++)
    //Access Device
    platform->getDevice(current_device, j);

    //Device Type
    int deviceType = current_device.type();

It's difficult to test for me because I have got only one context but may be you con read doc and try to set your own context

edit flag offensive delete link more



Thank you very much for your answer, I ran the code on my machine and i got 2 platforms :"Platform Name: Intel(R) OpenCL Platform Name: NVIDIA CUDA"

Humam Helfawi gravatar imageHumam Helfawi ( 2016-10-31 06:04:57 -0600 )edit

@humam-helfawi Remember to mark the answer as correct.

rhardih gravatar imagerhardih ( 2016-10-31 06:19:09 -0600 )edit

@rhardih sorry But I was just telling what I got.. I do not know how to processed from this points.. It seems that there is small step further that i could not figure yet

Humam Helfawi gravatar imageHumam Helfawi ( 2016-10-31 06:33:37 -0600 )edit

Oh I was just so stupid.. I understood now.. thanks very much Your code gave an device object which I did not notice.. Problem solved

Humam Helfawi gravatar imageHumam Helfawi ( 2016-10-31 06:36:26 -0600 )edit

@Humam-Helfawi Hi,I have same question. My machine's information: iGPU: Intel(R) HD Graphics 530 DGPU: GeForce GTX 980M CPU: Interl(R) Core i7-6700HQ I ran the code get same platforms : "Platform Name: Intel(R) OpenCL Platform Name: NVIDIA CUDA", but I don't know how to change my devices. By executing I am always getting the Intel one. Could you give me some idea,please?

Papan gravatar imagePapan ( 2016-12-27 01:14:19 -0600 )edit

@Papan: add this to environment variables OPENCV_OPENCL_DEVICE=NVIDIA:GPU:

Humam Helfawi gravatar imageHumam Helfawi ( 2016-12-28 01:13:55 -0600 )edit

Hi the cv::ocl::getPlatfomsInfo(platforms); give me an error OpenCL function is not available: [clGetPlatformIDs] in function opencl_check_fn, do you have any idea?

Summer Sun gravatar imageSummer Sun ( 2017-08-02 02:18:18 -0600 )edit

I have already installed NVIDIA CUDA toolkit. But the haveOpenCL() still return false... Do you have any further idea?

Summer Sun gravatar imageSummer Sun ( 2017-08-02 03:22:16 -0600 )edit

Do you build opencv using cmake?

LBerger gravatar imageLBerger ( 2017-08-02 05:04:46 -0600 )edit

Question Tools

1 follower


Asked: 2016-10-30 10:15:19 -0600

Seen: 3,194 times

Last updated: Oct 31 '16