3737 */
3838
3939#include " greedy_clusterer.h"
40- #include < array>
4140#include < cstdio>
4241#include < map>
4342#include < string>
5655#include " vtr_math.h"
5756#include " vtr_vector.h"
5857
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+
5975GreedyClusterer::GreedyClusterer (const t_packer_opts& packer_opts,
6076 const t_analysis_opts& analysis_opts,
6177 const AtomNetlist& atom_netlist,
@@ -93,9 +109,8 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
93109
94110 // The clustering stats holds information used for logging the progress
95111 // 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 ();
99114
100115 // TODO: Create a ClusteringTimingManager class.
101116 // This code relies on the prepacker, once the prepacker is moved to
@@ -124,7 +139,7 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
124139 alloc_and_init_clustering (max_molecule_stats,
125140 prepacker,
126141 clustering_data,
127- clustering_stats_ .num_molecules );
142+ clustering_stats .num_molecules );
128143
129144 // Create the greedy seed selector.
130145 GreedySeedSelector seed_selector (atom_netlist_,
@@ -156,7 +171,8 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
156171 // do full legalization for each molecule added to the cluster.
157172
158173 // 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).
160176 LegalizationClusterId new_cluster_id = try_grow_cluster (seed_mol,
161177 ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
162178 cluster_legalizer,
@@ -192,6 +208,21 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
192208 VTR_ASSERT (new_cluster_id.is_valid ());
193209 VTR_ASSERT (cluster_legalizer.is_mol_clustered (seed_mol));
194210
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+
195226 // Pick new seed.
196227 seed_mol = seed_selector.get_next_seed (prepacker,
197228 cluster_legalizer);
@@ -236,15 +267,6 @@ LegalizationClusterId GreedyClusterer::try_grow_cluster(
236267 num_used_type_instances,
237268 mutable_device_ctx);
238269
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-
248270 int high_fanout_threshold = high_fanout_thresholds_.get_threshold (cluster_legalizer.get_cluster_type (legalization_cluster_id)->name );
249271 update_cluster_stats (seed_mol,
250272 cluster_legalizer,
@@ -302,14 +324,6 @@ LegalizationClusterId GreedyClusterer::try_grow_cluster(
302324 // If the candidate molecule was clustered successfully, update
303325 // the cluster stats.
304326 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-
313327 update_cluster_stats (candidate_mol,
314328 cluster_legalizer,
315329 is_clock_, // Set of all clocks
@@ -492,10 +506,6 @@ LegalizationClusterId GreedyClusterer::start_new_cluster(
492506 // Progress dot for seed-block
493507 fflush (stdout);
494508
495- // Update the clustering progress stats.
496- clustering_stats_.num_molecules_processed ++;
497- clustering_stats_.mols_since_last_print ++;
498-
499509 // TODO: Below may make more sense in its own method.
500510
501511 // Successfully created cluster
@@ -563,13 +573,6 @@ bool GreedyClusterer::try_add_candidate_mol_to_cluster(t_pack_molecule* candidat
563573 fflush (stdout);
564574 }
565575
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-
573576 return pack_status == e_block_pack_status::BLK_PASSED;
574577}
575578
@@ -584,27 +587,32 @@ void GreedyClusterer::report_le_physical_block_usage(const ClusterLegalizer& clu
584587 if (le_pb_type == nullptr )
585588 return ;
586589
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 ;
596602
597603 for (LegalizationClusterId cluster_id : cluster_legalizer.clusters ()) {
598604 // Update the data structure holding the LE counts
599605 update_le_count (cluster_legalizer.get_cluster_pb (cluster_id),
600606 logic_block_type,
601607 le_pb_type,
602- le_count);
608+ num_logic_le,
609+ num_reg_le,
610+ num_logic_and_reg_le);
603611 }
604612
605613 // if this architecture has LE physical block, report its usage
606614 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);
608616 }
609617}
610618
0 commit comments