Skip to content

Commit 7214aff

Browse files
[SQUASH ME] Removed More Global Variables
1 parent 083f15a commit 7214aff

14 files changed

+86
-52
lines changed

vpr/src/base/read_netlist.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#include <cstring>
1111
#include <ctime>
1212
#include <map>
13+
#include <unordered_set>
1314

1415
#include "pugixml.hpp"
1516
#include "pugixml_loc.hpp"
1617
#include "pugixml_util.hpp"
1718

19+
#include "vpr_context.h"
1820
#include "vtr_assert.h"
1921
#include "vtr_util.h"
2022
#include "vtr_log.h"
@@ -75,6 +77,7 @@ ClusteredNetlist read_netlist(const char* net_file,
7577
std::vector<std::string> circuit_inputs, circuit_outputs, circuit_clocks;
7678

7779
auto& atom_ctx = g_vpr_ctx.mutable_atom();
80+
ClusteringHelperContext& mutable_helper_ctx = g_vpr_ctx.mutable_cl_helper();
7881

7982
int num_primitives = 0;
8083

@@ -247,6 +250,13 @@ ClusteredNetlist read_netlist(const char* net_file,
247250
/* load mapping between atom pins and pb_graph_pins */
248251
load_atom_pin_mapping(clb_nlist);
249252

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+
250260
clock_t end = clock();
251261

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

vpr/src/base/vpr_constraints_writer.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
#include "vpr_constraints_serializer.h"
88
#include "vpr_constraints_uxsdcxx.h"
99

10-
#include "vtr_time.h"
10+
#include "vpr_context.h"
1111

1212
#include "globals.h"
1313
#include "pugixml.hpp"
14-
#include "pugixml_util.hpp"
15-
#include "clustered_netlist_utils.h"
1614

1715
#include <fstream>
16+
#include <unordered_set>
1817
#include "vpr_constraints_writer.h"
1918
#include "region.h"
20-
#include "re_cluster_util.h"
2119

2220
/**
2321
* @brief Create a partition with the given name and a single region.
@@ -30,11 +28,14 @@ static Partition create_partition(const std::string& part_name, const Region& re
3028

3129
void write_vpr_floorplan_constraints(const char* file_name, int expand, bool subtile, int horizontal_partitions, int vertical_partitions) {
3230
VprConstraints constraints;
33-
3431
if (horizontal_partitions != 0 && vertical_partitions != 0) {
35-
setup_vpr_floorplan_constraints_cutpoints(constraints, horizontal_partitions, vertical_partitions);
32+
setup_vpr_floorplan_constraints_cutpoints(constraints,
33+
horizontal_partitions,
34+
vertical_partitions);
3635
} else {
37-
setup_vpr_floorplan_constraints_one_loc(constraints, expand, subtile);
36+
setup_vpr_floorplan_constraints_one_loc(constraints,
37+
expand,
38+
subtile);
3839
}
3940

4041
VprConstraintsSerializer writer(constraints);
@@ -52,9 +53,12 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
5253
}
5354
}
5455

55-
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile) {
56+
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
57+
int expand,
58+
bool subtile) {
5659
auto& cluster_ctx = g_vpr_ctx.clustering();
5760
auto& block_locs = g_vpr_ctx.placement().block_locs();
61+
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
5862

5963
int part_id = 0;
6064
/*
@@ -83,19 +87,21 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
8387
part.set_part_region(pr);
8488
constraints.mutable_place_constraints().add_partition(part);
8589

86-
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
87-
90+
const std::unordered_set<AtomBlockId>& atoms = helper_ctx.atoms_lookup[blk_id];
8891
for (AtomBlockId atom_id : atoms) {
8992
constraints.mutable_place_constraints().add_constrained_atom(atom_id, partid);
9093
}
9194
part_id++;
9295
}
9396
}
9497

95-
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints) {
98+
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
99+
int horizontal_cutpoints,
100+
int vertical_cutpoints) {
96101
auto& cluster_ctx = g_vpr_ctx.clustering();
97102
auto& block_locs = g_vpr_ctx.placement().block_locs();
98103
auto& device_ctx = g_vpr_ctx.device();
104+
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
99105

100106
const int n_layers = device_ctx.grid.get_num_layers();
101107

@@ -158,7 +164,7 @@ void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int
158164
* appropriate region accordingly
159165
*/
160166
for (ClusterBlockId blk_id : cluster_ctx.clb_nlist.blocks()) {
161-
const std::unordered_set<AtomBlockId>& atoms = cluster_to_atoms(blk_id);
167+
const std::unordered_set<AtomBlockId>& atoms = helper_ctx.atoms_lookup[blk_id];
162168
int x = block_locs[blk_id].loc.x;
163169
int y = block_locs[blk_id].loc.y;
164170
int width = device_ctx.grid.width();

vpr/src/base/vpr_constraints_writer.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
2626
#define VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_
2727

28+
class VprConstraints;
29+
2830
/**
2931
* @brief Write out floorplan constraints to an XML file based on current placement
3032
*
@@ -50,7 +52,9 @@ void write_vpr_floorplan_constraints(const char* file_name, int expand, bool sub
5052
* @param subtile Specifies whether to write out the constraint regions with or without
5153
* subtile values.
5254
*/
53-
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int expand, bool subtile);
55+
void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints,
56+
int expand,
57+
bool subtile);
5458

5559
/**
5660
* @brief Populates VprConstraints by dividing the grid into multiple partitions.
@@ -62,6 +66,8 @@ void setup_vpr_floorplan_constraints_one_loc(VprConstraints& constraints, int ex
6266
* @param horizontal_cutpoints The number of horizontal cut-lines.
6367
* @param vertical_cutpoints The number of vertical cut_lines.
6468
*/
65-
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints, int horizontal_cutpoints, int vertical_cutpoints);
69+
void setup_vpr_floorplan_constraints_cutpoints(VprConstraints& constraints,
70+
int horizontal_cutpoints,
71+
int vertical_cutpoints);
6672

6773
#endif /* VPR_SRC_BASE_VPR_CONSTRAINTS_WRITER_H_ */

vpr/src/base/vpr_context.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,20 +325,15 @@ struct ClusteringHelperContext : public Context {
325325
// - Maybe even remove this if it becomes trivial.
326326
int total_clb_num;
327327

328-
std::vector<LegalizationClusterId> legalized_clusters;
329-
// FIXME: These are overshadowed by the legalizer which can return these!
330-
// - They can just be removed and use the cluster legalizer as the lookup.
331-
// - This also gets invalidated by the compress, making it uber wrong!
332-
vtr::vector_map<LegalizationClusterId, t_pb*> cluster_pb;
333-
vtr::vector_map<LegalizationClusterId, t_logical_block_type_ptr> cluster_type;
334-
335328
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
336329
// FIXME: This is only used for a handoff between the vpr_setup and the packer.
337330
// This can be made cleaner.
338331
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
339332

340333
// the utilization of external input/output pins during packing (between 0 and 1)
341334
// FIXME: This one is weird and may take some work to fix.
335+
// - Putting this in the class and then creating an accessor may fix this
336+
// issue.
342337
t_ext_pin_util_targets target_external_pin_util;
343338

344339
// During clustering, a block is related to un-clustered primitives with nets.
@@ -347,7 +342,10 @@ struct ClusteringHelperContext : public Context {
347342
t_pack_high_fanout_thresholds high_fanout_thresholds;
348343

349344
// A vector of unordered_sets of AtomBlockIds that are inside each clustered block [0 .. num_clustered_blocks-1]
350-
// unordered_set for faster insertion/deletion during the iterative improvement process of packing
345+
// FIXME: This should be moved to a better place. It is populated in read
346+
// netlist and used all over the place.
347+
// - Ultimately this information can be read from the legalizer if the
348+
// legalizer can be kept alive for longer.
351349
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;
352350

353351
/** Stores the NoC group ID of each atom block. Atom blocks that belong

vpr/src/pack/cluster.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
134134
// Index 2 holds the number of LEs that are used for registers only.
135135
std::vector<int> le_count(3, 0);
136136

137-
// helper_ctx.legalized_clusters.clear();
138-
helper_ctx.cluster_pb.clear();
139-
helper_ctx.cluster_type.clear();
140137
helper_ctx.total_clb_num = 0;
141138

142139
/* TODO: This is memory inefficient, fix if causes problems */
@@ -256,13 +253,13 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
256253

257254
VTR_LOGV(verbosity > 2,
258255
"Complex block %d: '%s' (%s) ", helper_ctx.total_clb_num,
259-
helper_ctx.cluster_pb[legalization_cluster_id]->name,
260-
helper_ctx.cluster_type[legalization_cluster_id]->name);
256+
helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id)->name,
257+
helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->name);
261258
VTR_LOGV(verbosity > 2, ".");
262259
//Progress dot for seed-block
263260
fflush(stdout);
264261

265-
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(helper_ctx.cluster_type[legalization_cluster_id]->name);
262+
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->name);
266263
update_cluster_stats(istart,
267264
is_clock, //Set of clock nets
268265
is_global, //Set of global nets (currently all clocks)
@@ -281,9 +278,9 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
281278
*is only one atom block clustered it would not change anything */
282279
}
283280
// FIXME: This access should be a getter.
284-
cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_legalizer.cluster_placement_stats[helper_ctx.cluster_type[legalization_cluster_id]->index]);
281+
cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_legalizer.cluster_placement_stats[helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)->index]);
285282
cluster_stats.num_unrelated_clustering_attempts = 0;
286-
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_pb[legalization_cluster_id],
283+
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id),
287284
attraction_groups,
288285
allow_unrelated_clustering,
289286
packer_opts.prioritize_transitive_connectivity,

vpr/src/pack/cluster_legalizer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ class ClusterLegalizer {
202202
// FIXME: If we had a get_atom_primitive_pb that could remove a lot of
203203
// leaked state!
204204

205+
inline t_logical_block_type_ptr get_cluster_type(LegalizationClusterId cluster_id) const {
206+
VTR_ASSERT_SAFE(cluster_id.is_valid() && (size_t)cluster_id < legalization_clusters.size());
207+
const LegalizationCluster& cluster = legalization_clusters[cluster_id];
208+
return cluster.type;
209+
}
210+
205211
inline const PartitionRegion& get_cluster_pr(LegalizationClusterId cluster_id) const {
206212
VTR_ASSERT_SAFE(cluster_id.is_valid() && (size_t)cluster_id < legalization_clusters.size());
207213
const LegalizationCluster& cluster = legalization_clusters[cluster_id];

vpr/src/pack/cluster_util.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void echo_clusters(char* filename) {
8787
}
8888

8989
for (auto& cluster_atom : cluster_atoms) {
90-
const std::string& cluster_name = helper_ctx.cluster_pb[cluster_atom.first]->name;
90+
const std::string& cluster_name = helper_ctx.cluster_legalizer.get_cluster_pb(cluster_atom.first)->name;
9191
fprintf(fp, "Cluster %s Id: %zu \n", cluster_name.c_str(), size_t(cluster_atom.first));
9292
fprintf(fp, "\tAtoms in cluster: \n");
9393

@@ -160,7 +160,7 @@ void check_clustering() {
160160
atom_ctx.nlist.block_name(blk_id).c_str());
161161
}
162162

163-
if (cur_pb != helper_ctx.cluster_pb[cluster_id]) {
163+
if (cur_pb != helper_ctx.cluster_legalizer.get_cluster_pb(cluster_id)) {
164164
VPR_FATAL_ERROR(VPR_ERROR_PACK,
165165
"CLB %s does not match CLB contained by pb %s.\n",
166166
cur_pb->name, atom_pb->name);
@@ -169,7 +169,8 @@ void check_clustering() {
169169

170170
/* Check that I do not have spurious links in children pbs */
171171
for (LegalizationClusterId cluster_id : helper_ctx.cluster_legalizer.clusters()) {
172-
check_cluster_atom_blocks(helper_ctx.cluster_pb[cluster_id], atoms_checked);
172+
check_cluster_atom_blocks(helper_ctx.cluster_legalizer.get_cluster_pb(cluster_id),
173+
atoms_checked);
173174
}
174175

175176
for (auto blk_id : atom_ctx.nlist.blocks()) {
@@ -804,7 +805,7 @@ void try_fill_cluster(ClusterLegalizer& cluster_legalizer,
804805
}
805806
}
806807

807-
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_pb[legalization_cluster_id],
808+
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id),
808809
attraction_groups,
809810
allow_unrelated_clustering,
810811
packer_opts.prioritize_transitive_connectivity,
@@ -858,7 +859,7 @@ void try_fill_cluster(ClusterLegalizer& cluster_legalizer,
858859
if (packer_opts.timing_driven) {
859860
cluster_stats.blocks_since_last_analysis++; /* historically, timing slacks were recomputed after X number of blocks were packed, but this doesn't significantly alter results so I (jluu) did not port the code */
860861
}
861-
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_pb[legalization_cluster_id],
862+
next_molecule = get_molecule_for_cluster(helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id),
862863
attraction_groups,
863864
allow_unrelated_clustering,
864865
packer_opts.prioritize_transitive_connectivity,
@@ -905,7 +906,7 @@ void store_cluster_info_and_free(const t_packer_opts& packer_opts,
905906
auto& atom_ctx = g_vpr_ctx.atom();
906907

907908
/* store info that will be used later in packing from pb_stats and free the rest */
908-
t_pb* cur_pb = helper_ctx.cluster_pb[legalization_cluster_id];
909+
t_pb* cur_pb = helper_ctx.cluster_legalizer.get_cluster_pb(legalization_cluster_id);
909910
t_pb_stats* pb_stats = cur_pb->pb_stats;
910911
for (const AtomNetId mnet_id : pb_stats->marked_nets) {
911912
int external_terminals = atom_ctx.nlist.net_pins(mnet_id).size() - pb_stats->num_pins_of_net_in_pb[mnet_id];
@@ -932,7 +933,7 @@ void free_data_and_requeue_used_mols_if_illegal(const LegalizationClusterId lega
932933
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
933934

934935
// FIXME: This function is so simple it should be inlined.
935-
num_used_type_instances[helper_ctx.cluster_type[legalization_cluster_id]]--;
936+
num_used_type_instances[helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id)]--;
936937
num_clb--;
937938
seedindex = savedseedindex;
938939

@@ -1358,8 +1359,6 @@ void start_new_cluster(ClusterLegalizer& cluster_legalizer,
13581359
}
13591360
cluster_pb->name = vtr::strdup(root_atom_name.c_str());
13601361
// FIXME: Clean this up.
1361-
g_vpr_ctx.mutable_cl_helper().cluster_pb.insert(new_cluster_id, cluster_pb);
1362-
g_vpr_ctx.mutable_cl_helper().cluster_type.insert(new_cluster_id, type);
13631362
legalization_cluster_id = new_cluster_id;
13641363
block_type = type;
13651364
break;
@@ -1558,7 +1557,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
15581557
auto& atom_ctx = g_vpr_ctx.atom();
15591558
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
15601559

1561-
auto cluster_type = helper_ctx.cluster_type[legalization_cluster_id];
1560+
auto cluster_type = helper_ctx.cluster_legalizer.get_cluster_type(legalization_cluster_id);
15621561

15631562
/*
15641563
* For each cluster, we want to explore the attraction group molecules as potential

vpr/src/pack/output_clustering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ static void count_stats_from_legalizer(std::unordered_map<AtomNetId, bool>& nets
6464
int num_clb_outputs_used[]) {
6565
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
6666
for (LegalizationClusterId cluster_id : helper_ctx.cluster_legalizer.clusters()) {
67-
auto logical_block = helper_ctx.cluster_type[cluster_id];
67+
auto logical_block = helper_ctx.cluster_legalizer.get_cluster_type(cluster_id);
6868
auto physical_tile = pick_physical_type(logical_block);
6969
for (int ipin = 0; ipin < logical_block->pb_type->num_pins; ipin++) {
7070
int physical_pin = get_physical_pin(physical_tile, logical_block, ipin);
7171
auto pin_type = get_pin_type_from_pin_physical_num(physical_tile, physical_pin);
7272

73-
const t_pb* pb = helper_ctx.cluster_pb[cluster_id];
73+
const t_pb* pb = helper_ctx.cluster_legalizer.get_cluster_pb(cluster_id);
7474
// FIXME: Verify this special case. It seems like it is possible
7575
// for the legalizer to return an empty pb_route. In that
7676
// case just return nothing.
@@ -622,11 +622,11 @@ static void clustering_xml_blocks_from_legalizer(pugi::xml_node& block_node,
622622
size_t pb_index = 0;
623623
for (LegalizationClusterId cluster_id : mutabled_helper_ctx.cluster_legalizer.clusters()) {
624624
clustering_xml_block(block_node,
625-
mutabled_helper_ctx.cluster_type[cluster_id],
625+
mutabled_helper_ctx.cluster_legalizer.get_cluster_type(cluster_id),
626626
pb_graph_pin_lookup_from_index_by_type,
627-
mutabled_helper_ctx.cluster_pb[cluster_id],
627+
mutabled_helper_ctx.cluster_legalizer.get_cluster_pb(cluster_id),
628628
pb_index,
629-
mutabled_helper_ctx.cluster_pb[cluster_id]->pb_route);
629+
mutabled_helper_ctx.cluster_legalizer.get_cluster_pb(cluster_id)->pb_route);
630630
pb_index++;
631631
}
632632
}

vpr/src/pack/pack.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ bool try_pack(t_packer_opts* packer_opts,
108108
bool floorplan_regions_overfull = false;
109109

110110
// find all NoC router atoms
111+
// FIXME: This belongs in the legalizer.
111112
auto noc_atoms = find_noc_router_atoms();
112113
update_noc_reachability_partitions(noc_atoms);
113114

0 commit comments

Comments
 (0)