Skip to content

Commit 2dc22c5

Browse files
Merge pull request #3088 from verilog-to-routing/cleanup_grid_usage
Clean up the usage tracking in grid blocks.
2 parents 703090f + 3bd9677 commit 2dc22c5

File tree

4 files changed

+20
-43
lines changed

4 files changed

+20
-43
lines changed

vpr/src/base/blk_loc_registry.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& l
125125
location.layer);
126126
}
127127

128-
// Mark the grid location and usage of the block
128+
// Mark the grid location
129129
grid_blocks_.set_block_at_location(location, blk_id);
130-
grid_blocks_.increment_usage({location.x, location.y, location.layer});
131130

132131
place_sync_external_block_connections(blk_id);
133132
}
@@ -172,7 +171,6 @@ void BlkLocRegistry::clear_block_type_grid_locs(const std::unordered_set<int>& u
172171
const t_physical_tile_type_ptr type = device_ctx.grid.get_physical_type({i, j, layer_num});
173172
int itype = type->index;
174173
if (clear_all_block_types || unplaced_blk_types_index.count(itype)) {
175-
grid_blocks_.set_usage({i, j, layer_num}, 0);
176174
for (int k = 0; k < device_ctx.physical_tile_types[itype].capacity; k++) {
177175
grid_blocks_.set_block_at_location({i, j, k, layer_num}, ClusterBlockId::INVALID());
178176
}
@@ -267,14 +265,9 @@ void BlkLocRegistry::commit_move_blocks(const t_pl_blocks_to_be_moved& blocks_af
267265
// Remove from old location only if it hasn't already been updated by a previous block update
268266
if (grid_blocks_.block_at_location(from) == blk) {
269267
grid_blocks_.set_block_at_location(from, ClusterBlockId::INVALID());
270-
grid_blocks_.decrement_usage({from.x, from.y, from.layer});
271268
}
272269

273270
// Add to new location
274-
if (grid_blocks_.block_at_location(to) == ClusterBlockId::INVALID()) {
275-
//Only need to increase usage if previously unused
276-
grid_blocks_.increment_usage({to.x, to.y, to.layer});
277-
}
278271
grid_blocks_.set_block_at_location(to, blk);
279272

280273
} // Finish updating clb for all blocks

vpr/src/base/grid_block.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,24 @@ void GridBlock::init_grid_blocks(const DeviceGrid& device_grid) {
1717
for (size_t x = 0; x < grid_width; x++) {
1818
for (size_t y = 0; y < grid_height; y++) {
1919
const t_physical_tile_loc tile_loc({(int)x, (int)y, (int)layer_num});
20-
auto type = device_grid.get_physical_type(tile_loc);
20+
t_physical_tile_type_ptr type = device_grid.get_physical_type(tile_loc);
2121
initialized_grid_block_at_location(tile_loc, type->capacity);
2222
}
2323
}
2424
}
2525
}
2626

2727
void GridBlock::zero_initialize() {
28-
auto& device_ctx = g_vpr_ctx.device();
28+
const DeviceContext& device_ctx = g_vpr_ctx.device();
2929

3030
/* Initialize all occupancy to zero. */
3131
for (int layer_num = 0; layer_num < (int)device_ctx.grid.get_num_layers(); layer_num++) {
3232
for (int i = 0; i < (int)device_ctx.grid.width(); i++) {
3333
for (int j = 0; j < (int)device_ctx.grid.height(); j++) {
34-
set_usage({i, j, layer_num}, 0);
35-
auto tile = device_ctx.grid.get_physical_type({i, j, layer_num});
34+
t_physical_tile_type_ptr tile = device_ctx.grid.get_physical_type({i, j, layer_num});
3635

37-
for (const auto& sub_tile : tile->sub_tiles) {
38-
auto capacity = sub_tile.capacity;
36+
for (const t_sub_tile& sub_tile : tile->sub_tiles) {
37+
t_capacity_range capacity = sub_tile.capacity;
3938

4039
for (int k = 0; k < capacity.total(); k++) {
4140
set_block_at_location({i, j, k + capacity.low, layer_num}, ClusterBlockId::INVALID());
@@ -47,8 +46,8 @@ void GridBlock::zero_initialize() {
4746
}
4847

4948
void GridBlock::load_from_block_locs(const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs) {
50-
auto& cluster_ctx = g_vpr_ctx.clustering();
51-
auto& device_ctx = g_vpr_ctx.device();
49+
const ClusteringContext& cluster_ctx = g_vpr_ctx.clustering();
50+
const DeviceContext& device_ctx = g_vpr_ctx.device();
5251

5352
zero_initialize();
5453

@@ -59,20 +58,5 @@ void GridBlock::load_from_block_locs(const vtr::vector_map<ClusterBlockId, t_blo
5958
VTR_ASSERT(location.y < (int)device_ctx.grid.height());
6059

6160
set_block_at_location(location, blk_id);
62-
increment_usage({location.x, location.y, location.layer});
6361
}
6462
}
65-
66-
int GridBlock::increment_usage(const t_physical_tile_loc& loc) {
67-
int curr_usage = get_usage(loc);
68-
int updated_usage = set_usage(loc, curr_usage + 1);
69-
70-
return updated_usage;
71-
}
72-
73-
int GridBlock::decrement_usage(const t_physical_tile_loc& loc) {
74-
int curr_usage = get_usage(loc);
75-
int updated_usage = set_usage(loc, curr_usage - 1);
76-
77-
return updated_usage;
78-
}

vpr/src/base/grid_block.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
///@brief Stores the clustered blocks placed at a particular grid location
1010
struct t_grid_blocks {
11-
int usage; ///<How many valid blocks are in use at this location
12-
1311
/**
1412
* @brief The clustered blocks associated with this grid location.
1513
*
@@ -61,12 +59,19 @@ class GridBlock {
6159
return grid_blocks_[loc.layer_num][loc.x][loc.y].blocks.size();
6260
}
6361

64-
inline int set_usage(const t_physical_tile_loc loc, int usage) {
65-
return grid_blocks_[loc.layer_num][loc.x][loc.y].usage = usage;
66-
}
67-
62+
/**
63+
* @brief Returns the number of subtiles in use at the specified grid location.
64+
*
65+
* Iterates over all subtiles at the given physical tile location and counts
66+
* how many are currently occupied by a block.
67+
*/
6868
inline int get_usage(const t_physical_tile_loc loc) const {
69-
return grid_blocks_[loc.layer_num][loc.x][loc.y].usage;
69+
int usage = 0;
70+
for (size_t sub_tile = 0; sub_tile < num_blocks_at_location(loc); ++sub_tile) {
71+
if (!is_sub_tile_empty(loc, static_cast<int>(sub_tile)))
72+
usage++;
73+
}
74+
return usage;
7075
}
7176

7277
inline bool is_sub_tile_empty(const t_physical_tile_loc loc, int sub_tile) const {
@@ -88,10 +93,6 @@ class GridBlock {
8893
*/
8994
void load_from_block_locs(const vtr::vector_map<ClusterBlockId, t_block_loc>& block_locs);
9095

91-
int increment_usage(const t_physical_tile_loc& loc);
92-
93-
int decrement_usage(const t_physical_tile_loc& loc);
94-
9596
private:
9697
vtr::NdMatrix<t_grid_blocks, 3> grid_blocks_;
9798
};

vpr/src/place/noc_place_checkpoint.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void NoCPlacementCheckpoint::restore_checkpoint(t_placer_costs& costs,
4545
for (const NocRouter& phy_router : noc_phy_routers) {
4646
t_physical_tile_loc phy_loc = phy_router.get_router_physical_location();
4747

48-
grid_blocks.set_usage(phy_loc, 0);
4948
auto tile = device_ctx.grid.get_physical_type(phy_loc);
5049

5150
for (const auto& sub_tile : tile->sub_tiles) {

0 commit comments

Comments
 (0)