The CUDASHARP project is designed to allow you to run a C # program on a GPU that supports Cuda.
Sample code:
using system;
using cudasharp;
using managedcuda;
namespace cudasharptest { static class program { static void main () { var ptx =
CudaSharp.CudaSharp.Translate<int[]> (kernel);
test (PTX);
console.readkey (TRUE); } static Void store (int[] arr, int value) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;ARR[GPU.THREADX () + Gpu.BlockX () &NBSP;*&NBSP;GPU.THREADDIMX ()]&NBSP;=&NBSp;value; } // Resharper disable once inconsistentnaming static void kernel (Int[] arr) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;VAR&NBSP;TID&NBSP;=&NBSP;GPU.THREADX () +
Gpu.blockx () * gpu.threaddimx ();
var val = arr[tid]; if (val != 0) store (Arr, val
&NBSP;+&NBSP;3); } static Void test (Byte[] ptxfile) { const int
size = 16; var context = new
Cudacontext (); var kernel = context.
Loadkernelptx (ptxfile, "kernel"); var memory = context.
Allocatememory (4 * size); var gpumemory = new
CudaDeviceVariable<int> (memory); var cpumemory = new
int[size]; for (var i = 0; i < size; i++) cpumemory[i] = i - 2;
gpumemory.copytodevice (cpuMemory); kernel.
blockdimensions = 4; kernel.
griddimensions = 4; kernel.
Run (memory);
gpumemory.copytohost (cpuMemory); for (var i = 0; i < size; i++)
console.writeline ("{0} = {1}", i, cpumemory[i]); } }
}
Turn from: http://www.oschina.net/p/cudasharp?utm_source=tuicool&utm_medium=referral