37
37
*/
38
38
39
39
#include " greedy_clusterer.h"
40
- #include < array>
41
40
#include < cstdio>
42
41
#include < map>
43
42
#include < string>
56
55
#include " vtr_math.h"
57
56
#include " vtr_vector.h"
58
57
58
+ namespace {
59
+
60
+ /* *
61
+ * @brief Struct to hold statistics on the progress of clustering.
62
+ */
63
+ struct t_cluster_progress_stats {
64
+ // The total number of molecules in the design.
65
+ int num_molecules = 0 ;
66
+ // The number of molecules which have been clustered.
67
+ int num_molecules_processed = 0 ;
68
+ // The number of molecules clustered since the last time the status was
69
+ // logged.
70
+ int mols_since_last_print = 0 ;
71
+ };
72
+
73
+ } // namespace
74
+
59
75
GreedyClusterer::GreedyClusterer (const t_packer_opts& packer_opts,
60
76
const t_analysis_opts& analysis_opts,
61
77
const AtomNetlist& atom_netlist,
@@ -93,9 +109,8 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
93
109
94
110
// The clustering stats holds information used for logging the progress
95
111
// of the clustering to the user.
96
- // Reset the clustering stats in case the clusterer is called multiple times.
97
- clustering_stats_ = t_cluster_progress_stats ();
98
- clustering_stats_.num_molecules = prepacker.get_num_molecules ();
112
+ t_cluster_progress_stats clustering_stats;
113
+ clustering_stats.num_molecules = prepacker.get_num_molecules ();
99
114
100
115
// TODO: Create a ClusteringTimingManager class.
101
116
// This code relies on the prepacker, once the prepacker is moved to
@@ -124,7 +139,7 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
124
139
alloc_and_init_clustering (max_molecule_stats,
125
140
prepacker,
126
141
clustering_data,
127
- clustering_stats_ .num_molecules );
142
+ clustering_stats .num_molecules );
128
143
129
144
// Create the greedy seed selector.
130
145
GreedySeedSelector seed_selector (atom_netlist_,
@@ -156,7 +171,8 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
156
171
// do full legalization for each molecule added to the cluster.
157
172
158
173
// Try to grow a cluster from the seed molecule without doing intra-lb
159
- // route for each molecule.
174
+ // route for each molecule (i.e. just use faster but not fully
175
+ // conservative legality checks).
160
176
LegalizationClusterId new_cluster_id = try_grow_cluster (seed_mol,
161
177
ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
162
178
cluster_legalizer,
@@ -192,6 +208,21 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
192
208
VTR_ASSERT (new_cluster_id.is_valid ());
193
209
VTR_ASSERT (cluster_legalizer.is_mol_clustered (seed_mol));
194
210
211
+ // Update the clustering progress stats.
212
+ size_t num_molecules_in_cluster = cluster_legalizer.get_num_molecules_in_cluster (new_cluster_id);
213
+ clustering_stats.num_molecules_processed += num_molecules_in_cluster;
214
+ clustering_stats.mols_since_last_print += num_molecules_in_cluster;
215
+
216
+ // Print the current progress of the packing after a cluster has been
217
+ // successfully created.
218
+ print_pack_status (clustering_stats.num_molecules ,
219
+ clustering_stats.num_molecules_processed ,
220
+ clustering_stats.mols_since_last_print ,
221
+ mutable_device_ctx.grid .width (),
222
+ mutable_device_ctx.grid .height (),
223
+ attraction_groups,
224
+ cluster_legalizer);
225
+
195
226
// Pick new seed.
196
227
seed_mol = seed_selector.get_next_seed (prepacker,
197
228
cluster_legalizer);
@@ -236,15 +267,6 @@ LegalizationClusterId GreedyClusterer::try_grow_cluster(
236
267
num_used_type_instances,
237
268
mutable_device_ctx);
238
269
239
- // initial molecule in cluster has been processed
240
- print_pack_status (clustering_stats_.num_molecules ,
241
- clustering_stats_.num_molecules_processed ,
242
- clustering_stats_.mols_since_last_print ,
243
- mutable_device_ctx.grid .width (),
244
- mutable_device_ctx.grid .height (),
245
- attraction_groups,
246
- cluster_legalizer);
247
-
248
270
int high_fanout_threshold = high_fanout_thresholds_.get_threshold (cluster_legalizer.get_cluster_type (legalization_cluster_id)->name );
249
271
update_cluster_stats (seed_mol,
250
272
cluster_legalizer,
@@ -302,14 +324,6 @@ LegalizationClusterId GreedyClusterer::try_grow_cluster(
302
324
// If the candidate molecule was clustered successfully, update
303
325
// the cluster stats.
304
326
if (success) {
305
- print_pack_status (clustering_stats_.num_molecules ,
306
- clustering_stats_.num_molecules_processed ,
307
- clustering_stats_.mols_since_last_print ,
308
- mutable_device_ctx.grid .width (),
309
- mutable_device_ctx.grid .height (),
310
- attraction_groups,
311
- cluster_legalizer);
312
-
313
327
update_cluster_stats (candidate_mol,
314
328
cluster_legalizer,
315
329
is_clock_, // Set of all clocks
@@ -492,10 +506,6 @@ LegalizationClusterId GreedyClusterer::start_new_cluster(
492
506
// Progress dot for seed-block
493
507
fflush (stdout);
494
508
495
- // Update the clustering progress stats.
496
- clustering_stats_.num_molecules_processed ++;
497
- clustering_stats_.mols_since_last_print ++;
498
-
499
509
// TODO: Below may make more sense in its own method.
500
510
501
511
// Successfully created cluster
@@ -563,13 +573,6 @@ bool GreedyClusterer::try_add_candidate_mol_to_cluster(t_pack_molecule* candidat
563
573
fflush (stdout);
564
574
}
565
575
566
- // If candidate molecule was successfully added, update the clustering
567
- // progress stats.
568
- if (pack_status == e_block_pack_status::BLK_PASSED) {
569
- clustering_stats_.num_molecules_processed ++;
570
- clustering_stats_.mols_since_last_print ++;
571
- }
572
-
573
576
return pack_status == e_block_pack_status::BLK_PASSED;
574
577
}
575
578
@@ -584,27 +587,32 @@ void GreedyClusterer::report_le_physical_block_usage(const ClusterLegalizer& clu
584
587
if (le_pb_type == nullptr )
585
588
return ;
586
589
587
- // this data structure tracks the number of Logic Elements (LEs) used. It is
588
- // populated only for architectures which has LEs. The architecture is assumed
589
- // to have LEs only iff it has a logic block that contains LUT primitives and is
590
- // the first pb_block to have more than one instance from the top of the hierarchy
591
- // (All parent pb_block have one instance only and one mode only). Index 0 holds
592
- // the number of LEs that are used for both logic (LUTs/adders) and registers.
593
- // Index 1 holds the number of LEs that are used for logic (LUTs/adders) only.
594
- // Index 2 holds the number of LEs that are used for registers only.
595
- std::array<int , 3 > le_count = {0 , 0 , 0 };
590
+ // Track the number of Logic Elements (LEs) used. This is populated only for
591
+ // architectures which has LEs. The architecture is assumed to have LEs iff
592
+ // it has a logic block that contains LUT primitives and is the first
593
+ // pb_block to have more than one instance from the top of the hierarchy
594
+ // (All parent pb_block have one instance only and one mode only).
595
+
596
+ // The number of LEs that are used for logic (LUTs/adders) only.
597
+ int num_logic_le = 0 ;
598
+ // The number of LEs that are used for registers only.
599
+ int num_reg_le = 0 ;
600
+ // The number of LEs that are used for both logic (LUTs/adders) and registers.
601
+ int num_logic_and_reg_le = 0 ;
596
602
597
603
for (LegalizationClusterId cluster_id : cluster_legalizer.clusters ()) {
598
604
// Update the data structure holding the LE counts
599
605
update_le_count (cluster_legalizer.get_cluster_pb (cluster_id),
600
606
logic_block_type,
601
607
le_pb_type,
602
- le_count);
608
+ num_logic_le,
609
+ num_reg_le,
610
+ num_logic_and_reg_le);
603
611
}
604
612
605
613
// if this architecture has LE physical block, report its usage
606
614
if (le_pb_type) {
607
- print_le_count (le_count , le_pb_type);
615
+ print_le_count (num_logic_le, num_reg_le, num_logic_and_reg_le , le_pb_type);
608
616
}
609
617
}
610
618
0 commit comments