【发布时间】:2019-04-19 15:01:31
【问题描述】:
我正在尝试使用共享虚拟内存将链表(粒子模拟)上的函数外包给 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 文件吗?据我了解,我可以在源代码中定义结构、类型定义和函数,并在内核函数中使用它们。
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;
^ ~~~~~~~~~~~
我不确定这意味着什么,我可以不取消引用设备地址空间中的指针吗?
【问题讨论】:
-
您的第一步是致电
clGetProgramBuildInfo。这应该为您提供特定的源代码行和错误消息,以跟踪您的问题。 (不幸的是,我不熟悉 OpenCL 2.0/SVM,所以我不能通过查看您的代码来确定问题出在哪里。)如果对它有任何疑问,请将clGetProgramBuildInfo的输出添加到您的问题中意思是。 -
谢谢,这让调试变得容易多了。我用编译器错误更新了帖子