From 8f7aa26607eed07dfc85253d4d1500aff72ae415 Mon Sep 17 00:00:00 2001 From: Nathan Shreve Date: Fri, 5 Jul 2024 21:29:35 -0400 Subject: [PATCH] Reintroduce dfs recursive fn.; call set_sink_locs after intra-cluster rr graph built --- libs/librrgraph/src/base/rr_graph_utils.cpp | 51 ++++++++++++++------- vpr/src/route/rr_graph.cpp | 6 +-- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/libs/librrgraph/src/base/rr_graph_utils.cpp b/libs/librrgraph/src/base/rr_graph_utils.cpp index 6c2c57255d3..e7932457049 100644 --- a/libs/librrgraph/src/base/rr_graph_utils.cpp +++ b/libs/librrgraph/src/base/rr_graph_utils.cpp @@ -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>& fanins, + std::unordered_set& 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 find_rr_graph_switches(const RRGraph& rr_graph, const RRNodeId& from_node, const RRNodeId& to_node) { @@ -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 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 */ diff --git a/vpr/src/route/rr_graph.cpp b/vpr/src/route/rr_graph.cpp index 3ae69a6ca8f..9dc7b3ec3ff 100644 --- a/vpr/src/route/rr_graph.cpp +++ b/vpr/src/route/rr_graph.cpp @@ -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, @@ -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();