6
6
#include " rr_graph_obj.h"
7
7
#include " rr_graph_builder.h"
8
8
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
-
43
9
std::vector<RRSwitchId> find_rr_graph_switches (const RRGraph& rr_graph,
44
10
const RRNodeId& from_node,
45
11
const RRNodeId& to_node) {
@@ -134,12 +100,7 @@ vtr::vector<RRNodeId, std::vector<RREdgeId>> get_fan_in_list(const RRGraphView&
134
100
void set_sink_locs (const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder) {
135
101
auto node_fanins = get_fan_in_list (rr_graph);
136
102
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
143
104
for (size_t node = 0 ; node < rr_graph.num_nodes (); ++node) {
144
105
auto node_id = RRNodeId (node);
145
106
@@ -152,25 +113,36 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
152
113
if (tile_width == 0 && tile_height == 0 )
153
114
continue ;
154
115
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
+ }
158
134
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 */
164
136
165
- if (pin_set .empty ())
137
+ if (sink_ipins .empty ())
166
138
continue ;
167
139
168
140
// Use float so that we can take average later
169
141
std::vector<float > x_coords;
170
142
std::vector<float > y_coords;
171
143
172
144
// Add coordinates of each "cluster-edge" pin to vectors
173
- for (const auto & pin : pin_set ) {
145
+ for (const auto & pin : sink_ipins ) {
174
146
int pin_x = rr_graph.node_xlow (pin);
175
147
int pin_y = rr_graph.node_ylow (pin);
176
148
@@ -184,8 +156,7 @@ void set_sink_locs(const RRGraphView& rr_graph, RRGraphBuilder& rr_graph_builder
184
156
auto x_avg = (short )round (std::accumulate (x_coords.begin (), x_coords.end (), 0 .f ) / (double )x_coords.size ());
185
157
auto y_avg = (short )round (std::accumulate (y_coords.begin (), y_coords.end (), 0 .f ) / (double )y_coords.size ());
186
158
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);
189
160
}
190
161
}
191
162
0 commit comments