Exemplo n.º 1
0
        /// <summary>
        /// This function is for testing how Hastlayer works by running a random generator, writing the results into
        /// SimpleMemory.
        /// </summary>
        public void TestPrng(SimpleMemory memory)
        {
            var kernels = new KpzKernels();

            kernels.InitializeParametersFromMemory(memory);
            var numberOfStepsInIteration = KpzKernels.GridWidth * KpzKernels.GridHeight;

            for (int i = 0; i < numberOfStepsInIteration; i++)
            {
                memory.WriteUInt32(i, kernels.Random1.NextUInt32());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calling this function on the host starts the KPZ algorithm.
        /// </summary>
        public virtual void DoIterations(SimpleMemory memory)
        {
            var kernels = new KpzKernels();

            kernels.CopyFromSimpleMemoryToRawGrid(memory);
            kernels.InitializeParametersFromMemory(memory);
            // Assume that GridWidth and GridHeight are 2^N.
            var numberOfStepsInIteration = kernels.TestMode ? 1 : KpzKernels.GridWidth * KpzKernels.GridHeight;

            for (int j = 0; j < kernels.NumberOfIterations; j++)
            {
                for (int i = 0; i < numberOfStepsInIteration; i++)
                {
                    // We randomly choose a point on the grid. If there is a pyramid or hole, we randomly switch them.
                    kernels.RandomlySwitchFourCells(kernels.TestMode);
                }
            }

            kernels.CopyToSimpleMemoryFromRawGrid(memory);
        }