Skip to content

Commit a3f33ca

Browse files
[Prepacker] Removed Valid Flag From Molecules
Pack molecules originally contained a flag called "valid" which signified that the molecule has not been clustered yet. This flag is not necessary since the Cluster Legalizer maintains this information internally. Removed the valid flag from the pack molecule struct. See issue verilog-to-routing#2791
1 parent 660ecab commit a3f33ca

8 files changed

+76
-96
lines changed

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: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,58 @@ static void update_molecule_chain_info(t_pack_molecule* chain_molecule, const t_
997997
VTR_ASSERT(false);
998998
}
999999

1000+
static void revalid_molecules(const t_pb* pb, const Prepacker& prepacker) {
1001+
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;
1002+
1003+
if (pb_type->blif_model == nullptr) {
1004+
int mode = pb->mode;
1005+
for (int i = 0; i < pb_type->modes[mode].num_pb_type_children && pb->child_pbs != nullptr; i++) {
1006+
for (int j = 0; j < pb_type->modes[mode].pb_type_children[i].num_pb && pb->child_pbs[i] != nullptr; j++) {
1007+
if (pb->child_pbs[i][j].name != nullptr || pb->child_pbs[i][j].child_pbs != nullptr) {
1008+
revalid_molecules(&pb->child_pbs[i][j], prepacker);
1009+
}
1010+
}
1011+
}
1012+
} else {
1013+
//Primitive
1014+
auto& atom_ctx = g_vpr_ctx.mutable_atom();
1015+
1016+
auto blk_id = atom_ctx.lookup.pb_atom(pb);
1017+
if (blk_id) {
1018+
/* If any molecules were marked invalid because of this logic block getting packed, mark them valid */
1019+
1020+
//Update atom netlist mapping
1021+
atom_ctx.lookup.set_atom_clb(blk_id, ClusterBlockId::INVALID());
1022+
atom_ctx.lookup.set_atom_pb(blk_id, nullptr);
1023+
1024+
t_pack_molecule* cur_molecule = prepacker.get_atom_molecule(blk_id);
1025+
if (cur_molecule->valid == false) {
1026+
int i;
1027+
for (i = 0; i < get_array_size_of_molecule(cur_molecule); i++) {
1028+
if (cur_molecule->atom_block_ids[i]) {
1029+
if (atom_ctx.lookup.atom_clb(cur_molecule->atom_block_ids[i]) != ClusterBlockId::INVALID()) {
1030+
break;
1031+
}
1032+
}
1033+
}
1034+
/* All atom blocks are open for this molecule, place back in queue */
1035+
if (i == get_array_size_of_molecule(cur_molecule)) {
1036+
cur_molecule->valid = true;
1037+
// when invalidating a molecule check if it's a chain molecule
1038+
// that is part of a long chain. If so, check if this molecule
1039+
// have modified the chain_id value based on the stale packing
1040+
// then reset the chain id and the first packed molecule pointer
1041+
// this is packing is being reset
1042+
if (cur_molecule->is_chain() && cur_molecule->chain_info->is_long_chain && cur_molecule->chain_info->first_packed_molecule == cur_molecule) {
1043+
cur_molecule->chain_info->first_packed_molecule = nullptr;
1044+
cur_molecule->chain_info->chain_id = -1;
1045+
}
1046+
}
1047+
}
1048+
}
1049+
}
1050+
}
1051+
10001052
/*
10011053
* @brief Revert trial atom block iblock and free up memory space accordingly.
10021054
*/
@@ -1386,14 +1438,6 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
13861438
if (!atom_blk_id.is_valid())
13871439
continue;
13881440

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-
13971441
commit_primitive(cluster.placement_stats, primitives_list[i]);
13981442

13991443
atom_cluster_[atom_blk_id] = cluster_id;
@@ -1562,11 +1606,6 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
15621606
VTR_ASSERT_SAFE(molecule_cluster_.find(mol) != molecule_cluster_.end() &&
15631607
molecule_cluster_[mol] == cluster_id);
15641608
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;
15701609
// Revert the placement of all blocks in the molecule.
15711610
int molecule_size = get_array_size_of_molecule(mol);
15721611
for (int i = 0; i < molecule_size; i++) {

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)