Skip to content

Cluster attraction groups #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
04c3d8a
Add comment for attraction group gain in clusterer
sfkhalid Jul 5, 2021
d2c2349
Load attraction groups during prepacking
sfkhalid Jul 6, 2021
18966b5
Return highest gain molecule that also matches cluster's attraction g…
sfkhalid Jul 14, 2021
c080163
Added attraction gain to relevent atoms in update_total_gain during c…
sfkhalid Jul 14, 2021
ad5421f
Ran make format and added a routine to add cluster molecule candidate…
sfkhalid Jul 15, 2021
5653598
Added comment to routine for adding cluster molecule candidates by at…
sfkhalid Jul 15, 2021
9f6a324
Used attraction groups class constructor to create attraction groups …
sfkhalid Jul 21, 2021
95cdf56
Added changes to attraction groups class - made some functions inline…
sfkhalid Jul 21, 2021
683a3a9
Added comments to attraction groups class
sfkhalid Jul 21, 2021
f17da20
Got rid of unnecssary variables such as has_attraction_group in t_pb_…
sfkhalid Jul 21, 2021
59afa1c
Made a couple of fixes to get rid of warnings about variables being u…
sfkhalid Jul 22, 2021
b6217be
Refactored the functions that add cluster molecule candidates by movi…
sfkhalid Jul 22, 2021
1ae7dc3
Removed an unused variable to fix compiler warning
sfkhalid Jul 22, 2021
f262a97
Added comments to clarify attraction groups-related code
sfkhalid Jul 26, 2021
4dc0fe4
Added command line option to turn attraction groups on or off
sfkhalid Jul 27, 2021
c928ade
Added comment to attraction groups constructor to explain how it will…
sfkhalid Jul 29, 2021
fbb9337
Changed attraction group default gain
sfkhalid Jul 29, 2021
07127de
Added comments for functions related to adding cluster molecule candi…
sfkhalid Jul 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vpr/src/base/SetupVPR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ void SetupPackerOpts(const t_options& Options,
PackerOpts->high_fanout_threshold = Options.pack_high_fanout_threshold;
PackerOpts->transitive_fanout_threshold = Options.pack_transitive_fanout_threshold;
PackerOpts->feasible_block_array_size = Options.pack_feasible_block_array_size;
PackerOpts->use_attraction_groups = Options.use_attraction_groups;

//TODO: document?
PackerOpts->inter_cluster_net_delay = 1.0; /* DEFAULT */
Expand Down
5 changes: 5 additions & 0 deletions vpr/src/base/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,11 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
.default_value("2")
.show_in(argparse::ShowIn::HELP_ONLY);

pack_grp.add_argument<bool, ParseOnOff>(args.use_attraction_groups, "--use_attraction_groups")
.help("Whether attraction groups are used to make it easier to pack primitives in the same floorplan region together.")
.default_value("on")
.show_in(argparse::ShowIn::HELP_ONLY);

auto& place_grp = parser.add_argument_group("placement options");

place_grp.add_argument(args.Seed, "--seed")
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/read_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct t_options {
argparse::ArgValue<int> pack_feasible_block_array_size;
argparse::ArgValue<std::vector<std::string>> pack_high_fanout_threshold;
argparse::ArgValue<int> pack_verbosity;
argparse::ArgValue<bool> use_attraction_groups;

/* Placement options */
argparse::ArgValue<int> Seed;
Expand Down
1 change: 1 addition & 0 deletions vpr/src/base/vpr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ struct t_packer_opts {
enum e_packer_algorithm packer_algorithm;
std::string device_layout;
e_timing_update_type timing_update_type;
bool use_attraction_groups;
};

/**
Expand Down
54 changes: 54 additions & 0 deletions vpr/src/pack/attraction_groups.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "attraction_groups.h"

AttractionInfo::AttractionInfo(bool attraction_groups_on) {
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& atom_ctx = g_vpr_ctx.atom();
int num_parts = floorplanning_ctx.constraints.get_num_partitions();

//Initialize every atom to have no attraction group id
int num_atoms = atom_ctx.nlist.blocks().size();

atom_attraction_group.resize(num_atoms);
fill(atom_attraction_group.begin(), atom_attraction_group.end(), AttractGroupId::INVALID());

/*
* Create an attraction group for each partition in the floorplanning constraints
* if the packer option for attraction groups is turned on.
*/
if (attraction_groups_on) {
for (int ipart = 0; ipart < num_parts; ipart++) {
PartitionId partid(ipart);
Partition part = floorplanning_ctx.constraints.get_partition(partid);

AttractionGroup group_info;
group_info.group_atoms = floorplanning_ctx.constraints.get_part_atoms(partid);

attraction_groups.push_back(group_info);
}

//Then, fill in the group id for the atoms that do have an attraction group
int num_att_grps = attraction_groups.size();

for (int igroup = 0; igroup < num_att_grps; igroup++) {
AttractGroupId group_id(igroup);

AttractionGroup att_group = attraction_groups[group_id];

for (unsigned int iatom = 0; iatom < att_group.group_atoms.size(); iatom++) {
atom_attraction_group[att_group.group_atoms[iatom]] = group_id;
}
}
}
}

const AttractionGroup& AttractionInfo::get_attraction_group_info(const AttractGroupId group_id) {
return attraction_groups[group_id];
}

void AttractionInfo::set_attraction_group_info(AttractGroupId group_id, const AttractionGroup& group_info) {
attraction_groups[group_id] = group_info;
}

void AttractionInfo::add_attraction_group(const AttractionGroup& group_info) {
attraction_groups.push_back(group_info);
}
108 changes: 108 additions & 0 deletions vpr/src/pack/attraction_groups.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* attraction_groups.h
*
* Created on: Jun. 13, 2021
* Author: khalid88
*/

#ifndef VPR_SRC_PACK_ATTRACTION_GROUPS_H_
#define VPR_SRC_PACK_ATTRACTION_GROUPS_H_

#include "vtr_strong_id.h"
#include "vtr_vector.h"
#include "atom_netlist.h"
#include "globals.h"

/**
* @file
* @brief This file defines the AttractionInfo class, which is used to store atoms in attraction groups, which are
* used during the clustering process.
*
* Overview
* ========
* Attraction groups are used during the clustering process. Atoms in the same attraction groups will be highly desirable to
* be packed together. If an atom is in the same attraction group as an atoms already in the cluster, its gain will be increased
* to reflect the increased desire to pack atoms of the same attraction group together. Currently, the attraction groups are created
* based on which atoms are in the same Partition, from floorplanning constraints. In the future, attraction groups can be used to
* pack atoms together based on other concepts.
*/

/// @brief Type tag for AttractGroupId
struct attraction_id_tag;

/// @brief A unique identifier for an attraction group.
typedef vtr::StrongId<attraction_id_tag> AttractGroupId;

struct AttractionGroup {
//stores all atoms in the attraction group
std::vector<AtomBlockId> group_atoms;

/*
* Atoms belonging to this attraction group will receive this gain if they
* are potential candidates to be put in a cluster with the same attraction group.
*/
float gain = 5;

/*
* If the group is made up from a partition of atoms that are confined to a size one spot
* (i.e. one x, y grid location), the clusterer will immediately put all atoms in the group
* into the same cluster
*/
/* TODO: Add the code in the clusterer that will do the above steps. */
//bool must_be_packed_in_one_cluster = false;
};

class AttractionInfo {
public:
//Constructor that fills in the attraction groups based on vpr's floorplan constraints.
//If no constraints were specified, then no attraction groups will be created.
AttractionInfo(bool attraction_groups_on);

//Setters and getters for the class
AttractGroupId get_atom_attraction_group(const AtomBlockId atom_id);

const AttractionGroup& get_attraction_group_info(const AttractGroupId group_id);

void set_atom_attraction_group(const AtomBlockId atom_id, const AttractGroupId group_id);

void set_attraction_group_info(AttractGroupId group_id, const AttractionGroup& group_info);

float get_attraction_group_gain(const AttractGroupId group_id);

void set_attraction_group_gain(const AttractGroupId group_id, const float new_gain);

void add_attraction_group(const AttractionGroup& group_info);

int num_attraction_groups();

private:
//Store each atom's attraction group assuming each atom is in at most one attraction group
//Atoms with no attraction group will have AttractGroupId::INVALID
vtr::vector<AtomBlockId, AttractGroupId> atom_attraction_group;

//Store atoms and gain value that belong to each attraction group
vtr::vector<AttractGroupId, AttractionGroup> attraction_groups;
};

inline AttractGroupId AttractionInfo::get_atom_attraction_group(const AtomBlockId atom_id) {
return atom_attraction_group[atom_id];
}

inline void AttractionInfo::set_atom_attraction_group(const AtomBlockId atom_id, const AttractGroupId group_id) {
atom_attraction_group[atom_id] = group_id;
attraction_groups[group_id].group_atoms.push_back(atom_id);
}

inline int AttractionInfo::num_attraction_groups() {
return attraction_groups.size();
}

inline float AttractionInfo::get_attraction_group_gain(const AttractGroupId group_id) {
return attraction_groups[group_id].gain;
}

inline void AttractionInfo::set_attraction_group_gain(const AttractGroupId group_id, const float new_gain) {
attraction_groups[group_id].gain = new_gain;
}

#endif /* VPR_SRC_PACK_ATTRACTION_GROUPS_H_ */
Loading