OpenCL 在调用 clGetPlatformIDs 时返回 -64
OpenCL returning -64 upon calling clGetPlatformIDs
编辑:错误代码如下
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 库,以下代码 returns 最后检查后为 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
};
编辑:错误代码如下
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 库,以下代码 returns 最后检查后为 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
};