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 6 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
3 changes: 3 additions & 0 deletions vpr/src/base/vpr_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "compressed_grid.h"
#include "metadata_storage.h"
#include "vpr_constraints.h"
#include "attraction_groups.h"

/**
* @brief A Context is collection of state relating to a particular part of VPR
Expand Down Expand Up @@ -416,6 +417,8 @@ struct FloorplanningContext : public Context {
* The constraints on each cluster are computed during the clustering process and can change.
*/
vtr::vector<ClusterBlockId, PartitionRegion> cluster_constraints;

AttractionInfo attraction_groups;
};

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

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

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

void AttractionInfo::set_atom_attraction_group(AtomBlockId atom_id, AttractGroupId group_id) {
atom_attraction_group[atom_id] = group_id;
}

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

void AttractionInfo::add_attraction_group(AttractionGroup group_info) {
attraction_groups.push_back(group_info);
}

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

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

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

void AttractionInfo::initialize_atom_attraction_groups(int num_atoms) {
atom_attraction_group.resize(num_atoms);
fill(atom_attraction_group.begin(), atom_attraction_group.end(), NO_ATTRACTION_GROUP);
}
58 changes: 58 additions & 0 deletions vpr/src/pack/attraction_groups.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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"

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

/// @brief A unique identifier for a partition
typedef vtr::StrongId<attraction_id_tag> AttractGroupId;

struct AttractionGroup {
std::vector<AtomBlockId> group_atoms;
float gain = 5; //give every attraction group an initial gain of 5
bool region_size_one = false;
};

/// @brief sentinel value for indicating that an attraction group has not been specified
constexpr AttractGroupId NO_ATTRACTION_GROUP(-1);

class AttractionInfo {
public:
AttractGroupId get_atom_attraction_group(AtomBlockId atom_id);

AttractionGroup get_attraction_group_info(AttractGroupId group_id);

void set_atom_attraction_group(AtomBlockId atom_id, AttractGroupId group_id);

void set_attraction_group_info(AttractGroupId group_id, AttractionGroup group_info);

void add_attraction_group(AttractionGroup group_info);

int num_attraction_groups();

float get_attraction_group_gain(AttractGroupId group_id);

void set_attraction_group_gain(AttractGroupId group_id, float new_gain);

void initialize_atom_attraction_groups(int num_atoms);

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

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

#endif /* VPR_SRC_PACK_ATTRACTION_GROUPS_H_ */
127 changes: 127 additions & 0 deletions vpr/src/pack/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ void add_cluster_molecule_candidates_by_highfanout_connectivity(t_pb* cur_pb,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
const int feasible_block_array_size);

void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
t_cluster_placement_stats* cluster_placement_stats_ptr,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
const int feasible_block_array_size);

void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
t_cluster_placement_stats* cluster_placement_stats_ptr,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
Expand All @@ -308,6 +313,8 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
int transitive_fanout_threshold,
const int feasible_block_array_size);

t_pack_molecule* sort_cluster_molecule_candidates_by_attraction(t_pb* cur_pb);

static t_pack_molecule* get_molecule_for_cluster(t_pb* cur_pb,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
const bool allow_unrelated_clustering,
Expand Down Expand Up @@ -2041,6 +2048,11 @@ static void update_total_gain(float alpha, float beta, bool timing_driven, bool
*input sharing (sharinggain) and path_length minimization (timinggain)*/
auto& atom_ctx = g_vpr_ctx.atom();
t_pb* cur_pb = pb;

auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& attraction_info = floorplanning_ctx.attraction_groups;
AttractGroupId cluster_att_grp_id = cur_pb->pb_stats->attraction_grp_id;

while (cur_pb) {
for (AtomBlockId blk_id : cur_pb->pb_stats->marked_blocks) {
if (cur_pb->pb_stats->connectiongain.count(blk_id) == 0) {
Expand All @@ -2050,6 +2062,13 @@ static void update_total_gain(float alpha, float beta, bool timing_driven, bool
cur_pb->pb_stats->sharinggain[blk_id] = 0;
}

//Attraction Group stuff
AttractGroupId atom_grp_id = attraction_info.get_atom_attraction_group(blk_id);
if (atom_grp_id != NO_ATTRACTION_GROUP && atom_grp_id == cluster_att_grp_id) {
//increase gain of atom by 1
cur_pb->pb_stats->gain[blk_id]++;
}

/* Todo: This was used to explore different normalization options, can
* be made more efficient once we decide on which one to use*/
int num_used_input_pins = atom_ctx.nlist.block_input_pins(blk_id).size();
Expand Down Expand Up @@ -2115,6 +2134,8 @@ static void update_cluster_stats(const t_pack_molecule* molecule,
molecule_size = get_array_size_of_molecule(molecule);
cb = nullptr;

auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& attraction_info = floorplanning_ctx.attraction_groups;
for (iblock = 0; iblock < molecule_size; iblock++) {
auto blk_id = molecule->atom_block_ids[iblock];
if (!blk_id) {
Expand All @@ -2128,13 +2149,23 @@ static void update_cluster_stats(const t_pack_molecule* molecule,
VTR_ASSERT(atom_pb);

cur_pb = atom_pb->parent_pb;

//Update attraction group
AttractGroupId atom_grp_id = attraction_info.get_atom_attraction_group(blk_id);

while (cur_pb) {
/* reset list of feasible blocks */
if (cur_pb->is_root()) {
cb = cur_pb;
}
cur_pb->pb_stats->num_feasible_blocks = NOT_VALID;
cur_pb->pb_stats->num_child_blocks_in_pb++;

if (atom_grp_id != NO_ATTRACTION_GROUP) {
cur_pb->pb_stats->has_attraction_group = true;
cur_pb->pb_stats->attraction_grp_id = atom_grp_id;
}

cur_pb = cur_pb->parent_pb;
}

Expand Down Expand Up @@ -2418,6 +2449,15 @@ static t_pack_molecule* get_highest_gain_molecule(t_pb* cur_pb,
}
}

add_cluster_molecule_candidates_by_attraction_group(cur_pb, cluster_placement_stats_ptr, atom_molecules, feasible_block_array_size);

//t_pack_molecule* molecule = nullptr;

//Get highest gain molecule that also belongs to attraction group
/*if (cur_pb->pb_stats->num_feasible_blocks > 0) {
* molecule = sort_cluster_molecule_candidates_by_attraction(cur_pb);
* }*/

/* Grab highest gain molecule */
t_pack_molecule* molecule = nullptr;
if (cur_pb->pb_stats->num_feasible_blocks > 0) {
Expand Down Expand Up @@ -2522,6 +2562,50 @@ void add_cluster_molecule_candidates_by_highfanout_connectivity(t_pb* cur_pb,
cur_pb->pb_stats->tie_break_high_fanout_net = AtomNetId::INVALID(); /* Mark off that this high fanout net has been considered */
}

void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment on what this function does. Should have one.
I think this is a file scope function so should be static (I don't think it is in the header).
Should apply the same logic to all added functions: comment their use, and make them static if their declaration is not in the .h file. Comment their use in the .h file if they are declared there, or in the .cpp file (at the definition) if declared static in the .cpp file.
Should also declare all static functions near the top of the .cpp file (where the other static functions are declared).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll add a comment to this function and the other add_cluster_molecule functions.
I made all of the add_cluster_molecule_candidates_by_x functions static and added the declaration for this new one at the top of the file, I'm not sure why that's not showing here. I can see it on this pull request if I go on under files changed though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Maybe I clicked on the wrong link and wasn't looking at the latest commit.

t_cluster_placement_stats* cluster_placement_stats_ptr,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
const int feasible_block_array_size) {
auto& atom_ctx = g_vpr_ctx.atom();
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& attraction_info = floorplanning_ctx.attraction_groups;

//If the current cluster belongs to an attraction group, add all of the atoms
//from that attraction group to the feasible blocks
AttractGroupId grp_id = cur_pb->pb_stats->attraction_grp_id;
if (grp_id != NO_ATTRACTION_GROUP) {
AttractionGroup group = attraction_info.get_attraction_group_info(grp_id);

for (AtomBlockId blk_id : group.group_atoms) {
if (atom_ctx.lookup.atom_clb(blk_id) == ClusterBlockId::INVALID()) {
auto rng = atom_molecules.equal_range(blk_id);
for (const auto& kv : vtr::make_range(rng.first, rng.second)) {
t_pack_molecule* molecule = kv.second;
if (molecule->valid) {
bool success = true;
for (int j = 0; j < get_array_size_of_molecule(molecule); j++) {
if (molecule->atom_block_ids[j]) {
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[j]) == ClusterBlockId::INVALID());
auto blk_id2 = molecule->atom_block_ids[j];
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id2)) {
/* TODO: debating whether to check if placement exists for molecule
* (more robust) or individual atom blocks (faster) */
success = false;
break;
}
}
}
if (success) {
add_molecule_to_pb_stats_candidates(molecule,
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size);
}
}
}
}
}
}
}

void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
t_cluster_placement_stats* cluster_placement_stats_ptr,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
Expand Down Expand Up @@ -2566,6 +2650,49 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
}
}

t_pack_molecule* sort_cluster_molecule_candidates_by_attraction(t_pb* cur_pb) {
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& attraction_info = floorplanning_ctx.attraction_groups;

t_pack_molecule* matching_molecule = nullptr;
bool found_matching_molecule = false;

//Store last matching_molecule (i.e. matching_molecule with highest gain) to return if no matching_molecule is found that matches the attraction group
int num_feas_blocks = cur_pb->pb_stats->num_feasible_blocks;
int last_molecule_index = num_feas_blocks - 1;
t_pack_molecule* last_molecule = cur_pb->pb_stats->feasible_blocks[last_molecule_index];

//get cluster attraction group (if any)
if (cur_pb->pb_stats->has_attraction_group) {
//get the molecule with the highest gain that belongs to the cluster's attraction group
//if no molecule belongs to the attraction group, just return the molecule with the highest gain
for (int i = cur_pb->pb_stats->num_feasible_blocks - 1; i >= 0; i--) {
matching_molecule = cur_pb->pb_stats->feasible_blocks[i];
for (int j = 0; j < get_array_size_of_molecule(matching_molecule); j++) {
if (matching_molecule->atom_block_ids[j]) {
auto blk_id = matching_molecule->atom_block_ids[j];
AttractGroupId atom_group_id = attraction_info.get_atom_attraction_group(blk_id);
if (cur_pb->pb_stats->attraction_grp_id == atom_group_id) {
//Found a matching_molecule that belongs to the same attraction group as the cluster
found_matching_molecule = true;
break;
}
}
}
if (found_matching_molecule) {
break;
}
}
//if no feasible blocks were found that matched the cluster's attraction group, return the last molecule (i.e.highest gain molecule)
if (!found_matching_molecule) {
return last_molecule;
}
} else {
return last_molecule;
}
return matching_molecule;
}

/*****************************************/
static t_pack_molecule* get_molecule_for_cluster(t_pb* cur_pb,
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
Expand Down
3 changes: 3 additions & 0 deletions vpr/src/pack/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ bool try_pack(t_packer_opts* packer_opts,
atom_molecules,
expected_lowest_cost_pb_gnode,
list_of_packing_patterns.size()));

alloc_attraction_groups();

VTR_LOG("Finish prepacking.\n");

if (packer_opts->auto_compute_inter_cluster_net_delay) {
Expand Down
6 changes: 6 additions & 0 deletions vpr/src/pack/pack_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ struct t_pb_stats {
std::vector<std::vector<AtomNetId>> lookahead_input_pins_used; /* [0..pb_graph_node->num_pin_classes-1] vector of input pins of this class that are speculatively used */
std::vector<std::vector<AtomNetId>> lookahead_output_pins_used; /* [0..pb_graph_node->num_pin_classes-1] vector of input pins of this class that are speculatively used */

/*
* Does the t_pb have associated attraction group? If so, store the group.
*/
AttractGroupId attraction_grp_id;
bool has_attraction_group = false;

/* Array of feasible blocks to select from [0..max_array_size-1]
* Sorted in ascending gain order so that the last cluster_ctx.blocks is the most desirable (this makes it easy to pop blocks off the list
*/
Expand Down
33 changes: 33 additions & 0 deletions vpr/src/pack/prepack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "prepack.h"
#include "vpr_utils.h"
#include "echo_files.h"
#include "attraction_groups.h"

/*****************************************/
/*Local Function Declaration */
Expand Down Expand Up @@ -1684,3 +1685,35 @@ static void print_chain_starting_points(t_pack_patterns* chain_pattern) {

VTR_LOG("\n");
}

void alloc_attraction_groups() {
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
auto& atom_ctx = g_vpr_ctx.atom();
int num_parts = floorplanning_ctx.constraints.get_num_partitions();

for (int i = 0; i < num_parts; i++) {
PartitionId part_id(i);
Partition part = floorplanning_ctx.constraints.get_partition(part_id);

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

floorplanning_ctx.attraction_groups.add_attraction_group(group_info);
}

int num_att_grps = floorplanning_ctx.attraction_groups.num_attraction_groups();

floorplanning_ctx.attraction_groups.initialize_atom_attraction_groups(atom_ctx.nlist.blocks().size());

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

AttractionGroup att_group = floorplanning_ctx.attraction_groups.get_attraction_group_info(group_id);

for (unsigned int k = 0; k < att_group.group_atoms.size(); k++) {
floorplanning_ctx.attraction_groups.set_atom_attraction_group(att_group.group_atoms[k], group_id);
}
}

VTR_LOG("%d attraction groups created during prepacking. \n", num_att_grps);
}
2 changes: 2 additions & 0 deletions vpr/src/pack/prepack.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ t_pack_molecule* alloc_and_load_pack_molecules(t_pack_patterns* list_of_pack_pat

void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);

void alloc_attraction_groups();

#endif