CUDA 2.0 and complex data structures


For a complex algorithm I needed to use some complex data structures in C + CUDA.

I started with “struct” but have not been able to work even a very simple code with it.

I have written codes in C + CUDA with passing arrays between host and device.

Now I want to use “struct” as the data structure but it is giving me a lot of errors.

Eg. if M is a struct and if I use commands like (just for instance):
CUDA_SAFE_CALL(cudaMemcpy(Md,Mh, structsize, cudaMemcpyHostToDevice));
it gives me errors in places where I try to access the elements of the struct on the device and where I declare M to be struct.

If M is a pointer to a struct, it gives me many more compilation errors…many of them hint towards as if CUDA is expecting some “c++ class” instead of a struct. Whatever I do, the problem is not solved and I am not very familiar with C++ too.

No logical “struct” handling in C works to resolve this. Can someone please post an example of struct being passed between the device and the host, allocation on host and device, etc.?

I came across this blog:…hods-with-cuda/ which says that CUDA 1.0 doesnt support structs. But I am working with CUDA 2.0. Is it true for 2.0 too?

Thanks a lot.


Any explanation?

Yeah, I have resolved the issue of passing the struct when I declare a static array inside it. But I am still facing the problem when I have to pass a struct with a dynamic array of integers as a member.