Ask Your Question
1

openCV 3.0 beta and OpenCL setDevice

asked 2015-04-04 08:36:39 -0600

JohannesZ gravatar image

updated 2015-04-07 15:49:02 -0600

Hi,

in OpenCL, I have studied the ocl_test.cpp. Retrieving information about my system (Windows 7 SP1, 32bit) concerning available CPUs, GPUs and so on works fine. Studying the documentation, I have not found a way to set the device to do the actual computations.

In an older version of openCV, I saw a method like "setDevice", which is not available in the 3.0 beta. So, how can I enable a specific device for further computations? I only found a method called "set" which accepts a void-pointer. Since my GPU (device 0) is not the newest model I would like to enable my multicore-CPU (following device 1 and so on).

Thanks for your tips! Johannes

edit retag flag offensive close merge delete

Comments

1

@JohannesZ as I mention in my answer if you want to enable/specify the device that should be used with opencl, you need to apply the environment variable OPENCV_OPENCL_DEVICE. For example in linux: export OPENCV_OPENCL_DEVICE=":GPU:0" in windows I guess it would be to add the OPENCV_OPENCL_DEVICE=":GPU:0" in your environment variables path. Moreover, in the Qtcreator IDE that I am using I can specify this variable through the IDE settings for the specific project, so no need to set anything outside the IDE. I guess something similar would apply for other IDE's as well. Anyway, the idea is specify the above variable beforehand and not within your code. I guess this option will be added later on in the new v3.0.0 api.

theodore gravatar imagetheodore ( 2015-04-06 07:52:59 -0600 )edit

Thanks for your tip! I think it's too bad that you can't set the device in the code directly. I made some tests (see below) but the cast to the void* pointer is not working - no idea why.

JohannesZ gravatar imageJohannesZ ( 2015-04-06 08:54:20 -0600 )edit

Hm, this is strange: without the environment variable you mentioned, cv::ocl::useOpenCL() always return true.

When i set the environment variable to:

Intel(R) OpenCL:CPU:0

There are no error messages (I recently got an error message writing 1:CPU:0) So these parameters should be fine. But in this case, useOpenCL() always returns false.

This is somewhat strange!

JohannesZ gravatar imageJohannesZ ( 2015-04-06 11:46:25 -0600 )edit

you can switch opencl on or off by using the cv::ocl::setUseOpenCL() function:

/*  SWITCH OPENCL ON/OFF IN LINE BELLOW */
    cv::ocl::setUseOpenCL(true/false);
theodore gravatar imagetheodore ( 2015-04-06 11:57:17 -0600 )edit

yes sure. But in case of the environment variable, the methd useOpenCl always returns false, no matter of setuseOpenCL(true/false)

JohannesZ gravatar imageJohannesZ ( 2015-04-06 12:00:55 -0600 )edit

What do you recommend as a OpenCL Runtime for Intel Processors (Core Processors)?

For example, is the "Intel Integrated Native Developer Experience Starter Edition" suitable? Or ist there anoher software package from Intel recommended?

JohannesZ gravatar imageJohannesZ ( 2015-04-07 15:48:25 -0600 )edit

Hi JohannesZ. Did you solve this? I am trying to figure out how to force either the Intel HD 4000 GPU or the nVidia GT710M to do the OpenCL calculations. Check my thread: http://answers.opencv.org/question/62...

Thank you in advance! :)

ubehagelig gravatar imageubehagelig ( 2015-05-27 06:17:19 -0600 )edit

4 answers

Sort by ยป oldest newest most voted
3

answered 2015-04-04 10:03:18 -0600

theodore gravatar image

According to the OpenCV's documentation:

Right now, the user can select OpenCL device by specifying the environment variable OPENCV_OPENCL_DEVICE. Variable format:

<Platform>:<CPU|GPU|ACCELERATOR|nothing=GPU/CPU>:<DeviceName or ID>

Note: Device ID range is: 0..9 (only one digit, 10 - it is a part of name)

Samples:

'' = ':' = '::' = ':GPU|CPU:'

'AMD:GPU|CPU:'

'AMD::Tahiti'

':GPU:1'

':CPU:2'

Also the user can use cv::ocl::setDevice function (with cv::ocl::getOpenCLPlatforms and cv::ocl::getOpenCLDevices). This function initializes OpenCL runtime and setup the passed device as computing device.

edit flag offensive delete link more

Comments

setDevices is no longer available on 3.0, so there is no way to run-time select which GPU should be used? That would be an incredible design error given that many systems use dual or more GPUs, and sharing tasks between them is critical!

Boogaloo gravatar imageBoogaloo ( 2015-12-10 09:34:24 -0600 )edit

@Boogaloo I do not know to tell you. If that happened indeed it is a design mistake. Try to open a new thread about it. It might someone else knows something more.

theodore gravatar imagetheodore ( 2015-12-10 10:19:37 -0600 )edit
1

answered 2015-06-10 03:14:08 -0600

Anna Lucia gravatar image

updated 2015-07-12 20:10:01 -0600

How about trying following code: - current_device.set(current_device.ptr()); BTW, you'd beeter set the environment variables to set up the OpenCL device.

edit flag offensive delete link more
0

answered 2015-04-06 04:44:23 -0600

JohannesZ gravatar image

updated 2015-04-06 04:44:53 -0600

Hi theodore!

Thanks for your answer. As I understand correctly the current API von openCV 3.0 beta has some changes in the API. Actually, I am retieviing the platform info and device info using

//OpenCL: Platform Info
std::vector<cv::ocl::PlatformInfo> platforms;
cv::ocl::getPlatfomsInfo(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();

In the api, there is only a method like

void cv::ocl::Device::set   (void * d)

from: http://docs.opencv.org/master/d7/d9f/...

My question is, how can I use it? I really don't understand the parameter or the cast to void*. Any help would be appreciated!

edit flag offensive delete link more

Comments

The conversion is not working - both ways not:

//OpenCL:: Platform
const cv::ocl::PlatformInfo* platform = &platforms[0];

//Access known device
cv::ocl::Device current_device;
platform->getDevice(current_device, 0);

//set Device - NOT WORKING
cv::ocl::Device::set(&current_device);

or

//set Device - NOT WORKING

void *p;
p = (void*)& current_device;
cv::ocl::Device::set(p);
JohannesZ gravatar imageJohannesZ ( 2015-04-06 08:49:47 -0600 )edit

perhaps cv::ocl::Device(current_device); ?

biaspoint gravatar imagebiaspoint ( 2015-07-18 15:01:39 -0600 )edit
0

answered 2015-06-16 06:03:42 -0600

ubehagelig gravatar image

I think I may have found the solution. Check out my answer here: http://answers.opencv.org/question/62...

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2015-04-04 08:36:39 -0600

Seen: 11,823 times

Last updated: Jul 12 '15