コード例 #1
0
            public static void RunCore(IHostApi hostApi, Benchmark benchmark, BenchmarkActionCodegen codegenMode)
            {
                var target       = benchmark.Target;
                var job          = benchmark.Job;        // TODO: filter job (same as SourceCodePresenter does)?
                var unrollFactor = benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance);
                // var dummyUnrollFactor = 1 << 6; // TODO: as arg to CreateDummy()?

                // DONTTOUCH: these should be allocated together
                var instance      = Activator.CreateInstance(benchmark.Target.Type);
                var mainAction    = BenchmarkActionFactory.CreateRun(target, instance, codegenMode, unrollFactor);
                var idleAction    = BenchmarkActionFactory.CreateIdle(target, instance, codegenMode, unrollFactor);
                var setupAction   = BenchmarkActionFactory.CreateSetup(target, instance);
                var cleanupAction = BenchmarkActionFactory.CreateCleanup(target, instance);
                var dummy1        = BenchmarkActionFactory.CreateDummy();
                var dummy2        = BenchmarkActionFactory.CreateDummy();
                var dummy3        = BenchmarkActionFactory.CreateDummy();

                FillProperties(instance, benchmark);

                hostApi.WriteLine();
                foreach (var infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
                {
                    hostApi.WriteLine("// {0}", infoLine);
                }
                hostApi.WriteLine("// Job: {0}", job.DisplayInfo);
                hostApi.WriteLine();

                var engineParameters = new EngineParameters
                {
                    //HostApi = hostApi,
                    IsDiagnoserAttached = hostApi.IsDiagnoserAttached,
                    MainAction          = mainAction.InvokeMultiple,
                    Dummy1Action        = dummy1.InvokeSingle,
                    Dummy2Action        = dummy2.InvokeSingle,
                    Dummy3Action        = dummy3.InvokeSingle,
                    IdleAction          = idleAction.InvokeMultiple,
                    SetupAction         = setupAction.InvokeSingle,
                    CleanupAction       = cleanupAction.InvokeSingle,
                    TargetJob           = job,
                    OperationsPerInvoke = target.OperationsPerInvoke
                };

                var engine = job
                             .ResolveValue(InfrastructureMode.EngineFactoryCharacteristic, InfrastructureResolver.Instance)
                             .Create(engineParameters);

                engine.PreAllocate();

                setupAction.InvokeSingle();

                if (job.ResolveValue(RunMode.RunStrategyCharacteristic, EngineResolver.Instance)
                    != RunStrategy.ColdStart)
                {
                    engine.Jitting();                     // does first call to main action, must be executed after setup()!
                }
                if (hostApi.IsDiagnoserAttached)
                {
                    hostApi.AfterSetup();
                }

                var results = engine.Run();

                if (hostApi.IsDiagnoserAttached)
                {
                    hostApi.BeforeCleanup();
                }
                cleanupAction.InvokeSingle();

                hostApi.Print(results);                 // printing costs memory, do this after runs
            }
コード例 #2
0
            public static void RunCore(IHost host, BenchmarkCase benchmarkCase, BenchmarkActionCodegen codegenMode, IConfig config)
            {
                var target       = benchmarkCase.Descriptor;
                var job          = benchmarkCase.Job; // TODO: filter job (same as SourceCodePresenter does)?
                int unrollFactor = benchmarkCase.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvironmentResolver.Instance);

                // DONTTOUCH: these should be allocated together
                var instance               = Activator.CreateInstance(benchmarkCase.Descriptor.Type);
                var workloadAction         = BenchmarkActionFactory.CreateWorkload(target, instance, codegenMode, unrollFactor);
                var overheadAction         = BenchmarkActionFactory.CreateOverhead(target, instance, codegenMode, unrollFactor);
                var globalSetupAction      = BenchmarkActionFactory.CreateGlobalSetup(target, instance);
                var globalCleanupAction    = BenchmarkActionFactory.CreateGlobalCleanup(target, instance);
                var iterationSetupAction   = BenchmarkActionFactory.CreateIterationSetup(target, instance);
                var iterationCleanupAction = BenchmarkActionFactory.CreateIterationCleanup(target, instance);
                var dummy1 = BenchmarkActionFactory.CreateDummy();
                var dummy2 = BenchmarkActionFactory.CreateDummy();
                var dummy3 = BenchmarkActionFactory.CreateDummy();

                FillMembers(instance, benchmarkCase);

                host.WriteLine();
                foreach (string infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
                {
                    host.WriteLine("// {0}", infoLine);
                }
                host.WriteLine("// Job: {0}", job.DisplayInfo);
                host.WriteLine();

                var engineParameters = new EngineParameters
                {
                    Host = host,
                    WorkloadActionNoUnroll = invocationCount =>
                    {
                        for (int i = 0; i < invocationCount; i++)
                        {
                            workloadAction.InvokeSingle();
                        }
                    },
                    WorkloadActionUnroll   = workloadAction.InvokeMultiple,
                    Dummy1Action           = dummy1.InvokeSingle,
                    Dummy2Action           = dummy2.InvokeSingle,
                    Dummy3Action           = dummy3.InvokeSingle,
                    OverheadActionNoUnroll = invocationCount =>
                    {
                        for (int i = 0; i < invocationCount; i++)
                        {
                            overheadAction.InvokeSingle();
                        }
                    },
                    OverheadActionUnroll   = overheadAction.InvokeMultiple,
                    GlobalSetupAction      = globalSetupAction.InvokeSingle,
                    GlobalCleanupAction    = globalCleanupAction.InvokeSingle,
                    IterationSetupAction   = iterationSetupAction.InvokeSingle,
                    IterationCleanupAction = iterationCleanupAction.InvokeSingle,
                    TargetJob           = job,
                    OperationsPerInvoke = target.OperationsPerInvoke,
                    MeasureGcStats      = config.HasMemoryDiagnoser(),
                    BenchmarkName       = FullNameProvider.GetBenchmarkName(benchmarkCase)
                };

                using (var engine = job
                                    .ResolveValue(InfrastructureMode.EngineFactoryCharacteristic, InfrastructureResolver.Instance)
                                    .CreateReadyToRun(engineParameters))
                {
                    var results = engine.Run();

                    host.ReportResults(results); // printing costs memory, do this after runs
                }
            }
コード例 #3
0
            public static void RunCore(IHost host, Benchmark benchmark, BenchmarkActionCodegen codegenMode, IConfig config)
            {
                var target       = benchmark.Target;
                var job          = benchmark.Job; // TODO: filter job (same as SourceCodePresenter does)?
                var unrollFactor = benchmark.Job.ResolveValue(RunMode.UnrollFactorCharacteristic, EnvResolver.Instance);

                // DONTTOUCH: these should be allocated together
                var instance               = Activator.CreateInstance(benchmark.Target.Type);
                var mainAction             = BenchmarkActionFactory.CreateRun(target, instance, codegenMode, unrollFactor);
                var idleAction             = BenchmarkActionFactory.CreateIdle(target, instance, codegenMode, unrollFactor);
                var globalSetupAction      = BenchmarkActionFactory.CreateGlobalSetup(target, instance);
                var globalCleanupAction    = BenchmarkActionFactory.CreateGlobalCleanup(target, instance);
                var iterationSetupAction   = BenchmarkActionFactory.CreateIterationSetup(target, instance);
                var iterationCleanupAction = BenchmarkActionFactory.CreateIterationCleanup(target, instance);
                var dummy1 = BenchmarkActionFactory.CreateDummy();
                var dummy2 = BenchmarkActionFactory.CreateDummy();
                var dummy3 = BenchmarkActionFactory.CreateDummy();

                FillMembers(instance, benchmark);

                host.WriteLine();
                foreach (var infoLine in BenchmarkEnvironmentInfo.GetCurrent().ToFormattedString())
                {
                    host.WriteLine("// {0}", infoLine);
                }
                host.WriteLine("// Job: {0}", job.DisplayInfo);
                host.WriteLine();

                var engineParameters = new EngineParameters
                {
                    Host                   = host,
                    MainAction             = mainAction.InvokeMultiple,
                    Dummy1Action           = dummy1.InvokeSingle,
                    Dummy2Action           = dummy2.InvokeSingle,
                    Dummy3Action           = dummy3.InvokeSingle,
                    IdleAction             = idleAction.InvokeMultiple,
                    GlobalSetupAction      = globalSetupAction.InvokeSingle,
                    GlobalCleanupAction    = globalCleanupAction.InvokeSingle,
                    IterationSetupAction   = iterationSetupAction.InvokeSingle,
                    IterationCleanupAction = iterationCleanupAction.InvokeSingle,
                    TargetJob              = job,
                    OperationsPerInvoke    = target.OperationsPerInvoke,
                    MeasureGcStats         = config.HasMemoryDiagnoser()
                };

                var engine = job
                             .ResolveValue(InfrastructureMode.EngineFactoryCharacteristic, InfrastructureResolver.Instance)
                             .Create(engineParameters);

                globalSetupAction.InvokeSingle();
                iterationSetupAction.InvokeSingle();

                if (job.ResolveValue(RunMode.RunStrategyCharacteristic, EngineResolver.Instance).NeedsJitting())
                {
                    engine.Jitting(); // does first call to main action, must be executed after setup()!
                }
                iterationCleanupAction.InvokeSingle();

                var results = engine.Run();

                globalCleanupAction.InvokeSingle();

                host.ReportResults(results); // printing costs memory, do this after runs
            }