Skip to content

Commit 233dc26

Browse files
author
MohamedElgammal
committed
Change the printing statements to print based on verbosity
1 parent 638701f commit 233dc26

File tree

4 files changed

+92
-67
lines changed

4 files changed

+92
-67
lines changed

vpr/src/pack/re_cluster.cpp

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
bool move_mol_to_new_cluster(t_pack_molecule* molecule,
88
t_clustering_data& clustering_data,
9-
bool during_packing) {
9+
bool during_packing,
10+
int verbosity) {
1011
auto& cluster_ctx = g_vpr_ctx.clustering();
1112
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
1213
auto& device_ctx = g_vpr_ctx.device();
@@ -30,17 +31,23 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3031
}
3132

3233
if (helper_ctx.num_used_type_instances[block_type] == num_instances) {
33-
VTR_LOG("The utilization of block_type %s is 100%. No space for new clusters\n", block_type->name);
34-
VTR_LOG("Atom %d move aborted\n", molecule->atom_block_ids[molecule->root]);
34+
VTR_LOGV(verbosity > 4, "The utilization of block_type %s is 100%. No space for new clusters\n", block_type->name);
35+
VTR_LOGV(verbosity > 4, "Atom %d move aborted\n", molecule->atom_block_ids[molecule->root]);
3536
return false;
3637
}
3738

38-
//remove the molecule from its current cluster and check the cluster legality after
39-
is_removed = remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data, clustering_data, during_packing);
39+
//remove the molecule from its current cluster
40+
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data);
4041

41-
if (!is_removed) {
42-
VTR_LOG("Atom: %zu move failed. Can't remove it from the old cluster\n", molecule->atom_block_ids[molecule->root]);
43-
return (is_removed);
42+
//check old cluster legality after removing the molecule
43+
is_removed = is_cluster_legal(old_router_data);
44+
45+
//if the cluster is legal, commit the molecule removal. Otherwise, abort the move
46+
if (is_removed) {
47+
commit_mol_removal(molecule, molecule_size, old_clb, during_packing, old_router_data, clustering_data);
48+
} else {
49+
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. Can't remove it from the old cluster\n", molecule->atom_block_ids[molecule->root]);
50+
return false;
4451
}
4552

4653
//Create new cluster of the same type and mode.
@@ -52,17 +59,18 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
5259
helper_ctx.enable_pin_feasibility_filter,
5360
new_clb,
5461
during_packing,
62+
verbosity,
5563
clustering_data,
5664
&router_data,
5765
temp_cluster_pr);
5866

5967
//Commit or revert the move
6068
if (is_created) {
6169
commit_mol_move(old_clb, new_clb, during_packing, true);
62-
VTR_LOG("Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
70+
VTR_LOGV(verbosity > 4, "Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
6371
} else {
6472
revert_mol_move(old_clb, molecule, old_router_data, during_packing, clustering_data);
65-
VTR_LOG("Atom:%zu move failed. Can't start a new cluster of the same type and mode\n", molecule->atom_block_ids[molecule->root]);
73+
VTR_LOGV(verbosity > 4, "Atom:%zu move failed. Can't start a new cluster of the same type and mode\n", molecule->atom_block_ids[molecule->root]);
6674
}
6775

6876
free_router_data(old_router_data);
@@ -80,6 +88,7 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
8088
bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
8189
const ClusterBlockId& new_clb,
8290
bool during_packing,
91+
int verbosity,
8392
t_clustering_data& clustering_data) {
8493
//define required contexts
8594
auto& cluster_ctx = g_vpr_ctx.clustering();
@@ -94,36 +103,42 @@ bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
94103
//Check that the old and new clusters are the same type
95104
ClusterBlockId old_clb = atom_to_cluster(root_atom_id);
96105
if (cluster_ctx.clb_nlist.block_type(old_clb) != cluster_ctx.clb_nlist.block_type(new_clb)) {
97-
VTR_LOG("Atom:%zu move aborted. New and old cluster blocks are not of the same type",
106+
VTR_LOGV(verbosity > 4, "Atom:%zu move aborted. New and old cluster blocks are not of the same type",
98107
root_atom_id);
99108
return false;
100109
}
101110

102111
//Check that the old and new clusters are the mode
103112
if (cluster_ctx.clb_nlist.block_pb(old_clb)->mode != cluster_ctx.clb_nlist.block_pb(new_clb)->mode) {
104-
VTR_LOG("Atom:%zu move aborted. New and old cluster blocks are not of the same mode",
113+
VTR_LOGV(verbosity > 4, "Atom:%zu move aborted. New and old cluster blocks are not of the same mode",
105114
root_atom_id);
106115
return false;
107116
}
108117

109-
//remove the molecule from its current cluster and check the cluster legality
110-
is_removed = remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data, clustering_data, during_packing);
111-
if (!is_removed) {
112-
VTR_LOG("Atom: %zu move failed. Can't remove it from the old cluster\n", root_atom_id);
118+
//remove the molecule from its current cluster
119+
remove_mol_from_cluster(molecule, molecule_size, old_clb, old_router_data);
120+
121+
//check old cluster legality after removing the molecule
122+
is_removed = is_cluster_legal(old_router_data);
123+
124+
//if the cluster is legal, commit the molecule removal. Otherwise, abort the move
125+
if (is_removed) {
126+
commit_mol_removal(molecule, molecule_size, old_clb, during_packing, old_router_data, clustering_data);
127+
} else {
128+
VTR_LOGV(verbosity > 4, "Atom: %zu move failed. Can't remove it from the old cluster\n", root_atom_id);
113129
return false;
114130
}
115131

116-
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);
117132
//Add the atom to the new cluster
118133
is_added = pack_mol_in_existing_cluster(molecule, new_clb, new_clb_atoms, during_packing, clustering_data);
119134

120135
//Commit or revert the move
121136
if (is_added) {
122137
commit_mol_move(old_clb, new_clb, during_packing, false);
123-
VTR_LOG("Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
138+
VTR_LOGV(verbosity > 4, "Atom:%zu is moved to a new cluster\n", molecule->atom_block_ids[molecule->root]);
124139
} else {
125140
revert_mol_move(old_clb, molecule, old_router_data, during_packing, clustering_data);
126-
VTR_LOG("Atom:%zu move failed. Can't start a new cluster of the same type and mode\n", molecule->atom_block_ids[molecule->root]);
141+
VTR_LOGV(verbosity > 4, "Atom:%zu move failed. Can't start a new cluster of the same type and mode\n", molecule->atom_block_ids[molecule->root]);
127142
}
128143

129144
free_router_data(old_router_data);

vpr/src/pack/re_cluster.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
*/
2525
bool move_mol_to_new_cluster(t_pack_molecule* molecule,
2626
t_clustering_data& clustering_data,
27-
bool during_packing);
27+
bool during_packing,
28+
int verbosity);
2829

2930
/**
3031
* @brief This function moves a molecule out of its cluster to another cluster that already exists.
@@ -37,6 +38,7 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
3738
bool move_mol_to_existing_cluster(t_pack_molecule* molecule,
3839
const ClusterBlockId& new_clb,
3940
bool during_packing,
41+
int verbosity,
4042
t_clustering_data& clustering_data);
4143

4244
/**

vpr/src/pack/re_cluster_util.cpp

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ static void fix_cluster_net_after_moving(const t_pack_molecule* molecule,
3535
const ClusterBlockId& old_clb,
3636
const ClusterBlockId& new_clb);
3737

38+
static void rebuild_cluster_placemet_stats(const ClusterBlockId& clb_index,
39+
const std::vector<AtomBlockId>& clb_atoms,
40+
int type_idx,
41+
int mode);
42+
3843
/***************** API functions ***********************/
3944
ClusterBlockId atom_to_cluster(const AtomBlockId& atom) {
4045
auto& atom_ctx = g_vpr_ctx.atom();
@@ -46,18 +51,11 @@ std::vector<AtomBlockId> cluster_to_atoms(const ClusterBlockId& cluster) {
4651
return (cluster_lookup.atoms_in_cluster(cluster));
4752
}
4853

49-
bool remove_mol_from_cluster(const t_pack_molecule* molecule,
54+
void remove_mol_from_cluster(const t_pack_molecule* molecule,
5055
int molecule_size,
5156
ClusterBlockId& old_clb,
52-
t_lb_router_data*& router_data,
53-
t_clustering_data& clustering_data,
54-
bool during_packing) {
57+
t_lb_router_data*& router_data) {
5558
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
56-
auto& atom_ctx = g_vpr_ctx.atom();
57-
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
58-
59-
t_pb* temp_pb = const_cast<t_pb*>(atom_ctx.lookup.atom_pb(molecule->atom_block_ids[0]));
60-
t_pb* next_pb;
6159

6260
//Determine the cluster ID
6361
old_clb = atom_to_cluster(molecule->atom_block_ids[molecule->root]);
@@ -72,30 +70,6 @@ bool remove_mol_from_cluster(const t_pack_molecule* molecule,
7270
remove_atom_from_target(router_data, molecule->atom_block_ids[i_atom]);
7371
}
7472
}
75-
76-
//check cluster legality
77-
bool is_cluster_legal = check_cluster_legality(0, E_DETAILED_ROUTE_AT_END_ONLY, router_data);
78-
79-
if (is_cluster_legal) {
80-
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
81-
if (molecule->atom_block_ids[i_atom]) {
82-
revert_place_atom_block(molecule->atom_block_ids[i_atom], router_data);
83-
}
84-
}
85-
86-
cleanup_pb(cluster_ctx.clb_nlist.block_pb(old_clb));
87-
88-
if (during_packing) {
89-
free_intra_lb_nets(clustering_data.intra_lb_routing[old_clb]);
90-
clustering_data.intra_lb_routing[old_clb] = router_data->saved_lb_nets;
91-
router_data->saved_lb_nets = nullptr;
92-
} else {
93-
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route.clear();
94-
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route = alloc_and_load_pb_route(router_data->saved_lb_nets, cluster_ctx.clb_nlist.block_pb(old_clb)->pb_graph_node);
95-
}
96-
}
97-
//return true if succeeded
98-
return (is_cluster_legal);
9973
}
10074

10175
void commit_mol_move(const ClusterBlockId& old_clb,
@@ -133,6 +107,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
133107
bool enable_pin_feasibility_filter,
134108
ClusterBlockId clb_index,
135109
bool during_packing,
110+
int verbosity,
136111
t_clustering_data& clustering_data,
137112
t_lb_router_data** router_data,
138113
PartitionRegion& temp_cluster_pr) {
@@ -141,8 +116,6 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
141116
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
142117
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
143118

144-
int verbosity = 0;
145-
146119
/* Cluster's PartitionRegion is empty initially, meaning it has no floorplanning constraints */
147120
PartitionRegion empty_pr;
148121
floorplanning_ctx.cluster_constraints.push_back(empty_pr);
@@ -181,7 +154,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
181154

182155
// If clustering succeeds, add it to the clb netlist
183156
if (pack_result == BLK_PASSED) {
184-
VTR_LOGV(verbosity > 2, "\tPASSED_SEED: Block Type %s\n", type->name);
157+
VTR_LOGV(verbosity > 4, "\tPASSED_SEED: Block Type %s\n", type->name);
185158
//Once clustering succeeds, add it to the clb netlist
186159
if (pb->name != nullptr) {
187160
free(pb->name);
@@ -223,6 +196,10 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
223196
t_logical_block_type_ptr block_type = cluster_ctx.clb_nlist.block_type(new_clb);
224197
t_pb* temp_pb = cluster_ctx.clb_nlist.block_pb(new_clb);
225198

199+
200+
//re-build cluster placement stats
201+
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);
202+
226203
//re-build router_data structure for this cluster
227204
t_lb_router_data* router_data = lb_load_router_data(helper_ctx.lb_type_rr_graphs, new_clb, new_clb_atoms);
228205

@@ -612,8 +589,7 @@ static bool count_children_pbs(const t_pb* pb) {
612589
return false;
613590
}
614591

615-
#if 1
616-
void rebuild_cluster_placemet_stats(const ClusterBlockId& clb_index,
592+
static void rebuild_cluster_placemet_stats(const ClusterBlockId& clb_index,
617593
const std::vector<AtomBlockId>& clb_atoms,
618594
int type_idx,
619595
int mode) {
@@ -643,4 +619,33 @@ void rebuild_cluster_placemet_stats(const ClusterBlockId& clb_index,
643619
}
644620
}
645621
}
646-
#endif
622+
623+
bool is_cluster_legal(t_lb_router_data*& router_data) {
624+
return (check_cluster_legality(0, E_DETAILED_ROUTE_AT_END_ONLY, router_data));
625+
}
626+
627+
void commit_mol_removal(const t_pack_molecule* molecule,
628+
const int& molecule_size,
629+
const ClusterBlockId& old_clb,
630+
bool during_packing,
631+
t_lb_router_data*& router_data,
632+
t_clustering_data& clustering_data) {
633+
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
634+
635+
for (int i_atom = 0; i_atom < molecule_size; i_atom++) {
636+
if (molecule->atom_block_ids[i_atom]) {
637+
revert_place_atom_block(molecule->atom_block_ids[i_atom], router_data);
638+
}
639+
}
640+
641+
cleanup_pb(cluster_ctx.clb_nlist.block_pb(old_clb));
642+
643+
if (during_packing) {
644+
free_intra_lb_nets(clustering_data.intra_lb_routing[old_clb]);
645+
clustering_data.intra_lb_routing[old_clb] = router_data->saved_lb_nets;
646+
router_data->saved_lb_nets = nullptr;
647+
} else {
648+
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route.clear();
649+
cluster_ctx.clb_nlist.block_pb(old_clb)->pb_route = alloc_and_load_pb_route(router_data->saved_lb_nets, cluster_ctx.clb_nlist.block_pb(old_clb)->pb_graph_node);
650+
}
651+
}

vpr/src/pack/re_cluster_util.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ t_lb_router_data* lb_load_router_data(std::vector<t_lb_type_rr_node>* lb_type_rr
4747
* It aborts the removal and returns false if the removal will make the old cluster
4848
* illegal
4949
*/
50-
bool remove_mol_from_cluster(const t_pack_molecule* molecule,
50+
void remove_mol_from_cluster(const t_pack_molecule* molecule,
5151
int molecule_size,
5252
ClusterBlockId& old_clb,
53-
t_lb_router_data*& router_data,
54-
t_clustering_data& clustering_data,
55-
bool during_packing);
53+
t_lb_router_data*& router_data);
5654

5755
/**
5856
* @brief A function that starts a new cluster for one specific molecule
@@ -67,6 +65,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
6765
bool enable_pin_feasibility_filter,
6866
ClusterBlockId clb_index,
6967
bool during_packing,
68+
int verbosity,
7069
t_clustering_data& clustering_data,
7170
t_lb_router_data** router_data,
7271
PartitionRegion& temp_cluster_pr);
@@ -107,9 +106,13 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
107106
bool during_packing,
108107
t_clustering_data& clustering_data);
109108

110-
void rebuild_cluster_placemet_stats(const ClusterBlockId& clb_index,
111-
const std::vector<AtomBlockId>& clb_atoms,
112-
int type_idx,
113-
int mode);
109+
bool is_cluster_legal(t_lb_router_data*& router_data);
110+
111+
void commit_mol_removal(const t_pack_molecule* molecule,
112+
const int& molecule_size,
113+
const ClusterBlockId& old_clb,
114+
bool during_packing,
115+
t_lb_router_data*& router_data,
116+
t_clustering_data& clustering_data);
114117

115118
#endif

0 commit comments

Comments
 (0)