From dcd87f0af6f9fe4abc4762223b17748a0a8428aa Mon Sep 17 00:00:00 2001 From: adash Date: Fri, 30 Nov 2007 22:09:08 +0000 Subject: [PATCH] Added some intial code for Building flatcode for prefetch node Modified prefetch analyisis to take care of FlatCastNode and FlatTagDeclaration --- .../Analysis/Prefetch/PrefetchAnalysis.java | 129 +++++++++++++++--- Robust/src/IR/Flat/BuildCode.java | 54 ++++++-- Robust/src/IR/Flat/FlatPrefetchNode.java | 10 +- Robust/src/Runtime/DSTM/interface/trans.c | 28 +++- 4 files changed, 190 insertions(+), 31 deletions(-) diff --git a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java index b566bbc2..c62040a4 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java +++ b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java @@ -114,7 +114,6 @@ public class PrefetchAnalysis { doInsPrefetchAnalysis(fm); if(newprefetchset.size() > 0) { addFlatPrefetchNode(newprefetchset); - printMethod(fm); } } } @@ -195,7 +194,7 @@ public class PrefetchAnalysis { } break; case FKind.FlatOpNode: - processFlatOpNode(curr, child_prefetch_set_copy,parentpmap); + processFlatOpNode(curr, child_prefetch_set_copy, parentpmap); break; case FKind.FlatLiteralNode: processFlatLiteralNode(curr, child_prefetch_set_copy, parentpmap); @@ -213,7 +212,7 @@ public class PrefetchAnalysis { processDefaultCase(curr,child_prefetch_set_copy, parentpmap); break; case FKind.FlatCastNode: - processDefaultCase(curr,child_prefetch_set_copy, parentpmap); + processFlatCastNode(curr, child_prefetch_set_copy, parentpmap); break; case FKind.FlatFlagActionNode: processDefaultCase(curr,child_prefetch_set_copy, parentpmap); @@ -225,7 +224,7 @@ public class PrefetchAnalysis { processDefaultCase(curr,child_prefetch_set_copy, parentpmap); break; case FKind.FlatTagDeclaration: - processDefaultCase(curr,child_prefetch_set_copy, parentpmap); + processFlatTagDeclaration(curr, child_prefetch_set_copy, parentpmap); break; default: System.out.println("NO SUCH FLATNODE"); @@ -1104,6 +1103,94 @@ public class PrefetchAnalysis { } } + /** This functions processes for FlatCastNode + * for e.g x = (cast type) y followed by childnode with prefetch set x.f + * then drop the prefetches beyond this FlatCastNode */ + private void processFlatCastNode(FlatNode curr, Hashtablechild_prefetch_set_copy, + Hashtable parentpmap) { + boolean pSetHasChanged = false; + Hashtable tocompare = new Hashtable(); + FlatCastNode currfcn = (FlatCastNode) curr; + Float newprob = new Float((float)0.0); + PairMap pm = new PairMap(); + PrefetchPair childpp = null; + Enumeration ecld = null; + + ecld = child_prefetch_set_copy.keys(); + while (ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + if(childpp.base == currfcn.getDst()){ + child_prefetch_set_copy.remove(childpp); + } else { + tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + pm.addPair(childpp, childpp); + child_prefetch_set_copy.remove(childpp); + } + } + + /* Create prefetch mappings for child nodes */ + if(!pm.isEmpty()) { + parentpmap.put(curr, pm); + } + pmap_hash.put(curr.getNext(0), parentpmap); + + /* Compare with the old prefetch set */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + + /* Enqueue parent nodes */ + if(pSetHasChanged) { + for(int i=0; ichild_prefetch_set_copy, + Hashtable parentpmap) { + boolean pSetHasChanged = false; + Hashtable tocompare = new Hashtable(); + FlatTagDeclaration currftd = (FlatTagDeclaration) curr; + Float newprob = new Float((float)0.0); + PairMap pm = new PairMap(); + PrefetchPair childpp = null; + Enumeration ecld = null; + + ecld = child_prefetch_set_copy.keys(); + while (ecld.hasMoreElements()) { + childpp = (PrefetchPair) ecld.nextElement(); + if(childpp.base == currftd.getDst()){ + child_prefetch_set_copy.remove(childpp); + } else { + tocompare.put(childpp, child_prefetch_set_copy.get(childpp)); + pm.addPair(childpp, childpp); + child_prefetch_set_copy.remove(childpp); + } + } + + /* Create prefetch mappings for child nodes */ + if(!pm.isEmpty()) { + parentpmap.put(curr, pm); + } + pmap_hash.put(curr.getNext(0), parentpmap); + + /* Compare with the old prefetch set */ + pSetHasChanged = comparePrefetchSets(prefetch_hash.get(curr), tocompare); + + /* Enqueue parent nodes */ + if(pSetHasChanged) { + for(int i=0; i s = new HashSet(); + //if(!newpset.isEmpty() && !pset2.isEmpty()) { + if(!newpset.isEmpty()) { + if(!pset2.isEmpty()) { + for(Iterator it = newpset.iterator(); it.hasNext();) { + PrefetchPair pp = (PrefetchPair) it.next(); + if(!pset2.contains(pp)) { + s.add(pp); + } + } + } else { + for(Iterator it = newpset.iterator(); it.hasNext();) { + PrefetchPair pp = (PrefetchPair) it.next(); + s.add(pp); + } } } - } - if(s != null) { - newprefetchset.put(fn, s); + if(s.size() > 0) { + newprefetchset.put(fn, s); + } } } @@ -1301,11 +1396,11 @@ public class PrefetchAnalysis { for(i = 0; i< newprefetchset.get(fn).size(); i++) { fpn.insAllpp((HashSet)newprefetchset.get(fn)); } + //System.out.println("The HashSet of prefetch pairs are "+ fpn.getPrefetchPairs()); if(fn.kind() == FKind.FlatMethod) { FlatNode nn = fn.getNext(0); fn.setNext(0, fpn); fpn.addNext(nn); - } else { while(fn.numPrev() > 0) { FlatNode nn = fn.getPrev(0); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 7174ba91..11b93c84 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -15,6 +15,7 @@ import Analysis.TaskStateAnalysis.SafetyAnalysis; import Analysis.TaskStateAnalysis.TaskIndex; import Analysis.Locality.LocalityAnalysis; import Analysis.Locality.LocalityBinding; +import Analysis.Prefetch.*; public class BuildCode { State state; @@ -324,12 +325,12 @@ public class BuildCode { /* Generate code for methods */ if (state.DSM) { for(Iterator lbit=locality.getLocalityBindings().iterator();lbit.hasNext();) { - LocalityBinding lb=lbit.next(); - MethodDescriptor md=lb.getMethod(); - FlatMethod fm=state.getMethodFlat(md); - if (!md.getModifiers().isNative()) { - generateFlatMethod(fm, lb, outmethod); - } + LocalityBinding lb=lbit.next(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + if (!md.getModifiers().isNative()) { + generateFlatMethod(fm, lb, outmethod); + } } } else { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); @@ -1412,11 +1413,47 @@ public class BuildCode { case FKind.FlatFlagActionNode: generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output); return; + case FKind.FlatPrefetchNode: + generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output); + return; } throw new Error(); - } - + + public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) { + System.out.println("Inside generateFlatPrefetchNode()"); + if (state.PREFETCH) { + System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp); + Iterator it = fpn.hspp.iterator(); + for(;it.hasNext();) { + PrefetchPair pp = (PrefetchPair) it.next(); + //TODO handle arrays in prefetch tuples, currently only handle fields + Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base); + System.out.println("DEBUG-> generateFlatPrefetchNode()" + statusbase); + if(statusbase == LocalityAnalysis.GLOBAL) { + // Generate oid for base + } else { + for(int i = 0; i generateFlatPrefetchNode() fd" + statusfd); + //find out the locality of the fieldDescriptor + if(statusfd == LocalityAnalysis.GLOBAL) { + //generate oid for it + } + } + } + } + } + //Each temp descriptor can be an oid + //Find locality of each prefetch tuple in the FLatPrefetchNode + //Separate them as Local or Global + //generate oids and offset value for prefetch tuple + } + } + public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) { if (lb!=fgcn.getLocality()) return; @@ -1700,6 +1737,7 @@ public class BuildCode { output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); } + private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) { if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray()) throw new Error("Can't set array length"); diff --git a/Robust/src/IR/Flat/FlatPrefetchNode.java b/Robust/src/IR/Flat/FlatPrefetchNode.java index 7a8914c0..81a20d1d 100644 --- a/Robust/src/IR/Flat/FlatPrefetchNode.java +++ b/Robust/src/IR/Flat/FlatPrefetchNode.java @@ -3,10 +3,10 @@ import Analysis.Prefetch.*; import java.util.*; public class FlatPrefetchNode extends FlatNode { - HashSet pp; + HashSet hspp; public FlatPrefetchNode() { - pp = new HashSet(); + hspp = new HashSet(); } public String toString() { @@ -18,14 +18,14 @@ public class FlatPrefetchNode extends FlatNode { } public void insPrefetchPair(PrefetchPair pp) { - this.pp.add(pp); + hspp.add(pp); } public void insAllpp(HashSet hspp) { - this.pp.addAll(hspp); + this.hspp.addAll(hspp); } public HashSet getPrefetchPairs() { - return this.pp; + return hspp; } } diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index e76fc95c..d702c66b 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -47,6 +47,7 @@ unsigned int oidMin; unsigned int oidMax; void printhex(unsigned char *, int); +plistnode_t *createPiles(transrecord_t *); void printhex(unsigned char *ptr, int numBytes) { @@ -62,7 +63,6 @@ void printhex(unsigned char *ptr, int numBytes) return; } -plistnode_t *createPiles(transrecord_t *); inline int arrayLength(int *array) { int i; for(i=0 ;array[i] != -1; i++) @@ -132,6 +132,30 @@ int dstmStartup(const char * option) { } +//TODO Use this later +void *pCacheAlloc(objstr_t *store, unsigned int size) { + void *tmp; + objstr_t *ptr; + ptr = store; + int success = 0; + + while(ptr->next != NULL) { + /* check if store is empty */ + if(((unsigned int)ptr->top - (unsigned int)ptr - sizeof(objstr_t) + size) <= ptr->size) { + tmp = ptr->top; + ptr->top += size; + success = 1; + return tmp; + } else { + ptr = ptr-> next; + } + } + + if(success == 0) { + printf("DEBUG-> Unable to insert object in Prefetch cache\n"); + return NULL; + } +} /* This function initiates the prefetch thread * A queue is shared between the main thread of execution @@ -143,6 +167,8 @@ void transInit() { int retval; //Create and initialize prefetch cache structure prefetchcache = objstrCreate(PREFETCH_CACHE_SIZE); + //prefetchcache->next = objstrCreate(PREFETCH_CACHE_SIZE); + //prefetchcache->next->next = objstrCreate(PREFETCH_CACHE_SIZE); /* Initialize attributes for mutex */ pthread_mutexattr_init(&prefetchcache_mutex_attr); -- 2.34.1