Goodafternoon every one
I have the following structure.
I declare the structure in the host memory as
struct rngen ** new;
This array of structures i need to transfer to the device memory.
Questions are 1) how to allocate memory in the device memory
2) how to copy data from new to devnew(memory allocated in device)
can some body can help me with sample code of allocating and copying the structures into the device memory
for your first question
rngen *devnew = NULL;
cudaMalloc((void**)&devnew, sizeof(rngen) * numOfElements);
for your second question
you can not copy data from a pointer of pointer (in host memory) to device memory, but you can copy a 2D array (static allocated in host memory) to device memory with normal method.
assume that you have 2D array on host
and you want copy data to device memory
cudaMemcpy(devnew, new, sizeof(rngen) * numOfElements, cudaMemcpyHostToDevice);
but if you use pointer of pointer in host memory
new = (rgnen**)malloc(sizeof(rgnen*) * y);
for (int i = 0; i < x; i++)
new[i] = (rgnen)malloc(sizeof(rgnen) * x);
and you try to copy data from host memory to device memory, the only first row of new
is correctly, another rows are not correctly, because when allocated with dynamic method, all the elements are not contiguous.