Passing arrays of complex structures

Hi,

Could someone please give an advice on how to pass arrays of structures that contain members that contain other arrays of structs? To be more more clear, here’s what I am trying to do:

typedef struct
{
int p;
coef* t1;
coef* t2;
mydata* data;


} CL_ThreadData;

__kernel void calc(__global CL_ThreadData* tData)
{

//Do some calc
//Mask off tData by thread_ID
printf(“ID of data[0] is %d”,tData[get_global_id(0)].data[0].id);
}

On the host side I create an array of CL_ThreadData for 16 threads, initialize it, move it to device mem via clCreateBuffer and pass entire thing via SetArg() to the kernel.

this doesnt seem to work on current sdk implementations.

you have to copy the whole array to the gpu memory instead of passing it as a kernel parameter.
(this also makes sense because of the limited stack size on gpus).

Thank you for your reply. This was for CPU SDK, but you are correct that if this were to run on GPU I would need to be more sensitive to the parameter stack. If I am not mistaken, the current CPU reports a limit of 256MB for the max size of passed args.

So I can just create a separate buffer using clCreateBuffer for each of those arrays and just reference it in the kernel code?

Yes :wink:

Remember that you can access buffers however you want in the kernel. You can access them as structs, but it is up to you to make sure the data is packed as you expect. If you are passing lots of data you should always do it through cl_mem objects to avoid stack limitations.