Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

image processing - How can I change the device on which OpenCL-code will be executed with Umat in OpenCV?

As known, OpenCV 3.0 supports new class cv::Umat which provides Transparent API (TAPI) to use OpenCL automaticaly if it can: http://code.opencv.org/projects/opencv/wiki/Opencv3#tapi

There are two introductions to the cv::Umat and TAPI:

But if I have:

  1. Intel CPU Core i5 (Haswell) 4xCores (OpenCL Intel CPUs with SSE 4.1, SSE 4.2 or AVX support)
  2. Intel Integrated HD Graphics which supports OpenCL 1.2
  3. 1st nVidia GPU GeForce GTX 970 (Maxwell) which supports OpenCL 1.2 and CUDA
  4. 2nd nVidia GPU GeForce GTX 970 ...

If I turn on OpenCL in OpenCV, then how can I change the device on which OpenCL-code will be executed: on 8 Cores of CPU, on Integrated HD Graphics, on 1st nVidia GPU or 2nd nVidia GPU?

How can I select one of each of these 4 devices to use OpenCL for parallel execution algorithms with cv::Umat?

For example, how can I use OpenCL acceleration on 4xCores of CPU Core-i5 with cv::Umat?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I use something like this to check versions and hardware being used for OpenCL support.

ocl::setUseOpenCL(true);
if (!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;
}

Then you can set your preferred hardware to use, using this

cv::ocl::Device(context.device(1));

Hope this helps you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...