Skip to content

Commit b56a127

Browse files
[SQUASH ME] Removed Most Globals
1 parent 2e66dc2 commit b56a127

17 files changed

+97
-91
lines changed

vpr/src/base/read_netlist.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ ClusteredNetlist read_netlist(const char* net_file,
7777
std::vector<std::string> circuit_inputs, circuit_outputs, circuit_clocks;
7878

7979
auto& atom_ctx = g_vpr_ctx.mutable_atom();
80-
ClusteringHelperContext& mutable_helper_ctx = g_vpr_ctx.mutable_cl_helper();
8180

8281
int num_primitives = 0;
8382

@@ -250,13 +249,6 @@ ClusteredNetlist read_netlist(const char* net_file,
250249
/* load mapping between atom pins and pb_graph_pins */
251250
load_atom_pin_mapping(clb_nlist);
252251

253-
/* Load the mapping between clusters and their atoms */
254-
mutable_helper_ctx.atoms_lookup.resize(clb_nlist.blocks().size());
255-
for (AtomBlockId atom_blk_id : atom_ctx.nlist.blocks()) {
256-
ClusterBlockId atom_cluster_blk_id = atom_ctx.lookup.atom_clb(atom_blk_id);
257-
mutable_helper_ctx.atoms_lookup[atom_cluster_blk_id].insert(atom_blk_id);
258-
}
259-
260252
clock_t end = clock();
261253

262254
VTR_LOG("Finished loading packed FPGA netlist file (took %g seconds).\n", (float)(end - begin) / CLOCKS_PER_SEC);

vpr/src/base/vpr_api.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cstring>
1616
#include <cmath>
1717

18+
#include "vpr_context.h"
1819
#include "vtr_assert.h"
1920
#include "vtr_math.h"
2021
#include "vtr_log.h"
@@ -695,6 +696,7 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
695696
"Must have valid .net filename to load packing");
696697

697698
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
699+
const AtomContext& atom_ctx = g_vpr_ctx.atom();
698700

699701
/* Ensure we have a clean start with void net remapping information */
700702
cluster_ctx.post_routing_clb_pin_nets.clear();
@@ -705,8 +707,15 @@ void vpr_load_packing(t_vpr_setup& vpr_setup, const t_arch& arch) {
705707
vpr_setup.FileNameOpts.verify_file_digests,
706708
vpr_setup.PackerOpts.pack_verbosity);
707709

710+
/* Load the mapping between clusters and their atoms */
711+
cluster_ctx.atoms_lookup.resize(cluster_ctx.clb_nlist.blocks().size());
712+
for (AtomBlockId atom_blk_id : atom_ctx.nlist.blocks()) {
713+
ClusterBlockId atom_cluster_blk_id = atom_ctx.lookup.atom_clb(atom_blk_id);
714+
cluster_ctx.atoms_lookup[atom_cluster_blk_id].insert(atom_blk_id);
715+
}
716+
708717
process_constant_nets(g_vpr_ctx.mutable_atom().nlist,
709-
g_vpr_ctx.atom().lookup,
718+
atom_ctx.lookup,
710719
cluster_ctx.clb_nlist,
711720
vpr_setup.constant_net_method,
712721
vpr_setup.PackerOpts.pack_verbosity);

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
5858
bool subtile) {
5959
auto& cluster_ctx = g_vpr_ctx.clustering();
6060
auto& block_locs = g_vpr_ctx.placement().block_locs();
61-
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
6261

6362
int part_id = 0;
6463
/*
@@ -87,7 +86,7 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
8786
part.set_part_region(pr);
8887
constraints.mutable_place_constraints().add_partition(part);
8988

90-
const std::unordered_set<AtomBlockId>& atoms = helper_ctx.atoms_lookup[blk_id];
89+
const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
9190
for (AtomBlockId atom_id : atoms) {
9291
constraints.mutable_place_constraints().add_constrained_atom(atom_id, partid);
9392
}
@@ -101,7 +100,6 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
101100
auto& cluster_ctx = g_vpr_ctx.clustering();
102101
auto& block_locs = g_vpr_ctx.placement().block_locs();
103102
auto& device_ctx = g_vpr_ctx.device();
104-
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
105103

106104
const int n_layers = device_ctx.grid.get_num_layers();
107105

@@ -164,7 +162,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
164162
* appropriate region accordingly
165163
*/
166164
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
167-
const std::unordered_set<AtomBlockId>& atoms = helper_ctx.atoms_lookup[blk_id];
165+
const std::unordered_set<AtomBlockId>& atoms = cluster_ctx.atoms_lookup[blk_id];
168166
int x = block_locs[blk_id].loc.x;
169167
int y = block_locs[blk_id].loc.y;
170168
int width = device_ctx.grid.width();

vpr/src/base/vpr_context.h

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct AtomContext : public Context {
8585
/// molecules. Has a method to get the pack molecule of an AtomBlock.
8686
/// TODO: This is mainly only used in the clusterer. It can probably be
8787
/// removed from the AtomContext entirely.
88+
/// FIXME: Move this to the clustering helper context. It makes more sense there.
8889
Prepacker prepacker;
8990
};
9091

@@ -300,6 +301,11 @@ struct ClusteringContext : public Context {
300301
*/
301302
std::map<ClusterBlockId, std::map<int, ClusterNetId>> post_routing_clb_pin_nets;
302303
std::map<ClusterBlockId, std::map<int, int>> pre_routing_net_pin_mapping;
304+
305+
// A vector of unordered_sets of AtomBlockIds that are inside each clustered
306+
// block [0 .. num_clustered_blocks-1]
307+
// This is populated when the packing is loaded.
308+
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;
303309
};
304310

305311
/**
@@ -310,40 +316,14 @@ struct ClusteringContext : public Context {
310316
* in packing or placement stages.
311317
*/
312318
struct ClusteringHelperContext : public Context {
313-
// A map used to save the number of used instances from each logical block type.
314-
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
315-
316319
/// @brief Class used to construct legal clusters.
317320
/// FIXME: Move this to the cluster context?
318321
ClusterLegalizer cluster_legalizer;
319322

320-
// total number of CLBs
321-
// TODO: Rename to num_legalized_clusters.
322-
// - Maybe even remove this if it becomes trivial.
323-
int total_clb_num;
324-
325323
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
326324
// FIXME: This is only used for a handoff between the vpr_setup and the packer.
327325
// This can be made cleaner.
328326
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
329-
330-
// the utilization of external input/output pins during packing (between 0 and 1)
331-
// FIXME: This one is weird and may take some work to fix.
332-
// - Putting this in the class and then creating an accessor may fix this
333-
// issue.
334-
t_ext_pin_util_targets target_external_pin_util;
335-
336-
// During clustering, a block is related to un-clustered primitives with nets.
337-
// This relation has three types: low fanout, high fanout, and transitive
338-
// high_fanout_thresholds stores the threshold for nets to a block type to be considered high fanout
339-
t_pack_high_fanout_thresholds high_fanout_thresholds;
340-
341-
// A vector of unordered_sets of AtomBlockIds that are inside each clustered block [0 .. num_clustered_blocks-1]
342-
// FIXME: This should be moved to a better place. It is populated in read
343-
// netlist and used all over the place.
344-
// - Ultimately this information can be read from the legalizer if the
345-
// legalizer can be kept alive for longer.
346-
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;
347327
};
348328

349329
/**

vpr/src/pack/cluster.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
7575
bool balance_block_type_utilization,
7676
AttractionInfo& attraction_groups,
7777
bool& floorplan_regions_overfull,
78+
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
7879
t_clustering_data& clustering_data) {
7980
/* Does the actual work of clustering multiple netlist blocks *
8081
* into clusters. */
@@ -134,7 +135,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
134135
// Index 2 holds the number of LEs that are used for registers only.
135136
std::vector<int> le_count(3, 0);
136137

137-
helper_ctx.total_clb_num = 0;
138+
int total_clb_num = 0;
138139

139140
/* TODO: This is memory inefficient, fix if causes problems */
140141
/* Store stats on nets used by packed block, useful for determining transitively connected blocks
@@ -218,7 +219,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
218219

219220
LegalizationClusterId legalization_cluster_id;
220221

221-
VTR_LOGV(verbosity > 2, "Complex block %d:\n", helper_ctx.total_clb_num);
222+
VTR_LOGV(verbosity > 2, "Complex block %d:\n", total_clb_num);
222223

223224
start_new_cluster(helper_ctx.cluster_legalizer,
224225
legalization_cluster_id,
@@ -233,7 +234,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
233234
//initial molecule in cluster has been processed
234235
cluster_stats.num_molecules_processed++;
235236
cluster_stats.mols_since_last_print++;
236-
print_pack_status(helper_ctx.total_clb_num,
237+
print_pack_status(total_clb_num,
237238
cluster_stats.num_molecules,
238239
cluster_stats.num_molecules_processed,
239240
cluster_stats.mols_since_last_print,
@@ -242,14 +243,14 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
242243
attraction_groups);
243244

244245
VTR_LOGV(verbosity > 2,
245-
"Complex block %d: '%s' (%s) ", helper_ctx.total_clb_num,
246+
"Complex block %d: '%s' (%s) ", total_clb_num,
246247
helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id)->name,
247248
helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->name);
248249
VTR_LOGV(verbosity > 2, ".");
249250
//Progress dot for seed-block
250251
fflush(stdout);
251252

252-
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->name);
253+
int high_fanout_threshold = high_fanout_thresholds.get_threshold(helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->name);
253254
update_cluster_stats(istart,
254255
is_clock, //Set of clock nets
255256
is_global, //Set of global nets (currently all clocks)
@@ -260,7 +261,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
260261
*timing_info,
261262
attraction_groups,
262263
net_output_feeds_driving_block_input);
263-
helper_ctx.total_clb_num++;
264+
total_clb_num++;
264265

265266
if (packer_opts.timing_driven) {
266267
cluster_stats.blocks_since_last_analysis++;
@@ -312,7 +313,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
312313
next_molecule,
313314
num_repeated_molecules,
314315
cluster_stats,
315-
helper_ctx.total_clb_num,
316+
total_clb_num,
316317
legalization_cluster_id,
317318
attraction_groups,
318319
clb_inter_blk_nets,
@@ -344,7 +345,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
344345
istart = save_cluster_routing_and_pick_new_seed(packer_opts, seed_atoms, num_blocks_hill_added, seed_index, cluster_stats);
345346
store_cluster_info_and_free(packer_opts, legalization_cluster_id, logic_block_type, le_pb_type, le_count, clb_inter_blk_nets);
346347
} else {
347-
free_data_and_requeue_used_mols_if_illegal(legalization_cluster_id, saved_seed_index, num_used_type_instances, helper_ctx.total_clb_num, seed_index);
348+
free_data_and_requeue_used_mols_if_illegal(legalization_cluster_id, saved_seed_index, num_used_type_instances, total_clb_num, seed_index);
348349
}
349350
}
350351
}
@@ -357,6 +358,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
357358
//check_floorplan_regions(floorplan_regions_overfull);
358359
floorplan_regions_overfull = floorplan_constraints_regions_overfull();
359360

361+
// Ensure that we have kept track of the number of clusters correctly.
362+
// TODO: The total_clb_num variable could probably just be replaced by
363+
// clusters().size().
364+
VTR_ASSERT(helper_ctx.cluster_legalizer.clusters().size() == (size_t)total_clb_num);
365+
360366
return num_used_type_instances;
361367
}
362368

vpr/src/pack/cluster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
2222
bool balance_block_type_utilization,
2323
AttractionInfo& attraction_groups,
2424
bool& floorplan_regions_overfull,
25+
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
2526
t_clustering_data& clustering_data);
2627

2728
void print_pb_type_count(const ClusteredNetlist& clb_nlist);

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,9 @@ e_block_pack_status ClusterLegalizer::add_mol_to_cluster(t_pack_molecule* molecu
14351435
// FIXME: Handle destroyed clusters better.
14361436
VTR_ASSERT(cluster.pb != nullptr && "Cannot destory an already destroyed cluster");
14371437
// Set the target_external_pin_util.
1438-
// FIXME: Remove this access somehow.
1439-
t_ext_pin_util target_ext_pin_util = g_vpr_ctx.cl_helper().target_external_pin_util.get_pin_util(cluster.type->name);
1438+
// - FIXME: Double check if this can be a reference or not. pass by value
1439+
// may be expensive.
1440+
t_ext_pin_util target_ext_pin_util = target_external_pin_util.get_pin_util(cluster.type->name);
14401441

14411442
e_block_pack_status pack_status = try_pack_molecule(molecule,
14421443
cluster,
@@ -1532,6 +1533,8 @@ void ClusterLegalizer::init(const AtomNetlist& atom_netlist,
15321533
const std::vector<t_logical_block_type>& logical_block_types,
15331534
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
15341535
size_t t_num_models,
1536+
const std::vector<std::string>& target_external_pin_util_str,
1537+
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
15351538
ClusterLegalizationStrategy t_cluster_legalization_strategy,
15361539
bool t_enable_pin_feasibility_filter,
15371540
int t_feasible_block_array_size,
@@ -1555,9 +1558,11 @@ void ClusterLegalizer::init(const AtomNetlist& atom_netlist,
15551558
primitives_list[i] = nullptr;
15561559
}
15571560
// Calculate the max cluster size
1561+
// - Limit maximum number of elements for each cluster to MAX_SHORT
15581562
max_cluster_size = calc_max_cluster_size(logical_block_types);
1559-
// - Limit maximum number of elements for each cluster.
15601563
VTR_ASSERT(max_cluster_size < MAX_SHORT);
1564+
// Get the target external pin utilization
1565+
target_external_pin_util = t_ext_pin_util_targets(target_external_pin_util_str);
15611566
// Get a reference to the rr graphs.
15621567
lb_type_rr_graphs = t_lb_type_rr_graphs;
15631568
// Get the number of models in the architecture.
@@ -1570,6 +1575,7 @@ void ClusterLegalizer::init(const AtomNetlist& atom_netlist,
15701575
std::vector<AtomBlockId> noc_atoms = find_noc_router_atoms(atom_netlist);
15711576
update_noc_reachability_partitions(noc_atoms,
15721577
atom_netlist,
1578+
high_fanout_thresholds,
15731579
atom_noc_grp_id);
15741580
// Copy the options passed by the user
15751581
cluster_legalization_strategy = t_cluster_legalization_strategy;

vpr/src/pack/cluster_legalizer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ class ClusterLegalizer {
113113
const std::vector<t_logical_block_type>& logical_block_types,
114114
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
115115
size_t t_num_models,
116+
const std::vector<std::string>& target_external_pin_util_str,
117+
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
116118
ClusterLegalizationStrategy t_cluster_legalization_strategy,
117119
bool t_enable_pin_feasibility_filter,
118120
int t_feasible_block_array_size,
@@ -219,6 +221,10 @@ class ClusterLegalizer {
219221
return atom_cluster[blk_id];
220222
}
221223

224+
inline t_ext_pin_util_targets& get_target_external_pin_util() {
225+
return target_external_pin_util;
226+
}
227+
222228
inline size_t get_max_cluster_size() const {
223229
return max_cluster_size;
224230
}
@@ -302,6 +308,10 @@ class ClusterLegalizer {
302308

303309
// FIXME: cluster_placement_stats should be private.
304310

311+
/// @brief The utilization of external input/output pins during packing
312+
/// (between 0 and 1).
313+
t_ext_pin_util_targets target_external_pin_util;
314+
305315
// TODO: This should also be a vector.
306316
t_pb_graph_node** primitives_list = nullptr;
307317

vpr/src/pack/cluster_util.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,7 @@ void free_clustering_data(const t_packer_opts& packer_opts,
255255
//check the clustering and output it
256256
void check_and_output_clustering(const t_packer_opts& packer_opts,
257257
const std::unordered_set<AtomNetId>& is_clock,
258-
const t_arch* arch,
259-
const int& num_clb) {
260-
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
261-
262-
VTR_ASSERT(num_clb == (int)helper_ctx.cluster_legalizer.clusters().size());
258+
const t_arch* arch) {
263259
check_clustering();
264260

265261
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_CLUSTERS)) {

vpr/src/pack/cluster_util.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ void free_clustering_data(const t_packer_opts& packer_opts,
116116
//check clustering legality and output it
117117
void check_and_output_clustering(const t_packer_opts& packer_opts,
118118
const std::unordered_set<AtomNetId>& is_clock,
119-
const t_arch* arch,
120-
const int& num_clb);
119+
const t_arch* arch);
121120

122121
bool is_atom_blk_in_pb(const AtomBlockId blk_id, const t_pb* pb);
123122

vpr/src/pack/noc_aware_cluster_util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "noc_aware_cluster_util.h"
33
#include "atom_netlist.h"
44
#include "globals.h"
5+
#include "vpr_types.h"
56

67
#include <queue>
78

@@ -25,11 +26,10 @@ std::vector<AtomBlockId> find_noc_router_atoms(const AtomNetlist& atom_netlist)
2526

2627
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms,
2728
const AtomNetlist& atom_netlist,
29+
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
2830
vtr::vector<AtomBlockId, NocGroupId>& atom_noc_grp_id) {
29-
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
3031
const auto& grid = g_vpr_ctx.device().grid;
3132

32-
const auto& high_fanout_thresholds = helper_ctx.high_fanout_thresholds;
3333
t_logical_block_type_ptr logic_block_type = infer_logic_block_type(grid);
3434
const char* logical_block_name = logic_block_type != nullptr ? logic_block_type->name : "";
3535
const size_t high_fanout_threshold = high_fanout_thresholds.get_threshold(logical_block_name);

vpr/src/pack/noc_aware_cluster_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
class AtomNetlist;
2424
class AtomBlockId;
25+
class t_pack_high_fanout_thresholds;
2526

2627
/**
2728
* @brief Iterates over all atom blocks and check whether
@@ -42,6 +43,7 @@ std::vector<AtomBlockId> find_noc_router_atoms(const AtomNetlist& atom_netlist);
4243
*/
4344
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms,
4445
const AtomNetlist& atom_netlist,
46+
const t_pack_high_fanout_thresholds& high_fanout_threshold,
4547
vtr::vector<AtomBlockId, NocGroupId>& atom_noc_grp_id);
4648

4749
#endif

0 commit comments

Comments
 (0)