【发布时间】:2015-12-07 16:45:43
【问题描述】:
我可以访问运行 Debian 7 并安装了两个 Nvidia Tesla 卡的系统。我想使用 OpenCL 做一些基准测试。但是,OpenCL 找不到任何兼容的平台。是否需要任何其他库或特殊驱动程序才能使用 OpenCL?
这里是显示没有找到平台的示例代码:
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
int main() {
int i, j;
char* info;
size_t infoSize;
cl_uint platformCount;
cl_platform_id *platforms;
const char* attributeNames[5] = { "Name", "Vendor",
"Version", "Profile", "Extensions" };
const cl_platform_info attributeTypes[5] = { CL_PLATFORM_NAME, CL_PLATFORM_VENDOR,
CL_PLATFORM_VERSION, CL_PLATFORM_PROFILE, CL_PLATFORM_EXTENSIONS };
const int attributeCount = sizeof(attributeNames) / sizeof(char*);
// get platform count
clGetPlatformIDs(5, NULL, &platformCount);
// get all platforms
platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
clGetPlatformIDs(platformCount, platforms, NULL);
printf("Platform count: %d\n",platformCount);
// for each platform print all attributes
for (i = 0; i < platformCount; i++) {
printf("n %d. Platform n", i+1);
for (j = 0; j < attributeCount; j++) {
// get platform attribute value size
clGetPlatformInfo(platforms[i], attributeTypes[j], 0, NULL, &infoSize);
info = (char*) malloc(infoSize);
// get platform attribute value
clGetPlatformInfo(platforms[i], attributeTypes[j], infoSize, info, NULL);
printf(" %d.%d %-11s: %sn", i+1, j+1, attributeNames[j], info);
free(info);
}
printf("n");
}
free(platforms);
return 0;
}
还有我用来编译代码的命令:
gcc platforms.c -lOpenCL
如果我运行代码,输出是:
Platform count: 0
【问题讨论】:
-
当您调用 clGetPlatformIDs 时,它会告诉您安装了多少个平台。例如,AMD 可能有一个,NVIDIA 一个,Intel 一个。然后在每个平台内调用 clGetDeviceIDs,它将返回该平台内的设备数量。在您的 NVIDIA 平台上,您会找到 K20,在您的 Intel 平台上,您会找到 Xeon CPU 和 Xeon Phi 协处理器。
-
您是否安装了专有的 NVIDIA 驱动程序?有没有
/etc/OpenCL/vendors/nvidia.icd,它所包含的库名(通常是libnvidia-opencl.so)是否存在? -
文件
/etc/OpenCL/vendors/nvidia.icd确实存在,它的内容是libnvidia-opencl.so.1,它也存在。 -
这不是一个选项,因为我在那台机器上没有 root 访问权限。我只能向管理员请求安装包等。
-
clGetPlatformIDs调用返回的错误码是什么?
标签: c linux opencl nvidia tesla