Skip to content

Remove usage of atom to pb lookup from packing #2932

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2934ebd
Remove usage of atom to pb lookup from packing
AmirhosseinPoolad Mar 11, 2025
02e4f1e
Merge branch 'master' into refactor_atom_pb_from_packing
AmirhosseinPoolad Mar 12, 2025
00aad1b
Remove unused variables in cluster_legalizer.cpp
AmirhosseinPoolad Mar 13, 2025
14cff91
Remove code duplication between global context and AtomPBBimap
AmirhosseinPoolad Mar 13, 2025
f482530
Remove pb_free code duplication
AmirhosseinPoolad Mar 13, 2025
1741f76
Merge remote-tracking branch 'origin' into refactor_atom_pb_from_packing
AmirhosseinPoolad Mar 13, 2025
2b9179a
Merge remote-tracking branch 'origin' into refactor_atom_pb_from_packing
AmirhosseinPoolad Mar 13, 2025
7f3b274
Remove unused variable from update_connection_gain_values
AmirhosseinPoolad Mar 13, 2025
c8fe4e0
Add atom_pb_bimap locking
AmirhosseinPoolad Mar 13, 2025
6128622
Add documentation to atom_pb_bimap and general cleanup
AmirhosseinPoolad Mar 13, 2025
8d801d7
Add documentation and clean up AtomPBBimap
AmirhosseinPoolad Mar 17, 2025
4571d72
Add doxygen comments to atom_pb_bimap getter functions
AmirhosseinPoolad Mar 17, 2025
e2ac829
Fix styling regressions
AmirhosseinPoolad Mar 19, 2025
9e0d48a
Add reset_bimap helper method to AtomPBBimap
AmirhosseinPoolad Mar 19, 2025
4c61867
Remove copying empty bimap from global context to cluster legalizer
AmirhosseinPoolad Mar 19, 2025
624f251
Refactor is_atom_blk_in_pb function to get two t_pb* arguments
AmirhosseinPoolad Mar 19, 2025
0e6f62a
Merge branch 'master' into refactor_atom_pb_from_packing
AmirhosseinPoolad Mar 19, 2025
dfb6462
Fix minor styling issues
AmirhosseinPoolad Mar 19, 2025
f77c3c7
Merge branch 'master' into refactor_atom_pb_from_packing
AmirhosseinPoolad Mar 20, 2025
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
8 changes: 4 additions & 4 deletions utils/fasm/src/fasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ static AtomNetId _find_atom_input_logical_net(const t_pb* atom, const t_pb_route

static LogicVec lut_outputs(const t_pb* atom_pb, size_t num_inputs, const t_pb_routes &pb_route) {
auto& atom_ctx = g_vpr_ctx.atom();
AtomBlockId block_id = atom_ctx.lookup().pb_atom(atom_pb);
AtomBlockId block_id = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom_pb);
const auto& truth_table = atom_ctx.netlist().block_truth_table(block_id);
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().pb_atom(atom_pb));
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().atom_pb_bimap().pb_atom(atom_pb));

const t_pb_graph_node* gnode = atom_pb->pb_graph_node;

Expand Down Expand Up @@ -537,7 +537,7 @@ static const t_pb_routes &find_pb_route(const t_pb* pb) {
void FasmWriterVisitor::check_for_param(const t_pb *atom) {
auto& atom_ctx = g_vpr_ctx.atom();

auto atom_blk_id = atom_ctx.lookup().pb_atom(atom);
auto atom_blk_id = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
if (atom_blk_id == AtomBlockId::INVALID()) {
return;
}
Expand Down Expand Up @@ -592,7 +592,7 @@ void FasmWriterVisitor::check_for_param(const t_pb *atom) {
void FasmWriterVisitor::check_for_lut(const t_pb* atom) {
auto& atom_ctx = g_vpr_ctx.atom();

auto atom_blk_id = atom_ctx.lookup().pb_atom(atom);
auto atom_blk_id = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
if (atom_blk_id == AtomBlockId::INVALID()) {
return;
}
Expand Down
45 changes: 0 additions & 45 deletions vpr/src/base/atom_lookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,6 @@
#include "vtr_optional.h"

#include "atom_lookup.h"
/*
* PB
*/
const t_pb* AtomLookup::atom_pb(const AtomBlockId blk_id) const {
auto iter = atom_to_pb_.find(blk_id);
if (iter == atom_to_pb_.end()) {
//Not found
return nullptr;
}
return iter->second;
}

AtomBlockId AtomLookup::pb_atom(const t_pb* pb) const {
auto iter = atom_to_pb_.find(pb);
if (iter == atom_to_pb_.inverse_end()) {
//Not found
return AtomBlockId::INVALID();
}
return iter->second;
}

const t_pb_graph_node* AtomLookup::atom_pb_graph_node(const AtomBlockId blk_id) const {
const t_pb* pb = atom_pb(blk_id);
if (pb) {
//Found
return pb->pb_graph_node;
}
return nullptr;
}

void AtomLookup::set_atom_pb(const AtomBlockId blk_id, const t_pb* pb) {
//If either of blk_id or pb are not valid,
//remove any mapping

if (!blk_id && pb) {
//Remove
atom_to_pb_.erase(pb);
} else if (blk_id && !pb) {
//Remove
atom_to_pb_.erase(blk_id);
} else if (blk_id && pb) {
//If both are valid store the mapping
atom_to_pb_.update(blk_id, pb);
}
}

/*
* PB Pins
Expand Down
56 changes: 42 additions & 14 deletions vpr/src/base/atom_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "tatum/TimingGraphFwd.hpp"

#include "vtr_optional.h"
#include "atom_pb_bimap.h"

/**
* @brief The AtomLookup class describes the mapping between components in the AtomNetlist
Expand All @@ -31,23 +32,45 @@ class AtomLookup {
*/

/**
* @brief Returns the leaf pb associated with the atom blk_id
* @note this is the lowest level pb which corresponds directly to the atom block
* @brief Sets the atom to pb bimap access lock to value.
* If set to true, access to the bimap is prohibited and will result in failing assertions.
*
* @param value Value to set to lock to
*/
const t_pb* atom_pb(const AtomBlockId blk_id) const;

///@brief Returns the atom block id associated with pb
AtomBlockId pb_atom(const t_pb* pb) const;

///@brief Conveneince wrapper around atom_pb to access the associated graph node
const t_pb_graph_node* atom_pb_graph_node(const AtomBlockId blk_id) const;
inline void set_atom_pb_bimap_lock(bool value) {
VTR_ASSERT_SAFE_MSG(lock_atom_pb_bimap_ != value, "Double locking or unlocking the atom pb bimap lock");
lock_atom_pb_bimap_ = value;
}

/// @brief Gets the current atom to pb bimap lock value.
inline bool atom_pb_bimap_islocked() const { return lock_atom_pb_bimap_; }

// All accesses, mutable or immutable, to the atom to pb bimap
// will result in failing assertions if the lock is set to true.
// This is done to make sure there is only a single source of
// data in places that are supposed to use a local data structure
// instead of the global context.

/// @brief Returns a mutable reference to the atom to pb bimap, provided that access to it is unlocked. It will result in a crash otherwise.
/// @return Mutable reference to the atom pb bimap.
inline AtomPBBimap& mutable_atom_pb_bimap() {
VTR_ASSERT(!lock_atom_pb_bimap_);
return atom_to_pb_bimap_;
}

/// @brief Returns an immutable reference to the atom to pb bimap, provided that access to it is unlocked. It will result in a crash otherwise.
/// @return Immutable reference to the atom pb bimap.
inline const AtomPBBimap& atom_pb_bimap() const {
VTR_ASSERT(!lock_atom_pb_bimap_);
return atom_to_pb_bimap_;
}

/**
* @brief Sets the bidirectional mapping between an atom and pb
*
* If either blk_id or pb are not valid any, existing mapping is removed
* @brief Set atom to pb bimap
*
* @param atom_to_pb Reference to AtomPBBimab to be copied from
*/
void set_atom_pb(const AtomBlockId blk_id, const t_pb* pb);
void set_atom_to_pb_bimap(const AtomPBBimap& atom_to_pb) { atom_to_pb_bimap_ = atom_to_pb; }

/*
* PB Pins
Expand Down Expand Up @@ -112,7 +135,12 @@ class AtomLookup {

private: //Types
private:
vtr::bimap<AtomBlockId, const t_pb*, vtr::linear_map, std::unordered_map> atom_to_pb_;
/**
* @brief Allows or disallows access to the AtomPBBimap data.
* Useful to make sure global context is not accessed in places you don't want it to.
*/
bool lock_atom_pb_bimap_ = false;
AtomPBBimap atom_to_pb_bimap_;

vtr::vector_map<AtomPinId, const t_pb_graph_pin*> atom_pin_to_pb_graph_pin_;

Expand Down
4 changes: 2 additions & 2 deletions vpr/src/base/clustered_netlist.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "clustered_netlist.h"

#include "globals.h"
#include "physical_types_util.h"
#include "vtr_assert.h"

Expand Down Expand Up @@ -171,7 +171,7 @@ ClusterNetId ClusteredNetlist::create_net(const std::string& name) {

void ClusteredNetlist::remove_block_impl(const ClusterBlockId blk_id) {
//Remove & invalidate pointers
free_pb(block_pbs_[blk_id]);
free_pb(block_pbs_[blk_id], g_vpr_ctx.mutable_atom().mutable_lookup().mutable_atom_pb_bimap());
delete block_pbs_[blk_id];
block_pbs_.insert(blk_id, NULL);
block_types_.insert(blk_id, NULL);
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/base/load_flat_place.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void print_flat_cluster(FILE* fp,
// Print a line for each atom.
for (AtomBlockId atom : atoms_lookup[blk_id]) {
// Get the atom pb graph node.
t_pb_graph_node* atom_pbgn = atom_ctx.lookup().atom_pb(atom)->pb_graph_node;
t_pb_graph_node* atom_pbgn = atom_ctx.lookup().atom_pb_bimap().atom_pb(atom)->pb_graph_node;

// Print the flat placement information for this atom.
fprintf(fp, "%s %d %d %d %d %d #%zu %s\n",
Expand Down
14 changes: 7 additions & 7 deletions vpr/src/base/netlist_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
void visit_atom_impl(const t_pb* atom) override {
auto& atom_ctx = g_vpr_ctx.atom();

auto atom_pb = atom_ctx.lookup().pb_atom(atom);
auto atom_pb = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
if (atom_pb == AtomBlockId::INVALID()) {
return;
}
Expand Down Expand Up @@ -1787,7 +1787,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
}

auto& atom_ctx = g_vpr_ctx.atom();
AtomBlockId blk_id = atom_ctx.lookup().pb_atom(atom);
AtomBlockId blk_id = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
for (auto param : atom_ctx.netlist().block_params(blk_id)) {
params[param.first] = param.second;
}
Expand All @@ -1809,7 +1809,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
tatum::NodeId find_tnode(const t_pb* atom, int cluster_pin_idx) {
auto& atom_ctx = g_vpr_ctx.atom();

AtomBlockId blk_id = atom_ctx.lookup().pb_atom(atom);
AtomBlockId blk_id = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
ClusterBlockId clb_index = atom_ctx.lookup().atom_clb(blk_id);

auto key = std::make_pair(clb_index, cluster_pin_idx);
Expand Down Expand Up @@ -1840,7 +1840,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
const t_pb* atom) { //LUT primitive
auto& atom_ctx = g_vpr_ctx.atom();

const t_model* model = atom_ctx.netlist().block_model(atom_ctx.lookup().pb_atom(atom));
const t_model* model = atom_ctx.netlist().block_model(atom_ctx.lookup().atom_pb_bimap().pb_atom(atom));
VTR_ASSERT(model->name == std::string(MODEL_NAMES));

#ifdef DEBUG_LUT_MASK
Expand All @@ -1851,7 +1851,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
std::vector<int> permute = determine_lut_permutation(num_inputs, atom);

//Retrieve the truth table
const auto& truth_table = atom_ctx.netlist().block_truth_table(atom_ctx.lookup().pb_atom(atom));
const auto& truth_table = atom_ctx.netlist().block_truth_table(atom_ctx.lookup().atom_pb_bimap().pb_atom(atom));

//Apply the permutation
auto permuted_truth_table = permute_truth_table(truth_table, num_inputs, permute);
Expand Down Expand Up @@ -1896,7 +1896,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
//
//We walk through the logical inputs to this atom (i.e. in the original truth table/netlist)
//and find the corresponding input in the implementation atom (i.e. in the current netlist)
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().pb_atom(atom_pb));
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().atom_pb_bimap().pb_atom(atom_pb));
if (ports.size() == 1) {
const t_pb_graph_node* gnode = atom_pb->pb_graph_node;
VTR_ASSERT(gnode->num_input_ports == 1);
Expand Down Expand Up @@ -2144,7 +2144,7 @@ class MergedNetlistWriterVisitor : public NetlistWriterVisitor {
void visit_atom_impl(const t_pb* atom) override {
auto& atom_ctx = g_vpr_ctx.atom();

auto atom_pb = atom_ctx.lookup().pb_atom(atom);
auto atom_pb = atom_ctx.lookup().atom_pb_bimap().pb_atom(atom);
if (atom_pb == AtomBlockId::INVALID()) {
return;
}
Expand Down
16 changes: 8 additions & 8 deletions vpr/src/base/read_netlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ ClusteredNetlist read_netlist(const char* net_file,

//Reset atom/pb mapping (it is reloaded from the packed netlist file)
for (auto blk_id : atom_ctx.netlist().blocks())
atom_ctx.mutable_lookup().set_atom_pb(blk_id, nullptr);
atom_ctx.mutable_lookup().mutable_atom_pb_bimap().set_atom_pb(blk_id, nullptr);

//Count the number of blocks for allocation
bcount = pugiutil::count_children(top, "block", loc_data, pugiutil::ReqOpt::OPTIONAL);
Expand All @@ -197,7 +197,7 @@ ClusteredNetlist read_netlist(const char* net_file,

/* Error check */
for (auto blk_id : atom_ctx.netlist().blocks()) {
if (atom_ctx.lookup().atom_pb(blk_id) == nullptr) {
if (atom_ctx.lookup().atom_pb_bimap().atom_pb(blk_id) == nullptr) {
VPR_FATAL_ERROR(VPR_ERROR_NET_F,
".blif file and .net file do not match, .net file missing atom %s.\n",
atom_ctx.netlist().block_name(blk_id).c_str());
Expand Down Expand Up @@ -319,7 +319,7 @@ static void processComplexBlock(pugi::xml_node clb_block,
}

//Parse all pbs and CB internal nets
atom_ctx.mutable_lookup().set_atom_pb(AtomBlockId::INVALID(), clb_nlist->block_pb(index));
atom_ctx.mutable_lookup().mutable_atom_pb_bimap().set_atom_pb(AtomBlockId::INVALID(), clb_nlist->block_pb(index));

clb_nlist->block_pb(index)->pb_graph_node = clb_nlist->block_type(index)->pb_graph_head;
clb_nlist->block_pb(index)->pb_route = alloc_pb_route(clb_nlist->block_pb(index)->pb_graph_node);
Expand Down Expand Up @@ -474,7 +474,7 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p

//Update atom netlist mapping
VTR_ASSERT(blk_id);
atom_ctx.mutable_lookup().set_atom_pb(blk_id, pb);
atom_ctx.mutable_lookup().mutable_atom_pb_bimap().set_atom_pb(blk_id, pb);
atom_ctx.mutable_lookup().set_atom_clb(blk_id, index);

auto atom_attrs = atom_ctx.netlist().block_attrs(blk_id);
Expand Down Expand Up @@ -542,7 +542,7 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p
pb->child_pbs[i][pb_index].name = vtr::strdup(name.value());

/* Parse all pbs and CB internal nets*/
atom_ctx.mutable_lookup().set_atom_pb(AtomBlockId::INVALID(), &pb->child_pbs[i][pb_index]);
atom_ctx.mutable_lookup().mutable_atom_pb_bimap().set_atom_pb(AtomBlockId::INVALID(), &pb->child_pbs[i][pb_index]);

auto mode = child.attribute("mode");
pb->child_pbs[i][pb_index].mode = 0;
Expand All @@ -564,7 +564,7 @@ static void processPb(pugi::xml_node Parent, const ClusterBlockId index, t_pb* p
} else {
/* physical block has no used primitives but it may have used routing */
pb->child_pbs[i][pb_index].name = nullptr;
atom_ctx.mutable_lookup().set_atom_pb(AtomBlockId::INVALID(), &pb->child_pbs[i][pb_index]);
atom_ctx.mutable_lookup().mutable_atom_pb_bimap().set_atom_pb(AtomBlockId::INVALID(), &pb->child_pbs[i][pb_index]);

auto lookahead1 = pugiutil::get_first_child(child, "outputs", loc_data, pugiutil::OPTIONAL);
if (lookahead1) {
Expand Down Expand Up @@ -1180,7 +1180,7 @@ static void load_atom_pin_mapping(const ClusteredNetlist& clb_nlist) {
auto& atom_ctx = g_vpr_ctx.atom();

for (const AtomBlockId blk : atom_ctx.netlist().blocks()) {
const t_pb* pb = atom_ctx.lookup().atom_pb(blk);
const t_pb* pb = atom_ctx.lookup().atom_pb_bimap().atom_pb(blk);
VTR_ASSERT_MSG(pb, "Atom block must have a matching PB");

const t_pb_graph_node* gnode = pb->pb_graph_node;
Expand Down Expand Up @@ -1250,7 +1250,7 @@ void set_atom_pin_mapping(const ClusteredNetlist& clb_nlist, const AtomBlockId a
return;
}

const t_pb* atom_pb = atom_ctx.lookup().atom_pb(atom_blk);
const t_pb* atom_pb = atom_ctx.lookup().atom_pb_bimap().atom_pb(atom_blk);

//This finds the index within the atom port to which the current gpin
//is mapped. Note that this accounts for any applied pin rotations
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/draw/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ ezgl::point2d atom_pin_draw_coord(AtomPinId pin) {

AtomBlockId blk = atom_ctx.netlist().pin_block(pin);
ClusterBlockId clb_index = atom_ctx.lookup().atom_clb(blk);
const t_pb_graph_node* pg_gnode = atom_ctx.lookup().atom_pb_graph_node(blk);
const t_pb_graph_node* pg_gnode = atom_ctx.lookup().atom_pb_bimap().atom_pb_graph_node(blk);

t_draw_coords* draw_coords = get_draw_coords_vars();
ezgl::rectangle pb_bbox = draw_coords->get_absolute_pb_bbox(clb_index,
Expand Down
6 changes: 3 additions & 3 deletions vpr/src/draw/draw_floorplanning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ void draw_constrained_atoms(ezgl::renderer* g) {
auto atoms = constraints.get_part_atoms((PartitionId)partitionID);

for (const AtomBlockId atom_id : atoms) {
if (atom_ctx.lookup().atom_pb(atom_id) != nullptr) {
const t_pb* pb = atom_ctx.lookup().atom_pb(atom_id);
if (atom_ctx.lookup().atom_pb_bimap().atom_pb(atom_id) != nullptr) {
const t_pb* pb = atom_ctx.lookup().atom_pb_bimap().atom_pb(atom_id);
auto color = kelly_max_contrast_colors_no_black[partitionID % (kelly_max_contrast_colors_no_black.size())];
ClusterBlockId clb_index = atom_ctx.lookup().atom_clb(atom_id);
auto type = cluster_ctx.clb_nlist.block_type(clb_index);
Expand Down Expand Up @@ -310,7 +310,7 @@ static GtkTreeModel* create_and_fill_model() {
-1);

for (AtomBlockId const_atom : atoms) {
std::string atom_name = (atom_ctx.lookup().atom_pb(const_atom))->name;
std::string atom_name = (atom_ctx.lookup().atom_pb_bimap().atom_pb(const_atom))->name;
gtk_tree_store_append(store, &child_iter, &iter);
gtk_tree_store_set(store, &child_iter,
COL_NAME, atom_name.c_str(),
Expand Down
Loading