Skip to content

Commit 17c50d6

Browse files
author
Nathan Shreve
committed
Removed unnecessary recursion when updating SINK locs; IPINs are always one node away
1 parent f30b15c commit 17c50d6

File tree

2 files changed

+26
-58
lines changed

2 files changed

+26
-58
lines changed

libs/librrgraph/src/base/rr_graph_utils.cpp

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,6 @@
66
#include "rr_graph_obj.h"
77
#include "rr_graph_builder.h"
88

9-
// Add "cluster-edge" IPINs to sink_ipins
10-
static void walk_cluster_recursive(const RRGraphView& rr_graph,
11-
const vtr::vector<RRNodeId, std::vector<RREdgeId>>& fanins,
12-
std::unordered_set<RRNodeId>& sink_ipins,
13-
const RRNodeId curr,
14-
const RRNodeId origin) {
15-
// Make sure SINK in the same cluster as origin
16-
int curr_x = rr_graph.node_xlow(curr);
17-
int curr_y = rr_graph.node_ylow(curr);
18-
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)))
19-
return;
20-
21-
VTR_ASSERT_SAFE(rr_graph.node_type(origin) == e_rr_type::SINK);
22-
23-
// We want to go "backward" to the cluster IPINs connected to the origin node
24-
auto incoming_edges = fanins[curr];
25-
for (RREdgeId edge : incoming_edges) {
26-
RRNodeId parent = rr_graph.edge_src_node(edge);
27-
VTR_ASSERT_SAFE(parent != RRNodeId::INVALID());
28-
29-
if (rr_graph.node_type(parent) == e_rr_type::CHANX || rr_graph.node_type(parent) == e_rr_type::CHANY) { /* Outside of origin cluster */
30-
VTR_ASSERT_SAFE(rr_graph.node_type(curr) == e_rr_type::IPIN);
31-
32-
// If the parent node isn't in the origin's cluster, the current node is a "cluster-edge" pin,
33-
// so add it to sink_ipins
34-
sink_ipins.insert(curr);
35-
return;
36-
}
37-
38-
// If the parent node is intra-cluster, keep going "backward"
39-
walk_cluster_recursive(rr_graph, fanins, sink_ipins, parent, origin);
40-
}
41-
}
42-
439
std::vector<RRSwitchId> find_rr_graph_switches(const RRGraph& rr_graph,
4410
const RRNodeId& from_node,
4511
const RRNodeId& to_node) {
@@ -134,12 +100,7 @@ vtr::vector<RRNodeId, std::vector<RREdgeId>> get_fan_in_list(const RRGraphView&
134100
void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder) {
135101
auto node_fanins = get_fan_in_list(rr_graph);
136102

137-
// The "cluster-edge" IPINs of SINK nodes
138-
std::unordered_map<RRNodeId, std::unordered_set<RRNodeId>> sink_ipins;
139-
140-
// Iterate over all nodes and fill sink_ipins
141-
// We fill sink_ipins first and then iterate through it to avoid changing the rr_graph
142-
// before we are done collecting all the data we need
103+
// Iterate over all SINK nodes
143104
for (size_t node = 0; node < rr_graph.num_nodes(); ++node) {
144105
auto node_id = RRNodeId(node);
145106

@@ -152,25 +113,36 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
152113
if (tile_width == 0 && tile_height == 0)
153114
continue;
154115

155-
sink_ipins[node_id] = {};
156-
walk_cluster_recursive(rr_graph, node_fanins, sink_ipins[node_id], node_id, node_id);
157-
}
116+
// The IPINs of the current SINK node
117+
std::unordered_set<RRNodeId> sink_ipins = {};
118+
119+
// IPINs are always one node away from the SINK. So, we just get the fanins of the SINK
120+
// and add them to the set
121+
for (auto edge : node_fanins[node_id]) {
122+
RRNodeId pin = rr_graph.edge_src_node(edge);
123+
124+
VTR_ASSERT_SAFE(rr_graph.node_type(pin) == e_rr_type::IPIN);
125+
126+
// Make sure IPIN in the same cluster as origin
127+
int curr_x = rr_graph.node_xlow(pin);
128+
int curr_y = rr_graph.node_ylow(pin);
129+
if ((curr_x < rr_graph.node_xlow(pin)) || (curr_x > rr_graph.node_xhigh(pin)) || (curr_y < rr_graph.node_ylow(pin)) || (curr_y > rr_graph.node_yhigh(pin)))
130+
continue;
131+
132+
sink_ipins.insert(pin);
133+
}
158134

159-
// Set SINK locations as average of "cluster-edge" IPINs. Generally, larger blocks do not have
160-
// equivalent IPINs, so each SINK will be connected to only one IPIN, so taking the average is
161-
// redundant.
162-
for (const auto& node_pins : sink_ipins) {
163-
const auto& pin_set = node_pins.second;
135+
/* Set SINK locations as average of collected IPINs */
164136

165-
if (pin_set.empty())
137+
if (sink_ipins.empty())
166138
continue;
167139

168140
// Use float so that we can take average later
169141
std::vector<float> x_coords;
170142
std::vector<float> y_coords;
171143

172144
// Add coordinates of each "cluster-edge" pin to vectors
173-
for (const auto& pin : pin_set) {
145+
for (const auto& pin : sink_ipins) {
174146
int pin_x = rr_graph.node_xlow(pin);
175147
int pin_y = rr_graph.node_ylow(pin);
176148

@@ -184,8 +156,7 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
184156
auto x_avg = (short)round(std::accumulate(x_coords.begin(), x_coords.end(), 0.f) / (double)x_coords.size());
185157
auto y_avg = (short)round(std::accumulate(y_coords.begin(), y_coords.end(), 0.f) / (double)y_coords.size());
186158

187-
RRNodeId node = node_pins.first;
188-
rr_graph_builder.set_node_coordinates(node, x_avg, y_avg, x_avg, y_avg);
159+
rr_graph_builder.set_node_coordinates(node_id, x_avg, y_avg, x_avg, y_avg);
189160
}
190161
}
191162

vpr/src/route/rr_graph.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,7 @@ static void build_rr_graph(const t_graph_type graph_type,
643643
const int num_directs,
644644
int* wire_to_rr_ipin_switch,
645645
bool is_flat,
646-
int* Warnings,
647-
bool writing_graph_out);
646+
int* Warnings);
648647

649648
static void build_intra_cluster_rr_graph(const t_graph_type graph_type,
650649
const DeviceGrid& grid,
@@ -737,8 +736,7 @@ void create_rr_graph(const t_graph_type graph_type,
737736
directs, num_directs,
738737
&det_routing_arch->wire_to_rr_ipin_switch,
739738
is_flat,
740-
Warnings,
741-
!det_routing_arch->write_rr_graph_filename.empty());
739+
Warnings);
742740
}
743741
}
744742

@@ -959,8 +957,7 @@ static void build_rr_graph(const t_graph_type graph_type,
959957
const int num_directs,
960958
int* wire_to_rr_ipin_switch,
961959
bool is_flat,
962-
int* Warnings,
963-
bool writing_graph_out) {
960+
int* Warnings) {
964961
vtr::ScopedStartFinishTimer timer("Build routing resource graph");
965962

966963
/* Reset warning flag */

0 commit comments

Comments
 (0)