我有用C編寫的代碼(使用opencl規範)列出所有可用的設備。我的電腦安裝了AMD FirePro以及Nvidia的Tesla圖形卡。我首先安裝了AMD-APP-SDK-v3.0-0.113.50-Beta-linux64.tar.bz2,但它似乎沒有工作,所以此後我安裝了適用於Red Hat *和SLES * Linux * OS(64位)的英特爾®酷睿™和英特爾®至強®處理器的OpenCL™Runtime 15.1,然後OpenCL™ Code Builder。 但是下面的代碼只列出了CPU並且沒有檢測到2個圖形卡。 我需要爲OpenCL安裝Nvidia的SDK(CUDA)來檢測Nvidia GPU嗎?
int main() {
int i, j;
char* value;
size_t valueSize;
cl_uint platformCount;
cl_platform_id* platforms;
cl_uint deviceCount;
cl_device_id* devices;
cl_uint maxComputeUnits;
cl_device_type* dev_type;
// get all platforms
clGetPlatformIDs(2, NULL, &platformCount);
platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
clGetPlatformIDs(platformCount, platforms, NULL);
for (i = 0; i < platformCount; i++) {
// get all devices
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);
clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, valueSize, value, NULL);
printf("\n%d. Platform: %sn", j+1, value);
free(value);
// for each device print critical attributes
for (j = 0; j < deviceCount; j++) {
// print device name
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
printf("\n%d.%d Device: %sn", j+1,1, value);
free(value);
// print hardware device version
clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, 0, NULL, &valueSize);
dev_type = (cl_device_type*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, valueSize, dev_type, NULL);
if(*dev_type==CL_DEVICE_TYPE_CPU)
printf("\nIts a CPU.");
if(*dev_type==CL_DEVICE_TYPE_GPU)
printf("\nIts a GPU.");
if(*dev_type==CL_DEVICE_TYPE_ACCELERATOR)
printf("\nIts a ACCELERATOR.");
free(dev_type);
// print software driver version
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
printf(" \n%d.%d Software version: %sn", j+1, 2, value);
free(value);
// print parallel compute units
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(maxComputeUnits), &maxComputeUnits, NULL);
printf(" \n%d.%d Parallel compute units: %dn\n", j+1, 4, maxComputeUnits);
}
free(devices);
}
free(platforms);
return 0;}
這是它返回:
gcc -lOpenCL 1.c -o 1 && ./1
1. Platform: AMD Accelerated Parallel Processingn
1.1 Device: Intel(R) Xeon(R) CPU X5660 @ 2.80GHzn
Its a CPU.
1.2 Software version: 1642.5 (sse2)n
1.4 Parallel compute units: 24n
我是否需要安裝任何其他驅動程序或有什麼錯誤的代碼?
是的,您需要NVIDIA可安裝的客戶端驅動程序(隨CUDA SDK提供)。但是我對你的輸出感到有些驚訝,它應該至少有兩個平臺(AMD和Intel)。 'clinfo'說什麼? –
不,你不*需要SDK。您需要安裝驅動程序,該驅動程序將與OpenCL庫一起提供,並提供ICD支持。 AMD GPU也是如此 - 你需要他們的驅動程序('fglrx')。同時安裝兩個驅動程序可能會很棘手。 – jprice
clinfo給出了這樣的:1 平臺版本:平臺數量的OpenCL 2.0 AMD-APP(1642.5) 平臺名稱:AMD加速並行處理 平臺擴展:cl_khr_icd cl_amd_event_callback cl_amd_offline_devices 平臺名稱:的AMD加速並行處理 數裝置:設備類型:CL_DEVICE_TYPE_CPU 平臺ID:0x7fc6343ad830 名稱:英特爾(R)至強(R)CPU X5660 @ 2.80GHz的 賣方:GenuineIntel 設備的OpenCL C版:OpenCL的ç1.2 驅動程序版本:1642.5(SSE2 ) 配置文件:FULL _PROFILE 版本:\t OpenCL 1.2 AMD-APP(1642.5) – ikk