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
}
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());
lf.deliver();
lf.literal(5);
lf.deliver();
- Gadgets.dispatch(fp, ctx);
+ ctx.dispatch(fp);
fp.flush();
System.out.println("checking debug.in");
lf.sendToken(debugIn.getDataDestination(), new BitVector(1).set(1));
lf.setPredicate(null);
- Gadgets.dispatch(fp, ctx);
+ ctx.dispatch(fp);
fp.flush();
long kk;
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);
}
//////////////////////////////////////////////////////////////////////////////
lf.recvToken();
lf.deliver();
- Gadgets.dispatch(fp, ctx2);
+ ctx2.dispatch(fp);
fp.flush();
int count = 0;
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");
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;
/** 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) {
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();
*
*/
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;
}
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) {
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
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);
}
}
-package edu.berkeley.fleet.ir;
+package edu.berkeley.fleet.loops;
import edu.berkeley.fleet.loops.*;
import java.util.concurrent.Semaphore;
import java.util.*;
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);
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();