C structures cudaMalloc cudaMemcpy


Can we pass C structures with cudaMalloc/cudaMemcpy ?

Here is my code, but I don’t know how to pass this structure to my device :s

typedef struct s


		char a[5];

		word64 sb[128];

		word32 i;

} s;

void alloc_struct(struct s **sa, unsigned long int nb)


	int i;

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

			sa[i] = NULL;

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


			//s_i is a number between 0 and 1000 (the array size)

			sa[s_i] = (struct s *) calloc( 1, sizeof(struct s) );


			// here some stuff to fill the fresh allocated struct

		   t = sa[s_i];

		   strncpy( t->a, "abcd", 4);



int main()


   struct s *my_struct[1000];

   alloc_struct(my_struct, 7);

// here "my_struct" is allocated and I can access elements :

   // let	0 < i < 1000	:	

   printf("%s\n", (my_struct[i])->a );

// but now, how can I transfert the whole structure to the device ??

  // is it possible ? !


Thanks for your help !

It does work for a structure that is a collection of floats

struct_type *s, *d_s;

cudaMalloc((void**) &d_s, sizeof(struct_type)*No_of_Elements) ;

cudaMemcpy is the same way