Skip to content

Commit 76b8da2

Browse files
Merge pull request #2220 from verilog-to-routing/fix_atom_lookup
Fix atom lookup to be created once at the first query and re-used every time after it.
2 parents 6a93c67 + c899d52 commit 76b8da2

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <fstream>
1919
#include "vpr_constraints_writer.h"
2020
#include "region.h"
21+
#include "re_cluster_util.h"
2122

2223
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
2324
VprConstraints constraints;
@@ -46,7 +47,6 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
4647
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile) {
4748
auto& cluster_ctx = g_vpr_ctx.clustering();
4849
auto& place_ctx = g_vpr_ctx.placement();
49-
ClusterAtomsLookup atoms_lookup;
5050

5151
int part_id = 0;
5252
/*
@@ -77,9 +77,9 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
7777
part.set_part_region(pr);
7878
constraints.add_partition(part);
7979

80-
std::vector<AtomBlockId> atoms = atoms_lookup.atoms_in_cluster(blk_id);
80+
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(blk_id);
8181

82-
for (auto atom_id : atoms) {
82+
for (auto atom_id : *atoms) {
8383
constraints.add_constrained_atom(atom_id, partid);
8484
}
8585
part_id++;
@@ -90,7 +90,6 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
9090
auto& cluster_ctx = g_vpr_ctx.clustering();
9191
auto& place_ctx = g_vpr_ctx.placement();
9292
auto& device_ctx = g_vpr_ctx.device();
93-
ClusterAtomsLookup atoms_lookup;
9493

9594
//calculate the cutpoint values according to the grid size
9695
//load two arrays - one for horizontal cutpoints and one for vertical
@@ -151,7 +150,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
151150
* appropriate region accordingly
152151
*/
153152
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
154-
std::vector<AtomBlockId> atoms = atoms_lookup.atoms_in_cluster(blk_id);
153+
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(blk_id);
155154
int x = place_ctx.block_locs[blk_id].loc.x;
156155
int y = place_ctx.block_locs[blk_id].loc.y;
157156
int width = device_ctx.grid.width();
@@ -183,7 +182,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
183182

184183
VTR_ASSERT(got != region_atoms.end());
185184

186-
for (auto atom_id : atoms) {
185+
for (auto atom_id : *atoms) {
187186
got->second.push_back(atom_id);
188187
}
189188
}

vpr/src/pack/cluster_util.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,3 +3676,16 @@ t_pb* get_top_level_pb(t_pb* pb) {
36763676

36773677
return top_level_pb;
36783678
}
3679+
3680+
void init_clb_atoms_lookup(vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup) {
3681+
auto& atom_ctx = g_vpr_ctx.atom();
3682+
auto& cluster_ctx = g_vpr_ctx.clustering();
3683+
3684+
atoms_lookup.resize(cluster_ctx.clb_nlist.blocks().size());
3685+
3686+
for (auto atom_blk_id : atom_ctx.nlist.blocks()) {
3687+
ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id);
3688+
3689+
atoms_lookup[clb_index].insert(atom_blk_id);
3690+
}
3691+
}

vpr/src/pack/cluster_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,5 @@ bool cleanup_pb(t_pb* pb);
451451

452452
void alloc_and_load_pb_stats(t_pb* pb, const int feasible_block_array_size);
453453

454+
void init_clb_atoms_lookup(vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>>& atoms_lookup);
454455
#endif

vpr/src/pack/re_cluster_util.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ ClusterBlockId atom_to_cluster(const AtomBlockId& atom) {
5050

5151
std::unordered_set<AtomBlockId>* cluster_to_atoms(const ClusterBlockId& cluster) {
5252
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
53+
54+
//If the lookup is not built yet, build it first
55+
if (helper_ctx.atoms_lookup.empty())
56+
init_clb_atoms_lookup(helper_ctx.atoms_lookup);
57+
5358
return &(helper_ctx.atoms_lookup[cluster]);
5459
}
5560

vpr/src/place/place_constraints.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "globals.h"
1212
#include "place_constraints.h"
1313
#include "place_util.h"
14+
#include "re_cluster_util.h"
1415

1516
/*checks that each block's location is compatible with its floorplanning constraints if it has any*/
1617
int check_placement_floorplanning() {
@@ -228,18 +229,17 @@ bool cluster_floorplanning_legal(ClusterBlockId blk_id, const t_pl_loc& loc) {
228229
void load_cluster_constraints() {
229230
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
230231
auto& cluster_ctx = g_vpr_ctx.clustering();
231-
ClusterAtomsLookup atoms_lookup;
232232

233233
floorplanning_ctx.cluster_constraints.resize(cluster_ctx.clb_nlist.blocks().size());
234234

235235
for (auto cluster_id : cluster_ctx.clb_nlist.blocks()) {
236-
std::vector<AtomBlockId> atoms = atoms_lookup.atoms_in_cluster(cluster_id);
236+
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(cluster_id);
237237
PartitionRegion empty_pr;
238238
floorplanning_ctx.cluster_constraints[cluster_id] = empty_pr;
239239

240240
//if there are any constrainted atoms in the cluster,
241241
//we update the cluster's PartitionRegion
242-
for (auto atom : atoms) {
242+
for (auto atom : *atoms) {
243243
PartitionId partid = floorplanning_ctx.constraints.get_atom_partition(atom);
244244

245245
if (partid != PartitionId::INVALID()) {

0 commit comments

Comments
 (0)