我正在使用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。有什麼建議麼?
Radeon 4xxx OpenCL支持目前處於[測試階段](http://developer.amd.com/sdks/AMDAPPSDK/pages/DriverCompatibility.aspx),所以它可能是值得開發商比賽的。由於平臺找到正確,您的OpenCL安裝必須正常。順便說一句,如果你有機會通過SSH /任何其他遠程連接運行你的應用程序,你應該設置X授權。 – aland