From 8e57db54892d15aa57654f6eb37279f2d89efe6e Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 25 Mar 2010 17:17:38 +0000 Subject: [PATCH] Add BAMBOOCOMPILETIME flag into the state class. When this flag is set, only excute Bamboo schedule analysis and report the time --- .../Analysis/Scheduling/MCImplSynthesis.java | 40 ++++++++++++++----- .../Analysis/Scheduling/ScheduleAnalysis.java | 8 ++-- .../Scheduling/ScheduleSimulator.java | 6 +++ Robust/src/IR/State.java | 28 +++++++------ Robust/src/Main/Main.java | 14 ++++--- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/Robust/src/Analysis/Scheduling/MCImplSynthesis.java b/Robust/src/Analysis/Scheduling/MCImplSynthesis.java index fbac0574..08792bf1 100644 --- a/Robust/src/Analysis/Scheduling/MCImplSynthesis.java +++ b/Robust/src/Analysis/Scheduling/MCImplSynthesis.java @@ -101,9 +101,11 @@ public class MCImplSynthesis { // Create a new output stream for the stcriticalPathandard output. PrintStream stdout = null; try { + if(!state.BAMBOOCOMPILETIME) { stdout = new PrintStream( new FileOutputStream(this.state.outputdir + "SimulatorResult_" + this.coreNum + ".out")); + } } catch (Exception e) { // Sigh. Couldn't open the file. System.out.println("Redirect: Unable to open output file!"); @@ -118,7 +120,9 @@ public class MCImplSynthesis { //origOut.println ("Test output via 'origOut' reference."); // Set the System out and err streams to use our replacements. - System.setOut(stdout); + if(!state.BAMBOOCOMPILETIME) { + System.setOut(stdout); + } Vector scheduling = null; Vector schedulinggraph = null; @@ -164,8 +168,10 @@ public class MCImplSynthesis { int threshold = this.scheduleThreshold; // simulate the generated schedulings and try to optimize it do { + if(!state.BAMBOOCOMPILETIME) { System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n"); System.out.print("Simulate and optimize round: #" + tryindex + ": \n"); + } gid += newscheduleGraphs.size(); if(scheduleGraphs != null) { for(int i = 0; i < scheduleGraphs.size(); i++) { @@ -219,24 +225,31 @@ public class MCImplSynthesis { selectedSchedulings.elementAt(0)); selectedSimExeGraph_bk = selectedSimExeGraphs.elementAt(0); + if(!state.BAMBOOCOMPILETIME) { System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n"); System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + } tryindex++; threshold = this.scheduleThreshold; } else if(tmpexetime == bestexetime) { + if(!state.BAMBOOCOMPILETIME) { System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n"); System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + } tryindex++; - threshold = this.scheduleThreshold; - if((Math.abs(rand.nextInt()) % 100) < this.probThreshold) { + threshold += 10; + if((threshold > 40) || + ((Math.abs(rand.nextInt()) % 100) < this.probThreshold + 10)) { break; } } else { + if(!state.BAMBOOCOMPILETIME) { System.out.print("end of: #" + tryindex + " (bestexetime: " + bestexetime + ")\n"); System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + } tryindex++; if(threshold == this.scheduleThreshold) { if(scheduleGraphs != null) { @@ -253,13 +266,14 @@ public class MCImplSynthesis { selectedSimExeGraphs.addElement(selectedSimExeGraph_bk); } threshold += 10; - if((Math.abs(rand.nextInt()) % 100) < this.probThreshold + 1) { + if( (threshold > 40) || + ((Math.abs(rand.nextInt()) % 100) < this.probThreshold + 1)) { break; } - //break; + break; } - //if(tooptimize) { + if(tooptimize) { // try to optimize the best one scheduling //do { newscheduleGraphs = optimizeScheduling(scheduleGraphs, @@ -286,9 +300,9 @@ public class MCImplSynthesis { scheduleGraphs.removeElementAt(selectedSchedulings.elementAt(0)); selectedSimExeGraphs.removeElementAt(0); } - /*} else { + } else { break; - }*/ + } }while(newscheduleGraphs != null); // TODO: could it possibly lead to endless loop? if(scheduleGraphs != null) { @@ -308,16 +322,22 @@ public class MCImplSynthesis { td2maincd.clear(); td2maincd = null; + if(!state.BAMBOOCOMPILETIME) { System.out.print("+++++++++++++++++++++++++++++++++++++++++++++++++++\n"); + } System.out.print("selected bestexetime: " + bestexetime + "\n"); + if(!state.BAMBOOCOMPILETIME) { String path = this.state.outputdir + "scheduling_selected.dot"; SchedulingUtil.printScheduleGraph(path, schedulinggraph); + } // Close the streams. try { + if(!state.BAMBOOCOMPILETIME) { stdout.close(); stdout = null; System.setOut(origOut); + } } catch (Exception e) { origOut.println("Redirect: Unable to close files!"); } @@ -955,6 +975,7 @@ public class MCImplSynthesis { } // flush the dependences and earliest start time + if(!state.BAMBOOCOMPILETIME) { it_cores = tooptimize.keySet().iterator(); while(it_cores.hasNext()) { int corenum = it_cores.next(); @@ -1002,6 +1023,7 @@ public class MCImplSynthesis { left -= ops.size(); } ops = null; + } } else { // there are spare cores, try to reorganize the tasks to the spare // cores @@ -1124,7 +1146,7 @@ public class MCImplSynthesis { CombinationUtil.allocateCombineGenerator(rootNodes, nodes2combine); Random rand = new Random(); while ((left > 0) && (cGen.nextGen())) { - //while ((left > 0) && (cGen.randomGen())) { + //while ((left > 0) && (cGen.randomGenE())) { if(Math.abs(rand.nextInt()) % 100 > this.generateThreshold) { Vector> combine = cGen.getCombine(); Vector sNodes = diff --git a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java index f2cce70a..44910e3d 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java +++ b/Robust/src/Analysis/Scheduling/ScheduleAnalysis.java @@ -1233,11 +1233,11 @@ public class ScheduleAnalysis { int gid = 1; boolean isBig = Math.pow(this.coreNum, reduceNum) > 1000; Random rand = new Random(); - if(false) { + if(isBig && state.BAMBOOCOMPILETIME) { CombinationUtil.RootsGenerator rGen = CombinationUtil.allocateRootsGenerator(sNodeVecs, this.coreNum); - while((!isBig || (gid <= this.scheduleThreshold)) && (rGen.nextGen())) { + while((gid <= this.scheduleThreshold) && (rGen.nextGen())) { // first get the chosen rootNodes Vector> rootNodes = rGen.getRootNodes(); Vector> nodes2combine = rGen.getNode2Combine(); @@ -1245,7 +1245,7 @@ public class ScheduleAnalysis { CombinationUtil.CombineGenerator cGen = CombinationUtil.allocateCombineGenerator(rootNodes, nodes2combine); - while((!isBig || (gid <= this.scheduleThreshold)) && (cGen.randomGenE())) { + while((gid <= this.scheduleThreshold) && (cGen.randomGenE())) { boolean implement = true; /*if(isBig) { implement = Math.abs(rand.nextInt()) % 100 > generateThreshold; @@ -1277,7 +1277,7 @@ public class ScheduleAnalysis { CombinationUtil.allocateRandomGenerator(sNodeVecs, this.coreNum); // random genenration - while((!isBig || (gid <= this.scheduleThreshold)) && (rGen.nextGen())) { + while((gid <= this.scheduleThreshold) && (rGen.nextGen())) { Vector> mapping = rGen.getMapping(); boolean implement = true; if(isBig) { diff --git a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java index 2459b5f5..23ea4b3f 100644 --- a/Robust/src/Analysis/Scheduling/ScheduleSimulator.java +++ b/Robust/src/Analysis/Scheduling/ScheduleSimulator.java @@ -130,7 +130,9 @@ public class ScheduleSimulator { while(it_scheduling.hasNext()) { Vector scheduling = (Vector)it_scheduling.next(); + if(!state.BAMBOOCOMPILETIME) { System.out.println("Scheduling index:" + scheduling.elementAt(0).getGid()); + } this.setScheduling(scheduling); Vector simexegraph = new Vector(); Vector checkpoints = new Vector(); @@ -156,12 +158,14 @@ public class ScheduleSimulator { it_scheduling = null; //} + if(!state.BAMBOOCOMPILETIME) { System.out.print("Selected schedulings with least exectution time " + processTime + ": \n\t"); for(int i = 0; i < selectedScheduling.size(); i++) { int gid = schedulings.elementAt(selectedScheduling.elementAt(i)).elementAt(0).getGid(); System.out.print(gid + ", "); } System.out.println(); + } return processTime; } @@ -479,12 +483,14 @@ public class ScheduleSimulator { this.coreNum, checkpoints); } + if(!state.BAMBOOCOMPILETIME) { System.out.println("Simulate scheduling #" + gid + ": "); System.out.println("\tTotal execution time is: " + this.processTime); System.out.println("\tUtility of cores: "); for(int j = 0; j < this.cores.size(); j++) { System.out.println("\t\tcore" + j + ": " + getUtility(j) + "%"); } + } return this.processTime; } diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index 1183d77c..ba44145e 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -58,8 +58,6 @@ public class State { public boolean FLATIRGRAPHTASKS=false; public boolean FLATIRGRAPHUSERMETHODS=false; public boolean FLATIRGRAPHLIBMETHODS=false; - public boolean MULTICORE=false; - public boolean MULTICOREGC=false; public boolean OWNERSHIP=false; public int OWNERSHIPALLOCDEPTH=3; public boolean OWNERSHIPWRITEDOTS=false; @@ -86,12 +84,7 @@ public class State { public boolean DISJOINTSNAPSTOPAFTER=false; public boolean OPTIONAL=false; - public boolean ARRAYBOUNDARYCHECK=true; - public boolean RAW=false; public boolean ARRAYPAD=false; - public boolean SCHEDULING=false; - public boolean USEPROFILE=false; - public String profilename = null; public boolean THREAD=false; public boolean CONSCHECK=false; public boolean INSTRUCTIONFAILURE=false; @@ -102,9 +95,7 @@ public class State { public boolean METHODEFFECTS=false; public static double TRUEPROB=0.8; public static boolean PRINTFLAT=false; - public static boolean PRINTSCHEDULING=false; - public static boolean PRINTSCHEDULESIM=false; - public static boolean PRINTCRITICALPATH=false; + //DSM options public boolean DSM=false; public boolean DSMTASK=false; @@ -122,12 +113,25 @@ public class State { public boolean DELAYCOMP=false; public boolean DUALVIEW=false; public boolean HYBRID=false; - //Other options + + // Bamboo options + public boolean MULTICORE=false; + public boolean MULTICOREGC=false; + public boolean BAMBOOCOMPILETIME = false; + public boolean ARRAYBOUNDARYCHECK=true; + public boolean RAW=false; + public boolean SCHEDULING=false; + public boolean USEPROFILE=false; + public static boolean PRINTSCHEDULING=false; + public static boolean PRINTSCHEDULESIM=false; + public static boolean PRINTCRITICALPATH=false; public int CORENUM = 1; public int CORENUM4GC = 0; + public String profilename = null; + public String outputdir = "/scratch/"; + //Other options public String structfile; public String main; - public String outputdir = "/scratch/"; public boolean INLINEATOMIC=false; public int inlineatomicdepth; public HashSet selfloops; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 03fff64b..a2c20268 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -140,6 +140,8 @@ public class Main { } else if (option.equals("-flatirlibmethods")) { state.FLATIRGRAPH=true; state.FLATIRGRAPHLIBMETHODS=true; + } else if (option.equals("-bamboocompiletime")) { + state.BAMBOOCOMPILETIME = true; } else if (option.equals("-multicore")) state.MULTICORE=true; else if (option.equals("-multicoregc")) @@ -505,16 +507,18 @@ public class Main { if(isDistributeInfo) { mcImplSynthesis.distribution(isDisAll, startnum); } else { - //double timeStartAnalysis = (double) System.nanoTime(); + double timeStartAnalysis = (double) System.nanoTime(); mcImplSynthesis.setScheduleThreshold(20); mcImplSynthesis.setProbThreshold(0); mcImplSynthesis.setGenerateThreshold(30); Vector scheduling = mcImplSynthesis.synthesis(); - //double timeEndAnalysis = (double) System.nanoTime(); - //double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) ); - //System.err.println("The analysis took" + dt + "sec."); - //System.exit(0); + double timeEndAnalysis = (double) System.nanoTime(); + if(state.BAMBOOCOMPILETIME) { + double dt = (timeEndAnalysis - timeStartAnalysis)/(Math.pow( 10.0, 9.0 ) ); + System.err.println("The analysis took" + dt + "sec."); + System.exit(0); + } // generate multicore codes if(state.MULTICORE) { -- 2.34.1