@@ -123,49 +123,36 @@ static uint64_t interleave(uint32_t x) {
123
123
return i;
124
124
}
125
125
126
- // for each segment type, find the nearest nodes to an equally spaced grid of points
127
- // within the bounding box for that segment type
128
- std::vector<SampleRegion> find_sample_regions (int num_segments) {
129
- vtr::ScopedStartFinishTimer timer (" finding sample regions" );
130
- std::vector<SampleRegion> sample_regions;
126
+ // Used to get a valid segment index given an input rr_node.
127
+ // If the node is not interesting an invalid value is returned.
128
+ static std::tuple<int , int , int > get_node_info (const t_rr_node& node, int num_segments) {
131
129
auto & device_ctx = g_vpr_ctx.device ();
132
130
auto & rr_nodes = device_ctx.rr_nodes ;
133
- std::vector<vtr::Matrix<int >> segment_counts (num_segments);
134
131
135
- // compute bounding boxes for each segment type
136
- std::vector<vtr::Rect<int >> bounding_box_for_segment (num_segments, vtr::Rect<int >());
137
- for (auto & node : rr_nodes) {
138
- if (node.type () != CHANX && node.type () != CHANY) continue ;
139
- if (node.capacity () == 0 || node.num_edges () == 0 ) continue ;
140
- int seg_index = device_ctx.rr_indexed_data [node.cost_index ()].seg_index ;
141
-
142
- VTR_ASSERT (seg_index != OPEN);
143
- VTR_ASSERT (seg_index < num_segments);
144
-
145
- bounding_box_for_segment[seg_index].expand_bounding_box (bounding_box_for_node (node.id ()));
132
+ if (node.type () != CHANX && node.type () != CHANY) {
133
+ return std::tuple<int , int , int >(OPEN, OPEN, OPEN);
146
134
}
147
135
148
- // initialize counts
149
- for (int seg = 0 ; seg < num_segments; seg++) {
150
- const auto & box = bounding_box_for_segment[seg];
151
- segment_counts[seg] = vtr::Matrix<int >({size_t (box.width ()), size_t (box.height ())}, 0 );
136
+ if (node.capacity () == 0 || node.num_edges () == 0 ) {
137
+ return std::tuple<int , int , int >(OPEN, OPEN, OPEN);
152
138
}
153
139
154
- // count sample points
155
- for (auto & node : rr_nodes) {
156
- if (node.type () != CHANX && node.type () != CHANY) continue ;
157
- if (node.capacity () == 0 || node.num_edges () == 0 ) continue ;
140
+ int x = rr_nodes.node_xlow (node.id ());
141
+ int y = rr_nodes.node_ylow (node.id ());
158
142
159
- int x = rr_nodes.node_xlow (node.id ());
160
- int y = rr_nodes.node_ylow (node.id ());
143
+ int seg_index = device_ctx.rr_indexed_data [node.cost_index ()].seg_index ;
161
144
162
- int seg_index = device_ctx. rr_indexed_data [node. cost_index ()]. seg_index ;
163
- segment_counts[ seg_index][x][y] += 1 ;
145
+ VTR_ASSERT ( seg_index != OPEN) ;
146
+ VTR_ASSERT ( seg_index < num_segments) ;
164
147
165
- VTR_ASSERT (seg_index != OPEN);
166
- VTR_ASSERT (seg_index < num_segments);
167
- }
148
+ return std::tuple<int , int , int >(seg_index, x, y);
149
+ }
168
150
151
+ // Fills the sample_regions vector
152
+ static void compute_sample_regions (std::vector<SampleRegion>& sample_regions,
153
+ std::vector<vtr::Matrix<int >>& segment_counts,
154
+ std::vector<vtr::Rect<int >>& bounding_box_for_segment,
155
+ int num_segments) {
169
156
// select sample points
170
157
for (int i = 0 ; i < num_segments; i++) {
171
158
const auto & counts = segment_counts[i];
@@ -201,6 +188,47 @@ std::vector<SampleRegion> find_sample_regions(int num_segments) {
201
188
}
202
189
}
203
190
}
191
+ }
192
+
193
+ // for each segment type, find the nearest nodes to an equally spaced grid of points
194
+ // within the bounding box for that segment type
195
+ std::vector<SampleRegion> find_sample_regions (int num_segments) {
196
+ vtr::ScopedStartFinishTimer timer (" finding sample regions" );
197
+ std::vector<SampleRegion> sample_regions;
198
+ auto & device_ctx = g_vpr_ctx.device ();
199
+ auto & rr_nodes = device_ctx.rr_nodes ;
200
+ std::vector<vtr::Matrix<int >> segment_counts (num_segments);
201
+
202
+ // compute bounding boxes for each segment type
203
+ std::vector<vtr::Rect<int >> bounding_box_for_segment (num_segments, vtr::Rect<int >());
204
+ for (auto & node : rr_nodes) {
205
+ if (node.type () != CHANX && node.type () != CHANY) continue ;
206
+ if (node.capacity () == 0 || node.num_edges () == 0 ) continue ;
207
+ int seg_index = device_ctx.rr_indexed_data [node.cost_index ()].seg_index ;
208
+
209
+ VTR_ASSERT (seg_index != OPEN);
210
+ VTR_ASSERT (seg_index < num_segments);
211
+
212
+ bounding_box_for_segment[seg_index].expand_bounding_box (bounding_box_for_node (node.id ()));
213
+ }
214
+
215
+ // initialize counts
216
+ for (int seg = 0 ; seg < num_segments; seg++) {
217
+ const auto & box = bounding_box_for_segment[seg];
218
+ segment_counts[seg] = vtr::Matrix<int >({size_t (box.width ()), size_t (box.height ())}, 0 );
219
+ }
220
+
221
+ // count sample points
222
+ for (const auto & node : rr_nodes) {
223
+ int seg_index, x, y;
224
+ std::tie (seg_index, x, y) = get_node_info (node, num_segments);
225
+
226
+ if (seg_index == OPEN) continue ;
227
+
228
+ segment_counts[seg_index][x][y] += 1 ;
229
+ }
230
+
231
+ compute_sample_regions (sample_regions, segment_counts, bounding_box_for_segment, num_segments);
204
232
205
233
// sort regions
206
234
std::sort (sample_regions.begin (), sample_regions.end (),
@@ -217,17 +245,11 @@ std::vector<SampleRegion> find_sample_regions(int num_segments) {
217
245
}
218
246
219
247
// collect the node indices for each segment type at the selected sample points
220
- for (auto & node : rr_nodes) {
221
- if (node.type () != CHANX && node.type () != CHANY) continue ;
222
- if (node.capacity () == 0 || node.num_edges () == 0 ) continue ;
223
-
224
- int x = rr_nodes.node_xlow (node.id ());
225
- int y = rr_nodes.node_ylow (node.id ());
248
+ for (const auto & node : rr_nodes) {
249
+ int seg_index, x, y;
250
+ std::tie (seg_index, x, y) = get_node_info (node, num_segments);
226
251
227
- int seg_index = device_ctx.rr_indexed_data [node.cost_index ()].seg_index ;
228
-
229
- VTR_ASSERT (seg_index != OPEN);
230
- VTR_ASSERT (seg_index < num_segments);
252
+ if (seg_index == OPEN) continue ;
231
253
232
254
auto point = sample_point_index.find (std::make_tuple (seg_index, x, y));
233
255
if (point != sample_point_index.end ()) {
0 commit comments