Skip to content

Commit 0d44ae5

Browse files
author
MohamedElgammal
committed
swapping two molecule first implementation (WIP)
1 parent 0af92da commit 0d44ae5

File tree

2 files changed

+49
-112
lines changed

2 files changed

+49
-112
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 48 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
144144
return (is_added);
145145
}
146146

147-
#if 0
147+
#if 1
148148
bool swap_two_molecules(t_pack_molecule* molecule_1,
149149
t_pack_molecule* molecule_2,
150150
bool during_packing,
151+
int verbosity,
151152
t_clustering_data& clustering_data) {
152153
//define required contexts
153154
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -157,8 +158,7 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
157158
//define local variables
158159
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
159160

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;
162162

163163
AtomBlockId root_1_atom_id = molecule_1->atom_block_ids[molecule_1->root];
164164
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,
170170
ClusterBlockId clb_1 = atom_to_cluster(root_1_atom_id);
171171
ClusterBlockId clb_2 = atom_to_cluster(root_2_atom_id);
172172

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);
175175

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);
177177

178178
//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)
189181
return false;
190-
}
191182

183+
#if 0
192184
//Backup the original pb of the molecule before the move
193185
std::vector<t_pb*> mol_1_pb_backup, mol_2_pb_backup;
194186
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,
205197
mol_2_pb_backup.push_back(atom_pb_backup);
206198
}
207199
}
200+
#endif
208201

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;
212204

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);
216211

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]) {
221216
revert_place_atom_block(molecule_1->atom_block_ids[i_atom], old_1_router_data);
222217
}
223218
}
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-
}
230219

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;
261225

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);
262229

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;
263234

264235
//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) {
280237
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");
283240
} 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");
299244
}
300245

246+
301247
//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) {
303249
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);
305251
}
306252

307253
//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;
310256

311257
free_router_data(old_1_router_data);
312-
free_router_data(old_2_router_data);
258+
//free_router_data(old_2_router_data);
313259

314260
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;
326262

327263
//return the move result
328-
return (pack_1_result == BLK_PASSED && pack_2_result == BLK_PASSED);
264+
return (mol_1_success && mol_2_success);
329265
}
330266
#endif

vpr/src/pack/re_cluster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
5252
bool swap_two_molecules(t_pack_molecule* molecule_1,
5353
t_pack_molecule* molecule_2,
5454
bool during_packing,
55+
int verbosity,
5556
t_clustering_data& clustering_data);
5657
#endif

0 commit comments

Comments
 (0)