Ejemplo n.º 1
0
        /// <summary>
        /// This function adds two numbers on the FPGA using <see cref="KpzKernelsInterface.TestAdd(SimpleMemory)"/>.
        /// </summary>
        public static uint TestAddWrapper(this KpzKernelsInterface kernels, uint a, uint b)
        {
            var sm = new SimpleMemory(3);

            sm.WriteUInt32(0, a);
            sm.WriteUInt32(1, b);
            kernels.TestAdd(sm);
            return(sm.ReadUInt32(2));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is a wrapper for running the KPZ algorithm on the FPGA.
        /// </summary>
        /// <param name="kernels"></param>
        /// <param name="hostGrid">
        ///     This is the grid of initial <see cref="KpzNode"/> items for the algorithm to work on.
        /// </param>
        /// <param name="pushToFpga">
        ///     If this parameter is false, the FPGA will work on the grid currently available in it,
        ///     instead of the grid in the <see cref="hostGrid"/> parameter.
        /// </param>
        /// <param name="testMode">
        ///     does several things:
        ///     <list type="bullet">
        ///         <item>
        ///             if it is true, <see cref="KpzKernels.RandomlySwitchFourCells(bool)"/> always switches the cells
        ///             if it finds an adequate place,
        ///         </item>
        ///         <item>
        ///             it also does only a single poke, then sends the grid back to the host so that the algorithm
        ///             can be analyzed in the step-by-step window.
        ///         </item>
        ///     </list>
        /// </param>
        /// <param name="randomSeed1">is a random seed for the algorithm.</param>
        /// <param name="randomSeed2">is a random seed for the algorithm.</param>
        /// <param name="numberOfIterations">is the number of iterations to perform.</param>
        public static void DoIterationsWrapper(this KpzKernelsInterface kernels, KpzNode[,] hostGrid, bool pushToFpga,
                                               bool testMode, ulong randomSeed1, ulong randomSeed2, uint numberOfIterations)
        {
            SimpleMemory sm = new SimpleMemory(KpzKernels.SizeOfSimpleMemory);

            if (pushToFpga)
            {
                CopyParametersToMemory(sm, testMode, randomSeed1, randomSeed2, numberOfIterations);
                CopyFromGridToSimpleMemory(hostGrid, sm);
            }

            kernels.DoIterations(sm);
            CopyFromSimpleMemoryToGrid(hostGrid, sm);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function generates random numbers on the FPGA using
        /// <see cref="KpzKernelsInterface.TestPrng(SimpleMemory)"/>.
        /// </summary>
        public static uint[] TestPrngWrapper(this KpzKernelsInterface kernels)
        {
            var numbers = new uint[KpzKernels.GridWidth * KpzKernels.GridHeight];
            var sm      = new SimpleMemory(KpzKernels.SizeOfSimpleMemory);

            CopyParametersToMemory(sm, false, 0x5289a3b89ac5f211, 0x5289a3b89ac5f211, 0);

            kernels.TestPrng(sm);

            for (int i = 0; i < KpzKernels.GridWidth * KpzKernels.GridHeight; i++)
            {
                numbers[i] = sm.ReadUInt32(i);
            }

            return(numbers);
        }