Using 2D and 3D .net arrays

Jun 13, 2013 at 7:59 AM

I want to use 2 and 3 dimensional arrays with CudaDeviceVariable, and I couldn't find a way to do it. Is there a way besides managing the pointers to the arrays on my own and passing them to the CudaDeviceVariable.CopyToDevice ?

For example, I would want to do soemthing along the lines of:
int[,] array = new int[256, 256];
/* Code that populates the array */
CudaDeviceVariable<int> devArray = new CudaDeviceVariable<int>(array.Length);
I just want to make sure I'm not missing out on anything. For now I've added a few overloads for CopyToDevice and CopyToHost that take an Array as parameter, but it sort of feels like I should do it differently :)
Jun 13, 2013 at 8:50 AM
no you haven't missed anything, managedCuda doesn't support multi-dimensional arrays. The reason for this choice is, that I couldn’t find a proof that the CLR does not introduce some line padding to its internal representation of the array (same thing as the pitch for CudaPitchedDeviceVariable); passing a pointer to Cuda will then only work if there’s no line padding. Also multi dimensional arrays are treated differently compared to simple 1D arrays when it comes to optimization and p/invoke.

My experience is that normally it should work just fine, but I don’t know if that’s always the case, why they are not implemented. When dealing with 2D/3D-data, I always use 1D arrays and compute indices myself…