working up mlp system
authorjjenista <jjenista>
Fri, 24 Jul 2009 21:41:56 +0000 (21:41 +0000)
committerjjenista <jjenista>
Fri, 24 Jul 2009 21:41:56 +0000 (21:41 +0000)
Robust/src/Analysis/MLP/MLPAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/State.java
Robust/src/Main/Main.java
Robust/src/Runtime/mlp_runtime.c
Robust/src/Runtime/mlp_runtime.h
Robust/src/Runtime/psemaphore.c
Robust/src/Runtime/workschedule.c
Robust/src/Tests/mlp/tinyTest/makefile
Robust/src/buildscript

index e50017517bb2998167dceda56e1fdea9d8e86204..98629ce879518a76b94b438d13739d5724b333e0 100644 (file)
@@ -27,7 +27,7 @@ public class MLPAnalysis {
   private Hashtable< FlatNode, Set<TempDescriptor>      > notAvailableResults;
   private Hashtable< FlatNode, CodePlan                 > codePlans;
 
-  private static final int maxSESEage = 2;
+  private static int maxSESEage = -1;
 
 
   // use these methods in BuildCode to have access to analysis results
@@ -62,6 +62,7 @@ public class MLPAnalysis {
     this.typeUtil    = tu;
     this.callGraph   = callGraph;
     this.ownAnalysis = ownAnalysis;
+    this.maxSESEage  = state.MLP_MAXSESEAGE;
 
     // initialize analysis data structures
     allSESEs = new HashSet<FlatSESEEnterNode>();
index ffc2df2f45cb7b5e4233833fb77bd09ad9dc6b4c..2c485dcc36527cf8111364bd9cb8ec6e213d7b15 100644 (file)
@@ -277,9 +277,6 @@ public class BuildCode {
   private void outputMainMethod(PrintWriter outmethod) {
     outmethod.println("int main(int argc, const char *argv[]) {");
     outmethod.println("  int i;");
-    if (state.MLP) {
-      outmethod.println("  mlpInit( "+mlpa.getAllSESEs().size()+", "+mlpa.getMaxSESEage()+" );");
-    }
     if (state.DSM) {
       outmethod.println("#ifdef TRANSSTATS \n");
       outmethod.println("handle();\n");
@@ -380,6 +377,14 @@ public class BuildCode {
     if (state.THREAD||state.SINGLETM)
       outmethod.println("pthread_exit(NULL);");
 
+    if (state.MLP) {
+      outmethod.println("  mlpInit( "+state.MLP_NUMCORES+", "+
+                       "invokeSESEmethod, "+
+                       "argc, "+
+                       "argv, "+
+                       state.MLP_MAXSESEAGE+" );");
+    }
+
     outmethod.println("}");
   }
 
@@ -1660,25 +1665,14 @@ public class BuildCode {
                                             PrintWriter outmethod
                                             ) {
 
-    outmethodheader.println("void invokeSESEmethod( void* vargs );");
-    outmethod.println(      "void invokeSESEmethod( void* vargs ) {");
+    outmethodheader.println("void invokeSESEmethod( void* seseRecord );");
+    outmethod.println(      "void invokeSESEmethod( void* seseRecord ) {");
     outmethod.println(      "  int status;");
     outmethod.println(      "  char errmsg[128];");
-    outmethod.println(      "  invokeSESEargs* args = (invokeSESEargs*) vargs;");
-
-    /*
-    // wait on a condition variable that dispatcher will signal
-    // then this SESE instance's dependencies are resolved
-    outmethod.println(      "  status = pthread_mutex_lock( args->invokee->startCondVarLock );");
-    outmethod.println(      "  "+mlperrstr);
-    outmethod.println(      "  while( !(args->invokee->startedExecuting) ){");
-    outmethod.println(      "    status = pthread_cond_wait( args->invokee->startCondVar, args->invokee->startCondVarLock );");
-    outmethod.println(      "    "+mlperrstr);
-    outmethod.println(      "  }");
-    */
+    outmethod.println(      "  SESErecord* rec = (SESErecord*) seseRecord;");
 
     // generate a case for each SESE class that can be invoked
-    outmethod.println(      "  switch( args->classID ) {");
+    outmethod.println(      "  switch( rec->classID ) {");
     outmethod.println(      "    ");
     for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
       FlatSESEEnterNode fsen = seseit.next();
@@ -1701,7 +1695,7 @@ public class BuildCode {
   private void generateSESEinvocation(FlatSESEEnterNode fsen,
                                       PrintWriter output
                                       ) {
-
+    /*
     FlatMethod       fm = fsen.getEnclosingFlatMeth();
     MethodDescriptor md = fm.getMethod();
     ClassDescriptor  cn = md.getClassDesc();
@@ -1731,6 +1725,7 @@ public class BuildCode {
     }
     
     output.println(");");
+    */
   }
 
   protected void generateMethodSESE(FlatSESEEnterNode fsen,
@@ -1740,7 +1735,7 @@ public class BuildCode {
                                     PrintWriter outputMethods
                                     ) {
 
-
+    /*
     FlatMethod       fm = fsen.getEnclosingFlatMeth();
     MethodDescriptor md = fm.getMethod();
     ClassDescriptor  cn = md.getClassDesc();
@@ -1834,6 +1829,7 @@ public class BuildCode {
 
 
     generateFlatMethodSESE(bogusfm, cn, fsen, fsen.getFlatExit(), outputMethods);
+    */
   }
 
   private void generateFlatMethodSESE(FlatMethod fm, 
@@ -1908,8 +1904,10 @@ public class BuildCode {
     // TODO: only do this if we know the method actually
     // contains an SESE issue, not currently an annotation    
     if( state.MLP ) {
+      /*
       output.println("   SESErecord*     tempSESE;");
       output.println("   invokeSESEargs* tempSESEargs;");
+      */
     }    
 
     /* Assign labels to FlatNode's if necessary.*/
@@ -2267,7 +2265,7 @@ public class BuildCode {
     }
 
     if( state.MLP ) {
-
+      /*
       CodePlan cp = mlpa.getCodePlan( fn );
       if( cp != null ) {     
 
@@ -2276,6 +2274,7 @@ public class BuildCode {
          
        }
       }
+      */
     }
   }
 
@@ -2611,9 +2610,11 @@ public class BuildCode {
       // SESE nodes can be parsed for normal compilation, just skip over them
       return;
     }
-    
-    output.println("\n   /* SESE "+fsen.getPrettyIdentifier()+" issue */");
-    output.println("   tempSESE = mlpCreateSESErecord( "+
+   
+    //    output.println("\n   /* SESE "+fsen.getPrettyIdentifier()+" issue */");
+   
+    /*
+ output.println("   tempSESE = mlpCreateSESErecord( "+
                    fsen.getIdentifier()+", "+
                    "malloc( sizeof( "+fsen.namespaceStructNameString()+") ), "+
                    "NULL );");
@@ -2641,6 +2642,7 @@ public class BuildCode {
 
     output.println("   invokeSESEmethod( (void*) tempSESEargs );");   
     output.println("\n");
+    */
   }
 
   public void generateFlatSESEExitNode(FlatMethod fm,  LocalityBinding lb, FlatSESEExitNode fsen, PrintWriter output) {
index 1d52a75097fce82cd9fdf2caafadb6c3cdf79f10..81a463d6af1a6a02eb875da67c777abb5f19aefa 100644 (file)
@@ -77,6 +77,8 @@ public class State {
   public boolean INSTRUCTIONFAILURE=false;
   public boolean MLP=false;
   public boolean MLPDEBUG=false;
+  public int MLP_NUMCORES=0;
+  public int MLP_MAXSESEAGE=0;
   public static double TRUEPROB=0.8;
   public static boolean PRINTFLAT=false;
   public static boolean PRINTSCHEDULING=false;
index 340df9d83c74f66365996ec0f47e2b7a37cf28a6..146428666dc02ab02e9821ce59d1035b260834fb 100644 (file)
@@ -175,13 +175,16 @@ public class Main {
        state.INSTRUCTIONFAILURE=true;
       else if (option.equals("-abcclose"))
        state.ARRAYBOUNDARYCHECK=false;
+
       else if (option.equals("-mlp")) {
-       state.MLP=true;
-       state.OWNERSHIP=true;
+       state.MLP            = true;
+       state.OWNERSHIP      = true;
+       state.MLP_NUMCORES   = Integer.parseInt( args[++i] );
+       state.MLP_MAXSESEAGE = Integer.parseInt( args[++i] );
+
       } else if (option.equals("-mlpdebug")) {
-       state.MLP=true;
        state.MLPDEBUG=true;
-       state.OWNERSHIP=true;
+
       } else if (option.equals("-help")) {
        System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located");
        System.out.println("-selfloop task -- this task doesn't self loop its parameters forever");
@@ -212,8 +215,8 @@ public class Main {
        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("-mlp <num cores> <max sese age> build mlp code");
+       System.out.println("-mlpdebug if mlp, 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("-interrupt generate raw version binary with interruption (should be used togethere with -raw)");
index 6c724216bea4d80f4e947f66df6cb4b0c6cf5034..b1c09b643aed4898cb379e116ec9690b6b4b2420 100644 (file)
@@ -4,51 +4,34 @@
 #include <stdio.h>
 #include <assert.h>
 
-#include "mlp_runtime.h"
+#include "mem.h"
 #include "Queue.h"
+#include "mlp_runtime.h"
+#include "workschedule.h"
 
 
 #define FALSE 0
 #define TRUE  1
 
 
-// the root sese is accessible globally so
-// buildcode can generate references to it
-//SESErecord* rootsese;
-
-
-// the issuedQ, in this simple version, spits
-// out SESErecord's in the order they were issued
-static struct Queue* issuedQ;
-
-
-
 SESErecord* mlpCreateSESErecord( int   classID,
-                                 void* namespace,
-                                 void* paramStruct
+                                void* inSetObjs,
+                                void* outSetObjsNotInInSet,
+                                void* inSetPrims,
+                                void* outSetPrimsNotInInSet
                               ) {
 
-  SESErecord* newrec = malloc( sizeof( SESErecord ) );
-
-  //newrec->parent           = parent;
-  //newrec->childrenList     = createQueue();
-  //newrec->vars             = malloc( sizeof( SESEvar ) * numVars );
-
-  newrec->classID          = classID;
-  newrec->namespace        = namespace;
-  newrec->paramStruct      = paramStruct;
+  SESErecord* newrec = RUNMALLOC( sizeof( SESErecord ) );
 
-  newrec->forwardList      = createQueue();
-  newrec->doneExecuting    = FALSE;
-  //newrec->startedExecuting = FALSE;
+  newrec->classID               = classID;
+  newrec->inSetObjs             = inSetObjs;
+  newrec->outSetObjsNotInInSet  = outSetObjsNotInInSet;
+  newrec->inSetPrims            = inSetPrims;
+  newrec->outSetPrimsNotInInSet = outSetPrimsNotInInSet;
 
-  psem_init         ( &(newrec->stallSem)            );
-
-  /*
-  pthread_cond_init ( newrec->startCondVar,     NULL );
-  pthread_mutex_init( newrec->startCondVarLock, NULL );
-  pthread_mutex_init( newrec->forwardListLock,  NULL );
-  */
+  pthread_mutex_init( &(newrec->lock),  NULL );
+  newrec->forwardList   = createQueue();
+  newrec->doneExecuting = FALSE;
 
   return newrec;
 }
@@ -56,62 +39,54 @@ SESErecord* mlpCreateSESErecord( int   classID,
 
 void mlpDestroySESErecord( SESErecord* sese ) {
 
-  /*
-  pthread_cond_destroy ( sese->startCondVar     );
-  pthread_mutex_destroy( sese->startCondVarLock );
-  pthread_mutex_destroy( sese->forwardListLock  );
-  */
-
-  /*
-  free     ( sese->startCondVar     );
-  free     ( sese->startCondVarLock );
-  free     ( sese->forwardListLock  );
-  freeQueue( sese->forwardList      );
-  //freeQueue( sese->childrenList     );
-  free     ( sese->vars             );
-  */
-  free     ( sese->namespace        );
-  free     ( sese                   );
-}
+  pthread_mutex_destroy( &(sese->lock) );
+  freeQueue( sese->forwardList );
 
+  RUNFREE( sese->inSetObjs             );
+  RUNFREE( sese->outSetObjsNotInInSet  );
+  RUNFREE( sese->inSetPrims            );
+  RUNFREE( sese->outSetPrimsNotInInSet );
+  RUNFREE( sese                        );
+}
 
-void mlpInit( int totalNumSESEs, int maxSESEage ) {  
 
-  issuedQ = createQueue();
+struct rootSESEinSetObjs  { char** argv; };
+struct rootSESEinSetPrims { int argc;    };
 
-  /*
-  class_age2instance = (SESErecord**) malloc( sizeof( SESErecord* ) *
-                                              maxSESEage            *
-                                              totalNumSESEs
-                                            );
-  */
-  //current = rootsese;
-  //current = NULL;
-}
+void mlpInit( int numProcessors, 
+             void(*workFunc)(void*),
+             int argc, char** argv,
+             int maxSESEage ) {  
 
+  SESErecord* rootSESE;
+  
+  struct rootSESEinSetObjs*  inObjs  = RUNMALLOC( sizeof( struct rootSESEinSetObjs ) );
+  struct rootSESEinSetPrims* inPrims = RUNMALLOC( sizeof( struct rootSESEinSetPrims ) );
 
-/*
-SESErecord* mlpGetCurrent() {
-  return current;
-}
-*/
+  // first initialize the work scheduler
+  workScheduleInit( numProcessors, workFunc );
 
-void mlpIssue( SESErecord* sese ) {
-  addNewItem( issuedQ, (void*) sese );
-}
+  // the prepare the root SESE
+  inObjs->argv  = argv;
+  inPrims->argc = argc;
+  rootSESE = mlpCreateSESErecord( 0, inObjs, NULL, inPrims, NULL );
 
+  // skip the issue step because the root SESE will
+  // never have outstanding dependencies
+  workScheduleSubmit( (void*) rootSESE );
 
-SESErecord* mlpSchedule() {
-  assert( !isEmpty( issuedQ ) );
-  return (SESErecord*) getItem( issuedQ );  
+  // now the work scheduler is initialized and work is
+  // in the hopper, so begin processing.  This call 
+  // will not return
+  workScheduleBegin();
 }
 
 
-void mlpStall( SESErecord* sese ) {
-  
+void mlpIssue( SESErecord* sese ) {
+
 }
 
 
-void mlpNotifyExit( SESErecord* sese ) {
+void mlpStall( SESErecord* sese ) {
   
 }
index 4d12faeb0121af96ab118855561cad2c4010dc86..be636faac5249edf3a28f3ad8eb8092601ae50fd 100644 (file)
@@ -9,9 +9,10 @@
 
 // forward delcarations
 struct SESErecord_t;
-struct invokeSESEargs_t;
 
 
+
+/*
 typedef struct SESEvar_t {
   // the value when it is known will be placed
   // in this location, which can be accessed
@@ -28,74 +29,49 @@ typedef struct SESEvar_t {
     void*     sesetype_object;
   };  
 } SESEvar;
-
+*/
 
 typedef struct SESErecord_t {  
   // the identifier for the class of sese's that
   // are instances of one particular static code block
   int classID;
 
-  // for state of vars after issue
-  void* namespace;
-  
-  // when this sese is ready to be invoked,
-  // allocate and fill in this structure, and
-  // the primitives will be passed out of the
-  // above var array at the call site
-  void* paramStruct;
-
-  /*
-  // for signaling transition from issue 
-  // to execute
-  pthread_cond_t*  startCondVar;
-  pthread_mutex_t* startCondVarLock;
-  int startedExecuting;
-  */
-
-  // this will not be generally sufficient, but
-  // use a semaphore to let a child resume this
-  // parent when stall dependency is satisfied
-  psemaphore stallSem;
-
-  // use a list of SESErecords and a lock to let
-  // consumers tell this SESE who wants values
-  // forwarded to it
-  pthread_mutex_t forwardListLock;
-  struct Queue*   forwardList;
-  int doneExecuting;
+  // The following fields have this structure:
+  // [INTPTR numPtrs][void* next][ptr0][ptr1]...
+  void* inSetObjs;
+  void* outSetObjsNotInInSet;
 
-} SESErecord;
+  // The following fields point to compile-time
+  // generated structures that have named 
+  // primitive fields
+  void* inSetPrims;
+  void* outSetPrimsNotInInSet;
 
+  // the lock guards the following data SESE's
+  // use to coordinate with one another
+  pthread_mutex_t lock;
+  struct Queue*   forwardList;
+  int             doneExecuting;
 
-typedef struct invokeSESEargs_t {
-  int classID;
-  SESErecord* invokee;
-  SESErecord* parent;
-} invokeSESEargs;
+} SESErecord;
 
 
 // simple mechanical allocation and deallocation
 // of SESE records
 SESErecord* mlpCreateSESErecord( int   classID,
-                                void* namespace,
-                                 void* paramStruct
-                                 );
+                                void* inSetObjs,
+                                void* outSetObjsNotInInSet,
+                                void* inSetPrims,
+                                void* outSetPrimsNotInInSet
+                               );
 
 void mlpDestroySESErecord( SESErecord* sese );
 
 
 // main library functions
 void mlpInit();
-
-//SESErecord* mlpGetCurrent();
-SESErecord* mlpSchedule();
-
-void mlpIssue     ( SESErecord* sese );
-void mlpStall     ( SESErecord* sese );
-void mlpNotifyExit( SESErecord* sese );
-
-
-extern SESErecord* rootsese;
+void mlpIssue( SESErecord* sese );
+void mlpStall( SESErecord* sese );
 
 
 #endif /* __MLP_RUNTIME__ */
index 63f91eb00a9d01e32ec383c0a54ddfb5494b769c..59ee499024e559401f9c74cc942d84a7f4613277 100644 (file)
@@ -26,5 +26,3 @@ int psem_give( psemaphore* sem ) {
   if( pthread_mutex_unlock( &(sem->lock) ) == -1 ) { return -1; }
 
 }
-
-
index 85c019b5d8505c6356fd9c8a7623e7540cbb5821..b1e2331dcd6fbba7dae6f05fb7a59c4e3fd4f349 100644 (file)
@@ -1,6 +1,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <pthread.h>
+
+#include "mem.h"
 #include "Queue.h"
 #include "workschedule.h"
 
@@ -127,7 +129,7 @@ void workScheduleInit( int numProcessors,
   workFunc   = func;
 
   // allocate space for worker data
-  workerDataArray = malloc( sizeof( workerData ) * numWorkers );
+  workerDataArray = RUNMALLOC( sizeof( workerData ) * numWorkers );
   for( i = 0; i < numWorkers; ++i ) {    
 
     // the deque
index aba20a39d011919106793c29223f3ef008de84b9..33e9d122c9dd90a04e9f7f15d2db24bb6e32e76d 100644 (file)
@@ -3,9 +3,9 @@ PROGRAM=test
 SOURCE_FILES=$(PROGRAM).java
 
 BUILDSCRIPT=~/research/Robust/src/buildscript
-BSFLAGS= -mlpdebug -nooptimize -debug -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt
-#BSFLAGS= -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt
 
+USEMLP= #-mlp 1 2 # -mlpdebug # use to turn mlp on and off and make sure rest of build not broken
+BSFLAGS= $(USEMLP) -nooptimize -debug -garbagestats -mainclass Test -ownership -ownallocdepth 1 -ownwritedots final -enable-assertions -flatirusermethods -ownaliasfile aliases.txt
 
 all: $(PROGRAM).bin
 
index 06459124882144417fa4915a3c71493d4a791b9b..6d9ae67e2ea380a9a0cf7f5ef15877d212fa1f4d 100755 (executable)
@@ -80,7 +80,7 @@ SINGLETM=false
 NOJAVA=false
 CHECKFLAG=false
 RECOVERFLAG=false
-MLPFLAG=false
+MLP_ON=false
 MLPDEBUG=false
 MULTICOREFLAG=false
 RAWFLAG=false
@@ -302,15 +302,19 @@ EXTRAOPTIONS="$EXTRAOPTIONS -DDELAYCOMP"
 elif [[ $1 = '-minimize' ]]
 then
 JAVAOPTS="$JAVAOPTS -minimize"
+
 elif [[ $1 = '-mlp' ]]
 then
-MLPFLAG=true
-EXTRAOPTIONS="$EXTRAOPTIONS -precise -lpthread"
+MLP_ON=true
+EXTRAOPTIONS="$EXTRAOPTIONS -DPRECISE_GC -lpthread"
+JAVAOPTS="$JAVAOPTS -mlp $2 $3"
+shift
+shift
+
 elif [[ $1 = '-mlpdebug' ]]
 then
 JAVAOPTS="$JAVAOPTS -mlpdebug"
-MLPFLAG=true
-EXTRAOPTIONS="$EXTRAOPTIONS -precise -lpthread"
+
 elif [[ $1 = '-check' ]]
 then
 CHECKFLAG=true
@@ -679,7 +683,7 @@ then
 FILES="$FILES $ROBUSTROOT/Runtime/localobjects.c"
 fi
 
-if $MLPFLAG
+if $MLP_ON
 then
 FILES="$FILES $ROBUSTROOT/Runtime/mlp_runtime.c"
 FILES="$FILES $ROBUSTROOT/Runtime/psemaphore.c"