Skip to content

Commit e529249

Browse files
authored
Merge pull request #1778 from verilog-to-routing/improve_region_intersect
Improve region intersect function
2 parents 6e442d1 + 7fc899f commit e529249

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

vpr/src/base/region.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,36 @@ bool do_regions_intersect(Region r1, Region r2) {
8181

8282
Region intersection(const Region& r1, const Region& r2) {
8383
Region intersect;
84+
vtr::Rect<int> r1_rect = r1.get_region_rect();
85+
vtr::Rect<int> r2_rect = r2.get_region_rect();
86+
vtr::Rect<int> intersect_rect;
8487

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

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

111+
} else if (r1.get_sub_tile() != NO_SUBTILE && r2.get_sub_tile() == NO_SUBTILE) {
112+
intersect.set_sub_tile(r1.get_sub_tile());
113+
intersect_rect = intersection(r1_rect, r2_rect);
98114
intersect.set_region_rect(intersect_rect.xmin(), intersect_rect.ymin(), intersect_rect.xmax(), intersect_rect.ymax());
99115
}
100116

vpr/src/place/initial_placement.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ static t_physical_tile_type_ptr pick_placement_type(t_logical_block_type_ptr log
4747
vtr::vector<ClusterBlockId, t_block_score> assign_block_scores();
4848

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

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

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

360360
block_scores.resize(blocks.size());
361361

362+
/*
363+
* For the blocks with no floorplan constraints, and the blocks that are not part of macros,
364+
* the block scores will remain at their default values assigned by the constructor
365+
* (macro_size = 0; floorplan_constraints = 0; num_equivalent_tiles =1;
366+
*/
367+
362368
//go through all blocks and store floorplan constraints and num equivalent tiles
363369
for (auto blk_id : blocks) {
364370
if (is_cluster_constrained(blk_id)) {
@@ -380,7 +386,7 @@ vtr::vector<ClusterBlockId, t_block_score> assign_block_scores() {
380386
return block_scores;
381387
}
382388

383-
std::vector<ClusterBlockId> sort_blocks(vtr::vector<ClusterBlockId, t_block_score> block_scores) {
389+
std::vector<ClusterBlockId> sort_blocks(const vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
384390
auto& cluster_ctx = g_vpr_ctx.clustering();
385391

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

403-
void print_sorted_blocks(std::vector<ClusterBlockId> sorted_blocks, vtr::vector<ClusterBlockId, t_block_score> block_scores) {
409+
void print_sorted_blocks(const std::vector<ClusterBlockId>& sorted_blocks, const vtr::vector<ClusterBlockId, t_block_score>& block_scores) {
404410
VTR_LOG("\nPrinting sorted blocks: \n");
405411
for (unsigned int i = 0; i < sorted_blocks.size(); i++) {
406412
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);

0 commit comments

Comments
 (0)