The proper way to have arrays within arrays in cudafy

Jul 10, 2015 at 7:49 PM
One can achieve arrays within arrays if the innermost dimension is of a constant length.
Here's an example:
[Cudafy]
public unsafe struct MySampleStruct
{
    public const int arrLen = 10;
    public fixed float SomeFixedArray[arrLen];
}

[Cudafy]
private unsafe static void MyCUDAKernel(GThread thread, MySampleStruct[] d_myTestArray)
{
    int ix = (thread.blockDim.x * thread.blockIdx.x + thread.threadIdx.x);
    fixed (float* SomeFixedArrayPtr = myTestArray[ix].SomeFixedArray)
    {
        // do something with the inner array
        for (int f = 0; f < arrLen; f++) 
            SomeFixedArrayPtr[f] = ix * f;
    }
}
Before calling the kernel, the d_myTestArray array may be allocated on the kernel and copied into using the standard cudafy functions.