Example #1
0
        public static async Task Main(string[] args)
        {
            if (args.Length != 1)
            {
                throw new ArgumentException($"Illegal number of arguments. Expected: 1, Got {args.Length}");
            }

            var sizeFactor = uint.Parse(args[0]);
            var width      = 1_980 * sizeFactor;
            var height     = 1_020 * sizeFactor;

            var api = new NativeOpenClApi();

            var factory   = new PlatformFactory(api);
            var platforms = factory.GetPlatforms().ToArray();
            var platform  = platforms[0];

            System.Console.WriteLine($"{platform.Id} - {platform.Vendor}");

            var ctx = platform.CreateContext(platform.Devices);

            ctx.Notification += CtxOnNotification;

            var device = ctx.Devices.First();

            //var image = MandelbrotCalculator.Calculate(ctx, device, width, height);
            var image = await MandelbrotCalculator.CalculateAsync(ctx, device, width, height);

            SaveBitmap("mandelbrot", (int)width, (int)height, image.ToArray());

            ctx.Dispose();

            System.Console.WriteLine("--- Finished ---");
        }
Example #2
0
        public IReadOnlyCollection <byte> Compute()
        {
            var api      = new NativeOpenClApi();
            var factory  = new PlatformFactory(api);
            var platform = factory.GetPlatforms().First(f => f.Devices.Count == 1);
            var ctx      = platform.CreateContext(platform.Devices);
            var device   = ctx.Devices.Single();

            //Using synchronous calculation, since the MemoryDiagnoser is only able to fetch memory allocations by one thread
            var result = MandelbrotCalculator.Calculate(ctx, device, ActualWidth, ActualHeight);

            ctx.Dispose();
            return(result);
        }