Skip to content

Commit 51f9e6b

Browse files
committed
[vpr][place] adjust search range if number of blocks in the column is less that a certain number
1 parent fc9c6a5 commit 51f9e6b

File tree

2 files changed

+77
-57
lines changed

2 files changed

+77
-57
lines changed

vpr/src/place/move_utils.cpp

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616
//Note: The flag is only effective if compiled with VTR_ENABLE_DEBUG_LOGGING
1717
bool f_placer_breakpoint_reached = false;
1818

19+
20+
/**
21+
* @brief Adjust the search range based on how many blocks are in the column.
22+
* If the number of blocks in the column is less than MIN_NUM_BLOCKS_IN_COLUMN,
23+
* expand the search range to cover the entire column.
24+
*
25+
* @param block_type The type of the block to move
26+
* @param compressed_column_num The compressed column to move the block to
27+
* @param to_layer_num The layer that the block is moving to
28+
* @param is_range_fixed Whether the search range is fixed (e.g., in case of placement constraints)
29+
* @param search_range The search range to adjust
30+
*
31+
*/
32+
static void adjust_search_range(t_logical_block_type_ptr block_type,
33+
const int compressed_column_num,
34+
const int to_layer_num,
35+
const bool is_range_fixed,
36+
t_bb& search_range);
37+
1938
//Accessor for f_placer_breakpoint_reached
2039
bool placer_breakpoint_reached() {
2140
return f_placer_breakpoint_reached;
@@ -666,9 +685,17 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type,
666685
rlim);
667686
int delta_cx = search_range.xmax - search_range.xmin;
668687

669-
bool adjust_search_range_res = adjust_search_range(type, b_from, search_range, delta_cx, to_layer_num);
670-
if (!adjust_search_range_res) {
671-
return false;
688+
689+
auto block_constrained = is_cluster_constrained(block_id);
690+
691+
if (block_constrained) {
692+
bool intersect = intersect_range_limit_with_floorplan_constraints(block_id,
693+
search_range,
694+
delta_cx,
695+
to_layer_num);
696+
if (!intersect) {
697+
return false;
698+
}
672699
}
673700

674701
t_physical_tile_loc to_compressed_loc;
@@ -683,7 +710,8 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type,
683710
to_layer_num,
684711
/*search_for_empty=*/false,
685712
blk_loc_registry,
686-
rng);
713+
rng,
714+
block_constrained);
687715

688716
if (!legal) {
689717
//No valid position found
@@ -753,9 +781,16 @@ bool find_to_loc_median(t_logical_block_type_ptr blk_type,
753781
to_layer_num,
754782
to_layer_num);
755783

756-
bool adjust_search_range_res = adjust_search_range(blk_type, b_from, search_range, delta_cx, to_layer_num);
757-
if (!adjust_search_range_res) {
758-
return false;
784+
auto block_constrained = is_cluster_constrained(b_from);
785+
786+
if (block_constrained) {
787+
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
788+
search_range,
789+
delta_cx,
790+
to_layer_num);
791+
if (!intersect) {
792+
return false;
793+
}
759794
}
760795

761796
t_physical_tile_loc to_compressed_loc;
@@ -769,7 +804,8 @@ bool find_to_loc_median(t_logical_block_type_ptr blk_type,
769804
to_layer_num,
770805
/*search_for_empty=*/false,
771806
blk_loc_registry,
772-
rng);
807+
rng,
808+
block_constrained);
773809

774810
if (!legal) {
775811
//No valid position found
@@ -836,9 +872,16 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
836872
}
837873
delta_cx = search_range.xmax - search_range.xmin;
838874

839-
bool adjust_search_range_res = adjust_search_range(blk_type, b_from, search_range, delta_cx, to_layer_num);
840-
if (!adjust_search_range_res) {
841-
return false;
875+
auto block_constrained = is_cluster_constrained(b_from);
876+
877+
if (block_constrained) {
878+
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
879+
search_range,
880+
delta_cx,
881+
to_layer_num);
882+
if (!intersect) {
883+
return false;
884+
}
842885
}
843886

844887
t_physical_tile_loc to_compressed_loc;
@@ -854,7 +897,8 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
854897
to_layer_num,
855898
/*search_for_empty=*/false,
856899
blk_loc_registry,
857-
rng);
900+
rng,
901+
block_constrained);
858902

859903
if (!legal) {
860904
//No valid position found
@@ -948,7 +992,8 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
948992
int to_layer_num,
949993
bool search_for_empty,
950994
const BlkLocRegistry& blk_loc_registry,
951-
vtr::RngContainer& rng) {
995+
vtr::RngContainer& rng,
996+
const bool is_range_fixed) {
952997
//TODO For the time being, the blocks only moved in the same layer. This assertion should be removed after VPR is updated to move blocks between layers
953998
VTR_ASSERT(to_layer_num == from_loc.layer_num);
954999
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[type->index];
@@ -983,6 +1028,11 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
9831028
//The candidates are stored in a flat_map so we can efficiently find the set of valid
9841029
//candidates with upper/lower bound.
9851030
const auto& block_rows = compressed_block_grid.get_column_block_map(to_loc.x, to_layer_num);
1031+
adjust_search_range(type,
1032+
to_loc.x,
1033+
to_layer_num,
1034+
is_range_fixed,
1035+
search_range);
9861036
auto y_lower_iter = block_rows.lower_bound(search_range.ymin);
9871037
if (y_lower_iter == block_rows.end()) {
9881038
continue;
@@ -1167,30 +1217,20 @@ bool intersect_range_limit_with_floorplan_constraints(ClusterBlockId b_from,
11671217
return true;
11681218
}
11691219

1170-
bool adjust_search_range(t_logical_block_type_ptr block_type,
1171-
ClusterBlockId block_id,
1172-
t_bb& search_range,
1173-
int& delta_cx,
1174-
int to_layer_num) {
1220+
static void adjust_search_range(t_logical_block_type_ptr block_type,
1221+
const int compressed_column_num,
1222+
const int to_layer_num,
1223+
const bool is_range_fixed,
1224+
t_bb& search_range) {
1225+
// The value is chosen empirically to expand the search range for sparse blocks,
1226+
// or blocks located on the perimeter of the FPGA (e.g., IO blocks)
1227+
constexpr int MIN_NUM_BLOCKS_IN_COLUMN = 3;
11751228

1176-
auto block_constrained = is_cluster_constrained(block_id);
1229+
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[block_type->index];
11771230

1178-
if (block_constrained) {
1179-
bool intersect = intersect_range_limit_with_floorplan_constraints(block_id,
1180-
search_range,
1181-
delta_cx,
1182-
to_layer_num);
1183-
if (!intersect) {
1184-
return false;
1185-
}
1186-
}
1231+
size_t num_blocks_in_column = compressed_block_grid.get_column_block_map(compressed_column_num, to_layer_num).size();
11871232

1188-
if (block_type->is_io() && !block_constrained) {
1189-
/* We empirically found that for the IO blocks,
1190-
* Given their sparsity, we expand the y-axis search range
1191-
* to include all blocks in the column
1192-
*/
1193-
const t_compressed_block_grid& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[block_type->index];
1233+
if (num_blocks_in_column < MIN_NUM_BLOCKS_IN_COLUMN && !is_range_fixed) {
11941234
search_range.ymin = 0;
11951235
search_range.ymax = compressed_block_grid.get_num_rows(to_layer_num) - 1;
11961236
}

vpr/src/place/move_utils.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ int find_empty_compatible_subtile(t_logical_block_type_ptr type,
327327
* is_median: true if this is called from find_to_loc_median
328328
* to_layer_num: the layer number of the new location (set by the caller)
329329
* search_for_empty: indicates that the returned location must be empty
330-
* fixed_search_range: indicates that the search range is fixed and should not be adjusted
330+
* is_range_fixed: indicates that the search range is fixed and should not be adjusted
331331
*/
332332
bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
333333
int delta_cx,
@@ -338,7 +338,8 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
338338
int to_layer_num,
339339
bool search_for_empty,
340340
const BlkLocRegistry& blk_loc_registry,
341-
vtr::RngContainer& rng);
341+
vtr::RngContainer& rng,
342+
const bool is_range_fixed);
342343

343344
/**
344345
* @brief Get the the compressed loc from the uncompressed loc (grid_loc)
@@ -420,27 +421,6 @@ bool intersect_range_limit_with_floorplan_constraints(ClusterBlockId b_from,
420421
int& delta_cx,
421422
int layer_num);
422423

423-
/**
424-
* @brief Adjust the search range based on the block type and constraints
425-
*
426-
* If the block is an IO block, we expand the search range to include all blocks in the column
427-
* We found empirically that this is a good strategy for IO blocks given they are located in
428-
* the periphery for most FPGA architectures
429-
*
430-
* @param block_type The type of the block to move
431-
* @param block_id The block ID of the moving block
432-
* @param search_range The search range to adjust
433-
* @param delta_cx The delta x of the search range
434-
* @param to_layer_num The layer that the block is moving to
435-
*
436-
* @return true if the search range was adjusted, false otherwise
437-
*/
438-
bool adjust_search_range(t_logical_block_type_ptr block_type,
439-
ClusterBlockId block_id,
440-
t_bb& search_range,
441-
int& delta_cx,
442-
int to_layer_num);
443-
444424
std::string e_move_result_to_string(e_move_result move_outcome);
445425

446426
/**

0 commit comments

Comments
 (0)