Skip to content

Commit

Permalink
changed floorplan_constraints_regions_overfull() to check whether who…
Browse files Browse the repository at this point in the history
…le PartitionRegions are full instead of individual Regions
  • Loading branch information
soheilshahrouz committed Jun 30, 2024
1 parent 9fd7389 commit 571cede
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 50 deletions.
2 changes: 1 addition & 1 deletion vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ struct FloorplanningContext : public Context {
*/
std::vector<vtr::vector<ClusterBlockId, PartitionRegion>> compressed_cluster_constraints;

std::vector<Region> overfull_regions;
std::vector<PartitionRegion> overfull_partition_regions;
};

/**
Expand Down
31 changes: 10 additions & 21 deletions vpr/src/pack/attraction_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,24 @@ void AttractionInfo::create_att_groups_for_overfull_regions() {
atom_attraction_group.resize(num_atoms);
fill(atom_attraction_group.begin(), atom_attraction_group.end(), AttractGroupId::INVALID());

const auto& overfull_regions = floorplanning_ctx.overfull_regions;
PartitionRegion overfull_regions_pr;
for (const auto& overfull_region : overfull_regions) {
overfull_regions_pr.add_to_part_region(overfull_region);
}
/*
* Create a PartitionRegion that contains all the overfull regions so that you can
* make an attraction group for any partition that intersects with any of these regions
*/
const std::vector<PartitionRegion>& overfull_prs = floorplanning_ctx.overfull_partition_regions;

/*
* Create an attraction group for each parition with an overfull region.
* Create an attraction group for each partition that overlaps with at least one overfull partition
*/

for (int ipart = 0; ipart < num_parts; ipart++) {
PartitionId partid(ipart);

const Partition& part = floorplanning_ctx.constraints.get_partition(partid);
const auto& pr_regions = part.get_part_region();

PartitionRegion intersect_pr;

intersect_pr = intersection(overfull_regions_pr, pr_regions);

if (!intersect_pr.empty()) {
AttractionGroup group_info;
group_info.group_atoms = floorplanning_ctx.constraints.get_part_atoms(partid);

attraction_groups.push_back(group_info);
for (const PartitionRegion& overfull_pr : overfull_prs) {
PartitionRegion intersect_pr = intersection(part.get_part_region(), overfull_pr);
if (!intersect_pr.empty()) {
AttractionGroup group_info;
group_info.group_atoms = floorplanning_ctx.constraints.get_part_atoms(partid);
attraction_groups.push_back(group_info);
break;
}
}
}

Expand Down
59 changes: 31 additions & 28 deletions vpr/src/pack/constraints_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,55 @@ bool floorplan_constraints_regions_overfull() {
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& device_ctx = g_vpr_ctx.device();

auto& block_types = device_ctx.logical_block_types;
const std::vector<t_logical_block_type>& block_types = device_ctx.logical_block_types;

std::unordered_map<Region, std::vector<int>> regions_count_info;
// keep record of how many blocks of each type are assigned to each PartitionRegion
std::unordered_map<PartitionRegion, std::vector<int>> pr_count_info;

for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
for (const ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
if (!is_cluster_constrained(blk_id)) {
continue;
}
t_logical_block_type_ptr bt = cluster_ctx.clb_nlist.block_type(blk_id);

const PartitionRegion& pr = floorplanning_ctx.cluster_constraints[blk_id];
const std::vector<Region>& regions = pr.get_regions();

for (const auto& current_reg : regions) {
auto got = regions_count_info.find(current_reg);

if (got == regions_count_info.end()) {
std::vector<int> block_type_counts(block_types.size(), 0);

block_type_counts[bt->index]++;

regions_count_info.insert({current_reg, block_type_counts});
auto got = pr_count_info.find(pr);

} else {
got->second[bt->index]++;
}
if (got == pr_count_info.end()) {
std::vector<int> block_type_counts(block_types.size(), 0);
block_type_counts[bt->index]++;
pr_count_info.insert({pr, block_type_counts});
} else {
got->second[bt->index]++;
}
}

bool floorplan_regions_overfull = false;

for (const auto& [region, block_type_counts] : regions_count_info) {
const vtr::Rect<int>& rect = region.get_rect();
const auto [layer_low, layer_high] = region.get_layer_range();
for (const auto & block_type : block_types) {
for (const auto& [pr, block_type_counts] : pr_count_info) {
const std::vector<Region>& regions = pr.get_regions();

for (const t_logical_block_type& block_type : block_types) {
int num_assigned_blocks = block_type_counts[block_type.index];
int num_tiles = grid_tiles.region_tile_count(region, &block_type);
int num_tiles = std::accumulate(regions.begin(), regions.end(), 0, [&grid_tiles, &block_type](int acc, const Region& reg) -> int {
return acc + grid_tiles.region_tile_count(reg, &block_type);
});

if (num_assigned_blocks > num_tiles) {
floorplan_regions_overfull = true;
floorplanning_ctx.overfull_regions.push_back(region);
VTR_LOG("\n \nRegion (%d, %d, %d) to (%d, %d, %d) st %d \n",
rect.xmin(), rect.ymin(), layer_low,
rect.xmax(), rect.ymax(), layer_high,
region.get_sub_tile());
VTR_LOG("Assigned %d blocks of type %s, but only has %d tiles of that type\n",
floorplanning_ctx.overfull_partition_regions.push_back(pr);
VTR_LOG("\n\nA partition including the following regions has been assigned %d blocks of type $s, "
"but only has %d tiles of that type\n",
num_assigned_blocks, block_type.name, num_tiles);
for (const Region& reg : regions) {
const vtr::Rect<int>& rect = reg.get_rect();
const auto [layer_low, layer_high] = reg.get_layer_range();
VTR_LOG("\tRegion (%d, %d, %d) to (%d, %d, %d) st %d \n",
rect.xmin(), rect.ymin(), layer_low,
rect.xmax(), rect.ymax(), layer_high,
reg.get_sub_tile());
}

}
}
}
Expand Down

0 comments on commit 571cede

Please sign in to comment.