Skip to content

Commit 92babb5

Browse files
Merge pull request #2796 from AlexandreSinger/feature-prepacker-rework
[Prepacker] Removed Valid Flag From Molecules
2 parents 7a2cf8d + a34ebf1 commit 92babb5

9 files changed

+53
-103
lines changed

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ enum e_pack_pattern_molecule_type {
384384
* t_pack_pattern_block->block_id
385385
* chain_info : if this is a molecule representing a chained pack pattern, this data structure will
386386
* hold the data shared between all molecules forming a chain together.
387-
* valid : whether the molecule is still valid for packing or not.
388387
* num_blocks : maximum number of atom blocks that can fit in this molecule
389388
* root : index of the pack_pattern->root_block in the atom_blocks_ids. root_block_id = atom_block_ids[root]
390389
* base_gain : intrinsic "goodness" score for molecule independent of rest of netlist
@@ -393,7 +392,6 @@ enum e_pack_pattern_molecule_type {
393392
class t_pack_molecule {
394393
public:
395394
/* general molecule info */
396-
bool valid;
397395
float base_gain;
398396
enum e_pack_pattern_molecule_type type;
399397

vpr/src/pack/cluster.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
145145

146146
const t_molecule_stats max_molecule_stats = prepacker.calc_max_molecule_stats(atom_ctx.nlist);
147147

148-
prepacker.mark_all_molecules_valid();
149-
150148
cluster_stats.num_molecules = prepacker.get_num_molecules();
151149

152150
if (packer_opts.hill_climbing_flag) {

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,36 @@ static void update_molecule_chain_info(t_pack_molecule* chain_molecule, const t_
997997
VTR_ASSERT(false);
998998
}
999999

1000+
/*
1001+
* @brief Reset molecule information created while trying to cluster it.
1002+
*
1003+
* This code only resets information that has to do with long chains.
1004+
*
1005+
* TODO: This information should not be stored in the molecule, but should be
1006+
* stored in the ClusterLegalizer class instead.
1007+
*
1008+
* TODO: This code may be removable. Tried turning it off and found no test
1009+
* failures or QoR degredations. Should be investigated in more detail.
1010+
*/
1011+
static void reset_molecule_info(t_pack_molecule* mol) {
1012+
// when invalidating a molecule check if it's a chain molecule
1013+
// that is part of a long chain. If so, check if this molecule
1014+
// has modified the chain_id value based on the stale packing
1015+
// then reset the chain id and the first packed molecule pointer
1016+
// this is packing is being reset
1017+
if (mol->is_chain()
1018+
&& mol->chain_info->is_long_chain
1019+
&& mol->chain_info->first_packed_molecule == mol) {
1020+
mol->chain_info->first_packed_molecule = nullptr;
1021+
mol->chain_info->chain_id = -1;
1022+
}
1023+
}
1024+
10001025
/*
10011026
* @brief Revert trial atom block iblock and free up memory space accordingly.
10021027
*/
10031028
static void revert_place_atom_block(const AtomBlockId blk_id,
10041029
t_lb_router_data* router_data,
1005-
const Prepacker& prepacker,
10061030
vtr::vector_map<AtomBlockId, LegalizationClusterId>& atom_cluster) {
10071031
const AtomContext& atom_ctx = g_vpr_ctx.atom();
10081032
AtomContext& mutable_atom_ctx = g_vpr_ctx.mutable_atom();
@@ -1020,7 +1044,6 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
10201044
*/
10211045

10221046
t_pb* next = pb->parent_pb;
1023-
revalid_molecules(pb, prepacker);
10241047
free_pb(pb);
10251048
pb = next;
10261049

@@ -1037,7 +1060,6 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
10371060
/* If the code gets here, then that means that placing the initial seed molecule
10381061
* failed, don't free the actual complex block itself as the seed needs to find
10391062
* another placement */
1040-
revalid_molecules(pb, prepacker);
10411063
free_pb(pb);
10421064
}
10431065
}
@@ -1386,14 +1408,6 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
13861408
if (!atom_blk_id.is_valid())
13871409
continue;
13881410

1389-
/* invalidate all molecules that share atom block with current molecule */
1390-
t_pack_molecule* cur_molecule = prepacker_.get_atom_molecule(atom_blk_id);
1391-
// TODO: This should really be named better. Something like
1392-
// "is_clustered". and then it should be set to true.
1393-
// Right now, valid implies "not clustered" which is
1394-
// confusing.
1395-
cur_molecule->valid = false;
1396-
13971411
commit_primitive(cluster.placement_stats, primitives_list[i]);
13981412

13991413
atom_cluster_[atom_blk_id] = cluster_id;
@@ -1424,9 +1438,10 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
14241438
for (int i = 0; i < failed_location; i++) {
14251439
AtomBlockId atom_blk_id = molecule->atom_block_ids[i];
14261440
if (atom_blk_id) {
1427-
revert_place_atom_block(atom_blk_id, cluster.router_data, prepacker_, atom_cluster_);
1441+
revert_place_atom_block(atom_blk_id, cluster.router_data, atom_cluster_);
14281442
}
14291443
}
1444+
reset_molecule_info(molecule);
14301445

14311446
// Record the failure of this molecule in the current pb stats
14321447
record_molecule_failure(molecule, cluster.pb);
@@ -1562,19 +1577,15 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
15621577
VTR_ASSERT_SAFE(molecule_cluster_.find(mol) != molecule_cluster_.end() &&
15631578
molecule_cluster_[mol] == cluster_id);
15641579
molecule_cluster_[mol] = LegalizationClusterId::INVALID();
1565-
// The overall clustering algorithm uses this valid flag to indicate
1566-
// that a molecule has not been packed (clustered) yet. Since we are
1567-
// destroying a cluster, all of its molecules are now no longer clustered
1568-
// so they are all validated.
1569-
mol->valid = true;
15701580
// Revert the placement of all blocks in the molecule.
15711581
int molecule_size = get_array_size_of_molecule(mol);
15721582
for (int i = 0; i < molecule_size; i++) {
15731583
AtomBlockId atom_blk_id = mol->atom_block_ids[i];
15741584
if (atom_blk_id) {
1575-
revert_place_atom_block(atom_blk_id, cluster.router_data, prepacker_, atom_cluster_);
1585+
revert_place_atom_block(atom_blk_id, cluster.router_data, atom_cluster_);
15761586
}
15771587
}
1588+
reset_molecule_info(mol);
15781589
}
15791590
cluster.molecules.clear();
15801591
// Free the rest of the cluster data.

vpr/src/pack/cluster_legalizer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,21 @@ class ClusterLegalizer {
434434
return get_atom_cluster(blk_id) != LegalizationClusterId::INVALID();
435435
}
436436

437+
/// @brief Returns true if the given molecule has been packed into a
438+
/// cluster, false otherwise.
439+
inline bool is_mol_clustered(t_pack_molecule* mol) const {
440+
VTR_ASSERT_SAFE(mol != nullptr);
441+
// Check if the molecule has been assigned a cluster. It has not been
442+
// assigned a cluster if it does not have an entry in the map or if the
443+
// ID of the cluster it is assigned to is invalid.
444+
const auto iter = molecule_cluster_.find(mol);
445+
if (iter == molecule_cluster_.end())
446+
return false;
447+
if (!iter->second.is_valid())
448+
return false;
449+
return true;
450+
}
451+
437452
/// @brief Returns a reference to the target_external_pin_util object. This
438453
/// allows the user to modify the external pin utilization if needed.
439454
inline t_ext_pin_util_targets& get_target_external_pin_util() {

vpr/src/pack/cluster_util.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ t_pack_molecule* get_molecule_by_num_ext_inputs(const int ext_inps,
394394
t_molecule_link* ptr = unclustered_list_head[ext_inps].next;
395395
while (ptr != nullptr) {
396396
/* TODO: Get better candidate atom block in future, eg. return most timing critical or some other smarter metric */
397-
if (ptr->moleculeptr->valid) {
397+
if (!cluster_legalizer.is_mol_clustered(ptr->moleculeptr)) {
398398
/* TODO: I should be using a better filtering check especially when I'm
399399
* dealing with multiple clock/multiple global reset signals where the clock/reset
400400
* packed in matters, need to do later when I have the circuits to check my work */
@@ -1197,7 +1197,7 @@ t_pack_molecule* get_highest_gain_molecule(t_pb* cur_pb,
11971197
cur_pb->pb_stats->num_feasible_blocks--;
11981198
int index = cur_pb->pb_stats->num_feasible_blocks;
11991199
molecule = cur_pb->pb_stats->feasible_blocks[index];
1200-
VTR_ASSERT(molecule->valid == true);
1200+
VTR_ASSERT(!cluster_legalizer.is_mol_clustered(molecule));
12011201
return molecule;
12021202
}
12031203

@@ -1218,7 +1218,7 @@ void add_cluster_molecule_candidates_by_connectivity_and_timing(t_pb* cur_pb,
12181218
for (AtomBlockId blk_id : cur_pb->pb_stats->marked_blocks) {
12191219
if (!cluster_legalizer.is_atom_clustered(blk_id)) {
12201220
t_pack_molecule* molecule = prepacker.get_atom_molecule(blk_id);
1221-
if (molecule->valid) {
1221+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
12221222
if (cluster_legalizer.is_molecule_compatible(molecule, legalization_cluster_id)) {
12231223
add_molecule_to_pb_stats_candidates(molecule,
12241224
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size, attraction_groups);
@@ -1251,7 +1251,7 @@ void add_cluster_molecule_candidates_by_highfanout_connectivity(t_pb* cur_pb,
12511251

12521252
if (!cluster_legalizer.is_atom_clustered(blk_id)) {
12531253
t_pack_molecule* molecule = prepacker.get_atom_molecule(blk_id);
1254-
if (molecule->valid) {
1254+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
12551255
if (cluster_legalizer.is_molecule_compatible(molecule, legalization_cluster_id)) {
12561256
add_molecule_to_pb_stats_candidates(molecule,
12571257
cur_pb->pb_stats->gain, cur_pb, std::min(feasible_block_array_size, AAPACK_MAX_HIGH_FANOUT_EXPLORE), attraction_groups);
@@ -1328,7 +1328,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
13281328
if (!cluster_legalizer.is_atom_clustered(atom_id)
13291329
&& std::find(candidate_types.begin(), candidate_types.end(), cluster_type) != candidate_types.end()) {
13301330
t_pack_molecule* molecule = prepacker.get_atom_molecule(atom_id);
1331-
if (molecule->valid) {
1331+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
13321332
if (cluster_legalizer.is_molecule_compatible(molecule, legalization_cluster_id)) {
13331333
add_molecule_to_pb_stats_candidates(molecule,
13341334
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size, attraction_groups);
@@ -1359,7 +1359,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
13591359
if (!cluster_legalizer.is_atom_clustered(blk_id)
13601360
&& std::find(candidate_types.begin(), candidate_types.end(), cluster_type) != candidate_types.end()) {
13611361
t_pack_molecule* molecule = prepacker.get_atom_molecule(blk_id);
1362-
if (molecule->valid) {
1362+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
13631363
if (cluster_legalizer.is_molecule_compatible(molecule, legalization_cluster_id)) {
13641364
add_molecule_to_pb_stats_candidates(molecule,
13651365
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size, attraction_groups);
@@ -1390,7 +1390,7 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
13901390
/* Only consider candidates that pass a very simple legality check */
13911391
for (const auto& transitive_candidate : cur_pb->pb_stats->transitive_fanout_candidates) {
13921392
t_pack_molecule* molecule = transitive_candidate.second;
1393-
if (molecule->valid) {
1393+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
13941394
if (cluster_legalizer.is_molecule_compatible(molecule, legalization_cluster_id)) {
13951395
add_molecule_to_pb_stats_candidates(molecule,
13961396
cur_pb->pb_stats->gain, cur_pb, std::min(feasible_block_array_size, AAPACK_MAX_TRANSITIVE_EXPLORE), attraction_groups);
@@ -1659,7 +1659,7 @@ t_pack_molecule* get_highest_gain_seed_molecule(int& seed_index,
16591659
t_pack_molecule* best = nullptr;
16601660

16611661
t_pack_molecule* molecule = prepacker.get_atom_molecule(blk_id);
1662-
if (molecule->valid) {
1662+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
16631663
if (best == nullptr || (best->base_gain) < (molecule->base_gain)) {
16641664
best = molecule;
16651665
}
@@ -1764,7 +1764,7 @@ void load_transitive_fanout_candidates(LegalizationClusterId legalization_cluste
17641764
pb_stats->gain[blk_id] += 0.001;
17651765
}
17661766
t_pack_molecule* molecule = prepacker.get_atom_molecule(blk_id);
1767-
if (molecule->valid) {
1767+
if (!cluster_legalizer.is_mol_clustered(molecule)) {
17681768
transitive_fanout_candidates.insert({molecule->atom_block_ids[molecule->root], molecule});
17691769
}
17701770
}

vpr/src/pack/prepack.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ static t_pack_molecule* alloc_and_load_pack_molecules(t_pack_patterns* list_of_p
904904
bool rng_empty = (rng.first == rng.second);
905905
if (rng_empty) {
906906
cur_molecule = new t_pack_molecule;
907-
cur_molecule->valid = true;
908907
cur_molecule->type = MOLECULE_SINGLE_ATOM;
909908
cur_molecule->num_blocks = 1;
910909
cur_molecule->root = 0;
@@ -983,7 +982,6 @@ static t_pack_molecule* try_create_molecule(t_pack_patterns* list_of_pack_patter
983982
}
984983

985984
molecule = new t_pack_molecule;
986-
molecule->valid = true;
987985
molecule->type = MOLECULE_FORCED_PACK;
988986
molecule->pack_pattern = pack_pattern;
989987
molecule->atom_block_ids = std::vector<AtomBlockId>(pack_pattern->num_blocks); //Initializes invalid

vpr/src/pack/prepack.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,6 @@ class Prepacker {
119119
return molecules;
120120
}
121121

122-
/**
123-
* @brief Marks all of the molecules as valid.
124-
*
125-
* Within clustering, the valid flag of a molecule is used to signify if any
126-
* of the atoms in the molecule has been packed into a cluster yet or not.
127-
* If any atom in the molecule has been packed, the flag will be false.
128-
*
129-
* This method is used before clustering to mark all the molecules as
130-
* unpacked.
131-
*/
132-
inline void mark_all_molecules_valid() {
133-
t_pack_molecule* molecule_head = list_of_pack_molecules;
134-
for (auto cur_molecule = molecule_head; cur_molecule != nullptr; cur_molecule = cur_molecule->next) {
135-
cur_molecule->valid = true;
136-
}
137-
}
138-
139122
/**
140123
* @brief Calculates maximum molecule statistics accross all molecules,
141124
*/

vpr/src/util/vpr_utils.cpp

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,58 +1539,6 @@ void free_pb(t_pb* pb) {
15391539
free_pb_stats(pb);
15401540
}
15411541

1542-
void revalid_molecules(const t_pb* pb, const Prepacker& prepacker) {
1543-
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;
1544-
1545-
if (pb_type->blif_model == nullptr) {
1546-
int mode = pb->mode;
1547-
for (int i = 0; i < pb_type->modes[mode].num_pb_type_children && pb->child_pbs != nullptr; i++) {
1548-
for (int j = 0; j < pb_type->modes[mode].pb_type_children[i].num_pb && pb->child_pbs[i] != nullptr; j++) {
1549-
if (pb->child_pbs[i][j].name != nullptr || pb->child_pbs[i][j].child_pbs != nullptr) {
1550-
revalid_molecules(&pb->child_pbs[i][j], prepacker);
1551-
}
1552-
}
1553-
}
1554-
} else {
1555-
//Primitive
1556-
auto& atom_ctx = g_vpr_ctx.mutable_atom();
1557-
1558-
auto blk_id = atom_ctx.lookup.pb_atom(pb);
1559-
if (blk_id) {
1560-
/* If any molecules were marked invalid because of this logic block getting packed, mark them valid */
1561-
1562-
//Update atom netlist mapping
1563-
atom_ctx.lookup.set_atom_clb(blk_id, ClusterBlockId::INVALID());
1564-
atom_ctx.lookup.set_atom_pb(blk_id, nullptr);
1565-
1566-
t_pack_molecule* cur_molecule = prepacker.get_atom_molecule(blk_id);
1567-
if (cur_molecule->valid == false) {
1568-
int i;
1569-
for (i = 0; i < get_array_size_of_molecule(cur_molecule); i++) {
1570-
if (cur_molecule->atom_block_ids[i]) {
1571-
if (atom_ctx.lookup.atom_clb(cur_molecule->atom_block_ids[i]) != ClusterBlockId::INVALID()) {
1572-
break;
1573-
}
1574-
}
1575-
}
1576-
/* All atom blocks are open for this molecule, place back in queue */
1577-
if (i == get_array_size_of_molecule(cur_molecule)) {
1578-
cur_molecule->valid = true;
1579-
// when invalidating a molecule check if it's a chain molecule
1580-
// that is part of a long chain. If so, check if this molecule
1581-
// have modified the chain_id value based on the stale packing
1582-
// then reset the chain id and the first packed molecule pointer
1583-
// this is packing is being reset
1584-
if (cur_molecule->is_chain() && cur_molecule->chain_info->is_long_chain && cur_molecule->chain_info->first_packed_molecule == cur_molecule) {
1585-
cur_molecule->chain_info->first_packed_molecule = nullptr;
1586-
cur_molecule->chain_info->chain_id = -1;
1587-
}
1588-
}
1589-
}
1590-
}
1591-
}
1592-
}
1593-
15941542
void free_pb_stats(t_pb* pb) {
15951543
if (pb) {
15961544
if (pb->pb_stats == nullptr) {

vpr/src/util/vpr_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ void parse_direct_pin_name(char* src_string, int line, int* start_pin_index, int
222222

223223
void free_pb_stats(t_pb* pb);
224224
void free_pb(t_pb* pb);
225-
void revalid_molecules(const t_pb* pb, const Prepacker& prepacker);
226225

227226
void print_switch_usage();
228227
void print_usage_by_wire_length();

0 commit comments

Comments
 (0)