Skip to content

Commit 976813b

Browse files
add comments
1 parent 3bb2e9d commit 976813b

File tree

7 files changed

+63
-35
lines changed

7 files changed

+63
-35
lines changed

vpr/src/base/vpr_context.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,15 @@ struct FloorplanningContext : public Context {
520520
*/
521521
vtr::vector<ClusterBlockId, PartitionRegion> cluster_constraints;
522522

523+
/**
524+
* @brief Floorplanning constraints specified in the compressed grid coordinate system.
525+
*
526+
* Each clustered block has a logical type, and each logical type has a corresponding compressed grid.
527+
* Compressed floorplanning constraints are computed by translating grid location of floorplanning
528+
* regions to compressed locations in the corresponding compressed grid. To ensure this translation
529+
* does not enlarge the floorplanning regions, the bottom left corner of the region is rounded up
530+
* in compresses location approximation, while the top right corner is rounded down.
531+
*/
523532
vtr::vector<ClusterBlockId, PartitionRegion> compressed_cluster_constraints;
524533

525534
std::vector<Region> overfull_regions;

vpr/src/place/grid_tile_lookup.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void GridTileLookup::fill_type_matrix(t_logical_block_type_ptr block_type, vtr::
5454
max_placement_locations[block_type->index] = type_count[0][0][0];
5555
}
5656

57-
int GridTileLookup::total_type_tiles(t_logical_block_type_ptr block_type) {
57+
int GridTileLookup::total_type_tiles(t_logical_block_type_ptr block_type) const {
5858
return max_placement_locations[block_type->index];
5959
}
6060

@@ -65,7 +65,7 @@ int GridTileLookup::total_type_tiles(t_logical_block_type_ptr block_type) {
6565
* and subtracting four values from within/at the edge of the region.
6666
* The region with subtile case is taken care of by a helper routine, region_with_subtile_count().
6767
*/
68-
int GridTileLookup::region_tile_count(const Region& reg, t_logical_block_type_ptr block_type) {
68+
int GridTileLookup::region_tile_count(const Region& reg, t_logical_block_type_ptr block_type) const {
6969
auto& device_ctx = g_vpr_ctx.device();
7070
int subtile = reg.get_sub_tile();
7171
int layer_num = reg.get_layer_num();
@@ -120,7 +120,7 @@ int GridTileLookup::region_tile_count(const Region& reg, t_logical_block_type_pt
120120
* This routine is for the subtile specified case; an O(region_size) scan needs to be done to check whether each grid
121121
* location in the region is compatible for the block at the subtile specified.
122122
*/
123-
int GridTileLookup::region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type) {
123+
int GridTileLookup::region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type) const{
124124
auto& device_ctx = g_vpr_ctx.device();
125125
int num_sub_tiles = 0;
126126

@@ -134,8 +134,8 @@ int GridTileLookup::region_with_subtile_count(const Region& reg, t_logical_block
134134

135135
for (int i = xmax; i >= xmin; i--) {
136136
for (int j = ymax; j >= ymin; j--) {
137-
const auto& tile = device_ctx.grid.get_physical_type({i, j, reg_coord.layer_num});
138-
if (is_sub_tile_compatible(tile, block_type, subtile)) {
137+
const t_physical_tile_type_ptr tile_type = device_ctx.grid.get_physical_type({i, j, reg_coord.layer_num});
138+
if (is_sub_tile_compatible(tile_type, block_type, subtile)) {
139139
num_sub_tiles++;
140140
}
141141
}

vpr/src/place/grid_tile_lookup.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class GridTileLookup {
3131

3232
void fill_type_matrix(t_logical_block_type_ptr block_type, vtr::NdMatrix<int, 3>& type_count);
3333

34-
int region_tile_count(const Region& reg, t_logical_block_type_ptr block_type);
34+
int region_tile_count(const Region& reg, t_logical_block_type_ptr block_type) const;
3535

36-
int region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type);
36+
int region_with_subtile_count(const Region& reg, t_logical_block_type_ptr block_type) const;
3737

38-
int total_type_tiles(t_logical_block_type_ptr block_type);
38+
int total_type_tiles(t_logical_block_type_ptr block_type) const;
3939

4040
private:
4141
/*

vpr/src/place/initial_placement.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void clear_all_grid_locs();
5555
* 1) try_centroid_placement : tries to find a location based on the macro's logical connections.
5656
* 2) try_place_macro_randomly : if no smart location found in the centroid placement, the function tries
5757
* to place it randomly for the max number of tries.
58-
* 3) try_place_macro_exhaustively : if neither placement alogrithms work, the function will find a location
58+
* 3) try_place_macro_exhaustively : if neither placement algorithms work, the function will find a location
5959
* for the macro by exhaustively searching all available locations.
6060
* If first iteration failed, next iteration calls dense placement for specific block types.
6161
*
@@ -92,13 +92,13 @@ static vtr::vector<ClusterBlockId, t_block_score> assign_block_scores();
9292
static int get_y_loc_based_on_macro_direction(t_grid_empty_locs_block_type first_macro_loc, const t_pl_macro& pl_macro);
9393

9494
/**
95-
* @brief Tries to get the first available location of a specific block type that can accomodate macro blocks
95+
* @brief Tries to get the first available location of a specific block type that can accommodate macro blocks
9696
*
9797
* @param loc The first available location that can place the macro blocks.
9898
* @param pl_macro The macro to be placed.
9999
* @param blk_types_empty_locs_in_grid first location (lowest y) and number of remaining blocks in each column for the blk_id type
100100
*
101-
* @return index to a column of blk_types_empty_locs_in_grid that can accomodate pl_macro and location of first available location returned by reference
101+
* @return index to a column of blk_types_empty_locs_in_grid that can accommodate pl_macro and location of first available location returned by reference
102102
*/
103103
static int get_blk_type_first_loc(t_pl_loc& loc, const t_pl_macro& pl_macro, std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid);
104104

@@ -144,7 +144,9 @@ static inline void fix_IO_block_types(const t_pl_macro& pl_macro, t_pl_loc loc,
144144
*
145145
* @return True if the location is legal for the macro head member, false otherwise.
146146
*/
147-
static bool is_loc_legal(t_pl_loc& loc, PartitionRegion& pr, t_logical_block_type_ptr block_type);
147+
static bool is_loc_legal(const t_pl_loc& loc,
148+
const PartitionRegion& pr,
149+
t_logical_block_type_ptr block_type);
148150

149151
/**
150152
* @brief Calculates a centroid location for a block based on its placed connections.
@@ -180,7 +182,7 @@ static bool find_centroid_neighbor(t_pl_loc& centroid_loc, t_logical_block_type_
180182
* @return true if the macro gets placed, false if not.
181183
*/
182184
static bool try_centroid_placement(const t_pl_macro& pl_macro,
183-
PartitionRegion& pr,
185+
const PartitionRegion& pr,
184186
t_logical_block_type_ptr block_type,
185187
enum e_pad_loc_type pad_loc_type,
186188
vtr::vector<ClusterBlockId, t_block_score>& block_scores);
@@ -199,7 +201,7 @@ static bool try_centroid_placement(const t_pl_macro& pl_macro,
199201
* @return true if the macro gets placed, false if not.
200202
*/
201203
static bool try_dense_placement(const t_pl_macro& pl_macro,
202-
PartitionRegion& pr,
204+
const PartitionRegion& pr,
203205
t_logical_block_type_ptr block_type,
204206
enum e_pad_loc_type pad_loc_type,
205207
std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid);
@@ -253,7 +255,9 @@ bool is_block_placed(ClusterBlockId blk_id) {
253255
return (place_ctx.block_locs[blk_id].loc.x != INVALID_X);
254256
}
255257

256-
static bool is_loc_legal(t_pl_loc& loc, PartitionRegion& pr, t_logical_block_type_ptr block_type) {
258+
static bool is_loc_legal(const t_pl_loc& loc,
259+
const PartitionRegion& pr,
260+
t_logical_block_type_ptr block_type) {
257261
const auto& grid = g_vpr_ctx.device().grid;
258262
bool legal = false;
259263

@@ -424,7 +428,11 @@ static std::vector<ClusterBlockId> find_centroid_loc(const t_pl_macro& pl_macro,
424428
return connected_blocks_to_update;
425429
}
426430

427-
static bool try_centroid_placement(const t_pl_macro& pl_macro, PartitionRegion& pr, t_logical_block_type_ptr block_type, enum e_pad_loc_type pad_loc_type, vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
431+
static bool try_centroid_placement(const t_pl_macro& pl_macro,
432+
const PartitionRegion& pr,
433+
t_logical_block_type_ptr block_type,
434+
enum e_pad_loc_type pad_loc_type,
435+
vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
428436
t_pl_loc centroid_loc(OPEN, OPEN, OPEN, OPEN);
429437
std::vector<ClusterBlockId> unplaced_blocks_to_update_their_score;
430438

@@ -453,7 +461,7 @@ static bool try_centroid_placement(const t_pl_macro& pl_macro, PartitionRegion&
453461
auto& device_ctx = g_vpr_ctx.device();
454462
//choose the location's subtile if the centroid location is legal.
455463
//if the location is found within the "find_centroid_neighbor", it already has a subtile
456-
//we don't need to find one agian
464+
//we don't need to find one again
457465
if (!neighbor_legal_loc) {
458466
const auto& compressed_block_grid = g_vpr_ctx.placement().compressed_block_grids[block_type->index];
459467
const auto& type = device_ctx.grid.get_physical_type({centroid_loc.x, centroid_loc.y, centroid_loc.layer});
@@ -515,7 +523,7 @@ static void update_blk_type_first_loc(int blk_type_column_index,
515523
static int get_blk_type_first_loc(t_pl_loc& loc,
516524
const t_pl_macro& pl_macro,
517525
std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid) {
518-
//loop over all empty locations and choose first column that can accomodate macro blocks
526+
//loop over all empty locations and choose first column that can accommodate macro blocks
519527
for (unsigned int empty_loc_index = 0; empty_loc_index < blk_types_empty_locs_in_grid->size(); empty_loc_index++) {
520528
auto first_empty_loc = blk_types_empty_locs_in_grid->at(empty_loc_index);
521529

@@ -743,7 +751,7 @@ bool try_place_macro_exhaustively(const t_pl_macro& pl_macro, const PartitionReg
743751
}
744752

745753
static bool try_dense_placement(const t_pl_macro& pl_macro,
746-
PartitionRegion& pr,
754+
const PartitionRegion& pr,
747755
t_logical_block_type_ptr block_type,
748756
enum e_pad_loc_type pad_loc_type,
749757
std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid) {
@@ -911,7 +919,7 @@ static vtr::vector<ClusterBlockId, t_block_score> assign_block_scores() {
911919
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
912920
block_scores[blk_id].number_of_placed_connections = 0;
913921
if (is_cluster_constrained(blk_id)) {
914-
PartitionRegion pr = floorplan_ctx.cluster_constraints[blk_id];
922+
const PartitionRegion& pr = floorplan_ctx.cluster_constraints[blk_id];
915923
auto block_type = cluster_ctx.clb_nlist.block_type(blk_id);
916924
double floorplan_score = get_floorplan_score(blk_id, pr, block_type, grid_tiles);
917925
block_scores[blk_id].tiles_outside_of_floorplan_constraints = floorplan_score;
@@ -943,7 +951,7 @@ static void place_all_blocks([[maybe_unused]] const t_placer_opts& placer_opts,
943951
//keep tracks of which block types can not be placed in each iteration
944952
std::unordered_set<int> unplaced_blk_type_in_curr_itr;
945953

946-
auto criteria = [&block_scores, &cluster_ctx](const ClusterBlockId& lhs, const ClusterBlockId& rhs) {
954+
auto criteria = [&block_scores, &cluster_ctx](ClusterBlockId lhs, ClusterBlockId rhs) {
947955
int lhs_score = block_scores[lhs].macro_size + block_scores[lhs].number_of_placed_connections + SORT_WEIGHT_PER_TILES_OUTSIDE_OF_PR * block_scores[lhs].tiles_outside_of_floorplan_constraints + SORT_WEIGHT_PER_FAILED_BLOCK * block_scores[lhs].failed_to_place_in_prev_attempts;
948956
int rhs_score = block_scores[rhs].macro_size + block_scores[rhs].number_of_placed_connections + SORT_WEIGHT_PER_TILES_OUTSIDE_OF_PR * block_scores[rhs].tiles_outside_of_floorplan_constraints + SORT_WEIGHT_PER_FAILED_BLOCK * block_scores[rhs].failed_to_place_in_prev_attempts;
949957

@@ -1146,6 +1154,7 @@ void initial_placement(const t_placer_opts& placer_opts,
11461154
* as fixed so they do not get moved during initial placement or later during the simulated annealing stage of placement*/
11471155
mark_fixed_blocks();
11481156

1157+
// Compute and store compressed floorplanning constraints
11491158
alloc_and_load_compressed_cluster_constraints();
11501159

11511160

vpr/src/place/move_utils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,30 +1263,30 @@ bool intersect_range_limit_with_floorplan_constraints(ClusterBlockId b_from,
12631263
int layer_num) {
12641264
const auto& floorplanning_ctx = g_vpr_ctx.floorplanning();
12651265

1266-
const PartitionRegion& pr = floorplanning_ctx.compressed_cluster_constraints[b_from];
1267-
const std::vector<Region>& regions = pr.get_regions();
1268-
Region intersect_reg;
1266+
// get the block floorplanning constraints specified in the compressed grid
1267+
const PartitionRegion& compressed_pr = floorplanning_ctx.compressed_cluster_constraints[b_from];
1268+
const std::vector<Region>& compressed_regions = compressed_pr.get_regions();
12691269
/*
12701270
* If region size is greater than 1, the block is constrained to more than one rectangular region.
12711271
* In this case, we return true (i.e. the range limit intersects with
12721272
* the floorplan constraints) to simplify the problem. This simplification can be done because
12731273
* this routine is done for cpu time optimization, so we do not have to necessarily check each
12741274
* complicated case to get correct functionality during place moves.
12751275
*/
1276-
if (regions.size() == 1) {
1276+
if (compressed_regions.size() == 1) {
12771277
Region range_reg;
12781278
range_reg.set_region_rect({search_range.xmin, search_range.ymin,
12791279
search_range.xmax, search_range.ymax,
12801280
layer_num});
12811281

1282-
intersect_reg = intersection(regions[0], range_reg);
1282+
Region compressed_intersect_reg = intersection(compressed_regions[0], range_reg);
12831283

1284-
if (intersect_reg.empty()) {
1284+
if (compressed_intersect_reg.empty()) {
12851285
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug,
12861286
"\tCouldn't find an intersection between floorplan constraints and search region\n");
12871287
return false;
12881288
} else {
1289-
const auto intersect_coord = intersect_reg.get_region_rect();
1289+
const auto intersect_coord = compressed_intersect_reg.get_region_rect();
12901290
VTR_ASSERT(intersect_coord.layer_num == layer_num);
12911291

12921292
delta_cx = intersect_coord.xmax - intersect_coord.xmin;

vpr/src/place/place_constraints.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,9 @@ bool is_pr_size_one(PartitionRegion& pr, t_logical_block_type_ptr block_type, t_
480480
return pr_size_one;
481481
}
482482

483-
int get_part_reg_size(PartitionRegion& pr, t_logical_block_type_ptr block_type, GridTileLookup& grid_tiles) {
483+
int get_part_reg_size(const PartitionRegion& pr,
484+
t_logical_block_type_ptr block_type,
485+
const GridTileLookup& grid_tiles) {
484486
const std::vector<Region>& regions = pr.get_regions();
485487
int num_tiles = 0;
486488

@@ -491,7 +493,10 @@ int get_part_reg_size(PartitionRegion& pr, t_logical_block_type_ptr block_type,
491493
return num_tiles;
492494
}
493495

494-
double get_floorplan_score(ClusterBlockId blk_id, PartitionRegion& pr, t_logical_block_type_ptr block_type, GridTileLookup& grid_tiles) {
496+
double get_floorplan_score(ClusterBlockId blk_id,
497+
const PartitionRegion& pr,
498+
t_logical_block_type_ptr block_type,
499+
const GridTileLookup& grid_tiles) {
495500
auto& cluster_ctx = g_vpr_ctx.clustering();
496501

497502
int num_pr_tiles = get_part_reg_size(pr, block_type, grid_tiles);

vpr/src/place/place_constraints.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_
2+
#define VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_
3+
14
/*
25
* place_constraints.h
36
*
@@ -12,9 +15,6 @@
1215
#include "place_macro.h"
1316
#include "grid_tile_lookup.h"
1417

15-
#ifndef VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_
16-
# define VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_
17-
1818
/*
1919
* Check that placement of each block is within the floorplan constraint region of that block (if the block has any constraints).
2020
* Returns the number of errors (inconsistencies in adherence to floorplanning constraints).
@@ -131,14 +131,19 @@ bool is_pr_size_one(PartitionRegion& pr, t_logical_block_type_ptr block_type, t_
131131
* Used prior to initial placement to help sort blocks based on how difficult they
132132
* are to place.
133133
*/
134-
int get_part_reg_size(PartitionRegion& pr, t_logical_block_type_ptr block_type, GridTileLookup& grid_tiles);
134+
int get_part_reg_size(const PartitionRegion& pr,
135+
t_logical_block_type_ptr block_type,
136+
const GridTileLookup& grid_tiles);
135137

136138
/*
137139
* Return the floorplan score that will be used for sorting blocks during initial placement. This score is the
138140
* total number of subtiles for the block type in the grid, minus the number of subtiles in the block's floorplan PartitionRegion.
139141
* The resulting number is the number of tiles outside the block's floorplan region, meaning the higher
140142
* it is, the more difficult the block is to place.
141143
*/
142-
double get_floorplan_score(ClusterBlockId blk_id, PartitionRegion& pr, t_logical_block_type_ptr block_type, GridTileLookup& grid_tiles);
144+
double get_floorplan_score(ClusterBlockId blk_id,
145+
const PartitionRegion& pr,
146+
t_logical_block_type_ptr block_type,
147+
const GridTileLookup& grid_tiles);
143148

144149
#endif /* VPR_SRC_PLACE_PLACE_CONSTRAINTS_H_ */

0 commit comments

Comments
 (0)