我最近升级到了一张带有 OpenCL 2.0 (R9 390) 的 GPU 卡,而这张卡上只有 OpenCL 1.2。为了开始将它与 OpenCV 一起使用,我创建了一些基本调用来确定每个库认为我拥有的硬件。
cout << "Equipment according to OpenCV:" << endl;
//Setup OpenCV first
cv::ocl::setUseOpenCL(true);
//OpenCV: Platform Info
std::vector<cv::ocl::PlatformInfo> platforms;
cv::ocl::getPlatfomsInfo(platforms);
//OpenCV Platforms
for (size_t i = 0; i < platforms.size(); i++)
{
const cv::ocl::PlatformInfo* platform = &platforms[i];
//Platform Name
std::cout << "Platform Name: " << platform->name().c_str() << "\n";
//Access known device
cv::ocl::Device current_device;
for (int j = 0; j < platform->deviceNumber(); j++)
{
//Access Device
platform->getDevice(current_device, j);
std::cout << "Device Name: " << current_device.name().c_str() << "\n";
}
}
cv::ocl::Device(current_device); // Required?
cout << cvContext.ndevices() << " GPU devices are detected." << endl;
for (int i = 0; i < cvContext.ndevices(); i++)
{
cv::ocl::Device device = cvContext.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 << "Use OpenCL: " << cv::ocl::useOpenCL() << endl;
cout << endl;
}
cv::ocl::Device(cvContext.device(0)); //Here is where you change which GPU to use (e.g. 0 or 1)
// Setup OpenCL
cout << "Equipment according to OpenCL:" << endl;
vector<cl::Platform> clPlatforms;
vector<cl::Device> clPlatformDevices, clAllDevices;//, clCTXdevices;
string clPlatform_name, clDevice_name;
cl_uint i;
cl::Platform::get(&clPlatforms);
for(i=0; i<clPlatforms.size();i++)
{
clPlatform_name = clPlatforms[i].getInfo<CL_PLATFORM_NAME>();
cout<< "Platform: " <<clPlatform_name.c_str()<<endl;
clPlatforms[i].getDevices(CL_DEVICE_TYPE_ALL, &clPlatformDevices);
// Create context and access device names
clContext = cl::Context(clPlatformDevices);
clCTXdevices = clContext.getInfo<CL_CONTEXT_DEVICES>();
for(i=0; i<clCTXdevices.size(); i++) {
clDevice_name = clCTXdevices[i].getInfo<CL_DEVICE_NAME>();
cout << "Device: " << clDevice_name.c_str() << endl;
}
}
cout << "OpenCL Version: "<<clPlatforms[0].getInfo<CL_PLATFORM_VERSION>().c_str() <<endl;
cout << "Vendor: "<<clPlatforms[0].getInfo<CL_PLATFORM_VENDOR>().c_str() <<endl;
cout << "Extensions: "<<clPlatforms[0].getInfo<CL_PLATFORM_EXTENSIONS>().c_str() <<endl;
和输出:
Equipment according to OpenCV:
Platform Name: AMD Accelerated Parallel Processing
Device Name: Hawaii
Device Name: Intel(R) Core(TM)2 Quad CPU Q9450 @ 2.66GHz
1 GPU devices are detected.
name: Hawaii
available: 1
imageSupport: 1
OpenCL_C_Version: OpenCL C 1.2
Use OpenCL: 1
Equipment according to OpenCL:
Platform: AMD Accelerated Parallel Processing
Device: Hawaii
Device: Intel(R) Core(TM)2 Quad CPU Q9450 @ 2.66GHz
OpenCL Version: OpenCL 2.0 AMD-APP (1729.3)
Vendor: Advanced Micro Devices, Inc.
Extensions: cl_khr_icd cl_amd_event_callback cl_amd_offline_devices
所以 OpenCV 认为我有 OpenCL 1.2,而 OpenCL 更聪明一点,并返回 2.0……有什么想法为什么他们不会返回相同版本的 OpenCL?我想知道是否需要重新编译 OpenCV,以便它可以识别出有更新版本的 OpenCL 可用?OpenCV 3.0 是否仅限于使用 OpenCL 1.2 调用?谢谢!