-
Notifications
You must be signed in to change notification settings - Fork 415
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
Changes from 6 commits
04c3d8a
d2c2349
18966b5
c080163
ad5421f
5653598
9f6a324
95cdf56
683a3a9
f17da20
59afa1c
b6217be
1ae7dc3
f262a97
4dc0fe4
c928ade
fbb9337
07127de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return atom_attraction_group[atom_id]; | ||
} | ||
|
||
AttractionGroup AttractionInfo::get_attraction_group_info(AttractGroupId group_id) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return attraction_groups[group_id]; | ||
} | ||
|
||
void AttractionInfo::set_atom_attraction_group(AtomBlockId atom_id, AttractGroupId group_id) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
atom_attraction_group.resize(num_atoms); | ||
fill(atom_attraction_group.begin(), atom_attraction_group.end(), NO_ATTRACTION_GROUP); | ||
} |
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" | ||
|
||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// @brief Type tag for AttractGroupId | ||
struct attraction_id_tag; | ||
|
||
/// @brief A unique identifier for a partition | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
/// @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); | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t_cluster_placement_stats* cluster_placement_stats_ptr, | ||
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules, | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const int feasible_block_array_size); | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb, | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t_cluster_placement_stats* cluster_placement_stats_ptr, | ||
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules, | ||
|
@@ -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, | ||
|
@@ -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) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -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 | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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]++; | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/* 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(); | ||
|
@@ -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(); | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) { | ||
|
@@ -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) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cur_pb->pb_stats->has_attraction_group = true; | ||
cur_pb->pb_stats->attraction_grp_id = atom_grp_id; | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
cur_pb = cur_pb->parent_pb; | ||
} | ||
|
||
|
@@ -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 | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/*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) { | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No comment on what this function does. Should have one. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
t_pack_molecule* molecule = kv.second; | ||
if (molecule->valid) { | ||
bool success = true; | ||
for (int j = 0; j < get_array_size_of_molecule(molecule); j++) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
|
@@ -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) { | ||
sfkhalid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
|
Uh oh!
There was an error while loading. Please reload this page.