Пример #1
0
        public void CalcGPURepeat(ref int[] buffer, int[] dispayPort, float[] viewArea, int max_iterations)
        {
            _computing = true;

            if (!_disposing)
            {
                ArrayViewExtensions.CopyFromCPU(_area, viewArea);
            }


            if (!_disposing)
            {
                // Launch kernel
                mandelbrot_kernel(_buffersize, _display, _area, max_iterations, _output.View);
            }


            // Reads data from the GPU buffer into a new CPU array.
            // Implicitly calls accelerator.DefaultStream.Synchronize() to ensure
            // that the kernel and memory copy are completed first.
            if (!_disposing)
            {
                _output.CopyToCPU(buffer);
            }

            _computing = false;

            return;
        }
Пример #2
0
        public async Task <bool> CalcGPU(int[] buffer, float[] viewArea)
        {
            bool result = false;

            if (buffer.Length != _buffersize)
            {
                return(false);
            }

            // copy parameters to GPU inbound buffer
            ArrayViewExtensions.CopyFromCPU(_area, viewArea);

            if (IsActive && !_computing && !_disposing)
            {
                // Launch kernel
                _computing = true;

                mandelbrot_kernel(_stream, _buffersize, _display, _area, _iterations, _output.View);
                await _stream.SynchronizeAsync(); // wait for the stream to synchronize

                result     = IsActive;
                _computing = false;
            }


            // Reads data from the GPU buffer into a CPU array.
            // that the kernel and memory copy are completed first.
            if (IsActive && !_disposing)
            {
                _computing = true;
                _output.CopyToCPU(buffer);
                result     = IsActive;
                _computing = false;
            }

            return(result && !_disposing);
        }