Exemplo n.º 1
0
  public void visitNode(FlatNode node) {
    System.out.println("Creating SliceNodes: " + node);
    OutputSliceNode output = new OutputSliceNode();
    InputSliceNode input = new InputSliceNode();
    FilterContent content;
    int mult = 1;

    if (node.isFilter()) {
      if (node.contents instanceof SIRFileWriter) {
        content = new FileOutputContent((SIRFileWriter) node.contents);
      } else if (node.contents instanceof SIRFileReader) {
        content = new FileInputContent((SIRFileReader) node.contents);
      } else content = new FilterContent(node.getFilter());

    } else if (node.isSplitter()) {
      CType type = CommonUtils.getOutputType(node);
      SIRIdentity id = new SIRIdentity(type);
      RenameAll.renameAllFilters(id);
      content = new FilterContent(id);
      if (!node.isDuplicateSplitter()) mult = node.getTotalOutgoingWeights();

    } else {
      // joiner
      CType type = CommonUtils.getOutputType(node);
      SIRIdentity id = new SIRIdentity(type);
      RenameAll.renameAllFilters(id);
      content = new FilterContent(id);
      mult = node.getTotalIncomingWeights();
    }
    if (exeCounts[0].containsKey(node.contents))
      content.setInitMult(mult * ((int[]) exeCounts[0].get(node.contents))[0]);
    else content.setInitMult(0);

    content.setSteadyMult(mult * ((int[]) exeCounts[1].get(node.contents))[0]);

    FilterSliceNode filterNode = new FilterSliceNode(content);
    if (node.isSplitter() || node.isJoiner()) generatedIds.add(filterNode);

    inputNodes.put(node.contents, input);
    outputNodes.put(node.contents, output);
    filterNodes.put(node.contents, filterNode);
  }
Exemplo n.º 2
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);
  }