static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            dim3 grid  = new dim3(< gridX >, <gridY>, 1);
            dim3 block = new dim3(< blockX >, <blockY>, 1);

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Filter());

            // run the method on GPU
            wrapper.SetDistrib(grid, block).ParForGPU(output, input, (int)image.Width, (int)image.Height);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Parallel2D GPU time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-05-dice-gpu/denoised.bmp");
        }
示例#2
0
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int window = 3;

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Program());

            // run the method on GPU
            wrapper.ParForGPU(output, input, (int)image.Width, (int)image.Height, window);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Naive GPU time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-03-naive-gpu/denoised.bmp");
        }
示例#3
0
        static void Main(string[] args)
        {
            int currentDevice;

            cuda.GetDevice(out currentDevice);
            cudaDeviceProp prop;

            cuda.GetDeviceProperties(out prop, currentDevice);

            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            Stopwatch watch = new Stopwatch();

            watch.Start();

            int chunk;

            if ((prop.major >= 6) && (prop.minor == 0))
            {
                chunk = ((int)image.Height + (prop.multiProcessorCount / 2) - 1) / (prop.multiProcessorCount / 2);
            }
            else
            {
                chunk = ((int)image.Height + (prop.multiProcessorCount) - 1) / (prop.multiProcessorCount);
            }

            Console.Out.WriteLine("Chunk size = {0}", chunk);

            dim3 grid  = new dim3(16, ((int)image.Height + chunk - 1) / chunk, 1);
            dim3 block = new dim3(128, 1, 1);

            // create an instance of runner
            HybRunner runner = HybRunner.Cuda();
            // wrap a new instance of Program
            dynamic wrapper = runner.Wrap(new Filter());

            // run the method on GPU
            wrapper.SetDistrib(grid, block).ParForGPU(output, input, (int)image.Width, (int)image.Height, chunk);
            cuda.DeviceSynchronize();

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            string kernelTime = String.Format("{0:0.00}", runner.LastKernelDuration.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"SweepSort GPU time : {time}");
            Console.WriteLine($"SweepSort GPU -- kernel time : {kernelTime}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-07-cache-aware-gpu/denoised.bmp");

            cuda.DeviceReset();
        }
示例#4
0
        static void Main(string[] args)
        {
            GrayBitmap image    = GrayBitmap.Load("../../images/lena_highres_greyscale_noise.bmp");
            GrayBitmap denoised = new GrayBitmap(image.Width, image.Height);

            ushort[] input  = image.PixelsUShort;
            ushort[] output = new ushort[image.Width * image.Height];

            int window = 3;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            NaiveCsharp(output, input, (int)image.Width, (int)image.Height, window);

            watch.Stop();
            string time = String.Format("{0:0.00}", watch.ElapsedMilliseconds * 1.0E-3);

            Console.WriteLine($"Parallel.For time : {time}");
            denoised.PixelsUShort = output;
            denoised.Save("../../output-02-parfor/denoised.bmp");
        }