class Worker { public GPGPU gpu { get; set; } public int TID { get; set; } public void test(object stateObject) { int[] dev0 = gpu.Allocate<int>(512); int gridSize = 1; int blockSize = 512; gpu.Launch(gridSize, blockSize, "aaa", dev0); int[] host0 = new int[512]; gpu.CopyFromDevice<int>(dev0, host0); gpu.FreeAll(); Console.WriteLine(TID + " thread done."); Console.ReadKey(); } } class Program { static void Main(string[] args) { GPGPU gpu = CudafyHost.GetDevice(); CudafyModule module = CudafyModule.TryDeserialize(); if (module == null || !module.TryVerifyChecksums()) { module = CudafyTranslator.Cudafy(); module.Serialize(); } if (!gpu.IsModuleLoaded(module.Name)) { gpu.LoadModule(module); } if (!gpu.IsMultithreadingEnabled) { gpu.EnableMultithreading(); } List<Thread> threadArray = new List<Thread>(); for (int i = 0; i < 10; i++) { Worker w = new Worker() { gpu = gpu, TID=i }; Thread t = new Thread(w.test); t.Start(); threadArray.Add(t); } } [Cudafy] public static void aaa(GThread thread, int[] a) { int tid = thread.threadIdx.x; a[tid] = 1; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)