Skip to content

Clean up the usage tracking in grid blocks. #3088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions vpr/src/base/blk_loc_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ void BlkLocRegistry::set_block_location(ClusterBlockId blk_id, const t_pl_loc& l
location.layer);
}

// Mark the grid location and usage of the block
// Mark the grid location
grid_blocks_.set_block_at_location(location, blk_id);
grid_blocks_.increment_usage({location.x, location.y, location.layer});

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

// Add to new location
if (grid_blocks_.block_at_location(to) == ClusterBlockId::INVALID()) {
//Only need to increase usage if previously unused
grid_blocks_.increment_usage({to.x, to.y, to.layer});
}
grid_blocks_.set_block_at_location(to, blk);

} // Finish updating clb for all blocks
Expand Down
30 changes: 7 additions & 23 deletions vpr/src/base/grid_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,24 @@ void GridBlock::init_grid_blocks(const DeviceGrid& device_grid) {
for (size_t x = 0; x < grid_width; x++) {
for (size_t y = 0; y < grid_height; y++) {
const t_physical_tile_loc tile_loc({(int)x, (int)y, (int)layer_num});
auto type = device_grid.get_physical_type(tile_loc);
t_physical_tile_type_ptr type = device_grid.get_physical_type(tile_loc);
initialized_grid_block_at_location(tile_loc, type->capacity);
}
}
}
}

void GridBlock::zero_initialize() {
auto& device_ctx = g_vpr_ctx.device();
const DeviceContext& device_ctx = g_vpr_ctx.device();

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

for (const auto& sub_tile : tile->sub_tiles) {
auto capacity = sub_tile.capacity;
for (const t_sub_tile& sub_tile : tile->sub_tiles) {
t_capacity_range capacity = sub_tile.capacity;

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

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

zero_initialize();

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

set_block_at_location(location, blk_id);
increment_usage({location.x, location.y, location.layer});
}
}

int GridBlock::increment_usage(const t_physical_tile_loc& loc) {
int curr_usage = get_usage(loc);
int updated_usage = set_usage(loc, curr_usage + 1);

return updated_usage;
}

int GridBlock::decrement_usage(const t_physical_tile_loc& loc) {
int curr_usage = get_usage(loc);
int updated_usage = set_usage(loc, curr_usage - 1);

return updated_usage;
}
23 changes: 12 additions & 11 deletions vpr/src/base/grid_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

///@brief Stores the clustered blocks placed at a particular grid location
struct t_grid_blocks {
int usage; ///<How many valid blocks are in use at this location

/**
* @brief The clustered blocks associated with this grid location.
*
Expand Down Expand Up @@ -61,12 +59,19 @@ class GridBlock {
return grid_blocks_[loc.layer_num][loc.x][loc.y].blocks.size();
}

inline int set_usage(const t_physical_tile_loc loc, int usage) {
return grid_blocks_[loc.layer_num][loc.x][loc.y].usage = usage;
}

/**
* @brief Returns the number of subtiles in use at the specified grid location.
*
* Iterates over all subtiles at the given physical tile location and counts
* how many are currently occupied by a block.
*/
inline int get_usage(const t_physical_tile_loc loc) const {
return grid_blocks_[loc.layer_num][loc.x][loc.y].usage;
int usage = 0;
for (size_t sub_tile = 0; sub_tile < num_blocks_at_location(loc); ++sub_tile) {
if (!is_sub_tile_empty(loc, static_cast<int>(sub_tile)))
usage++;
}
return usage;
}

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

int increment_usage(const t_physical_tile_loc& loc);

int decrement_usage(const t_physical_tile_loc& loc);

private:
vtr::NdMatrix<t_grid_blocks, 3> grid_blocks_;
};
1 change: 0 additions & 1 deletion vpr/src/place/noc_place_checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void NoCPlacementCheckpoint::restore_checkpoint(t_placer_costs& costs,
for (const NocRouter& phy_router : noc_phy_routers) {
t_physical_tile_loc phy_loc = phy_router.get_router_physical_location();

grid_blocks.set_usage(phy_loc, 0);
auto tile = device_ctx.grid.get_physical_type(phy_loc);

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