Ask Your Question
3

OpenCV 3.0: How to determine which GPU is used for OpenCL?

asked 2015-05-26 09:56:10 -0500

ubehagelig gravatar image

Hi,

I ran the ufacedetect.cpp code from the sample folder, and it ran with ~10 FPS. This made me curious to learn:

  • Is it running on the Intel HD 2500 or the nVidia GT 710M in my laptop?

So, how do I determine which GPU is being used? And how do I force either one of the two (Intel or nVidia)?

I have looked through the documentation, but I haven't been able to find an answer. Any help is appreciated!

edit retag flag offensive close merge delete

Comments

1

You can check this link for more information.

On windows, you can use GPU-Z to check the GPU load of both the integrated and dedicated GPU device.

Eduardo gravatar imageEduardo ( 2015-05-26 13:11:41 -0500 )edit

Thank you. GPU-Z was a great idea. I can see that it's the Intel HD 4000 that is doing the work. I followed the link, but there was no solution for specifying which GPU should be prefered over the other (I would really like the GT710M to do the calculations). Any other suggestions are appreciated!

ubehagelig gravatar imageubehagelig ( 2015-05-27 06:47:44 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2015-06-16 05:43:28 -0500

ubehagelig gravatar image

OK, so I thought I should answer this for others who might want to change which GPU is doing the calculations.

I found the code below here

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

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

cout << context.ndevices() << " GPU 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)

In the end I found that in my case the GT 710M in my laptop only supports OpenCL 1.1, and it seems OpenCL 1.2 and above is required. So I could not "force" it to use the 710M instead of the HD4000.

edit flag offensive delete link more

Comments

1

Hi unbehagelig,

thanks for your answer and your code, I will test it soon! Did you also set the environment variable for openCL OPENCV_OPENCL_DEVICE. if yes, what kind of value did you set?

Thanks for your help, JoZ

JohannesZ gravatar imageJohannesZ ( 2015-06-16 08:24:26 -0500 )edit

Nope, I didn't fiddle with OPENCV_OPENCL_DEVICE. I am curious, so please return and let us know if you got it to work :)

ubehagelig gravatar imageubehagelig ( 2015-06-17 03:59:33 -0500 )edit

strange, afaik, the ocl module should be gone in 3.0? Arent you using 2.4?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-17 04:27:13 -0500 )edit

I am using 3.0.

ubehagelig gravatar imageubehagelig ( 2015-06-17 05:37:31 -0500 )edit

Hm, the context GPU works well both in debug and release. However, the context CPU throws an exception in debug mode:

"C:\builds\master_PackSlave-win32-vc12-shared\opencv\modules\core\src\ocl.cpp:2530: error: (-215) clGetDeviceIDs_pfn( pl, dtype, 0, 0, &nd0 ) == 0 in function cv::ocl::Context::Impl::Impl

in release mode, the CPU context works, but no devices are found... this is strange.

JohannesZ gravatar imageJohannesZ ( 2015-06-28 10:01:58 -0500 )edit

Which CPU and GPU are you using, JohannesZ?

ubehagelig gravatar imageubehagelig ( 2015-07-02 05:35:15 -0500 )edit

Hi, it is a GeForce GTX 550Ti, not the newest model, I know. OpenCL compute capability is 1.1. This could be too low for openCV, right? Iterating trough the platform info (please see my post before) I was able to see the accelerator, with the context mentioned above not. This is somewhat strange...

JohannesZ gravatar imageJohannesZ ( 2015-07-03 05:00:22 -0500 )edit

Well, in my case I have two GPUs. One is my Geforce GT710M (supports OpenCL 1.1) and the other is the Intel HD4000 (supports OpenCL 1.2) in the CPU. The only GPU it "sees" when I run the code is my Intel HD4000. I am thinking that in your case you don't have a GPU that supports OpenCL 1.2. Which CPU do you have?

ubehagelig gravatar imageubehagelig ( 2015-07-03 07:03:01 -0500 )edit

I am using a Core 2 Duo Processor with compute capability 1.2.

On another system with a new Xeon processor and and integrated Intel GPU I get the following:

  • when I am iterating trough all devices with context.create(cv::ocl::Device::TYPE_ALL)), only the CPU is detected. Splitting the search in CPU and GPU from the code above I can see both devices.

  • to what refers the attribute "type" of a found device? i though that the original mapping would be:

    0 -> default; 1 -> CPU; 2 -> GPU; 3 -> Accelerator; 4 -> dGPU; 5 -> iGPU; 6->ALL.

    But from this point of view, my XEON CPU is specified as type = 2, means a GPU. What is wrong here?

JohannesZ gravatar imageJohannesZ ( 2015-07-03 07:20:01 -0500 )edit

I am almost 100% certain that a Core 2 Duo CPU does not support OpenCL 1.2, and that OpenCL calculations are exclusively performed by a GPU. Also, the Core 2 Duo range of CPUs do not have a built-in GPU like the later Core i3, i5, and i7 do. Can you borrow a graphics card that supports OpenCL 1.2 and see if this solves your problems?

ubehagelig gravatar imageubehagelig ( 2015-07-03 08:02:35 -0500 )edit
0

answered 2015-07-30 23:25:28 -0500

hi, my board have intel hd4600 and GT740m ,I use the code below

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

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

cout << context.ndevices() << " GPU 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)

but context.create(cv::ocl::Device::TYPE_GPU) TYPE_GPU /TYPE_CPU TYPE_DGPU TYPE_IGPU TYPE_ALL cant not found GT740M , why? did you say this ?

by the way I use cvtest::ocl::dumpOpenCLDevice(); get my board info like this:

Intel(R) OpenCL CPU: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz (OpenCL 1.2 (Build 76413))

    iGPU: Intel(R) HD Graphics 4600 (OpenCL 1.2 )
NVIDIA CUDA
    dGPU: GeForce GT 740M (OpenCL 1.2 CUDA)

Current OpenCL device: Type = iGPU Name = Intel(R) HD Graphics 4600 Version = OpenCL 1.2 Compute units = 20 Max work group size = 512 Local memory size = 64 kB Max memory allocation size = 324 MB 409 kB 614 B Double support = No Host unified memory = Yes Has AMD Blas = No Has AMD Fft = No Preferred vector width char = 1 Preferred vector width short = 1 Preferred vector width int = 1 Preferred vector width long = 1 Preferred vector width float = 1 Preferred vector width double = 0

edit flag offensive delete link more

Comments

-1: Please open a new topic if you have a problem... this answer does not contribute to this question ...

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-31 02:19:58 -0500 )edit

xuefeihumei, could you add code tags around the code, please? It makes it a lot easier to view for the rest of us :) If I understand correctly you can't get it to use the GT 740M, correct? Even if you change it to cv::ocl::Device::TYPE_DGPU, correct?

ubehagelig gravatar imageubehagelig ( 2015-09-01 07:06:42 -0500 )edit
Login/Signup to Answer

Question Tools

4 followers

Stats

Asked: 2015-05-26 09:56:10 -0500

Seen: 14,094 times

Last updated: Jul 30 '15