示例#1
0
        protected int[] Crunch()
        {
            int[] data = new int[displayPort[0] * displayPort[1]];

            if (DeviceName == "CPUOnly")
            {
                RestartWatch();
                //page resource
                MandelbrotExtensions.CalcCPUParallel(data, displayPort, areaView, maxIterations); // Single thread CPU
                ExecutionsDetails1 = ElapsedTime("CPU Only Mandelbrot");
            }
            else
            {
                Device device = MandelbrotInstance.ContextInstance.Devices.First(x => x.Name == DeviceName);

                if (_lastDevice != device)
                {
                    RestartWatch();
                    MandelbrotInstance.CompileKernel(device);
                    ExecutionsDetails2 = ElapsedTime("IL Compile - " + device.Name);
                    _lastDevice        = device;
                }


                RestartWatch();

                MandelbrotInstance.CalcGPU(ref data, displayPort, areaView, maxIterations); // ILGPU-CPU-Mode
                ExecutionsDetails3 = ElapsedTime("IL Run - " + DeviceName);
            }


            return(data);
        }
示例#2
0
        public async void AnimateMandelbrot()
        {
            int[] data = new int[displayPort[0] * displayPort[1]];

            Device device = MandelbrotInstance.ContextInstance.Devices.First(x => x.Name == DeviceName);

            if (_lastDevice != device)
            {
                RestartWatch();
                MandelbrotInstance.CompileKernel(device);
                ExecutionsDetails2 = ElapsedTime("IL Compile - " + device.Name);
                _lastDevice        = device;
            }


            MandelbrotInstance.InitGPURepeat(ref data, displayPort, areaView, maxIterations);
            StateHasChanged();
            float offsetX = -0.02f;
            float offsetY = 0.00562f;

            for (int i = 0; i < 500; i++)
            {
                // here we are in a long running loop, a user can navigate away or close a window which will
                // eventually result in an exception as this loop will continue to run


                if (_disposing || MandelbrotInstance.IsDisposing)
                {
                    break;
                }
                RestartWatch();
                MandelbrotInstance.CalcGPURepeat(ref data, displayPort, areaView, maxIterations); // ILGPU-CPU-Mode
                ExecutionsDetails2 = ElapsedTime($"IL Run - {DeviceName}");

                areaView[0] = areaView[0] * 0.98f + offsetX;
                areaView[1] = areaView[1] * 0.98f + offsetX;
                areaView[2] = areaView[2] * 0.98f + offsetY;
                areaView[3] = areaView[3] * 0.98f + offsetY;


                if (_disposing || MandelbrotInstance.IsDisposing)
                {
                    break;
                }
                RestartWatch();
                await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

                ExecutionsDetails3 = ElapsedTime("Web Server Render");
                StateHasChanged();
            }

            MandelbrotInstance.CleanupGPURepeat();
        }
示例#3
0
        public async Task RenderDevice(string deviceName)
        {
            areaView[0]   = -2.0f;
            areaView[1]   = 1.0f;
            areaView[2]   = -1.0f;
            areaView[3]   = 1.0f;
            maxIterations = 1000;

            int[] data = Crunch();
            await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

            StateHasChanged();
        }
示例#4
0
        protected async void UpdateSelected(ChangeEventArgs e)
        {
            DeviceName = e.Value.ToString();

            areaView[0]   = -2.0f;
            areaView[1]   = 1.0f;
            areaView[2]   = -1.0f;
            areaView[3]   = 1.0f;
            maxIterations = 1000;
            _computing    = true;
            int[] data = Crunch(DeviceName);
            await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

            _computing = false;
            StateHasChanged();
        }
示例#5
0
        private async void CanvasInitComplete(BasicCanvas basicCanvas)
        {
            // we could start the rendering process here rather than having a button click to start rendering.
            DisabledButtons = false;
            GetAvailableDevices();

            displayPort[0] = Canvas2D.Width;
            displayPort[1] = Canvas2D.Height;
            areaView[0]    = -2.0f;
            areaView[1]    = 1.0f;
            areaView[2]    = -1.0f;
            areaView[3]    = 1.0f;
            maxIterations  = 1000;

            int[] data = Crunch(DeviceName);
            await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

            StateHasChanged();
        }
        public async void AnimateMandelbrot()
        {
            // Target information
            float offsetX = -0.02f;
            float offsetY = 0.00562f;

            for (int i = 0; i < 500; i++)
            {
                if (_disposing || !MandelbrotInstance.IsActive)
                {
                    break;
                }

                // Set the next areaView size
                areaView[0] = areaView[0] * 0.98f + offsetX;
                areaView[1] = areaView[1] * 0.98f + offsetX;
                areaView[2] = areaView[2] * 0.98f + offsetY;
                areaView[3] = areaView[3] * 0.98f + offsetY;

                // Generate the next frame of this animation.
                RestartWatch();
                int[] data = await MandelbrotInstance.CalculateMandelbrot(areaView[0], areaView[1], areaView[2], areaView[3]); // ILGPU-CPU-Mode

                if (data == null || _disposing)
                {
                    break;
                }
                ExecutionsDetails2 = ElapsedTime($"IL Run - {DeviceName}");



                // Render the generated frame to the canvas.
                RestartWatch();
                await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

                StateHasChanged();

                ExecutionsDetails3 = ElapsedTime("Web Server Render");
            }
        }
        private async void CanvasInitComplete(BasicCanvas basicCanvas)
        {
            DeviceName = MandelbrotInstance.AcceleratorName();

            displayPort[0] = Canvas2D.Width;
            displayPort[1] = Canvas2D.Height;
            areaView[0]    = -2.0f;
            areaView[1]    = 1.0f;
            areaView[2]    = -1.0f;
            areaView[3]    = 1.0f;
            maxIterations  = 1000;

            if (_disposing || !MandelbrotInstance.IsActive)
            {
                return;
            }
            RestartWatch();
            MandelbrotInstance.SetDisplay(Canvas2D.Width, Canvas2D.Height);
            ExecutionsDetails1 = ElapsedTime($"IL Compile - {DeviceName}");

            if (_disposing || !MandelbrotInstance.IsActive)
            {
                return;
            }
            RestartWatch();
            int[] data = await MandelbrotInstance.CalculateMandelbrot(areaView[0], areaView[1], areaView[2], areaView[3]); // ILGPU-CPU-Mode

            ExecutionsDetails2 = ElapsedTime($"IL Run - {DeviceName}");

            if (data == null || _disposing)
            {
                return;
            }

            await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

            DisabledButtons = false;
            StateHasChanged(); // note StateHasChanged will force an update of controls on our razor page.
        }
示例#8
0
        protected int[] Crunch(string device)
        {
            int[] data = new int[displayPort[0] * displayPort[1]];

            if (DeviceName == "Single Thread")
            {
                RestartWatch();
                MandelbrotExtensions.CalcCPUSingle(data, displayPort, areaView, maxIterations); // Single thread CPU
                ExecutionsDetails1 = ElapsedTime("Single Thread");
            }
            else if (DeviceName == "Parallel CPU")
            {
                RestartWatch();
                MandelbrotExtensions.CalcCPUParallel(data, displayPort, areaView, maxIterations); // Single thread CPU
                ExecutionsDetails2 = ElapsedTime("Parallel CPU");
            }
            else
            {
                _computing = true;
                if (_lastDevice != _CPUDevice)
                {
                    RestartWatch();
                    MandelbrotInstance.CompileKernel(_CPUDevice);
                    ExecutionsDetails3 = ElapsedTime("IL Compile - " + _CPUDevice.Name);
                    _lastDevice        = _CPUDevice;
                }


                RestartWatch();

                MandelbrotInstance.CalcGPU(ref data, displayPort, areaView, maxIterations); // ILGPU-CPU-Mode
                _computing         = false;
                ExecutionsDetails4 = ElapsedTime("IL Run - " + _CPUDevice.Name);
            }
            return(data);
        }
示例#9
0
        public async void AnimateMandelbrot()
        {
            int[] data = new int[displayPort[0] * displayPort[1]];


            float offsetX = -0.02f;
            float offsetY = 0.00562f;

            switch (DeviceName)
            {
            case "Single Thread":

                for (int i = 0; i < 500; i++)
                {
                    if (_disposing)
                    {
                        break;
                    }
                    RestartWatch();

                    MandelbrotExtensions.CalcCPUSingle(data, displayPort, areaView, maxIterations);     // ILGPU-CPU-Mode
                    ExecutionsDetails3 = ElapsedTime($"Single Thread");

                    areaView[0] = areaView[0] * 0.98f + offsetX;
                    areaView[1] = areaView[1] * 0.98f + offsetX;
                    areaView[2] = areaView[2] * 0.98f + offsetY;
                    areaView[3] = areaView[3] * 0.98f + offsetY;

                    if (_disposing)
                    {
                        break;
                    }
                    RestartWatch();

                    await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

                    StateHasChanged();

                    ExecutionsDetails4 = ElapsedTime("Render Time");
                }



                break;


            case "Parallel CPU":


                for (int i = 0; i < 500; i++)
                {
                    if (_disposing)
                    {
                        break;
                    }

                    RestartWatch();
                    MandelbrotExtensions.CalcCPUParallel(data, displayPort, areaView, maxIterations);     // ILGPU-CPU-Mode
                    ExecutionsDetails3 = ElapsedTime($"CPU Parallel");

                    areaView[0] = areaView[0] * 0.98f + offsetX;
                    areaView[1] = areaView[1] * 0.98f + offsetX;
                    areaView[2] = areaView[2] * 0.98f + offsetY;
                    areaView[3] = areaView[3] * 0.98f + offsetY;

                    if (_disposing)
                    {
                        break;
                    }

                    RestartWatch();
                    await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

                    StateHasChanged();

                    ExecutionsDetails4 = ElapsedTime("Render Time");
                }


                break;


            default:
                _computing = true;

                if (_lastDevice != _CPUDevice)
                {
                    RestartWatch();
                    MandelbrotInstance.CompileKernel(_CPUDevice);
                    ExecutionsDetails2 = ElapsedTime("IL Compile - " + _CPUDevice.Name);
                    _lastDevice        = _CPUDevice;
                }

                MandelbrotInstance.InitGPURepeat(ref data, displayPort, areaView, maxIterations);

                for (int i = 0; i < 500; i++)
                {
                    if (_disposing)
                    {
                        break;
                    }

                    RestartWatch();

                    MandelbrotInstance.CalcGPURepeat(ref data, displayPort, areaView, maxIterations);     // ILGPU-CPU-Mode
                    ExecutionsDetails3 = ElapsedTime($"IL Run - {DeviceName}");

                    areaView[0] = areaView[0] * 0.98f + offsetX;
                    areaView[1] = areaView[1] * 0.98f + offsetX;
                    areaView[2] = areaView[2] * 0.98f + offsetY;
                    areaView[3] = areaView[3] * 0.98f + offsetY;

                    if (_disposing)
                    {
                        break;
                    }
                    RestartWatch();

                    await MandelbrotExtensions.Draw(Canvas2D, data, displayPort[0], displayPort[1], maxIterations, Color.Blue);

                    StateHasChanged();

                    ExecutionsDetails4 = ElapsedTime("Render Time");
                }
                MandelbrotInstance.CleanupGPURepeat();
                _computing = false;
                break;
            }
        }