struc containing pointer?

Hi All,

I would like to define a set of arrays that I will pass to some kernel. Since I might have many of them, it might be simpler to organized them in a struct. I would then like to do something like :

[codebox]

struct data{

float *val;

};

device data mydata;

global void init(float *in){

mydata.val = in;

}

global void kernel(float *out){

int tid = threadIdx.x;

out[tid] = (mydata.val)[tid];

}

[/codebox]

But this is not working. Is there a simple way to store the address of a global mem object in a device struct?

thanks

[codebox]

struct struct_of_arrays

{

int *array0;

int *array1;

int *arrayN;

};

global

void foo(struct_of_arrays soa)

{

int tid = threadIdx.x;

soa.array0[tid] = tid;

soa.array1[tid] = tid;

soa.arrayN[tid] = tid;

}

int main(void)

{

struct_of_arrays soa;

cudaMalloc((void**)&soa.array0, …);

cudaMalloc((void**)&soa.array1, …);

cudaMalloc((void**)&soa.arrayN, …);

foo<<<…,…>>>(soa);

return 0;

}

[/codebox]

Thanks to both of you.

Now I see what I was doing wrong and how to do it right…

cheers