如何克服错误代码-11 cl_build_program_failure

时间:2018-11-16 12:06:08

标签: c list kernel opencl

我正在尝试使用共享虚拟内存将链表(粒子模拟)上的函数外包给OpenCL内核。 我尝试通过简单地遍历链接列表并更改其中每个元素(结构)的值开始。

这是.cl文件(实际的typedef与主机代码保持一致):

//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返回CL_SUCCESS,但是该程序上的clBuildProgram返回错误代码-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;
              ^ ~~~~~~~~~~~

我不确定这意味着什么,是否可以不取消引用设备地址空间中的指针?

1 个答案:

答案 0 :(得分:0)

指针始终引用特定的地址空间:globalconstantlocalprivate。即使未注释指针,默认情况下也会根据上下文选择其中之一。就您而言,

__global ParticleList *pList

(正确地)注释为位于global空间中,而结构中的字段next没有注释:

struct ParticleList
{
  Particle p;
  struct ParticleList *next; // <--- no address space specified, defaults to `private`
}

很明显,next字段不会指向在private内存中分配的结构,因此该默认值是错误的,您应该显式指定global

(就我个人而言,我认为默认地址空间是OpenCL设计中的一个错误,应该始终是明确的,但是您可以做什么。)

相关问题