4

I have access to a system running Debian 7 with two Nvidia Tesla cards installed. I'd like to do some benchmarking using OpenCL. However, OpenCL fails to find any compatible platforms. Do I need any additional libraries or special drivers in order to work with OpenCL?

Here is the sample code that shows that no platforms are found:

#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;

}

And the command I used to compile the code:

gcc platforms.c -lOpenCL

If I run the code, the output is:

Platform count: 0
Daniel Becker
  • 771
  • 1
  • 7
  • 25
  • When you call clGetPlatformIDs it will tell you how many platforms you have installed. There could be one for AMD, one for NVIDIA, and one for Intel, for example. Then within each platform you call clGetDeviceIDs which will return the number of devices within that platform. On your NVIDIA platform you'll find your K20, and within your Intel platform you'll find your Xeon CPU and Xeon Phi co-processor. – LPs Sep 11 '15 at 07:48
  • 2
    Have you installed the proprietary NVIDIA driver? Is there a `/etc/OpenCL/vendors/nvidia.icd`, and does the library name that it contains (usually `libnvidia-opencl.so`) exist? – jprice Sep 11 '15 at 07:48
  • The file `/etc/OpenCL/vendors/nvidia.icd` does exist, its contents is `libnvidia-opencl.so.1` which exists as well. – Daniel Becker Sep 11 '15 at 07:59
  • That is not an option, since I don't have root access on that machine. I just can request package installation and so on from the admins. – Daniel Becker Sep 11 '15 at 08:03
  • 1
    What is the error code returned by the `clGetPlatformIDs` calls? – jprice Sep 11 '15 at 08:05
  • The returned error code is `-1001` – Daniel Becker Sep 11 '15 at 08:30
  • You have some sort of OpenCL installation problem. On a host with an NVIDIA and Intel ICD correctly installed, the code you posted runs and identifies both platforms correctly (after fixing one small cosmetic syntax error in the code) – talonmies Sep 27 '15 at 15:07

1 Answers1

2

You are probably facing the typical ICD 32/64 bits problem. The ICD for 64 and 32 bits are completely isolated, and you cannot run a 64bits app using 32 bits ICD and viceversa.

When ICD is not found, or platform for that ICD architecture, clGetPlatformIDs returns -1001 error code:

Returned by clGetPlatformIDs when no platforms are found

    CL_PLATFORM_NOT_FOUND_KHR            -1001

nVIDIA only installs the platform library for the version you download, typically 64 bits, leaving 32 bit OpenCL apps out of the scope. ICD will still load but return no platforms.

Compile your application in "the other mode" (32/64 bits), and it will work.

DarkZeros
  • 8,235
  • 1
  • 26
  • 36
  • I just verified that CUDA is installed in the 64 bit version. The OpenCL program has been compiled in 64 bit mode as well. Still, no platform detected. – Daniel Becker Sep 14 '15 at 07:20