在Nvidia Tesla上使用OpenCL:未找到平台

4

我可以访问一个安装了两张Nvidia Tesla卡的Debian 7系统。我想使用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

2
你是否安装了专有的NVIDIA驱动程序?是否存在/etc/OpenCL/vendors/nvidia.icd文件,并且它所包含的库名称(通常为libnvidia-opencl.so)是否存在? - jprice
文件/etc/OpenCL/vendors/nvidia.icd确实存在,其内容为libnvidia-opencl.so.1,该文件也存在。 - Daniel Becker
那不是个选项,因为我没有在那台机器上的 root 权限。我只能向管理员请求软件包的安装等操作。 - Daniel Becker
1
clGetPlatformIDs 调用返回的错误代码是什么? - jprice
返回的错误代码是“-1001”。 - Daniel Becker
显示剩余2条评论
1个回答

2
你可能遇到了典型的ICD 32/64位问题。 64位和32位的ICD是完全隔离的,你不能使用32位的ICD运行64位应用程序,反之亦然。
当找不到ICD或该ICD架构的平台时,clGetPlatformIDs将返回-1001错误代码。
Returned by clGetPlatformIDs when no platforms are found

    CL_PLATFORM_NOT_FOUND_KHR            -1001

nVIDIA只为你下载的版本安装平台库,通常是64位的,而32位的OpenCL应用程序则不在范围内。ICD仍然会加载但不返回平台。

请在“另一种模式”(32/64位)下编译您的应用程序,它将可以正常工作。


我刚刚验证了CUDA已经安装在64位版本中。OpenCL程序也已经以64位模式编译。然而,仍然没有检测到平台。 - Daniel Becker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接