move Gadgets to MemoryUtils, discard a ton of obsolete junk
authormegacz <adam@megacz.com>
Fri, 13 Mar 2009 18:09:03 +0000 (11:09 -0700)
committermegacz <adam@megacz.com>
Fri, 13 Mar 2009 18:09:03 +0000 (11:09 -0700)
src/edu/berkeley/fleet/ir/Process.java
src/edu/berkeley/fleet/loops/Context.java
src/edu/berkeley/fleet/loops/LoopFactory.java
src/edu/berkeley/fleet/loops/MemoryUtils.java [moved from src/edu/berkeley/fleet/ir/Gadgets.java with 50% similarity]

index 6b35112..47a6604 100644 (file)
@@ -521,7 +521,7 @@ public class Process {
         fp = null;
 
         fp = fleet.run(new Instruction[0]);
-        Gadgets.writeMem(fp, mem1, 0, bv(vals));
+        MemoryUtils.writeMem(fp, mem1, 0, bv(vals));
         int vals_length = vals.length;
 
         // Disable readback/writeback inside the loop
@@ -550,7 +550,7 @@ public class Process {
         }
 
         BitVector[] bvs = new BitVector[vals_length];
-        Gadgets.readMem(fp, mem1, 0, bvs);
+        MemoryUtils.readMem(fp, mem1, 0, bvs);
         System.out.println("results:");
         for(int i=0; i<vals_length; i++)
             System.out.println(bvs[i].toLong());
@@ -570,7 +570,7 @@ public class Process {
         lf.deliver();
         lf.literal(5);
         lf.deliver();
-        Gadgets.dispatch(fp, ctx);
+        ctx.dispatch(fp);
         fp.flush();
 
         System.out.println("checking debug.in");
@@ -616,7 +616,7 @@ public class Process {
                     lf.sendToken(debugIn.getDataDestination(), new BitVector(1).set(1));
                     lf.setPredicate(null);
 
-                    Gadgets.dispatch(fp, ctx);
+                    ctx.dispatch(fp);
                     fp.flush();
 
                     long kk;
@@ -639,7 +639,7 @@ public class Process {
         if (vals != null) {
             BitVector[] mem = new BitVector[vals_length];
             for(int i=0; i<mem.length; i++) mem[i] = new BitVector(fleet.getWordWidth()).set(vals[i]);
-            Gadgets.writeMem(fp, memoryShip1, 0, mem);
+            MemoryUtils.writeMem(fp, memoryShip1, 0, mem);
         }
 
         //////////////////////////////////////////////////////////////////////////////
@@ -729,7 +729,7 @@ public class Process {
         lf.recvToken();
         lf.deliver();
 
-        Gadgets.dispatch(fp, ctx2);
+        ctx2.dispatch(fp);
         fp.flush();
 
         int count = 0;
@@ -762,10 +762,10 @@ public class Process {
             lf.collectWord();
             lf.sendToken(counter.getDock("in2").getInstructionDestination());  // HACK: we don't check to make sure this hits
             lf.sendToken(debugIn.getDataDestination());
-            Gadgets.dispatch(fp, ctx3);  // HACK: we don't check to make sure that this is "firmly in place"
+            ctx3.dispatch(fp);  // HACK: we don't check to make sure that this is "firmly in place"
 
             for(Dock dock : torpedoes) fp.sendToken(dock.getInstructionDestination());
-            Gadgets.dispatch(fp, ctx2);
+            ctx2.dispatch(fp);
             fp.flush();
             System.out.println("flushed");
 
@@ -786,7 +786,7 @@ public class Process {
         if (vals != null) {
             ret = new long[vals_length];
             BitVector[] mem = new BitVector[vals_length];
-            Gadgets.readMem(fp, memoryShip2, 0, mem);
+            MemoryUtils.readMem(fp, memoryShip2, 0, mem);
             for(int i=0; i<ret.length; i++) ret[i] = mem[i].toLong();
         }
         return ret;
index 7db5290..00bd35d 100644 (file)
@@ -62,4 +62,12 @@ public class Context {
             lf.emit(ic);
     }
 
+    public void dispatch(FleetProcess fp) {
+        ArrayList<Instruction> ai;
+        emit(ai = new ArrayList<Instruction>());
+        for(Instruction ins : ai) {
+            fp.sendInstruction(ins);
+        }
+    }
+
 }
index 4873c79..d7b6648 100644 (file)
@@ -221,7 +221,7 @@ public class LoopFactory {
     /** sets the data latch to a literal value */
     public void literal(BitVector literal) {
         // FIXME: code duplication here
-        // FIXME: be more intelligent here to avoid shifts if possible?
+        // FEATURE: be more intelligent here to avoid shifts if possible?
         int counter = 0;
         while(counter < dock.getShip().getFleet().getWordWidth()) counter += ctx.fleet.getShiftWidth();
         while(counter > 0) {
@@ -263,7 +263,6 @@ public class LoopFactory {
                                              newFlagB));
     }
 
-    // FIXME: what if we're using an ILC-loop?
     /** abort the loop immediately (if predicate is met) and invoke the successor loop */
     public void abort() {
         flush_pending();
@@ -297,11 +296,12 @@ public class LoopFactory {
      *
      */
     public void emit(ArrayList<Instruction> ic) {
+        emit(ic, dock.getInstructionFifoSize());
+    }
+    private void emit(ArrayList<Instruction> ic, int capacity) {
         flush_pending();
         optimize();
 
-        // FIXME: if this loop is a count==1 loop, we can emit the successor loop along with it...
-
         // the number of instructions after and including the first blocking instruction
         int numInstructionsNotIncludingNonblockingPrefix = 0;
         int loopSize = 0;
@@ -323,8 +323,7 @@ public class LoopFactory {
         }
 
         if (count==1) {
-            if (/*!instructionFifoSizeCheckDisabled &&*/
-                numInstructionsNotIncludingNonblockingPrefix > dock.getInstructionFifoSize())
+            if (numInstructionsNotIncludingNonblockingPrefix > capacity)
                 throw new RuntimeException("instruction sequence is too long for instruction fifo at " + dock);
         } else {
             if (count != 0) {
@@ -334,13 +333,10 @@ public class LoopFactory {
                 loopSize++;
             }
         }
-        if (count!=1) {
+        if (count!=1)
             ic.add(new Instruction.Abort(dock, Predicate.FlagD));
-        }
-        if (ctx.autoflush && !"Debug".equals(dock.getShip().getType()) && next==null) {
-            if (dock.isInputDock())
-                ic.add(new Instruction.Flush(dock, true, Predicate.FlagD));
-        }
+        if (ctx.autoflush && next==null && dock.isInputDock())
+            ic.add(new Instruction.Flush(dock, true, Predicate.FlagD));
 
         // FIXME: need to somehow deal with count!=0 loops that are
         // torpedoable; they need to wait for a torpedo to arrive
@@ -348,16 +344,13 @@ public class LoopFactory {
 
         if (count!=1) {
             ic.add(new Instruction.Tail(dock));
-            if (/*!instructionFifoSizeCheckDisabled &&*/
-                loopSize > dock.getInstructionFifoSize())
+            if (loopSize > capacity)
                 throw new RuntimeException("instruction loop is too long for instruction fifo");
         }
 
         if (next != null) {
             if (count != 1) throw new RuntimeException("no support for successor loops when count!=1 yet");
-            // FIXME: must include check based on reduced FIFO capacity
-            // FIXME: review this
-            next.emit(ic);
+            next.emit(ic, capacity - loopSize);
         }
     }
 
similarity index 50%
rename from src/edu/berkeley/fleet/ir/Gadgets.java
rename to src/edu/berkeley/fleet/loops/MemoryUtils.java
index 8e0c19c..05d14a9 100644 (file)
@@ -1,4 +1,4 @@
-package edu.berkeley.fleet.ir;
+package edu.berkeley.fleet.loops;
 import edu.berkeley.fleet.loops.*;
 import java.util.concurrent.Semaphore;
 import java.util.*;
@@ -9,27 +9,11 @@ import edu.berkeley.fleet.api.*;
 import edu.berkeley.fleet.api.Instruction.*;
 import edu.berkeley.fleet.api.Instruction.Set;
 import edu.berkeley.fleet.api.Instruction.Set.*;
-import static edu.berkeley.fleet.util.BitManipulations.*;
-import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
-import edu.berkeley.fleet.api.Instruction.Set;
 import edu.berkeley.fleet.api.Instruction.Set.SetDest;
 import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
 import static edu.berkeley.fleet.api.Predicate.*;
 
-/*
-  - Change Alu behavior to "drain one"
-  - DROP1, DROP2
-  - secondary DDR chip
-  - facility for launching and Concluding a context
-  - implement the merge operation and test it
-  - test case for DRAM ship
-  - hideously ugly hacks in Verilog.java!
-  - dispatch ALWAYS needs to go via memory first, unless transmissions to
-    debugIn are flow-controlled properly
-  - current write-to-mem transformation screws up -- it can clog
- */
-
-public class Gadgets {
+public class MemoryUtils {
 
     public static void readMem(FleetProcess fp, Ship memory, long offset, BitVector[] vals) throws RuntimeException {
         doMem(true, fp, memory, offset, vals);
@@ -120,114 +104,6 @@ public class Gadgets {
         System.out.println();
     }
 
-    /** returns the output Dock at which the merged values may be collected */
-    public static Dock mergeSort(FleetProcess fp,
-                                 Context ctx,
-                                 Ship sourceMem,
-                                 Ship destMem,
-                                 long read_start,
-                                 long write_start,
-                                 int  stride_length,    /* per arity */
-                                 int  num_strides,
-                                 int  arity
-                                 )
-        throws RuntimeException {
-
-        if (arity != 2) throw new RuntimeException();
-        if (num_strides != 1) throw new RuntimeException();
-        LoopFactory lf;
-
-        Dock mem_inAddrData = sourceMem.getDock("inAddrData");
-        Dock mem_out        = sourceMem.getDock("out");
-
-        Ship merger = ctx.allocateShip("Alu");
-        Dock[] merger_inputs = new Dock[] { merger.getDock("in1"), merger.getDock("in2") };
-        Dock merger_inOp = merger.getDock("inOp");
-
-        // Address Generators (arity-many) /////////////////////////////////////////////////////////////////////
-
-        Ship[] address_generators = new Ship[arity];
-        for(int i=0; i<address_generators.length; i++) {
-            address_generators[i] = ctx.allocateShip("Alu");
-            long start = read_start + i*stride_length;
-            int  count = stride_length;
-
-            Dock ag_out = address_generators[i].getDock("out");
-            Dock ag_op  = address_generators[i].getDock("inOp");
-            Dock ag_in1 = address_generators[i].getDock("in1");
-            Dock ag_in2 = address_generators[i].getDock("in2");
-            BitVector signal = new BitVector(1/*FIXME*/).set(i/*FIXME*/);
-
-            lf = new LoopFactory(ctx, ag_in1, 0);
-            lf.literal(1);
-            lf = lf.makeNext(count);
-            
-
-            lf = new LoopFactory(ctx, ag_out, 1);
-            lf.literal(start);
-            lf = lf.makeNext(0);
-            lf.recvToken();
-            lf.sendWord(mem_inAddrData.getDataDestination(), signal);
-            //lf.sendWord(ag_in1);
-            // FIXME ...
-        }
-
-        // Memory Read ////////////////////////////////////////////////////////////////////////////////////////
-
-        lf = new LoopFactory(ctx, mem_inAddrData, 0);
-        lf.recvWord();
-        lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
-        lf.setPredicate(Predicate.NotFlagA);
-        lf.sendToken(mem_out.getDataDestination(), new BitVector(1/*FIXME*/).set(0));   // note: arity-many tokens may pile up at mem_out...
-        lf.setPredicate(Predicate.FlagA);
-        lf.sendToken(mem_out.getDataDestination(), new BitVector(1/*FIXME*/).set(1));
-        lf.setPredicate(null);
-        lf.deliver();
-
-        lf = new LoopFactory(ctx, mem_out, 0);
-        lf.collectWord();
-        lf.recvToken();
-        lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
-        lf.setPredicate(Predicate.NotFlagA);
-        lf.sendWord(merger_inputs[0].getDataDestination());
-        lf.setPredicate(Predicate.FlagA);
-        lf.sendWord(merger_inputs[1].getDataDestination());
-        lf.setPredicate(null);
-
-        // Merger /////////////////////////////////////////////////////////////////////////////////////////////
-
-        for(int i=0; i<merger_inputs.length; i++) {
-            lf = new LoopFactory(ctx, merger_inputs[i], stride_length);
-            lf.sendToken(address_generators[i].getDock("out").getDataDestination());
-            lf.recvWord();
-            lf.deliver();
-
-            lf = lf.makeNext(1);
-            lf.literal(-1);
-            lf.deliver();
-        }
-
-        lf = new LoopFactory(ctx, merger_inOp, 1);
-        lf.literal(5); // MIN
-        lf = lf.makeNext(stride_length * arity);
-        lf.deliver();
-        lf = lf.makeNext(1);
-        lf.literal(7); // DROP1
-        lf.deliver();
-        lf.literal(8); // DROP2
-        lf.deliver();
-
-        return merger.getDock("out");
-    }
-
-    public static void dispatch(FleetProcess fp, Context ctx) {
-        ArrayList<Instruction> ai;
-        ctx.emit(ai = new ArrayList<Instruction>());
-        for(Instruction ins : ai) {
-            fp.sendInstruction(ins);
-        }
-    }
-
     public static void main(String[] s) throws Exception {
         Random random = new Random(System.currentTimeMillis());
         Fleet fleet = new Fpga();