Newbie 2D Array Question

Hi all,

I have an irregular (not AxB elements) 2-D array that I want to write to the GPU without using pitched pointers (which as I understand insist on rectangular arrays). Extreme performance is not an issue with reading elements from this array.

Is it enough to take an array Values[a][b] of structs and simply use cudaMemcpy(dev_Values, Values, sizeof(Values), cudaMemcpyHostToDevice) to be able to access the array on the GPU through a kernel with the syntax dev_Values[i][j]? Or will I have to create a pointer to an array of pointers on the GPU and call cudaMemcpy separately for every element?



The latter, which is why pointer based jagged arrays are really a bad idea in CUDA. If there is a large variation in element lengths, you might want to consider storing indexes into a linear allocation (rather like compressed sparse matrix storage) instead.