|
| 1 | +/* |
| 2 | + * attraction_groups.h |
| 3 | + * |
| 4 | + * Created on: Jun. 13, 2021 |
| 5 | + * Author: khalid88 |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef VPR_SRC_PACK_ATTRACTION_GROUPS_H_ |
| 9 | +#define VPR_SRC_PACK_ATTRACTION_GROUPS_H_ |
| 10 | + |
| 11 | +#include "vtr_strong_id.h" |
| 12 | +#include "vtr_vector.h" |
| 13 | +#include "atom_netlist.h" |
| 14 | +#include "globals.h" |
| 15 | + |
| 16 | +/** |
| 17 | + * @file |
| 18 | + * @brief This file defines the AttractionInfo class, which is used to store atoms in attraction groups, which are |
| 19 | + * used during the clustering process. |
| 20 | + * |
| 21 | + * Overview |
| 22 | + * ======== |
| 23 | + * Attraction groups are used during the clustering process. Atoms in the same attraction groups will be highly desirable to |
| 24 | + * be packed together. If an atom is in the same attraction group as an atoms already in the cluster, its gain will be increased |
| 25 | + * to reflect the increased desire to pack atoms of the same attraction group together. Currently, the attraction groups are created |
| 26 | + * based on which atoms are in the same Partition, from floorplanning constraints. In the future, attraction groups can be used to |
| 27 | + * pack atoms together based on other concepts. |
| 28 | + */ |
| 29 | + |
| 30 | +/// @brief Type tag for AttractGroupId |
| 31 | +struct attraction_id_tag; |
| 32 | + |
| 33 | +/// @brief A unique identifier for an attraction group. |
| 34 | +typedef vtr::StrongId<attraction_id_tag> AttractGroupId; |
| 35 | + |
| 36 | +struct AttractionGroup { |
| 37 | + //stores all atoms in the attraction group |
| 38 | + std::vector<AtomBlockId> group_atoms; |
| 39 | + |
| 40 | + /* |
| 41 | + * Atoms belonging to this attraction group will receive this gain if they |
| 42 | + * are potential candidates to be put in a cluster with the same attraction group. |
| 43 | + */ |
| 44 | + float gain = 5; |
| 45 | + |
| 46 | + /* |
| 47 | + * If the group is made up from a partition of atoms that are confined to a size one spot |
| 48 | + * (i.e. one x, y grid location), the clusterer will immediately put all atoms in the group |
| 49 | + * into the same cluster |
| 50 | + */ |
| 51 | + /* TODO: Add the code in the clusterer that will do the above steps. */ |
| 52 | + //bool must_be_packed_in_one_cluster = false; |
| 53 | +}; |
| 54 | + |
| 55 | +class AttractionInfo { |
| 56 | + public: |
| 57 | + //Constructor that fills in the attraction groups based on vpr's floorplan constraints. |
| 58 | + //If no constraints were specified, then no attraction groups will be created. |
| 59 | + AttractionInfo(bool attraction_groups_on); |
| 60 | + |
| 61 | + //Setters and getters for the class |
| 62 | + AttractGroupId get_atom_attraction_group(const AtomBlockId atom_id); |
| 63 | + |
| 64 | + const AttractionGroup& get_attraction_group_info(const AttractGroupId group_id); |
| 65 | + |
| 66 | + void set_atom_attraction_group(const AtomBlockId atom_id, const AttractGroupId group_id); |
| 67 | + |
| 68 | + void set_attraction_group_info(AttractGroupId group_id, const AttractionGroup& group_info); |
| 69 | + |
| 70 | + float get_attraction_group_gain(const AttractGroupId group_id); |
| 71 | + |
| 72 | + void set_attraction_group_gain(const AttractGroupId group_id, const float new_gain); |
| 73 | + |
| 74 | + void add_attraction_group(const AttractionGroup& group_info); |
| 75 | + |
| 76 | + int num_attraction_groups(); |
| 77 | + |
| 78 | + private: |
| 79 | + //Store each atom's attraction group assuming each atom is in at most one attraction group |
| 80 | + //Atoms with no attraction group will have AttractGroupId::INVALID |
| 81 | + vtr::vector<AtomBlockId, AttractGroupId> atom_attraction_group; |
| 82 | + |
| 83 | + //Store atoms and gain value that belong to each attraction group |
| 84 | + vtr::vector<AttractGroupId, AttractionGroup> attraction_groups; |
| 85 | +}; |
| 86 | + |
| 87 | +inline AttractGroupId AttractionInfo::get_atom_attraction_group(const AtomBlockId atom_id) { |
| 88 | + return atom_attraction_group[atom_id]; |
| 89 | +} |
| 90 | + |
| 91 | +inline void AttractionInfo::set_atom_attraction_group(const AtomBlockId atom_id, const AttractGroupId group_id) { |
| 92 | + atom_attraction_group[atom_id] = group_id; |
| 93 | + attraction_groups[group_id].group_atoms.push_back(atom_id); |
| 94 | +} |
| 95 | + |
| 96 | +inline int AttractionInfo::num_attraction_groups() { |
| 97 | + return attraction_groups.size(); |
| 98 | +} |
| 99 | + |
| 100 | +inline float AttractionInfo::get_attraction_group_gain(const AttractGroupId group_id) { |
| 101 | + return attraction_groups[group_id].gain; |
| 102 | +} |
| 103 | + |
| 104 | +inline void AttractionInfo::set_attraction_group_gain(const AttractGroupId group_id, const float new_gain) { |
| 105 | + attraction_groups[group_id].gain = new_gain; |
| 106 | +} |
| 107 | + |
| 108 | +#endif /* VPR_SRC_PACK_ATTRACTION_GROUPS_H_ */ |
0 commit comments