Skip to content

Commit cbe5062

Browse files
Clean up AtomContext
Changes the fields of AtomContext from public to private and provides two methods to get each field: One that returns an immutable const reference and another that returns a mutable reference. The main advantage here is that it is now simple to see where the global context is written to and where it is only read from.
1 parent ced1418 commit cbe5062

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+606
-606
lines changed

doc/src/api/vpr/mapping.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
===============
22
Netlist mapping
33
===============
4-
As shown in the previous section, there are multiple levels of abstraction (multiple netlists) in VPR which are the ClusteredNetlist and the AtomNetlist. To fully use these netlists, we provide some functions to map between them.
4+
As shown in the previous section, there are multiple levels of abstraction (multiple netlists) in VPR which are the ClusteredNetlist and the AtomNetlist. To fully use these netlists, we provide some functions to map between them.
55

66
In this section, we will state how to map between the atom and clustered netlists.
77

@@ -16,11 +16,11 @@ To get the block Id of a cluster in the ClusteredNetlist from the block Id of on
1616

1717
.. code-block:: cpp
1818
19-
ClusterBlockId clb_index = g_vpr_ctx.atom().lookup.atom_clb(atom_blk_id);
19+
ClusterBlockId clb_index = g_vpr_ctx.atom().lookup().atom_clb(atom_blk_id);
2020
2121
2222
* Using re_cluster_util.h helper functions
23-
23+
2424
.. code-block:: cpp
2525
2626
ClusterBlockId clb_index = atom_to_cluster(atom_blk_id);
@@ -53,7 +53,7 @@ To get the net Id in the ClusteredNetlist from its Id in the AtomNetlist, use At
5353

5454
.. code-block:: cpp
5555
56-
ClusterNetId clb_net = g_vpr_ctx.atom().lookup.clb_net(atom_net);
56+
ClusterNetId clb_net = g_vpr_ctx.atom().lookup().clb_net(atom_net);
5757
5858
5959
Cluster net Id to Atom net Id
@@ -62,4 +62,4 @@ To get the net Id in the AtomNetlist from its Id in the ClusteredNetlist, use At
6262

6363
.. code-block:: cpp
6464
65-
ClusterNetId atom_net = g_vpr_ctx.atom().lookup.atom_net(clb_net);
65+
ClusterNetId atom_net = g_vpr_ctx.atom().lookup().atom_net(clb_net);

utils/fasm/src/fasm.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ static AtomNetId _find_atom_input_logical_net(const t_pb* atom, const t_pb_route
343343

344344
static LogicVec lut_outputs(const t_pb* atom_pb, size_t num_inputs, const t_pb_routes &pb_route) {
345345
auto& atom_ctx = g_vpr_ctx.atom();
346-
AtomBlockId block_id = atom_ctx.lookup.pb_atom(atom_pb);
347-
const auto& truth_table = atom_ctx.nlist.block_truth_table(block_id);
348-
auto ports = atom_ctx.nlist.block_input_ports(atom_ctx.lookup.pb_atom(atom_pb));
346+
AtomBlockId block_id = atom_ctx.lookup().pb_atom(atom_pb);
347+
const auto& truth_table = atom_ctx.netlist().block_truth_table(block_id);
348+
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().pb_atom(atom_pb));
349349

350350
const t_pb_graph_node* gnode = atom_pb->pb_graph_node;
351351

@@ -384,7 +384,7 @@ static LogicVec lut_outputs(const t_pb* atom_pb, size_t num_inputs, const t_pb_r
384384

385385
if(impl_input_net_id) {
386386
//If there is a valid net connected in the implementation
387-
AtomNetId logical_net_id = atom_ctx.nlist.port_net(port_id, orig_index);
387+
AtomNetId logical_net_id = atom_ctx.netlist().port_net(port_id, orig_index);
388388
VTR_ASSERT(impl_input_net_id == logical_net_id);
389389

390390
//Mark the permutation.
@@ -537,7 +537,7 @@ static const t_pb_routes &find_pb_route(const t_pb* pb) {
537537
void FasmWriterVisitor::check_for_param(const t_pb *atom) {
538538
auto& atom_ctx = g_vpr_ctx.atom();
539539

540-
auto atom_blk_id = atom_ctx.lookup.pb_atom(atom);
540+
auto atom_blk_id = atom_ctx.lookup().pb_atom(atom);
541541
if (atom_blk_id == AtomBlockId::INVALID()) {
542542
return;
543543
}
@@ -580,7 +580,7 @@ void FasmWriterVisitor::check_for_param(const t_pb *atom) {
580580

581581
auto &params = iter->second;
582582

583-
for(const auto& param : atom_ctx.nlist.block_params(atom_blk_id)) {
583+
for(const auto& param : atom_ctx.netlist().block_params(atom_blk_id)) {
584584
auto feature = params.EmitFasmFeature(param.first, param.second);
585585

586586
if(!feature.empty()) {
@@ -592,12 +592,12 @@ void FasmWriterVisitor::check_for_param(const t_pb *atom) {
592592
void FasmWriterVisitor::check_for_lut(const t_pb* atom) {
593593
auto& atom_ctx = g_vpr_ctx.atom();
594594

595-
auto atom_blk_id = atom_ctx.lookup.pb_atom(atom);
595+
auto atom_blk_id = atom_ctx.lookup().pb_atom(atom);
596596
if (atom_blk_id == AtomBlockId::INVALID()) {
597597
return;
598598
}
599599

600-
const t_model* model = atom_ctx.nlist.block_model(atom_blk_id);
600+
const t_model* model = atom_ctx.netlist().block_model(atom_blk_id);
601601
if (model->name == std::string(MODEL_NAMES)) {
602602
VTR_ASSERT(atom->pb_graph_node != nullptr);
603603
const auto *lut_definition = find_lut(atom->pb_graph_node);

utils/fasm/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static bool write_fasm(bool is_flat) {
4141
auto& device_ctx = g_vpr_ctx.device();
4242
auto& atom_ctx = g_vpr_ctx.atom();
4343

44-
std::string fasm_filename = atom_ctx.nlist.netlist_name() + ".fasm";
44+
std::string fasm_filename = atom_ctx.netlist().netlist_name() + ".fasm";
4545
vtr::printf("Writing Implementation FASM: %s\n", fasm_filename.c_str());
4646
std::ofstream fasm_os(fasm_filename);
4747
fasm::FasmWriterVisitor visitor(&device_ctx.arch->strings, fasm_os, is_flat);

utils/route_diag/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ int main(int argc, const char **argv) {
284284

285285
bool is_flat = vpr_setup.RouterOpts.flat_routing;
286286

287-
const Netlist<>& net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().nlist :
287+
const Netlist<>& net_list = is_flat ? (const Netlist<>&)g_vpr_ctx.atom().netlist() :
288288
(const Netlist<>&)g_vpr_ctx.clustering().clb_nlist;
289289

290290
t_chan_width chan_width = setup_chan_width(vpr_setup.RouterOpts,

vpr/src/analysis/timing_reports.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void generate_setup_timing_stats(const std::string& prefix,
2323

2424
print_setup_timing_summary(*timing_ctx.constraints, *timing_info.setup_analyzer(), "Final ", analysis_opts.write_timing_summary);
2525

26-
VprTimingGraphResolver resolver(atom_ctx.nlist, atom_ctx.lookup, *timing_ctx.graph, delay_calc, is_flat, blk_loc_registry);
26+
VprTimingGraphResolver resolver(atom_ctx.netlist(), atom_ctx.lookup(), *timing_ctx.graph, delay_calc, is_flat, blk_loc_registry);
2727
resolver.set_detail_level(analysis_opts.timing_report_detail);
2828

2929
tatum::TimingReporter timing_reporter(resolver, *timing_ctx.graph, *timing_ctx.constraints);
@@ -48,7 +48,7 @@ void generate_hold_timing_stats(const std::string& prefix,
4848

4949
print_hold_timing_summary(*timing_ctx.constraints, *timing_info.hold_analyzer(), "Final ");
5050

51-
VprTimingGraphResolver resolver(atom_ctx.nlist, atom_ctx.lookup, *timing_ctx.graph, delay_calc, is_flat, blk_loc_registry);
51+
VprTimingGraphResolver resolver(atom_ctx.netlist(), atom_ctx.lookup(), *timing_ctx.graph, delay_calc, is_flat, blk_loc_registry);
5252
resolver.set_detail_level(analysis_opts.timing_report_detail);
5353

5454
tatum::TimingReporter timing_reporter(resolver, *timing_ctx.graph, *timing_ctx.constraints);

vpr/src/analytical_place/analytical_placement_flow.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
6363
vtr::ScopedStartFinishTimer timer("Analytical Placement");
6464

6565
// The global state used/modified by this flow.
66-
const AtomNetlist& atom_nlist = g_vpr_ctx.atom().nlist;
66+
const AtomNetlist& atom_nlist = g_vpr_ctx.atom().netlist();
6767
const DeviceContext& device_ctx = g_vpr_ctx.device();
6868
const UserPlaceConstraints& constraints = g_vpr_ctx.floorplanning().constraints;
6969

@@ -107,4 +107,3 @@ void run_analytical_placement_flow(t_vpr_setup& vpr_setup) {
107107
device_ctx.grid);
108108
full_legalizer->legalize(p_placement);
109109
}
110-

vpr/src/analytical_place/full_legalizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static LegalizationClusterId create_new_cluster(PackMoleculeId seed_molecule_id,
234234
VTR_ASSERT(seed_molecule_id.is_valid());
235235
const t_pack_molecule& seed_molecule = prepacker.get_molecule(seed_molecule_id);
236236
AtomBlockId root_atom = seed_molecule.atom_block_ids[seed_molecule.root];
237-
const t_model* root_model = atom_ctx.nlist.block_model(root_atom);
237+
const t_model* root_model = atom_ctx.netlist().block_model(root_atom);
238238

239239
auto itr = primitive_candidate_block_types.find(root_model);
240240
VTR_ASSERT(itr != primitive_candidate_block_types.end());
@@ -535,4 +535,3 @@ void APPack::legalize(const PartialPlacement& p_placement) {
535535
// it.
536536
post_place_sync();
537537
}
538-

vpr/src/base/clustered_netlist_utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void ClusterAtomsLookup::init_lookup() {
4545

4646
cluster_atoms.resize(cluster_ctx.clb_nlist.blocks().size());
4747

48-
for (auto atom_blk_id : atom_ctx.nlist.blocks()) {
49-
ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id);
48+
for (auto atom_blk_id : atom_ctx.netlist().blocks()) {
49+
ClusterBlockId clb_index = atom_ctx.lookup().atom_clb(atom_blk_id);
5050

5151
/* if this data structure is being built alongside the clustered netlist */
5252
/* e.g. when ingesting and legalizing a flat placement solution, some atoms */

vpr/src/base/load_flat_place.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ static void print_flat_cluster(FILE* fp,
7171
// Print a line for each atom.
7272
for (AtomBlockId atom : atoms_lookup[blk_id]) {
7373
// Get the atom pb graph node.
74-
t_pb_graph_node* atom_pbgn = atom_ctx.lookup.atom_pb(atom)->pb_graph_node;
74+
t_pb_graph_node* atom_pbgn = atom_ctx.lookup().atom_pb(atom)->pb_graph_node;
7575

7676
// Print the flat placement information for this atom.
7777
fprintf(fp, "%s %d %d %d %d %d #%zu %s\n",
78-
atom_ctx.nlist.block_name(atom).c_str(),
78+
atom_ctx.netlist().block_name(atom).c_str(),
7979
blk_loc.x, blk_loc.y, blk_loc.layer,
8080
blk_loc.sub_tile,
8181
atom_pbgn->flat_site_index,
@@ -299,7 +299,7 @@ void log_flat_placement_reconstruction_info(
299299
// debugging flat placement reconstruction.
300300
/*
301301
VTR_LOG("%s %d %d %d %d\n",
302-
g_vpr_ctx.atom().nlist.block_name(atom_blk_id).c_str(),
302+
g_vpr_ctx.atom().netlist().block_name(atom_blk_id).c_str(),
303303
clb_loc.loc.x,
304304
clb_loc.loc.y,
305305
clb_loc.loc.layer,
@@ -322,4 +322,3 @@ void log_flat_placement_reconstruction_info(
322322
VTR_LOG("\tPercent of atoms misplaced from the flat placement: %f\n",
323323
static_cast<float>(num_atoms_missplaced) / static_cast<float>(num_atoms));
324324
}
325-

vpr/src/base/netlist_walker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void NetlistWalker::walk() {
66
auto& atom_ctx = g_vpr_ctx.atom();
77
auto& cluster_ctx = g_vpr_ctx.clustering();
88

9-
visitor_.visit_top(atom_ctx.nlist.netlist_name().c_str());
9+
visitor_.visit_top(atom_ctx.netlist().netlist_name().c_str());
1010

1111
for (auto blk_id : cluster_ctx.clb_nlist.blocks()) {
1212
const auto* pb = cluster_ctx.clb_nlist.block_pb(blk_id);

vpr/src/base/netlist_writer.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -827,15 +827,15 @@ class NetlistWriterVisitor : public NetlistVisitor {
827827
auto& atom_ctx = g_vpr_ctx.atom();
828828

829829
//Initialize the pin to tnode look-up
830-
for (AtomPinId pin : atom_ctx.nlist.pins()) {
831-
AtomBlockId blk = atom_ctx.nlist.pin_block(pin);
832-
ClusterBlockId clb_idx = atom_ctx.lookup.atom_clb(blk);
830+
for (AtomPinId pin : atom_ctx.netlist().pins()) {
831+
AtomBlockId blk = atom_ctx.netlist().pin_block(pin);
832+
ClusterBlockId clb_idx = atom_ctx.lookup().atom_clb(blk);
833833

834-
const t_pb_graph_pin* gpin = atom_ctx.lookup.atom_pin_pb_graph_pin(pin);
834+
const t_pb_graph_pin* gpin = atom_ctx.lookup().atom_pin_pb_graph_pin(pin);
835835
VTR_ASSERT(gpin);
836836
int pb_pin_idx = gpin->pin_count_in_cluster;
837837

838-
tatum::NodeId tnode_id = atom_ctx.lookup.atom_pin_tnode(pin);
838+
tatum::NodeId tnode_id = atom_ctx.lookup().atom_pin_tnode(pin);
839839

840840
auto key = std::make_pair(clb_idx, pb_pin_idx);
841841
auto value = std::make_pair(key, tnode_id);
@@ -859,11 +859,11 @@ class NetlistWriterVisitor : public NetlistVisitor {
859859
void visit_atom_impl(const t_pb* atom) override {
860860
auto& atom_ctx = g_vpr_ctx.atom();
861861

862-
auto atom_pb = atom_ctx.lookup.pb_atom(atom);
862+
auto atom_pb = atom_ctx.lookup().pb_atom(atom);
863863
if (atom_pb == AtomBlockId::INVALID()) {
864864
return;
865865
}
866-
const t_model* model = atom_ctx.nlist.block_model(atom_pb);
866+
const t_model* model = atom_ctx.netlist().block_model(atom_pb);
867867

868868
if (model->name == std::string(MODEL_INPUT)) {
869869
inputs_.emplace_back(make_io(atom, PortType::INPUT));
@@ -1787,12 +1787,12 @@ class NetlistWriterVisitor : public NetlistVisitor {
17871787
}
17881788

17891789
auto& atom_ctx = g_vpr_ctx.atom();
1790-
AtomBlockId blk_id = atom_ctx.lookup.pb_atom(atom);
1791-
for (auto param : atom_ctx.nlist.block_params(blk_id)) {
1790+
AtomBlockId blk_id = atom_ctx.lookup().pb_atom(atom);
1791+
for (auto param : atom_ctx.netlist().block_params(blk_id)) {
17921792
params[param.first] = param.second;
17931793
}
17941794

1795-
for (auto attr : atom_ctx.nlist.block_attrs(blk_id)) {
1795+
for (auto attr : atom_ctx.netlist().block_attrs(blk_id)) {
17961796
attrs[attr.first] = attr.second;
17971797
}
17981798

@@ -1809,8 +1809,8 @@ class NetlistWriterVisitor : public NetlistVisitor {
18091809
tatum::NodeId find_tnode(const t_pb* atom, int cluster_pin_idx) {
18101810
auto& atom_ctx = g_vpr_ctx.atom();
18111811

1812-
AtomBlockId blk_id = atom_ctx.lookup.pb_atom(atom);
1813-
ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(blk_id);
1812+
AtomBlockId blk_id = atom_ctx.lookup().pb_atom(atom);
1813+
ClusterBlockId clb_index = atom_ctx.lookup().atom_clb(blk_id);
18141814

18151815
auto key = std::make_pair(clb_index, cluster_pin_idx);
18161816
auto iter = pin_id_to_tnode_lookup_.find(key);
@@ -1840,7 +1840,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
18401840
const t_pb* atom) { //LUT primitive
18411841
auto& atom_ctx = g_vpr_ctx.atom();
18421842

1843-
const t_model* model = atom_ctx.nlist.block_model(atom_ctx.lookup.pb_atom(atom));
1843+
const t_model* model = atom_ctx.netlist().block_model(atom_ctx.lookup().pb_atom(atom));
18441844
VTR_ASSERT(model->name == std::string(MODEL_NAMES));
18451845

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

18531853
//Retrieve the truth table
1854-
const auto& truth_table = atom_ctx.nlist.block_truth_table(atom_ctx.lookup.pb_atom(atom));
1854+
const auto& truth_table = atom_ctx.netlist().block_truth_table(atom_ctx.lookup().pb_atom(atom));
18551855

18561856
//Apply the permutation
18571857
auto permuted_truth_table = permute_truth_table(truth_table, num_inputs, permute);
@@ -1896,7 +1896,7 @@ class NetlistWriterVisitor : public NetlistVisitor {
18961896
//
18971897
//We walk through the logical inputs to this atom (i.e. in the original truth table/netlist)
18981898
//and find the corresponding input in the implementation atom (i.e. in the current netlist)
1899-
auto ports = atom_ctx.nlist.block_input_ports(atom_ctx.lookup.pb_atom(atom_pb));
1899+
auto ports = atom_ctx.netlist().block_input_ports(atom_ctx.lookup().pb_atom(atom_pb));
19001900
if (ports.size() == 1) {
19011901
const t_pb_graph_node* gnode = atom_pb->pb_graph_node;
19021902
VTR_ASSERT(gnode->num_input_ports == 1);
@@ -1913,16 +1913,16 @@ class NetlistWriterVisitor : public NetlistVisitor {
19131913

19141914
if (impl_input_net_id) {
19151915
//If there is a valid net connected in the implementation
1916-
AtomNetId logical_net_id = atom_ctx.nlist.port_net(port_id, orig_index);
1916+
AtomNetId logical_net_id = atom_ctx.netlist().port_net(port_id, orig_index);
19171917

19181918
// Fatal error should be flagged when the net marked in implementation
19191919
// does not match the net marked in input netlist
19201920
if (impl_input_net_id != logical_net_id) {
19211921
VPR_FATAL_ERROR(VPR_ERROR_IMPL_NETLIST_WRITER,
19221922
"Unmatch:\n\tlogical net is '%s' at pin '%lu'\n\timplmented net is '%s' at pin '%s'\n",
1923-
atom_ctx.nlist.net_name(logical_net_id).c_str(),
1923+
atom_ctx.netlist().net_name(logical_net_id).c_str(),
19241924
size_t(orig_index),
1925-
atom_ctx.nlist.net_name(impl_input_net_id).c_str(),
1925+
atom_ctx.netlist().net_name(impl_input_net_id).c_str(),
19261926
gpin->to_string().c_str());
19271927
}
19281928

@@ -2144,11 +2144,11 @@ class MergedNetlistWriterVisitor : public NetlistWriterVisitor {
21442144
void visit_atom_impl(const t_pb* atom) override {
21452145
auto& atom_ctx = g_vpr_ctx.atom();
21462146

2147-
auto atom_pb = atom_ctx.lookup.pb_atom(atom);
2147+
auto atom_pb = atom_ctx.lookup().pb_atom(atom);
21482148
if (atom_pb == AtomBlockId::INVALID()) {
21492149
return;
21502150
}
2151-
const t_model* model = atom_ctx.nlist.block_model(atom_pb);
2151+
const t_model* model = atom_ctx.netlist().block_model(atom_pb);
21522152

21532153
if (model->name == std::string(MODEL_INPUT)) {
21542154
auto merged_io_name = make_io(atom, PortType::INPUT);

0 commit comments

Comments
 (0)