I am trying to outsource functions on linked lists (simulation of particles) to OpenCL kernels, using shared virtual memory. I tried starting by simply iterating through a linked list and changing one value of every element in it (structs).
This is the .cl file (the typedef to real is to keep consistent with host code):
//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;
}
}
}
Any idea on why it does not compile the .cl file? As I've understood I can define structs, typedefs and functions in the source code and use them in a kernel function.
clCreateProgramWithSource returns CL_SUCCESS, but clBuildProgram on that program returns error code -11.
Maybe some tips for debugging opencl c?
EDIT: calling clGetProgramBuildInfo yields:
1:49:19: error: assigning 'struct ParticleList *__global' to '__global
ParticleList *' (aka '__global struct ParticleList *') changes address space
of pointer
pList = pList->next;
^ ~~~~~~~~~~~
I'm not sure what that means, can I not dereference pointers that are in the devices adress space?
clGetProgramBuildInfo. This should give you specific source code lines and error messages for tracking down your problem. (I'm unfortunately not familiar with OpenCL 2.0/SVM, so I can't say for sure what the issue is just by looking at your code.) Add the output fromclGetProgramBuildInfoto your question in if any doubt about what it means. - pmdj