refactoring in dataflow
authormegacz <adam@megacz.com>
Sun, 15 Mar 2009 01:19:45 +0000 (18:19 -0700)
committermegacz <adam@megacz.com>
Sun, 15 Mar 2009 01:19:45 +0000 (18:19 -0700)
src/edu/berkeley/fleet/dataflow/DataFlowGraph.java
src/edu/berkeley/fleet/dataflow/MergeSort.java
src/edu/berkeley/fleet/dataflow/Node.java
src/edu/berkeley/fleet/dataflow/PunctuatorNode.java
src/edu/berkeley/fleet/dataflow/UnPunctuatorNode.java

index 6d4a5fd..1510a7b 100644 (file)
@@ -25,6 +25,10 @@ public class DataFlowGraph {
 
     public final Fleet    fleet;
     public final ShipPool pool;
+    private HashSet<Node> nodes = new HashSet<Node>();
+
+    public static int reset_count = 0;
+    public static HashSet<Dock> torpedoes = new HashSet<Dock>();
 
     public DataFlowGraph(Fleet fleet) {
         this(fleet, new ShipPool(fleet));
@@ -34,14 +38,7 @@ public class DataFlowGraph {
         this.pool  = pool;
     }
 
-    public void addNode(Node node) {
-        this.nodes.add(node);
-    }
-
-    public static int reset_count = 0;
-    public static HashSet<Dock> torpedoes = new HashSet<Dock>();
-
-    private HashSet<Node> nodes = new HashSet<Node>();
+    public void addNode(Node node) { this.nodes.add(node); }
 
     public void build(Context ctx) {
         for(Node mod : nodes)
@@ -53,76 +50,6 @@ public class DataFlowGraph {
         for(Node mod : nodes)
             mod.reset(ctx, phase, ackDestination);
     }
-
-    BitVector bv(long l) { return new BitVector(fleet.getWordWidth()).set(l); }
-    BitVector[] bv(long[] l) {
-        BitVector[] ret = new BitVector[l.length];
-        for(int i=0; i<ret.length; i++) ret[i] = bv(l[i]);
-        return ret;
-    }
-
-    public static void main(String[] s) throws Exception {
-        Fleet fleet = new Fpga();
-        //Fleet fleet = new Interpreter(false);
-
-        Random random = new Random(System.currentTimeMillis());
-        long[] vals = new long[256];
-        for(int i=0; i<vals.length; i++) {
-            vals[i] = Math.abs(random.nextInt());
-        }
-
-        Ship mem1 = fleet.getShip("Memory", 0);
-        Ship mem2 = fleet.getShip("Memory", 1);
-        //Ship mem2 = fleet.getShip("DDR2", 0);
-
-        FleetProcess fp;
-        int stride = 1;
-        fp = null;
-
-        fp = fleet.run(new Instruction[0]);
-        MemoryUtils.writeMem(fp, mem1, 0, vals);
-        int vals_length = vals.length;
-
-        // Disable readback/writeback inside the loop
-        vals = null;
-
-        while(stride < vals_length) {
-            
-            // reset the FleetProcess
-            //fp.terminate(); fp = null;
-
-            System.out.println("stride " + stride);
-
-            // if we reset the FleetProcess, restart it
-            if (fp==null) fp = fleet.run(new Instruction[0]);
-
-            // do the mergeSort
-            vals = MergeSort.mergeSort(fp, fleet, vals, vals_length, stride, mem1, mem2);
-
-            // verify the cleanup
-            //CleanupUtils.verifyClean(fp);
-
-            Ship mem = mem1; mem1=mem2; mem2=mem;
-
-            stride = stride * 2;
-            System.out.println();
-        }
-
-        BitVector[] bvs = new BitVector[vals_length];
-        MemoryUtils.readMem(fp, mem1, 0, bvs);
-        System.out.println("results:");
-        for(int i=0; i<vals_length; i++)
-            System.out.println(bvs[i].toLong());
-    }
-
-
-
-    private BitVector[] longsToBitVectors(long[] initialValues) {
-        BitVector[] bv = new BitVector[initialValues.length];
-        for(int i=0; i<initialValues.length; i++)
-            bv[i] = new BitVector(fleet.getWordWidth()).set(initialValues[i]);
-        return bv;
-    }
 }
 
 
index cdfc8b3..36cd08f 100644 (file)
@@ -1,6 +1,7 @@
 package edu.berkeley.fleet.dataflow;
 import edu.berkeley.fleet.loops.*;
 import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.fpga.*;
 import java.util.*;
 
 public class MergeSort {
@@ -163,4 +164,60 @@ public class MergeSort {
         }
         return ret;
     }
-}
\ No newline at end of file
+
+    /** demo */
+    public static void main(String[] s) throws Exception {
+        Fleet fleet = new Fpga();
+        //Fleet fleet = new Interpreter(false);
+
+        Random random = new Random(System.currentTimeMillis());
+        long[] vals = new long[256];
+        for(int i=0; i<vals.length; i++) {
+            vals[i] = Math.abs(random.nextInt());
+        }
+
+        Ship mem1 = fleet.getShip("Memory", 0);
+        Ship mem2 = fleet.getShip("Memory", 1);
+        //Ship mem2 = fleet.getShip("DDR2", 0);
+
+        FleetProcess fp;
+        int stride = 1;
+        fp = null;
+
+        fp = fleet.run(new Instruction[0]);
+        MemoryUtils.writeMem(fp, mem1, 0, vals);
+        int vals_length = vals.length;
+
+        // Disable readback/writeback inside the loop
+        vals = null;
+
+        while(stride < vals_length) {
+            
+            // reset the FleetProcess
+            //fp.terminate(); fp = null;
+
+            System.out.println("stride " + stride);
+
+            // if we reset the FleetProcess, restart it
+            if (fp==null) fp = fleet.run(new Instruction[0]);
+
+            // do the mergeSort
+            vals = MergeSort.mergeSort(fp, fleet, vals, vals_length, stride, mem1, mem2);
+
+            // verify the cleanup
+            //CleanupUtils.verifyClean(fp);
+
+            Ship mem = mem1; mem1=mem2; mem2=mem;
+
+            stride = stride * 2;
+            System.out.println();
+        }
+
+        BitVector[] bvs = new BitVector[vals_length];
+        MemoryUtils.readMem(fp, mem1, 0, bvs);
+        System.out.println("results:");
+        for(int i=0; i<vals_length; i++)
+            System.out.println(bvs[i].toLong());
+    }
+
+}
index 2b6ad25..5684e84 100644 (file)
@@ -240,4 +240,10 @@ public class Node {
         }
     }
 
+    BitVector bv(long l) { return new BitVector(dfg.fleet.getWordWidth()).set(l); }
+    BitVector[] bv(long[] l) {
+        BitVector[] ret = new BitVector[l.length];
+        for(int i=0; i<ret.length; i++) ret[i] = bv(l[i]);
+        return ret;
+    }
 }
index 7fe4577..da79084 100644 (file)
@@ -14,6 +14,6 @@ public class PunctuatorNode extends Node {
     public PunctuatorNode(DataFlowGraph dfg, long punc) {
         super(dfg);
         this.punc = punc;
-        this.count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, dfg.bv(1), dfg.bv(punc) });
+        this.count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, bv(1), bv(punc) });
     }
 }
index 9607730..3c72907 100644 (file)
@@ -6,7 +6,7 @@ public class UnPunctuatorNode extends Node {
     private final Ship    ship  = dfg.pool.allocateShip("Counter");
     public  final OutPort out   = new DockOutPort("out", ship.getDock("out"));
     public  final InPort  val   = new DockInPort("in1",  ship.getDock("in1"));
-    public  final InPort  count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, dfg.bv(1) });
+    public  final InPort  count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, bv(1) });
     public  final InPort  op    = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
             ship.getDock("inOp").getConstant("PASS_C2_V1"),
             ship.getDock("inOp").getConstant("DROP_C2_V1") } );