static void Run(string[] args) { int[] Primes = Enumerable.Range(2, 1000000).ToArray(); EasyCL cl = new EasyCL(); cl.Accelerator = Accelerator.Gpu; //You can also set the accelerator after loading the kernel cl.LoadKernel(IsPrime); //Load kernel string here, (Compiles in the background) cl.Invoke("GetIfPrime", Primes.Length, Primes); //Call Function By Name With Parameters //Primes now contains all Prime Numbers }
void RunCPU(int[] WorkSet) { base.WriteMessage("\nRun on CPU: " + AcceleratorDevice.CPU.ToString()); EasyCL cl = new EasyCL() { Accelerator = AcceleratorDevice.CPU }; cl.LoadKernel(IsPrime); cl.Invoke("GetIfPrime", 0, 1, WorkSet); //OpenCL uses a Cache. Real speed after that Stopwatch time = Stopwatch.StartNew(); cl.Invoke("GetIfPrime", 0, WorkSet.Length, WorkSet); time.Stop(); double performance = WorkSet.Length / (1000000.0 * time.Elapsed.TotalSeconds); base.WriteMessage("\t" + performance.ToString("0.00") + " MegaPrimes/Sec"); }
void AsyncTest(int[] WorkSet) { EasyCL cl = new EasyCL() { Accelerator = AcceleratorDevice.GPU }; cl.LoadKernel(IsPrime); Task primes = cl.InvokeAsync("GetIfPrime", WorkSet.Length, WorkSet); //OpenCL uses a Cache. Real speed after that Stopwatch time = Stopwatch.StartNew(); long i = 0; while (primes.IsCompleted == false) { i++; } double millis = time.Elapsed.TotalMilliseconds; base.WriteMessage(i + $" CPU cycles saved ({millis.ToString("0.00")}ms)"); }