How to copy struct with a dynamic array in it to the Device Ram

For example,

struct A
{
int* b;
}

If I want to make a deep copy of A from Host Ram to Device Ram, I encountered a problem:

A* a;

cudaMalloc((void**)&a, xxx); //after this line, I can not access “a->b” anymore in my host code, since “a” now is already a device pointer.

Then how can I assign the pointer of the dynamic array on Device Ram to “a->b” ??

Thanks in advance.

You have no choice but to use host side code to allocate the memory and copy the data into that memory, and then device side code (ie. a small kernel) to assign the actual pointer values inside the structure. It will get very unwieldy very quickly, especially if the structure has a lot of depth (like trees or multiply linked lists), but for simple structures of arrays it is manageable.

Thanks very much!
I tried what you said. It seems a feasible plan.
However, I wonder if there is any formal solution without involving global/device function for my pointer initialization? :)