Start New Discussion within our Software Development Community

I have two structures as;

struct collapsed {
    char **seq;
    int num;
};

// set of collapsed examples
struct data {
    collapsed *x;
    int num;
    int numblocks;
    int *blocksizes;
    float *regmult;
    float *learnmult;
};

And I have one statically defined 'data X;' need to be transmitted into device memory from host memory. I am currently out of my mind to do that for a week. Is there any senior deveoper that can help thi newbie with a little code snippet or example?

Something like this might do it.

collapsed theCollapsedobject; // Create the one to copy across
data theOneYouWantToCopy; // Create the one to copy across
theOneYouWantToCopy.collapsed = &theCollapsedobject;


data* d_pointer_to_struct_on_device; // make a pointer that will point to the device memory
cudaMalloc(&d_pointer_to_struct_on_device, sizeof(data); // allocate memory on device

collapsed* d_pointer_to_collapsed_on_device; // make a pointer that will point to the device memory   
cudaMalloc(&d_pointer_to_collapsed_on_device, sizeof(collapsed); // allocate memory on device

cudaMemCpy(d_pointer_to_collapsed_on_device, &theCollapsedobject, sizeof(collapsed),  cudaMemcpyHostToDevice); // copy the collapsed across to the device

theOneYouWantToCopy.collapsed = d_pointer_to_collapsed_on_device; // now it's internal pointer points to the device...
cudaMemCpy(d_pointer_to_struct_on_device, &theOneYouWantToCopy, sizeof(data),  cudaMemcpyHostToDevice); // copy the struct across to the device

What I did was create a collapsed, and a data. Copied the collapsed over to the CUDA device, and then make the data point to that one on the CUDA device, and then copied the data over as well, so now the CUDA memory contains a copy of the collapsed and a copy of the data, and the data points to the collapsed on the device. I have a CUDA device here but I haven't installed the CUDA libraries so I can't test it, I'm afraid.

This article has been dead for over six months. Start a new discussion instead.