add Fleet.getDefaultImpl() and use it in Makefile
authorAdam Megacz <adam@megacz.com>
Sun, 30 Aug 2009 02:18:46 +0000 (19:18 -0700)
committerAdam Megacz <adam@megacz.com>
Sun, 30 Aug 2009 02:18:46 +0000 (19:18 -0700)
Makefile
src/edu/berkeley/fleet/Main.java
src/edu/berkeley/fleet/api/Fleet.java
src/edu/berkeley/fleet/dataflow/MergeSort.java
src/edu/berkeley/fleet/dataflow/SortingDemo.java
src/edu/berkeley/fleet/loops/MemoryUtils.java

index b2b1bd9..586f284 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,17 @@
 
 ## Fleeterpreter ##############################################################################
 
-cp                = -cp fleet.jar:lib/RXTXcomm.jar
+ifeq ($(impl),ml509)
+java              = java -Xmx500m -Dfleet.impl=edu.berkeley.fleet.fpga.Fpga
+else
+ifeq ($(impl),java)
+java              = java -Xmx500m -Dfleet.impl=edu.berkeley.fleet.interpreter.Interpreter
+else
 java              = java -Xmx500m
+endif
+endif
+
+cp                = -cp fleet.jar:lib/RXTXcomm.jar
 
 run: fleet.jar; $(java) $(cp) $(interpreter_class)
 
@@ -21,7 +30,7 @@ fleet.jar: $(java_files) $(ship_files) src/edu/berkeley/fleet/assembler/fleet.g
        cd build/class/; jar xf ../../lib/edu.berkeley.sbp.jar
        cd build/class/; jar xf ../../lib/ibex.jar
        for A in `find ships -name \*.ship`;\
-         do java -cp fleet.jar:build/class edu.berkeley.fleet.Main expand $$A;\
+         do $(java) -cp fleet.jar:build/class edu.berkeley.fleet.Main expand $$A;\
          done
        javac -classpath lib/com.sun.async.test.jar:lib/ibex.jar:lib/RXTXcomm.jar:build/class${ps}lib/edu.berkeley.sbp.jar -d build/class/ `find build/java -name \*.java`
        echo 'Main-Class: edu.berkeley.fleet.Main' > build/class/manifest
@@ -97,7 +106,7 @@ build/fpga/main.bit: $(java_files) $(ship_files)
        $(java) $(cp) edu.berkeley.fleet.fpga.Fpga build/fpga/
        cp src/edu/berkeley/fleet/fpga/* build/fpga || true
        for A in `find ships -name \*.ship`;\
-         do java -cp build/class edu.berkeley.fleet.Main target=fpga expand $$A;\
+         do $(java) -cp build/class edu.berkeley.fleet.Main target=fpga expand $$A;\
          done
        ssh ${host} 'mkdir -p ${remote_dir}'
        ${rsync} --delete ./ ${host}:${remote_dir}
@@ -224,14 +233,11 @@ synth:
 
 
 runserver: fleet.jar
-       java -Djava.library.path=lib -cp fleet.jar:lib/RXTXcomm.jar edu.berkeley.fleet.fpga.Server
+       $(java) -Djava.library.path=lib -cp fleet.jar:lib/RXTXcomm.jar edu.berkeley.fleet.fpga.Server
 
 test:     fleet.jar
        $(java) -jar fleet.jar             test ships/*.ship tests
-       java -cp fleet.jar edu.berkeley.fleet.dataflow.MergeSort interpreter Memory 0 256
-testfpga: fleet.jar
-       $(java) -jar fleet.jar target=fpga test ships/*.ship tests
-       java -cp fleet.jar edu.berkeley.fleet.dataflow.MergeSort fpga Memory 0 256
+       $(java) -cp fleet.jar edu.berkeley.fleet.dataflow.MergeSort Memory 0 256
 
 ## Manual ####################################################################################
 
@@ -381,6 +387,7 @@ testlocal: fleet.jar
          export PATH=/proj/async/cad/linux/bin/:$$PATH; \
          /proj/async/cad/linux/lib/jdk1.5.0_05-linux-i586/bin/java \
          -cp `pwd`/../../../lib/com.sun.async.test.jar:`pwd`/../../../fleet.jar \
+         -Dfleet.impl=com.sun.vlsi.chips.marina.test.Marina \
          com.sun.vlsi.chips.marina.test.MarinaTest \
          -hsim \
          -testNum ${testnum} || tail -n 20 marina.spi.run
@@ -391,6 +398,7 @@ siliconlocal: fleet.jar
          /proj/async/cad/linux/lib/jdk1.5.0_05-linux-i586/bin/java \
          -cp `pwd`/../../../lib/com.sun.async.test.jar:`pwd`/../../../fleet.jar \
          -Djava.library.path=/proj/async/cad/test/ \
+         -Dfleet.impl=com.sun.vlsi.chips.marina.test.Marina \
          com.sun.vlsi.chips.marina.test.MarinaTest \
          -silicon \
          -testNum ${testnum}
@@ -409,9 +417,6 @@ chips/marina/testCode/marina.schematic-parasitics.spi: ${all_electric_files}
 electric:
        ${electric} chips/marina/electric/aMarinaM.jelib
 
-chaing:
-       java -cp lib/com.sun.async.test.jar com.sun.async.test.ChainG chips/marina/testCode/marina.xml
-
 sync:
        ${rsync} ${sun_server}:fleet/chips/marina/testCode/marina\*.dump ~/ || true
        ${rsync} ${sun_server}:fleet/chips/marina/testCode/marina.spi.out ~/${modname}.out || true
index f8e5956..885e0c1 100644 (file)
@@ -34,17 +34,7 @@ public class Main {
         }
 
         String target = options.get("target");
-        Fleet fleet;
-        if ("fpga".equals(target)) {
-            String bitfile = options.get("bitfile");
-            fleet = new Fpga();
-        } else if ("sim".equals(target) || "fleetsim".equals(target)) {
-            fleet = (Fleet)Class.forName("com.sunlabs.fleetsim.fleet.FleetDescription").newInstance();
-        } else if (command.equals("expand")) {
-            fleet = new Interpreter(new String[0], false);
-        } else {
-            fleet = new Interpreter();
-        }
+        Fleet fleet = Fleet.getDefaultImpl();
 
         if (!"yes".equals(options.get("verbose")))
             Log.log = null;
index 361f5af..0e9700c 100644 (file)
@@ -60,4 +60,16 @@ public abstract class Fleet implements Iterable<Ship> {
     public FleetProcess run(Instruction[] program) {
         throw new RuntimeException("class " + this.getClass().getName() + " does not implement method run()");
     }
+
+    /** Assumes that the system property "fleet.impl" holds the name of a subclass to instantiate */
+    public static Fleet getDefaultImpl() {
+        String impl = System.getProperty("fleet.impl");
+        if (impl==null) throw new RuntimeException("You must invoke the JVM with -Dfleet.impl=<impl>");
+        try {
+            return (Fleet)Class.forName(impl).newInstance();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
 }
index 459bab5..36f4624 100644 (file)
@@ -158,20 +158,15 @@ public class MergeSort {
     }
 
     public static void main(String[] s) throws Exception {
-        if (s.length != 4) {
-            System.err.println("usage: java " + MergeSort.class.getName() + " <target> <shipname> <base> <length>");
+        if (s.length != 3) {
+            System.err.println("usage: java " + MergeSort.class.getName() + " <shipname> <base> <length>");
             System.exit(-1);
         }
-        Fleet fleet = null;
-        if (s[0].equals("fpga"))             fleet = new Fpga();
-        else if (s[0].equals("interpreter")) {
-            fleet = new Interpreter();
-            Log.log = null;
-        }
+        Fleet fleet = Fleet.getDefaultImpl();
         ShipPool pool = new ShipPool(fleet);
-        Ship memory = pool.allocateShip(s[1]);
-        int base = Integer.parseInt(s[2]);
-        int length = Integer.parseInt(s[3]);
+        Ship memory = pool.allocateShip(s[0]);
+        int base = Integer.parseInt(s[1]);
+        int length = Integer.parseInt(s[2]);
 
         Random random = new Random(System.currentTimeMillis());        
         BitVector[] vals  = new BitVector[length];
index 2690646..6a0f6e5 100644 (file)
@@ -4,6 +4,7 @@ import java.io.*;
 import edu.berkeley.fleet.loops.*;
 import edu.berkeley.fleet.api.*;
 import edu.berkeley.fleet.fpga.*;
+import edu.berkeley.fleet.interpreter.*;
 import org.ibex.graphics.*;
 
 public class SortingDemo {
@@ -33,7 +34,7 @@ public class SortingDemo {
     }
 
     public static long timeit(int count, int inflight) throws Exception {
-        Fleet fleet = new Fpga();
+        Fleet fleet = Fleet.getDefaultImpl();
         FleetProcess fp = fleet.run(new Instruction[0]);
         ShipPool pool = new ShipPool(fleet);
         //Program program = new Program(pool.allocateShip("Memory"));
@@ -116,10 +117,10 @@ public class SortingDemo {
         lf.collectWord();
         lf.sendWord(debug.getDock("in"));
 
-        FpgaDock out = (FpgaDock)counter1.getDock("out");
-        FpgaDock in  = (FpgaDock)counter2.getDock("in2");
-        System.out.println("distance is " + out.getPathLength((FpgaDestination)in.getDataDestination()));
-        System.out.println("reverse distance is " + in.getPathLength((FpgaDestination)out.getDataDestination()));
+        Dock out = (Dock)counter1.getDock("out");
+        Dock in  = (Dock)counter2.getDock("in2");
+        //System.out.println("distance is " + out.getPathLength((FpgaDestination)in.getDataDestination()));
+        //System.out.println("reverse distance is " + in.getPathLength((FpgaDestination)out.getDataDestination()));
 
         for(Instruction i : cb.emit()) System.out.println(i);
         cb.dispatch(fp, true);
@@ -137,12 +138,11 @@ public class SortingDemo {
     public static long mergeSort(int vals_length, int inflight, String shipType, int clearAmount) throws Exception {
         Node.CAPACITY = inflight;
 
-        Fleet fleet = new Fpga();
+        Fleet fleet = Fleet.getDefaultImpl();
         FleetProcess fp = fleet.run(new Instruction[0]);
         ShipPool pool = new ShipPool(fleet);
         Ship mem1 = pool.allocateShip(shipType);
 
-
         if (clearAmount > 0)
             randomizeMemory(fp, pool, mem1, 0, clearAmount, false);
 
index 8290954..1527c3e 100644 (file)
@@ -6,6 +6,7 @@ import java.io.*;
 import java.net.*;
 import edu.berkeley.fleet.two.*;
 import edu.berkeley.fleet.fpga.*;
+import edu.berkeley.fleet.interpreter.*;
 import edu.berkeley.fleet.api.*;
 import edu.berkeley.fleet.api.Instruction.*;
 import edu.berkeley.fleet.api.Instruction.Set;
@@ -206,11 +207,9 @@ public class MemoryUtils {
 
     public static void main(String[] s) throws Exception {
         Random random = new Random(System.currentTimeMillis());
-        Fleet fleet = new Fpga();
+        Fleet fleet = Fleet.getDefaultImpl();
         FleetProcess fp = fleet.run(new Instruction[0]);
-        Ship memory = fleet.getShip("DDR2",0);
-        //Ship memory = fleet.getShip("Dvi",0);
-        //Ship memory = fleet.getShip("Memory",0);
+        Ship memory = fleet.getShip(s[0],0);
 
         //int size = (548 * 478) / 2;
         int size = 2048;