【问题标题】:clGetPlatformID error when running OpenCL program.运行 OpenCL 程序时出现 clGetPlatformID 错误。
【发布时间】:2015-09-06 13:00:09
【问题描述】:

我一直在尝试让 OpenCL 在我的笔记本电脑上运行。为此,我关注了this 链接。我有一个 NVIDIA GT525M 显卡和 Windows 8.1。 我遵循的步骤是:

安装最新的 NVIDIA 驱动程序。

安装 Visual Studio 2013 社区版。

添加链接器和编译器的路径。

然后我尝试运行该页面中给出的以下代码:

#include <stdio.h>
#include <CL/cl.h>

int main(void)
{
    cl_int err;
    cl_uint* numPlatforms=NULL;

    err = clGetPlatformIDs(0, NULL,numPlatforms);
    if (CL_SUCCESS == err)
        printf("\nDetected OpenCL platforms: %d", numPlatforms);
    else
        printf("\nError calling clGetPlatformIDs. Error code: %d", err);
    getchar();
    return 0;
}

代码构建成功,但我得到的结果是:

Error calling clGetPlatformIDs. Error code: -30

平台数量为零。 我一直在互联网上寻找解决方案,但找不到。请帮忙。

【问题讨论】:

  • @AnastasiyaAsadullayeva 很抱歉在这里提出愚蠢的问题。但是那里的文档不是很清楚。 (或者我太笨了,无法理解)谢谢你,那行得通。

标签: opencl


【解决方案1】:

这个:

cl_uint* numPlatforms=NULL;
err = clGetPlatformIDs(0, NULL,numPlatforms);

相当于这个:

err = clGetPlatformIDs(0, NULL, NULL);

这没有意义。根据documentation

如果函数执行成功,则返回 CL_SUCCESS。否则,如果 num_entries 等于 0 且平台不为 NULL,或者 num_platforms 和平台都为 NULL,则返回 CL_INVALID_VALUE。

CL_INVALID_VALUE 是您得到的 -30,原因如上所述。

你真正想要的是:

cl_uint numPlatforms = 0;
err = clGetPlatformIDs(0, NULL, &numPlatforms);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多