@@ -144,10 +144,11 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
144
144
return (is_added);
145
145
}
146
146
147
- #if 0
147
+ #if 1
148
148
bool swap_two_molecules (t_pack_molecule* molecule_1,
149
149
t_pack_molecule* molecule_2,
150
150
bool during_packing,
151
+ int verbosity,
151
152
t_clustering_data& clustering_data) {
152
153
// define required contexts
153
154
auto & cluster_ctx = g_vpr_ctx.clustering ();
@@ -157,8 +158,7 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
157
158
// define local variables
158
159
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
159
160
160
- e_block_pack_status pack_1_result = BLK_STATUS_UNDEFINED;
161
- e_block_pack_status pack_2_result = BLK_STATUS_UNDEFINED;
161
+ bool mol_1_success, mol_2_success;
162
162
163
163
AtomBlockId root_1_atom_id = molecule_1->atom_block_ids [molecule_1->root ];
164
164
AtomBlockId root_2_atom_id = molecule_2->atom_block_ids [molecule_2->root ];
@@ -170,25 +170,17 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
170
170
ClusterBlockId clb_1 = atom_to_cluster (root_1_atom_id);
171
171
ClusterBlockId clb_2 = atom_to_cluster (root_2_atom_id);
172
172
173
- t_logical_block_type_ptr block_1_type = cluster_ctx.clb_nlist.block_type(clb_1);
174
- t_logical_block_type_ptr block_2_type = cluster_ctx.clb_nlist.block_type(clb_2);
173
+ // t_logical_block_type_ptr block_1_type = cluster_ctx.clb_nlist.block_type(clb_1);
174
+ // t_logical_block_type_ptr block_2_type = cluster_ctx.clb_nlist.block_type(clb_2);
175
175
176
- 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);
176
+ // 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);
177
177
178
178
// Check that the old and new clusters are of the same type
179
- if (cluster_ctx.clb_nlist.block_type(clb_1) != cluster_ctx.clb_nlist.block_type(clb_2)) {
180
- VTR_LOG("swapping atoms:(%zu, %zu) is aborted. The 2 cluster blocks are not of the same type",
181
- root_1_atom_id, root_2_atom_id);
182
- return false;
183
- }
184
-
185
- //Check that the old and new clusters are of the same mode
186
- if (cluster_ctx.clb_nlist.block_pb(clb_1)->mode != cluster_ctx.clb_nlist.block_pb(clb_2)->mode) {
187
- VTR_LOG("swapping atoms:(%zu, %zu) is aborted. The 2 cluster blocks are not of the same mode",
188
- root_1_atom_id, root_2_atom_id);
179
+ bool is_compitable = check_type_and_mode_compitability (clb_1, clb_2, verbosity);
180
+ if (!is_compitable)
189
181
return false ;
190
- }
191
182
183
+ #if 0
192
184
//Backup the original pb of the molecule before the move
193
185
std::vector<t_pb*> mol_1_pb_backup, mol_2_pb_backup;
194
186
for (int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
@@ -205,126 +197,70 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
205
197
mol_2_pb_backup.push_back(atom_pb_backup);
206
198
}
207
199
}
200
+ #endif
208
201
209
- //save the atoms of the 2 clusters
210
- std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
211
- std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms(clb_2);
202
+ t_lb_router_data* old_1_router_data = nullptr ;
203
+ t_lb_router_data* old_2_router_data = nullptr ;
212
204
213
- //re-load the intra-cluster routing
214
- t_lb_router_data* old_1_router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, clb_1, clb_1_atoms);
215
- t_lb_router_data* old_2_router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, clb_2, clb_2_atoms);
205
+ // remove the molecule from its current cluster
206
+ remove_mol_from_cluster (molecule_1, molecule_1_size, clb_1, old_1_router_data);
207
+ // remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, old_2_router_data);
208
+
209
+ // bool is_removed = is_cluster_legal(old_1_router_data);
210
+ // bool is_removed_2 = is_cluster_legal(old_2_router_data);
216
211
217
- //remove molecules from their old clusters
218
- for(int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
219
- if(molecule_1->atom_block_ids[ i_atom] ) {
220
- remove_atom_from_target(old_1_router_data, molecule_1->atom_block_ids[i_atom]);
212
+ // commit_mol_removal(molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
213
+ // commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
214
+ for ( int i_atom = 0 ; i_atom < molecule_1_size; i_atom++ ) {
215
+ if ( molecule_1->atom_block_ids [i_atom]) {
221
216
revert_place_atom_block (molecule_1->atom_block_ids [i_atom], old_1_router_data);
222
217
}
223
218
}
224
- for(int i_atom = 0; i_atom < molecule_2_size; i_atom++) {
225
- if(molecule_2->atom_block_ids[i_atom]) {
226
- remove_atom_from_target(old_2_router_data, molecule_2->atom_block_ids[i_atom]);
227
- revert_place_atom_block(molecule_2->atom_block_ids[i_atom], old_2_router_data);
228
- }
229
- }
230
219
231
- //add the molecules to their new clusters
232
- pack_2_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_1_type->index]),
233
- molecule_2,
234
- helper_ctx.primitives_list,
235
- cluster_ctx.clb_nlist.block_pb(clb_1),
236
- helper_ctx.num_models,
237
- helper_ctx.max_cluster_size,
238
- clb_1,
239
- E_DETAILED_ROUTE_FOR_EACH_ATOM,
240
- old_1_router_data,
241
- 0,
242
- helper_ctx.enable_pin_feasibility_filter,
243
- helper_ctx.feasible_block_array_size,
244
- target_ext_pin_util,
245
- temp_cluster_pr_1);
246
-
247
- pack_1_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_2_type->index]),
248
- molecule_1,
249
- helper_ctx.primitives_list,
250
- cluster_ctx.clb_nlist.block_pb(clb_2),
251
- helper_ctx.num_models,
252
- helper_ctx.max_cluster_size,
253
- clb_2,
254
- E_DETAILED_ROUTE_FOR_EACH_ATOM,
255
- old_2_router_data,
256
- 0,
257
- helper_ctx.enable_pin_feasibility_filter,
258
- helper_ctx.feasible_block_array_size,
259
- target_ext_pin_util,
260
- temp_cluster_pr_2);
220
+ cleanup_pb (cluster_ctx.clb_nlist .block_pb (clb_1));
221
+ bool is_removed = is_cluster_legal (old_1_router_data);
222
+ free_intra_lb_nets (clustering_data.intra_lb_routing [clb_1]);
223
+ clustering_data.intra_lb_routing [clb_1] = old_1_router_data->saved_lb_nets ;
224
+ old_1_router_data->saved_lb_nets = nullptr ;
261
225
226
+ // save the atoms of the 2 clusters
227
+ std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms (clb_1);
228
+ std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms (clb_2);
262
229
230
+ // Add the atom to the new cluster
231
+ mol_1_success = pack_mol_in_existing_cluster (molecule_1, clb_2, clb_2_atoms, during_packing, clustering_data);
232
+ // mol_2_success = pack_mol_in_existing_cluster(molecule_2, clb_1, clb_1_atoms, during_packing, clustering_data);
233
+ mol_2_success = true ;
263
234
264
235
// commit the move if succeeded or revert if failed
265
- if (pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED) {
266
- if(during_packing) {
267
- free_intra_lb_nets(clustering_data.intra_lb_routing[clb_1]);
268
- free_intra_lb_nets(clustering_data.intra_lb_routing[clb_2]);
269
-
270
- clustering_data.intra_lb_routing[clb_1] = old_1_router_data->saved_lb_nets;
271
- clustering_data.intra_lb_routing[clb_2] = old_2_router_data->saved_lb_nets;
272
- } else {
273
- cluster_ctx.clb_nlist.block_pb(clb_1)->pb_route.clear();
274
- cluster_ctx.clb_nlist.block_pb(clb_1)->pb_route = alloc_and_load_pb_route(old_1_router_data->saved_lb_nets, cluster_ctx.clb_nlist.block_pb(clb_1)->pb_graph_node);
275
- cluster_ctx.clb_nlist.block_pb(clb_2)->pb_route.clear();
276
- cluster_ctx.clb_nlist.block_pb(clb_2)->pb_route = alloc_and_load_pb_route(old_2_router_data->saved_lb_nets, cluster_ctx.clb_nlist.block_pb(clb_1)->pb_graph_node);
277
-
278
- }
279
-
236
+ if (mol_1_success && mol_2_success) {
280
237
commit_mol_move (clb_1, clb_2, during_packing, false );
281
- commit_mol_move(clb_2, clb_1, during_packing, false);
282
-
238
+ // commit_mol_move(clb_2, clb_1, during_packing, false);
239
+ VTR_LOGV (verbosity > 4 , " Molecules swap is performed successfully \n " );
283
240
} else {
284
- int atom_idx = 0;
285
- for(int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
286
- if(molecule_1->atom_block_ids[i_atom]) {
287
- atom_ctx.lookup.set_atom_clb(molecule_1->atom_block_ids[i_atom], clb_1);
288
- atom_ctx.lookup.set_atom_pb(molecule_1->atom_block_ids[i_atom], mol_1_pb_backup[atom_idx]);
289
- }
290
- }
291
-
292
- atom_idx = 0;
293
- for(int i_atom = 0; i_atom < molecule_2_size; i_atom++) {
294
- if(molecule_2->atom_block_ids[i_atom]) {
295
- atom_ctx.lookup.set_atom_clb(molecule_2->atom_block_ids[i_atom], clb_2);
296
- atom_ctx.lookup.set_atom_pb(molecule_2->atom_block_ids[i_atom], mol_2_pb_backup[atom_idx]);
297
- }
298
- }
241
+ revert_mol_move (clb_1, molecule_1, old_1_router_data, during_packing, clustering_data);
242
+ // revert_mol_move(clb_2, molecule_2, old_2_router_data, during_packing, clustering_data);
243
+ VTR_LOGV (verbosity > 4 , " Molecules swap failed\n " );
299
244
}
300
245
246
+
301
247
// If the move is done after packing not during it, some fixes need to be done on the clustered netlist
302
- if(pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED && !during_packing) {
248
+ if (mol_1_success && mol_2_success && !during_packing) {
303
249
fix_clustered_netlist (molecule_1, molecule_1_size, clb_1, clb_2);
304
- fix_clustered_netlist(molecule_2, molecule_2_size, clb_2, clb_1);
250
+ // fix_clustered_netlist(molecule_2, molecule_2_size, clb_2, clb_1);
305
251
}
306
252
307
253
// free memory
308
- old_1_router_data->saved_lb_nets = nullptr;
309
- old_2_router_data->saved_lb_nets = nullptr;
254
+ // old_1_router_data->saved_lb_nets = nullptr;
255
+ // old_2_router_data->saved_lb_nets = nullptr;
310
256
311
257
free_router_data (old_1_router_data);
312
- free_router_data(old_2_router_data);
258
+ // free_router_data(old_2_router_data);
313
259
314
260
old_1_router_data = nullptr ;
315
- old_2_router_data = nullptr;
316
-
317
- //free backup memory
318
- for(auto atom_pb_backup : mol_1_pb_backup) {
319
- cleanup_pb(atom_pb_backup);
320
- delete atom_pb_backup;
321
- }
322
- for(auto atom_pb_backup : mol_2_pb_backup) {
323
- cleanup_pb(atom_pb_backup);
324
- delete atom_pb_backup;
325
- }
261
+ // old_2_router_data = nullptr;
326
262
327
263
// return the move result
328
- return (pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED );
264
+ return (mol_1_success && mol_2_success );
329
265
}
330
266
#endif
0 commit comments