OpenCL 无法通过 OpenCV 检测到我的 nVidia GPU

OpenCL can not detect my nVidia GPU via OpenCV

我有两个 GPU:Intel HD 和 nVidia Quadro。使用 GPU Caps Viewer,我可以在 OpenCL 选项卡中检测到我的两个 GPU。然而,通过执行这段代码,我只得到了英特尔的:

cv::ocl::setUseOpenCL(true);
if (!cv::ocl::haveOpenCL()) {
    std::cout << "OpenCL is not available..." << std::endl;
}
cv::ocl::Context context;
if (!context.create(cv::ocl::Device::TYPE_ALL)) {
    std::cout << "Failed creating the context..." << std::endl;
}
std::cout << context.ndevices() << " GPU devices are detected." << std::endl; 
for (int i = 0; i < context.ndevices(); i++) {
    cv::ocl::Device device = context.device(i);
    std::cout << "name:              " << device.name() << std::endl;
    std::cout << "available:         " << device.available() << std::endl;
    std::cout << "imageSupport:      " << device.imageSupport() << std::endl;
    std::cout << "OpenCL_C_Version:  " << device.OpenCL_C_Version() << std::endl;
    std::cout << std::endl;
}

结果:

1 GPU devices are detected.
name:              Intel(R) HD Graphics P530
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 2.0

信息:

  1. Windows 10
  2. OpenCV 3.1
  3. Visual studio 2013
  4. nVidia Quadro M4000M

备注:

  1. 我可以使用 OpenCV Cuda 接口直接调用我的 nVidia GPU。
  2. 我刚刚从 nVidia 网站安装了最新的驱动程序。

我的解决方案是添加这个环境变量:

OPENCV_OPENCL_DEVICE=NVIDIA:GPU: