gpt4 book ai didi

c++ - OpenCL 在调用 clGetPlatformIDs 时返回 -64

转载 作者:行者123 更新时间:2023-11-28 05:22:58 25 4
gpt4 key购买 nike

编辑:错误代码如下

CL_INVALID_PROPERTY if context property name in properties is not a 
supported property name, if the value specified for a supported property
name is not valid, or if the same property name is specified more than once.
However if the extension cl_khr_gl_sharing is enabled, then
CL_INVALID_PROPERTY is returned if an attribute name other than those listed
in the table for properties above is specified in properties.

我正在使用 MinGW (x86) 和 x86 AMD OpenCL 库,以下代码在最终检查后返回 NULL:

cl_context CreateContext()
{
cl_int errNum;
cl_uint numPlatforms;
cl_platform_id firstPlatformID;
cl_context context=NULL;
//Select an OpenCL platform

errNum=clGetPlatformIDs(1, &firstPlatformID, &numPlatforms);
if (errNum!=CL_SUCCESS||numPlatforms<=0)
{
cerr<<"Failed to find any OpenCL platforms."<<endl;
return NULL;
}

cl_context_properties contextProperties[]=
{
CL_CONTEXT_PLATFORM,
(cl_context_properties) firstPlatformID,
};
context=clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &errNum);
cout << errNum << endl;
if (errNum!=CL_SUCCESS)
{
cerr<<"Failed to create an OpenCL GPU context, trying CPU."<<endl;
context=clCreateContextFromType(contextProperties,CL_DEVICE_TYPE_CPU, NULL, NULL, &errNum);

if (errNum!=CL_SUCCESS)
{
cerr<<"Failed to create an OpenCL GPU or CPU context."<<endl;
return NULL;
}
}
return context;
}

它检测到 2 个平台(intel cpu、AMD gpu),但无法创建上下文。 x64 库做同样的事情。有人知道怎么解决吗?

最佳答案

根据 clCreateContext 的文档您必须用零终止 cl_context_properties 列表。

通过以下更改代码适用于我:

cl_context_properties contextProperties[] =
{
CL_CONTEXT_PLATFORM,
(cl_context_properties)firstPlatformID,
0
};

关于c++ - OpenCL 在调用 clGetPlatformIDs 时返回 -64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41084645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com