Skip to content

[Prepack] Pack Molecule Data Structure Cleanup #2884

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

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vpr/src/analytical_place/analytical_placement_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
const UserPlaceConstraints& constraints = g_vpr_ctx.floorplanning().constraints;

// Run the prepacker
Prepacker prepacker;
prepacker.init(atom_nlist, device_ctx.logical_block_types);
const Prepacker prepacker(atom_nlist, device_ctx.logical_block_types);

// Create the ap netlist from the atom netlist using the result from the
// prepacker.
Expand All @@ -80,7 +79,8 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {

// Run the Global Placer
std::unique_ptr<GlobalPlacer> global_placer = make_global_placer(e_global_placer::SimPL,
ap_netlist);
ap_netlist,
prepacker);
PartialPlacement p_placement = global_placer->place();

// Verify that the partial placement is valid before running the full
Expand Down
10 changes: 5 additions & 5 deletions vpr/src/analytical_place/ap_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <string>
#include "netlist_fwd.h"
#include "netlist_utils.h"
#include "vpr_types.h"
#include "prepack.h"
#include "vtr_assert.h"

/*
* Blocks
*/
const t_pack_molecule* APNetlist::block_molecule(const APBlockId id) const {
PackMoleculeId APNetlist::block_molecule(const APBlockId id) const {
VTR_ASSERT_SAFE(valid_block_id(id));

return block_molecules_[id];
Expand All @@ -37,19 +37,19 @@ const APFixedBlockLoc& APNetlist::block_loc(const APBlockId id) const {
/*
* Mutators
*/
APBlockId APNetlist::create_block(const std::string& name, const t_pack_molecule* mol) {
APBlockId APNetlist::create_block(const std::string& name, PackMoleculeId molecule_id) {
APBlockId blk_id = Netlist::create_block(name);

// Initialize the data
block_molecules_.insert(blk_id, mol);
block_molecules_.insert(blk_id, molecule_id);
block_mobilities_.insert(blk_id, APBlockMobility::MOVEABLE);
block_locs_.insert(blk_id, APFixedBlockLoc());

// Check post-conditions: size
VTR_ASSERT(validate_block_sizes());

// Check post-conditions: values
VTR_ASSERT(block_molecule(blk_id) == mol);
VTR_ASSERT(block_molecule(blk_id) == molecule_id);
VTR_ASSERT(block_mobility(blk_id) == APBlockMobility::MOVEABLE);

return blk_id;
Expand Down
10 changes: 4 additions & 6 deletions vpr/src/analytical_place/ap_netlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include <string>
#include "netlist.h"
#include "ap_netlist_fwd.h"

// Forward declarations
class t_pack_molecule;
#include "prepack.h"

/**
* @brief Struct to store fixed block location information
Expand Down Expand Up @@ -83,7 +81,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {
*/

/// @brief Returns the molecule that this block represents.
const t_pack_molecule* block_molecule(const APBlockId id) const;
PackMoleculeId block_molecule(const APBlockId id) const;

/// @brief Returns the mobility of this block.
APBlockMobility block_mobility(const APBlockId id) const;
Expand All @@ -104,7 +102,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {
* @param name The unique name of the block
* @param mol The molecule the block represents
*/
APBlockId create_block(const std::string& name, const t_pack_molecule* mol);
APBlockId create_block(const std::string& name, PackMoleculeId molecule_id);

/**
* @brief Fixes a block at the given location
Expand Down Expand Up @@ -182,7 +180,7 @@ class APNetlist : public Netlist<APBlockId, APPortId, APPinId, APNetId> {

private: // Private Data
/// @brief Molecule of each block
vtr::vector_map<APBlockId, const t_pack_molecule*> block_molecules_;
vtr::vector_map<APBlockId, PackMoleculeId> block_molecules_;
/// @brief Type of each block
vtr::vector_map<APBlockId, APBlockMobility> block_mobilities_;
/// @brief Location of each block (if fixed).
Expand Down
33 changes: 17 additions & 16 deletions vpr/src/analytical_place/full_legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "place_and_route.h"
#include "place_constraints.h"
#include "place_macro.h"
#include "prepack.h"
#include "verify_clustering.h"
#include "verify_placement.h"
#include "vpr_api.h"
Expand Down Expand Up @@ -202,7 +203,8 @@ class APClusterPlacer {
* @param primitive_candidate_block_types A list of candidate block types for
* the given molecule.
*/
static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
static LegalizationClusterId create_new_cluster(PackMoleculeId seed_molecule_id,
const Prepacker& prepacker,
ClusterLegalizer& cluster_legalizer,
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types) {
const AtomContext& atom_ctx = g_vpr_ctx.atom();
Expand All @@ -212,7 +214,9 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
// placed into.
// TODO: The original implementation sorted based on balance. Perhaps this
// should do the same.
AtomBlockId root_atom = seed_molecule->atom_block_ids[seed_molecule->root];
VTR_ASSERT(seed_molecule_id.is_valid());
const t_pack_molecule& seed_molecule = prepacker.get_molecule(seed_molecule_id);
AtomBlockId root_atom = seed_molecule.atom_block_ids[seed_molecule.root];
const t_model* root_model = atom_ctx.nlist.block_model(root_atom);

auto itr = primitive_candidate_block_types.find(root_model);
Expand All @@ -224,7 +228,7 @@ static LegalizationClusterId create_new_cluster(t_pack_molecule* seed_molecule,
for (int mode = 0; mode < num_modes; mode++) {
e_block_pack_status pack_status = e_block_pack_status::BLK_STATUS_UNDEFINED;
LegalizationClusterId new_cluster_id;
std::tie(pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster(seed_molecule, type, mode);
std::tie(pack_status, new_cluster_id) = cluster_legalizer.start_new_cluster(seed_molecule_id, type, mode);
if (pack_status == e_block_pack_status::BLK_PASSED)
return new_cluster_id;
}
Expand Down Expand Up @@ -290,33 +294,29 @@ void FullLegalizer::create_clusters(const PartialPlacement& p_placement) {
for (size_t tile_id_idx = 0; tile_id_idx < num_device_tiles; tile_id_idx++) {
DeviceTileId tile_id = DeviceTileId(tile_id_idx);
// Create the molecule list
std::list<t_pack_molecule*> mol_list;
std::list<PackMoleculeId> mol_list;
for (APBlockId ap_blk_id : blocks_in_tiles[tile_id]) {
// FIXME: The netlist stores a const pointer to mol; but the cluster
// legalizer does not accept this. Need to fix one or the other.
// For now, using const_cast.
t_pack_molecule* mol = const_cast<t_pack_molecule*>(ap_netlist_.block_molecule(ap_blk_id));
mol_list.push_back(mol);
mol_list.push_back(ap_netlist_.block_molecule(ap_blk_id));
}
// Clustering algorithm: Create clusters one at a time.
while (!mol_list.empty()) {
// Arbitrarily choose the first molecule as a seed molecule.
t_pack_molecule* seed_mol = mol_list.front();
PackMoleculeId seed_mol_id = mol_list.front();
mol_list.pop_front();
// Use the seed molecule to create a cluster for this tile.
LegalizationClusterId new_cluster_id = create_new_cluster(seed_mol, cluster_legalizer, primitive_candidate_block_types);
LegalizationClusterId new_cluster_id = create_new_cluster(seed_mol_id, prepacker_, cluster_legalizer, primitive_candidate_block_types);
// Insert all molecules that you can into the cluster.
// NOTE: If the mol_list was somehow sorted, we can just stop at
// first failure!
auto it = mol_list.begin();
while (it != mol_list.end()) {
t_pack_molecule* mol = *it;
if (!cluster_legalizer.is_molecule_compatible(mol, new_cluster_id)) {
PackMoleculeId mol_id = *it;
if (!cluster_legalizer.is_molecule_compatible(mol_id, new_cluster_id)) {
++it;
continue;
}
// Try to insert it. If successful, remove from list.
e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster(mol, new_cluster_id);
e_block_pack_status pack_status = cluster_legalizer.add_mol_to_cluster(mol_id, new_cluster_id);
if (pack_status == e_block_pack_status::BLK_PASSED) {
it = mol_list.erase(it);
} else {
Expand Down Expand Up @@ -352,8 +352,9 @@ void FullLegalizer::place_clusters(const ClusteredNetlist& clb_nlist,
// Create a lookup from the AtomBlockId to the APBlockId
vtr::vector<AtomBlockId, APBlockId> atom_to_ap_block(atom_netlist_.blocks().size());
for (APBlockId ap_blk_id : ap_netlist_.blocks()) {
const t_pack_molecule* blk_mol = ap_netlist_.block_molecule(ap_blk_id);
for (AtomBlockId atom_blk_id : blk_mol->atom_block_ids) {
PackMoleculeId blk_mol_id = ap_netlist_.block_molecule(ap_blk_id);
const t_pack_molecule& blk_mol = prepacker_.get_molecule(blk_mol_id);
for (AtomBlockId atom_blk_id : blk_mol.atom_block_ids) {
// See issue #2791, some of the atom_block_ids may be invalid. They
// can safely be ignored.
if (!atom_blk_id.is_valid())
Expand Down
13 changes: 7 additions & 6 deletions vpr/src/analytical_place/gen_ap_netlist_from_atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "prepack.h"
#include "region.h"
#include "user_place_constraints.h"
#include "vpr_types.h"
#include "vtr_assert.h"
#include "vtr_geometry.h"
#include "vtr_time.h"
Expand All @@ -40,10 +39,11 @@ APNetlist gen_ap_netlist_from_atoms(const AtomNetlist& atom_netlist,
// Each net has the exact same name as in the atom netlist
for (AtomBlockId atom_blk_id : atom_netlist.blocks()) {
// Get the molecule of this block
t_pack_molecule* mol = prepacker.get_atom_molecule(atom_blk_id);
PackMoleculeId molecule_id = prepacker.get_atom_molecule(atom_blk_id);
const t_pack_molecule& mol = prepacker.get_molecule(molecule_id);
// Create the AP block (if not already done)
const std::string& first_blk_name = atom_netlist.block_name(mol->atom_block_ids[0]);
APBlockId ap_blk_id = ap_netlist.create_block(first_blk_name, mol);
const std::string& first_blk_name = atom_netlist.block_name(mol.atom_block_ids[0]);
APBlockId ap_blk_id = ap_netlist.create_block(first_blk_name, molecule_id);
// Add the ports and pins of this block to the supernode
for (AtomPortId atom_port_id : atom_netlist.block_ports(atom_blk_id)) {
BitIndex port_width = atom_netlist.port_width(atom_port_id);
Expand All @@ -68,8 +68,9 @@ APNetlist gen_ap_netlist_from_atoms(const AtomNetlist& atom_netlist,

// Fix the block locations given by the VPR constraints
for (APBlockId ap_blk_id : ap_netlist.blocks()) {
const t_pack_molecule* mol = ap_netlist.block_molecule(ap_blk_id);
for (AtomBlockId mol_atom_blk_id : mol->atom_block_ids) {
PackMoleculeId molecule_id = ap_netlist.block_molecule(ap_blk_id);
const t_pack_molecule& mol = prepacker.get_molecule(molecule_id);
for (AtomBlockId mol_atom_blk_id : mol.atom_block_ids) {
PartitionId part_id = constraints.get_atom_partition(mol_atom_blk_id);
if (!part_id.is_valid())
continue;
Expand Down
12 changes: 8 additions & 4 deletions vpr/src/analytical_place/global_placer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
#include "vtr_time.h"

std::unique_ptr<GlobalPlacer> make_global_placer(e_global_placer placer_type,
const APNetlist& netlist) {
const APNetlist& netlist,
const Prepacker& prepacker) {
// Based on the placer type passed in, build the global placer.
switch (placer_type) {
case e_global_placer::SimPL:
return std::make_unique<SimPLGlobalPlacer>(netlist);
return std::make_unique<SimPLGlobalPlacer>(netlist, prepacker);
default:
VPR_FATAL_ERROR(VPR_ERROR_AP,
"Unrecognized global placer type");

}
}

SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist) : GlobalPlacer(netlist) {
SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist,
const Prepacker& prepacker)
: GlobalPlacer(netlist) {
// This can be a long method. Good to time this to see how long it takes to
// construct the global placer.
vtr::ScopedStartFinishTimer global_placer_building_timer("Constructing Global Placer");
Expand All @@ -39,7 +42,8 @@ SimPLGlobalPlacer::SimPLGlobalPlacer(const APNetlist& netlist) : GlobalPlacer(ne
netlist);
// Build the partial legalizer
partial_legalizer_ = make_partial_legalizer(e_partial_legalizer::FLOW_BASED,
netlist);
netlist,
prepacker);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions vpr/src/analytical_place/global_placer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
// Forward declarations
class APNetlist;
class AnalyticalSolver;
class PartialPlacement;
class PartialLegalizer;
class PartialPlacement;
class Prepacker;

/**
* @brief Enumeration of all of the global placers currently implemented in VPR.
Expand Down Expand Up @@ -77,7 +78,8 @@ class GlobalPlacer {
* @brief A factory method which creates a Global Placer of the given type.
*/
std::unique_ptr<GlobalPlacer> make_global_placer(e_global_placer placer_type,
const APNetlist& netlist);
const APNetlist& netlist,
const Prepacker& prepacker);

/**
* @brief A Global Placer based on the SimPL work for analytical ASIC placement.
Expand Down Expand Up @@ -130,7 +132,7 @@ class SimPLGlobalPlacer : public GlobalPlacer {
*
* Constructs the solver and partial legalizer.
*/
SimPLGlobalPlacer(const APNetlist& netlist);
SimPLGlobalPlacer(const APNetlist& netlist, const Prepacker& prepacker);

/**
* @brief Run a SimPL-like global placement algorithm
Expand Down
21 changes: 12 additions & 9 deletions vpr/src/analytical_place/partial_legalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "globals.h"
#include "partial_placement.h"
#include "physical_types.h"
#include "prepack.h"
#include "primitive_vector.h"
#include "vpr_context.h"
#include "vpr_error.h"
#include "vpr_types.h"
#include "vtr_assert.h"
#include "vtr_geometry.h"
#include "vtr_log.h"
Expand All @@ -36,11 +36,12 @@
#include "vtr_vector_map.h"

std::unique_ptr<PartialLegalizer> make_partial_legalizer(e_partial_legalizer legalizer_type,
const APNetlist& netlist) {
const APNetlist& netlist,
const Prepacker& prepacker) {
// Based on the partial legalizer type passed in, build the partial legalizer.
switch (legalizer_type) {
case e_partial_legalizer::FLOW_BASED:
return std::make_unique<FlowBasedLegalizer>(netlist);
return std::make_unique<FlowBasedLegalizer>(netlist, prepacker);
default:
VPR_FATAL_ERROR(VPR_ERROR_AP,
"Unrecognized partial legalizer type");
Expand Down Expand Up @@ -72,10 +73,12 @@ static inline float get_model_mass(const t_model* model) {
* (primitive types) in the architecture.
*/
static inline PrimitiveVector get_primitive_mass(APBlockId blk_id,
const APNetlist& netlist) {
const APNetlist& netlist,
const Prepacker& prepacker) {
PrimitiveVector mass;
const t_pack_molecule* mol = netlist.block_molecule(blk_id);
for (AtomBlockId atom_blk_id : mol->atom_block_ids) {
PackMoleculeId mol_id = netlist.block_molecule(blk_id);
const t_pack_molecule& mol = prepacker.get_molecule(mol_id);
for (AtomBlockId atom_blk_id : mol.atom_block_ids) {
// See issue #2791, some of the atom_block_ids may be invalid. They can
// safely be ignored.
if (!atom_blk_id.is_valid())
Expand Down Expand Up @@ -459,8 +462,8 @@ void FlowBasedLegalizer::compute_neighbors_of_bin(LegalizerBinId src_bin_id, siz
bins_[src_bin_id].neighbors.assign(neighbors.begin(), neighbors.end());
}

FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist)
: PartialLegalizer(netlist),
FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist, const Prepacker& prepacker)
: PartialLegalizer(netlist, prepacker),
// TODO: Pass the device grid in.
tile_bin_({g_vpr_ctx.device().grid.width(), g_vpr_ctx.device().grid.height()}) {
const DeviceGrid& grid = g_vpr_ctx.device().grid;
Expand Down Expand Up @@ -542,7 +545,7 @@ FlowBasedLegalizer::FlowBasedLegalizer(const APNetlist& netlist)
// Pre-compute the masses of the APBlocks
VTR_LOGV(log_verbosity_ >= 10, "Pre-computing the block masses...\n");
for (APBlockId blk_id : netlist.blocks()) {
block_masses_.insert(blk_id, get_primitive_mass(blk_id, netlist));
block_masses_.insert(blk_id, get_primitive_mass(blk_id, netlist, prepacker));
}
VTR_LOGV(log_verbosity_ >= 10, "Finished pre-computing the block masses.\n");

Expand Down
Loading
Loading