Skip to content

Commit 553766b

Browse files
committed
Added more detailed commenting to clustering stage
1 parent b79865b commit 553766b

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

vpr/src/pack/cluster.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void print_pack_status(int num_clb,
169169
int device_height,
170170
AttractionInfo& attraction_groups);
171171

172-
static void update_attraction_group_status(AttractionInfo& attraction_groups);
172+
static void rebuild_attraction_groups(AttractionInfo& attraction_groups);
173173

174174
static void record_molecule_failure(t_pack_molecule* molecule, t_pb* pb);
175175

@@ -443,6 +443,12 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
443443
*
444444
*/
445445

446+
/* This routine returns a map that details the number of used block type instances.
447+
* The bool floorplan_regions_overfull also acts as a return value - it is set to
448+
* true when one or more floorplan regions have more blocks assigned to them than
449+
* they can fit.
450+
*/
451+
446452
/****************************************************************
447453
* Initialization
448454
*****************************************************************/
@@ -638,6 +644,14 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
638644
primitive_candidate_block_types);
639645
prev_molecule = istart;
640646

647+
/*
648+
* When attraction groups are created, the purpose is to pack more densely by adding more molecules
649+
* from the cluster's attraction group to the cluster. In a normal flow, (when attraction groups are
650+
* not on), the cluster keeps being packed until the get_molecule routines return either a repeated
651+
* molecule or a nullptr. When attraction groups are on, we want to keep exploring molecules for the
652+
* cluster until a nullptr is returned. So, the number of repeated molecules allowed is increased to a
653+
* large value.
654+
*/
641655
int max_num_repeated_molecules = 0;
642656
if (attraction_groups.num_attraction_groups() > 0) {
643657
max_num_repeated_molecules = ATTRACTION_GROUPS_MAX_REPEATED_MOLECULES;
@@ -719,6 +733,7 @@ static void print_pack_status(int num_clb,
719733
int device_width,
720734
int device_height,
721735
AttractionInfo& attraction_groups) {
736+
//Print a packing update each time another 4% of molecules have been packed.
722737
const float print_frequency = 0.04;
723738

724739
double percentage = (num_molecules_processed / (double)tot_num_molecules) * 100;
@@ -743,17 +758,17 @@ static void print_pack_status(int num_clb,
743758
fflush(stdout);
744759
mols_since_last_print = 0;
745760
if (attraction_groups.num_attraction_groups() > 0) {
746-
update_attraction_group_status(attraction_groups);
761+
rebuild_attraction_groups(attraction_groups);
747762
}
748763
}
749764
}
750765

751766
/*
752-
* Periodically update the attraction groups to reflect which atoms in them
767+
* Periodically rebuild the attraction groups to reflect which atoms in them
753768
* are still available for new clusters (i.e. remove the atoms that have already
754769
* been packed from the attraction group).
755770
*/
756-
static void update_attraction_group_status(AttractionInfo& attraction_groups) {
771+
static void rebuild_attraction_groups(AttractionInfo& attraction_groups) {
757772
auto& atom_ctx = g_vpr_ctx.atom();
758773

759774
for (int igroup = 0; igroup < attraction_groups.num_attraction_groups(); igroup++) {
@@ -762,6 +777,7 @@ static void update_attraction_group_status(AttractionInfo& attraction_groups) {
762777
AttractionGroup new_att_group_info;
763778

764779
for (AtomBlockId atom : group.group_atoms) {
780+
//If the ClusterBlockId is anything other than invalid, the atom has been packed already
765781
if (atom_ctx.lookup.atom_clb(atom) == ClusterBlockId::INVALID()) {
766782
new_att_group_info.group_atoms.push_back(atom);
767783
}
@@ -785,6 +801,9 @@ static bool is_atom_blk_in_pb(const AtomBlockId blk_id, const t_pb* pb) {
785801
return false;
786802
}
787803

804+
/* Remove blk from list of feasible blocks sorted according to gain
805+
* Useful for removing blocks that are repeatedly failing. If a block
806+
* has been found to be illegal, we don't repeatedly consider it.*/
788807
static void remove_molecule_from_pb_stats_candidates(t_pack_molecule* molecule,
789808
t_pb* pb) {
790809
int molecule_index;
@@ -1528,16 +1547,21 @@ static enum e_block_pack_status try_pack_molecule(t_cluster_placement_stats* clu
15281547
return block_pack_status;
15291548
}
15301549

1550+
/* Record the failure of the molecule in this cluster in the current pb stats.
1551+
* If a molecule fails repeatedly, it's gain will be penalized if packing with
1552+
* attraction groups on. */
15311553
static void record_molecule_failure(t_pack_molecule* molecule, t_pb* pb) {
1532-
//Record the failure of the molecule in this cluster in the current pb stats
1533-
for (unsigned int i_atom = 0; i_atom < molecule->atom_block_ids.size(); i_atom++) {
1534-
auto got = pb->pb_stats->atom_failures.find(molecule->atom_block_ids[i_atom]);
1535-
if (got == pb->pb_stats->atom_failures.end()) {
1536-
pb->pb_stats->atom_failures.insert({molecule->atom_block_ids[i_atom], 1});
1537-
} else {
1538-
got->second++;
1539-
}
1540-
}
1554+
//Only have to record the failure for the first atom in the molecule.
1555+
//The convention when checking if a molecule has failed to pack in the cluster
1556+
//is to check whether the first atoms has been recorded as having failed
1557+
1558+
auto got = pb->pb_stats->atom_failures.find(molecule->atom_block_ids[0]);
1559+
if (got == pb->pb_stats->atom_failures.end()) {
1560+
pb->pb_stats->atom_failures.insert({molecule->atom_block_ids[0], 1});
1561+
} else {
1562+
got->second++;
1563+
}
1564+
15411565
}
15421566

15431567
/**

vpr/src/pack/pack.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ bool try_pack(t_packer_opts* packer_opts,
186186
} else if (pack_iteration >= 2 && pack_iteration < 5 && floorplan_not_fitting) {
187187
VTR_LOG("Floorplan regions are overfull: trying to pack again with more attraction groups exploration and higher target pin utilization. \n");
188188
attraction_groups.create_att_groups_for_overfull_regions();
189-
int att_pulls = attraction_groups.get_att_group_pulls() + 4;
190-
attraction_groups.set_att_group_pulls(att_pulls);
189+
attraction_groups.set_att_group_pulls(4);
191190
t_ext_pin_util pin_util(1.0, 1.0);
192191
target_external_pin_util.set_block_pin_util("clb", pin_util);
193192

0 commit comments

Comments
 (0)