Skip to content

Commit 8a32b61

Browse files
cluster_to_atoms() returns a reference
1 parent 6d94b75 commit 8a32b61

File tree

7 files changed

+72
-48
lines changed

7 files changed

+72
-48
lines changed

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
8080
part.set_part_region(pr);
8181
constraints.mutable_place_constraints().add_partition(part);
8282

83-
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(blk_id);
83+
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
8484

85-
for (auto atom_id : *atoms) {
85+
for (AtomBlockId atom_id : atoms) {
8686
constraints.mutable_place_constraints().add_constrained_atom(atom_id, partid);
8787
}
8888
part_id++;
@@ -156,7 +156,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
156156
* appropriate region accordingly
157157
*/
158158
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
159-
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(blk_id);
159+
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
160160
int x = place_ctx.block_locs[blk_id].loc.x;
161161
int y = place_ctx.block_locs[blk_id].loc.y;
162162
int width = device_ctx.grid.width();
@@ -189,7 +189,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
189189

190190
VTR_ASSERT(got != region_atoms.end());
191191

192-
for (auto atom_id : *atoms) {
192+
for (AtomBlockId atom_id : atoms) {
193193
got->second.push_back(atom_id);
194194
}
195195
}

vpr/src/pack/re_cluster.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3737
}
3838

3939
//remove the molecule from its current cluster
40-
std::unordered_set<AtomBlockId>* old_clb_atoms = cluster_to_atoms(old_clb);
41-
if (old_clb_atoms->size() == 1) {
40+
std::unordered_set<AtomBlockId>& old_clb_atoms = cluster_to_mutable_atoms(old_clb);
41+
if (old_clb_atoms.size() == 1) {
4242
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. This is the last atom in its cluster.\n");
4343
return false;
4444
}
@@ -109,7 +109,7 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
109109
AtomBlockId root_atom_id = molecule->atom_block_ids[molecule->root];
110110
int molecule_size = get_array_size_of_molecule(molecule);
111111
t_lb_router_data* old_router_data = nullptr;
112-
std::unordered_set<AtomBlockId>* new_clb_atoms = cluster_to_atoms(new_clb);
112+
std::unordered_set<AtomBlockId>& new_clb_atoms = cluster_to_mutable_atoms(new_clb);
113113
ClusterBlockId old_clb = atom_to_cluster(root_atom_id);
114114

115115
//check old and new clusters compitability
@@ -118,8 +118,8 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
118118
return false;
119119

120120
//remove the molecule from its current cluster
121-
std::unordered_set<AtomBlockId>* old_clb_atoms = cluster_to_atoms(old_clb);
122-
if (old_clb_atoms->size() == 1) {
121+
std::unordered_set<AtomBlockId>& old_clb_atoms = cluster_to_mutable_atoms(old_clb);
122+
if (old_clb_atoms.size() == 1) {
123123
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. This is the last atom in its cluster.\n");
124124
return false;
125125
}
@@ -197,11 +197,13 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
197197
t_lb_router_data* old_2_router_data = nullptr;
198198

199199
//save the atoms of the 2 clusters
200-
std::unordered_set<AtomBlockId>* clb_1_atoms = cluster_to_atoms(clb_1);
201-
std::unordered_set<AtomBlockId>* clb_2_atoms = cluster_to_atoms(clb_2);
200+
std::unordered_set<AtomBlockId>& clb_1_atoms = cluster_to_mutable_atoms(clb_1);
201+
std::unordered_set<AtomBlockId>& clb_2_atoms = cluster_to_mutable_atoms(clb_2);
202202

203-
if (clb_1_atoms->size() == 1 || clb_2_atoms->size() == 1) {
204-
VTR_LOGV(verbosity > 4, "Atom: %zu, %zu swap failed. This is the last atom in its cluster.\n", molecule_1->atom_block_ids[molecule_1->root], molecule_2->atom_block_ids[molecule_2->root]);
203+
if (clb_1_atoms.size() == 1 || clb_2_atoms.size() == 1) {
204+
VTR_LOGV(verbosity > 4, "Atom: %zu, %zu swap failed. This is the last atom in its cluster.\n",
205+
molecule_1->atom_block_ids[molecule_1->root],
206+
molecule_2->atom_block_ids[molecule_2->root]);
205207
return false;
206208
}
207209

vpr/src/pack/re_cluster_util.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void fix_cluster_net_after_moving(const t_pack_molecule* molecule,
3434
const ClusterBlockId& new_clb);
3535

3636
static void rebuild_cluster_placement_stats(const ClusterBlockId& clb_index,
37-
const std::unordered_set<AtomBlockId>* clb_atoms);
37+
const std::unordered_set<AtomBlockId>& clb_atoms);
3838

3939
static void update_cluster_pb_stats(const t_pack_molecule* molecule,
4040
int molecule_size,
@@ -47,29 +47,25 @@ ClusterBlockId atom_to_cluster(const AtomBlockId& atom) {
4747
return (atom_ctx.lookup.atom_clb(atom));
4848
}
4949

50-
std::unordered_set<AtomBlockId>* cluster_to_atoms(const ClusterBlockId& cluster) {
51-
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
50+
const std::unordered_set<AtomBlockId>& cluster_to_atoms(ClusterBlockId cluster) {
51+
const auto& atoms = cluster_to_mutable_atoms(cluster);
5252

53-
//If the lookup is not built yet, build it first
54-
if (helper_ctx.atoms_lookup.empty())
55-
init_clb_atoms_lookup(helper_ctx.atoms_lookup);
56-
57-
return &(helper_ctx.atoms_lookup[cluster]);
53+
return atoms;
5854
}
5955

6056
void remove_mol_from_cluster(const t_pack_molecule* molecule,
6157
int molecule_size,
6258
ClusterBlockId& old_clb,
63-
std::unordered_set<AtomBlockId>* old_clb_atoms,
59+
std::unordered_set<AtomBlockId>& old_clb_atoms,
6460
bool router_data_ready,
6561
t_lb_router_data*& router_data) {
6662
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
6763

6864
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
6965
if (molecule->atom_block_ids[i_atom]) {
70-
auto it = old_clb_atoms->find(molecule->atom_block_ids[i_atom]);
71-
if (it != old_clb_atoms->end())
72-
old_clb_atoms->erase(molecule->atom_block_ids[i_atom]);
66+
auto it = old_clb_atoms.find(molecule->atom_block_ids[i_atom]);
67+
if (it != old_clb_atoms.end())
68+
old_clb_atoms.erase(molecule->atom_block_ids[i_atom]);
7369
}
7470
}
7571

@@ -96,18 +92,16 @@ void commit_mol_move(const ClusterBlockId& old_clb,
9692
}
9793
}
9894

99-
t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr_graphs, const ClusterBlockId& clb_index, const std::unordered_set<AtomBlockId>* clb_atoms) {
95+
t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
96+
const ClusterBlockId& clb_index,
97+
const std::unordered_set<AtomBlockId>& clb_atoms) {
10098
//build data structures used by intra-logic block router
10199
auto& cluster_ctx = g_vpr_ctx.clustering();
102100
auto& atom_ctx = g_vpr_ctx.atom();
103101
auto block_type = cluster_ctx.clb_nlist.block_type(clb_index);
104102
t_lb_router_data* router_data = alloc_and_load_router_data(&lb_type_rr_graphs[block_type->index], block_type);
105103

106-
//iterate over atoms of the current cluster and add them to router data
107-
if (!clb_atoms)
108-
return router_data;
109-
110-
for (auto atom_id : *clb_atoms) {
104+
for (auto atom_id : clb_atoms) {
111105
add_atom_as_target(router_data, atom_id);
112106
const t_pb* pb = atom_ctx.lookup.atom_pb(atom_id);
113107
while (pb) {
@@ -209,7 +203,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
209203
bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
210204
int molecule_size,
211205
const ClusterBlockId& new_clb,
212-
std::unordered_set<AtomBlockId>* new_clb_atoms,
206+
std::unordered_set<AtomBlockId>& new_clb_atoms,
213207
bool during_packing,
214208
t_clustering_data& clustering_data,
215209
t_lb_router_data*& router_data) {
@@ -262,7 +256,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
262256

263257
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
264258
if (molecule->atom_block_ids[i_atom]) {
265-
new_clb_atoms->insert(molecule->atom_block_ids[i_atom]);
259+
new_clb_atoms.insert(molecule->atom_block_ids[i_atom]);
266260
}
267261
}
268262
update_cluster_pb_stats(molecule, molecule_size, new_clb, true);
@@ -364,10 +358,10 @@ static void fix_cluster_net_after_moving(const t_pack_molecule* molecule,
364358
fix_cluster_pins_after_moving(old_clb);
365359
fix_cluster_pins_after_moving(new_clb);
366360

367-
for (auto& atom_blk : *(cluster_to_atoms(old_clb)))
361+
for (AtomBlockId atom_blk : cluster_to_atoms(old_clb))
368362
fix_atom_pin_mapping(atom_blk);
369363

370-
for (auto& atom_blk : *(cluster_to_atoms(new_clb)))
364+
for (AtomBlockId atom_blk : cluster_to_atoms(new_clb))
371365
fix_atom_pin_mapping(atom_blk);
372366

373367
cluster_ctx.clb_nlist.remove_and_compress();
@@ -641,7 +635,7 @@ static bool count_children_pbs(const t_pb* pb) {
641635
#endif
642636

643637
static void rebuild_cluster_placement_stats(const ClusterBlockId& clb_index,
644-
const std::unordered_set<AtomBlockId>* clb_atoms) {
638+
const std::unordered_set<AtomBlockId>& clb_atoms) {
645639
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
646640
auto& cluster_ctx = g_vpr_ctx.clustering();
647641
auto& atom_ctx = g_vpr_ctx.atom();
@@ -650,7 +644,7 @@ static void rebuild_cluster_placement_stats(const ClusterBlockId& clb_index,
650644
reset_cluster_placement_stats(cluster_placement_stats);
651645
set_mode_cluster_placement_stats(cluster_ctx.clb_nlist.block_pb(clb_index)->pb_graph_node, cluster_ctx.clb_nlist.block_pb(clb_index)->mode);
652646

653-
for (auto& atom : *clb_atoms) {
647+
for (AtomBlockId atom : clb_atoms) {
654648
const t_pb* atom_pb = atom_ctx.lookup.atom_pb(atom);
655649
commit_primitive(cluster_placement_stats, atom_pb->pb_graph_node);
656650
}
@@ -744,3 +738,13 @@ static void update_cluster_pb_stats(const t_pack_molecule* molecule,
744738
}
745739
}
746740
}
741+
742+
std::unordered_set<AtomBlockId>& cluster_to_mutable_atoms(ClusterBlockId cluster) {
743+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
744+
745+
//If the lookup is not built yet, build it first
746+
if (helper_ctx.atoms_lookup.empty())
747+
init_clb_atoms_lookup(helper_ctx.atoms_lookup);
748+
749+
return helper_ctx.atoms_lookup[cluster];
750+
}

vpr/src/pack/re_cluster_util.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,26 @@ ClusterBlockId atom_to_cluster(const AtomBlockId& atom);
2727

2828
/**
2929
* @brief A function that return a list of atoms in a cluster
30-
* @note This finction can be called only after cluster/packing is done or
31-
* the clustered netlist is created
30+
* @note This function can be called only after cluster/packing is done or
31+
* the clustered netlist is created.
32+
* @return Atoms in the given cluster. The returned set is immutable.
3233
*/
34+
const std::unordered_set<AtomBlockId>& cluster_to_atoms(ClusterBlockId cluster);
35+
36+
/**
37+
* @brief A function that return a list of atoms in a cluster
38+
* @note This function can be called only after cluster/packing is done or
39+
* the clustered netlist is created.
40+
* @return Atoms in the given cluster. The returned set is mutable.
41+
*/
42+
std::unordered_set<AtomBlockId>& cluster_to_mutable_atoms(ClusterBlockId cluster);
3343

34-
std::unordered_set<AtomBlockId>* cluster_to_atoms(const ClusterBlockId& cluster);
3544
/**
3645
* @brief A function that loads the intra-cluster router data of one cluster
3746
*/
3847
t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
3948
const ClusterBlockId& clb_index,
40-
const std::unordered_set<AtomBlockId>* clb_atoms);
49+
const std::unordered_set<AtomBlockId>& clb_atoms);
4150

4251
/**
4352
* @brief A function that removes a molecule from a cluster and checks legality of
@@ -58,7 +67,7 @@ t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr
5867
void remove_mol_from_cluster(const t_pack_molecule* molecule,
5968
int molecule_size,
6069
ClusterBlockId& old_clb,
61-
std::unordered_set<AtomBlockId>* old_clb_atoms,
70+
std::unordered_set<AtomBlockId>& old_clb_atoms,
6271
bool router_data_ready,
6372
t_lb_router_data*& router_data);
6473

@@ -105,7 +114,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
105114
bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
106115
int molecule_size,
107116
const ClusterBlockId& new_clb,
108-
std::unordered_set<AtomBlockId>* new_clb_atoms,
117+
std::unordered_set<AtomBlockId>& new_clb_atoms,
109118
bool during_packing,
110119
t_clustering_data& clustering_data,
111120
t_lb_router_data*& router_data);

vpr/src/place/place_constraints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ void load_cluster_constraints() {
245245
floorplanning_ctx.cluster_constraints.resize(cluster_ctx.clb_nlist.blocks().size());
246246

247247
for (auto cluster_id : cluster_ctx.clb_nlist.blocks()) {
248-
std::unordered_set<AtomBlockId>* atoms = cluster_to_atoms(cluster_id);
248+
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(cluster_id);
249249
PartitionRegion empty_pr;
250250
floorplanning_ctx.cluster_constraints[cluster_id] = empty_pr;
251251

252252
//if there are any constrained atoms in the cluster,
253253
//we update the cluster's PartitionRegion
254-
for (auto atom : *atoms) {
254+
for (AtomBlockId atom : atoms) {
255255
PartitionId partid = floorplanning_ctx.constraints.get_atom_partition(atom);
256256

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

vpr/src/place/place_constraints.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ inline bool floorplan_legal(const t_pl_blocks_to_be_moved& blocks_affected) {
7171
for (int i = 0; i < blocks_affected.num_moved_blocks; i++) {
7272
floorplan_legal = cluster_floorplanning_legal(blocks_affected.moved_blocks[i].block_num, blocks_affected.moved_blocks[i].new_loc);
7373
if (!floorplan_legal) {
74-
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug, "\tMove aborted for block %zu, location tried was x: %d, y: %d, subtile: %d \n", size_t(blocks_affected.moved_blocks[i].block_num), blocks_affected.moved_blocks[i].new_loc.x, blocks_affected.moved_blocks[i].new_loc.y, blocks_affected.moved_blocks[i].new_loc.sub_tile);
74+
VTR_LOGV_DEBUG(g_vpr_ctx.placement().f_placer_debug,
75+
"\tMove aborted for block %zu, location tried was x: %d, y: %d, subtile: %d \n",
76+
size_t(blocks_affected.moved_blocks[i].block_num),
77+
blocks_affected.moved_blocks[i].new_loc.x,
78+
blocks_affected.moved_blocks[i].new_loc.y,
79+
blocks_affected.moved_blocks[i].new_loc.sub_tile);
7580
return false;
7681
}
7782
}
@@ -96,6 +101,10 @@ void load_cluster_constraints();
96101
*/
97102
void mark_fixed_blocks();
98103

104+
/**
105+
* @brief Converts the floorplanning constraints from grid location to
106+
* compressed grid locations and store them in FloorplanningContext.
107+
*/
99108
void alloc_and_load_compressed_cluster_constraints();
100109

101110
/*

vpr/src/util/vpr_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,8 +1372,8 @@ std::vector<int> get_cluster_internal_class_pairs(const AtomLookup& atom_lookup,
13721372
std::tie(physical_tile, sub_tile, rel_cap, logical_block) = get_cluster_blk_physical_spec(cluster_block_id);
13731373
class_num_vec.reserve(physical_tile->primitive_class_inf.size());
13741374

1375-
const auto& cluster_atoms = *cluster_to_atoms(cluster_block_id);
1376-
for (auto atom_blk_id : cluster_atoms) {
1375+
const auto& cluster_atoms = cluster_to_atoms(cluster_block_id);
1376+
for (AtomBlockId atom_blk_id : cluster_atoms) {
13771377
auto atom_pb_graph_node = atom_lookup.atom_pb_graph_node(atom_blk_id);
13781378
auto class_range = get_pb_graph_node_class_physical_range(physical_tile,
13791379
sub_tile,

0 commit comments

Comments
 (0)