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

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

问题描述

众所周知,OpenCV 3.0支持新课程 cv :: Umat 如果可以的话,它提供透明API(TAPI)以自动使用OpenCL: http://code.opencv.org/projects/opencv/wiki/Opencv3#tapi

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 indtroductions 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或AVX支持的Intel CPU

  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,那么我该怎么办?在第一个nVidia GPU或第二个nVidia GPU上,在8个CPU核心,集成高清显卡上更改设备?

If I turn on OpenCL in OpenCV, then how can I change the device on wich 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?

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

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天全站免登陆