From: adam Date: Mon, 4 Dec 2006 15:03:08 +0000 (+0100) Subject: checkpoint X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=5ae5525fa9e040d3570c5a5124959e60d210fb88;p=fleet.git checkpoint --- diff --git a/Makefile b/Makefile index 3dd2cfc..be93738 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,11 @@ go: fleeterpreter.jar java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser -run: fleeterpreter.jar - java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser < test.fleet +code: fleeterpreter.jar + java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-code < demo.fleet + +fabric: fleeterpreter.jar + java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-fabric < demo.fleet applet: fleeterpreter.jar java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetApplet < test.fleet diff --git a/demo.fleet b/demo.fleet index 85a2380..b36eb85 100644 --- a/demo.fleet +++ b/demo.fleet @@ -1,38 +1,7 @@ #include "demo.ships" -// NOTE: "accept" is a synonym for "move" it is less confusing in the case -// of inboxes, but is otherwise identical - -////////////////////////////////////////////////////////////////////////////// -// The following three instructions simply produce one hundred "3"s -// and put them into fifo "a". Ignore the switch-fabric clogging -// issue here; this is just setup for the rest of the code. - - 3 -> helper.in - copy helper.out -[10]-> source.in - discard helper.out -> () - - -////////////////////////////////////////////////////////////////////////////// -// set up a counting move of 10 items from source.out to dest.in, but require -// flow control tokens (10 items is too many to send at once) - - triggered move source.out -[10]-> dest.in - - -////////////////////////////////////////////////////////////////////////////// -// The next instruction tears down the "default" standing move on dest.in -// and uses the resulting tokens to prime source.out's pump. Once that -// has been kicked off, any subsequent incoming items will generate tokens -// which are sent back to the source outbox - - nop+ack dest.in -[3]-> source.out - accept+ack dest.in -[7]-> source.out - accept dest.in -[3]-> source.out - nop+ack dest.in -> fetch.release // then release the fetch - accept dest.in -[*]-> () // and return the fabric to normal - -{ tokensource.out -> halt.in } -> fetch.codebag // termination codebag +//3 -> adder1.a +3 -> debug.data diff --git a/demo.ships b/demo.ships index cf84978..a255134 100644 --- a/demo.ships +++ b/demo.ships @@ -1,8 +1,5 @@ #import edu.berkeley.fleet.ships -#ship helper : FifoShip -#ship source : FifoShip -#ship dest : FifoShip -#ship halt : HaltShip -#ship fetch : FetchShip -#ship tokensource : TokenSourceShip +#ship debug : DebugShip +#ship adder1 : AdderShip +#ship adder2 : AdderShip diff --git a/src/edu/berkeley/fleet/CodeBag.java b/src/edu/berkeley/fleet/CodeBag.java index 64edd4b..fb7325a 100644 --- a/src/edu/berkeley/fleet/CodeBag.java +++ b/src/edu/berkeley/fleet/CodeBag.java @@ -1,6 +1,7 @@ package edu.berkeley.fleet; import java.util.*; +import java.io.*; /** a codebag */ public class CodeBag { @@ -53,6 +54,39 @@ public class CodeBag { return parent.getCodeBag(name); } + public void dump(OutputStream os, int data) throws Exception { + os.write((byte)data); + System.out.print(data+" "); + } + public void dump(Fleet fleet) throws Exception { + OutputStream os = new FileOutputStream("fleet.bin"); + for(Dispatchable d : dispatchables) { + if (d instanceof Instruction) { + Instruction inst = (Instruction)d; + dump(os, inst.source.resolve(fleet).instr_bits); + dump(os, inst.source.resolve(fleet).instr_addr); + dump(os, 5); + dump(os, 10); // input+output + dump(os, inst.destination.resolve(fleet).bits); + dump(os, inst.destination.resolve(fleet).addr); + dump(os, 0); + System.out.println(); + } else if (d instanceof Literal.LiteralDatum) { + Literal.LiteralDatum ld = (Literal.LiteralDatum)d; + dump(os, ld.destination.resolve(fleet).instr_bits); + dump(os, ld.destination.resolve(fleet).instr_addr); + dump(os, 5); + dump(os, 2); + dump(os, 32); + dump(os, ld.data); + dump(os, 0); + System.out.println(); + } + } + os.flush(); + os.close(); + } + public String toString() { if (name != null) return name; StringBuffer ret = new StringBuffer(); diff --git a/src/edu/berkeley/fleet/Fleet.java b/src/edu/berkeley/fleet/Fleet.java index 2c570be..cd41c9f 100644 --- a/src/edu/berkeley/fleet/Fleet.java +++ b/src/edu/berkeley/fleet/Fleet.java @@ -8,6 +8,7 @@ import edu.berkeley.sbp.bind.*; import edu.berkeley.sbp.util.*; import java.util.*; import java.io.*; +import edu.berkeley.fleet.ships.*; public class Fleet { @@ -17,6 +18,7 @@ public class Fleet { public int[] mem = new int[0]; public ArrayList imports = new ArrayList(); + public ArrayList shiplist = new ArrayList(); public HashMap ships = new HashMap(); public void go() { @@ -83,4 +85,178 @@ public class Fleet { Log.data(data+"", source, dest); dest.addDataFromFabric(data); } + + public void dumpFabric(boolean quiet) { + // FIXME: this is really ugly: the order of port declarations in + // the XXXShip.java file must match the order in the .balsa file! + + ArrayList instructionports = new ArrayList(); + for(Ship ship : shiplist) + for(Port port : ship.portlist) + instructionports.add(port); + FabricTree instructions = + new FabricTree((Port[])instructionports.toArray(new Port[0]), + "horn", + "instruction"); + + ArrayList inputports = new ArrayList(); + for(Ship ship : shiplist) + for(Port port : ship.portlist) + if (port instanceof Inbox) + inputports.add(port); + FabricTree inputs = + new FabricTree((Port[])inputports.toArray(new Port[0]), + "horn", + "dest"); + + ArrayList outputports = new ArrayList(); + for(Ship ship : shiplist) + for(Port port : ship.portlist) + if (port instanceof Outbox && !(port.getShip() instanceof DebugShip)) + outputports.add(port); + FabricTree outputs = + new FabricTree((Port[])outputports.toArray(new Port[0]), + "funnel", + "source"); + + if (quiet) return; + System.out.println("import [balsa.sim.portio]"); + System.out.println("import [xbit]"); + System.out.println("import [funnel]"); + System.out.println("import [horn]"); + System.out.println("import [par2ser]"); + System.out.println("import [ser2par]"); + + HashSet added = new HashSet(); + for(Ship ship : shiplist) + if (!added.contains(ship.getClass())) { + added.add(ship.getClass()); + System.out.println("import ["+ship.getBalsaName()+"]"); + } + + System.out.println("procedure fabric(input top_in:XBit; output top_out:XBit)"); + System.out.println("is"); + System.out.println(" channel source_debug_out : XBit"); + instructions.dumpChannels(true); + outputs.dumpChannels(true); + inputs.dumpChannels(true); + System.out.println("begin"); + System.out.println(" loop source -> dest end"); + System.out.println(" || loop top_in -> instruction end"); + System.out.println(" || loop source_debug_out -> top_out end"); + System.out.println(""); + instructions.dumpChannels(false); + System.out.println(""); + outputs.dumpChannels(false); + System.out.println(""); + inputs.dumpChannels(false); + System.out.println(""); + for(Ship ship : shiplist) { + System.out.print(" || "); + System.out.print(ship.getBalsaName()); + System.out.print("("); + boolean first = true; + for(Port port : ship.portlist) { + if (!first) System.out.print(", "); + first = false; + System.out.print("instruction_"+port.getShip().getName()+"_"+port.getName()); + System.out.print(","); + if (port instanceof Inbox) + System.out.print("dest_"+port.getShip().getName()+"_"+port.getName()); + else + System.out.print("source_"+port.getShip().getName()+"_"+port.getName()); + System.out.print(" "); + } + System.out.println(")"); + } + System.out.println("end"); + } + + private static class FabricTree { + int master_idx = 1; + String prefix; + Node root; + public void dumpChannels(boolean decl) { root.dumpChannels(0, decl); } + public FabricTree(Port[] ports, String component, String prefix) { + this.prefix = prefix; + root = (Node)mkNode("", component, ports, 0, ports.length, 0, 0); + } + private Object mkNode(String name, String component, Port[] ports, int start, int end, int addr, int bits) { + if (end-start == 0) return null; + if (end-start == 1) { + Port p = ports[start]; + if (prefix.equals("instruction")) { + p.instr_addr = addr; + p.instr_bits = bits; + } else { + p.addr = addr; + p.bits = bits; + } + return p; + } + int len = end-start; + return new Node(name, + component, + mkNode(name+"_0", component, ports, start, start+len/2, (addr<<1)|0, bits+1), + mkNode(name+"_1", component, ports, start+len/2, end, (addr<<1)|1, bits+1), + addr, + bits); + } + private String describe(String prefix, Object o) { + if (o==null) return null; + if (o instanceof Port) { + Port p = (Port)o; + return prefix+"_"+p.getShip().getName()+"_"+p.getName(); + } + if (o instanceof Node) { + return ((Node)o).describe(prefix); + } + return null; + } + private class Node { + Object left; + Object right; + String name; + String component; + int addr; + int bits; + public Node(String name, String component, Object left, Object right, int addr, int bits) { + this.left = left; + this.right = right; + this.name = name; + this.component = component; + this.addr = addr; + this.bits = bits; + } + public void dumpChannels(int indentamount, boolean decl) { + String indent = ""; + for(int i=0; i portlist = new ArrayList(); private HashMap ports = new HashMap(); private String name; @@ -20,6 +21,7 @@ public abstract class Ship { public Ship(Fleet fleet, String name) { this.name = name; this.fleet = fleet; + fleet.shiplist.add(this); fleet.ships.put(name, this); } @@ -29,6 +31,8 @@ public abstract class Ship { return p; } + public String getBalsaName() { return name; } + public String getName() { return name; } public String toString() { return name; } public Fleet getFleet() { return fleet; } @@ -46,6 +50,7 @@ public abstract class Ship { } void addPort(String name, Port port) { + portlist.add(port); ports.put(name, port); } diff --git a/src/edu/berkeley/fleet/ships/AdderShip.java b/src/edu/berkeley/fleet/ships/AdderShip.java new file mode 100644 index 0000000..122105d --- /dev/null +++ b/src/edu/berkeley/fleet/ships/AdderShip.java @@ -0,0 +1,35 @@ +package edu.berkeley.fleet.ships; +import edu.berkeley.fleet.*; + +import java.util.*; +import java.io.*; + +/** + * @author Adam Megacz + */ +public class AdderShip extends Ship { + + private int link; + + DataInbox a = new DataInbox(this, "a"); + DataInbox b = new DataInbox(this, "b"); + DataOutbox out = new DataOutbox(this, "out"); + + public String getBalsaName() { return "adder"; } + + public AdderShip(Fleet fleet, String name) { + super(fleet, name); + } + + public void service() { + if (!out.readyForDataFromShip()) return; + if (!a.dataReadyForShip()) return; + if (!b.dataReadyForShip()) return; + + int inA = a.removeDataForShip(); + int inB = b.removeDataForShip(); + int result = inA + inB; + + out.addDataFromShip(result); + } +} diff --git a/src/edu/berkeley/fleet/ships/DebugShip.java b/src/edu/berkeley/fleet/ships/DebugShip.java index dc14450..2354a8e 100644 --- a/src/edu/berkeley/fleet/ships/DebugShip.java +++ b/src/edu/berkeley/fleet/ships/DebugShip.java @@ -6,18 +6,23 @@ import java.io.*; public class DebugShip extends Ship { - TokenInbox token = new TokenInbox(this, "token"); + //TokenInbox token = new TokenInbox(this, "token"); DataInbox data = new DataInbox(this, "data"); + DataOutbox out = new DataOutbox(this, "out"); + + public String getBalsaName() { return "debug"; } public DebugShip(Fleet fleet, String name) { super(fleet, name); } public void service() { + /* if (token.tokenReadyForShip()) { Log.println(Log.invert(" DEBUG: got a token"+Log.clreol())); token.removeTokenForShip(); } + */ if (data.dataReadyForShip()) Log.println(Log.invert(" DEBUG: got a datum: " + data.removeDataForShip()+Log.clreol())); }