Skip to content

Improve region intersect function #1778

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 3 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 30 additions & 7 deletions vpr/src/base/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,46 @@ bool do_regions_intersect(Region r1, Region r2) {

Region intersection(const Region& r1, const Region& r2) {
Region intersect;
vtr::Rect<int> r1_rect = r1.get_region_rect();
vtr::Rect<int> r2_rect = r2.get_region_rect();
vtr::Rect<int> intersect_rect;

/**
* If the subtiles of the two regions don't match, there is no intersection.
* If they do match, the intersection function if used to get the overlap of the two regions' rectangles.
* If there is no overlap, an empty rectangle will be returned.
/*
* If the subtiles of two regions match (i.e. they both have no subtile specified, or the same subtile specified),
* the regions are intersected. The resulting intersection region will have a rectangle that reflects their overlap,
* (it will be empty if there is no overlap), and a subtile that is the same as that of both regions.
*
* If one of the two regions has a subtile specified, and the other does not, the regions are intersected.
* The resulting intersection region will have a rectangle that reflects their overlap (it will be empty if there is
* no overlap), and a subtile that is the same as the subtile of the region with the specific subtile assigned.
*
* If none of the above cases are true (i.e. the regions both have subtiles specified, but the subtiles do not
* match each other) then the intersection is not performed and a region with an empty rectangle is returned.
* This is because there can be no overlap in this case since the regions are constrained to two separate subtiles.
*/
if (r1.get_sub_tile() == r2.get_sub_tile()) {
intersect.set_sub_tile(r1.get_sub_tile());
vtr::Rect<int> r1_rect = r1.get_region_rect();
vtr::Rect<int> r2_rect = r2.get_region_rect();
vtr::Rect<int> intersect_rect;
intersect_rect = intersection(r1_rect, r2_rect);
intersect.set_region_rect(intersect_rect.xmin(), intersect_rect.ymin(), intersect_rect.xmax(), intersect_rect.ymax());

return intersect;

} else if (r1.get_sub_tile() == NO_SUBTILE && r2.get_sub_tile() != NO_SUBTILE) {
intersect.set_sub_tile(r2.get_sub_tile());
intersect_rect = intersection(r1_rect, r2_rect);
intersect.set_region_rect(intersect_rect.xmin(), intersect_rect.ymin(), intersect_rect.xmax(), intersect_rect.ymax());

return intersect;

} else if (r1.get_sub_tile() != NO_SUBTILE && r2.get_sub_tile() == NO_SUBTILE) {
intersect.set_sub_tile(r1.get_sub_tile());
intersect_rect = intersection(r1_rect, r2_rect);
intersect.set_region_rect(intersect_rect.xmin(), intersect_rect.ymin(), intersect_rect.xmax(), intersect_rect.ymax());

return intersect;
}

//If none of the above cases are true, an empty intersect region is returned
return intersect;
}

Expand Down
14 changes: 10 additions & 4 deletions vpr/src/place/initial_placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static t_physical_tile_type_ptr pick_placement_type(t_logical_block_type_ptr log
vtr::vector<ClusterBlockId, t_block_score> assign_block_scores();

//Sort the blocks according to how difficult they are to place, prior to initial placement
std::vector<ClusterBlockId> sort_blocks(vtr::vector<ClusterBlockId, t_block_score> block_scores);
std::vector<ClusterBlockId> sort_blocks(const vtr::vector<ClusterBlockId, t_block_score>& block_scores);

void print_sorted_blocks(std::vector<ClusterBlockId> sorted_blocks, vtr::vector<ClusterBlockId, t_block_score> block_scores);
void print_sorted_blocks(const std::vector<ClusterBlockId> sorted_blocks, vtr::vector<ClusterBlockId, t_block_score>& block_scores);

static int get_free_sub_tile(std::vector<std::vector<int>>& free_locations, int itype, std::vector<int> possible_sub_tiles) {
for (int sub_tile : possible_sub_tiles) {
Expand Down Expand Up @@ -359,6 +359,12 @@ vtr::vector<ClusterBlockId, t_block_score> assign_block_scores() {

block_scores.resize(blocks.size());

/*
* For the blocks with no floorplan constraints, and the blocks that are not part of macros,
* the block scores will remain at their default values assigned by the constructor
* (macro_size = 0; floorplan_constraints = 0; num_equivalent_tiles =1;
*/

//go through all blocks and store floorplan constraints and num equivalent tiles
for (auto blk_id : blocks) {
if (is_cluster_constrained(blk_id)) {
Expand All @@ -380,7 +386,7 @@ vtr::vector<ClusterBlockId, t_block_score> assign_block_scores() {
return block_scores;
}

std::vector<ClusterBlockId> sort_blocks(vtr::vector<ClusterBlockId, t_block_score> block_scores) {
std::vector<ClusterBlockId> sort_blocks(const vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
auto& cluster_ctx = g_vpr_ctx.clustering();

auto blocks = cluster_ctx.clb_nlist.blocks();
Expand All @@ -400,7 +406,7 @@ std::vector<ClusterBlockId> sort_blocks(vtr::vector<ClusterBlockId, t_block_scor
return sorted_blocks;
}

void print_sorted_blocks(std::vector<ClusterBlockId> sorted_blocks, vtr::vector<ClusterBlockId, t_block_score> block_scores) {
void print_sorted_blocks(const std::vector<ClusterBlockId> sorted_blocks, vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
VTR_LOG("\nPrinting sorted blocks: \n");
for (unsigned int i = 0; i < sorted_blocks.size(); i++) {
VTR_LOG("Block_Id: %zu, Macro size: %d, Num floorplan constraints: %d, Num equivalent tiles %d \n", sorted_blocks[i], block_scores[sorted_blocks[i]].macro_size, block_scores[sorted_blocks[i]].floorplan_constraints, block_scores[sorted_blocks[i]].num_equivalent_tiles);
Expand Down