@@ -37,6 +37,10 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
37
37
38
38
// remove the molecule from its current cluster
39
39
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms (old_clb);
40
+ if (old_clb_atoms.size () == 1 ) {
41
+ VTR_LOGV (verbosity > 4 , " Atom: %zu move failed. This is the last atom in its cluster.\n " );
42
+ return false ;
43
+ }
40
44
remove_mol_from_cluster (molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
41
45
42
46
// check old cluster legality after removing the molecule
@@ -90,9 +94,6 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
90
94
bool during_packing,
91
95
int verbosity,
92
96
t_clustering_data& clustering_data) {
93
- // define required contexts
94
- auto & cluster_ctx = g_vpr_ctx.clustering ();
95
-
96
97
// define local variables
97
98
bool is_removed, is_added;
98
99
AtomBlockId root_atom_id = molecule->atom_block_ids [molecule->root ];
@@ -108,6 +109,10 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
108
109
109
110
// remove the molecule from its current cluster
110
111
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms (old_clb);
112
+ if (old_clb_atoms.size () == 1 ) {
113
+ VTR_LOGV (verbosity > 4 , " Atom: %zu move failed. This is the last atom in its cluster.\n " );
114
+ return false ;
115
+ }
111
116
remove_mol_from_cluster (molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
112
117
113
118
// check old cluster legality after removing the molecule
@@ -122,7 +127,8 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
122
127
}
123
128
124
129
// Add the atom to the new cluster
125
- is_added = pack_mol_in_existing_cluster (molecule, new_clb, new_clb_atoms, during_packing, clustering_data);
130
+ t_lb_router_data* new_router_data = nullptr ;
131
+ is_added = pack_mol_in_existing_cluster (molecule, new_clb, new_clb_atoms, during_packing, clustering_data, false , new_router_data);
126
132
127
133
// Commit or revert the move
128
134
if (is_added) {
@@ -151,11 +157,6 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
151
157
bool during_packing,
152
158
int verbosity,
153
159
t_clustering_data& clustering_data) {
154
- // define required contexts
155
- auto & cluster_ctx = g_vpr_ctx.clustering ();
156
- auto & atom_ctx = g_vpr_ctx.mutable_atom ();
157
- auto & helper_ctx = g_vpr_ctx.mutable_cl_helper ();
158
-
159
160
// define local variables
160
161
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
161
162
@@ -171,128 +172,52 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
171
172
ClusterBlockId clb_1 = atom_to_cluster (root_1_atom_id);
172
173
ClusterBlockId clb_2 = atom_to_cluster (root_2_atom_id);
173
174
174
- // t_logical_block_type_ptr block_1_type = cluster_ctx.clb_nlist.block_type(clb_1);
175
- // t_logical_block_type_ptr block_2_type = cluster_ctx.clb_nlist.block_type(clb_2);
176
-
177
- // t_ext_pin_util target_ext_pin_util = helper_ctx.target_external_pin_util.get_pin_util(cluster_ctx.clb_nlist.block_type(clb_1)->name);
178
-
179
175
// Check that the old and new clusters are of the same type
180
176
bool is_compitable = check_type_and_mode_compitability (clb_1, clb_2, verbosity);
181
177
if (!is_compitable)
182
178
return false ;
183
179
184
- #if 0
185
- //Backup the original pb of the molecule before the move
186
- std::vector<t_pb*> mol_1_pb_backup, mol_2_pb_backup;
187
- for (int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
188
- if (molecule_1->atom_block_ids[i_atom]) {
189
- t_pb* atom_pb_backup = new t_pb;
190
- atom_pb_backup->pb_deep_copy(atom_ctx.lookup.atom_pb(molecule_1->atom_block_ids[i_atom]));
191
- mol_1_pb_backup.push_back(atom_pb_backup);
192
- }
193
- }
194
- for (int i_atom = 0; i_atom < molecule_2_size; i_atom++) {
195
- if (molecule_2->atom_block_ids[i_atom]) {
196
- t_pb* atom_pb_backup = new t_pb;
197
- atom_pb_backup->pb_deep_copy(atom_ctx.lookup.atom_pb(molecule_2->atom_block_ids[i_atom]));
198
- mol_2_pb_backup.push_back(atom_pb_backup);
199
- }
200
- }
201
- #endif
202
-
203
180
t_lb_router_data* old_1_router_data = nullptr ;
204
181
t_lb_router_data* old_2_router_data = nullptr ;
205
182
206
183
// save the atoms of the 2 clusters
207
184
std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms (clb_1);
208
185
std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms (clb_2);
209
186
187
+ if (clb_1_atoms.size () == 1 || clb_2_atoms.size () == 1 ) {
188
+ 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 ]);
189
+ return false ;
190
+ }
191
+
210
192
// remove the molecule from its current cluster
211
193
remove_mol_from_cluster (molecule_1, molecule_1_size, clb_1, clb_1_atoms, old_1_router_data);
212
- // remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, old_2_router_data);
213
-
214
- // bool is_removed = is_cluster_legal(old_1_router_data);
215
- // bool is_removed_2 = is_cluster_legal(old_2_router_data);
216
-
217
194
commit_mol_removal (molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
218
- #if 0
219
- for (int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
220
- if (molecule_1->atom_block_ids[i_atom]) {
221
- revert_place_atom_block(molecule_1->atom_block_ids[i_atom], old_1_router_data);
222
- }
223
- }
224
- cleanup_pb(cluster_ctx.clb_nlist.block_pb(clb_1));
225
- #endif
226
- #if 0
227
- for (int i_atom = 0; i_atom < molecule_2_size; i_atom++) {
228
- if (molecule_2->atom_block_ids[i_atom]) {
229
- revert_place_atom_block(molecule_2->atom_block_ids[i_atom], old_2_router_data);
230
- }
231
- }
232
- cleanup_pb(cluster_ctx.clb_nlist.block_pb(clb_2));
233
- #endif
234
-
235
- // bool is_removed = is_cluster_legal(old_1_router_data);
236
- // bool is_removed_2 = is_cluster_legal(old_2_router_data);
237
195
238
196
remove_mol_from_cluster (molecule_2, molecule_2_size, clb_2, clb_2_atoms, old_2_router_data);
239
197
commit_mol_removal (molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
240
198
241
199
242
200
// Add the atom to the new cluster
243
- mol_1_success = pack_mol_in_existing_cluster (molecule_1, clb_2, clb_2_atoms, during_packing, clustering_data);
201
+ mol_1_success = pack_mol_in_existing_cluster (molecule_1, clb_2, clb_2_atoms, during_packing, clustering_data, true , old_2_router_data);
202
+ mol_2_success = pack_mol_in_existing_cluster (molecule_2, clb_1, clb_1_atoms, during_packing, clustering_data, true , old_1_router_data);
244
203
245
- #if 1
246
- /*
247
- remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, old_2_router_data);
248
- bool is_removed_2 = is_cluster_legal(old_2_router_data);
249
- std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
250
- commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
251
- */
252
- mol_2_success = pack_mol_in_existing_cluster (molecule_2, clb_1, clb_1_atoms, during_packing, clustering_data);
253
- #endif
254
- mol_2_success = true ;
255
-
256
- #if 0
257
- free_intra_lb_nets(clustering_data.intra_lb_routing[clb_1]);
258
- clustering_data.intra_lb_routing[clb_1] = old_1_router_data->saved_lb_nets;
259
- old_1_router_data->saved_lb_nets = nullptr;
260
- #endif
261
204
262
205
// commit the move if succeeded or revert if failed
263
206
if (mol_1_success && mol_2_success) {
264
- // commit_mol_move(clb_1, clb_2, during_packing, false);
265
- // commit_mol_move(clb_2, clb_1, during_packing, false);
266
207
VTR_LOGV (verbosity > 4 , " Molecules swap is performed successfully\n " );
267
208
} else {
268
- // revert_mol_move(clb_1, molecule_1, old_1_router_data, during_packing, clustering_data);
269
- // revert_mol_move(clb_2, molecule_2, old_2_router_data, during_packing, clustering_data);
209
+ revert_mol_move (clb_1, molecule_1, old_1_router_data, during_packing, clustering_data);
210
+ revert_mol_move (clb_2, molecule_2, old_2_router_data, during_packing, clustering_data);
270
211
VTR_LOGV (verbosity > 4 , " Molecules swap failed\n " );
271
212
}
272
213
273
214
274
215
// If the move is done after packing not during it, some fixes need to be done on the clustered netlist
275
216
if (mol_1_success && mol_2_success && !during_packing) {
276
- // fix_clustered_netlist(molecule_1, molecule_1_size, clb_1, clb_2);
277
- // fix_clustered_netlist(molecule_2, molecule_2_size, clb_2, clb_1);
217
+ fix_clustered_netlist (molecule_1, molecule_1_size, clb_1, clb_2);
218
+ fix_clustered_netlist (molecule_2, molecule_2_size, clb_2, clb_1);
278
219
}
279
220
280
- // free memory
281
- old_1_router_data->saved_lb_nets = nullptr ;
282
- old_2_router_data->saved_lb_nets = nullptr ;
283
-
284
- free_router_data (old_1_router_data);
285
- free_router_data (old_2_router_data);
286
- // remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, old_2_router_data);
287
- // bool is_removed_2 = is_cluster_legal(old_2_router_data);
288
- // commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
289
- // std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
290
- // mol_2_success = pack_mol_in_existing_cluster(molecule_2, clb_1, clb_1_atoms, during_packing, clustering_data);
291
-
292
-
293
- old_1_router_data = nullptr ;
294
- old_2_router_data = nullptr ;
295
-
296
221
// return the move result
297
222
return (mol_1_success && mol_2_success);
298
223
}
0 commit comments