c++ - CUDA Copying multiple arrays of structs with cudaMemcpy -


suppose struct x primitives , array of y structs:

typedef struct  {     int a;        y** y; } x; 

an instance x1 of x initialized @ host, , copied instance x2 of x, on device memory, through cudamemcpy.

this works fine primitives in x (such int a), cudamemcpy seems flatten double pointer single pointer, causing out of bounds exceptions wherever there's access struct arrays in x (such y).

in case supposed use memcpy function, such cudamemcpy2d or cudamemcpyarraytoarray?

suggestions appreciated. thanks!

edit

the natural approach (as in "that's i'd if c) towards copying array of structures cudamalloc array , cudamalloc , initialize each element separately, e.g.:

x** h_x; x** d_x; int num_x;  cudamalloc((void**)&d_x, sizeof(x)*num_x);  int i=0; for(;i<num_x;i++) {     cudamalloc((void**)d_x[i], sizeof(x));     cudamemcpy(&d_x[i], &h_x[i], sizeof(x), cudamemcpyhosttodevice); } 

however, for's cudamalloc generates crash. confess i'm not yet comfortable usage of pointers in cuda functions, perhaps screwed cudamalloc , cudamemcpy parameters?

cudamemcpy, cudamemcpy2d , cudamemcpyarraytoarray copy contiguous memory region in host contiguous memory region on device.

you have copy data in intermediary contiguous buffer send device.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -