Skip to content

Commit

Permalink
[Prepacker] Removed Revalid Molecules Method
Browse files Browse the repository at this point in the history
Found that the revalid molecules method was more complicated than it
needed to be in the context of the Cluster Legalizer. Simplified its
code so that it makes more sense.
  • Loading branch information
AlexandreSinger committed Nov 5, 2024
1 parent 3aecece commit a34ebf1
Showing 1 changed file with 25 additions and 62 deletions.
87 changes: 25 additions & 62 deletions vpr/src/pack/cluster_legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,61 +997,28 @@ static void update_molecule_chain_info(t_pack_molecule* chain_molecule, const t_
VTR_ASSERT(false);
}

/**
* @brief Revalidate the molecules associated with this pb. The mol_validated
* flag is used to check if the mol has already been validated.
/*
* @brief Reset molecule information created while trying to cluster it.
*
* This code only resets information that has to do with long chains.
*
* TODO: This information should not be stored in the molecule, but should be
* stored in the ClusterLegalizer class instead.
*
* TODO: This code may be removable. Tried turning it off and found no test
* failures or QoR degredations. Should be investigated in more detail.
*/
static void revalid_molecules(const t_pb* pb,
bool &mol_validated,
const Prepacker& prepacker) {
const t_pb_type* pb_type = pb->pb_graph_node->pb_type;

if (pb_type->blif_model == nullptr) {
int mode = pb->mode;
for (int i = 0; i < pb_type->modes[mode].num_pb_type_children && pb->child_pbs != nullptr; i++) {
for (int j = 0; j < pb_type->modes[mode].pb_type_children[i].num_pb && pb->child_pbs[i] != nullptr; j++) {
if (pb->child_pbs[i][j].name != nullptr || pb->child_pbs[i][j].child_pbs != nullptr) {
revalid_molecules(&pb->child_pbs[i][j], mol_validated, prepacker);
}
}
}
} else {
//Primitive
auto& atom_ctx = g_vpr_ctx.mutable_atom();

auto blk_id = atom_ctx.lookup.pb_atom(pb);
if (blk_id) {
/* If any molecules were marked invalid because of this logic block getting packed, mark them valid */

//Update atom netlist mapping
atom_ctx.lookup.set_atom_clb(blk_id, ClusterBlockId::INVALID());
atom_ctx.lookup.set_atom_pb(blk_id, nullptr);

t_pack_molecule* cur_molecule = prepacker.get_atom_molecule(blk_id);
if (!mol_validated) {
int i;
for (i = 0; i < get_array_size_of_molecule(cur_molecule); i++) {
if (cur_molecule->atom_block_ids[i]) {
if (atom_ctx.lookup.atom_clb(cur_molecule->atom_block_ids[i]) != ClusterBlockId::INVALID()) {
break;
}
}
}
/* All atom blocks are open for this molecule, place back in queue */
if (i == get_array_size_of_molecule(cur_molecule)) {
mol_validated = true;
// when invalidating a molecule check if it's a chain molecule
// that is part of a long chain. If so, check if this molecule
// have modified the chain_id value based on the stale packing
// then reset the chain id and the first packed molecule pointer
// this is packing is being reset
if (cur_molecule->is_chain() && cur_molecule->chain_info->is_long_chain && cur_molecule->chain_info->first_packed_molecule == cur_molecule) {
cur_molecule->chain_info->first_packed_molecule = nullptr;
cur_molecule->chain_info->chain_id = -1;
}
}
}
}
static void reset_molecule_info(t_pack_molecule* mol) {
// when invalidating a molecule check if it's a chain molecule
// that is part of a long chain. If so, check if this molecule
// has modified the chain_id value based on the stale packing
// then reset the chain id and the first packed molecule pointer
// this is packing is being reset
if (mol->is_chain()
&& mol->chain_info->is_long_chain
&& mol->chain_info->first_packed_molecule == mol) {
mol->chain_info->first_packed_molecule = nullptr;
mol->chain_info->chain_id = -1;
}
}

Expand All @@ -1060,8 +1027,6 @@ static void revalid_molecules(const t_pb* pb,
*/
static void revert_place_atom_block(const AtomBlockId blk_id,
t_lb_router_data* router_data,
bool &mol_validated,
const Prepacker& prepacker,
vtr::vector_map<AtomBlockId, LegalizationClusterId>& atom_cluster) {
const AtomContext& atom_ctx = g_vpr_ctx.atom();
AtomContext& mutable_atom_ctx = g_vpr_ctx.mutable_atom();
Expand All @@ -1079,7 +1044,6 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
*/

t_pb* next = pb->parent_pb;
revalid_molecules(pb, mol_validated, prepacker);
free_pb(pb);
pb = next;

Expand All @@ -1096,7 +1060,6 @@ static void revert_place_atom_block(const AtomBlockId blk_id,
/* If the code gets here, then that means that placing the initial seed molecule
* failed, don't free the actual complex block itself as the seed needs to find
* another placement */
revalid_molecules(pb, mol_validated, prepacker);
free_pb(pb);
}
}
Expand Down Expand Up @@ -1472,13 +1435,13 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
remove_atom_from_target(cluster.router_data, atom_blk_id);
}
}
bool mol_validated = false;
for (int i = 0; i < failed_location; i++) {
AtomBlockId atom_blk_id = molecule->atom_block_ids[i];
if (atom_blk_id) {
revert_place_atom_block(atom_blk_id, cluster.router_data, mol_validated, prepacker_, atom_cluster_);
revert_place_atom_block(atom_blk_id, cluster.router_data, atom_cluster_);
}
}
reset_molecule_info(molecule);

// Record the failure of this molecule in the current pb stats
record_molecule_failure(molecule, cluster.pb);
Expand Down Expand Up @@ -1615,14 +1578,14 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
molecule_cluster_[mol] == cluster_id);
molecule_cluster_[mol] = LegalizationClusterId::INVALID();
// Revert the placement of all blocks in the molecule.
bool mol_validated = false;
int molecule_size = get_array_size_of_molecule(mol);
for (int i = 0; i < molecule_size; i++) {
AtomBlockId atom_blk_id = mol->atom_block_ids[i];
if (atom_blk_id) {
revert_place_atom_block(atom_blk_id, cluster.router_data, mol_validated, prepacker_, atom_cluster_);
revert_place_atom_block(atom_blk_id, cluster.router_data, atom_cluster_);
}
}
reset_molecule_info(mol);
}
cluster.molecules.clear();
// Free the rest of the cluster data.
Expand Down

0 comments on commit a34ebf1

Please sign in to comment.