Skip to content

Commit 110bae4

Browse files
authored
Merge pull request #1802 from verilog-to-routing/cluster_attraction_groups
Cluster attraction groups
2 parents c4279dd + 07127de commit 110bae4

11 files changed

+344
-102
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ void SetupPackerOpts(const t_options& Options,
495495
PackerOpts->high_fanout_threshold = Options.pack_high_fanout_threshold;
496496
PackerOpts->transitive_fanout_threshold = Options.pack_transitive_fanout_threshold;
497497
PackerOpts->feasible_block_array_size = Options.pack_feasible_block_array_size;
498+
PackerOpts->use_attraction_groups = Options.use_attraction_groups;
498499

499500
//TODO: document?
500501
PackerOpts->inter_cluster_net_delay = 1.0; /* DEFAULT */

vpr/src/base/read_options.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,11 @@ argparse::ArgumentParser create_arg_parser(std::string prog_name, t_options& arg
16381638
.default_value("2")
16391639
.show_in(argparse::ShowIn::HELP_ONLY);
16401640

1641+
pack_grp.add_argument<bool, ParseOnOff>(args.use_attraction_groups, "--use_attraction_groups")
1642+
.help("Whether attraction groups are used to make it easier to pack primitives in the same floorplan region together.")
1643+
.default_value("on")
1644+
.show_in(argparse::ShowIn::HELP_ONLY);
1645+
16411646
auto& place_grp = parser.add_argument_group("placement options");
16421647

16431648
place_grp.add_argument(args.Seed, "--seed")

vpr/src/base/read_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct t_options {
9191
argparse::ArgValue<int> pack_feasible_block_array_size;
9292
argparse::ArgValue<std::vector<std::string>> pack_high_fanout_threshold;
9393
argparse::ArgValue<int> pack_verbosity;
94+
argparse::ArgValue<bool> use_attraction_groups;
9495

9596
/* Placement options */
9697
argparse::ArgValue<int> Seed;

vpr/src/base/vpr_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ struct t_packer_opts {
814814
enum e_packer_algorithm packer_algorithm;
815815
std::string device_layout;
816816
e_timing_update_type timing_update_type;
817+
bool use_attraction_groups;
817818
};
818819

819820
/**

vpr/src/pack/attraction_groups.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "attraction_groups.h"
2+
3+
AttractionInfo::AttractionInfo(bool attraction_groups_on) {
4+
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
5+
auto& atom_ctx = g_vpr_ctx.atom();
6+
int num_parts = floorplanning_ctx.constraints.get_num_partitions();
7+
8+
//Initialize every atom to have no attraction group id
9+
int num_atoms = atom_ctx.nlist.blocks().size();
10+
11+
atom_attraction_group.resize(num_atoms);
12+
fill(atom_attraction_group.begin(), atom_attraction_group.end(), AttractGroupId::INVALID());
13+
14+
/*
15+
* Create an attraction group for each partition in the floorplanning constraints
16+
* if the packer option for attraction groups is turned on.
17+
*/
18+
if (attraction_groups_on) {
19+
for (int ipart = 0; ipart < num_parts; ipart++) {
20+
PartitionId partid(ipart);
21+
Partition part = floorplanning_ctx.constraints.get_partition(partid);
22+
23+
AttractionGroup group_info;
24+
group_info.group_atoms = floorplanning_ctx.constraints.get_part_atoms(partid);
25+
26+
attraction_groups.push_back(group_info);
27+
}
28+
29+
//Then, fill in the group id for the atoms that do have an attraction group
30+
int num_att_grps = attraction_groups.size();
31+
32+
for (int igroup = 0; igroup < num_att_grps; igroup++) {
33+
AttractGroupId group_id(igroup);
34+
35+
AttractionGroup att_group = attraction_groups[group_id];
36+
37+
for (unsigned int iatom = 0; iatom < att_group.group_atoms.size(); iatom++) {
38+
atom_attraction_group[att_group.group_atoms[iatom]] = group_id;
39+
}
40+
}
41+
}
42+
}
43+
44+
const AttractionGroup& AttractionInfo::get_attraction_group_info(const AttractGroupId group_id) {
45+
return attraction_groups[group_id];
46+
}
47+
48+
void AttractionInfo::set_attraction_group_info(AttractGroupId group_id, const AttractionGroup& group_info) {
49+
attraction_groups[group_id] = group_info;
50+
}
51+
52+
void AttractionInfo::add_attraction_group(const AttractionGroup& group_info) {
53+
attraction_groups.push_back(group_info);
54+
}

vpr/src/pack/attraction_groups.h

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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

Comments
 (0)