Skip to content

Commit a2ae770

Browse files
committed
[vpr][place] adjust search range in another function
1 parent 271640b commit a2ae770

File tree

2 files changed

+71
-40
lines changed

2 files changed

+71
-40
lines changed

vpr/src/place/move_utils.cpp

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,51 @@ void set_placer_breakpoint_reached(bool flag) {
3636
f_placer_breakpoint_reached = flag;
3737
}
3838

39+
/**
40+
* @brief Expand the y-axis search range based on the number of blocks in the column
41+
*
42+
* @param search_range The search range to adjust
43+
* @param y_lower_iter The lower bound of the search range in the compressed grid
44+
* @param y_range The search range across the y-axis
45+
* @param type The type of the block to move
46+
* @param block_rows Compatible blocks in the column
47+
*/
48+
static void adjust_y_axis_search_range(t_bb& search_range,
49+
vtr::flat_map2<int, t_physical_tile_loc>::const_iterator& y_lower_iter,
50+
int& y_range,
51+
t_logical_block_type_ptr type,
52+
const vtr::flat_map2<int, t_physical_tile_loc>& block_rows) {
53+
54+
auto y_upper_iter = block_rows.upper_bound(search_range.ymax);
55+
56+
if (block_rows.size() > G_MIN_NUM_BLOCKS_IN_COLUMN) {
57+
if (y_lower_iter->first > search_range.ymin) {
58+
//No valid blocks at this x location which are within rlim_y
59+
//
60+
if (type->index != 1) {
61+
continue;
62+
} else {
63+
//Fall back to allow the whole y range
64+
y_lower_iter = block_rows.begin();
65+
y_upper_iter = block_rows.end();
66+
67+
search_range.ymin = y_lower_iter->first;
68+
search_range.ymax = (y_upper_iter - 1)->first;
69+
}
70+
}
71+
} else { // search_range is not fixed and there are less than G_MIN_NUM_BLOCKS_IN_COLUMN blocks at this x location
72+
y_lower_iter = block_rows.begin();
73+
y_upper_iter = block_rows.end();
74+
75+
search_range.ymin = y_lower_iter->first;
76+
search_range.ymax = (y_upper_iter - 1)->first;
77+
}
78+
79+
y_range = std::distance(y_lower_iter, y_upper_iter);
80+
81+
return y_lower_iter;
82+
}
83+
3984
e_create_move create_move(t_pl_blocks_to_be_moved& blocks_affected,
4085
ClusterBlockId b_from,
4186
t_pl_loc to,
@@ -680,7 +725,8 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type,
680725
t_physical_tile_loc to_compressed_loc;
681726
bool legal = false;
682727

683-
if (is_cluster_constrained(b_from)) {
728+
bool cluster_constrained = is_cluster_constrained(b_from);
729+
if (cluster_constrained) {
684730
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
685731
search_range,
686732
delta_cx,
@@ -699,7 +745,8 @@ bool find_to_loc_uniform(t_logical_block_type_ptr type,
699745
to_layer_num,
700746
/*search_for_empty=*/false,
701747
blk_loc_registry,
702-
rng);
748+
rng,
749+
cluster_constrained);
703750

704751
if (!legal) {
705752
//No valid position found
@@ -772,7 +819,8 @@ bool find_to_loc_median(t_logical_block_type_ptr blk_type,
772819
t_physical_tile_loc to_compressed_loc;
773820
bool legal = false;
774821

775-
if (is_cluster_constrained(b_from)) {
822+
bool cluster_constrained = is_cluster_constrained(b_from);
823+
if (cluster_constrained) {
776824
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
777825
search_range,
778826
delta_cx,
@@ -791,7 +839,8 @@ bool find_to_loc_median(t_logical_block_type_ptr blk_type,
791839
to_layer_num,
792840
/*search_for_empty=*/false,
793841
blk_loc_registry,
794-
rng);
842+
rng,
843+
cluster_constrained);
795844

796845
if (!legal) {
797846
//No valid position found
@@ -861,7 +910,8 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
861910
t_physical_tile_loc to_compressed_loc;
862911
bool legal = false;
863912

864-
if (is_cluster_constrained(b_from)) {
913+
bool cluster_constrained = is_cluster_constrained(b_from);
914+
if (cluster_constrained) {
865915
bool intersect = intersect_range_limit_with_floorplan_constraints(b_from,
866916
search_range,
867917
delta_cx,
@@ -871,7 +921,7 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
871921
}
872922
}
873923

874-
//TODO: For now, we only move the blocks on the same tile
924+
//TODO: For now, we only move the blocks on the same layer
875925
legal = find_compatible_compressed_loc_in_range(blk_type,
876926
delta_cx,
877927
from_compressed_loc[to_layer_num],
@@ -881,7 +931,8 @@ bool find_to_loc_centroid(t_logical_block_type_ptr blk_type,
881931
to_layer_num,
882932
/*search_for_empty=*/false,
883933
blk_loc_registry,
884-
rng);
934+
rng,
935+
cluster_constrained);
885936

886937
if (!legal) {
887938
//No valid position found
@@ -975,7 +1026,8 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
9751026
int to_layer_num,
9761027
bool search_for_empty,
9771028
const BlkLocRegistry& blk_loc_registry,
978-
vtr::RngContainer& rng) {
1029+
vtr::RngContainer& rng,
1030+
bool fixed_search_range) {
9791031
//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
9801032
VTR_ASSERT(to_layer_num == from_loc.layer_num);
9811033
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[type->index];
@@ -1010,39 +1062,16 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
10101062
//The candidates are stored in a flat_map so we can efficiently find the set of valid
10111063
//candidates with upper/lower bound.
10121064
const auto& block_rows = compressed_block_grid.get_column_block_map(to_loc.x, to_layer_num);
1013-
auto y_lower_iter = block_rows.begin();
1014-
auto y_upper_iter = block_rows.end();
1015-
1016-
if (block_rows.size() > G_MIN_NUM_BLOCKS_IN_COLUMN || search_range.is_fixed) {
1017-
y_lower_iter = block_rows.lower_bound(search_range.ymin);
1018-
if (y_lower_iter == block_rows.end()) {
1019-
continue;
1020-
}
1021-
y_upper_iter = block_rows.upper_bound(search_range.ymax);
1022-
1023-
if (y_lower_iter->first > search_range.ymin) {
1024-
//No valid blocks at this x location which are within rlim_y
1025-
//
1026-
if (type->index != 1) {
1027-
continue;
1028-
} else if (!search_range.is_fixed) {
1029-
//Fall back to allow the whole y range
1030-
y_lower_iter = block_rows.begin();
1031-
y_upper_iter = block_rows.end();
1032-
1033-
search_range.ymin = y_lower_iter->first;
1034-
search_range.ymax = (y_upper_iter - 1)->first;
1035-
}
1036-
}
1037-
} else { // search_range is not fixed and there are less than G_MIN_NUM_BLOCKS_IN_COLUMN blocks at this x location
1038-
y_lower_iter = block_rows.begin();
1039-
y_upper_iter = block_rows.end();
1040-
1041-
search_range.ymin = y_lower_iter->first;
1042-
search_range.ymax = (y_upper_iter - 1)->first;
1065+
auto y_lower_iter = block_rows.lower_bound(search_range.ymin);
1066+
auto y_upper_iter = block_rows.upper_bound(search_range.ymax);
1067+
if (y_lower_iter == block_rows.end()) {
1068+
continue;
10431069
}
1044-
10451070
int y_range = std::distance(y_lower_iter, y_upper_iter);
1071+
if (!fixed_search_range) {
1072+
y_lower_iter = adjust_y_axis_search_range(search_range, y_range, type, block_rows);
1073+
}
1074+
10461075
VTR_ASSERT(y_range >= 0);
10471076

10481077
//At this point we know y_lower_iter and y_upper_iter

vpr/src/place/move_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ int find_empty_compatible_subtile(t_logical_block_type_ptr type,
328328
* is_median: true if this is called from find_to_loc_median
329329
* to_layer_num: the layer number of the new location (set by the caller)
330330
* search_for_empty: indicates that the returned location must be empty
331+
* fixed_search_range: indicates that the search range is fixed and should not be adjusted
331332
*/
332333
bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
333334
int delta_cx,
@@ -338,7 +339,8 @@ bool find_compatible_compressed_loc_in_range(t_logical_block_type_ptr type,
338339
int to_layer_num,
339340
bool search_for_empty,
340341
const BlkLocRegistry& blk_loc_registry,
341-
vtr::RngContainer& rng);
342+
vtr::RngContainer& rng,
343+
bool fixed_search_range = false);
342344

343345
/**
344346
* @brief Get the the compressed loc from the uncompressed loc (grid_loc)

0 commit comments

Comments
 (0)