2 Dimensional Array


Is there anyone know how to copy 2 dimensional array into the device?

I have this array variable: int data[200][200];
And i would like to do some calculations using it on the device.


You flatten the array into a 1D array, and copy that as a single block. When accessing it on the GPU, you compute pointer offsets.

If it’s a statically assigned array, then there’s no need to flatten it, it’s already flattened. Just copying from the starting address of the array (&(data[0][0])) using a cudaMemcpy with a size of 200200sizeof(int) will do the job. One only needs to worry about array flattening for dynamically allocated arrays (pointer to pointer hell as YDD is all too familiar with :wacko: ).

Thanks for the solutions :)

It’s all worked now :banana: :ike: :thanks: