OpenCV 3.0与OpenCL 2.0,每个响应OpenCL的不同版本

时间:2015-08-10 05:27:28

标签: opencv opencl amd

我最近升级到使用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调用吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

我完全开始使用Ubuntu 14.04 64位代替。现在,当我运行相同的代码时,OpenCV库确实将GPU识别为OpenCL 2.0