Skip to content

Commit 8d801d7

Browse files
Add documentation and clean up AtomPBBimap
1 parent 6128622 commit 8d801d7

File tree

6 files changed

+80
-27
lines changed

6 files changed

+80
-27
lines changed

vpr/src/base/atom_lookup.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,36 @@ class AtomLookup {
2727

2828
typedef vtr::Range<pin_tnode_iterator> pin_tnode_range;
2929

30-
bool lock_atom_pb_bimap = false;
30+
3131

3232
public:
3333
/*
3434
* PBs
3535
*/
3636

37-
inline AtomPBBimap &mutable_atom_pb_bimap() {VTR_ASSERT(!lock_atom_pb_bimap); return atom_to_pb_bimap_;}
38-
inline const AtomPBBimap &atom_pb_bimap() const {VTR_ASSERT(!lock_atom_pb_bimap); return atom_to_pb_bimap_;}
37+
38+
/**
39+
* @brief Sets the atom to pb bimap access lock to value.
40+
* If set to true, access to the bimap is prohibited and will result in failing assertions.
41+
*
42+
* @param value Value to set to lock to
43+
*/
44+
inline void set_atom_pb_bimap_lock(bool value) {
45+
VTR_ASSERT_SAFE_MSG(lock_atom_pb_bimap_ != value, "Double locking or unlocking the atom pb bimap lock");
46+
lock_atom_pb_bimap_ = value;
47+
}
48+
49+
/// @brief Gets the current atom to pb bimap lock value.
50+
inline bool atom_pb_bimap_islocked() {return lock_atom_pb_bimap_;}
51+
52+
53+
// All accesses, mutable or immutable, to the atom to pb bimap
54+
// will result in failing assertions if the lock is set to true.
55+
// This is done to make sure there is only a single source of
56+
// data in places that are supposed to use a local data structure
57+
// instead of the global context.
58+
inline AtomPBBimap &mutable_atom_pb_bimap() {VTR_ASSERT(!lock_atom_pb_bimap_); return atom_to_pb_bimap_;}
59+
inline const AtomPBBimap &atom_pb_bimap() const {VTR_ASSERT(!lock_atom_pb_bimap_); return atom_to_pb_bimap_;}
3960

4061
/**
4162
* @brief Set atom to pb bimap
@@ -107,6 +128,12 @@ class AtomLookup {
107128

108129
private: //Types
109130
private:
131+
132+
/**
133+
* @brief Allows or disallows access to the AtomPBBimap data.
134+
* Useful to make sure global context is not accessed in places you don't want it to.
135+
*/
136+
bool lock_atom_pb_bimap_ = false;
110137
AtomPBBimap atom_to_pb_bimap_;
111138

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

vpr/src/pack/atom_pb_bimap.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
/**
2+
* @file
3+
* @author Amir Poolad
4+
* @date March 2025
5+
* @brief The code for the AtomPBBimap class.
6+
*
7+
* This file implements the various functions of the AtomPBBimap class.
8+
*/
9+
110
#include "atom_pb_bimap.h"
11+
#include "atom_netlist.h"
212

313
AtomPBBimap::AtomPBBimap(const vtr::bimap<AtomBlockId, const t_pb*, vtr::linear_map, std::unordered_map>& atom_to_pb) {
414
atom_to_pb_ = atom_to_pb;
@@ -34,7 +44,6 @@ const t_pb_graph_node* AtomPBBimap::atom_pb_graph_node(const AtomBlockId blk_id)
3444
void AtomPBBimap::set_atom_pb(const AtomBlockId blk_id, const t_pb* pb) {
3545
//If either of blk_id or pb are not valid,
3646
//remove any mapping
37-
3847
if (!blk_id && pb) {
3948
//Remove
4049
atom_to_pb_.erase(pb);
@@ -46,3 +55,9 @@ void AtomPBBimap::set_atom_pb(const AtomBlockId blk_id, const t_pb* pb) {
4655
atom_to_pb_.update(blk_id, pb);
4756
}
4857
}
58+
59+
void AtomPBBimap::reset_bimap(const AtomNetlist &netlist) {
60+
for (auto blk : netlist.blocks()) {
61+
set_atom_pb(blk, nullptr);
62+
}
63+
}

vpr/src/pack/atom_pb_bimap.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @file
3+
* @author Amir Poolad
4+
* @date March 2025
5+
* @brief The declaration of the AtomPBBimap class.
6+
*
7+
* This file declares a class called AtomPBBimap that
8+
* contains a two way mapping between AtomBlockIds and pb types.
9+
*/
10+
111
#pragma once
212

313
#include "vpr_types.h"
@@ -37,6 +47,10 @@ class AtomPBBimap {
3747
*/
3848
void set_atom_pb(const AtomBlockId blk_id, const t_pb* pb);
3949

50+
/// @brief Sets the pb for all blocks in the netlist to nullptr.
51+
void reset_bimap(const AtomNetlist &netlist);
52+
4053
private:
54+
/// @brief Two way map between AtomBlockIds and t_pb
4155
vtr::bimap<AtomBlockId, const t_pb*, vtr::linear_map, std::unordered_map> atom_to_pb_;
4256
};

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
#include "vtr_vector_map.h"
4040

4141
/*
42-
* @brief Allocates the stats stored within the pb of a cluster.
43-
*
44-
* Used to store information used during clustering.
45-
*/
42+
* @brief Allocates the stats stored within the pb of a cluster.
43+
*
44+
* Used to store information used during clustering.
45+
*/
4646
static void alloc_and_load_pb_stats(t_pb* pb) {
4747
/* Call this routine when starting to fill up a new cluster. It resets *
4848
* the gain vector, etc. */
@@ -58,8 +58,8 @@ static void alloc_and_load_pb_stats(t_pb* pb) {
5858
}
5959

6060
/*
61-
* @brief Check the atom blocks of a cluster pb. Used in the verify method.
62-
*/
61+
* @brief Check the atom blocks of a cluster pb. Used in the verify method.
62+
*/
6363
/* TODO: May want to check that all atom blocks are actually reached */
6464
static void check_cluster_atom_blocks(t_pb* pb, std::unordered_set<AtomBlockId>& blocks_checked, const AtomPBBimap &atom_pb_lookup) {
6565
const AtomContext& atom_ctx = g_vpr_ctx.atom();
@@ -118,7 +118,6 @@ static void free_pb_stats_recursive(t_pb* pb) {
118118
}
119119
}
120120

121-
122121
/**
123122
* @brief Checks whether an atom block can be added to a clustered block
124123
* without violating floorplanning constraints. It also updates the
@@ -244,11 +243,12 @@ static bool check_cluster_noc_group(AtomBlockId atom_blk_id,
244243
// If the cluster belongs to a different NoC group than the atom's group,
245244
// they are incompatible.
246245
VTR_LOGV(log_verbosity > 3,
247-
"\t\t\t NoC Group: Atom block %d failed NoC group check for cluster. Cluster's NoC group: %d, atom's NoC group: %d\n",
248-
atom_blk_id, (size_t)cluster_noc_grp_id, (size_t)atom_noc_grp_id);
249-
return false;
246+
"\t\t\t NoC Group: Atom block %d failed NoC group check for cluster. Cluster's NoC group: %d, atom's NoC group: %d\n",
247+
atom_blk_id, (size_t)cluster_noc_grp_id, (size_t)atom_noc_grp_id);
248+
return false;
250249
}
251250

251+
252252
/**
253253
* @brief This function takes the root block of a chain molecule and a proposed
254254
* placement primitive for this block. The function then checks if this
@@ -260,7 +260,7 @@ static enum e_block_pack_status check_chain_root_placement_feasibility(const t_p
260260
const t_clustering_chain_info& clustering_chain_info,
261261
t_pack_patterns* mol_pack_patterns,
262262
const AtomBlockId blk_id) {
263-
const AtomNetlist& netlist_context = g_vpr_ctx.atom().netlist();
263+
const AtomNetlist& atom_netlist = g_vpr_ctx.atom().netlist();
264264

265265
enum e_block_pack_status block_pack_status = e_block_pack_status::BLK_PASSED;
266266

@@ -270,10 +270,10 @@ static enum e_block_pack_status check_chain_root_placement_feasibility(const t_p
270270

271271
t_model_ports* root_port = chain_root_pins[0][0]->port->model_port;
272272
AtomNetId chain_net_id;
273-
auto port_id = netlist_context.find_atom_port(blk_id, root_port);
273+
auto port_id = atom_netlist.find_atom_port(blk_id, root_port);
274274

275275
if (port_id) {
276-
chain_net_id = netlist_context.port_net(port_id, chain_root_pins[0][0]->pin_number);
276+
chain_net_id = atom_netlist.port_net(port_id, chain_root_pins[0][0]->pin_number);
277277
}
278278

279279
// if this block is part of a long chain or it is driven by a cluster

vpr/src/pack/cluster_legalizer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class Prepacker;
2929
class t_intra_cluster_placement_stats;
3030
class t_pb_graph_node;
3131
struct t_lb_router_data;
32-
class UserPlaceConstraints;
3332

3433
// A special ID to identify the legalization clusters. This is separate from the
3534
// ClusterBlockId since this legalizer is not necessarily tied to the Clustered
@@ -192,7 +191,6 @@ struct LegalizationCluster {
192191
*
193192
* // new_cluster_id now contains a fully legalized cluster.
194193
*/
195-
196194
class ClusterLegalizer {
197195
public:
198196
// Iterator for the legalization cluster IDs
@@ -593,6 +591,9 @@ class ClusterLegalizer {
593591
/// @brief The prepacker object that stores the molecules which will be
594592
/// legalized into clusters.
595593
const Prepacker& prepacker_;
594+
595+
/// @brief A two way map between AtomBlockIds and pb types. This is a copy
596+
/// of the AtomPBBimap in the global context's AtomLookup
596597
AtomPBBimap atom_pb_lookup_;
597598

598599
};

vpr/src/pack/pack.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool try_pack(t_packer_opts* packer_opts,
175175
is_global,
176176
flat_placement_info);
177177

178-
g_vpr_ctx.mutable_atom().mutable_lookup().lock_atom_pb_bimap = true;
178+
g_vpr_ctx.mutable_atom().mutable_lookup().set_atom_pb_bimap_lock(true);
179179

180180
while (true) {
181181
//Cluster the netlist
@@ -288,11 +288,8 @@ bool try_pack(t_packer_opts* packer_opts,
288288
}
289289

290290
//Reset clustering for re-packing
291-
// g_vpr_ctx.mutable_atom().mutable_lookup().lock_atom_pb = false;
292-
for (auto blk : g_vpr_ctx.atom().netlist().blocks()) {
293-
g_vpr_ctx.mutable_atom().mutable_lookup().set_atom_clb(blk, ClusterBlockId::INVALID());
294-
cluster_legalizer.mutable_atom_pb_lookup().set_atom_pb(blk, nullptr);
295-
}
291+
cluster_legalizer.mutable_atom_pb_lookup().reset_bimap(g_vpr_ctx.atom().netlist());
292+
296293
for (auto net : g_vpr_ctx.atom().netlist().nets()) {
297294
g_vpr_ctx.mutable_atom().mutable_lookup().remove_atom_net(net);
298295
}
@@ -301,7 +298,6 @@ bool try_pack(t_packer_opts* packer_opts,
301298

302299
// Reset the cluster legalizer for re-clustering.
303300
cluster_legalizer.reset();
304-
// g_vpr_ctx.mutable_atom().mutable_lookup().lock_atom_pb = true;
305301
++pack_iteration;
306302
}
307303

@@ -319,7 +315,7 @@ bool try_pack(t_packer_opts* packer_opts,
319315
* }
320316
*/
321317
/******************** End **************************/
322-
g_vpr_ctx.mutable_atom().mutable_lookup().lock_atom_pb_bimap = false;
318+
g_vpr_ctx.mutable_atom().mutable_lookup().set_atom_pb_bimap_lock(false);
323319
g_vpr_ctx.mutable_atom().mutable_lookup().set_atom_to_pb_bimap(cluster_legalizer.atom_pb_lookup());
324320
//check clustering and output it
325321
check_and_output_clustering(cluster_legalizer, *packer_opts, is_clock, &arch);

0 commit comments

Comments
 (0)