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

Do i need to install Nvidia's SDK(CUDA) for OpenCL to detect Nvidia GPU?

我有一个用 C 编写的代码(使用 opencl 规范)来列出所有可用的设备。我的 PC 安装了 AMD FirePro 和 Nvidia 的 Tesla 显卡。我首先安装了 AMD-APP-SDK-v3.0-0.113.50-Beta-linux64.tar.bz2 but it didn't seem to work so thereafter I installed OpenCL™ Runtime 15.1 for Intel® Core™ and Intel® Xeon® Processors for Red Hat* and SLES* Linux* OS (64-bit) & then 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;}

就是这样 returns:

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 GPU 要支持 OpenCL,唯一需要的就是 GPU 驱动程序。 CUDA 工具包应该不是必需的。

可以使用向导 here 为您的 GPU 和 OS 找到合适的 NVIDIA GPU 驱动程序。