Skip to content

Commit

Permalink
Avoid building huge unavailableNodes set in GlobalSignalRouting
Browse files Browse the repository at this point in the history
  • Loading branch information
eddieh-xlnx committed Nov 24, 2022
1 parent 8ee265c commit ff9ce78
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 63 deletions.
17 changes: 11 additions & 6 deletions src/com/xilinx/rapidwright/rwroute/GlobalSignalRouting.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.function.Predicate;

import com.xilinx.rapidwright.design.Design;
import com.xilinx.rapidwright.design.Net;
Expand Down Expand Up @@ -281,11 +282,13 @@ private static ClockRegion findCentroid(Net clk, Device device) {
/**
* Routes a static net (GND or VCC).
* @param currNet The current static net to be routed.
* @param unavailableNodes A set of unavailable nodes.
* @param isNodeUnavailable A Predicate lambda to check if node is unavailable for use.
* @param design The {@link Design} instance to use.
* @param routeThruHelper The {@link RouteThruHelper} instance to use.
*/
public static Map<SitePinInst, List<Node>> routeStaticNet(Net currNet, Set<Node> unavailableNodes, Design design, RouteThruHelper routeThruHelper) {
public static Map<SitePinInst, List<Node>> routeStaticNet(Net currNet,
Predicate<Node> isNodeUnavailable,
Design design, RouteThruHelper routeThruHelper) {
NetType netType = currNet.getType();
Set<PIP> netPIPs = new HashSet<>();
Map<SitePinInst, List<Node>> sinkPathNodes = new HashMap<>();
Expand Down Expand Up @@ -347,7 +350,7 @@ public static Map<SitePinInst, List<Node>> routeStaticNet(Net currNet, Set<Node>
for (Node uphillNode : routingNode.getNode().getAllUphillNodes()) {
if (routeThruHelper.isRouteThru(uphillNode, routingNode.getNode())) continue;
LightweightRouteNode nParent = RouterHelper.createRoutingNode(uphillNode, createdRoutingNodes);
if (!pruneNode(nParent, unavailableNodes, visitedRoutingNodes)) {
if (!pruneNode(nParent, isNodeUnavailable, visitedRoutingNodes)) {
nParent.setPrev(routingNode);
q.add(nParent);
}
Expand Down Expand Up @@ -375,11 +378,13 @@ public static Map<SitePinInst, List<Node>> routeStaticNet(Net currNet, Set<Node>
/**
* Checks if a {@link LightweightRouteNode} instance that represents a {@link Node} object should be pruned.
* @param routingNode The RoutingNode in question.
* @param unavailableNodes A set of unavailable Node instances.
* @param isNodeUnavailable A Predicate lambda to check if node is unavailable for use.
* @param visitedRoutingNodes RoutingNode instances that have been visited.
* @return true, if the RoutingNode instance should not be considered as an available resource.
*/
private static boolean pruneNode(LightweightRouteNode routingNode, Set<Node> unavailableNodes, Set<LightweightRouteNode> visitedRoutingNodes) {
private static boolean pruneNode(LightweightRouteNode routingNode,
Predicate<Node> isNodeUnavailable,
Set<LightweightRouteNode> visitedRoutingNodes) {
Node node = routingNode.getNode();
IntentCode ic = node.getTile().getWireIntentCode(node.getWire());
switch(ic) {
Expand All @@ -394,7 +399,7 @@ private static boolean pruneNode(LightweightRouteNode routingNode, Set<Node> una
return true;
default:
}
if (unavailableNodes.contains(node)) return true;
if (isNodeUnavailable.test(node)) return true;
return visitedRoutingNodes.contains(routingNode);
}

Expand Down
36 changes: 14 additions & 22 deletions src/com/xilinx/rapidwright/rwroute/RWRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,38 +407,30 @@ protected void routeStaticNets() {
.addAll(newVccPins);
}

// If connections of other nets are routed first, used resources should be preserved.
Set<Node> unavailableNodes = getAllUsedNodesOfRoutedConnections();
unavailableNodes.addAll(routingGraph.getPreservedNodes());
// If the connections of other nets are not routed yet,
// the nodes connected to pins of other nets must be preserved.
unavailableNodes.addAll(routingGraph.getNodes());

for (Map.Entry<Net,List<SitePinInst>> e : staticNetAndRoutingTargets.entrySet()) {
Net net = e.getKey();
List<SitePinInst> pins = e.getValue();
System.out.println("INFO: Route " + pins.size() + " pins of " + net);
Map<SitePinInst, List<Node>> sinksRoutingPaths = GlobalSignalRouting.routeStaticNet(net, unavailableNodes, design, routethruHelper);
Map<SitePinInst, List<Node>> sinksRoutingPaths = GlobalSignalRouting.routeStaticNet(net,
(node) -> {
Net preservedNet = routingGraph.getPreservedNet(node);
if (net == null) {
return true;
}
if (net == preservedNet) {
return false;
}
return routingGraph.getNode(node) != null;
},
design, routethruHelper);

for (Entry<SitePinInst, List<Node>> sinkPath : sinksRoutingPaths.entrySet()) {
for (Entry<?, List<Node>> sinkPath : sinksRoutingPaths.entrySet()) {
addPreservedNodes(sinkPath.getValue(), net);
unavailableNodes.addAll(sinkPath.getValue());
}
routingGraph.awaitPreserve();
}
}

/**
* Gets a set of nodes used by all the routed connections.
* @return A set of used nodes.
*/
private Set<Node> getAllUsedNodesOfRoutedConnections() {
Set<Node> nodes = new HashSet<>();
for (Connection connection : sortedIndirectConnections) {
if (connection.getNodes() != null) nodes.addAll(connection.getNodes());
}
return nodes;
}

/**
* Preserves a net by preserving all nodes use by the net.
* @param net The net to be preserved.
Expand Down
39 changes: 4 additions & 35 deletions src/com/xilinx/rapidwright/rwroute/RouteNodeGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,6 @@ protected boolean isExcluded(Node parent, Node child) {
return !allowedTileEnums.contains(tileType);
}

public List<Node> getPreservedNodes() {
awaitPreserve();
// TODO: Return a custom Interable to save on creating a new List
int size = preservedMapSize.get();
List<Node> nodes = new ArrayList<>(size);
for (Map.Entry<Tile,Net[]> e : preservedMap.entrySet()) {
Tile tile = e.getKey();
Net[] nets = e.getValue();
for (int wireIndex = 0; wireIndex < nets.length; wireIndex++) {
if (nets[wireIndex] != null) {
nodes.add(Node.getNode(tile, wireIndex));
}
}
}
assert(nodes.size() == size);
return nodes;
}

public Net getPreservedNet(Node node) {
return getPreservedNet(node.getTile(), node.getWire());
}
Expand All @@ -371,23 +353,6 @@ private RouteNode getNode(Tile tile, int wireIndex) {
return rnodes != null ? rnodes[wireIndex] : null;
}

public List<Node> getNodes() {
// TODO: Return a custom Interable to save on creating a new List
List<Node> nodes = new ArrayList<>(nodesMapSize);
for (Map.Entry<Tile,RouteNode[]> e : nodesMap.entrySet()) {
Tile tile = e.getKey();
RouteNode[] rnodes = e.getValue();
for (int wireIndex = 0; wireIndex < rnodes.length; wireIndex++) {
RouteNode rnode = rnodes[wireIndex];
if (rnode != null) {
nodes.add(Node.getNode(tile, wireIndex));
}
}
}
assert(nodes.size() == nodesMapSize);
return nodes;
}

public Iterable<RouteNode> getRnodes() {
return new Iterable<RouteNode>() {
final Iterator<Map.Entry<Tile, RouteNode[]>> it = nodesMap.entrySet().iterator();
Expand All @@ -399,6 +364,9 @@ public Iterator<RouteNode> iterator() {
return new Iterator() {
@Override
public boolean hasNext() {
if (curr == null) {
return false;
}
while(true) {
while (index < curr.length) {
if (curr[index] != null) {
Expand All @@ -410,6 +378,7 @@ public boolean hasNext() {
return false;
}
curr = it.next().getValue();
assert(curr != null);
index = 0;
}
}
Expand Down

0 comments on commit ff9ce78

Please sign in to comment.