|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Alex Singer |
| 4 | + * @date November 2024 |
| 5 | + * @brief The declarations of the Greedy Clusterer class which is used to |
| 6 | + * encapsulate the process of greedy clustering. |
| 7 | + */ |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include <map> |
| 12 | +#include <unordered_set> |
| 13 | +#include "physical_types.h" |
| 14 | + |
| 15 | +// Forward declarations |
| 16 | +class AtomNetId; |
| 17 | +class AtomNetlist; |
| 18 | +class AttractionInfo; |
| 19 | +class ClusterLegalizer; |
| 20 | +class Prepacker; |
| 21 | +struct t_analysis_opts; |
| 22 | +struct t_clustering_data; |
| 23 | +struct t_pack_high_fanout_thresholds; |
| 24 | +struct t_packer_opts; |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief A clusterer that generates clusters by greedily choosing the clusters |
| 28 | + * which appear to have the best gain for a given neighbor. |
| 29 | + * |
| 30 | + * This clusterer generates one cluster at a time by finding candidate molecules |
| 31 | + * and selecting the molecule with the highest gain. |
| 32 | + * |
| 33 | + * The clusterer takes an Atom Netlist which has be pre-packed into pack |
| 34 | + * patterns (e.g. carry chains) as input and produces a set of legal clusters |
| 35 | + * of these pack molecules as output. Legality here means that it was able to |
| 36 | + * find a valid intra-lb route for the inputs of the clusters, through the |
| 37 | + * internal molecules, and to the outputs of the clusters. |
| 38 | + */ |
| 39 | +class GreedyClusterer { |
| 40 | +public: |
| 41 | + /** |
| 42 | + * @brief Constructor of the Greedy Clusterer class. |
| 43 | + * |
| 44 | + * The clusterer may be invoked many times during the packing flow. This |
| 45 | + * constructor will pre-compute information before clustering which can |
| 46 | + * improve the performance of the clusterer. |
| 47 | + * |
| 48 | + * @param packer_opts |
| 49 | + * Options passed by the user to configure the packing and |
| 50 | + * clustering algorithms. |
| 51 | + * @param analysis_opts |
| 52 | + * Options passed by the user to configure timing analysis in |
| 53 | + * the clusterer. |
| 54 | + * @param atom_netlist |
| 55 | + * The atom netlist to cluster over. |
| 56 | + * @param arch |
| 57 | + * The architecture to cluster over. |
| 58 | + * @param high_fanout_thresholds |
| 59 | + * The thresholds for what to consider as a high-fanout net |
| 60 | + * for each logical block type. The clusterer will not consider |
| 61 | + * nets with fanout higher than this to be important in |
| 62 | + * candidate block selection (gain computation). |
| 63 | + * A reason for it being per block type is that some blocks, |
| 64 | + * like RAMs, have weak gains to other RAM primitives due to |
| 65 | + * fairly high fanout address nets, so a higher fanout |
| 66 | + * threshold for them is useful in generating a more dense |
| 67 | + * packing. |
| 68 | + * @param is_clock |
| 69 | + * The set of clock nets in the Atom Netlist. |
| 70 | + * @param is_global |
| 71 | + * The set of global nets in the Atom Netlist. These will be |
| 72 | + * routed on special dedicated networks, and hence are less |
| 73 | + * relavent to locality / attraction. |
| 74 | + */ |
| 75 | + GreedyClusterer(const t_packer_opts& packer_opts, |
| 76 | + const t_analysis_opts& analysis_opts, |
| 77 | + const AtomNetlist& atom_netlist, |
| 78 | + const t_arch* arch, |
| 79 | + const t_pack_high_fanout_thresholds& high_fanout_thresholds, |
| 80 | + const std::unordered_set<AtomNetId>& is_clock, |
| 81 | + const std::unordered_set<AtomNetId>& is_global); |
| 82 | + |
| 83 | + /** |
| 84 | + * @brief Performs clustering on the pack molecules formed by the prepacker. |
| 85 | + * |
| 86 | + * The clustering is contained within the Cluster Legalizer. |
| 87 | + * |
| 88 | + * @param cluster_legalizer |
| 89 | + * The cluster legalizer which is used to create clusters and |
| 90 | + * grow clusters by adding molecules to a cluster. |
| 91 | + * @param prepacker |
| 92 | + * The prepacker object which contains the pack molecules that |
| 93 | + * are atoms which are pre-packed before the main clustering |
| 94 | + * (due to pack patterns, e.g. carry chains). |
| 95 | + * @param allow_unrelated_clustering |
| 96 | + * Allows primitives which have no attraction to the given |
| 97 | + * cluster to be packed into it. This can lead to a denser |
| 98 | + * packing, but tends to be bad for wirelength and timing. |
| 99 | + * @param balance_block_type_utilization |
| 100 | + * When true, tries to create clusters that balance the logical |
| 101 | + * block type utilization. This is useful when some primitives |
| 102 | + * have multiple logical block types to which they can cluster, |
| 103 | + * e.g. multiple sizes of physical RAMs exist on the chip. |
| 104 | + * @param attraction_groups |
| 105 | + * Information on the attraction groups used during the |
| 106 | + * clustering process. These are groups of primitives that have |
| 107 | + * extra attraction to each other; currently they are used to |
| 108 | + * guide the clusterer when it must cluster some parts of a |
| 109 | + * design densely due to user placement/floorplanning |
| 110 | + * constraints. They are created if some floorplan regions are |
| 111 | + * overfilled after a clustering attempt. |
| 112 | + * |
| 113 | + * @return num_used_type_instances |
| 114 | + * The number of used logical blocks of each type by the |
| 115 | + * clustering. This information may be useful when detecting |
| 116 | + * if the clustering can fit on the device. |
| 117 | + */ |
| 118 | + std::map<t_logical_block_type_ptr, size_t> |
| 119 | + do_clustering(ClusterLegalizer& cluster_legalizer, |
| 120 | + Prepacker& prepacker, |
| 121 | + bool allow_unrelated_clustering, |
| 122 | + bool balance_block_type_utilization, |
| 123 | + AttractionInfo& attraction_groups); |
| 124 | + |
| 125 | +private: |
| 126 | + /* |
| 127 | + * When attraction groups are created, the purpose is to pack more densely by adding more molecules |
| 128 | + * from the cluster's attraction group to the cluster. In a normal flow, (when attraction groups are |
| 129 | + * not on), the cluster keeps being packed until the get_molecule routines return either a repeated |
| 130 | + * molecule or a nullptr. When attraction groups are on, we want to keep exploring molecules for the |
| 131 | + * cluster until a nullptr is returned. So, the number of repeated molecules is changed from 1 to 500, |
| 132 | + * effectively making the clusterer pack a cluster until a nullptr is returned. |
| 133 | + */ |
| 134 | + static constexpr int attraction_groups_max_repeated_molecules_ = 500; |
| 135 | + |
| 136 | + /// @brief The packer options used to configure the clusterer. |
| 137 | + const t_packer_opts& packer_opts_; |
| 138 | + |
| 139 | + /// @brief The analysis options used to configure timing analysis within the |
| 140 | + /// clusterer. |
| 141 | + const t_analysis_opts& analysis_opts_; |
| 142 | + |
| 143 | + /// @brief The atom netlist to cluster over. |
| 144 | + const AtomNetlist& atom_netlist_; |
| 145 | + |
| 146 | + /// @brief The device architecture to cluster onto. |
| 147 | + const t_arch* arch_ = nullptr; |
| 148 | + |
| 149 | + /// @brief The high-fanout thresholds per logical block type. Used to ignore |
| 150 | + /// certain nets when calculating the gain for the next candidate |
| 151 | + /// molecule to cluster. |
| 152 | + const t_pack_high_fanout_thresholds& high_fanout_thresholds_; |
| 153 | + |
| 154 | + /// @brief A set of atom nets which are considered as clocks. |
| 155 | + const std::unordered_set<AtomNetId>& is_clock_; |
| 156 | + |
| 157 | + /// @brief A set of atom nets which are considered as global nets. |
| 158 | + const std::unordered_set<AtomNetId>& is_global_; |
| 159 | + |
| 160 | + /// @brief Pre-computed logical block types for each model in the architecture. |
| 161 | + std::map<const t_model*, std::vector<t_logical_block_type_ptr>> primitive_candidate_block_types_; |
| 162 | +}; |
| 163 | + |
0 commit comments