Skip to content

Commit 369fe11

Browse files
committed
equivalent: use logical_block_types in compressed grid locations
equivalent: add compatibility check in is_legal_swap Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 6d340a0 commit 369fe11

File tree

5 files changed

+45
-63
lines changed

5 files changed

+45
-63
lines changed

vpr/src/place/compressed_grid.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ std::vector<t_compressed_block_grid> create_compressed_block_grids() {
66
auto& grid = device_ctx.grid;
77

88
//Collect the set of x/y locations for each instace of a block type
9-
std::vector<std::vector<vtr::Point<int>>> block_locations(device_ctx.physical_tile_types.size());
9+
std::vector<std::vector<vtr::Point<int>>> block_locations(device_ctx.logical_block_types.size());
1010
for (size_t x = 0; x < grid.width(); ++x) {
1111
for (size_t y = 0; y < grid.height(); ++y) {
1212
const t_grid_tile& tile = grid[x][y];
1313
if (tile.width_offset == 0 && tile.height_offset == 0) {
14-
//Only record at block root location
15-
block_locations[tile.type->index].emplace_back(x, y);
14+
for (auto& block : tile.type->equivalent_sites) {
15+
//Only record at block root location
16+
block_locations[block->index].emplace_back(x, y);
17+
}
1618
}
1719
}
1820
}
1921

20-
std::vector<t_compressed_block_grid> compressed_type_grids(device_ctx.physical_tile_types.size());
21-
for (const auto& type : device_ctx.physical_tile_types) {
22+
std::vector<t_compressed_block_grid> compressed_type_grids(device_ctx.logical_block_types.size());
23+
for (const auto& type : device_ctx.logical_block_types) {
2224
compressed_type_grids[type.index] = create_compressed_block_grid(block_locations[type.index]);
2325
}
2426

vpr/src/place/move_utils.cpp

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,12 @@ bool is_legal_swap_to_location(ClusterBlockId blk, t_pl_loc to) {
417417
//(neccessarily) translationally invariant for an arbitrary macro
418418

419419
auto& device_ctx = g_vpr_ctx.device();
420+
auto& cluster_ctx = g_vpr_ctx.clustering();
420421

421422
if (to.x < 0 || to.x >= int(device_ctx.grid.width())
422423
|| to.y < 0 || to.y >= int(device_ctx.grid.height())
423424
|| to.z < 0 || to.z >= device_ctx.grid[to.x][to.y].type->capacity
424-
|| (device_ctx.grid[to.x][to.y].type != physical_tile_type(blk))) {
425+
|| !is_tile_compatible(device_ctx.grid[to.x][to.y].type, cluster_ctx.clb_nlist.block_type(blk))) {
425426
return false;
426427
}
427428
return true;
@@ -482,7 +483,7 @@ ClusterBlockId pick_from_block() {
482483
return ClusterBlockId::INVALID();
483484
}
484485

485-
bool find_to_loc_uniform(t_physical_tile_type_ptr type,
486+
bool find_to_loc_uniform(t_logical_block_type_ptr type,
486487
float rlim,
487488
const t_pl_loc from,
488489
t_pl_loc& to) {
@@ -495,29 +496,25 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
495496
//
496497
//This ensures that such blocks don't get locked down too early during placement (as would be the
497498
//case with a physical distance rlim)
498-
auto& grid = g_vpr_ctx.device().grid;
499-
500-
auto from_type = grid[from.x][from.y].type;
501499

502500
//Retrieve the compressed block grid for this block type
503-
const auto& to_compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[type->index];
504-
const auto& from_compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[from_type->index];
501+
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[type->index];
505502

506503
//Determine the rlim in each dimension
507-
int rlim_x = std::min<int>(to_compressed_block_grid.compressed_to_grid_x.size(), rlim);
508-
int rlim_y = std::min<int>(to_compressed_block_grid.compressed_to_grid_y.size(), rlim); /* for aspect_ratio != 1 case. */
504+
int rlim_x = std::min<int>(compressed_block_grid.compressed_to_grid_x.size(), rlim);
505+
int rlim_y = std::min<int>(compressed_block_grid.compressed_to_grid_y.size(), rlim); /* for aspect_ratio != 1 case. */
509506

510507
//Determine the coordinates in the compressed grid space of the current block
511-
int cx_from = grid_to_compressed(from_compressed_block_grid.compressed_to_grid_x, from.x);
512-
int cy_from = grid_to_compressed(from_compressed_block_grid.compressed_to_grid_y, from.y);
508+
int cx_from = grid_to_compressed(compressed_block_grid.compressed_to_grid_x, from.x);
509+
int cy_from = grid_to_compressed(compressed_block_grid.compressed_to_grid_y, from.y);
513510

514511
//Determine the valid compressed grid location ranges
515512
int min_cx = std::max(0, cx_from - rlim_x);
516-
int max_cx = std::min<int>(to_compressed_block_grid.compressed_to_grid_x.size() - 1, cx_from + rlim_x);
513+
int max_cx = std::min<int>(compressed_block_grid.compressed_to_grid_x.size() - 1, cx_from + rlim_x);
517514
int delta_cx = max_cx - min_cx;
518515

519516
int min_cy = std::max(0, cy_from - rlim_y);
520-
int max_cy = std::min<int>(to_compressed_block_grid.compressed_to_grid_y.size() - 1, cy_from + rlim_y);
517+
int max_cy = std::min<int>(compressed_block_grid.compressed_to_grid_y.size() - 1, cy_from + rlim_y);
521518

522519
int cx_to = OPEN;
523520
int cy_to = OPEN;
@@ -544,19 +541,19 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
544541
//
545542
//The candidates are stored in a flat_map so we can efficiently find the set of valid
546543
//candidates with upper/lower bound.
547-
auto y_lower_iter = to_compressed_block_grid.grid[cx_to].lower_bound(min_cy);
548-
if (y_lower_iter == to_compressed_block_grid.grid[cx_to].end()) {
544+
auto y_lower_iter = compressed_block_grid.grid[cx_to].lower_bound(min_cy);
545+
if (y_lower_iter == compressed_block_grid.grid[cx_to].end()) {
549546
continue;
550547
}
551548

552-
auto y_upper_iter = to_compressed_block_grid.grid[cx_to].upper_bound(max_cy);
549+
auto y_upper_iter = compressed_block_grid.grid[cx_to].upper_bound(max_cy);
553550

554551
if (y_lower_iter->first > min_cy) {
555552
//No valid blocks at this x location which are within rlim_y
556553
//
557554
//Fall back to allow the whole y range
558-
y_lower_iter = to_compressed_block_grid.grid[cx_to].begin();
559-
y_upper_iter = to_compressed_block_grid.grid[cx_to].end();
555+
y_lower_iter = compressed_block_grid.grid[cx_to].begin();
556+
y_upper_iter = compressed_block_grid.grid[cx_to].end();
560557

561558
min_cy = y_lower_iter->first;
562559
max_cy = (y_upper_iter - 1)->first;
@@ -588,33 +585,7 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
588585
if (cx_from == cx_to && cy_from == cy_to) {
589586
continue; //Same from/to location -- try again for new y-position
590587
} else {
591-
VTR_ASSERT(cx_to != OPEN);
592-
VTR_ASSERT(cy_to != OPEN);
593-
594-
//Convert to true (uncompressed) grid locations
595-
to.x = to_compressed_block_grid.compressed_to_grid_x[cx_to];
596-
to.y = to_compressed_block_grid.compressed_to_grid_y[cy_to];
597-
598-
auto& place_ctx = g_vpr_ctx.placement();
599-
auto& cluster_ctx = g_vpr_ctx.clustering();
600-
601-
auto blocks = place_ctx.grid_blocks[to.x][to.y].blocks;
602-
bool impossible_swap = false;
603-
for (auto blk : blocks) {
604-
if (blk == ClusterBlockId::INVALID()) {
605-
continue;
606-
}
607-
608-
auto block_type = cluster_ctx.clb_nlist.block_type(blk);
609-
if (!is_tile_compatible(from_type, block_type)) {
610-
impossible_swap = true;
611-
break;
612-
}
613-
}
614-
615-
if (!impossible_swap) {
616-
legal = true;
617-
}
588+
legal = true;
618589
}
619590
}
620591
}
@@ -624,11 +595,22 @@ bool find_to_loc_uniform(t_physical_tile_type_ptr type,
624595
return false;
625596
}
626597

598+
VTR_ASSERT(cx_to != OPEN);
599+
VTR_ASSERT(cy_to != OPEN);
600+
601+
//Convert to true (uncompressed) grid locations
602+
to.x = compressed_block_grid.compressed_to_grid_x[cx_to];
603+
to.y = compressed_block_grid.compressed_to_grid_y[cy_to];
604+
605+
auto& grid = g_vpr_ctx.device().grid;
606+
607+
auto to_type = grid[to.x][to.y].type;
608+
627609
//Each x/y location contains only a single type, so we can pick a random
628610
//z (capcity) location
629-
to.z = vtr::irand(type->capacity - 1);
611+
to.z = vtr::irand(to_type->capacity - 1);
630612

631-
VTR_ASSERT_MSG(grid[to.x][to.y].type == type, "Type must match");
613+
VTR_ASSERT_MSG(is_tile_compatible(to_type, type), "Type must be compatible");
632614
VTR_ASSERT_MSG(grid[to.x][to.y].width_offset == 0, "Should be at block base location");
633615
VTR_ASSERT_MSG(grid[to.x][to.y].height_offset == 0, "Should be at block base location");
634616

vpr/src/place/move_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::set<t_pl_loc> determine_locations_emptied_by_move(t_pl_blocks_to_be_moved&
4646

4747
ClusterBlockId pick_from_block();
4848

49-
bool find_to_loc_uniform(t_physical_tile_type_ptr type,
49+
bool find_to_loc_uniform(t_logical_block_type_ptr type,
5050
float rlim,
5151
const t_pl_loc from,
5252
t_pl_loc& to);

vpr/src/place/place.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,8 @@ static void placement_inner_loop(float t,
940940

941941
/* Lines below prevent too much round-off error from accumulating
942942
* in the cost over many iterations (due to incremental updates).
943-
* This round-off can lead to error checks failing because the cost
944-
* is different from what you get when you recompute from scratch.
943+
* This round-off can lead to error checks failing because the cost
944+
* is different from what you get when you recompute from scratch.
945945
*/
946946
++(*moves_since_cost_recompute);
947947
if (*moves_since_cost_recompute > MAX_MOVES_BEFORE_RECOMPUTE) {
@@ -1219,15 +1219,15 @@ static e_move_result try_swap(float t,
12191219
VTR_ASSERT(create_move_outcome == e_create_move::VALID);
12201220

12211221
/*
1222-
* To make evaluating the move simpler (e.g. calculating changed bounding box),
1223-
* we first move the blocks to thier new locations (apply the move to
1224-
* place_ctx.block_locs) and then computed the change in cost. If the move is
1222+
* To make evaluating the move simpler (e.g. calculating changed bounding box),
1223+
* we first move the blocks to thier new locations (apply the move to
1224+
* place_ctx.block_locs) and then computed the change in cost. If the move is
12251225
* accepted, the inverse look-up in place_ctx.grid_blocks is updated (committing
1226-
* the move). If the move is rejected the blocks are returned to their original
1226+
* the move). If the move is rejected the blocks are returned to their original
12271227
* positions (reverting place_ctx.block_locs to its original state).
12281228
*
12291229
* Note that the inverse look-up place_ctx.grid_blocks is only updated
1230-
* after move acceptance is determined, and so should not be used when
1230+
* after move acceptance is determined, and so should not be used when
12311231
* evaluating a move.
12321232
*/
12331233

vpr/src/place/uniform_move_generator.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ e_create_move UniformMoveGenerator::propose_move(t_pl_blocks_to_be_moved& blocks
1818

1919
t_pl_loc to;
2020

21-
auto type = pick_best_physical_type(cluster_from_type);
22-
23-
if (!find_to_loc_uniform(type, rlim, from, to)) {
21+
if (!find_to_loc_uniform(cluster_from_type, rlim, from, to)) {
2422
return e_create_move::ABORT;
2523
}
2624

0 commit comments

Comments
 (0)