Skip to content

Commit 3812406

Browse files
[SQUASH ME] More Comments and Improvements
1 parent 8ddca93 commit 3812406

File tree

8 files changed

+159
-126
lines changed

8 files changed

+159
-126
lines changed

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ enum class e_cluster_seed {
168168
BLEND2
169169
};
170170

171-
enum class e_block_pack_status {
172-
BLK_PASSED,
173-
BLK_FAILED_FEASIBLE,
174-
BLK_FAILED_ROUTE,
175-
BLK_FAILED_FLOORPLANNING,
176-
BLK_FAILED_NOC_GROUP,
177-
BLK_STATUS_UNDEFINED
178-
};
179-
180171
struct t_ext_pin_util {
181172
t_ext_pin_util() = default;
182173
t_ext_pin_util(float in, float out)

vpr/src/pack/cluster.cpp

Lines changed: 24 additions & 7 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, detailed_routing_stage;
103+
int num_blocks_hill_added, max_pb_depth;
104104

105105
const int verbosity = packer_opts.pack_verbosity;
106106

@@ -177,7 +177,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
177177
packer_opts.target_external_pin_util,
178178
helper_ctx.lb_type_rr_graphs,
179179
helper_ctx.num_models,
180-
e_detailed_routing_stages::E_DETAILED_ROUTE_AT_END_ONLY,
180+
ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
181181
helper_ctx.enable_pin_feasibility_filter,
182182
helper_ctx.feasible_block_array_size,
183183
verbosity);
@@ -224,8 +224,20 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
224224
while (istart != nullptr) {
225225
bool is_cluster_legal = false;
226226
int saved_seed_index = seed_index;
227-
for (detailed_routing_stage = (int)E_DETAILED_ROUTE_AT_END_ONLY; !is_cluster_legal && detailed_routing_stage != (int)E_DETAILED_ROUTE_INVALID; detailed_routing_stage++) {
228-
helper_ctx.cluster_legalizer.set_detailed_routing_stage(detailed_routing_stage);
227+
// The basic algorithm:
228+
// 1) Try to put all the molecules in that you can without doing the
229+
// full intra-lb route. Then do full legalization at the end.
230+
// 2) If the legalization at the end fails, try again, but this time
231+
// do full legalization for each molecule added to the cluster.
232+
const ClusterLegalizationStrategy legalization_strategies[] = {ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
233+
ClusterLegalizationStrategy::FULL};
234+
for (const ClusterLegalizationStrategy strategy : legalization_strategies) {
235+
// If the cluster is legal, no need to try a stronger cluster legalizer
236+
// mode.
237+
if (is_cluster_legal)
238+
break;
239+
// Set the legalization strategy of the cluster legalizer.
240+
helper_ctx.cluster_legalizer.set_legalization_strategy(strategy);
229241

230242
// FIXME: Remove the reference to the clustered netlist. It is not
231243
// even correct.
@@ -349,10 +361,15 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
349361
primitive_candidate_block_types);
350362
}
351363

352-
if (detailed_routing_stage == (int)E_DETAILED_ROUTE_AT_END_ONLY) {
353-
is_cluster_legal = helper_ctx.cluster_legalizer.check_cluster_legality(legalization_cluster_id);
354-
} else {
364+
if (strategy == ClusterLegalizationStrategy::FULL) {
365+
// If the legalizer fully legalized for every molecule added,
366+
// the cluster should be legal.
355367
is_cluster_legal = true;
368+
} else {
369+
// If the legalizer did not check everything for every molecule,
370+
// need to check that the full cluster is legal (need to perform
371+
// intra-lb routing).
372+
is_cluster_legal = helper_ctx.cluster_legalizer.check_cluster_legality(legalization_cluster_id);
356373
}
357374

358375
if (is_cluster_legal) {

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 47 additions & 46 deletions
Large diffs are not rendered by default.

vpr/src/pack/cluster_legalizer.h

Lines changed: 72 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class t_ext_pin_util_targets;
1515
class t_pack_molecule;
1616
class t_pb;
1717
class t_pb_graph_node;
18-
enum class e_block_pack_status;
1918
struct t_ext_pin_util;
2019
struct t_lb_router_data;
2120

@@ -25,11 +24,22 @@ struct t_lb_router_data;
2524
struct legalization_cluster_id_tag;
2625
typedef vtr::StrongId<legalization_cluster_id_tag, size_t> LegalizationClusterId;
2726

28-
// FIXME: Make this an enum class and use proper format.
29-
enum e_detailed_routing_stages {
30-
E_DETAILED_ROUTE_AT_END_ONLY = 0,
31-
E_DETAILED_ROUTE_FOR_EACH_ATOM,
32-
E_DETAILED_ROUTE_INVALID
27+
/// @brief The different legalization strategies the cluster legalizer can perform.
28+
///
29+
/// Allows the user of the API to select how thorough the legalizer should be.
30+
enum class ClusterLegalizationStrategy {
31+
FULL, // Run the full legalizer (including intra-lb routing)
32+
SKIP_INTRA_LB_ROUTE // Do all legality checks except intra-lb routing
33+
};
34+
35+
/// @brief The status of the cluster legalization.
36+
enum class e_block_pack_status {
37+
BLK_PASSED, // Passed legalization.
38+
BLK_FAILED_FEASIBLE, // Failed due to block not feasibly being able to go in the cluster.
39+
BLK_FAILED_ROUTE, // Failed due to intra-lb routing failure.
40+
BLK_FAILED_FLOORPLANNING, // Failed due to not being compatible with the cluster's current PartitionRegion.
41+
BLK_FAILED_NOC_GROUP, // Failed due to not being compatible with the cluster's NoC group.
42+
BLK_STATUS_UNDEFINED // Undefined status. Something went wrong.
3343
};
3444

3545
/*
@@ -49,25 +59,25 @@ struct LegalizationCluster {
4959
/// FIXME: We should be more careful with how this is allocated. Instead of
5060
/// pointers, we really should use IDs and store them in a standard
5161
/// container.
52-
t_pb* cluster_pb;
62+
t_pb* pb;
5363

5464
/// @brief The logical block type this cluster represents.
55-
t_logical_block_type_ptr cluster_type;
65+
t_logical_block_type_ptr type;
5666

5767
/// @brief The partition region of legal positions this cluster can be placed.
5868
/// Used to detect if a molecule can physically be placed in a cluster.
59-
PartitionRegion cluster_pr;
69+
PartitionRegion pr;
6070

6171
/// @brief The NoC group that this cluster is a part of. Is used to check if
6272
/// a candidate primitive is in the same NoC group as the atom blocks
6373
/// that have already been added to the primitive.
64-
NocGroupId cluster_noc_grp_id;
74+
NocGroupId noc_grp_id;
6575

6676
/// @brief The router data of the intra lb router used for this cluster.
6777
// NOTE: This may not actually need to be kept per cluster... Not sure...
6878
// I think this is passed into the subroutines to prevent repetitive work
6979
// in the lb router; but I am not sure...
70-
t_lb_router_data* cluster_router_data;
80+
t_lb_router_data* router_data;
7181
};
7282

7383
// FIXME: We should completely remove access to the atom context. The legalizer
@@ -82,19 +92,21 @@ class ClusterLegalizer {
8292
const t_ext_pin_util& max_external_pin_util);
8393
public:
8494

95+
// Default constructor. Use the init method to initialize the legalizer.
8596
ClusterLegalizer() = default;
8697

8798
/*
8899
* @brief Initialize the ClusterLegalizer class. Must be called before use.
89100
*
90101
* Allocates internal state.
102+
* FIXME: See if we can simplify the parameters. Can any of these be inferred?
91103
*/
92104
void init(const Prepacker& prepacker,
93105
const std::vector<t_logical_block_type>& logical_block_types,
94106
const std::vector<std::string>& target_external_pin_util,
95107
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
96108
size_t t_num_models,
97-
int t_detailed_routing_stage,
109+
ClusterLegalizationStrategy t_cluster_legalization_strategy,
98110
bool t_enable_pin_feasibility_filter,
99111
int t_feasible_block_array_size,
100112
int t_log_verbosity,
@@ -147,27 +159,58 @@ class ClusterLegalizer {
147159
VTR_ASSERT(false && "Not implemented.");
148160
}
149161

162+
// TODO: It would be nice to have an API to remove a molecule from a cluster.
163+
150164
// TODO: Make a better name for this. The basic idea is that it will uncluster
151165
// all molecules in the cluster and free all aspects of the cluster.
152166
void destroy_cluster(LegalizationClusterId cluster_id);
153167

154168
/*
155-
* @brief Double check that the given cluster is legal.
169+
* @brief Check that the given cluster is fully legal.
156170
*
157171
* This method runs an intra_lb_route on the given cluster. This ignores
158-
* the detailed_routing_stage parameter to this class.
172+
* the cluster legalization strategy set by the user. This method will not
173+
* correct the problematic molecules, it will only return true if the
174+
* cluster is legal and false if it is not.
175+
*
176+
* @param cluster_id The ID of the cluster to fully legalize.
177+
*
178+
* @return True if the cluster is legal, false otherwise.
159179
*/
160180
bool check_cluster_legality(LegalizationClusterId cluster_id);
161181

162-
inline const LegalizationCluster& get_cluster(LegalizationClusterId cluster_id) const {
182+
inline t_pb* get_cluster_pb(LegalizationClusterId cluster_id) const {
163183
VTR_ASSERT_SAFE(cluster_id.is_valid() && (size_t)cluster_id < legalization_clusters.size());
164-
return legalization_clusters[cluster_id];
184+
LegalizationCluster cluster = legalization_clusters[cluster_id];
185+
return cluster.pb;
165186
}
166187

167-
void inline set_detailed_routing_stage(int stage) {
168-
detailed_routing_stage = stage;
188+
/*
189+
* @brief Set the legalization strategy of the cluster legalizer.
190+
*
191+
* This allows the strategy of the cluster legalizer to change based on the
192+
* needs of the user. For example, one can set the legalizer to use a more
193+
* relaxed strategy to insert a batch of molecules in cheaply, saving the
194+
* full legalizerion for the end (using check_cluster_legality).
195+
*
196+
* @param strategy The strategy to set the cluster legalizer to.
197+
*/
198+
void inline set_legalization_strategy(ClusterLegalizationStrategy strategy) {
199+
cluster_legalization_strategy = strategy;
169200
}
170201

202+
/*
203+
* @brief Set how verbose the log messages should be for the cluster legalizer.
204+
*
205+
* This allows the user to set the verbosity at different points for easier
206+
* usability.
207+
*
208+
* Set the verbosity to 4 to see most of the log messages on how the molecules
209+
* move through the legalizer.
210+
* Set the verbosity to 5 to see all the log messages in the legalizer.
211+
*
212+
* @param verbosity The value to set the verbosity to.
213+
*/
171214
inline void set_log_verbosity(int verbosity) {
172215
log_verbosity = verbosity;
173216
}
@@ -176,15 +219,23 @@ class ClusterLegalizer {
176219

177220
void reset();
178221

222+
/// @brief Destructor of the class. Calls the reset method.
179223
~ClusterLegalizer() { reset(); }
180224

181225
// TODO: This should be a vector.
226+
// FIXME: Make this private and create a getter. This may need to be left
227+
// accessible.
228+
// FIXME: Something fishy is going on with this. See update_cluster_stats.
229+
// Need to cross-reference and see what matters and what doesnt for
230+
// legalization. What variables do we touch and does this function
231+
// touch it!
182232
t_cluster_placement_stats* cluster_placement_stats = nullptr;
183233

184234
private:
185235
/// @brief Lookup table for which cluster each molecule is in.
186236
std::unordered_map<t_pack_molecule*, LegalizationClusterId> molecule_cluster;
187-
237+
238+
/// @brief List of all legalization clusters.
188239
vtr::vector<LegalizationClusterId, LegalizationCluster> legalization_clusters;
189240

190241
// FIXME: This can be made a vector if the atom netlist is passed into init.
@@ -205,8 +256,8 @@ class ClusterLegalizer {
205256

206257
size_t num_models;
207258

208-
// TODO: Make this a better enum (enum class).
209-
int detailed_routing_stage;
259+
/// @brief The current legalization strategy of the cluster legalizer.
260+
ClusterLegalizationStrategy cluster_legalization_strategy;
210261

211262
bool enable_pin_feasibility_filter;
212263

vpr/src/pack/cluster_util.cpp

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -300,31 +300,6 @@ void get_max_cluster_size_and_pb_depth(int& max_cluster_size,
300300
}
301301
}
302302

303-
bool check_cluster_legality(const int& verbosity,
304-
const int& detailed_routing_stage,
305-
t_lb_router_data* router_data) {
306-
bool is_cluster_legal;
307-
308-
if (detailed_routing_stage == (int)E_DETAILED_ROUTE_AT_END_ONLY) {
309-
/* is_mode_conflict does not affect this stage. It is needed when trying to route the packed clusters.
310-
*
311-
* It holds a flag that is used to verify whether try_intra_lb_route ended in a mode conflict issue.
312-
* If the value is TRUE the cluster has to be repacked, and its internal pb_graph_nodes will have more restrict choices
313-
* for what regards the mode that has to be selected
314-
*/
315-
t_mode_selection_status mode_status;
316-
is_cluster_legal = try_intra_lb_route(router_data, verbosity, &mode_status);
317-
if (is_cluster_legal) {
318-
VTR_LOGV(verbosity > 2, "\tPassed route at end.\n");
319-
} else {
320-
VTR_LOGV(verbosity > 0, "Failed route at end, repack cluster trying detailed routing at each stage.\n");
321-
}
322-
} else {
323-
is_cluster_legal = true;
324-
}
325-
return is_cluster_legal;
326-
}
327-
328303
/*print the header for the clustering progress table*/
329304
void print_pack_status_header() {
330305
VTR_LOG("Starting Clustering - Clustering Progress: \n");
@@ -1402,12 +1377,12 @@ void start_new_cluster(ClusterLegalizer& cluster_legalizer,
14021377
// - Also this code may be able to partially be put in the
14031378
// legalizer
14041379
// - also the control flow of this function is really bad.
1405-
const LegalizationCluster& legalization_cluster = cluster_legalizer.get_cluster(new_cluster_id);
1406-
if (legalization_cluster.cluster_pb->name != nullptr) {
1407-
free(legalization_cluster.cluster_pb->name);
1380+
t_pb* cluster_pb = cluster_legalizer.get_cluster_pb(new_cluster_id);
1381+
if (cluster_pb->name != nullptr) {
1382+
free(cluster_pb->name);
14081383
}
1409-
legalization_cluster.cluster_pb->name = vtr::strdup(root_atom_name.c_str());
1410-
clb_index = clb_nlist->create_block(root_atom_name.c_str(), legalization_cluster.cluster_pb, type);
1384+
cluster_pb->name = vtr::strdup(root_atom_name.c_str());
1385+
clb_index = clb_nlist->create_block(root_atom_name.c_str(), cluster_pb, type);
14111386
legalization_cluster_id = new_cluster_id;
14121387
// FIXME: This was stolen out of the legalizer. Need to be made better!
14131388
// - Also it may be wrong. See try_place_atom_block_rec

vpr/src/pack/cluster_util.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ void check_and_output_clustering(const t_packer_opts& packer_opts,
122122
void get_max_cluster_size_and_pb_depth(int& max_cluster_size,
123123
int& max_pb_depth);
124124

125-
bool check_cluster_legality(const int& verbosity,
126-
const int& detailed_routing_stage,
127-
t_lb_router_data* router_data);
128-
129125
bool is_atom_blk_in_pb(const AtomBlockId blk_id, const t_pb* pb);
130126

131127
void add_molecule_to_pb_stats_candidates(t_pack_molecule* molecule,

vpr/src/pack/re_cluster_util.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
121121
t_lb_router_data** router_data,
122122
PartitionRegion& temp_cluster_pr,
123123
NocGroupId& temp_cluster_noc_grp_id,
124-
enum e_detailed_routing_stages detailed_routing_stage,
124+
// enum e_detailed_routing_stages detailed_routing_stage,
125125
int force_site) {
126126
auto& atom_ctx = g_vpr_ctx.atom();
127127
auto& floorplanning_ctx = g_vpr_ctx.mutable_floorplanning();
@@ -160,7 +160,7 @@ bool start_new_cluster_for_mol(t_pack_molecule* molecule,
160160
helper_ctx.num_models,
161161
helper_ctx.max_cluster_size,
162162
clb_index,
163-
detailed_routing_stage,
163+
0/*detailed_routing_stage*/,
164164
*router_data,
165165
0,
166166
enable_pin_feasibility_filter,
@@ -218,7 +218,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
218218
bool during_packing,
219219
t_clustering_data& clustering_data,
220220
t_lb_router_data*& router_data,
221-
enum e_detailed_routing_stages detailed_routing_stage,
221+
// enum e_detailed_routing_stages detailed_routing_stage,
222222
bool enable_pin_feasibility_filter,
223223
int force_site) {
224224

@@ -247,7 +247,7 @@ bool pack_mol_in_existing_cluster(t_pack_molecule* molecule,
247247
helper_ctx.num_models,
248248
helper_ctx.max_cluster_size,
249249
new_clb,
250-
detailed_routing_stage,
250+
0/*detailed_routing_stage*/,
251251
router_data,
252252
0,
253253
enable_pin_feasibility_filter,
@@ -310,7 +310,7 @@ void revert_mol_move(ClusterBlockId old_clb,
310310
helper_ctx.num_models,
311311
helper_ctx.max_cluster_size,
312312
old_clb,
313-
E_DETAILED_ROUTE_FOR_EACH_ATOM,
313+
0/*(int)e_detailed_routing_stages::E_DETAILED_ROUTE_FOR_EACH_ATOM*/,
314314
old_router_data,
315315
0,
316316
helper_ctx.enable_pin_feasibility_filter,
@@ -666,8 +666,10 @@ static void rebuild_cluster_placement_stats(ClusterBlockId clb_index,
666666
}
667667
}
668668

669-
bool is_cluster_legal(t_lb_router_data*& router_data) {
670-
return (check_cluster_legality(0, E_DETAILED_ROUTE_AT_END_ONLY, router_data));
669+
bool is_cluster_legal(t_lb_router_data*& /*router_data*/) {
670+
// FIXME: This should use the new API.
671+
// return (check_cluster_legality(0, (int)e_detailed_routing_stages::E_DETAILED_ROUTE_AT_END_ONLY, router_data));
672+
return true;
671673
}
672674

673675
void commit_mol_removal(const t_pack_molecule* molecule,

0 commit comments

Comments
 (0)