Passing an array of a user defined structure to a Kernel

Hi *,

I have created the following structure

[codebox]

typedef struct{

unsigned char *OF;

int over;

}overflow;[/codebox]

And I declared two arrays of this structure

overflow of[25],d_of[25];

Then I allocated memory for the dynamic array in the structure for all elements of the arrays with

[codebox]

for(i=0;i<no_part;i++)

{

    of[i].OF=(unsigned char*)calloc(size_part,sizeof(unsigned char));



    cudaMalloc((void**)&d_of[i].OF,size_part*sizeof(unsigned char));



    cudaMemcpy(d_of[i].OF,of[i].OF,size_part*sizeof(unsigned char),cudaMemcpyHostToDevice);

}[/codebox]

I want to use the array d_of as an argument in my kernel invocation but I’m running into problems using the kernel side array.

Heres how I’m invoking my kernel

Count<<<1,4>>>(d_bloom,d_pv,d_of,x);

And in the kernel side this is the function prototype

global void Count(BLOOM bloom, PV pv,overflow *of,int *x)

Im returning the value of x to my host, but if I use the variable *of in anyway It messes the value of x Im returning so its returning 0 instead of the value I’m actually returning.

so in the kernel Im setting the value of an element of the dynamically allocated OF in my structure

[codebox]

of[0].OF[0]=3;

[/codebox]

And this line causes the following warning:

Warning: Cannot tell what pointer points to, assuming global memory space

So I just want to be able to use an array of my structure normally in the kernel. I tried using a dynamically allocated vector of my structure instead of an array but that didn’t work. My other user defined structures work and are passed fine but I’m running into trouble with the structure overflow since its an array and not a single instance of a structure. I’ve been stuck on this for a while please help.

I also noticed problems even passing arrays of any type like int. So how can arrays be passed to kernels without using dynamically allocated vectors?

As I remeber it right, the pointer you are using in your kernel points to memory in your host memory.

Copy your array with cudaMemcpy to the device memory and use the device pointer to access the data in your kernel.

I did the cudaMemcpy for the array of overflow and I still got the same warning.

I am passing the device pointer d_of of the array of overflow structures, how is it then the memory the pointer is pointing to in the kernel is host memory?