|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Alex Singer |
| 4 | + * @date September 2024 |
| 5 | + * @brief Defines the APNetlist class used to store the connectivity of |
| 6 | + * primitives in the Analytical Placement context. |
| 7 | + * |
| 8 | + * In the context of Analytical Placement, a block is a collection of atoms |
| 9 | + * (primitives) which want to move together. For example, if one atom in a block |
| 10 | + * should be moved one unit to the left, all atoms in the block want to move one |
| 11 | + * unit to the left. |
| 12 | + * |
| 13 | + * An example of a block is pack molecules, which are atoms which were prepacked |
| 14 | + * together. |
| 15 | + * |
| 16 | + * The nets in the netlist represent the logical connections between AP |
| 17 | + * blocks (inferred from the atom block connectivity), where nets which are |
| 18 | + * unused by Analytical Placement are ignored. |
| 19 | + */ |
| 20 | + |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include <string> |
| 24 | +#include "netlist.h" |
| 25 | +#include "ap_netlist_fwd.h" |
| 26 | + |
| 27 | +// Forward declarations |
| 28 | +class t_pack_molecule; |
| 29 | + |
| 30 | +/** |
| 31 | + * @brief Struct to store fixed block location information |
| 32 | + * |
| 33 | + * Currently assumes that blocks are fixed to single locations (not ranges). |
| 34 | + * TODO: This assumption could be relaxed and allow fixing a range of locations. |
| 35 | + * |
| 36 | + * -1 implies that the block is not fixed in that dimension. |
| 37 | + */ |
| 38 | +struct APFixedBlockLoc { |
| 39 | + int x = -1; |
| 40 | + int y = -1; |
| 41 | + int layer_num = -1; |
| 42 | + int sub_tile = -1; |
| 43 | +}; |
| 44 | + |
| 45 | +/** |
| 46 | + * @brief The mobility of a block in the APNetlist |
| 47 | + * TODO: It would be nice if the netlist contained lists of moveable and fixed |
| 48 | + * block ids. |
| 49 | + */ |
| 50 | +enum class APBlockMobility : bool { |
| 51 | + MOVEABLE, // The block is not constrained in any dimension. |
| 52 | + FIXED // The block is fixed. |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
| 56 | + * @brief The netlist used during Analytical Placement |
| 57 | + * |
| 58 | + * This class abstracts the placeable blocks and connections between the blocks |
| 59 | + * away from the atom netlist. An APBlock is assumed to be some collection of |
| 60 | + * primitive blocks and an APNet is assumed to be some connection between the |
| 61 | + * APBlocks. These need not have physical meaning. |
| 62 | + */ |
| 63 | +class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> { |
| 64 | +public: |
| 65 | + /** |
| 66 | + * @brief Constructs a netlist |
| 67 | + * |
| 68 | + * @param name The name of the netlist (e.g. top-level module) |
| 69 | + * @param id A unique identifier for the netlist (e.g. a secure digest of |
| 70 | + * the input file) |
| 71 | + */ |
| 72 | + APNetlist(std::string name = "", std::string id = "") : Netlist(name, id) {} |
| 73 | + |
| 74 | + APNetlist(const APNetlist& rhs) = default; |
| 75 | + APNetlist& operator=(const APNetlist& rhs) = default; |
| 76 | + |
| 77 | +public: // Public Accessors |
| 78 | + /* |
| 79 | + * Blocks |
| 80 | + */ |
| 81 | + |
| 82 | + /// @brief Returns the molecule that this block represents. |
| 83 | + const t_pack_molecule* block_molecule(const APBlockId id) const; |
| 84 | + |
| 85 | + /// @brief Returns the mobility of this block. |
| 86 | + APBlockMobility block_mobility(const APBlockId id) const; |
| 87 | + |
| 88 | + /// @brief Returns the location of this block, if the block is fixed. |
| 89 | + /// This method should not be used if the block is moveable. |
| 90 | + const APFixedBlockLoc& block_loc(const APBlockId id) const; |
| 91 | + |
| 92 | +public: // Public Mutators |
| 93 | + /* |
| 94 | + * Note: all create_*() functions will silently return the appropriate ID |
| 95 | + * if it has already been created. |
| 96 | + */ |
| 97 | + |
| 98 | + /** |
| 99 | + * @brief Create or return an existing block in the netlist |
| 100 | + * |
| 101 | + * @param name The unique name of the block |
| 102 | + * @param mol The molecule the block represents |
| 103 | + */ |
| 104 | + APBlockId create_block(const std::string& name, const t_pack_molecule* mol); |
| 105 | + |
| 106 | + /** |
| 107 | + * @brief Fixes a block at the given location |
| 108 | + * |
| 109 | + * @param id The block to fix |
| 110 | + * @param loc The location to fix the block to |
| 111 | + */ |
| 112 | + void set_block_loc(const APBlockId id, const APFixedBlockLoc& loc); |
| 113 | + |
| 114 | + /** |
| 115 | + * @brief Create or return an existing port in the netlist |
| 116 | + * |
| 117 | + * @param blk_id The block the port is associated with |
| 118 | + * @param name The name of the port |
| 119 | + * @param width The width (number of bits) of the port |
| 120 | + * @param type The type of the port (INPUT, OUTPUT, or CLOCK) |
| 121 | + */ |
| 122 | + APPortId create_port(const APBlockId blk_id, const std::string& name, BitIndex width, PortType type); |
| 123 | + |
| 124 | + /** |
| 125 | + * @brief Create or return an existing pin in the netlist |
| 126 | + * |
| 127 | + * @param port_id The port this pin is associated with |
| 128 | + * @param port_bit The bit index of the pin in the port |
| 129 | + * @param net_id The net the pin drives/sinks |
| 130 | + * @param pin_type The type of the pin (driver/sink) |
| 131 | + * @param is_const Indicates whether the pin holds a constant value (e.g. |
| 132 | + * vcc/gnd) |
| 133 | + */ |
| 134 | + APPinId create_pin(const APPortId port_id, BitIndex port_bit, const APNetId net_id, const PinType pin_type, bool is_const = false); |
| 135 | + |
| 136 | + /** |
| 137 | + * @brief Create an empty, or return an existing net in the netlist |
| 138 | + * |
| 139 | + * @param name The unique name of the net |
| 140 | + */ |
| 141 | + APNetId create_net(const std::string& name); |
| 142 | + |
| 143 | +private: // Private Members |
| 144 | + /* |
| 145 | + * Netlist compression / optimization |
| 146 | + */ |
| 147 | + |
| 148 | + /// @brief Removes invalid components and reorders them |
| 149 | + void clean_blocks_impl(const vtr::vector_map<APBlockId, APBlockId>& block_id_map) override; |
| 150 | + void clean_ports_impl(const vtr::vector_map<APPortId, APPortId>& port_id_map) override; |
| 151 | + void clean_pins_impl(const vtr::vector_map<APPinId, APPinId>& pin_id_map) override; |
| 152 | + void clean_nets_impl(const vtr::vector_map<APNetId, APNetId>& net_id_map) override; |
| 153 | + |
| 154 | + void rebuild_block_refs_impl(const vtr::vector_map<APPinId, APPinId>& pin_id_map, const vtr::vector_map<APPortId, APPortId>& port_id_map) override; |
| 155 | + void rebuild_port_refs_impl(const vtr::vector_map<APBlockId, APBlockId>& block_id_map, const vtr::vector_map<APPinId, APPinId>& pin_id_map) override; |
| 156 | + void rebuild_pin_refs_impl(const vtr::vector_map<APPortId, APPortId>& port_id_map, const vtr::vector_map<APNetId, APNetId>& net_id_map) override; |
| 157 | + void rebuild_net_refs_impl(const vtr::vector_map<APPinId, APPinId>& pin_id_map) override; |
| 158 | + |
| 159 | + /// @brief Shrinks internal data structures to required size to reduce |
| 160 | + /// memory consumption |
| 161 | + void shrink_to_fit_impl() override; |
| 162 | + |
| 163 | + /* |
| 164 | + * Component removal |
| 165 | + */ |
| 166 | + void remove_block_impl(const APBlockId blk_id) override; |
| 167 | + void remove_port_impl(const APPortId port_id) override; |
| 168 | + void remove_pin_impl(const APPinId pin_id) override; |
| 169 | + void remove_net_impl(const APNetId net_id) override; |
| 170 | + |
| 171 | + /* |
| 172 | + * Sanity checks |
| 173 | + */ |
| 174 | + // Verify the internal data structure sizes match |
| 175 | + bool validate_block_sizes_impl(size_t num_blocks) const override; |
| 176 | + bool validate_port_sizes_impl(size_t num_ports) const override; |
| 177 | + bool validate_pin_sizes_impl(size_t num_pins) const override; |
| 178 | + bool validate_net_sizes_impl(size_t num_nets) const override; |
| 179 | + |
| 180 | +private: // Private Data |
| 181 | + /// @brief Molecule of each block |
| 182 | + vtr::vector_map<APBlockId, const t_pack_molecule*> block_molecules_; |
| 183 | + /// @brief Type of each block |
| 184 | + vtr::vector_map<APBlockId, APBlockMobility> block_mobilities_; |
| 185 | + /// @brief Location of each block (if fixed). |
| 186 | + /// NOTE: This vector will likely be quite sparse. |
| 187 | + vtr::vector_map<APBlockId, APFixedBlockLoc> block_locs_; |
| 188 | +}; |
| 189 | + |
0 commit comments