Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eddieh-xlnx committed Nov 21, 2022
1 parent 417cab9 commit ba63b33
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 79 deletions.
23 changes: 4 additions & 19 deletions src/com/xilinx/rapidwright/rwroute/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.xilinx.rapidwright.design.Net;
import com.xilinx.rapidwright.design.SitePinInst;
import com.xilinx.rapidwright.device.Node;
import com.xilinx.rapidwright.device.Tile;
import com.xilinx.rapidwright.timing.TimingEdge;
import com.xilinx.rapidwright.timing.delayestimator.DelayEstimatorBase;

Expand Down Expand Up @@ -219,6 +218,10 @@ public boolean useRnodesWithMultiDrivers() {
}

public void addRnode(RouteNode rn) {
xMinBB = (short) Math.min(xMinBB, rn.getBeginTileXCoordinate() - 1);
xMaxBB = (short) Math.max(xMaxBB, rn.getEndTileXCoordinate() + 1);
yMinBB = (short) Math.min(yMinBB, rn.getBeginTileYCoordinate() - 1);
yMaxBB = (short) Math.max(yMaxBB, rn.getEndTileYCoordinate() + 1);
rnodes.add(rn);
}

Expand Down Expand Up @@ -401,24 +404,6 @@ public void enlargeBoundingBox(int horizontalIncrement, int verticalIncrement) {
yMinBB = yMinBB < 0? -1:yMinBB;
}

public void fitBoundingBoxToRouting() {
int xmin = Integer.MAX_VALUE;
int xmax = Integer.MIN_VALUE;
int ymin = Integer.MAX_VALUE;
int ymax = Integer.MIN_VALUE;
for (RouteNode rnode : rnodes) {
Tile beginTile = rnode.node.getTile();
xmin = (short) Math.min(xmin, beginTile.getTileXCoordinate());
xmax = (short) Math.max(xmax, rnode.getEndTileXCoordinate());
ymin = (short) Math.min(ymin, beginTile.getTileYCoordinate());
ymax = (short) Math.max(ymax, rnode.getEndTileYCoordinate());
}
xMinBB = (short) Math.min(xMinBB, xmin - 1);
xMaxBB = (short) Math.max(xMaxBB, xmax + 1);
yMinBB = (short) Math.min(yMinBB, ymin - 1);
yMaxBB = (short) Math.max(yMaxBB, ymax + 1);
}

@Override
public int hashCode() {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* Adapted from RapidWright APIs.
*/
public class GlobalSignalRouting {
final private static HashSet<String> lutOutputPinNames;
private static final HashSet<String> lutOutputPinNames;
static {
lutOutputPinNames = new HashSet<>();
for (String cle : new String[]{"L", "M"}) {
Expand Down
8 changes: 2 additions & 6 deletions src/com/xilinx/rapidwright/rwroute/NetWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.List;

import com.xilinx.rapidwright.design.Net;
import com.xilinx.rapidwright.design.SitePinInst;
import com.xilinx.rapidwright.device.Tile;

/**
* A wrapper class of {@link Net} with additional information for the router.
Expand Down Expand Up @@ -85,10 +83,8 @@ public void computeHPWLAndCenterCoordinates(int[] nextLagunaColumn, int[] prevLa
sourceRnodeAdded = true;
count++;
}
SitePinInst sink = connection.getSink();
Tile sinkTile = sink.getTile();
int x = sinkTile.getTileXCoordinate();
int y = sinkTile.getTileYCoordinate();
short x = connection.getSinkRnode().getEndTileXCoordinate();
short y = connection.getSinkRnode().getEndTileYCoordinate();
xMin = Integer.min(xMin, x);
yMin = Integer.min(yMin, y);
xMax = Integer.max(xMax, x);
Expand Down
34 changes: 20 additions & 14 deletions src/com/xilinx/rapidwright/rwroute/PartialRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
public class PartialRouter extends RWRoute{

final protected boolean softPreserve;
protected final boolean softPreserve;

protected Set<NetWrapper> partiallyPreservedNets;

Expand Down Expand Up @@ -112,31 +112,29 @@ public PartialRouter(Design design, RWRouteConfig config, Collection<SitePinInst
* @return True if arc is part of an existing route.
*/
private boolean isPartOfExistingRoute(Node start, Node end) {
// End node must be preserved
if (!routingGraph.isPreserved(end))
return false;

// End node must have been created already
// End node can only be part of existing route if it is in the graph already
RouteNode endRnode = routingGraph.getNode(end);
if (endRnode == null)
return false;

// Only check if end node has not been visited
// If end node has been visited already
if (endRnode.isVisited()) {
// Visited possibly from a different arc uphill of end, or possibly from
// the same start -> end arc during prepareRouteConnection()
return false;
}

// Presence means that the only arc allowed to enter this end node is if it came from prev
// Presence of a prev pointer means that only that arc allowed to enter this end node
RouteNode prev = endRnode.getPrev();
if (prev != null) {
assert((prev.getNode() == start) == prev.getNode().equals(start));
if (prev.getNode() == start) {
assert(routingGraph.isPreserved(end));
return true;
}
}

// No presence means that it is used by a fully preserved net which needs no routing
return false;
}

Expand Down Expand Up @@ -229,12 +227,13 @@ protected void determineRoutingTargets() {
for (Connection connection : netWrapper.getConnections()) {
if (connection.getSink().isRouted()) {
finishRouteConnection(connection, connection.getSinkRnode());
connection.fitBoundingBoxToRouting();
assert(connection.getSink().isRouted());
}
}
}

routingGraph.resetExpansion();

// Mark each static sink node -- if it exists -- as being used, unpreserving any nets
// using those nodes (likely bounce points) as needed
for (Map.Entry<Net,List<SitePinInst>> e : staticNetAndRoutingTargets.entrySet()) {
Expand Down Expand Up @@ -389,6 +388,11 @@ protected void unpreserveNet(Net net) {
Node start = (pip.isReversed()) ? pip.getEndNode() : pip.getStartNode();
Node end = (pip.isReversed()) ? pip.getStartNode() : pip.getEndNode();

// Do not include arcs that the router wouldn't explore
// e.g. those that leave the INT tile, since we project pins to their INT tile
if (routingGraph.isExcluded(start, end))
continue;

// Since net already exists, all the nodes it uses must already
// have been created
RouteNode rstart = routingGraph.getNode(start);
Expand All @@ -403,9 +407,8 @@ protected void unpreserveNet(Net net) {
boolean endPreserved = routingGraph.unpreserve(end);
assert(rendAdded == endPreserved);

// Check the prev pointer consistent with PIP
// (it may be null because isPartOfExistingRoute() will erase prev once rend was created)
assert(rend.getPrev() == null || rend.getPrev().equals(rstart));
// Check the prev pointer is consistent with PIP
assert(rend.getPrev() == rstart);
}
} else {
// Net needs to be created
Expand Down Expand Up @@ -441,7 +444,6 @@ protected void unpreserveNet(Net net) {
if (netnewConnection.getSink().isRouted()) {
finishRouteConnection(netnewConnection, netnewConnection.getSinkRnode());
assert(netnewConnection.getSink().isRouted());
netnewConnection.fitBoundingBoxToRouting();
}
}

Expand All @@ -455,6 +457,9 @@ protected void unpreserveNet(Net net) {
}
}

routingGraph.resetExpansion();

// TODO: Avoid using a set by backtracking from sinks (and stubs) until an already-reset node is seen
for (RouteNode rnode : rnodes) {
Node toBuild = rnode.getNode();
// Check already unpreserved above
Expand All @@ -467,7 +472,8 @@ protected void unpreserveNet(Net net) {
if (parent == null)
continue;

// Reset its list of children so that they may be regenerated to include newly unpreserved node
// Reset its list of children so that they may be regenerated to include the
// newly unpreserved node
parent.resetChildren();
}

Expand Down
25 changes: 13 additions & 12 deletions src/com/xilinx/rapidwright/rwroute/RWRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class RWRoute{
private long nodesPopped;

/** The maximum criticality constraint of connection */
final private static float MAX_CRITICALITY = 0.99f;
private static final float MAX_CRITICALITY = 0.99f;
/** The minimum criticality of connections that should be re-routed, updated after each iteration */
private float minRerouteCriticality;
/** The list of critical connections */
Expand Down Expand Up @@ -243,7 +243,7 @@ protected TimingManager createTimingManager(ClkRouteTiming clkTiming, Collection
protected void determineRoutingTargets() {
categorizeNets();

// Wait for all outstanding RoutingGraph.asyncPreserve() calls to complete
// Wait for all outstanding RouteNodeGraph.asyncPreserve() calls to complete
// FIXME: Calling thread does nothing while waiting
routingGraph.awaitPreserve();
}
Expand Down Expand Up @@ -505,7 +505,7 @@ protected NetWrapper createNetWrapperAndConnections(Net net) {
}
sourceINTRnode = getOrCreateRouteNode(sourceINTNode, RouteNodeType.PINFEED_O);

// Pre-emptively set up alternate source
// Pre-emptively set up alternate source since we are expanding from both sources
SitePinInst altSource = net.getAlternateSource();
if (altSource == null) {
altSource = DesignTools.getLegalAlternativeOutputPin(net);
Expand All @@ -515,6 +515,7 @@ protected NetWrapper createNetWrapperAndConnections(Net net) {
}
}
if (altSource != null) {
assert(!altSource.equals(source));
Node altSourceNode = RouterHelper.projectOutputPinToINTNode(altSource);
if (altSourceNode != null) {
altSourceINTRnode = getOrCreateRouteNode(altSourceNode, RouteNodeType.PINFEED_O);
Expand Down Expand Up @@ -975,6 +976,9 @@ private void updateCost() {
overUsedRnodes.add(rnode);
rnode.setPresentCongestionCost(1 + (overuse + 1) * presentCongestionFactor);
rnode.setHistoricalCongestionCost(rnode.getHistoricalCongestionCost() + overuse * historicalCongestionFactor);
} else {
assert(overuse < 0);
assert(rnode.getPresentCongestionCost() == 1);
}
}
}
Expand Down Expand Up @@ -1203,11 +1207,11 @@ private void routeConnection(Connection connection) {
assert(queue.isEmpty());
// Clears previous route of the connection
connection.resetRoute();
assert(connection.getRnodes().isEmpty());
assert(!connection.getSink().isRouted());
}

routingGraph.resetExpansion();
assert(!connection.getSinkRnode().isVisited());
}

/**
Expand Down Expand Up @@ -1301,8 +1305,7 @@ private void saveRouting(Connection connection, RouteNode rnode) {
connection.resetRoute();
do {
connection.addRnode(rnode);
rnode = rnode.getPrev();
} while (rnode != null);
} while ((rnode = rnode.getPrev()) != null);

List<RouteNode> rnodes = connection.getRnodes();
RouteNode sourceRnode = rnodes.get(rnodes.size()-1);
Expand Down Expand Up @@ -1340,7 +1343,7 @@ private void saveRouting(Connection connection, RouteNode rnode) {
/**
* Explores children (downhill rnodes) of a rnode for routing a connection and pushes the child into the queue,
* if it is the target or is an accessible routing resource.
* @param rnode The parent rnode popped out from the queue.
* @param rnode The rnode popped out from the queue.
* @param connection The connection that is being routed.
* @param shareWeight The criticality-aware share weight for a new sharing factor.
* @param rnodeCostWeight The cost weight of the childRnode
Expand Down Expand Up @@ -1460,14 +1463,12 @@ private void evaluateCostAndPush(RouteNode rnode, boolean longParent, RouteNode

int childX = childRnode.getEndTileXCoordinate();
int childY = childRnode.getEndTileYCoordinate();
SitePinInst sink = connection.getSink();
Tile sinkTile = sink.getTile();
int sinkX = sinkTile.getTileXCoordinate();
int sinkY = sinkTile.getTileYCoordinate();
RouteNode sinkRnode = connection.getSinkRnode();
int sinkX = sinkRnode.getBeginTileXCoordinate();
int sinkY = sinkRnode.getBeginTileYCoordinate();
int deltaX = Math.abs(childX - sinkX);
int deltaY = Math.abs(childY - sinkY);
if (connection.isCrossSLR()) {
RouteNode sinkRnode = connection.getSinkRnode();
int deltaSLR = Math.abs(sinkRnode.getSLRIndex() - childRnode.getSLRIndex());
if (deltaSLR != 0) {
// Check for overshooting which occurs when child and sink node are in
Expand Down
2 changes: 1 addition & 1 deletion src/com/xilinx/rapidwright/rwroute/RapidStreamRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class RapidStreamRoute extends PartialRouter{
/** Nets with conflicting nodes that should be added to the routing targets */
protected Set<Net> conflictNets;
/** A keyword to help recognize the target conflict nets */
final private String anchorNameKeyword;
private final String anchorNameKeyword;

public RapidStreamRoute(Design design, RWRouteConfig config, String anchorNameKeyword) {
// FIXME
Expand Down
2 changes: 1 addition & 1 deletion src/com/xilinx/rapidwright/rwroute/RouteFixer.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void setShortestPathToEachVertex() {
}
}

final private static Comparator<NodeWithDelay> NodeWithDelayComparator = (a, b) -> Float.compare(a.getDelay(), b.getDelay());
private static final Comparator<NodeWithDelay> NodeWithDelayComparator = (a, b) -> Float.compare(a.getDelay(), b.getDelay());

static class NodeWithDelay{
private int id;
Expand Down
17 changes: 14 additions & 3 deletions src/com/xilinx/rapidwright/rwroute/RouteNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ public RouteNode(Node node, RouteNodeType type) {

@Override
public int compareTo(RouteNode that) {
// Do not use Float.compare() since it also checks NaN, which we'll assume is unreachable
// Do not use Float.compare() since it also compares NaN, which we'll assume is unreachable
// return Float.compare(this.lowerBoundTotalPathCost, that.lowerBoundTotalPathCost);
return (int) Math.signum(this.lowerBoundTotalPathCost - that.lowerBoundTotalPathCost);
float signum = Math.signum(this.lowerBoundTotalPathCost - that.lowerBoundTotalPathCost);
// Tie break according to larger known cost (thus smaller estimated cost to target)
return (int) ((signum != 0) ? signum : Math.signum(that.upstreamPathCost - this.upstreamPathCost));

}

abstract protected RouteNode getOrCreate(Node node, RouteNodeType type);
Expand Down Expand Up @@ -227,7 +230,7 @@ public boolean hasMultiDrivers() {
return RouteNode.capacity < uniqueDriverCount();
}

public final static EnumSet<TileTypeEnum> lagunaTileTypes = EnumSet.of(
public static final EnumSet<TileTypeEnum> lagunaTileTypes = EnumSet.of(
TileTypeEnum.LAG_LAG // UltraScale+
, TileTypeEnum.LAGUNA_TILE // UltraScale
);
Expand Down Expand Up @@ -394,6 +397,14 @@ public float getDelay() {
return 0;
}

public short getBeginTileXCoordinate() {
return (short) node.getTile().getTileXCoordinate();
}

public short getBeginTileYCoordinate() {
return (short) node.getTile().getTileYCoordinate();
}

/**
* Gets the x coordinate of the INT {@link Tile} instance
* that the associated {@link Node} instance stops at.
Expand Down
Loading

0 comments on commit ba63b33

Please sign in to comment.