如何克服错误代码 -11 cl_build_program_failure
How to overcome Error Code -11 cl_build_program_failure
我正在尝试使用共享虚拟内存将链接列表(粒子模拟)上的功能外包给 OpenCL 内核。
我尝试从简单地遍历链表并更改其中每个元素(结构)的一个值开始。
这是.cl文件(typedef为real是为了和主机代码保持一致):
//real is of type cl_double
typedef cl_double real;
typedef cl_double2 real2;
typedef struct
{
// Mass
real m;
// Position
real2 x;
// Velocity
real2 v;
// Force
real2 F;
// Force_old
real2 F_old;
// Bodytype
cl_char body;
} Particle;
// Datastructure of linked list
typedef struct ParticleList
{
Particle p;
struct ParticleList *next;
} ParticleList;
// A cell is defined as the anchor of a linked list
typedef ParticleList *Cell;
__kernel void test(
__global ParticleList *pList){
// Check if pList->next is NULL
if(pList->next != NULL){
while(pList->next != NULL){
pList->p.body = 'Z';
pList = pList->next;
}
}
}
知道为什么它不编译 .cl 文件吗?据我所知,我可以在源代码中定义结构、typedef 和函数,并在内核函数中使用它们。
clCreateProgramWithSource returns CL_SUCCESS,但该程序上的 clBuildProgram returns 错误代码 -11。
也许有一些调试 opencl c 的技巧?
编辑:调用 clGetProgramBuildInfo 产生:
1:49:19: error: assigning 'struct ParticleList *__global' to '__global
ParticleList *' (aka '__global struct ParticleList *') changes address space
of pointer
pList = pList->next;
^ ~~~~~~~~~~~
我不确定那是什么意思,我不能取消引用设备地址 space 中的指针吗?
指针始终指向特定地址 space:global
、constant
、local
或 private
。即使指针没有注释,默认情况下也会根据上下文选择其中一个。在你的情况下,
__global ParticleList *pList
被(正确地)注释为在 global
space 中,而结构中的字段 next
没有注释:
struct ParticleList
{
Particle p;
struct ParticleList *next; // <--- no address space specified, defaults to `private`
}
显然,next
字段 而不是 指向在 private
内存中分配的结构,因此此默认值不正确,您应该明确指定 global
.
(我个人觉得默认地址space是OpenCL设计的一个错误,它应该总是显式的,但是你能做什么。)
我正在尝试使用共享虚拟内存将链接列表(粒子模拟)上的功能外包给 OpenCL 内核。 我尝试从简单地遍历链表并更改其中每个元素(结构)的一个值开始。
这是.cl文件(typedef为real是为了和主机代码保持一致):
//real is of type cl_double
typedef cl_double real;
typedef cl_double2 real2;
typedef struct
{
// Mass
real m;
// Position
real2 x;
// Velocity
real2 v;
// Force
real2 F;
// Force_old
real2 F_old;
// Bodytype
cl_char body;
} Particle;
// Datastructure of linked list
typedef struct ParticleList
{
Particle p;
struct ParticleList *next;
} ParticleList;
// A cell is defined as the anchor of a linked list
typedef ParticleList *Cell;
__kernel void test(
__global ParticleList *pList){
// Check if pList->next is NULL
if(pList->next != NULL){
while(pList->next != NULL){
pList->p.body = 'Z';
pList = pList->next;
}
}
}
知道为什么它不编译 .cl 文件吗?据我所知,我可以在源代码中定义结构、typedef 和函数,并在内核函数中使用它们。
clCreateProgramWithSource returns CL_SUCCESS,但该程序上的 clBuildProgram returns 错误代码 -11。
也许有一些调试 opencl c 的技巧?
编辑:调用 clGetProgramBuildInfo 产生:
1:49:19: error: assigning 'struct ParticleList *__global' to '__global
ParticleList *' (aka '__global struct ParticleList *') changes address space
of pointer
pList = pList->next;
^ ~~~~~~~~~~~
我不确定那是什么意思,我不能取消引用设备地址 space 中的指针吗?
指针始终指向特定地址 space:global
、constant
、local
或 private
。即使指针没有注释,默认情况下也会根据上下文选择其中一个。在你的情况下,
__global ParticleList *pList
被(正确地)注释为在 global
space 中,而结构中的字段 next
没有注释:
struct ParticleList
{
Particle p;
struct ParticleList *next; // <--- no address space specified, defaults to `private`
}
显然,next
字段 而不是 指向在 private
内存中分配的结构,因此此默认值不正确,您应该明确指定 global
.
(我个人觉得默认地址space是OpenCL设计的一个错误,它应该总是显式的,但是你能做什么。)