如何在OpenCV中更改将使用Umat在其上执行OpenCL代码的设备? [英] How can I change the device on which OpenCL-code will be executed with Umat in OpenCV?

查看:145
本文介绍了如何在OpenCV中更改将使用Umat在其上执行OpenCL代码的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,OpenCV 3.0支持新的类 cv::Umat 可以提供透明API(TAPI)以自动使用OpenCL,如果可以的话:

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

cv::Umat和TAPI有两个介绍:

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

  • Intel: https://software.intel.com/en-us/articles/opencv-30-architecture-guide-for-intel-inde-opencv
  • AMD: http://developer.amd.com/community/blog/2014/10/15/opencv-3-0-transparent-api-opencl-acceleration/

但如果我有:

  1. Intel CPU Core i5(Haswell)4xCores(OpenCL 具有SSE 4.1,SSE 4.2或以下版本的Intel CPU AVX支持)
  2. 支持OpenCL 1.2的英特尔集成高清显卡
  3. 第一个nVidia GPU GeForce GTX 970(Maxwell),它支持OpenCL 1.2 和CUDA
  4. 第二个nVidia GPU GeForce GTX 970 ...
  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 ...

如果我在OpenCV中打开OpenCL,那么如何更改将在其上执行OpenCL代码的设备:在8个CPU内核上,在集成HD图形上,在第一个nVidia GPU或第二个nVidia GPU上?

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?

如何在这4个设备中的每一个中选择一个以使用OpenCL进行cv::Umat的并行执行算法?

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

例如,如何在具有cv::Umat的CPU Core-i5的4xCore上使用OpenCL加速?

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

推荐答案

我使用类似的方法来检查用于OpenCL支持的版本和硬件.

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

希望这对您有所帮助.

这篇关于如何在OpenCV中更改将使用Umat在其上执行OpenCL代码的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆