Skip to content

Instantly share code, notes, and snippets.

@Yey007
Created September 6, 2020 02:18
Embed
What would you like to do?
unsafe struct FSMUnit
{
public int tx;
public int ty;
public fixed int test[256];
public fixed int test2[256];
}
unsafe static void MathKernel(Index2 index, ArrayView2D<FSMUnit> grid)
{
int tx = index.X;
int ty = index.Y;
grid[tx, ty].tx = tx;
grid[tx, ty].ty = ty;
for (int n = 0; n < 256; n++)
{
grid[tx, ty].test[n] = n;
grid[tx, ty].test2[n] = (256 - n);
}
}
static void Main(string[] args)
{
Context c = new Context();
Accelerator acc = Accelerator.Create(c, CudaAccelerator.CudaAccelerators[0]);
MemoryBuffer2D<FSMUnit> memBuf = acc.Allocate<FSMUnit>((2, 2));
var k = acc.LoadAutoGroupedStreamKernel<Index2, ArrayView2D<FSMUnit>>(MathKernel);
k(memBuf.Extent, memBuf.View);
var a = memBuf.GetAs2DArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment