Skip to content

Commit

Permalink
Reintroduce dfs recursive fn.; call set_sink_locs after intra-cluster…
Browse files Browse the repository at this point in the history
… rr graph built
  • Loading branch information
Nathan Shreve committed Jul 6, 2024
1 parent c16f7df commit 8f7aa26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
51 changes: 35 additions & 16 deletions libs/librrgraph/src/base/rr_graph_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@
#include "rr_graph_obj.h"
#include "rr_graph_builder.h"

// Add "cluster-edge" IPINs to sink_ipins
static void walk_cluster_recursive(const RRGraphView& rr_graph,
const vtr::vector<RRNodeId, std::vector<RREdgeId>>& fanins,
std::unordered_set<RRNodeId>& sink_ipins,
const RRNodeId curr,
const RRNodeId origin) {
// Make sure SINK in the same cluster as origin
int curr_x = rr_graph.node_xlow(curr);
int curr_y = rr_graph.node_ylow(curr);
if ((curr_x < rr_graph.node_xlow(origin)) || (curr_x > rr_graph.node_xhigh(origin)) || (curr_y < rr_graph.node_ylow(origin)) || (curr_y > rr_graph.node_yhigh(origin)))
return;

VTR_ASSERT_SAFE(rr_graph.node_type(origin) == e_rr_type::SINK);

// We want to go "backward" to the cluster IPINs connected to the origin node
auto incoming_edges = fanins[curr];
for (RREdgeId edge : incoming_edges) {
RRNodeId parent = rr_graph.edge_src_node(edge);
VTR_ASSERT_SAFE(parent != RRNodeId::INVALID());

if (rr_graph.node_type(parent) == e_rr_type::CHANX || rr_graph.node_type(parent) == e_rr_type::CHANY) { /* Outside of origin cluster */
VTR_ASSERT_SAFE(rr_graph.node_type(curr) == e_rr_type::IPIN);

// If the parent node isn't in the origin's cluster, the current node is a "cluster-edge" pin,
// so add it to sink_ipins
sink_ipins.insert(curr);
return;
}

// If the parent node is intra-cluster, keep going "backward"
walk_cluster_recursive(rr_graph, fanins, sink_ipins, parent, origin);
}
}

std::vector<RRSwitchId> find_rr_graph_switches(const RRGraph& rr_graph,
const RRNodeId& from_node,
const RRNodeId& to_node) {
Expand Down Expand Up @@ -144,22 +178,7 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder

// The IPINs of the current SINK node
std::unordered_set<RRNodeId> sink_ipins = {};

// IPINs are always one node away from the SINK. So, we just get the fanins of the SINK
// and add them to the set
for (auto edge : node_fanins[node_id]) {
RRNodeId pin = rr_graph.edge_src_node(edge);

VTR_ASSERT_SAFE(rr_graph.node_type(pin) == e_rr_type::IPIN);

// Make sure IPIN in the same cluster as origin
size_t curr_x = rr_graph.node_xlow(pin);
size_t curr_y = rr_graph.node_ylow(pin);
if ((curr_x < tile_xlow) || (curr_x > tile_xhigh) || (curr_y < tile_ylow) || (curr_y > tile_yhigh))
continue;

sink_ipins.insert(pin);
}
walk_cluster_recursive(rr_graph, node_fanins, sink_ipins, node_id, node_id);

/* Set SINK locations as average of collected IPINs */

Expand Down
6 changes: 3 additions & 3 deletions vpr/src/route/rr_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ void create_rr_graph(const t_graph_type graph_type,
mutable_device_ctx.rr_graph_is_flat = true;
}

// Get better locations for SINK nodes
set_sink_locs(device_ctx.rr_graph, mutable_device_ctx.rr_graph_builder, grid);

process_non_config_sets();

verify_rr_node_indices(grid,
Expand Down Expand Up @@ -1437,9 +1440,6 @@ static void build_rr_graph(const t_graph_type graph_type,
delete[] clb_to_clb_directs;
}

// Get better locations for SINK nodes
set_sink_locs(rr_graph, device_ctx.rr_graph_builder, device_ctx.grid);

// We are done with building the RR Graph. Thus, we can clear the storages only used
// to build the RR Graph
device_ctx.rr_graph_builder.clear_temp_storage();
Expand Down

0 comments on commit 8f7aa26

Please sign in to comment.