【发布时间】:2015-09-10 05:53:03
【问题描述】:
我有一个用 C 语言编写的代码(使用 opencl 规范)来列出所有可用的设备。我的电脑安装了 AMD FirePro 和 Nvidia 的 Tesla 显卡。我首先安装了AMD-APP-SDK-v3.0-0.113.50-Beta-linux64.tar.bz2,但它似乎无法正常工作,因此此后我安装了适用于英特尔® 酷睿™ 的 OpenCL™ 运行时 15.1 和适用于 Red Hat* 和 SLES* Linux* 操作系统(64 位)的英特尔® 至强® 处理器,然后OpenCL™ Code Builder 。 但是下面的代码只列出了CPU,并没有检测到2显卡。
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
我需要安装任何其他驱动程序还是代码有什么问题?
【问题讨论】:
-
不,您确实不需要需要 SDK。您需要安装他们的驱动程序,该驱动程序将随 OpenCL 库一起提供并提供 ICD 支持。 AMD GPU 也是如此 - 您将需要他们的驱动程序 (
fglrx)。不过同时安装两个驱动程序可能会很棘手。 -
clinfo 给出了这个: 平台数量:1 平台版本:OpenCL 2.0 AMD-APP (1642.5) 平台名称:AMD 加速并行处理平台扩展:cl_khr_icd cl_amd_event_callback cl_amd_offline_devices 平台名称:AMD 加速并行处理数量设备:1 设备类型:CL_DEVICE_TYPE_CPU 平台 ID:0x7fc6343ad830 名称:Intel(R) Xeon(R) CPU X5660 @ 2.80GHz 供应商:正版英特尔设备 OpenCL C 版本:OpenCL C 1.2 驱动程序版本:1642.5 (sse2) 配置文件:FULL_PROFILE 版本:OpenCL 1.2 AMD-APP (1642.5)
-
运行
dmesg | grep fglrx | grep module以查看是否出现问题。如果没有,那么您没有安装 AMD 显卡驱动程序。第一次您可能需要使用sudo运行您的opencl 程序,以便系统中的所有内容都初始化。此外,您可能还需要停止桌面 GUI。 -
它是 Nvidia Tesla 显卡。请建议我应该安装一个特定的驱动程序来解决这个问题。操作系统是 RHEL
-
安装最新的CUDA,还有驱动。
标签: c linux cuda parallel-processing opencl