private List <Command> GetProgramCommands(JSProgram program) { (CDFG cdfg, _) = TestTools.ParseProgram(program); TestCommandExecutor executor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(executor); programExecutor.TimeBetweenCommands = 0; programExecutor.ShowEmptyRectangles = false; programExecutor.Run(10, 10, cdfg, false); return(executor.Commands); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { CompilerOptions.PROGRAM_FOLDER_PATH = PROGRAMS_FOLDER_PATH; var programData = InlineProgram.LoadProgram("Basic protocol for E. coli Quick"); //var programData = InlineProgram.LoadProgram("showcasing using inline program block"); //var programData = InlineProgram.LoadProgram("UsingDiluter3"); var sassdad = XmlParser.Parse("<xml xmlns='http://www.w3.org/1999/xhtml'><variables><variable type='' id='gZ,c_HQgu:,yfA:J+Lxt'>input_fluid_name</variable></variables><block type='start' id='7skRs`d%@XtBz=rV_7{/' x='528' y='219'><statement name='program'><block type='inputDeclaration' id='2lbQ[al;v|T3G{$fy9Tn'><field name='inputName' id='gZ,c_HQgu:,yfA:J+Lxt' variabletype=''>asd</field><field name='inputAmount'>1</field></block></statement></block></xml>"); for (int i = 0; i < 1; i++) { BenchmarkExecutor executor = new BenchmarkExecutor(); ProgramExecutor <string> CurrentlyExecutionProgram = new ProgramExecutor <string>(executor); CurrentlyExecutionProgram.TimeBetweenCommands = 0; CurrentlyExecutionProgram.ShowEmptyRectangles = false; CurrentlyExecutionProgram.EnableOptimizations = true; CurrentlyExecutionProgram.EnableGarbageCollection = true; CurrentlyExecutionProgram.EnableSparseElectrodes = false; CurrentlyExecutionProgram.Run(45, 45, programData.cdfg, false); } this.Close(); //Run in another thread to not block the UI await Task.Run(() => { SettingsInfo settings = new SettingsInfo(); settings.LoadSettings(SETTINGS_FILE_PATH); this.Updater = new WebUpdater(Browser, settings); Browser.Load("costum://index.html"); Browser.JavascriptObjectRepository.Register("saver", new Saver(Browser), true); Browser.JavascriptObjectRepository.Register("webUpdater", Updater, true); //Wait for the MainFrame to finish loading Browser.FrameLoadEnd += async(s, args) => { //Wait for the MainFrame to finish loading if (args.Frame.IsMain) { //Run in another thread to not block the UI await Task.Run(() => { GiveSettingsToJS(settings); GiveProgramsToJS(); }); } }; }); }
private void RunSimulator(CDFG cdfg, bool alreadyOptimized) { lock (simulatorLocker) { if (CurrentlyExecutionProgram != null) { CurrentlyExecutionProgram.KeepRunning.Cancel(); } simulatorThread?.Join(); simulatorThread = new Thread(() => { try { int boardWidth = Settings.BoardWidth; int boardHeight = Settings.BoardHeight; int timeBetweenCommands = (int)((1f / Settings.CommandFrequency) * 1000); using (SimulatorConnector executor = new SimulatorConnector(Browser, boardWidth, boardHeight)) { CurrentlyExecutionProgram = new ProgramExecutor<string>(executor); CurrentlyExecutionProgram.TimeBetweenCommands = timeBetweenCommands; CurrentlyExecutionProgram.ShowEmptyRectangles = Settings.ShowEmptyRectangles; CurrentlyExecutionProgram.EnableOptimizations = Settings.EnableOptimizations; CurrentlyExecutionProgram.EnableGarbageCollection = Settings.EnableGC; CurrentlyExecutionProgram.EnableSparseElectrodes = Settings.EnableSparseBoard; CurrentlyExecutionProgram.Run(boardWidth, boardHeight, cdfg, alreadyOptimized); } } catch (InternalRuntimeException e) { Browser.ExecuteScriptAsync($"ShowUnexpectedError(\"{e.Message.Replace('\"', '\'')}\");"); } catch (RuntimeException e) { Browser.ExecuteScriptAsync($"ShowUnexpectedError(\"{e.Message.Replace('\"', '\'')}\");"); } catch (ThreadInterruptedException) { } catch (Exception e) { Debug.WriteLine(e.Message + Environment.NewLine + e.StackTrace); } }); simulatorThread.Start(); } }
private static void Main(string[] args) { ulong? seed = null; int? numPrograms = null; int? parallelism = null; FuzzlynOptions options = null; bool help = false; bool dumpOptions = false; bool? output = null; bool? executePrograms = null; bool? enableChecksumming = null; bool? reduce = null; bool? reduceInChildProcesses = null; string reduceDebugGitDir = null; string removeFixed = null; bool? stats = null; OptionSet optionSet = new OptionSet { { "seed=|s=", "Seed to use when generating a single program", (ulong v) => seed = v }, { "parallelism=", "Number of cores to use", (int?p) => parallelism = p }, { "num-programs=|n=", "Number of programs to generate", (int v) => numPrograms = v }, { "options=", "Path to options.json. Command-line options will override options from this file.", s => options = JsonConvert.DeserializeObject <FuzzlynOptions>(File.ReadAllText(s)) }, { "dump-options", "Dump options to stdout and do nothing else", v => dumpOptions = v != null }, { "output-source", "Output program source instead of feeding them directly to Roslyn and execution", v => output = v != null }, { "execute-programs", "Accept programs to execute on stdin and report back differences", v => executePrograms = v != null }, { "checksum", "Enable or disable checksumming in the generated code", v => enableChecksumming = v != null }, { "reduce", "Reduce program to a minimal example", v => reduce = v != null }, { "reduce-use-child-processes", "Check reduced example candidates in child processes", v => reduceInChildProcesses = v != null }, { "reduce-debug-git-dir=", "Create reduce path in specified dir (must not exists beforehand)", v => reduceDebugGitDir = v }, { "remove-fixed=", "Remove fixed programs in directory", v => removeFixed = v }, { "stats", "Generate a bunch of programs and record their sizes", v => stats = v != null }, { "help|h", v => help = v != null } }; string error = null; try { List <string> leftover = optionSet.Parse(args); if (leftover.Any()) { error = "Unknown arguments: " + string.Join(" ", leftover); } } catch (OptionException ex) { error = ex.Message; } if (error != null) { Console.WriteLine("Fuzzlyn: {0}", error); Console.WriteLine("Use --help for help."); return; } if (help) { Console.WriteLine("Usage: fuzzlyn.exe"); optionSet.WriteOptionDescriptions(Console.Out); return; } if (executePrograms.HasValue && executePrograms.Value) { ProgramExecutor.Run(); return; } if (options == null) { options = new FuzzlynOptions(); } if (seed.HasValue) { options.Seed = seed.Value; } if (numPrograms.HasValue) { options.NumPrograms = numPrograms.Value; } if (parallelism.HasValue) { options.Parallelism = parallelism.Value; } if (output.HasValue) { options.Output = output.Value; } if (enableChecksumming.HasValue) { options.EnableChecksumming = enableChecksumming.Value; } if (reduce.HasValue) { options.Reduce = reduce.Value; } if (reduceInChildProcesses.HasValue) { options.ReduceWithChildProcesses = reduceInChildProcesses.Value; } if (stats.HasValue) { options.Stats = stats.Value; } if (options.NumPrograms != 1 && options.Seed.HasValue) { Console.WriteLine("Error: Must specify exactly 1 program if a seed is specified."); return; } if (options.Reduce && !options.Seed.HasValue) { Console.WriteLine("Error: Cannot reduce without a seed."); return; } if (dumpOptions) { Console.Write(JsonConvert.SerializeObject(options, Formatting.Indented)); return; } string val = Environment.GetEnvironmentVariable("COMPlus_TieredCompilation"); if (val != "0") { Console.WriteLine( "Please set the COMPlus_TieredCompilation environment variable " + "to \"0\" before starting Fuzzlyn."); Console.WriteLine("For cmd use \"set COMPlus_TieredCompilation=0\"."); Console.WriteLine("For powershell use \"$env:COMPlus_TieredCompilation='0'\""); Console.WriteLine("For bash use \"export COMPlus_TieredCompilation=0\""); Console.WriteLine("For Visual Studio, check the debug tab"); } else if (removeFixed != null) { RemoveFixedPrograms(options, removeFixed); } else if (options.Reduce) { ReduceProgram(options, reduceDebugGitDir); } else if (options.Stats) { GenerateProgramsAndGetStats(options); } else if (options.Output) { GenerateProgramsAndOutput(options); } else { GenerateProgramsAndCheck(options); } if (Debugger.IsAttached) { Console.ReadLine(); } }
static void Main(string[] args) { if (!Directory.Exists("unoptimizedPrograms")) { Directory.CreateDirectory("unoptimizedPrograms"); } List <perf_data> unoptimizedDatas = new List <perf_data>(); List <perf_data> optimizedDatas = new List <perf_data>(); List <perf_data> optimizedNoGCDatas = new List <perf_data>(); int nameID = 0; Random random = new Random(15231); TestTools tools = new TestTools(); for (int i = 0; i < 2000; i++) { try { perf_data unoptimizedData = new perf_data(); perf_data optimizedData = new perf_data(); perf_data optimizedNoGCData = new perf_data(); JSProgram program = new JSProgram(); program.Render = false; tools.ClearWorkspace(); program.CreateCDFG(3, 15, random); tools.ExecuteJS(program); string xml = tools.GetWorkspaceString(); var result = XmlParser.Parse(xml); if (result.Item2.Count > 0) { i--; continue; } int testCount = 5; float[] untimes = new float[testCount]; float[] optimes = new float[testCount]; Stopwatch watch = new Stopwatch(); for (int z = 0; z < testCount; z++) { watch.Reset(); watch.Start(); TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = false; programExecutor.EnableGarbageCollection = false; programExecutor.Run(100, 100, result.Item1, false); unoptimizedData.makespan = commandExecutor.ticks; watch.Stop(); untimes[z] = watch.ElapsedMilliseconds / (float)testCount; } { int minSize = 10; while (true) { try { result.Item1.Nodes.ForEach(x => x.dfg.Nodes.ForEach(qq => qq.value.Reset())); TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = false; programExecutor.EnableGarbageCollection = false; programExecutor.Run(minSize, minSize, result.Item1, false); break; } catch (Exception e) { if (minSize > 100) { Console.Write(e.Message + Environment.NewLine + e.StackTrace); } minSize++; } } unoptimizedData.size = minSize; } for (int z = 0; z < testCount; z++) { watch.Reset(); watch.Start(); TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = true; programExecutor.EnableGarbageCollection = true; programExecutor.Run(100, 100, result.Item1, false); optimizedData.makespan = commandExecutor.ticks; watch.Stop(); optimes[z] = watch.ElapsedMilliseconds / (float)testCount; } { int minSize = 10; while (true) { try { result.Item1.Nodes.ForEach(x => x.dfg.Nodes.ForEach(qq => qq.value.Reset())); TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = true; programExecutor.EnableGarbageCollection = true; programExecutor.Run(minSize, minSize, result.Item1, false); break; } catch (Exception) { minSize++; } } optimizedData.size = minSize; } { TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = true; programExecutor.EnableGarbageCollection = false; programExecutor.Run(100, 100, result.Item1, false); optimizedNoGCData.makespan = commandExecutor.ticks; } { int minSize = 10; while (true) { try { result.Item1.Nodes.ForEach(x => x.dfg.Nodes.ForEach(qq => qq.value.Reset())); TestCommandExecutor commandExecutor = new TestCommandExecutor(); ProgramExecutor <string> programExecutor = new ProgramExecutor <string>(commandExecutor); programExecutor.TimeBetweenCommands = 0; programExecutor.EnableOptimizations = true; programExecutor.EnableGarbageCollection = false; programExecutor.Run(minSize, minSize, result.Item1, false); break; } catch (Exception) { minSize++; } } optimizedNoGCData.size = minSize; } unoptimizedData.time = untimes.Min(); optimizedData.time = optimes.Min(); unoptimizedDatas.Add(unoptimizedData); optimizedDatas.Add(optimizedData); optimizedNoGCDatas.Add(optimizedNoGCData); string path = Path.Combine("unoptimizedPrograms", $"program_{nameID++}.bc"); File.WriteAllText(path, xml); } catch (Exception e) { //Console.Write(e.Message + Environment.NewLine + e.StackTrace); i--; } Console.WriteLine(i); } tools.AssemblyCleanup(); File.WriteAllText("unoptimized_data.txt", String.Join(Environment.NewLine, unoptimizedDatas.Select(x => x.makespan + " " + x.time.ToString(CultureInfo.InvariantCulture) + " " + x.size))); File.WriteAllText("optimized_data.txt", String.Join(Environment.NewLine, optimizedDatas.Select(x => x.makespan + " " + x.time.ToString(CultureInfo.InvariantCulture) + " " + x.size))); File.WriteAllText("optimized_no_gc_data.txt", String.Join(Environment.NewLine, optimizedNoGCDatas.Select(x => x.makespan + " " + x.size))); }
private static void Main(string[] args) { ulong? seed = null; int? numPrograms = null; int? parallelism = null; FuzzlynOptions options = null; bool help = false; bool dumpOptions = false; bool? output = null; bool? executePrograms = null; bool? enableChecksumming = null; bool? reduce = null; string removeFixed = null; OptionSet optionSet = new OptionSet { { "seed=|s=", "Seed to use when generating a single program", (ulong v) => seed = v }, { "parallelism=", "Number of cores to use", (int?p) => parallelism = p }, { "num-programs=|n=", "Number of programs to generate", (int v) => numPrograms = v }, { "options=", "Path to options.json. Command-line options will override options from this file.", s => options = JsonConvert.DeserializeObject <FuzzlynOptions>(File.ReadAllText(s)) }, { "dump-options", "Dump options to stdout and do nothing else", v => dumpOptions = v != null }, { "output-source", "Output program source instead of feeding them directly to Roslyn and execution", v => output = v != null }, { "execute-programs", "Accept programs to execute on stdin and report back differences", v => executePrograms = v != null }, { "checksum", "Enable or disable checksumming in the generated code", v => enableChecksumming = v != null }, { "reduce", "Reduce program to a minimal example", v => reduce = v != null }, { "remove-fixed=", "Remove fixed programs in directory", v => removeFixed = v }, { "help|h", v => help = v != null } }; string error = null; try { List <string> leftover = optionSet.Parse(args); if (leftover.Any()) { error = "Unknown arguments: " + string.Join(" ", leftover); } } catch (OptionException ex) { error = ex.Message; } if (error != null) { Console.WriteLine("Fuzzlyn: {0}", error); Console.WriteLine("Use --help for help."); return; } if (help) { Console.WriteLine("Usage: fuzzlyn.exe"); optionSet.WriteOptionDescriptions(Console.Out); return; } if (executePrograms.HasValue && executePrograms.Value) { ProgramExecutor.Run(); return; } if (options == null) { options = new FuzzlynOptions(); } if (seed.HasValue) { options.Seed = seed.Value; } if (numPrograms.HasValue) { options.NumPrograms = numPrograms.Value; } if (parallelism.HasValue) { options.Parallelism = parallelism.Value; } if (output.HasValue) { options.Output = output.Value; } if (enableChecksumming.HasValue) { options.EnableChecksumming = enableChecksumming.Value; } if (reduce.HasValue) { options.Reduce = reduce.Value; } if (options.NumPrograms != 1 && options.Seed.HasValue) { Console.WriteLine("Error: Must specify exactly 1 program if a seed is specified."); return; } if (options.NumPrograms != 1 && options.Output) { Console.WriteLine("Error: Must specify exactly 1 program if output is desired."); return; } if (options.Reduce && !options.Seed.HasValue) { Console.WriteLine("Error: Cannot reduce without a seed."); return; } if (dumpOptions) { Console.Write(JsonConvert.SerializeObject(options, Formatting.Indented)); return; } if (removeFixed != null) { RemoveFixedPrograms(options, removeFixed); return; } if (options.Reduce) { ReduceProgram(options); } else { GenerateProgram(options); } }