Skip to content

Commit c8b4a59

Browse files
committed
Added checks to ensure updated PartitionRegions do not go out of grid dimensions.
1 parent d8414cc commit c8b4a59

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

vpr/src/place/place_constraints.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool is_macro_constrained(const t_pl_macro& pl_macro) {
5454
}
5555

5656
/*Returns PartitionRegion of where the head of the macro could go*/
57-
PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro) {
57+
PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro, const PartitionRegion& grid_pr) {
5858
PartitionRegion macro_head_pr;
5959
bool is_member_constrained = false;
6060
int num_constrained_members = 0;
@@ -105,6 +105,9 @@ PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro) {
105105
}
106106
}
107107

108+
//intersect to ensure the head pr does not go outside of grid dimensions
109+
macro_head_pr = intersection(macro_head_pr, grid_pr);
110+
108111
//if the intersection is empty, no way to place macro members together, give an error
109112
if (macro_head_pr.empty()) {
110113
VPR_ERROR(VPR_ERROR_PLACE, " \n Feasible floorplanning constraints could not be calculated for the placement macro.\n");
@@ -113,7 +116,7 @@ PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro) {
113116
return macro_head_pr;
114117
}
115118

116-
PartitionRegion update_macro_member_pr(PartitionRegion& head_pr, const t_pl_offset& offset) {
119+
PartitionRegion update_macro_member_pr(PartitionRegion& head_pr, const t_pl_offset& offset, const PartitionRegion& grid_pr) {
117120
std::vector<Region> block_regions = head_pr.get_partition_region();
118121
PartitionRegion macro_pr;
119122

@@ -139,20 +142,38 @@ PartitionRegion update_macro_member_pr(PartitionRegion& head_pr, const t_pl_offs
139142
macro_pr.add_to_part_region(modified_reg);
140143
}
141144

145+
//intersect to ensure the head pr does not go outside of grid dimensions
146+
macro_pr = intersection(macro_pr, grid_pr);
147+
148+
//if the intersection is empty, no way to place macro members together, give an error
149+
if (macro_pr.empty()) {
150+
VPR_ERROR(VPR_ERROR_PLACE, " \n Feasible floorplanning constraints could not be calculated for the placement macro.\n");
151+
}
152+
142153
return macro_pr;
143154
}
144155

145156
void propagate_place_constraints() {
146157
auto& place_ctx = g_vpr_ctx.placement();
147158
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
159+
auto& device_ctx = g_vpr_ctx.device();
160+
161+
//Create a PartitionRegion with grid dimensions
162+
//Will be used to check that updated PartitionRegions are within grid bounds
163+
int width = device_ctx.grid.width() - 1;
164+
int height = device_ctx.grid.height() - 1;
165+
Region grid_reg;
166+
grid_reg.set_region_rect(0, 0, width, height);
167+
PartitionRegion grid_pr;
168+
grid_pr.add_to_part_region(grid_reg);
148169

149170
for (auto pl_macro : place_ctx.pl_macros) {
150171
if (is_macro_constrained(pl_macro)) {
151172
/*
152173
* Update the PartitionRegion for the head of the macro
153174
* based on the constraints of all blocks contained in the macro
154175
*/
155-
PartitionRegion macro_head_pr = update_macro_head_pr(pl_macro);
176+
PartitionRegion macro_head_pr = update_macro_head_pr(pl_macro, grid_pr);
156177

157178
//Update PartitionRegions of all members of the macro
158179
for (size_t imember = 0; imember < pl_macro.members.size(); imember++) {
@@ -163,7 +184,7 @@ void propagate_place_constraints() {
163184
if (imember == 0) {
164185
floorplanning_ctx.cluster_constraints[iblk] = macro_head_pr;
165186
} else { //Update macro member PR
166-
PartitionRegion macro_pr = update_macro_member_pr(macro_head_pr, offset);
187+
PartitionRegion macro_pr = update_macro_member_pr(macro_head_pr, offset, grid_pr);
167188
floorplanning_ctx.cluster_constraints[iblk] = macro_pr;
168189
}
169190
}

vpr/src/place/place_constraints.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,27 @@ bool is_macro_constrained(const t_pl_macro& pl_macro);
3535

3636
/*
3737
* Returns PartitionRegion for the head of the macro based on the floorplan constraints
38-
* of all blocks in the macro.
38+
* of all blocks in the macro. For example, if there was a macro of length two and each block has
39+
* a constraint, this routine will shift and intersect the two constraint regions to calculate
40+
* the tightest region constraint for the head macro.
3941
*/
40-
PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro);
42+
PartitionRegion update_macro_head_pr(const t_pl_macro& pl_macro, const PartitionRegion& grid_pr);
4143

4244
/*
4345
* Update the PartitionRegions of non-head members of a macro,
44-
* based on the constraint that was calculated for the head region.
45-
* The constraint that was calculated for the head region considered all
46-
* constrained blocks in the macro, so to calculate the constraint for the rest
47-
* of the blocks, it is just the head constraint with the offset of the member
48-
* applied.
46+
* based on the constraint that was calculated for the head region, head_pr.
47+
* The constraint that was calculated for the head region must have
48+
* calculated the tightest constraints for the head member
49+
* by shifting and intersecting the constraints on all macro members.
50+
* For each macro member, the updated constraint is essentially the head constraint
51+
* with the member's offset applied.
4952
*/
50-
PartitionRegion update_macro_member_pr(PartitionRegion& head_pr, const t_pl_offset& offset);
53+
PartitionRegion update_macro_member_pr(PartitionRegion& head_pr, const t_pl_offset& offset, const PartitionRegion& grid_pr);
5154

5255
/*
5356
* Updates the floorplan constraints information for all constrained macros.
54-
* The head member of each constrained macro is assigned a new PartitionRegion
55-
* that is calculated based on the constraints of all the blocks in the macro.
57+
* Updates the constraints to be the tightest constraints possible while adhering
58+
* to the floorplan constraints of each macro member.
5659
* This is done at the start of initial placement to ease floorplan legality checking
5760
* while placing macros during initial placement.
5861
*/

vpr/test/test_vpr_constraints.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,12 @@ TEST_CASE("MacroConstraints", "[vpr]") {
436436

437437
head_pr.add_to_part_region(reg);
438438

439-
PartitionRegion macro_pr = update_macro_member_pr(head_pr, offset);
439+
Region grid_reg;
440+
grid_reg.set_region_rect(0, 0, 20, 20);
441+
PartitionRegion grid_pr;
442+
grid_pr.add_to_part_region(grid_reg);
443+
444+
PartitionRegion macro_pr = update_macro_member_pr(head_pr, offset, grid_pr);
440445

441446
std::vector<Region> mac_regions = macro_pr.get_partition_region();
442447

0 commit comments

Comments
 (0)