Skip to content

Commit df22e4c

Browse files
[SQUASH ME] Removed Global Variables, Moved Legalizer Up, Started
Working on Free Methods.
1 parent 4cea938 commit df22e4c

11 files changed

+72
-92
lines changed

vpr/src/base/clustered_netlist.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ ClusterNetId ClusteredNetlist::create_net(const std::string& name) {
171171

172172
void ClusteredNetlist::remove_block_impl(const ClusterBlockId blk_id) {
173173
//Remove & invalidate pointers
174-
// FIXME: How will we free the pb?
174+
// FIXME: This cannot set the pb to nullptr properly, causing it to double
175+
// free... Need some way to transfer ownership.
175176
/*
176177
free_pb(block_pbs_[blk_id]);
177178
delete block_pbs_[blk_id];

vpr/src/base/vpr_context.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,27 +313,22 @@ struct ClusteringHelperContext : public Context {
313313
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
314314

315315
/// @brief Class used to construct legal clusters.
316+
/// FIXME: Move this to the cluster context?
316317
ClusterLegalizer cluster_legalizer;
317318

318-
// Stats keeper for placement information during packing/clustering
319-
t_cluster_placement_stats* cluster_placement_stats;
320-
321-
// total number of models in the architecture
322-
int num_models;
323-
319+
// FIXME: This can be removed by adding an accessor to the cluster legalizer.
324320
int max_cluster_size;
325-
t_pb_graph_node** primitives_list;
326-
327-
bool enable_pin_feasibility_filter;
328-
int feasible_block_array_size;
329321

330322
// total number of CLBs
331323
int total_clb_num;
332324

333325
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
326+
// FIXME: This is only used for a handoff between the vpr_setup and the packer.
327+
// This can be made cleaner.
334328
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
335329

336330
// 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.
337332
t_ext_pin_util_targets target_external_pin_util;
338333

339334
// During clustering, a block is related to un-clustered primitives with nets.
@@ -349,10 +344,6 @@ struct ClusteringHelperContext : public Context {
349344
* to different NoC groups can't be clustered with each other into the
350345
* same clustered block.*/
351346
vtr::vector<AtomBlockId, NocGroupId> atom_noc_grp_id;
352-
353-
~ClusteringHelperContext() {
354-
delete[] primitives_list;
355-
}
356347
};
357348

358349
/**

vpr/src/pack/cluster.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ 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-
t_clustering_data& clustering_data) {
78+
t_clustering_data& clustering_data,
79+
size_t num_models) {
7980
/* Does the actual work of clustering multiple netlist blocks *
8081
* into clusters. */
8182

@@ -122,9 +123,6 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
122123
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
123124
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
124125

125-
helper_ctx.enable_pin_feasibility_filter = packer_opts.enable_pin_feasibility_filter;
126-
helper_ctx.feasible_block_array_size = packer_opts.feasible_block_array_size;
127-
128126
std::shared_ptr<PreClusterDelayCalculator> clustering_delay_calc;
129127
std::shared_ptr<SetupTimingInfo> timing_info;
130128

@@ -157,6 +155,8 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
157155

158156
cluster_stats.num_molecules = prepacker.get_num_molecules();
159157

158+
// FIXME: The cluster legalizer has max_cluster size within it. We should
159+
// use it!
160160
get_max_cluster_size_and_pb_depth(helper_ctx.max_cluster_size, max_pb_depth);
161161

162162
if (packer_opts.hill_climbing_flag) {
@@ -171,20 +171,8 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
171171
check_for_duplicate_inputs ();
172172
#endif
173173

174-
// TODO: Try to separate from the helper context.
175-
helper_ctx.cluster_legalizer.init(prepacker,
176-
device_ctx.logical_block_types,
177-
packer_opts.target_external_pin_util,
178-
helper_ctx.lb_type_rr_graphs,
179-
helper_ctx.num_models,
180-
ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
181-
helper_ctx.enable_pin_feasibility_filter,
182-
helper_ctx.feasible_block_array_size,
183-
verbosity);
184-
helper_ctx.cluster_placement_stats = helper_ctx.cluster_legalizer.cluster_placement_stats;
185-
186174
alloc_and_init_clustering(max_molecule_stats,
187-
&(helper_ctx.primitives_list), prepacker,
175+
prepacker,
188176
clustering_data, net_output_feeds_driving_block_input,
189177
unclustered_list_head_size, cluster_stats.num_molecules);
190178

@@ -237,6 +225,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
237225
if (is_cluster_legal)
238226
break;
239227
// Set the legalization strategy of the cluster legalizer.
228+
// FIXME: Pass in the cluster legalizer.
240229
helper_ctx.cluster_legalizer.set_legalization_strategy(strategy);
241230

242231
// FIXME: Remove the reference to the clustered netlist. It is not
@@ -298,8 +287,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
298287
/*it doesn't make sense to do a timing analysis here since there*
299288
*is only one atom block clustered it would not change anything */
300289
}
301-
// FIXME: This is very gross and should be fixed.
302-
// cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_placement_stats[cluster_ctx.clb_nlist.block_type(clb_index)->index]);
290+
// FIXME: This access should be a getter.
303291
cur_cluster_placement_stats_ptr = &(helper_ctx.cluster_legalizer.cluster_placement_stats[cluster_ctx.clb_nlist.block_type(clb_index)->index]);
304292
cluster_stats.num_unrelated_clustering_attempts = 0;
305293
next_molecule = get_molecule_for_cluster(cluster_ctx.clb_nlist.block_pb(clb_index),

vpr/src/pack/cluster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ 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-
t_clustering_data& clustering_data);
25+
t_clustering_data& clustering_data,
26+
size_t num_models);
2627

2728
int get_cluster_of_block(int blkidx);
2829

vpr/src/pack/cluster_legalizer.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ e_block_pack_status ClusterLegalizer::try_pack_molecule(t_pack_molecule* molecul
11611161
if (atom_blk_id) {
11621162
bool block_pack_noc_grp_status = check_cluster_noc_group(atom_blk_id,
11631163
new_cluster_noc_grp_id,
1164+
// FIXME: Get this global access out of here!
11641165
cl_helper_ctx.atom_noc_grp_id,
11651166
log_verbosity);
11661167
if (!block_pack_noc_grp_status) {
@@ -1412,7 +1413,6 @@ ClusterLegalizer::start_new_cluster(t_pack_molecule* molecule,
14121413
// TODO: Move this to the destructor of the cluster class (however, this
14131414
// may cause issues so maybe just make it into a free method)...
14141415
free_pb(new_cluster.pb);
1415-
// free_pb_stats_recursive(new_cluster.cluster_pb);
14161416
delete new_cluster.pb;
14171417
free_router_data(new_cluster.router_data);
14181418
new_cluster_id = LegalizationClusterId::INVALID();
@@ -1436,8 +1436,9 @@ e_block_pack_status ClusterLegalizer::add_mol_to_cluster(t_pack_molecule* molecu
14361436
LegalizationCluster& cluster = legalization_clusters[cluster_id];
14371437
// FIXME: Handle destroyed clusters better.
14381438
VTR_ASSERT(cluster.pb != nullptr && "Cannot destory an already destroyed cluster");
1439-
// FIXME: Why is this different from creating a new cluster?
1440-
t_ext_pin_util target_ext_pin_util = ext_pin_util_targets.get_pin_util(cluster.type->name);
1439+
// Set the target_external_pin_util.
1440+
// FIXME: Remove this access somehow.
1441+
t_ext_pin_util target_ext_pin_util = g_vpr_ctx.cl_helper().target_external_pin_util.get_pin_util(cluster.type->name);
14411442

14421443
e_block_pack_status pack_status = try_pack_molecule(molecule,
14431444
cluster,
@@ -1483,11 +1484,7 @@ void ClusterLegalizer::destroy_cluster(LegalizationClusterId cluster_id) {
14831484
// Casting things to nullptr for safety just in case someone is trying to use it.
14841485
// TODO: Make this a free method!!!
14851486
// This was stolen from the reset method.
1486-
// FIXME: There must be a memory leak somewhere. As we continue to clean
1487-
// the code we will need to check valgrind.
1488-
// - Need to take care of who owns the pb data.
1489-
// free_pb(cluster.cluster_pb);
1490-
// free_pb_stats_recursive(cluster.cluster_pb);
1487+
free_pb(cluster.pb);
14911488
delete cluster.pb;
14921489
cluster.pb = nullptr;
14931490
free_router_data(cluster.router_data);
@@ -1503,7 +1500,6 @@ bool ClusterLegalizer::check_cluster_legality(LegalizationClusterId cluster_id)
15031500

15041501
void ClusterLegalizer::init(const Prepacker& prepacker,
15051502
const std::vector<t_logical_block_type>& logical_block_types,
1506-
const std::vector<std::string>& target_external_pin_util,
15071503
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
15081504
size_t t_num_models,
15091505
ClusterLegalizationStrategy t_cluster_legalization_strategy,
@@ -1528,8 +1524,6 @@ void ClusterLegalizer::init(const Prepacker& prepacker,
15281524
}
15291525
// Calculate the max cluster size
15301526
max_cluster_size = get_max_cluster_size(logical_block_types);
1531-
// Initialize the external pin util targets
1532-
ext_pin_util_targets = t_ext_pin_util_targets(target_external_pin_util);
15331527
// Get a reference to the rr graphs.
15341528
lb_type_rr_graphs = t_lb_type_rr_graphs;
15351529
// Get the number of models in the architecture.
@@ -1567,15 +1561,12 @@ void ClusterLegalizer::reset() {
15671561
// FIXME: It would make sense if this were to call the destroy method
15681562
// somehow.
15691563
for (LegalizationCluster& cluster : legalization_clusters) {
1570-
// FIXME: Handle destroyed clusters better.
1564+
// FIXME: Should improve the interface for destroying a cluster.
15711565
if (cluster.pb == nullptr)
15721566
continue;
15731567
// Free the cluster's data.
15741568
// TODO: Make this a free method!!!
1575-
// FIXME: There must be a memory leak somewhere. As we continue to clean
1576-
// the code we will need to check valgrind.
1577-
// free_pb(cluster.cluster_pb);
1578-
// free_pb_stats_recursive(cluster.cluster_pb);
1569+
free_pb(cluster.pb);
15791570
delete cluster.pb;
15801571
free_router_data(cluster.router_data);
15811572
}

vpr/src/pack/cluster_legalizer.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class ClusterLegalizer {
102102
*/
103103
void init(const Prepacker& prepacker,
104104
const std::vector<t_logical_block_type>& logical_block_types,
105-
const std::vector<std::string>& target_external_pin_util,
106105
std::vector<t_lb_type_rr_node>* t_lb_type_rr_graphs,
107106
size_t t_num_models,
108107
ClusterLegalizationStrategy t_cluster_legalization_strategy,
@@ -214,6 +213,13 @@ class ClusterLegalizer {
214213
log_verbosity = verbosity;
215214
}
216215

216+
// FIXME: We should make a clean method to clean 1 or all clusters.
217+
// - free_pb_stats_recursive for example.
218+
// - free the router data.
219+
// - etc.
220+
// - This is to help reduce the memory overhead of the class without
221+
// breaking anything.
222+
217223
void finalize();
218224

219225
void reset();
@@ -228,6 +234,7 @@ class ClusterLegalizer {
228234
// Need to cross-reference and see what matters and what doesnt for
229235
// legalization. What variables do we touch and does this function
230236
// touch it!
237+
// Stats keeper for placement information during packing/clustering
231238
t_cluster_placement_stats* cluster_placement_stats = nullptr;
232239

233240
private:
@@ -247,12 +254,11 @@ class ClusterLegalizer {
247254

248255
size_t max_cluster_size;
249256

250-
t_ext_pin_util_targets ext_pin_util_targets;
251-
252257
// TODO: This really should not be a pointer to a vector... I think this is
253258
// meant to be a vector of vectors...
254259
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs = nullptr;
255260

261+
// total number of models in the architecture.
256262
size_t num_models;
257263

258264
/// @brief The current legalization strategy of the cluster legalizer.

vpr/src/pack/cluster_util.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ void add_molecule_to_pb_stats_candidates(t_pack_molecule* molecule,
482482

483483
/*****************************************/
484484
void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats,
485-
t_pb_graph_node*** primitives_list,
486485
const Prepacker& prepacker,
487486
t_clustering_data& clustering_data,
488487
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input,
@@ -539,21 +538,10 @@ void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats,
539538
}
540539
}
541540
}
542-
543-
/* alloc and load cluster placement info */
544-
// *cluster_placement_stats = alloc_and_load_cluster_placement_stats();
545-
546-
/* alloc array that will store primitives that a molecule gets placed to,
547-
* primitive_list is referenced by index, for example a atom block in index 2 of a molecule matches to a primitive in index 2 in primitive_list
548-
* this array must be the size of the biggest molecule
549-
*/
550-
size_t max_molecule_size = prepacker.get_max_molecule_size();
551-
*primitives_list = new t_pb_graph_node*[max_molecule_size];
552-
for (size_t i = 0; i < max_molecule_size; i++)
553-
(*primitives_list)[i] = nullptr;
554541
}
555542

556543
/*****************************************/
544+
// FIXME: This now has no users. Should move to legalizers clean method.
557545
void free_pb_stats_recursive(t_pb* pb) {
558546
int i, j;
559547
/* Releases all the memory used by clustering data structures. */
@@ -937,7 +925,7 @@ void store_cluster_info_and_free(const t_packer_opts& packer_opts,
937925

938926
//print clustering progress incrementally
939927
//print_pack_status(num_clb, num_molecules, num_molecules_processed, mols_since_last_print, device_ctx.grid.width(), device_ctx.grid.height());
940-
free_pb_stats_recursive(cur_pb);
928+
//free_pb_stats_recursive(cur_pb);
941929
}
942930

943931
/* Free up data structures and requeue used molecules */

vpr/src/pack/cluster_util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void remove_molecule_from_pb_stats_candidates(t_pack_molecule* molecule,
134134
t_pb* pb);
135135

136136
void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats,
137-
t_pb_graph_node*** primitives_list,
138137
const Prepacker& prepacker,
139138
t_clustering_data& clustering_data,
140139
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input,

vpr/src/pack/pack.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <unordered_set>
22

3+
#include "cluster_legalizer.h"
34
#include "vpr_context.h"
45
#include "vtr_assert.h"
56
#include "vtr_log.h"
@@ -46,8 +47,7 @@ bool try_pack(t_packer_opts* packer_opts,
4647
VTR_LOG("Begin packing '%s'.\n", packer_opts->circuit_file_name.c_str());
4748

4849
/* determine number of models in the architecture */
49-
helper_ctx.num_models = count_models(user_models);
50-
helper_ctx.num_models += count_models(library_models);
50+
size_t num_models = count_models(user_models) + count_models(library_models);
5151

5252
is_clock = alloc_and_load_is_clock();
5353
is_global.insert(is_clock.begin(), is_clock.end());
@@ -114,6 +114,16 @@ bool try_pack(t_packer_opts* packer_opts,
114114
while (true) {
115115
free_clustering_data(*packer_opts, clustering_data);
116116

117+
// Initialize the cluster legalizer.
118+
helper_ctx.cluster_legalizer.init(atom_mutable_ctx.prepacker,
119+
device_ctx.logical_block_types,
120+
helper_ctx.lb_type_rr_graphs,
121+
num_models,
122+
ClusterLegalizationStrategy::SKIP_INTRA_LB_ROUTE,
123+
packer_opts->enable_pin_feasibility_filter,
124+
packer_opts->feasible_block_array_size,
125+
packer_opts->pack_verbosity);
126+
117127
//Cluster the netlist
118128
helper_ctx.num_used_type_instances = do_clustering(
119129
*packer_opts,
@@ -126,7 +136,8 @@ bool try_pack(t_packer_opts* packer_opts,
126136
balance_block_type_util,
127137
attraction_groups,
128138
floorplan_regions_overfull,
129-
clustering_data);
139+
clustering_data,
140+
num_models);
130141

131142
//Try to size/find a device
132143
bool fits_on_device = try_size_device_grid(*arch, helper_ctx.num_used_type_instances, packer_opts->target_device_utilization, packer_opts->device_layout);
@@ -227,8 +238,8 @@ bool try_pack(t_packer_opts* packer_opts,
227238
g_vpr_ctx.mutable_floorplanning().cluster_constraints.clear();
228239
//attraction_groups.reset_attraction_groups();
229240

230-
free_cluster_placement_stats(helper_ctx.cluster_placement_stats);
231-
delete[] helper_ctx.primitives_list;
241+
// Reset the cluster legalizer for re-clustering.
242+
helper_ctx.cluster_legalizer.reset();
232243

233244
++pack_iteration;
234245
}
@@ -255,6 +266,9 @@ bool try_pack(t_packer_opts* packer_opts,
255266
VTR_LOG("IS THIS YOUR CARD?\n");
256267
free_clustering_data(*packer_opts, clustering_data);
257268

269+
// Clear the cluster legalizer.
270+
helper_ctx.cluster_legalizer.reset();
271+
258272
VTR_LOG("\n");
259273
VTR_LOG("Netlist conversion complete.\n");
260274
VTR_LOG("\n");

vpr/src/pack/re_cluster.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ bool move_mol_to_new_cluster(t_pack_molecule* molecule,
6060
is_created = start_new_cluster_for_mol(molecule,
6161
block_type,
6262
block_mode,
63-
helper_ctx.feasible_block_array_size,
64-
helper_ctx.enable_pin_feasibility_filter,
63+
0, // helper_ctx.feasible_block_array_size,
64+
false, // helper_ctx.enable_pin_feasibility_filter,
6565
new_clb,
6666
during_packing,
6767
verbosity,

0 commit comments

Comments
 (0)