Пример #1
0
  /**
   * generate the switch code for 1 data item given the list of destinations we do not want to
   * duplicate items until neccessary, so we have to keep track of all the routes and then generate
   * the switch code this way we can route multiple dests per route instruction
   */
  protected void generateSwitchCode(FlatNode fire, List<FlatNode> dests) {
    assert !(layout.getIdentities().contains(fire));

    // should only have one previous
    HashMap<ComputeNode, ComputeNode> prev = new HashMap<ComputeNode, ComputeNode>();
    HashMap<ComputeNode, HashSet> next = new HashMap<ComputeNode, HashSet>();

    ListIterator<FlatNode> destsIt = dests.listIterator();
    while (destsIt.hasNext()) {
      FlatNode dest = destsIt.next();
      assert dest != null;
      assert !(layout.getIdentities().contains(dest));
      //  System.out.println("  Dest: " + dest + " " + layout.getTile(dest));
      ComputeNode[] hops =
          layout
              .router
              .getRoute(ssg, layout.getComputeNode(fire), layout.getComputeNode(dest))
              .toArray(new ComputeNode[0]);

      assert hops.length > 1
          : "Error: Bad Layout (could not find route from "
              + fire.toString()
              + " -> "
              + dest.toString();

      // for (int i = 0; i < hops.length; i++)
      //      System.out.println("     " + hops[i]);

      // add to fire's next
      if (!next.containsKey(layout.getComputeNode(fire)))
        next.put(layout.getComputeNode(fire), new HashSet());
      next.get(layout.getComputeNode(fire)).add(hops[1]);
      // add to all other previous, next
      for (int i = 1; i < hops.length - 1; i++) {
        if (prev.containsKey(hops[i]))
          if (prev.get(hops[i]) != hops[i - 1])
            Utils.fail("More than one previous tile for a single data item");
        prev.put(hops[i], hops[i - 1]);
        if (!next.containsKey(hops[i])) next.put(hops[i], new HashSet());
        next.get(hops[i]).add(hops[i + 1]);
      }
      // add the last step, plus the dest to the dest map
      if (prev.containsKey(hops[hops.length - 1]))
        if (prev.get(hops[hops.length - 1]) != hops[hops.length - 2])
          Utils.fail("More than one previous tile for a single data item (2)");
      prev.put(hops[hops.length - 1], hops[hops.length - 2]);
      if (!next.containsKey(hops[hops.length - 1])) next.put(hops[hops.length - 1], new HashSet());
      next.get(hops[hops.length - 1]).add(hops[hops.length - 1]);
    }

    // create the appropriate amount of routing instructions
    int elements = Util.getTypeSize(CommonUtils.getOutputType(fire));
    for (int i = 0; i < elements; i++) asm(layout.getComputeNode(fire), prev, next);
  }
Пример #2
0
 // remove all tiles mapped to joiners from the coordinate hashset *tiles*
 private static void removeJoiners(HashSet<ComputeNode> tiles) {
   Iterator<FlatNode> it = layout.getJoiners().iterator();
   while (it.hasNext()) {
     tiles.remove(layout.getTile(it.next()));
   }
 }