X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FMain%2FMain.java;h=cb8bf768501a1bda095d1cabb30f4c949a924c5f;hb=18ba60849200d7a58a47baa07074b90cdcfb7382;hp=e9b82b964763480cc99e87e55f83288f0918c7c6;hpb=4da6c0eeeab1ffc76a4ee5e8cc1a2f992e90c18a;p=IRC.git diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index e9b82b96..cb8bf768 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -6,6 +6,7 @@ import java.io.Reader; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileInputStream; +import java.util.Hashtable; import java.util.Iterator; import java.util.Set; import java.util.Vector; @@ -20,6 +21,7 @@ import IR.ClassDescriptor; import IR.State; import IR.TaskDescriptor; import IR.TypeUtil; +import Analysis.Scheduling.MCImplSynthesis; import Analysis.Scheduling.Schedule; import Analysis.Scheduling.ScheduleAnalysis; import Analysis.Scheduling.ScheduleSimulator; @@ -38,6 +40,10 @@ import Analysis.Locality.GenerateConversions; import Analysis.Prefetch.PrefetchAnalysis; import Analysis.FlatIRGraph.FlatIRGraph; import Analysis.OwnershipAnalysis.OwnershipAnalysis; +import Analysis.MLP.MLPAnalysis; +import Analysis.Loops.*; +import IR.MethodDescriptor; +import IR.Flat.FlatMethod; import Interface.*; import Util.GraphNode; import Util.GraphNode.DFS; @@ -50,6 +56,11 @@ public class Main { public static void main(String args[]) throws Exception { String ClassLibraryPrefix="./ClassLibrary/"; State state=new State(); + Vector sourcefiles=new Vector(); + state.classpath.add("."); + + String outputdir = null; + boolean isDistributeInfo = false; for(int i=0; i -- probability of true branch"); System.out.println("-printflat -- print out flat representation"); @@ -145,76 +186,61 @@ public class Main { System.out.println("-ownallocdepth -- set allocation depth for ownership analysis"); System.out.println("-ownwritedots -- write ownership graphs; can be all results or just final results"); System.out.println("-ownaliasfile -- write a text file showing all detected aliases in program tasks"); + System.out.println("-optimize -- enable optimizations"); System.out.println("-optional -- enable optional arguments"); + System.out.println("-abcclose close the array boundary check"); + System.out.println("-scheduling do task scheduling"); + System.out.println("-mlp build mlp code"); + System.out.println("-mlp build mlp code, report progress and interim results"); + System.out.println("-multicore generate multi-core version binary"); + System.out.println("-numcore set the number of cores (should be used together with -multicore), defaultly set as 1"); + System.out.println("-raw generate raw version binary (should be used together with -multicore)"); + System.out.println("-interrupt generate raw version binary with interruption (should be used togethere with -raw)"); + System.out.println("-rawconfig config raw simulator as 4xn (should be used together with -raw)"); + System.out.println("-rawpath print out execute path information for raw version (should be used together with -raw)"); + System.out.println("-useprofile use profiling data for scheduling (should be used together with -raw)"); + System.out.println("-threadsimulate generate multi-thread simulate version binary"); + System.out.println("-rawuseio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version"); + System.out.println("-printscheduling -- print out scheduling graphs"); + System.out.println("-printschedulesim -- print out scheduling simulation result graphs"); System.out.println("-webinterface -- enable web interface"); System.out.println("-help -- print out help"); System.exit(0); } else { - readSourceFile(state, args[i]); + sourcefiles.add(args[i]); } } + //add default classpath + if (state.classpath.size()==1) + state.classpath.add(ClassLibraryPrefix); - readSourceFile(state, ClassLibraryPrefix+"System.java"); - readSourceFile(state, ClassLibraryPrefix+"String.java"); - readSourceFile(state, ClassLibraryPrefix+"HashSet.java"); - readSourceFile(state, ClassLibraryPrefix+"HashMap.java"); - readSourceFile(state, ClassLibraryPrefix+"HashMapIterator.java"); - readSourceFile(state, ClassLibraryPrefix+"HashEntry.java"); - readSourceFile(state, ClassLibraryPrefix+"Integer.java"); - readSourceFile(state, ClassLibraryPrefix+"StringBuffer.java"); - //if(!state.RAW) { - readSourceFile(state, ClassLibraryPrefix+"FileInputStream.java"); - readSourceFile(state, ClassLibraryPrefix+"InputStream.java"); - readSourceFile(state, ClassLibraryPrefix+"OutputStream.java"); - readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java"); - readSourceFile(state, ClassLibraryPrefix+"File.java"); - readSourceFile(state, ClassLibraryPrefix+"InetAddress.java"); - readSourceFile(state, ClassLibraryPrefix+"SocketInputStream.java"); - readSourceFile(state, ClassLibraryPrefix+"SocketOutputStream.java"); - //} - readSourceFile(state, ClassLibraryPrefix+"Math.java"); - readSourceFile(state, ClassLibraryPrefix+"gnu/Random.java"); - readSourceFile(state, ClassLibraryPrefix+"Vector.java"); - readSourceFile(state, ClassLibraryPrefix+"Enumeration.java"); - readSourceFile(state, ClassLibraryPrefix+"Dictionary.java"); - readSourceFile(state, ClassLibraryPrefix+"Writer.java"); - readSourceFile(state, ClassLibraryPrefix+"BufferedWriter.java"); - readSourceFile(state, ClassLibraryPrefix+"OutputStreamWriter.java"); - readSourceFile(state, ClassLibraryPrefix+"FileWriter.java"); - readSourceFile(state, ClassLibraryPrefix+"Date.java"); + BuildIR bir=new BuildIR(state); + TypeUtil tu=new TypeUtil(state, bir); + - if (state.TASK) { - readSourceFile(state, ClassLibraryPrefix+"Object.java"); - readSourceFile(state, ClassLibraryPrefix+"TagDescriptor.java"); - } else if (state.DSM) { - readSourceFile(state, ClassLibraryPrefix+"ThreadDSM.java"); - readSourceFile(state, ClassLibraryPrefix+"ObjectJavaDSM.java"); - readSourceFile(state, ClassLibraryPrefix+"Barrier.java"); - } else { - if (state.THREAD) { - readSourceFile(state, ClassLibraryPrefix+"Thread.java"); - readSourceFile(state, ClassLibraryPrefix+"ObjectJava.java"); - } else - readSourceFile(state, ClassLibraryPrefix+"ObjectJavaNT.java"); - } + SemanticCheck sc=new SemanticCheck(state,tu); + for(int i=0;i fss = ta.getFlagStates(cd); - SCC scc=GraphNode.DFS.computeSCC(fss); - if (scc.hasCycles()) { - for(int i=0; i taskinfo = new java.util.Hashtable(); - - int inindex = profiledata.indexOf('\n'); - while((inindex != -1) ) { - String inline = profiledata.substring(0, inindex); - profiledata = profiledata.substring(inindex + 1); - //System.printString(inline + "\n"); - int tmpinindex = inline.indexOf(','); - if(tmpinindex == -1) { - break; - } - String inname = inline.substring(0, tmpinindex); - String inint = inline.substring(tmpinindex + 1); - while(inint.startsWith(" ")) { - inint = inint.substring(1); - } - int duration = Integer.parseInt(inint); - taskinfo.put(inname, duration); - inindex = profiledata.indexOf('\n'); - } - - java.util.Random r=new java.util.Random(); - int tint = 0; - for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) { - ClassDescriptor cd=(ClassDescriptor) it_classes.next(); - if(cd.hasFlags()) { - Vector rootnodes=ta.getRootNodes(cd); - if(rootnodes!=null) { - for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) { - FlagState root=(FlagState)it_rootnodes.next(); - Vector allocatingTasks = root.getAllocatingTasks(); - if(allocatingTasks != null) { - for(int k = 0; k < allocatingTasks.size(); k++) { - TaskDescriptor td = (TaskDescriptor)allocatingTasks.elementAt(k); - Vector fev = (Vector)ta.getFEdgesFromTD(td); - int numEdges = fev.size(); - int total = 100; - for(int j = 0; j < numEdges; j++) { - FEdge pfe = fev.elementAt(j); - if(numEdges - j == 1) { - pfe.setProbability(total); - } else { - if((total != 0) && (total != 1)) { - do { - tint = r.nextInt()%total; - } while(tint <= 0); - } - pfe.setProbability(tint); - total -= tint; - } - //do { - // tint = r.nextInt()%10; - // } while(tint <= 0); - //int newRate = tint; - //int newRate = (j+1)%2+1; - int newRate = 1; - String cdname = cd.getSymbol(); - if((cdname.equals("SeriesRunner")) || - (cdname.equals("MDRunner")) || - (cdname.equals("Stage")) || - (cdname.equals("AppDemoRunner")) || - (cdname.equals("FilterBankAtom"))) { - newRate = 16; - } else if(cdname.equals("SentenceParser")) { - newRate = 4; - } - //do { - // tint = r.nextInt()%100; - // } while(tint <= 0); - // int probability = tint; - int probability = 100; - pfe.addNewObjInfo(cd, newRate, probability); - } - } - } - } - } - Iterator it_flags = ta.getFlagStates(cd).iterator(); - while(it_flags.hasNext()) { - FlagState fs = (FlagState)it_flags.next(); - Iterator it_edges = fs.edges(); - int total = 100; - while(it_edges.hasNext()) { - //do { - // tint = r.nextInt()%10; - // } while(tint <= 0); - FEdge edge = (FEdge)it_edges.next(); - tint = taskinfo.get(edge.getTask().getSymbol()).intValue(); - edge.setExeTime(tint); - if((fs.getClassDescriptor().getSymbol().equals("MD")) && (edge.getTask().getSymbol().equals("t6"))) { - if(edge.isbackedge()) { - if(edge.getTarget().equals(edge.getSource())) { - edge.setProbability(93.75); - } else { - edge.setProbability(3.125); - } - } else { - edge.setProbability(3.125); - } - continue; - } - if(!it_edges.hasNext()) { - edge.setProbability(total); - } else { - if((total != 0) && (total != 1)) { - do { - tint = r.nextInt()%total; - } while(tint <= 0); - } - edge.setProbability(tint); - total -= tint; - } - } - } - } - } - } else { - // for test - // Randomly set the newRate and probability of FEdges - java.util.Random r=new java.util.Random(); - int tint = 0; - for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext();) { - ClassDescriptor cd=(ClassDescriptor) it_classes.next(); - if(cd.hasFlags()) { - Vector rootnodes=ta.getRootNodes(cd); - if(rootnodes!=null) { - for(Iterator it_rootnodes=rootnodes.iterator(); it_rootnodes.hasNext();) { - FlagState root=(FlagState)it_rootnodes.next(); - Vector allocatingTasks = root.getAllocatingTasks(); - if(allocatingTasks != null) { - for(int k = 0; k < allocatingTasks.size(); k++) { - TaskDescriptor td = (TaskDescriptor)allocatingTasks.elementAt(k); - Vector fev = (Vector)ta.getFEdgesFromTD(td); - int numEdges = fev.size(); - int total = 100; - for(int j = 0; j < numEdges; j++) { - FEdge pfe = fev.elementAt(j); - if(numEdges - j == 1) { - pfe.setProbability(total); - } else { - if((total != 0) && (total != 1)) { - do { - tint = r.nextInt()%total; - } while(tint <= 0); - } - pfe.setProbability(tint); - total -= tint; - } - //do { - // tint = r.nextInt()%10; - // } while(tint <= 0); - //int newRate = tint; - //int newRate = (j+1)%2+1; - int newRate = 1; - String cdname = cd.getSymbol(); - if((cdname.equals("SeriesRunner")) || - (cdname.equals("MDRunner")) || - (cdname.equals("Stage")) || - (cdname.equals("AppDemoRunner")) || - (cdname.equals("FilterBankAtom"))) { - newRate = 16; - } else if(cdname.equals("SentenceParser")) { - newRate = 4; - } - //do { - // tint = r.nextInt()%100; - // } while(tint <= 0); - // int probability = tint; - int probability = 100; - pfe.addNewObjInfo(cd, newRate, probability); - } - } - } - } - } - - Iterator it_flags = ta.getFlagStates(cd).iterator(); - while(it_flags.hasNext()) { - FlagState fs = (FlagState)it_flags.next(); - Iterator it_edges = fs.edges(); - int total = 100; - while(it_edges.hasNext()) { - //do { - // tint = r.nextInt()%10; - // } while(tint <= 0); - tint = 3; - FEdge edge = (FEdge)it_edges.next(); - edge.setExeTime(tint); - if((fs.getClassDescriptor().getSymbol().equals("MD")) && (edge.getTask().getSymbol().equals("t6"))) { - if(edge.isbackedge()) { - if(edge.getTarget().equals(edge.getSource())) { - edge.setProbability(93.75); - } else { - edge.setProbability(3.125); - } - } else { - edge.setProbability(3.125); - } - continue; - } - if(!it_edges.hasNext()) { - edge.setProbability(total); - } else { - if((total != 0) && (total != 1)) { - do { - tint = r.nextInt()%total; - } while(tint <= 0); - } - edge.setProbability(tint); - total -= tint; - } - } - } - } - } - } - // Use ownership analysis to get alias information CallGraph callGraph = new CallGraph(state); OwnershipAnalysis oa = new OwnershipAnalysis(state, @@ -518,135 +348,49 @@ public class Main { state.OWNERSHIPWRITEDOTS, state.OWNERSHIPWRITEALL, state.OWNERSHIPALIASFILE); - - // Save the current standard input, output, and error streams - // for later restoration. - PrintStream origOut = System.out; - - // Create a new output stream for the standard output. - PrintStream stdout = null; - try { - stdout = new PrintStream(new FileOutputStream("SimulatorResult.out")); - } catch (Exception e) { - // Sigh. Couldn't open the file. - System.out.println("Redirect: Unable to open output file!"); - System.exit(1); - } - - // Print stuff to the original output and error streams. - // On most systems all of this will end up on your console when you - // run this application. - //origOut.println ("\nRedirect: Round #1"); - //System.out.println ("Test output via 'System.out'."); - //origOut.println ("Test output via 'origOut' reference."); - - // Set the System out and err streams to use our replacements. - System.setOut(stdout); - - // Print stuff to the original output and error streams. - // The stuff printed through the 'origOut' and 'origErr' references - // should go to the console on most systems while the messages - // printed through the 'System.out' and 'System.err' will end up in - // the files we created for them. - //origOut.println ("\nRedirect: Round #2"); - //System.out.println ("Test output via 'SimulatorResult.out'."); - //origOut.println ("Test output via 'origOut' reference."); - - // generate multiple schedulings - ScheduleAnalysis scheduleAnalysis = new ScheduleAnalysis(state, ta); - scheduleAnalysis.preSchedule(); - scheduleAnalysis.scheduleAnalysis(); - //scheduleAnalysis.setCoreNum(scheduleAnalysis.getSEdges4Test().size()); - scheduleAnalysis.setCoreNum(state.CORENUM); - scheduleAnalysis.schedule(); - - //simulate these schedulings - ScheduleSimulator scheduleSimulator = new ScheduleSimulator(scheduleAnalysis.getCoreNum(), state, ta); - Iterator it_scheduling = scheduleAnalysis.getSchedulingsIter(); - int index = 0; - Vector selectedScheduling = new Vector(); - int processTime = Integer.MAX_VALUE; - while(it_scheduling.hasNext()) { - Vector scheduling = (Vector)it_scheduling.next(); - scheduleSimulator.setScheduling(scheduling); - int tmpTime = scheduleSimulator.process(); - if(tmpTime < processTime) { - selectedScheduling.clear(); - selectedScheduling.add(index); - processTime = tmpTime; - } else if(tmpTime == processTime) { - selectedScheduling.add(index); - } - index++; - } - System.out.print("Selected schedulings with least exectution time " + processTime + ": \n\t"); - for(int i = 0; i < selectedScheduling.size(); i++) { - System.out.print((selectedScheduling.elementAt(i) + 1) + ", "); - } - System.out.println(); - - /*ScheduleSimulator scheduleSimulator = new ScheduleSimulator(4, state, ta); - Vector scheduling = new Vector(); - for(int i = 0; i < 4; i++) { - Schedule schedule = new Schedule(i); - scheduling.add(schedule); - } - Iterator it_tasks = state.getTaskSymbolTable().getAllDescriptorsIterator(); - while(it_tasks.hasNext()) { - TaskDescriptor td = (TaskDescriptor)it_tasks.next(); - if(td.getSymbol().equals("t10")) { - scheduling.elementAt(1).addTask(td); - } else { - scheduling.elementAt(0).addTask(td); + + // synthesis a layout according to target multicore processor + MCImplSynthesis mcImplSynthesis = new MCImplSynthesis(state, + ta, + oa); + if(isDistributeInfo) { + mcImplSynthesis.distribution(); + } else { + //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."); + + // generate multicore codes + if(state.MULTICORE) { + BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, + bf.getMap(), + tu, + sa, + scheduling, + mcImplSynthesis.getCoreNum(), + pa); + bcm.setOwnershipAnalysis(oa); + bcm.buildCode(); } - } - ClassDescriptor cd = (ClassDescriptor)state.getClassSymbolTable().get("E"); - scheduling.elementAt(0).addTargetCore(cd, 1); - scheduleSimulator.setScheduling(scheduling); - scheduleSimulator.process(); - - Vector scheduling1 = new Vector(); - for(int i = 0; i < 4; i++) { - Schedule schedule = new Schedule(i); - scheduling1.add(schedule); - } - Iterator it_tasks1 = state.getTaskSymbolTable().getAllDescriptorsIterator(); - while(it_tasks1.hasNext()) { - TaskDescriptor td = (TaskDescriptor)it_tasks1.next(); - scheduling1.elementAt(0).addTask(td); - } - scheduleSimulator.setScheduling(scheduling1); - scheduleSimulator.process();*/ - - // Close the streams. - try { - stdout.close(); - System.setOut(origOut); - } catch (Exception e) { - origOut.println("Redirect: Unable to close files!"); - } - - if(state.MULTICORE) { - //it_scheduling = scheduleAnalysis.getSchedulingsIter(); - //Vector scheduling = (Vector)it_scheduling.next(); - Vector scheduling = scheduleAnalysis.getSchedulings().elementAt(selectedScheduling.lastElement()); - BuildCodeMultiCore bcm=new BuildCodeMultiCore(state, bf.getMap(), tu, sa, scheduling, scheduleAnalysis.getCoreNum(), pa); - bcm.setOwnershipAnalysis(oa); - bcm.buildCode(); + scheduling.clear(); + scheduling = null; } } - } - if(!state.MULTICORE) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { CallGraph callgraph=new CallGraph(state); if (state.PREFETCH) { //speed up prefetch generation using locality analysis results LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); pa=new PrefetchAnalysis(state, callgraph, tu, la); } - LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); GenerateConversions gc=new GenerateConversions(la, state); BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa); @@ -657,46 +401,41 @@ public class Main { } } - if (state.FLATIRGRAPH) { - FlatIRGraph firg = new FlatIRGraph(state, - state.FLATIRGRAPHTASKS, - state.FLATIRGRAPHUSERMETHODS, - state.FLATIRGRAPHLIBMETHODS); - } - - if (state.OWNERSHIP) { - CallGraph callGraph = new CallGraph(state); - OwnershipAnalysis oa = new OwnershipAnalysis(state, - tu, - callGraph, - state.OWNERSHIPALLOCDEPTH, - state.OWNERSHIPWRITEDOTS, - state.OWNERSHIPWRITEALL, - state.OWNERSHIPALIASFILE); - } - + System.out.println("Lines="+state.lines); System.exit(0); } + public static void loadClass(State state, BuildIR bir, String sourcefile) { + ParseNode pn=readSourceFile(state, sourcefile); + bir.buildtree(pn, null); + } + /** Reads in a source file and adds the parse tree to the state object. */ - private static void readSourceFile(State state, String sourcefile) throws Exception { - Reader fr = new BufferedReader(new FileReader(sourcefile)); - Lex.Lexer l = new Lex.Lexer(fr); - java_cup.runtime.lr_parser g; - g = new Parse.Parser(l); - ParseNode p=null; + public static ParseNode readSourceFile(State state, String sourcefile) { try { - p=(ParseNode) g./*debug_*/ parse().value; + Reader fr= new BufferedReader(new FileReader(sourcefile)); + Lex.Lexer l = new Lex.Lexer(fr); + java_cup.runtime.lr_parser g; + g = new Parse.Parser(l); + ParseNode p=null; + try { + p=(ParseNode) g./*debug_*/parse().value; + } catch (Exception e) { + System.err.println("Error parsing file:"+sourcefile); + e.printStackTrace(); + System.exit(-1); + } + state.addParseNode(p); + if (l.numErrors()!=0) { + System.out.println("Error parsing "+sourcefile); + System.exit(l.numErrors()); + } + state.lines+=l.line_num; + return p; + } catch (Exception e) { - System.err.println("Error parsing file:"+sourcefile); - e.printStackTrace(); - System.exit(-1); - } - state.addParseNode(p); - if (l.numErrors()!=0) { - System.out.println("Error parsing "+sourcefile); - System.exit(l.numErrors()); + throw new Error(e); } } }