2012-05-14 107 views
0

我正在使用ATI Radeon Mobility 4800 HD运行Ubuntu Lucid。支持3D作品(即OpenGL应用程序,以正常速度运行),但是当我试图使用OpenCL的失败:clGetDeviceIds返回-1

#include <CL/opencl.h> 
#include <iostream> 
#include <cstdlib> 

#define CL_SAFE_CALL(call) {                \ 
    cl_int err = call; std::cerr << "EC: " << err << std::endl;        \ 
    if(CL_SUCCESS != err){                 \ 
     std::cerr << "Unsuccesful OpenCL call " << __FILE__ << " : " << __LINE__ << std::endl; \ 
     exit(EXIT_FAILURE);             \ 
    } } 

// OpenCL platform 
cl_platform_id platform; 

char* getPlatformInfo(cl_platform_id platform, cl_platform_info paramName){ 
    size_t infoSize = 0; 
    CL_SAFE_CALL(clGetPlatformInfo(platform, paramName, 0, NULL, &infoSize)); 
    char* info = (char*)malloc(infoSize); 
    CL_SAFE_CALL(clGetPlatformInfo(platform, paramName, infoSize, info, NULL)); 
    return info; 
} 

cl_platform_id createPlatform(){ 
    cl_platform_id platform; 

    CL_SAFE_CALL(clGetPlatformIDs(1, &platform, NULL)); 
    std::cout << getPlatformInfo(platform, CL_PLATFORM_VERSION) << std::endl; 
    return platform; 
} 

// OpenCL devices of the platform 
cl_device_id device_id; 

void* getDeviceInfo(cl_device_id device_id, cl_device_info paramName){ 
    size_t infoSize = 0; 
    CL_SAFE_CALL(clGetDeviceInfo(device_id, paramName, 0, NULL, &infoSize)); 

    char* info = (char*)malloc(infoSize); 
    CL_SAFE_CALL(clGetDeviceInfo(device_id, paramName, infoSize, info, NULL)); 
    return info; 
} 

cl_device_id createDevice(cl_platform_id platform, cl_device_type type){ 
    cl_device_id device_id; 

    // THIS IS LINE 44: 

    CL_SAFE_CALL(clGetDeviceIDs(platform, type, 1, &device_id, NULL)); 

    cl_uint* max_compute_units = (cl_uint*)getDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS); 
    std::cout << "Max compute units: " << *max_compute_units << std::endl; 

    return device_id; 
} 

int main(void){ 
    std::cerr << "createDevice:" << std::endl; 
    platform = createPlatform(); 
    std::cerr << "createDevice:" << std::endl; 
    device_id = createDevice(platform, CL_DEVICE_TYPE_GPU); 
} 

以下:

~$ g++ -o test test.cc -lOpenCL 
~$ ./test 
createDevice: 
EC: 0 
EC: 0 
EC: 0 
OpenCL 1.2 AMD-APP (923.1) 
createDevice: 
EC: -1 
Unsuccesful OpenCL call test.cc : 44 

我libOpenCl从安装和我容易 - 获取opencl-headers。有什么建议么?

+0

Radeon 4xxx OpenCL支持目前处于[测试阶段](http://developer.amd.com/sdks/AMDAPPSDK/pages/DriverCompatibility.aspx),所以它可能是值得开发商比赛的。由于平台找到正确,您的OpenCL安装必须正常。顺便说一句,如果你有机会通过SSH /任何其他远程连接运行你的应用程序,你应该设置X授权。 – aland

回答

1

-1的错误代码其实意味着CL_DEVICE_NOT_FOUND(请查看include \ CL文件夹中的cl.h以供参考)。这可能意味着几件事情:

  • 什么是您的GPU视频驱动程序?检查它是否完全不支持OpenCL。
  • 您的驱动程序是最新的吗?检查您是否有最新版本。
+1

如果以上所有内容都检查完毕 - 请参阅本指南(适用于Ubuntu),以确保您安装了所有正确的内容以使所有内容正常工作。 http://www.thebigblob.com/getting-started-with-opencl-and-gpu-computing/ – Ani

+0

我的GPU驱动程序不支持OpenCL,尽管它是最新的。我不得不下载实验版本。 – ther