Skip to content

Commit 8db689a

Browse files
add compressed_cluster_constraints
1 parent 62fa97e commit 8db689a

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

vpr/src/base/vpr_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ struct FloorplanningContext : public Context {
520520
*/
521521
vtr::vector<ClusterBlockId, PartitionRegion> cluster_constraints;
522522

523+
vtr::vector<ClusterBlockId, PartitionRegion> compressed_cluster_constraints;
524+
523525
std::vector<Region> overfull_regions;
524526
};
525527

vpr/src/place/compressed_grid.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,46 @@ struct t_compressed_block_grid {
5555
return {cx, cy, layer_num};
5656
}
5757

58+
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_up(t_physical_tile_loc grid_loc) const {
59+
int cx = OPEN;
60+
int cy = OPEN;
61+
int layer_num = grid_loc.layer_num;
62+
63+
auto itr_x = std::upper_bound(compressed_to_grid_x[layer_num].begin(), compressed_to_grid_x[layer_num].end(), grid_loc.x);
64+
if (itr_x == compressed_to_grid_x[layer_num].begin())
65+
cx = 0;
66+
else
67+
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x - 1);
68+
69+
auto itr_y = std::upper_bound(compressed_to_grid_y[layer_num].begin(), compressed_to_grid_y[layer_num].end(), grid_loc.y);
70+
if (itr_y == compressed_to_grid_y[layer_num].begin())
71+
cy = 0;
72+
else
73+
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y - 1);
74+
75+
return {cx, cy, layer_num};
76+
}
77+
78+
inline t_physical_tile_loc grid_loc_to_compressed_loc_approx_round_down(t_physical_tile_loc grid_loc) const {
79+
int cx = OPEN;
80+
int cy = OPEN;
81+
int layer_num = grid_loc.layer_num;
82+
83+
auto itr_x = std::lower_bound(compressed_to_grid_x[layer_num].begin(), compressed_to_grid_x[layer_num].end(), grid_loc.x);
84+
if (itr_x == compressed_to_grid_x[layer_num].end())
85+
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x - 1);
86+
else
87+
cx = std::distance(compressed_to_grid_x[layer_num].begin(), itr_x);
88+
89+
auto itr_y = std::lower_bound(compressed_to_grid_y[layer_num].begin(), compressed_to_grid_y[layer_num].end(), grid_loc.y);
90+
if (itr_y == compressed_to_grid_y[layer_num].end())
91+
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y - 1);
92+
else
93+
cy = std::distance(compressed_to_grid_y[layer_num].begin(), itr_y);
94+
95+
return {cx, cy, layer_num};
96+
}
97+
5898
/**
5999
* @brief find the nearest location in the compressed grid.
60100
*

vpr/src/place/initial_placement.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,8 @@ void initial_placement(const t_placer_opts& placer_opts,
11461146
* as fixed so they do not get moved during initial placement or later during the simulated annealing stage of placement*/
11471147
mark_fixed_blocks();
11481148

1149+
alloc_and_load_compressed_cluster_constraints();
1150+
11491151

11501152
// read the constraint file and place fixed blocks
11511153
if (strlen(constraints_file) != 0) {

vpr/src/place/place_constraints.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,49 @@ void mark_fixed_blocks() {
297297
}
298298
}
299299

300+
void alloc_and_load_compressed_cluster_constraints() {
301+
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
302+
const auto& cluster_ctx = g_vpr_ctx.clustering();
303+
// used to access the compressed grid
304+
const auto& place_ctx = g_vpr_ctx.placement();
305+
306+
floorplanning_ctx.compressed_cluster_constraints.resize(cluster_ctx.clb_nlist.blocks().size());
307+
308+
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
309+
if (!is_cluster_constrained(blk_id)) {
310+
continue;
311+
}
312+
313+
const PartitionRegion& pr = floorplanning_ctx.cluster_constraints[blk_id];
314+
auto block_type = cluster_ctx.clb_nlist.block_type(blk_id);
315+
// Get the compressed grid for NoC
316+
const auto& compressed_grid = place_ctx.compressed_block_grids[block_type->index];
317+
318+
PartitionRegion compressed_pr;
319+
320+
for (const Region& region : pr.get_regions()) {
321+
RegionRectCoord rect = region.get_region_rect();
322+
t_physical_tile_loc min_loc{rect.xmin, rect.ymin, rect.layer_num};
323+
t_physical_tile_loc max_loc{rect.xmax, rect.ymax, rect.layer_num};
324+
t_physical_tile_loc compressed_min_loc = compressed_grid.grid_loc_to_compressed_loc_approx_round_up(min_loc);
325+
t_physical_tile_loc compressed_max_loc = compressed_grid.grid_loc_to_compressed_loc_approx_round_down(max_loc);
326+
327+
RegionRectCoord compressed_rect{compressed_min_loc.x, compressed_min_loc.y,
328+
compressed_max_loc.x, compressed_max_loc.y,
329+
rect.layer_num};
330+
331+
Region compressed_region;
332+
compressed_region.set_region_rect(compressed_rect);
333+
compressed_region.set_sub_tile(region.get_sub_tile());
334+
335+
compressed_pr.add_to_part_region(compressed_region);
336+
}
337+
338+
floorplanning_ctx.compressed_cluster_constraints[blk_id] = compressed_pr;
339+
}
340+
341+
}
342+
300343
/*
301344
* Returns 0, 1, or 2 depending on the number of tiles covered.
302345
* Will not return a value above 2 because as soon as num_tiles is above 1,

vpr/src/place/place_constraints.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ void load_cluster_constraints();
9696
*/
9797
void mark_fixed_blocks();
9898

99+
void alloc_and_load_compressed_cluster_constraints();
100+
99101
/*
100102
* Returns the number of tiles covered by a floorplan region.
101103
* The return value of this routine will either be 0, 1, or 2. This

0 commit comments

Comments
 (0)