2012-05-14 149 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