Skip to content

Commit 6b88b4b

Browse files
author
MohamedElgammal
committed
Some fixes and adding check for the last atom in a cluster
1 parent 34e5661 commit 6b88b4b

File tree

3 files changed

+38
-103
lines changed

3 files changed

+38
-103
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 21 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3737

3838
//remove the molecule from its current cluster
3939
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+
}
4044
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
4145

4246
//check old cluster legality after removing the molecule
@@ -90,9 +94,6 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
9094
bool during_packing,
9195
int verbosity,
9296
t_clustering_data& clustering_data) {
93-
//define required contexts
94-
auto& cluster_ctx = g_vpr_ctx.clustering();
95-
9697
//define local variables
9798
bool is_removed, is_added;
9899
AtomBlockId root_atom_id = molecule->atom_block_ids[molecule->root];
@@ -108,6 +109,10 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
108109

109110
//remove the molecule from its current cluster
110111
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+
}
111116
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_clb_atoms, old_router_data);
112117

113118
//check old cluster legality after removing the molecule
@@ -122,7 +127,8 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
122127
}
123128

124129
//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);
126132

127133
//Commit or revert the move
128134
if (is_added) {
@@ -151,11 +157,6 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
151157
bool during_packing,
152158
int verbosity,
153159
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-
159160
//define local variables
160161
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
161162

@@ -171,128 +172,52 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
171172
ClusterBlockId clb_1 = atom_to_cluster(root_1_atom_id);
172173
ClusterBlockId clb_2 = atom_to_cluster(root_2_atom_id);
173174

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-
179175
//Check that the old and new clusters are of the same type
180176
bool is_compitable = check_type_and_mode_compitability(clb_1, clb_2, verbosity);
181177
if (!is_compitable)
182178
return false;
183179

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-
203180
t_lb_router_data* old_1_router_data = nullptr;
204181
t_lb_router_data* old_2_router_data = nullptr;
205182

206183
//save the atoms of the 2 clusters
207184
std::vector<AtomBlockId> clb_1_atoms = cluster_to_atoms(clb_1);
208185
std::vector<AtomBlockId> clb_2_atoms = cluster_to_atoms(clb_2);
209186

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+
210192
//remove the molecule from its current cluster
211193
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-
217194
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);
237195

238196
remove_mol_from_cluster(molecule_2, molecule_2_size, clb_2, clb_2_atoms, old_2_router_data);
239197
commit_mol_removal(molecule_2, molecule_2_size, clb_2, during_packing, old_2_router_data, clustering_data);
240198

241199

242200
//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);
244203

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
261204

262205
//commit the move if succeeded or revert if failed
263206
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);
266207
VTR_LOGV(verbosity > 4, "Molecules swap is performed successfully\n");
267208
} 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);
270211
VTR_LOGV(verbosity > 4, "Molecules swap failed\n");
271212
}
272213

273214

274215
//If the move is done after packing not during it, some fixes need to be done on the clustered netlist
275216
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);
278219
}
279220

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-
296221
//return the move result
297222
return (mol_1_success && mol_2_success);
298223
}

vpr/src/pack/re_cluster_util.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
188188
const ClusterBlockId new_clb,
189189
const std::vector<AtomBlockId>& new_clb_atoms,
190190
bool during_packing,
191-
t_clustering_data& clustering_data) {
191+
t_clustering_data& clustering_data,
192+
bool is_swap,
193+
t_lb_router_data*& router_data) {
192194
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
193195
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
194196

@@ -202,7 +204,8 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
202204
rebuild_cluster_placemet_stats(new_clb, new_clb_atoms, cluster_ctx.clb_nlist.block_type(new_clb)->index, cluster_ctx.clb_nlist.block_pb(new_clb)->mode);
203205

204206
//re-build router_data structure for this cluster
205-
t_lb_router_data* router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
207+
if(!is_swap)
208+
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
206209

207210
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_type->index]),
208211
molecule,
@@ -232,10 +235,12 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
232235
}
233236
}
234237

235-
//Free failed clustering
236-
free_router_data(router_data);
237-
router_data = nullptr;
238-
238+
if(pack_result == BLK_PASSED || !is_swap ) {
239+
//Free clustering router data
240+
free_router_data(router_data);
241+
router_data = nullptr;
242+
}
243+
239244
return (pack_result == BLK_PASSED);
240245
}
241246

@@ -280,6 +285,9 @@ void revert_mol_move(const ClusterBlockId& old_clb,
280285
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route.clear();
281286
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route = alloc_and_load_pb_route(old_router_data->saved_lb_nets, cluster_ctx.clb_nlist.block_pb(old_clb)->pb_graph_node);
282287
}
288+
289+
free_router_data(old_router_data);
290+
old_router_data = nullptr;
283291
}
284292
/*******************************************/
285293
/************ static functions *************/

vpr/src/pack/re_cluster_util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
105105
const ClusterBlockId clb_index,
106106
const std::vector<AtomBlockId>& clb_atoms,
107107
bool during_packing,
108-
t_clustering_data& clustering_data);
108+
t_clustering_data& clustering_data,
109+
bool is_swap,
110+
t_lb_router_data*& router_data);
109111

110112
bool is_cluster_legal(t_lb_router_data*& router_data);
111113

0 commit comments

Comments
 (0)