Example #1
0
        /// <summary>
        /// This copies random seed from the host to the FPGA.
        /// </summary>
        public static SimpleMemory PushRandomSeed(this PrngTestInterface kernels, ulong seed)
        {
            SimpleMemory sm = new SimpleMemory(3);

            sm.WriteUInt32(0, (uint)seed); //LE: 0 is low byte, 1 is high byte
            sm.WriteUInt32(1, (uint)(seed >> 32));
            return(sm);
        }
Example #2
0
        public async Task <IHastlayer> InitializeHastlayer(bool verifyOutput, bool randomSeedEnable)
        {
            _verifyOutput     = verifyOutput;
            _randomSeedEnable = randomSeedEnable;

            LogItFunction("Creating Hastlayer Factory...");

            var hastlayer = await Hastlayer.Create();

            hastlayer.ExecutedOnHardware += (sender, e) =>
            {
                LogItFunction("Hastlayer timer: " +
                              e.HardwareExecutionInformation.HardwareExecutionTimeMilliseconds + "ms (net) / " +
                              e.HardwareExecutionInformation.FullExecutionTimeMilliseconds + " ms (total)"
                              );
            };

            var configuration = new HardwareGenerationConfiguration((await hastlayer.GetSupportedDevices()).First().Name);

            configuration.VhdlTransformerConfiguration().VhdlGenerationConfiguration = VhdlGenerationConfiguration.Debug;
            configuration.EnableCaching = false;

            LogItFunction("Generating hardware...");

            if (_kpzTarget.HastlayerParallelizedAlgorithm())
            {
                configuration.AddHardwareEntryPointType <KpzKernelsParallelizedInterface>();
                configuration.TransformerConfiguration().AddAdditionalInlinableMethod <RandomMwc64X>(r => r.NextUInt32());
            }
            else if (_kpzTarget.HastlayerPlainAlgorithm())
            {
                configuration.AddHardwareEntryPointType <KpzKernelsInterface>();
            }
            else // if (kpzTarget == KpzTarget.PrngTest)
            {
                configuration.AddHardwareEntryPointType <PrngTestInterface>();
            }


            var hardwareRepresentation = await hastlayer.GenerateHardware(new[] {
                typeof(KpzKernelsParallelizedInterface).Assembly,
                typeof(RandomMwc64X).Assembly
            }, configuration);

            await hardwareRepresentation.HardwareDescription.WriteSource(VhdlOutputFilePath);

            LogItFunction("Generating proxy...");

            if (_kpzTarget.HastlayerOnFpga())
            {
                var proxyConf = new ProxyGenerationConfiguration
                {
                    VerifyHardwareResults = _verifyOutput
                };

                if (_kpzTarget == KpzTarget.Fpga)
                {
                    Kernels = await hastlayer.GenerateProxy(
                        hardwareRepresentation,
                        new KpzKernelsInterface(),
                        proxyConf);
                }
                else if (_kpzTarget == KpzTarget.FpgaParallelized)
                {
                    KernelsParallelized = await hastlayer.GenerateProxy(
                        hardwareRepresentation,
                        new KpzKernelsParallelizedInterface(),
                        proxyConf);
                }
                else //if(kpzTarget == KpzTarget.PrngTest)
                {
                    KernelsP = await hastlayer.GenerateProxy(
                        hardwareRepresentation,
                        new PrngTestInterface(),
                        proxyConf);
                }

                LogItFunction("FPGA target detected");
            }
            else //if (kpzTarget == KpzTarget.HastlayerSimulation())
            {
                Kernels             = new KpzKernelsInterface();
                KernelsParallelized = new KpzKernelsParallelizedInterface();
                LogItFunction("Simulation target detected");
            }

            if (_kpzTarget.HastlayerPlainAlgorithm())
            {
                LogItFunction("Running TestAdd...");
                uint resultFpga = Kernels.TestAddWrapper(4313, 123);
                uint resultCpu  = 4313 + 123;
                if (resultCpu == resultFpga)
                {
                    LogItFunction(string.Format("Success: {0} == {1}", resultFpga, resultCpu));
                }
                else
                {
                    LogItFunction(string.Format("Fail: {0} != {1}", resultFpga, resultCpu));
                }
            }

            if (_kpzTarget == KpzTarget.PrngTest)
            {
                LogItFunction("Running TestPrng...");

                var   kernelsCpu = new PrngTestInterface();
                ulong randomSeed = 0x37a92d76a96ef210UL;
                var   smCpu      = kernelsCpu.PushRandomSeed(randomSeed);
                var   smFpga     = KernelsP.PushRandomSeed(randomSeed);
                LogItFunction("PRNG results:");
                bool success = true;

                for (int PrngTestIndex = 0; PrngTestIndex < 10; PrngTestIndex++)
                {
                    uint prngCpuResult  = kernelsCpu.GetNextRandom(smCpu);
                    uint prngFpgaResult = KernelsP.GetNextRandom(smFpga);
                    if (prngCpuResult != prngFpgaResult)
                    {
                        success = false;
                    }
                    LogItFunction(String.Format("{0}, {1}", prngCpuResult, prngFpgaResult));
                }

                if (success)
                {
                    LogItFunction("TestPrng succeeded!");
                }
                else
                {
                    LogItFunction("TestPrng failed!");
                }
            }
            return(hastlayer);
        }
Example #3
0
 /// <summary>It runs the PRNG on the FPGA and returns a random 32-bit uint.</summary>
 public static uint GetNextRandom(this PrngTestInterface kernels, SimpleMemory memory)
 {
     kernels.MWC64X(memory);
     return(memory.ReadUInt32(2));
 }