Quantcast
Channel: CUDAfy.NET
Viewing all articles
Browse latest Browse all 1169

New Post: The proper way to have arrays within arrays in cudafy

$
0
0
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.

Viewing all articles
Browse latest Browse all 1169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>