Skip to content

Commit f83cd43

Browse files
MohamedElgammalAlexandreSinger
MohamedElgammal
authored andcommitted
Re-clustering API bug fixes
1 parent 8a97e52 commit f83cd43

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
7171
//Commit or revert the move
7272
if (is_created) {
7373
commit_mol_move(old_clb, new_clb, during_packing, true);
74+
// Update the clb-->atoms lookup table
75+
helper_ctx.atoms_lookup.resize(helper_ctx.total_clb_num);
76+
for (int i_atom = 0; i_atom < molecule_size; ++i_atom) {
77+
if (molecule->atom_block_ids[i_atom]) {
78+
helper_ctx.atoms_lookup[new_clb].insert(molecule->atom_block_ids[i_atom]);
79+
}
80+
}
81+
7482
VTR_LOGV(verbosity > 4, "Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
7583
} else {
7684
revert_mol_move(old_clb, molecule, old_router_data, during_packing, clustering_data);
@@ -157,6 +165,9 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
157165
bool during_packing,
158166
int verbosity,
159167
t_clustering_data& clustering_data) {
168+
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
169+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
170+
160171
//define local variables
161172
PartitionRegion temp_cluster_pr_1, temp_cluster_pr_2;
162173

@@ -193,6 +204,11 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
193204
return false;
194205
}
195206

207+
t_pb* clb_pb_1 = cluster_ctx.clb_nlist.block_pb(clb_1);
208+
std::string clb_pb_1_name = (std::string)clb_pb_1->name;
209+
t_pb* clb_pb_2 = cluster_ctx.clb_nlist.block_pb(clb_2);
210+
std::string clb_pb_2_name = (std::string)clb_pb_2->name;
211+
196212
//remove the molecule from its current cluster
197213
remove_mol_from_cluster(molecule_1, molecule_1_size, clb_1, clb_1_atoms, false, old_1_router_data);
198214
commit_mol_removal(molecule_1, molecule_1_size, clb_1, during_packing, old_1_router_data, clustering_data);
@@ -211,6 +227,12 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
211227
free_router_data(old_2_router_data);
212228
old_1_router_data = nullptr;
213229
old_2_router_data = nullptr;
230+
231+
free(clb_pb_1->name);
232+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
233+
free(clb_pb_2->name);
234+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
235+
214236
return false;
215237
}
216238

@@ -226,6 +248,12 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
226248
free_router_data(old_2_router_data);
227249
old_1_router_data = nullptr;
228250
old_2_router_data = nullptr;
251+
252+
free(clb_pb_1->name);
253+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
254+
free(clb_pb_2->name);
255+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
256+
229257
return false;
230258
}
231259

@@ -242,6 +270,12 @@ bool swap_two_molecules(t_pack_molecule* molecule_1,
242270
free_router_data(old_2_router_data);
243271
old_1_router_data = nullptr;
244272
old_2_router_data = nullptr;
273+
274+
free(clb_pb_1->name);
275+
cluster_ctx.clb_nlist.block_pb(clb_1)->name = vtr::strdup(clb_pb_1_name.c_str());
276+
free(clb_pb_2->name);
277+
cluster_ctx.clb_nlist.block_pb(clb_2)->name = vtr::strdup(clb_pb_2_name.c_str());
278+
245279
return true;
246280
}
247281
#endif

vpr/src/pack/re_cluster_util.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
#include "read_netlist.h"
1111
#include <cstring>
1212

13-
//The name suffix of the new block (if exists)
13+
// The name suffix of the new block (if exists)
14+
// This suffex is useful in preventing duplicate high-level cluster block names
1415
const char* name_suffix = "_m";
1516

1617
/******************* Static Functions ********************/
17-
//static void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId atom_blk, const AtomPortId atom_port, const t_pb_graph_pin* gpin);
1818
static void load_atom_index_for_pb_pin(t_pb_routes& pb_route, int ipin);
1919
static void load_internal_to_block_net_nums(const t_logical_block_type_ptr type, t_pb_routes& pb_route);
20-
//static bool count_children_pbs(const t_pb* pb);
2120
static void fix_atom_pin_mapping(const AtomBlockId blk);
2221

2322
static void fix_cluster_pins_after_moving(const ClusterBlockId clb_index);
@@ -42,6 +41,7 @@ static void update_cluster_pb_stats(const t_pack_molecule* molecule,
4241
int molecule_size,
4342
ClusterBlockId clb_index,
4443
bool is_added);
44+
4545
/***************** API functions ***********************/
4646
ClusterBlockId atom_to_cluster(const AtomBlockId& atom) {
4747
auto& atom_ctx = g_vpr_ctx.atom();
@@ -66,19 +66,18 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
6666
t_lb_router_data*& router_data) {
6767
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
6868

69-
//re-build router_data structure for this cluster
70-
if (!router_data_ready)
71-
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
72-
73-
//remove atom from router_data
7469
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
7570
if (molecule->atom_block_ids[i_atom]) {
76-
remove_atom_from_target(router_data, molecule->atom_block_ids[i_atom]);
7771
auto it = old_clb_atoms->find(molecule->atom_block_ids[i_atom]);
7872
if (it != old_clb_atoms->end())
7973
old_clb_atoms->erase(molecule->atom_block_ids[i_atom]);
8074
}
8175
}
76+
77+
//re-build router_data structure for this cluster
78+
if (!router_data_ready)
79+
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, old_clb, old_clb_atoms);
80+
8281
update_cluster_pb_stats(molecule, molecule_size, old_clb, false);
8382
}
8483

@@ -101,6 +100,7 @@ void commit_mol_move(const ClusterBlockId& old_clb,
101100
t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr_graphs, const ClusterBlockId& clb_index, const std::unordered_set<AtomBlockId>* clb_atoms) {
102101
//build data structures used by intra-logic block router
103102
auto& cluster_ctx = g_vpr_ctx.clustering();
103+
auto& atom_ctx = g_vpr_ctx.atom();
104104
auto block_type = cluster_ctx.clb_nlist.block_type(clb_index);
105105
t_lb_router_data* router_data = alloc_and_load_router_data(&lb_type_rr_graphs[block_type->index], block_type);
106106

@@ -110,14 +110,19 @@ t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr
110110

111111
for (auto atom_id : *clb_atoms) {
112112
add_atom_as_target(router_data, atom_id);
113+
const t_pb* pb = atom_ctx.lookup.atom_pb(atom_id);
114+
while(pb) {
115+
set_reset_pb_modes(router_data, pb, true);
116+
pb = pb->parent_pb;
117+
}
113118
}
114119
return (router_data);
115120
}
116121

117122
bool start_new_cluster_for_mol(t_pack_molecule* molecule,
118123
const t_logical_block_type_ptr& type,
119-
const int mode,
120-
const int feasible_block_array_size,
124+
const int& mode,
125+
const int& feasible_block_array_size,
121126
bool enable_pin_feasibility_filter,
122127
ClusterBlockId clb_index,
123128
bool during_packing,
@@ -148,10 +153,11 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
148153

149154
e_block_pack_status pack_result = BLK_STATUS_UNDEFINED;
150155
pb->mode = mode;
151-
reset_cluster_placement_stats(&(helper_ctx.cluster_placement_stats[type->index]));
156+
t_cluster_placement_stats* cluster_placement_stats = &(helper_ctx.cluster_placement_stats[type->index]);
157+
reset_cluster_placement_stats(cluster_placement_stats);
152158
set_mode_cluster_placement_stats(pb->pb_graph_node, mode);
153159

154-
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[type->index]),
160+
pack_result = try_pack_molecule(cluster_placement_stats,
155161
molecule,
156162
helper_ctx.primitives_list,
157163
pb,
@@ -177,6 +183,8 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
177183
pb->name = vtr::strdup(new_name.c_str());
178184
clb_index = cluster_ctx.clb_nlist.create_block(new_name.c_str(), pb, type);
179185
helper_ctx.total_clb_num++;
186+
int molecule_size = get_array_size_of_molecule(molecule);
187+
update_cluster_pb_stats(molecule, molecule_size, clb_index, true);
180188

181189
//If you are still in packing, update the clustering data. Otherwise, update the clustered netlist.
182190
if (during_packing) {
@@ -220,8 +228,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
220228
return false;
221229

222230
//re-build router_data structure for this cluster
223-
if (!is_swap)
224-
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
231+
router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
225232

226233
pack_result = try_pack_molecule(&(helper_ctx.cluster_placement_stats[block_type->index]),
227234
molecule,
@@ -259,11 +266,9 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
259266
update_cluster_pb_stats(molecule, molecule_size, new_clb, true);
260267
}
261268

262-
if (!is_swap) {
263-
//Free clustering router data
264-
free_router_data(router_data);
265-
router_data = nullptr;
266-
}
269+
//Free clustering router data
270+
free_router_data(router_data);
271+
router_data = nullptr;
267272

268273
return (pack_result == BLK_PASSED);
269274
}

vpr/src/pack/re_cluster_util.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void remove_mol_from_cluster(const t_pack_molecule* molecule,
7979
*/
8080
bool start_new_cluster_for_mol(t_pack_molecule* molecule,
8181
const t_logical_block_type_ptr& type,
82-
const int mode,
83-
const int feasible_block_array_size,
82+
const int& mode,
83+
const int& feasible_block_array_size,
8484
bool enable_pin_feasibility_filter,
8585
ClusterBlockId clb_index,
8686
bool during_packing,
@@ -102,8 +102,8 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
102102
*/
103103
bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
104104
int molecule_size,
105-
const ClusterBlockId clb_index,
106-
std::unordered_set<AtomBlockId>* clb_atoms,
105+
const ClusterBlockId& clb_index,
106+
std::unordered_set<AtomBlockId>* new_clb_atoms,
107107
bool during_packing,
108108
bool is_swap,
109109
t_clustering_data& clustering_data,
@@ -125,29 +125,51 @@ void fix_clustered_netlist(t_pack_molecule* molecule,
125125
/**
126126
* @brief A function that commits the molecule move if it is legal
127127
*
128-
* @during_packing: true if this function is called during packing, false if it is called during placement
129-
* @new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
128+
* @params during_packing: true if this function is called during packing, false if it is called during placement
129+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
130130
*/
131131
void commit_mol_move(const ClusterBlockId& old_clb,
132132
const ClusterBlockId& new_clb,
133133
bool during_packing,
134134
bool new_clb_created);
135135

136+
/**
137+
* @brief A function that reverts the molecule move if it is illegal
138+
*
139+
* @params during_packing: true if this function is called during packing, false if it is called during placement
140+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
141+
* @params
142+
*/
136143
void revert_mol_move(const ClusterBlockId& old_clb,
137144
t_pack_molecule* molecule,
138145
t_lb_router_data*& old_router_data,
139146
bool during_packing,
140147
t_clustering_data& clustering_data);
141148

149+
/**
150+
*
151+
* @brief A function that checks the legality of a cluster by running the intra-cluster routing
152+
*/
142153
bool is_cluster_legal(t_lb_router_data*& router_data);
143154

155+
/**
156+
* @brief A function that commits the molecule removal if it is legal
157+
*
158+
* @params during_packing: true if this function is called during packing, false if it is called during placement
159+
* @params new_clb_created: true if the move is creating a new cluster (e.g. move_mol_to_new_cluster)
160+
*/
144161
void commit_mol_removal(const t_pack_molecule* molecule,
145162
const int& molecule_size,
146163
const ClusterBlockId& old_clb,
147164
bool during_packing,
148165
t_lb_router_data*& router_data,
149166
t_clustering_data& clustering_data);
150167

168+
/**
169+
*
170+
* @brief A function that check that two clusters are of the same type and in the same mode of operation
171+
*
172+
*/
151173
bool check_type_and_mode_compitability(const ClusterBlockId& old_clb,
152174
const ClusterBlockId& new_clb,
153175
int verbosity);

0 commit comments

Comments
 (0)