25
25
#include " expr_eval.h"
26
26
27
27
static DeviceGrid auto_size_device_grid (const std::vector<t_grid_def>& grid_layouts, const std::map<t_logical_block_type_ptr, size_t >& minimum_instance_counts, float maximum_device_utilization);
28
- static std::vector<t_physical_tile_type_ptr > grid_overused_resources (const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t > instance_counts);
28
+ static std::vector<t_logical_block_type_ptr > grid_overused_resources (const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t > instance_counts);
29
29
static bool grid_satisfies_instance_counts (const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t > instance_counts, float maximum_utilization);
30
- static DeviceGrid build_device_grid (const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true , std::vector<t_physical_tile_type_ptr > limiting_resources = std::vector<t_physical_tile_type_ptr >());
30
+ static DeviceGrid build_device_grid (const t_grid_def& grid_def, size_t width, size_t height, bool warn_out_of_range = true , std::vector<t_logical_block_type_ptr > limiting_resources = std::vector<t_logical_block_type_ptr >());
31
31
32
32
static void CheckGrid (const DeviceGrid& grid);
33
33
@@ -152,7 +152,7 @@ static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layo
152
152
// specifications
153
153
size_t width = 3 ;
154
154
size_t height = 3 ;
155
- std::vector<t_physical_tile_type_ptr > limiting_resources;
155
+ std::vector<t_logical_block_type_ptr > limiting_resources;
156
156
do {
157
157
// Scale opposite dimension to match aspect ratio
158
158
height = vtr::nint (width / grid_def.aspect_ratio );
@@ -203,7 +203,7 @@ static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layo
203
203
};
204
204
std::stable_sort (grid_layouts_view.begin (), grid_layouts_view.end (), area_cmp);
205
205
206
- std::vector<t_physical_tile_type_ptr > limiting_resources;
206
+ std::vector<t_logical_block_type_ptr > limiting_resources;
207
207
208
208
// Try all the fixed devices in order from smallest to largest
209
209
for (const auto * grid_def : grid_layouts_view) {
@@ -220,37 +220,58 @@ static DeviceGrid auto_size_device_grid(const std::vector<t_grid_def>& grid_layo
220
220
return grid; // Unreachable
221
221
}
222
222
223
- static std::vector<t_physical_tile_type_ptr> grid_overused_resources (const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t > instance_counts) {
223
+ static std::vector<t_logical_block_type_ptr> grid_overused_resources (const DeviceGrid& grid, std::map<t_logical_block_type_ptr, size_t > instance_counts) {
224
+ // Estimates what logical block types will be unimplementable due to resource limits in the available grid
225
+ //
226
+ // Performs a fast counting based estimate, allocating the least flexible block types (those with the fewest
227
+ // equivalent tiles) first.
224
228
auto & device_ctx = g_vpr_ctx.device ();
225
229
226
- std::vector<t_physical_tile_type_ptr > overused_resources;
230
+ std::vector<t_logical_block_type_ptr > overused_resources;
227
231
228
232
std::unordered_map<t_physical_tile_type_ptr, size_t > min_count_map;
229
233
// Initialize min_count_map
230
- for (const auto & physical_tile : device_ctx.physical_tile_types ) {
231
- min_count_map.insert (std::make_pair (&physical_tile , size_t (0 )));
234
+ for (const auto & tile_type : device_ctx.physical_tile_types ) {
235
+ min_count_map.insert (std::make_pair (&tile_type , size_t (0 )));
232
236
}
233
237
234
- // Are the resources satisified?
235
- for (auto kv : instance_counts) {
236
- t_physical_tile_type_ptr type = nullptr ;
238
+ // Initialize available tile counts
239
+ std::unordered_map<t_physical_tile_type_ptr, int > avail_tiles;
240
+ for (auto & tile_type : device_ctx.physical_tile_types ) {
241
+ avail_tiles[&tile_type] = grid.num_instances (&tile_type);
242
+ }
237
243
238
- size_t inst_cnt = 0 ;
239
- for (auto & physical_tile : kv.first ->equivalent_tiles ) {
240
- size_t tmp_inst_cnt = grid.num_instances (physical_tile);
244
+ // Sort so we allocate logical blocks with the fewest equivalent sites first (least flexible)
245
+ std::vector<const t_logical_block_type*> logical_block_types;
246
+ for (auto & block_type : device_ctx.logical_block_types ) {
247
+ logical_block_types.push_back (&block_type);
248
+ }
241
249
242
- if (inst_cnt <= tmp_inst_cnt) {
243
- type = physical_tile;
244
- inst_cnt = tmp_inst_cnt;
245
- }
246
- }
250
+ auto by_ascending_equiv_tiles = [](t_logical_block_type_ptr lhs, t_logical_block_type_ptr rhs) {
251
+ return lhs->equivalent_tiles .size () < rhs->equivalent_tiles .size ();
252
+ };
253
+ std::stable_sort (logical_block_types.begin (), logical_block_types.end (), by_ascending_equiv_tiles);
254
+
255
+ // Allocate logical blocks to available tiles
256
+ for (auto block_type : logical_block_types) {
257
+ if (instance_counts.count (block_type)) {
258
+ int required_blocks = instance_counts[block_type];
259
+
260
+ for (auto tile_type : block_type->equivalent_tiles ) {
261
+ if (avail_tiles[tile_type] >= required_blocks) {
262
+ avail_tiles[tile_type] -= required_blocks;
263
+ required_blocks = 0 ;
264
+ } else {
265
+ required_blocks -= avail_tiles[tile_type];
266
+ avail_tiles[tile_type] = 0 ;
267
+ }
247
268
248
- VTR_ASSERT (type);
249
- size_t min_count = min_count_map.at (type) + kv.second ;
250
- min_count_map.at (type) = min_count;
269
+ if (required_blocks == 0 ) break ;
270
+ }
251
271
252
- if (inst_cnt < min_count) {
253
- overused_resources.push_back (type);
272
+ if (required_blocks > 0 ) {
273
+ overused_resources.push_back (block_type);
274
+ }
254
275
}
255
276
}
256
277
@@ -276,7 +297,7 @@ static bool grid_satisfies_instance_counts(const DeviceGrid& grid, std::map<t_lo
276
297
}
277
298
278
299
// Build the specified device grid
279
- static DeviceGrid build_device_grid (const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_physical_tile_type_ptr > limiting_resources) {
300
+ static DeviceGrid build_device_grid (const t_grid_def& grid_def, size_t grid_width, size_t grid_height, bool warn_out_of_range, const std::vector<t_logical_block_type_ptr > limiting_resources) {
280
301
if (grid_def.grid_type == GridDefType::FIXED) {
281
302
if (grid_def.width != int (grid_width) || grid_def.height != int (grid_height)) {
282
303
VPR_FATAL_ERROR (VPR_ERROR_OTHER,
0 commit comments