我是否需要为OpenCL安装Nvidia的SDK(CUDA)来检测Nvidia GPU?

时间:2015-06-24 06:51:29

标签: c linux cuda parallel-processing opencl

我有一个用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个图形卡。

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

我是否需要安装任何其他驱动程序或代码有什么问题?

1 个答案:

答案 0 :(得分:3)

NVIDIA GPU支持OpenCL唯一需要的是GPU驱动程序。不一定需要CUDA工具包。

使用向导here可以找到适合您的GPU和操作系统的适当NVIDIA GPU驱动程序。