|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Alex Singer |
| 4 | + * @date October 2024 |
| 5 | + * @brief The declarations of the Global Placer base class which is used to |
| 6 | + * define the functionality of all global placers in the AP flow. |
| 7 | + * |
| 8 | + * A Global Placer creates a Partial Placement given only the netlist and the |
| 9 | + * architecture. It uses analytical techniques (i.e. efficient numerical |
| 10 | + * minimization of an objective function of a placement) to find a placement |
| 11 | + * that optimizes for objectives subject to some of the constraints of the FPGA |
| 12 | + * architecture. |
| 13 | + */ |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include <memory> |
| 18 | + |
| 19 | +// Forward declarations |
| 20 | +class APNetlist; |
| 21 | +class AnalyticalSolver; |
| 22 | +class PartialPlacement; |
| 23 | +class PartialLegalizer; |
| 24 | + |
| 25 | +/** |
| 26 | + * @brief Enumeration of all of the global placers currently implemented in VPR. |
| 27 | + */ |
| 28 | +enum class e_global_placer { |
| 29 | + SimPL // Global placer based on the SimPL paper. |
| 30 | +}; |
| 31 | + |
| 32 | +/** |
| 33 | + * @brief The Global Placer base class |
| 34 | + * |
| 35 | + * This declares the functionality that all Global Placers will use. This |
| 36 | + * provides a standard interface for the global placers so they can be used |
| 37 | + * interchangably. This makes it very easy to test and compare different global |
| 38 | + * placers. |
| 39 | + */ |
| 40 | +class GlobalPlacer { |
| 41 | +public: |
| 42 | + virtual ~GlobalPlacer() {} |
| 43 | + |
| 44 | + /** |
| 45 | + * @brief Constructor of the base GlobalPlacer class |
| 46 | + * |
| 47 | + * @param netlist Netlist of the design at some abstraction level; |
| 48 | + * typically this would have some atoms and groups of |
| 49 | + * atoms (in a pack pattern). |
| 50 | + * @param log_verbosity The verbosity of log messages in the Global |
| 51 | + * Placer. |
| 52 | + */ |
| 53 | + GlobalPlacer(const APNetlist& netlist, int log_verbosity = 1) |
| 54 | + : netlist_(netlist), |
| 55 | + log_verbosity_(log_verbosity) {} |
| 56 | + |
| 57 | + /** |
| 58 | + * @brief Perform global placement on the given netlist. |
| 59 | + * |
| 60 | + * The role of a global placer is to try and find a placement for the given |
| 61 | + * netlist which optimizes some objective function and is mostly legal. |
| 62 | + */ |
| 63 | + virtual PartialPlacement place() = 0; |
| 64 | + |
| 65 | +protected: |
| 66 | + |
| 67 | + /// @brief The APNetlist the global placer is placing. |
| 68 | + const APNetlist& netlist_; |
| 69 | + |
| 70 | + /// @brief The setting of how verbose the log messages should be in the |
| 71 | + /// global placer. Anything larger than zero will display per |
| 72 | + /// iteration status messages. |
| 73 | + int log_verbosity_; |
| 74 | +}; |
| 75 | + |
| 76 | +/** |
| 77 | + * @brief A factory method which creates a Global Placer of the given type. |
| 78 | + */ |
| 79 | +std::unique_ptr<GlobalPlacer> make_global_placer(e_global_placer placer_type, |
| 80 | + const APNetlist& netlist); |
| 81 | + |
| 82 | +/** |
| 83 | + * @brief A Global Placer based on the SimPL work for analytical ASIC placement. |
| 84 | + * https://doi.org/10.1145/2461256.2461279 |
| 85 | + * |
| 86 | + * This placement technique uses a solver to generate a placement that optimizes |
| 87 | + * over some objective function and is likely very illegal (has many overlapping |
| 88 | + * blocks and blocks in the wrong places). This solution represents the "lower- |
| 89 | + * bound" on the solution quality. |
| 90 | + * |
| 91 | + * This technique passes this "lower-bound" solution into a legalizer, which |
| 92 | + * tries to find the closest legal solution to the lower-bound solution (by |
| 93 | + * spreading out blocks and placing them in legal positions). This often |
| 94 | + * destroys the quality of the lower-bound solution, and is considered an |
| 95 | + * "upper-bound" on the solution quality. |
| 96 | + * |
| 97 | + * Each iteration of this global placer, the upper-bound solution is fed into |
| 98 | + * the solver as a "hint" to what a legal solution looks like. This allows the |
| 99 | + * solver to produce another placement which will make decisions knowing where |
| 100 | + * the blocks will end-up in the legal solution. This worstens the quality of |
| 101 | + * the lower-bound solution; however, after passing this solution back into |
| 102 | + * the legalizer, this will likely improve the quality of the upper-bound |
| 103 | + * solution. |
| 104 | + * |
| 105 | + * Over several iterations the upper-bound and lower-bound solutions will |
| 106 | + * approach each other until a good quality, mostly-legal solution is found. |
| 107 | + */ |
| 108 | +class SimPLGlobalPlacer : public GlobalPlacer { |
| 109 | +private: |
| 110 | + |
| 111 | + /// @brief The maximum number of iterations the global placer can perform. |
| 112 | + static constexpr size_t max_num_iterations_ = 100; |
| 113 | + |
| 114 | + /// @brief The target relative gap between the HPWL of the upper-bound and |
| 115 | + /// lower-bound placements. The placer will stop if the difference |
| 116 | + /// between the two bounds, normalized to the upper-bound, is smaller |
| 117 | + /// than this number. |
| 118 | + static constexpr double target_hpwl_relative_gap_ = 0.10; |
| 119 | + |
| 120 | + /// @brief The solver which generates the lower-bound placement. |
| 121 | + std::unique_ptr<AnalyticalSolver> solver_; |
| 122 | + |
| 123 | + /// @brief The legalizer which generates the upper-bound placement. |
| 124 | + std::unique_ptr<PartialLegalizer> partial_legalizer_; |
| 125 | + |
| 126 | +public: |
| 127 | + |
| 128 | + /** |
| 129 | + * @brief Constructor for the SimPL Global Placer |
| 130 | + * |
| 131 | + * Constructs the solver and partial legalizer. |
| 132 | + */ |
| 133 | + SimPLGlobalPlacer(const APNetlist& netlist); |
| 134 | + |
| 135 | + /** |
| 136 | + * @brief Run a SimPL-like global placement algorithm |
| 137 | + * |
| 138 | + * This iteratively runs the solver and legalizer until a good quality and |
| 139 | + * mostly-legal placement is found. |
| 140 | + */ |
| 141 | + PartialPlacement place() final; |
| 142 | +}; |
| 143 | + |
0 commit comments