Beispiel #1
0
        public ColorClusterCreator(int width, int height)
        {
            List <byte> lColors = new List <byte>();

            foreach (var colorValue in Enum.GetValues(typeof(KnownColor)))
            {
                System.Drawing.Color color = System.Drawing.Color.FromKnownColor((KnownColor)colorValue);
                lColors.Add(color.R);
                lColors.Add(color.G);
                lColors.Add(color.B);
            }
            this.colors = lColors.ToArray();

            this.ImageWidth       = width;
            this.ImageHeight      = height;
            this.RGBPixels        = new byte[ImageWidth * ImageHeight * 3];
            this.GaussedRGBPixels = new byte[RGBPixels.Length];
            this.LabPixels        = new sbyte[ImageWidth * ImageHeight * 3];
            this.LabDistances     = new byte[ImageWidth * ImageHeight * 4];
            this.ClusterMap       = new int[ImageWidth * ImageHeight];
            clusterImage          = new Bitmap(ImageWidth, ImageHeight, PixelFormat.Format24bppRgb);

            this.gpuAccel             = new EasyCL();
            this.gpuAccel.Accelerator = AcceleratorDevice.GPU;
            this.gpuAccel.LoadKernel(OpenClKernels.Kernel);
        }
Beispiel #2
0
        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
        }
Beispiel #3
0
        void BenchmarkDevice(AcceleratorDevice Device)
        {
            Console.Write("\tSingle GFlops = ");
            base.WriteMessage(EasyCL.GetDeviceGFlops_Single(Device).ToString("0.00") + "GFlops");

            Console.Write("\tDouble GFlops = ");
            base.WriteMessage(EasyCL.GetDeviceGFlops_Double(Device).ToString("0.00") + "GFlops");

            Console.Write("\tMemory Bandwidth = ");
            base.WriteMessage(EasyCL.GetDeviceBandwidth_GBps(Device).ToString("0.00") + "GByte/s");
            base.WriteMessage("");
        }
Beispiel #4
0
        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");
        }
Beispiel #5
0
        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)");
        }