我正在使用ATI Radeon Mobility 4800 HD运行Ubuntu Lucid。 3D支持工作(即OpenGL应用程序以正常速度运行),但是当我尝试使用OpenCL时它失败了:
#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,并且apt-get opencl-headers。有什么建议吗?
答案 0 :(得分:1)
错误代码-1
实际上意味着CL_DEVICE_NOT_FOUND
(查看include \ CL文件夹中的cl.h以供参考)。这可能意味着几件事: