Array of pointers and memcpy


I got an array of pointers (it is merely a multidimensional array, but that should not make a difference) and want to use cudaMemcpy to transfer the underlying data to the gpu.

The problem arises when my data is not linear in the memory, i.e. array[i+1] does not point to the subsequent memory location as array[i]. So I can not give cudaMemcpy the pointer array[0] and just copy linear.

Is there a possibility to memcpy such a structure to the gpu and keep it?

The only way to do this will be the creation of a second array of pointers pointing to device memory (I’ll call it darray) and then copying array[i] to darray[i]. Afterwards you’ll also have to copy the darray to the card.

Maybe cudaMemcpy2D() will work for you…There are two formal parameters: a pitch for the destination memory, and a separate pitch for the source memory.