Skip to content

Commit 34e5661

Browse files
author
MohamedElgammal
committed
Swapping function is now working (need more cleaning)
1 parent 0d44ae5 commit 34e5661

File tree

3 files changed

+62
-26
lines changed

3 files changed

+62
-26
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
1414

1515
bool is_removed, is_created;
1616
ClusterBlockId old_clb = atom_to_cluster(molecule->atom_block_ids[molecule->root]);
17-
;
1817
int molecule_size = get_array_size_of_molecule(molecule);
1918

2019
PartitionRegion temp_cluster_pr;
@@ -37,7 +36,8 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3736
}
3837

3938
//remove the molecule from its current cluster
40-
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data);
39+
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
40+
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
4141

4242
//check old cluster legality after removing the molecule
4343
is_removed = is_cluster_legal(old_router_data);
@@ -107,7 +107,8 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
107107
return false;
108108

109109
//remove the molecule from its current cluster
110-
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data);
110+
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
111+
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
111112

112113
//check old cluster legality after removing the molecule
113114
is_removed = is_cluster_legal(old_router_data);
@@ -202,63 +203,95 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
202203
t_lb_router_data* old_1_router_data = nullptr;
203204
t_lb_router_data* old_2_router_data = nullptr;
204205

206+
//save the atoms of the 2 clusters
207+
std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
208+
std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms(clb_2);
209+
205210
//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);
211+
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);
208213

209214
//bool is_removed = is_cluster_legal(old_1_router_data);
210215
//bool is_removed_2 = is_cluster_legal(old_2_router_data);
211216

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);
217+
commit_mol_removal(molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
218+
#if 0
214219
for (int i_atom = 0; i_atom < molecule_1_size; i_atom++) {
215220
if (molecule_1->atom_block_ids[i_atom]) {
216221
revert_place_atom_block(molecule_1->atom_block_ids[i_atom], old_1_router_data);
217222
}
218223
}
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+
238+
remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, old_2_router_data);
239+
commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
240+
219241

220-
cleanup_pb(cluster_ctx.clb_nlist.block_pb(clb_1));
221-
bool is_removed = is_cluster_legal(old_1_router_data);
242+
//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);
244+
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
222257
free_intra_lb_nets(clustering_data.intra_lb_routing[clb_1]);
223258
clustering_data.intra_lb_routing[clb_1] = old_1_router_data->saved_lb_nets;
224259
old_1_router_data->saved_lb_nets = nullptr;
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);
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;
260+
#endif
234261

235262
//commit the move if succeeded or revert if failed
236263
if (mol_1_success && mol_2_success) {
237-
commit_mol_move(clb_1, clb_2, during_packing, false);
264+
//commit_mol_move(clb_1, clb_2, during_packing, false);
238265
//commit_mol_move(clb_2, clb_1, during_packing, false);
239266
VTR_LOGV(verbosity > 4, "Molecules swap is performed successfully\n");
240267
} else {
241-
revert_mol_move(clb_1, molecule_1, old_1_router_data, during_packing, clustering_data);
268+
//revert_mol_move(clb_1, molecule_1, old_1_router_data, during_packing, clustering_data);
242269
//revert_mol_move(clb_2, molecule_2, old_2_router_data, during_packing, clustering_data);
243270
VTR_LOGV(verbosity > 4, "Molecules swap failed\n");
244271
}
245272

246273

247274
//If the move is done after packing not during it, some fixes need to be done on the clustered netlist
248275
if (mol_1_success && mol_2_success && !during_packing) {
249-
fix_clustered_netlist(molecule_1, molecule_1_size, clb_1, clb_2);
276+
//fix_clustered_netlist(molecule_1, molecule_1_size, clb_1, clb_2);
250277
//fix_clustered_netlist(molecule_2, molecule_2_size, clb_2, clb_1);
251278
}
252279

253280
//free memory
254-
//old_1_router_data->saved_lb_nets = nullptr;
255-
//old_2_router_data->saved_lb_nets = nullptr;
281+
old_1_router_data->saved_lb_nets = nullptr;
282+
old_2_router_data->saved_lb_nets = nullptr;
256283

257284
free_router_data(old_1_router_data);
258-
//free_router_data(old_2_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+
259292

260293
old_1_router_data = nullptr;
261-
//old_2_router_data = nullptr;
294+
old_2_router_data = nullptr;
262295

263296
//return the move result
264297
return (mol_1_success && mol_2_success);

vpr/src/pack/re_cluster_util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ std::vector<AtomBlockId> cluster_to_atoms(const ClusterBlockId& cluster) {
5454
void remove_mol_from_cluster(const t_pack_molecule* molecule,
5555
int molecule_size,
5656
ClusterBlockId& old_clb,
57+
std::vector<AtomBlockId>& old_clb_atoms,
5758
t_lb_router_data*& router_data) {
5859
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
5960

6061
//Determine the cluster ID
6162
old_clb = atom_to_cluster(molecule->atom_block_ids[molecule->root]);
62-
std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
63+
//std::vector<AtomBlockId> old_clb_atoms = cluster_to_atoms(old_clb);
6364

6465
//re-build router_data structure for this cluster
6566
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
@@ -68,6 +69,7 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
6869
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
6970
if (molecule->atom_block_ids[i_atom]) {
7071
remove_atom_from_target(router_data, molecule->atom_block_ids[i_atom]);
72+
old_clb_atoms.erase(std::remove(old_clb_atoms.begin(), old_clb_atoms.end(), molecule->atom_block_ids[i_atom]));
7173
}
7274
}
7375
}

vpr/src/pack/re_cluster_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr
5050
void remove_mol_from_cluster(const t_pack_molecule* molecule,
5151
int molecule_size,
5252
ClusterBlockId& old_clb,
53+
std::vector<AtomBlockId>& old_clb_atoms,
5354
t_lb_router_data*& router_data);
5455

5556
/**

0 commit comments

Comments
 (0)