Skip to content

Commit 2e66dc2

Browse files
[SQUASH ME] Removed Max Cluster Size and NoC Grp ID global variables
1 parent 7214aff commit 2e66dc2

10 files changed

+63
-85
lines changed

vpr/src/base/vpr_context.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ struct ClusteringHelperContext : public Context {
317317
/// FIXME: Move this to the cluster context?
318318
ClusterLegalizer cluster_legalizer;
319319

320-
// FIXME: This can be removed by adding an accessor to the cluster legalizer.
321-
int max_cluster_size;
322-
323320
// total number of CLBs
324321
// TODO: Rename to num_legalized_clusters.
325322
// - Maybe even remove this if it becomes trivial.
@@ -347,11 +344,6 @@ struct ClusteringHelperContext : public Context {
347344
// - Ultimately this information can be read from the legalizer if the
348345
// legalizer can be kept alive for longer.
349346
vtr::vector<ClusterBlockId, std::unordered_set<AtomBlockId>> atoms_lookup;
350-
351-
/** Stores the NoC group ID of each atom block. Atom blocks that belong
352-
* to different NoC groups can't be clustered with each other into the
353-
* same clustered block.*/
354-
vtr::vector<AtomBlockId, NocGroupId> atom_noc_grp_id;
355347
};
356348

357349
/**

vpr/src/pack/cluster.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
100100
t_cluster_progress_stats cluster_stats;
101101

102102
//int num_molecules, num_molecules_processed, mols_since_last_print, blocks_since_last_analysis,
103-
int num_blocks_hill_added, max_pb_depth;
103+
int num_blocks_hill_added;
104104

105105
const int verbosity = packer_opts.pack_verbosity;
106106

@@ -143,23 +143,16 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
143143

144144
istart = nullptr;
145145

146-
/* determine bound on cluster size and primitive input size */
147-
helper_ctx.max_cluster_size = 0;
148-
max_pb_depth = 0;
149-
150146
const t_molecule_stats max_molecule_stats = prepacker.calc_max_molecule_stats(atom_ctx.nlist);
151147

152148
prepacker.mark_all_molecules_valid();
153149

154150
cluster_stats.num_molecules = prepacker.get_num_molecules();
155151

156-
// FIXME: The cluster legalizer has max_cluster size within it. We should
157-
// use it!
158-
get_max_cluster_size_and_pb_depth(helper_ctx.max_cluster_size, max_pb_depth);
159-
160152
if (packer_opts.hill_climbing_flag) {
161-
clustering_data.hill_climbing_inputs_avail = new int[helper_ctx.max_cluster_size + 1];
162-
for (int i = 0; i < helper_ctx.max_cluster_size + 1; i++)
153+
size_t max_cluster_size = helper_ctx.cluster_legalizer.get_max_cluster_size();
154+
clustering_data.hill_climbing_inputs_avail = new int[max_cluster_size + 1];
155+
for (size_t i = 0; i < max_cluster_size + 1; i++)
163156
clustering_data.hill_climbing_inputs_avail[i] = 0;
164157
} else {
165158
clustering_data.hill_climbing_inputs_avail = nullptr; /* if used, die hard */
@@ -183,9 +176,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
183176
cluster_stats.blocks_since_last_analysis = 0;
184177
num_blocks_hill_added = 0;
185178

186-
VTR_ASSERT(helper_ctx.max_cluster_size < MAX_SHORT);
187-
/* Limit maximum number of elements for each cluster */
188-
189179
//Default criticalities set to zero (e.g. if not timing driven)
190180
vtr::vector<AtomBlockId, float> atom_criticality(atom_ctx.nlist.blocks().size(), 0.);
191181

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "globals.h"
2323
#include "logic_types.h"
2424
#include "netlist_utils.h"
25+
#include "noc_aware_cluster_util.h"
2526
#include "noc_data_types.h"
2627
#include "pack_types.h"
2728
#include "partition.h"
@@ -39,7 +40,7 @@
3940
/*
4041
* @brief Gets the max cluster size that any logical block can have.
4142
*/
42-
static size_t get_max_cluster_size(const std::vector<t_logical_block_type>& logical_block_types) {
43+
static size_t calc_max_cluster_size(const std::vector<t_logical_block_type>& logical_block_types) {
4344
size_t max_cluster_size = 0;
4445
for (const t_logical_block_type& blk_type : logical_block_types) {
4546
if (is_empty_type(&blk_type))
@@ -1089,9 +1090,6 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
10891090
// - Checking if the atom can be placed in the cluster for floorplanning
10901091
// constraints.
10911092
const FloorplanningContext& floorplanning_ctx = g_vpr_ctx.floorplanning();
1092-
// ClusteringHelperContext used for:
1093-
// - Getting the atom noc group IDs
1094-
const ClusteringHelperContext& cl_helper_ctx = g_vpr_ctx.cl_helper();
10951093
if (log_verbosity > 3) {
10961094
AtomBlockId root_atom = molecule->atom_block_ids[molecule->root];
10971095
VTR_LOG("\t\tTry pack molecule: '%s' (%s)",
@@ -1157,8 +1155,7 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
11571155
if (atom_blk_id) {
11581156
bool block_pack_noc_grp_status = check_cluster_noc_group(atom_blk_id,
11591157
new_cluster_noc_grp_id,
1160-
// FIXME: Get this global access out of here!
1161-
cl_helper_ctx.atom_noc_grp_id,
1158+
atom_noc_grp_id,
11621159
log_verbosity);
11631160
if (!block_pack_noc_grp_status) {
11641161
// Record the failure of this molecule in the current pb stats
@@ -1558,13 +1555,22 @@ void ClusterLegalizer::init(const AtomNetlist& atom_netlist,
15581555
primitives_list[i] = nullptr;
15591556
}
15601557
// Calculate the max cluster size
1561-
max_cluster_size = get_max_cluster_size(logical_block_types);
1558+
max_cluster_size = calc_max_cluster_size(logical_block_types);
1559+
// - Limit maximum number of elements for each cluster.
1560+
VTR_ASSERT(max_cluster_size < MAX_SHORT);
15621561
// Get a reference to the rr graphs.
15631562
lb_type_rr_graphs = t_lb_type_rr_graphs;
15641563
// Get the number of models in the architecture.
15651564
// FIXME: This should probably be caclulated in here since it is possible
15661565
// this gets messed up.
15671566
num_models = t_num_models;
1567+
// Find all NoC router atoms.
1568+
// - TODO: There is a bit of global state in these methods that we can
1569+
// remove somewhat easily.
1570+
std::vector<AtomBlockId> noc_atoms = find_noc_router_atoms(atom_netlist);
1571+
update_noc_reachability_partitions(noc_atoms,
1572+
atom_netlist,
1573+
atom_noc_grp_id);
15681574
// Copy the options passed by the user
15691575
cluster_legalization_strategy = t_cluster_legalization_strategy;
15701576
enable_pin_feasibility_filter = t_enable_pin_feasibility_filter;

vpr/src/pack/cluster_legalizer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ class ClusterLegalizer {
219219
return atom_cluster[blk_id];
220220
}
221221

222+
inline size_t get_max_cluster_size() const {
223+
return max_cluster_size;
224+
}
225+
222226
// FIXME: Consider renaming?
223227
// - is_atom_clustered?
224228
// - Maybe use the inverse. May be more likely to ask if an atom is unclustered?
@@ -291,6 +295,11 @@ class ClusterLegalizer {
291295

292296
vtr::vector_map<AtomBlockId, LegalizationClusterId> atom_cluster;
293297

298+
/// @brief Stores the NoC group ID of each atom block. Atom blocks that
299+
/// belong to different NoC groups can't be clustered with each other
300+
/// into the same clustered block.
301+
vtr::vector<AtomBlockId, NocGroupId> atom_noc_grp_id;
302+
294303
// FIXME: cluster_placement_stats should be private.
295304

296305
// TODO: This should also be a vector.

vpr/src/pack/cluster_util.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "PreClusterDelayCalculator.h"
77
#include "atom_netlist.h"
88
#include "cluster_legalizer.h"
9-
#include "cluster_router.h"
109
#include "cluster_placement.h"
1110
#include "concrete_timing_info.h"
1211
#include "output_clustering.h"
@@ -277,26 +276,6 @@ void check_and_output_clustering(const t_packer_opts& packer_opts,
277276
// VTR_ASSERT(cluster_ctx.clb_nlist.blocks().size() == intra_lb_routing.size());
278277
}
279278

280-
void get_max_cluster_size_and_pb_depth(int& max_cluster_size,
281-
int& max_pb_depth) {
282-
auto& device_ctx = g_vpr_ctx.mutable_device();
283-
int cur_cluster_size, cur_pb_depth;
284-
285-
for (const auto& type : device_ctx.logical_block_types) {
286-
if (is_empty_type(&type))
287-
continue;
288-
289-
cur_cluster_size = get_max_primitives_in_pb_type(type.pb_type);
290-
cur_pb_depth = get_max_depth_of_pb_type(type.pb_type);
291-
if (cur_cluster_size > max_cluster_size) {
292-
max_cluster_size = cur_cluster_size;
293-
}
294-
if (cur_pb_depth > max_pb_depth) {
295-
max_pb_depth = cur_pb_depth;
296-
}
297-
}
298-
}
299-
300279
/*print the header for the clustering progress table*/
301280
void print_pack_status_header() {
302281
VTR_LOG("Starting Clustering - Clustering Progress: \n");

vpr/src/pack/cluster_util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ void check_and_output_clustering(const t_packer_opts& packer_opts,
119119
const t_arch* arch,
120120
const int& num_clb);
121121

122-
void get_max_cluster_size_and_pb_depth(int& max_cluster_size,
123-
int& max_pb_depth);
124-
125122
bool is_atom_blk_in_pb(const AtomBlockId blk_id, const t_pb* pb);
126123

127124
void add_molecule_to_pb_stats_candidates(t_pack_molecule* molecule,

vpr/src/pack/noc_aware_cluster_util.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11

22
#include "noc_aware_cluster_util.h"
3+
#include "atom_netlist.h"
34
#include "globals.h"
45

56
#include <queue>
67

7-
std::vector<AtomBlockId> find_noc_router_atoms() {
8-
const auto& atom_ctx = g_vpr_ctx.atom();
9-
8+
std::vector<AtomBlockId> find_noc_router_atoms(const AtomNetlist& atom_netlist) {
109
// NoC router atoms are expected to have a specific blif model
1110
const std::string noc_router_blif_model_name = "noc_router_adapter_block";
1211

1312
// stores found NoC router atoms
1413
std::vector<AtomBlockId> noc_router_atoms;
1514

1615
// iterate over all atoms and find those whose blif model matches
17-
for (auto atom_id : atom_ctx.nlist.blocks()) {
18-
const t_model* model = atom_ctx.nlist.block_model(atom_id);
16+
for (auto atom_id : atom_netlist.blocks()) {
17+
const t_model* model = atom_netlist.block_model(atom_id);
1918
if (noc_router_blif_model_name == model->name) {
2019
noc_router_atoms.push_back(atom_id);
2120
}
@@ -24,22 +23,23 @@ std::vector<AtomBlockId> find_noc_router_atoms() {
2423
return noc_router_atoms;
2524
}
2625

27-
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms) {
28-
const auto& atom_ctx = g_vpr_ctx.atom();
29-
auto& cl_helper_ctx = g_vpr_ctx.mutable_cl_helper();
30-
const auto& high_fanout_thresholds = g_vpr_ctx.cl_helper().high_fanout_thresholds;
26+
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms,
27+
const AtomNetlist& atom_netlist,
28+
vtr::vector<AtomBlockId, NocGroupId>& atom_noc_grp_id) {
29+
const ClusteringHelperContext& helper_ctx = g_vpr_ctx.cl_helper();
3130
const auto& grid = g_vpr_ctx.device().grid;
3231

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);
3636

3737
// get the total number of atoms
38-
const size_t n_atoms = atom_ctx.nlist.blocks().size();
38+
const size_t n_atoms = atom_netlist.blocks().size();
3939

4040
vtr::vector<AtomBlockId, bool> atom_visited(n_atoms, false);
4141

42-
cl_helper_ctx.atom_noc_grp_id.resize(n_atoms, NocGroupId::INVALID());
42+
atom_noc_grp_id.resize(n_atoms, NocGroupId::INVALID());
4343

4444
int noc_grp_id_cnt = 0;
4545

@@ -68,24 +68,24 @@ void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atom
6868
AtomBlockId current_atom = q.front();
6969
q.pop();
7070

71-
cl_helper_ctx.atom_noc_grp_id[current_atom] = noc_grp_id;
71+
atom_noc_grp_id[current_atom] = noc_grp_id;
7272

73-
for(auto pin : atom_ctx.nlist.block_pins(current_atom)) {
74-
AtomNetId net_id = atom_ctx.nlist.pin_net(pin);
75-
size_t net_fanout = atom_ctx.nlist.net_sinks(net_id).size();
73+
for(auto pin : atom_netlist.block_pins(current_atom)) {
74+
AtomNetId net_id = atom_netlist.pin_net(pin);
75+
size_t net_fanout = atom_netlist.net_sinks(net_id).size();
7676

7777
if (net_fanout >= high_fanout_threshold) {
7878
continue;
7979
}
8080

81-
AtomBlockId driver_atom_id = atom_ctx.nlist.net_driver_block(net_id);
81+
AtomBlockId driver_atom_id = atom_netlist.net_driver_block(net_id);
8282
if (!atom_visited[driver_atom_id]) {
8383
q.push(driver_atom_id);
8484
atom_visited[driver_atom_id] = true;
8585
}
8686

87-
for (auto sink_pin : atom_ctx.nlist.net_sinks(net_id)) {
88-
AtomBlockId sink_atom_id = atom_ctx.nlist.pin_block(sink_pin);
87+
for (auto sink_pin : atom_netlist.net_sinks(net_id)) {
88+
AtomBlockId sink_atom_id = atom_netlist.pin_block(sink_pin);
8989
if (!atom_visited[sink_atom_id]) {
9090
q.push(sink_atom_id);
9191
atom_visited[sink_atom_id] = true;
@@ -96,4 +96,4 @@ void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atom
9696
}
9797

9898
}
99-
}
99+
}

vpr/src/pack/noc_aware_cluster_util.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
*/
1818

1919
#include <vector>
20+
#include "noc_data_types.h"
21+
#include "vtr_vector.h"
2022

21-
#include "vpr_types.h"
23+
class AtomNetlist;
24+
class AtomBlockId;
2225

2326
/**
2427
* @brief Iterates over all atom blocks and check whether
2528
* their blif model is the same as a NoC routers.
2629
*
2730
* @return The atom block IDs of the NoC router blocks in the netlist.
2831
*/
29-
std::vector<AtomBlockId> find_noc_router_atoms();
32+
std::vector<AtomBlockId> find_noc_router_atoms(const AtomNetlist& atom_netlist);
3033

3134

3235
/**
@@ -37,6 +40,8 @@ std::vector<AtomBlockId> find_noc_router_atoms();
3740
*
3841
* @param noc_atoms The atom block IDs of the NoC router blocks in the netlist.
3942
*/
40-
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms);
43+
void update_noc_reachability_partitions(const std::vector<AtomBlockId>& noc_atoms,
44+
const AtomNetlist& atom_netlist,
45+
vtr::vector<AtomBlockId, NocGroupId>& atom_noc_grp_id);
4146

4247
#endif

vpr/src/pack/pack.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "pack.h"
1414
#include "cluster.h"
1515
#include "SetupGrid.h"
16-
#include "noc_aware_cluster_util.h"
1716

1817
/* #define DUMP_PB_GRAPH 1 */
1918
/* #define DUMP_BLIF_INPUT 1 */
@@ -107,15 +106,14 @@ bool try_pack(t_packer_opts* packer_opts,
107106
int pack_iteration = 1;
108107
bool floorplan_regions_overfull = false;
109108

110-
// find all NoC router atoms
111-
// FIXME: This belongs in the legalizer.
112-
auto noc_atoms = find_noc_router_atoms();
113-
update_noc_reachability_partitions(noc_atoms);
114-
115109
while (true) {
116110
free_clustering_data(*packer_opts, clustering_data);
117111

118112
// Initialize the cluster legalizer.
113+
// FIXME: To make things faster, maybe the reset method brings it back
114+
// to its init state?
115+
// - That way we can initialize once. But perhaps this is not worth
116+
// the effort.
119117
helper_ctx.cluster_legalizer.init(atom_ctx.nlist,
120118
atom_ctx.prepacker,
121119
device_ctx.logical_block_types,

0 commit comments

Comments
 (0)