Skip to content

Commit eace358

Browse files
move clear_all_grid_locs() to BlkLocRegistry
This function clears a BlkLocRegistry object. It makes more sense if it is implemented as a BlkLocRegistry method
1 parent d1eea5f commit eace358

File tree

5 files changed

+84
-91
lines changed

5 files changed

+84
-91
lines changed

vpr/src/analytical_place/full_legalizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class APClusterPlacer {
104104
// to share the code.
105105

106106
// Clear the grid locations (stolen from initial_placement)
107-
clear_all_grid_locs(blk_loc_registry);
107+
blk_loc_registry.clear_all_grid_locs();
108108

109109
// Deal with the placement constraints.
110110
propagate_place_constraints();

vpr/src/base/blk_loc_registry.cpp

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int BlkLocRegistry::tile_pin_index(const ClusterPinId pin) const {
3636
}
3737

3838
int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net_pin_index) const {
39-
auto& cluster_ctx = g_vpr_ctx.clustering();
39+
const auto& cluster_ctx = g_vpr_ctx.clustering();
4040

4141
// Get the logical pin index of pin within its logical block type
4242
ClusterPinId pin_id = cluster_ctx.clb_nlist.net_pin(net_id, net_pin_index);
@@ -45,22 +45,22 @@ int BlkLocRegistry::net_pin_to_tile_pin_index(const ClusterNetId net_id, int net
4545
}
4646

4747
void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& location) {
48-
auto& device_ctx = g_vpr_ctx.device();
49-
auto& cluster_ctx = g_vpr_ctx.clustering();
48+
const auto& device_ctx = g_vpr_ctx.device();
49+
const auto& cluster_ctx = g_vpr_ctx.clustering();
5050

5151
const std::string& block_name = cluster_ctx.clb_nlist.block_name(blk_id);
5252

53-
//Check if block location is out of range of grid dimensions
53+
// Check if block location is out of range of grid dimensions
5454
if (location.x < 0 || location.x > int(device_ctx.grid.width() - 1)
5555
|| location.y < 0 || location.y > int(device_ctx.grid.height() - 1)) {
5656
VPR_THROW(VPR_ERROR_PLACE, "Block %s with ID %d is out of range at location (%d, %d). \n",
5757
block_name.c_str(), blk_id, location.x, location.y);
5858
}
5959

60-
//Set the location of the block
60+
// Set the location of the block
6161
block_locs_[blk_id].loc = location;
6262

63-
//Check if block is at an illegal location
63+
// Check if block is at an illegal location
6464
auto physical_tile = device_ctx.grid.get_physical_type({location.x, location.y, location.layer});
6565
auto logical_block = cluster_ctx.clb_nlist.block_type(blk_id);
6666

@@ -77,13 +77,71 @@ void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& l
7777
location.layer);
7878
}
7979

80-
//Mark the grid location and usage of the block
80+
// Mark the grid location and usage of the block
8181
grid_blocks_.set_block_at_location(location, blk_id);
8282
grid_blocks_.increment_usage({location.x, location.y, location.layer});
8383

8484
place_sync_external_block_connections(blk_id);
8585
}
8686

87+
void BlkLocRegistry::clear_all_grid_locs() {
88+
const auto& device_ctx = g_vpr_ctx.device();
89+
90+
std::unordered_set<int> blk_types_to_be_cleared;
91+
const auto& logical_block_types = device_ctx.logical_block_types;
92+
93+
// Insert all the logical block types into the set except the empty type
94+
// clear_block_type_grid_locs does not expect empty type to be among given types
95+
for (const t_logical_block_type& logical_type : logical_block_types) {
96+
if (!is_empty_type(&logical_type)) {
97+
blk_types_to_be_cleared.insert(logical_type.index);
98+
}
99+
}
100+
101+
clear_block_type_grid_locs(blk_types_to_be_cleared);
102+
}
103+
104+
void BlkLocRegistry::clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index) {
105+
const auto& device_ctx = g_vpr_ctx.device();
106+
const auto& cluster_ctx = g_vpr_ctx.clustering();
107+
108+
bool clear_all_block_types = false;
109+
110+
/* check if all types should be cleared
111+
* logical_block_types contain empty type, needs to be ignored.
112+
* Not having any type in unplaced_blk_types_index means that it is the first iteration, hence all grids needs to be cleared
113+
*/
114+
if (unplaced_blk_types_index.size() == device_ctx.logical_block_types.size() - 1) {
115+
clear_all_block_types = true;
116+
}
117+
118+
/* We'll use the grid to record where everything goes. Initialize to the grid has no
119+
* blocks placed anywhere.
120+
*/
121+
for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
122+
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
123+
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
124+
const t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({i, j, layer_num});
125+
int itype = type->index;
126+
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
127+
grid_blocks_.set_usage({i, j, layer_num}, 0);
128+
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
129+
grid_blocks_.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
130+
}
131+
}
132+
}
133+
}
134+
}
135+
136+
// Similarly, mark all blocks as not being placed yet.
137+
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
138+
int blk_type = cluster_ctx.clb_nlist.block_type(blk_id)->index;
139+
if (clear_all_block_types || unplaced_blk_types_index.count(blk_type)) {
140+
block_locs_[blk_id].loc = t_pl_loc();
141+
}
142+
}
143+
}
144+
87145
void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk) {
88146
const auto& cluster_ctx = g_vpr_ctx.clustering();
89147
const auto& clb_nlist = cluster_ctx.clb_nlist;
@@ -119,7 +177,7 @@ void BlkLocRegistry::place_sync_external_block_connections(ClusterBlockId iblk)
119177
}
120178

121179
void BlkLocRegistry::apply_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
122-
auto& device_ctx = g_vpr_ctx.device();
180+
const auto& device_ctx = g_vpr_ctx.device();
123181

124182
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::APPLY);
125183

@@ -177,7 +235,7 @@ void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
177235
}
178236

179237
void BlkLocRegistry::revert_move_blocks(const t_pl_blocks_to_be_moved& blocks_affected) {
180-
auto& device_ctx = g_vpr_ctx.device();
238+
const auto& device_ctx = g_vpr_ctx.device();
181239

182240
VTR_ASSERT_DEBUG(expected_transaction_ == e_expected_transaction::COMMIT_REVERT);
183241

vpr/src/base/blk_loc_registry.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ class BlkLocRegistry {
6161
*/
6262
void set_block_location(ClusterBlockId blk_id, const t_pl_loc& location);
6363

64+
/**
65+
* @brief Initializes the grid to empty. It also initializes the location for
66+
* all blocks to unplaced.
67+
*/
68+
void clear_all_grid_locs();
69+
70+
/**
71+
* @brief Set chosen grid locations to EMPTY block id before each placement iteration
72+
*
73+
* @param unplaced_blk_types_index Block types that their grid locations must be cleared.
74+
*/
75+
void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index);
76+
6477
/**
6578
* @brief Syncs the logical block pins corresponding to the input iblk with the corresponding chosen physical tile
6679
* @param iblk cluster block ID to sync within the assigned physical tile

vpr/src/place/initial_placement.cpp

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ static constexpr int SORT_WEIGHT_PER_FAILED_BLOCK = 10;
3232
// The amount of weight that will be added to each tile which is outside the floorplanning constraints
3333
static constexpr int SORT_WEIGHT_PER_TILES_OUTSIDE_OF_PR = 100;
3434

35-
/**
36-
* @brief Set chosen grid locations to EMPTY block id before each placement iteration
37-
*
38-
* @param unplaced_blk_types_index Block types that their grid locations must be cleared.
39-
* @param blk_loc_registry Placement block location information. To be filled with the location
40-
* where pl_macro is placed.
41-
*/
42-
static void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index,
43-
BlkLocRegistry& blk_loc_registry);
44-
4535
/**
4636
* @brief Control routine for placing a macro.
4737
* First iteration of place_marco performs the following steps to place a macro:
@@ -1022,7 +1012,7 @@ static void place_all_blocks(const t_placer_opts& placer_opts,
10221012

10231013
for (auto iter_no = 0; iter_no < MAX_INIT_PLACE_ATTEMPTS; iter_no++) {
10241014
//clear grid for a new placement iteration
1025-
clear_block_type_grid_locs(unplaced_blk_type_in_curr_itr, blk_loc_registry);
1015+
blk_loc_registry.clear_block_type_grid_locs(unplaced_blk_type_in_curr_itr);
10261016
unplaced_blk_type_in_curr_itr.clear();
10271017

10281018
// read the constraint file if the user has provided one and this is not the first attempt
@@ -1096,67 +1086,6 @@ static void place_all_blocks(const t_placer_opts& placer_opts,
10961086
}
10971087
}
10981088

1099-
static void clear_block_type_grid_locs(const std::unordered_set<int>& unplaced_blk_types_index,
1100-
BlkLocRegistry& blk_loc_registry) {
1101-
auto& device_ctx = g_vpr_ctx.device();
1102-
auto& cluster_ctx = g_vpr_ctx.clustering();
1103-
auto& grid_blocks = blk_loc_registry.mutable_grid_blocks();
1104-
auto& block_locs = blk_loc_registry.mutable_block_locs();
1105-
1106-
bool clear_all_block_types = false;
1107-
1108-
/* check if all types should be cleared
1109-
* logical_block_types contain empty type, needs to be ignored.
1110-
* Not having any type in unplaced_blk_types_index means that it is the first iteration, hence all grids needs to be cleared
1111-
*/
1112-
if (unplaced_blk_types_index.size() == device_ctx.logical_block_types.size() - 1) {
1113-
clear_all_block_types = true;
1114-
}
1115-
1116-
/* We'll use the grid to record where everything goes. Initialize to the grid has no
1117-
* blocks placed anywhere.
1118-
*/
1119-
for (int layer_num = 0; layer_num < device_ctx.grid.get_num_layers(); layer_num++) {
1120-
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
1121-
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
1122-
const t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({i, j, layer_num});
1123-
int itype = type->index;
1124-
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
1125-
grid_blocks.set_usage({i, j, layer_num}, 0);
1126-
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
1127-
grid_blocks.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
1128-
}
1129-
}
1130-
}
1131-
}
1132-
}
1133-
1134-
/* Similarly, mark all blocks as not being placed yet. */
1135-
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
1136-
int blk_type = cluster_ctx.clb_nlist.block_type(blk_id)->index;
1137-
if (clear_all_block_types || unplaced_blk_types_index.count(blk_type)) {
1138-
block_locs[blk_id].loc = t_pl_loc();
1139-
}
1140-
}
1141-
}
1142-
1143-
void clear_all_grid_locs(BlkLocRegistry& blk_loc_registry) {
1144-
auto& device_ctx = g_vpr_ctx.device();
1145-
1146-
std::unordered_set<int> blk_types_to_be_cleared;
1147-
const auto& logical_block_types = device_ctx.logical_block_types;
1148-
1149-
// Insert all the logical block types into the set except the empty type
1150-
// clear_block_type_grid_locs does not expect empty type to be among given types
1151-
for (const t_logical_block_type& logical_type : logical_block_types) {
1152-
if (!is_empty_type(&logical_type)) {
1153-
blk_types_to_be_cleared.insert(logical_type.index);
1154-
}
1155-
}
1156-
1157-
clear_block_type_grid_locs(blk_types_to_be_cleared, blk_loc_registry);
1158-
}
1159-
11601089
bool place_one_block(const ClusterBlockId blk_id,
11611090
enum e_pad_loc_type pad_loc_type,
11621091
std::vector<t_grid_empty_locs_block_type>* blk_types_empty_locs_in_grid,
@@ -1229,7 +1158,7 @@ void initial_placement(const t_placer_opts& placer_opts,
12291158
/* Initialize the grid blocks to empty.
12301159
* Initialize all the blocks to unplaced.
12311160
*/
1232-
clear_all_grid_locs(blk_loc_registry);
1161+
blk_loc_registry.clear_all_grid_locs();
12331162

12341163
/* Go through cluster blocks to calculate the tightest placement
12351164
* floorplan constraint for each constrained block

vpr/src/place/initial_placement.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ bool place_one_block(const ClusterBlockId blk_id,
159159
vtr::vector<ClusterBlockId, t_block_score>* block_scores,
160160
BlkLocRegistry& blk_loc_registry);
161161

162-
/**
163-
* @brief Initializes the grid to empty. It also initializes the location for
164-
* all blocks to unplaced.
165-
*
166-
* @param blk_loc_registry Placement block location information. To be filled with the location
167-
* where pl_macro is placed.
168-
*/
169-
void clear_all_grid_locs(BlkLocRegistry& blk_loc_registry);
162+
170163

171164
#endif

0 commit comments

Comments
 (0)