rename Process to DataFlowGraph, de-static-ify some methods
authormegacz <adam@megacz.com>
Sun, 15 Mar 2009 00:31:19 +0000 (17:31 -0700)
committermegacz <adam@megacz.com>
Sun, 15 Mar 2009 00:31:19 +0000 (17:31 -0700)
src/edu/berkeley/fleet/dataflow/DataFlowGraph.java [moved from src/edu/berkeley/fleet/dataflow/Process.java with 89% similarity]
src/edu/berkeley/fleet/loops/MemoryUtils.java

@@ -14,40 +14,43 @@ import static edu.berkeley.fleet.util.BitManipulations.*;
 
 // does peer.recvWord() have to honor the currently-set predicate?
 
-// public class ReplaceModule extends Module { }
-// public class CountMergeModule extends Module { }
-// public class SortMergeModule extends Module { }
-// public class FanOutModule extends Module { }
-// public class MemoryModule extends Module { }
-// public class DoneModule extends Module { }
+// public class ReplaceNode extends Node { }
+// public class CountMergeNode extends Node { }
+// public class SortMergeNode extends Node { }
+// public class FanOutNode extends Node { }
+// public class MemoryNode extends Node { }
+// public class DoneNode extends Node { }
 
-public class Process {
-
-    public static int reset_count = 0;
-    public static HashSet<Dock> torpedoes = new HashSet<Dock>();
+public class DataFlowGraph {
 
     public final Fleet    fleet;
     public final ShipPool pool;
 
-    public Process(Fleet fleet) {
+    public DataFlowGraph(Fleet fleet) {
+        this(fleet, new ShipPool(fleet));
+    }
+    public DataFlowGraph(Fleet fleet, ShipPool pool) {
         this.fleet = fleet;
-        this.pool  = new ShipPool(fleet);
+        this.pool  = pool;
     }
 
-    private HashSet<Module> modules = new HashSet<Module>();
+    public static int reset_count = 0;
+    public static HashSet<Dock> torpedoes = new HashSet<Dock>();
+
+    private HashSet<Node> nodes = new HashSet<Node>();
 
     public void build(Context ctx) {
-        for(Module mod : modules)
+        for(Node mod : nodes)
             mod.build(ctx);
     }
     public void reset(Context ctx, int phase, Destination ackDestination) {
         reset_count = 0;
         torpedoes.clear();
-        for(Module mod : modules)
+        for(Node mod : nodes)
             mod.reset(ctx, phase, ackDestination);
     }
 
-    public class Module {
+    public class Node {
 
         void doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) {
             if (dock.getShip().getType().equals("Debug")) return;
@@ -127,8 +130,8 @@ public class Process {
             }
         }
 
-        public Module() {
-            Process.this.modules.add(this);
+        public Node() {
+            DataFlowGraph.this.nodes.add(this);
         }
 
         private HashMap<String,Port> ports = new HashMap<String,Port>();
@@ -145,8 +148,8 @@ public class Process {
             public final String name;
             public Port(String name) {
                 this.name = name;
-                if (Module.this.ports.get(name)!=null) throw new RuntimeException();
-                Module.this.ports.put(name,this);
+                if (Node.this.ports.get(name)!=null) throw new RuntimeException();
+                Node.this.ports.put(name,this);
             }
             public abstract void build(Context ctx);
             public abstract void reset(Context ctx, int phase, Destination ackDestination);
@@ -274,8 +277,8 @@ public class Process {
         }
     }
 
-    private static BitVector bv(long l) { return new BitVector(/*FIXME fleet.getWordWidth()*/37).set(l); }
-    private static BitVector[] bv(long[] l) {
+    private BitVector bv(long l) { return new BitVector(/*FIXME fleet.getWordWidth()*/37).set(l); }
+    private 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;
@@ -287,7 +290,7 @@ public class Process {
      *  that every datum sent there is consumed synchronously wiht
      *  data items sent to out.
      */
-    public class ForeverModule extends Module {
+    public class ForeverNode extends Node {
         private BitVector bv;
         public final OutPort out = new OutPort("out") {
                 public void sendToken(LoopFactory lf) { }
@@ -303,11 +306,11 @@ public class Process {
                     }
                 }
             };
-        public ForeverModule(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
-        public ForeverModule(final BitVector bv) { this.bv = bv; }
+        public ForeverNode(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
+        public ForeverNode(final BitVector bv) { this.bv = bv; }
     }
 
-    public class OnceModule extends Module {
+    public class OnceNode extends Node {
         private BitVector bv;
         public final OutPort out = new OutPort("out") {
                 public void sendToken(LoopFactory lf) { }
@@ -339,18 +342,18 @@ public class Process {
                     pip.count = 1;
                 }
             };
-        public OnceModule(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
-        public OnceModule(final BitVector bv) { this.bv = bv; }
+        public OnceNode(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
+        public OnceNode(final BitVector bv) { this.bv = bv; }
     }
 
-    public class DebugModule extends Module {
+    public class DebugNode extends Node {
         public final Ship ship = pool.allocateShip("Debug");
         public final InPort in = new DockInPort("in", ship.getDock("in"));
         // NOTE: shutdown needs to treat this specially
-        public DebugModule() { }
+        public DebugNode() { }
     }
 
-    public class UnPunctuatorModule extends Module {
+    public class UnPunctuatorNode extends Node {
         private final Ship    ship  = pool.allocateShip("Counter");
         public  final OutPort out   = new DockOutPort("out", ship.getDock("out"));
         public  final InPort  val   = new DockInPort("in1",  ship.getDock("in1"));
@@ -358,10 +361,10 @@ public class Process {
         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") } );
-        public UnPunctuatorModule() { }
+        public UnPunctuatorNode() { }
     }
 
-    public class PunctuatorModule extends Module {
+    public class PunctuatorNode extends Node {
         private final long    punc;
         private final Ship    ship  = pool.allocateShip("Counter");
         public  final OutPort out   = new DockOutPort("out", ship.getDock("out"));
@@ -370,52 +373,52 @@ public class Process {
                 ship.getDock("inOp").getConstant("PASS_C2_V1"),
                 ship.getDock("inOp").getConstant("PASS_C2_V2") } );
         public  final InPort  count;
-        public PunctuatorModule(long punc) {
+        public PunctuatorNode(long punc) {
             this.punc = punc;
             this.count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, bv(1), bv(punc) });
         }
     }
 
-    public class AluModule extends Module {
+    public class AluNode extends Node {
         public final Ship    ship = pool.allocateShip("Alu");
         public final InPort  in1 = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  in2 = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp = new DockInPort("inOp", ship.getDock("inOp"));
         public final OutPort out  = new DockOutPort("out", ship.getDock("out"));
-        public AluModule() { }
+        public AluNode() { }
     }
 
-    public class DownCounterModule extends Module {
+    public class DownCounterNode extends Node {
         public final Ship    ship  = pool.allocateShip("Counter");
         public final InPort  start = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  incr  = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp  = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("COUNT") });
         public final OutPort out   = new DockOutPort("out", ship.getDock("out"));
-        public DownCounterModule() { }
+        public DownCounterNode() { }
     }
 
-    public class RepeatModule extends Module {
+    public class RepeatNode extends Node {
         public final Ship    ship   = pool.allocateShip("Counter");
         public final InPort  count  = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  val    = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOP   = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("REPEAT_C1_V2") });
         public final OutPort out    = new DockOutPort("out", ship.getDock("out"));
-        public RepeatModule() { }
+        public RepeatNode() { }
     }
 
-    public class SortedMergeModule extends Module {
+    public class SortedMergeNode extends Node {
         public final Ship    ship = pool.allocateShip("Alu");
         public final InPort  in1  = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  in2  = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("MAXMERGE") });
         public final OutPort out  = new DockOutPort("out", ship.getDock("out"));
-        public SortedMergeModule() { }
+        public SortedMergeNode() { }
     }
 
-    public class MemoryModule extends Module {
+    public class MemoryNode extends Node {
         public final Ship    ship;
         public final InPort  inCBD;
         public final InPort  inAddrRead1;
@@ -425,7 +428,7 @@ public class Process {
         public final OutPort outRead1;
         public final OutPort outRead2;
         public final OutPort outWrite;
-        public MemoryModule(Ship memoryShip) {
+        public MemoryNode(Ship memoryShip) {
             this.ship = memoryShip;
             this.inCBD        = ship.getType().equals("Memory") ? new DockInPort("inCBD", ship.getDock("inCBD")) : null;
             this.inAddrWrite  = new DockInPort("inAddrWrite", ship.getDock("inAddrWrite"));
@@ -525,7 +528,7 @@ public class Process {
         fp = null;
 
         fp = fleet.run(new Instruction[0]);
-        MemoryUtils.writeMem(fp, mem1, 0, bv(vals));
+        MemoryUtils.writeMem(fp, mem1, 0, vals);
         int vals_length = vals.length;
 
         // Disable readback/writeback inside the loop
@@ -573,52 +576,52 @@ public class Process {
 
         //////////////////////////////////////////////////////////////////////////////
 
-        Process proc = new Process(fleet);
-        DebugModule dm = proc.new DebugModule();
+        DataFlowGraph proc = new DataFlowGraph(fleet);
+        DebugNode dm = proc.new DebugNode();
 
         int end_of_data = vals_length;
         int num_strides = end_of_data / (stride_length * 2);
 
-        MemoryModule mm  = proc.new MemoryModule(memoryShip1);
-        SortedMergeModule sm = proc.new SortedMergeModule();
+        MemoryNode mm  = proc.new MemoryNode(memoryShip1);
+        SortedMergeNode sm = proc.new SortedMergeNode();
 
         // So far: we have four spare Counter ships; one can be used for resetting
         for(int i=0; i<2; i++) {
 
-            DownCounterModule c0 = proc.new DownCounterModule();
-            DownCounterModule c1 = proc.new DownCounterModule();
+            DownCounterNode c0 = proc.new DownCounterNode();
+            DownCounterNode c1 = proc.new DownCounterNode();
 
-            c0.start.connect(proc.new ForeverModule(stride_length).out);
-            c0.incr.connect(proc.new ForeverModule(1).out);
+            c0.start.connect(proc.new ForeverNode(stride_length).out);
+            c0.incr.connect(proc.new ForeverNode(1).out);
 
-            c1.start.connect(proc.new OnceModule(end_of_data + i*stride_length).out);
-            c1.incr.connect(proc.new OnceModule(stride_length*2).out);
+            c1.start.connect(proc.new OnceNode(end_of_data + i*stride_length).out);
+            c1.incr.connect(proc.new OnceNode(stride_length*2).out);
 
-            RepeatModule r1 = proc.new RepeatModule();
+            RepeatNode r1 = proc.new RepeatNode();
             r1.val.connect(c1.out);
-            r1.count.connect(proc.new ForeverModule(stride_length).out);
+            r1.count.connect(proc.new ForeverNode(stride_length).out);
 
-            AluModule alu = proc.new AluModule();
+            AluNode alu = proc.new AluNode();
             alu.in1.connect(r1.out);
             alu.in2.connect(c0.out);
-            alu.inOp.connect(proc.new ForeverModule(((Module.DockInPort)alu.inOp).getConstant("ADD")).out);
+            alu.inOp.connect(proc.new ForeverNode(((Node.DockInPort)alu.inOp).getConstant("ADD")).out);
             alu.out.connect(i==0 ? mm.inAddrRead1 : mm.inAddrRead2);
 
-            PunctuatorModule punc = proc.new PunctuatorModule(-1);
-            punc.count.connect(proc.new ForeverModule(stride_length).out);
+            PunctuatorNode punc = proc.new PunctuatorNode(-1);
+            punc.count.connect(proc.new ForeverNode(stride_length).out);
             punc.val.connect(i==0 ? mm.outRead1 : mm.outRead2);
             punc.out.connect(i==0 ? sm.in1 : sm.in2);
         }
 
-        UnPunctuatorModule unpunc = proc.new UnPunctuatorModule();
+        UnPunctuatorNode unpunc = proc.new UnPunctuatorNode();
         unpunc.val.connect(sm.out);
-        unpunc.count.connect(proc.new ForeverModule(2*stride_length).out);
+        unpunc.count.connect(proc.new ForeverNode(2*stride_length).out);
 
-        DownCounterModule cw = proc.new DownCounterModule();
-        cw.start.connect(proc.new OnceModule(end_of_data).out);
-        cw.incr.connect(proc.new OnceModule(1).out);
+        DownCounterNode cw = proc.new DownCounterNode();
+        cw.start.connect(proc.new OnceNode(end_of_data).out);
+        cw.incr.connect(proc.new OnceNode(1).out);
 
-        MemoryModule mm2 = proc.new MemoryModule(memoryShip2);
+        MemoryNode mm2 = proc.new MemoryNode(memoryShip2);
         mm2.inAddrWrite.connect(cw.out);
         mm2.inDataWrite.connect(unpunc.out);
         mm2.outWrite.connect(dm.in);
index 05d14a9..bfbd26a 100644 (file)
@@ -18,6 +18,9 @@ public class MemoryUtils {
     public static void readMem(FleetProcess fp, Ship memory, long offset, BitVector[] vals) throws RuntimeException {
         doMem(true, fp, memory, offset, vals);
     }
+    public static void writeMem(FleetProcess fp, Ship memory, long offset, long[] vals) throws RuntimeException {
+        doMem(false, fp, memory, offset, long2bv(fp.getFleet(), vals));
+    }
     public static void writeMem(FleetProcess fp, Ship memory, long offset, BitVector[] vals) throws RuntimeException {
         doMem(false, fp, memory, offset, vals);
     }
@@ -104,6 +107,13 @@ public class MemoryUtils {
         System.out.println();
     }
 
+    private static BitVector[] long2bv(Fleet fleet, 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;
+    }
+
     public static void main(String[] s) throws Exception {
         Random random = new Random(System.currentTimeMillis());
         Fleet fleet = new Fpga();