Skip to content

Commit 75746eb

Browse files
authored
Merge pull request #2397 from verilog-to-routing/reclustering-api-bug-fixes
Re-clustering API bug fixes
2 parents 28e7960 + b95d1e3 commit 75746eb

File tree

3 files changed

+96
-38
lines changed

3 files changed

+96
-38
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
7373
//Commit or revert the move
7474
if (is_created) {
7575
commit_mol_move(old_clb, new_clb, during_packing, true);
76+
// Update the clb-->atoms lookup table
77+
helper_ctx.atoms_lookup.resize(helper_ctx.total_clb_num);
78+
for (int i_atom = 0; i_atom < molecule_size; ++i_atom) {
79+
if (molecule->atom_block_ids[i_atom]) {
80+
helper_ctx.atoms_lookup[new_clb].insert(molecule->atom_block_ids[i_atom]);
81+
}
82+
}
83+
7684
VTR_LOGV(verbosity > 4, "Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
7785
} else {
7886
revert_mol_move(old_clb, molecule, old_router_data, during_packing, clustering_data);
@@ -130,7 +138,7 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
130138

131139
//Add the atom to the new cluster
132140
t_lb_router_data* new_router_data = nullptr;
133-
is_added = pack_mol_in_existing_cluster(molecule, molecule_size, new_clb, new_clb_atoms, during_packing, false, clustering_data, new_router_data);
141+
is_added = pack_mol_in_existing_cluster(molecule, molecule_size, new_clb, new_clb_atoms, during_packing, clustering_data, new_router_data);
134142

135143
//Commit or revert the move
136144
if (is_added) {
@@ -159,6 +167,8 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
159167
bool during_packing,
160168
int verbosity,
161169
t_clustering_data& clustering_data) {
170+
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
171+
162172
//define local variables
163173
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
164174

@@ -195,6 +205,11 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
195205
return false;
196206
}
197207

208+
t_pb* clb_pb_1 = cluster_ctx.clb_nlist.block_pb(clb_1);
209+
std::string clb_pb_1_name = (std::string)clb_pb_1->name;
210+
t_pb* clb_pb_2 = cluster_ctx.clb_nlist.block_pb(clb_2);
211+
std::string clb_pb_2_name = (std::string)clb_pb_2->name;
212+
198213
//remove the molecule from its current cluster
199214
remove_mol_from_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, false, old_1_router_data);
200215
commit_mol_removal(molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
@@ -203,31 +218,43 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
203218
commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
204219

205220
//Add the atom to the new cluster
206-
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_2, clb_2_atoms, during_packing, true, clustering_data, old_2_router_data);
221+
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_2, clb_2_atoms, during_packing, clustering_data, old_2_router_data);
207222
if (!mol_1_success) {
208-
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, during_packing, true, clustering_data, old_1_router_data);
209-
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, during_packing, true, clustering_data, old_2_router_data);
223+
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, during_packing, clustering_data, old_1_router_data);
224+
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, during_packing, clustering_data, old_2_router_data);
210225

211226
VTR_ASSERT(mol_1_success && mol_2_success);
212227
free_router_data(old_1_router_data);
213228
free_router_data(old_2_router_data);
214229
old_1_router_data = nullptr;
215230
old_2_router_data = nullptr;
231+
232+
free(clb_pb_1->name);
233+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
234+
free(clb_pb_2->name);
235+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
236+
216237
return false;
217238
}
218239

219-
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_1, clb_1_atoms, during_packing, true, clustering_data, old_1_router_data);
240+
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_1, clb_1_atoms, during_packing, clustering_data, old_1_router_data);
220241
if (!mol_2_success) {
221242
remove_mol_from_cluster(molecule_1, molecule_1_size, clb_2, clb_2_atoms, true, old_2_router_data);
222243
commit_mol_removal(molecule_1, molecule_1_size, clb_2, during_packing, old_2_router_data, clustering_data);
223-
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, during_packing, true, clustering_data, old_1_router_data);
224-
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, during_packing, true, clustering_data, old_2_router_data);
244+
mol_1_success = pack_mol_in_existing_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, during_packing, clustering_data, old_1_router_data);
245+
mol_2_success = pack_mol_in_existing_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, during_packing, clustering_data, old_2_router_data);
225246

226247
VTR_ASSERT(mol_1_success && mol_2_success);
227248
free_router_data(old_1_router_data);
228249
free_router_data(old_2_router_data);
229250
old_1_router_data = nullptr;
230251
old_2_router_data = nullptr;
252+
253+
free(clb_pb_1->name);
254+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
255+
free(clb_pb_2->name);
256+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
257+
231258
return false;
232259
}
233260

@@ -244,6 +271,12 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
244271
free_router_data(old_2_router_data);
245272
old_1_router_data = nullptr;
246273
old_2_router_data = nullptr;
274+
275+
free(clb_pb_1->name);
276+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
277+
free(clb_pb_2->name);
278+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
279+
247280
return true;
248281
}
249282
#endif

vpr/src/pack/re_cluster_util.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
#include "read_netlist.h"
1010

1111

12-
//The name suffix of the new block (if exists)
12+
// The name suffix of the new block (if exists)
13+
// This suffex is useful in preventing duplicate high-level cluster block names
1314
const char* name_suffix = "_m";
1415

1516
/******************* Static Functions ********************/
16-
//static void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId atom_blk, const AtomPortId atom_port, const t_pb_graph_pin* gpin);
1717
static void load_atom_index_for_pb_pin(t_pb_routes& pb_route, int ipin);
1818
static void load_internal_to_block_net_nums(const t_logical_block_type_ptr type, t_pb_routes& pb_route);
19-
//static bool count_children_pbs(const t_pb* pb);
2019
static void fix_atom_pin_mapping(const AtomBlockId blk);
2120

2221
static void fix_cluster_pins_after_moving(const ClusterBlockId clb_index);
@@ -41,6 +40,7 @@ static void update_cluster_pb_stats(const t_pack_molecule* molecule,
4140
int molecule_size,
4241
ClusterBlockId clb_index,
4342
bool is_added);
43+
4444
/***************** API functions ***********************/
4545
ClusterBlockId atom_to_cluster(const AtomBlockId& atom) {
4646
auto& atom_ctx = g_vpr_ctx.atom();
@@ -65,19 +65,18 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
6565
t_lb_router_data*& router_data) {
6666
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
6767

68-
//re-build router_data structure for this cluster
69-
if (!router_data_ready)
70-
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
71-
72-
//remove atom from router_data
7368
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
7469
if (molecule->atom_block_ids[i_atom]) {
75-
remove_atom_from_target(router_data, molecule->atom_block_ids[i_atom]);
7670
auto it = old_clb_atoms->find(molecule->atom_block_ids[i_atom]);
7771
if (it != old_clb_atoms->end())
7872
old_clb_atoms->erase(molecule->atom_block_ids[i_atom]);
7973
}
8074
}
75+
76+
//re-build router_data structure for this cluster
77+
if (!router_data_ready)
78+
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
79+
8180
update_cluster_pb_stats(molecule, molecule_size, old_clb, false);
8281
}
8382

@@ -87,7 +86,7 @@ void commit_mol_move(const ClusterBlockId& old_clb,
8786
bool new_clb_created) {
8887
auto& device_ctx = g_vpr_ctx.device();
8988

90-
//Place the new cluster if this function called during placement (after the initial placement is done)
89+
//place the new cluster if this function called during placement (after the initial placement is done)
9190
if (!during_packing && new_clb_created) {
9291
int imacro;
9392
g_vpr_ctx.mutable_placement().block_locs.resize(g_vpr_ctx.placement().block_locs.size() + 1);
@@ -100,6 +99,7 @@ void commit_mol_move(const ClusterBlockId& old_clb,
10099
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) {
101100
//build data structures used by intra-logic block router
102101
auto& cluster_ctx = g_vpr_ctx.clustering();
102+
auto& atom_ctx = g_vpr_ctx.atom();
103103
auto block_type = cluster_ctx.clb_nlist.block_type(clb_index);
104104
t_lb_router_data* router_data = alloc_and_load_router_data(&lb_type_rr_graphs[block_type->index], block_type);
105105

@@ -109,14 +109,19 @@ t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr
109109

110110
for (auto atom_id : *clb_atoms) {
111111
add_atom_as_target(router_data, atom_id);
112+
const t_pb* pb = atom_ctx.lookup.atom_pb(atom_id);
113+
while (pb) {
114+
set_reset_pb_modes(router_data, pb, true);
115+
pb = pb->parent_pb;
116+
}
112117
}
113118
return (router_data);
114119
}
115120

116121
bool start_new_cluster_for_mol(t_pack_molecule* molecule,
117122
const t_logical_block_type_ptr& type,
118-
const int mode,
119-
const int feasible_block_array_size,
123+
const int& mode,
124+
const int& feasible_block_array_size,
120125
bool enable_pin_feasibility_filter,
121126
ClusterBlockId clb_index,
122127
bool during_packing,
@@ -148,10 +153,11 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
148153

149154
e_block_pack_status pack_result = e_block_pack_status::BLK_STATUS_UNDEFINED;
150155
pb->mode = mode;
151-
reset_cluster_placement_stats(&(helper_ctx.cluster_placement_stats[type->index]));
156+
t_cluster_placement_stats* cluster_placement_stats = &(helper_ctx.cluster_placement_stats[type->index]);
157+
reset_cluster_placement_stats(cluster_placement_stats);
152158
set_mode_cluster_placement_stats(pb->pb_graph_node, mode);
153159

154-
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[type->index]),
160+
pack_result = try_pack_molecule(cluster_placement_stats,
155161
molecule,
156162
helper_ctx.primitives_list,
157163
pb,
@@ -178,6 +184,8 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
178184
pb->name = vtr::strdup(new_name.c_str());
179185
clb_index = cluster_ctx.clb_nlist.create_block(new_name.c_str(), pb, type);
180186
helper_ctx.total_clb_num++;
187+
int molecule_size = get_array_size_of_molecule(molecule);
188+
update_cluster_pb_stats(molecule, molecule_size, clb_index, true);
181189

182190
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
183191
if (during_packing) {
@@ -200,10 +208,9 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
200208

201209
bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
202210
int molecule_size,
203-
const ClusterBlockId new_clb,
211+
const ClusterBlockId& new_clb,
204212
std::unordered_set<AtomBlockId>* new_clb_atoms,
205213
bool during_packing,
206-
bool is_swap,
207214
t_clustering_data& clustering_data,
208215
t_lb_router_data*& router_data) {
209216
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
@@ -222,8 +229,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
222229
return false;
223230

224231
//re-build router_data structure for this cluster
225-
if (!is_swap)
226-
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
232+
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
227233

228234
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_type->index]),
229235
molecule,
@@ -262,11 +268,9 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
262268
update_cluster_pb_stats(molecule, molecule_size, new_clb, true);
263269
}
264270

265-
if (!is_swap) {
266-
//Free clustering router data
267-
free_router_data(router_data);
268-
router_data = nullptr;
269-
}
271+
//Free clustering router data
272+
free_router_data(router_data);
273+
router_data = nullptr;
270274

271275
return (pack_result == e_block_pack_status::BLK_PASSED);
272276
}
@@ -735,4 +739,4 @@ static void update_cluster_pb_stats(const t_pack_molecule* molecule,
735739
cur_pb = cur_pb->parent_pb;
736740
}
737741
}
738-
}
742+
}

vpr/src/pack/re_cluster_util.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
7979
*/
8080
bool start_new_cluster_for_mol(t_pack_molecule* molecule,
8181
const t_logical_block_type_ptr& type,
82-
const int mode,
83-
const int feasible_block_array_size,
82+
const int& mode,
83+
const int& feasible_block_array_size,
8484
bool enable_pin_feasibility_filter,
8585
ClusterBlockId clb_index,
8686
bool during_packing,
@@ -103,10 +103,9 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
103103
*/
104104
bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
105105
int molecule_size,
106-
const ClusterBlockId clb_index,
107-
std::unordered_set<AtomBlockId>* clb_atoms,
106+
const ClusterBlockId& new_clb,
107+
std::unordered_set<AtomBlockId>* new_clb_atoms,
108108
bool during_packing,
109-
bool is_swap,
110109
t_clustering_data& clustering_data,
111110
t_lb_router_data*& router_data);
112111

@@ -126,29 +125,51 @@ void fix_clustered_netlist(t_pack_molecule* molecule,
126125
/**
127126
* @brief A function that commits the molecule move if it is legal
128127
*
129-
* @during_packing: true if this function is called during packing, false if it is called during placement
130-
* @new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
128+
* @params during_packing: true if this function is called during packing, false if it is called during placement
129+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
131130
*/
132131
void commit_mol_move(const ClusterBlockId& old_clb,
133132
const ClusterBlockId& new_clb,
134133
bool during_packing,
135134
bool new_clb_created);
136135

136+
/**
137+
* @brief A function that reverts the molecule move if it is illegal
138+
*
139+
* @params during_packing: true if this function is called during packing, false if it is called during placement
140+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
141+
* @params
142+
*/
137143
void revert_mol_move(const ClusterBlockId& old_clb,
138144
t_pack_molecule* molecule,
139145
t_lb_router_data*& old_router_data,
140146
bool during_packing,
141147
t_clustering_data& clustering_data);
142148

149+
/**
150+
*
151+
* @brief A function that checks the legality of a cluster by running the intra-cluster routing
152+
*/
143153
bool is_cluster_legal(t_lb_router_data*& router_data);
144154

155+
/**
156+
* @brief A function that commits the molecule removal if it is legal
157+
*
158+
* @params during_packing: true if this function is called during packing, false if it is called during placement
159+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
160+
*/
145161
void commit_mol_removal(const t_pack_molecule* molecule,
146162
const int& molecule_size,
147163
const ClusterBlockId& old_clb,
148164
bool during_packing,
149165
t_lb_router_data*& router_data,
150166
t_clustering_data& clustering_data);
151167

168+
/**
169+
*
170+
* @brief A function that check that two clusters are of the same type and in the same mode of operation
171+
*
172+
*/
152173
bool check_type_and_mode_compitability(const ClusterBlockId& old_clb,
153174
const ClusterBlockId& new_clb,
154175
int verbosity);

0 commit comments

Comments
 (0)