Skip to content

Commit 0c715b6

Browse files
authored
Merge pull request #2051 from MohamedElgammal/re-cluster-api-cont
Building a re-clustering API (cont.)
2 parents 25e723a + 72f2a16 commit 0c715b6

12 files changed

+670
-211
lines changed

vpr/src/base/vpr_api.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,10 @@ void vpr_init_with_options(const t_options* options, t_vpr_setup* vpr_setup, t_a
351351

352352
fflush(stdout);
353353

354-
auto& helper_ctx = g_vpr_ctx.mutable_helper();
354+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
355+
auto& device_ctx = g_vpr_ctx.mutable_device();
355356
helper_ctx.lb_type_rr_graphs = vpr_setup->PackerRRGraph;
357+
device_ctx.pad_loc_type = vpr_setup->PlacerOpts.pad_loc_type;
356358
}
357359

358360
bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
@@ -390,7 +392,7 @@ bool vpr_flow(t_vpr_setup& vpr_setup, t_arch& arch) {
390392

391393
//clean packing-placement data
392394
if (vpr_setup.PackerOpts.doPacking == STAGE_DO) {
393-
auto& helper_ctx = g_vpr_ctx.mutable_helper();
395+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
394396
free_cluster_placement_stats(helper_ctx.cluster_placement_stats);
395397
}
396398

vpr/src/base/vpr_context.h

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,33 @@ struct AtomContext : public Context {
5656
/********************************************************************
5757
* Atom Netlist
5858
********************************************************************/
59+
/**
60+
* @brief constructor
61+
*
62+
* In the constructor initialize the list of pack molecules to nullptr and defines a custom deletor for it
63+
*/
5964
AtomContext()
6065
: list_of_pack_molecules(nullptr, free_pack_molecules) {}
66+
6167
///@brief Atom netlist
6268
AtomNetlist nlist;
6369

6470
///@brief Mappings to/from the Atom Netlist to physically described .blif models
6571
AtomLookup lookup;
6672

67-
///@brief The molecules associated with each atom block
73+
/**
74+
* @brief The molecules associated with each atom block.
75+
*
76+
* This map is loaded in the pre-packing stage and freed at the very end of vpr flow run.
77+
* The pointers in this multimap is shared with list_of_pack_molecules.
78+
*/
6879
std::multimap<AtomBlockId, t_pack_molecule*> atom_molecules;
6980

81+
/**
82+
* @brief A linked list of all the packing molecules that are loaded in pre-packing stage.
83+
*
84+
* Is is useful in freeing the pack molecules at the destructor of the Atom context using free_pack_molecules.
85+
*/
7086
std::unique_ptr<t_pack_molecule, decltype(&free_pack_molecules)> list_of_pack_molecules;
7187
};
7288

@@ -219,6 +235,11 @@ struct DeviceContext : public Context {
219235
* Used to determine when reading rrgraph if file is already loaded.
220236
*/
221237
std::string read_rr_graph_filename;
238+
239+
/*******************************************************************
240+
* Place Related
241+
*******************************************************************/
242+
enum e_pad_loc_type pad_loc_type;
222243
};
223244

224245
/**
@@ -266,23 +287,40 @@ struct ClusteringContext : public Context {
266287
*/
267288
std::map<ClusterBlockId, std::map<int, ClusterNetId>> post_routing_clb_pin_nets;
268289
std::map<ClusterBlockId, std::map<int, int>> pre_routing_net_pin_mapping;
269-
270-
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
271290
};
272291

292+
/**
293+
* @brief State relating to helper data structure using in the clustering stage
294+
*
295+
* This should contain helper data structures that are useful in the clustering/packing stage.
296+
* They are encapsulated here as they are useful in clustering and reclustering algorithms that may be used
297+
* in packing or placement stages.
298+
*/
273299
struct ClusteringHelperContext : public Context {
300+
// A map used to save the number of used instances from each logical block type.
274301
std::map<t_logical_block_type_ptr, size_t> num_used_type_instances;
302+
303+
// Stats keeper for placement information during packing/clustering
275304
t_cluster_placement_stats* cluster_placement_stats;
305+
306+
// total number of models in the architecture
276307
int num_models;
308+
277309
int max_cluster_size;
278310
t_pb_graph_node** primitives_list;
279311

280312
bool enable_pin_feasibility_filter;
281313
int feasible_block_array_size;
282314

315+
// total number of CLBs
283316
int total_clb_num;
317+
318+
// A vector of routing resource nodes within each of logic cluster_ctx.blocks types [0 .. num_logical_block_type-1]
284319
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs;
285320

321+
// the utilization of external input/output pins during packing (between 0 and 1)
322+
t_ext_pin_util_targets target_external_pin_util;
323+
286324
~ClusteringHelperContext() {
287325
free(primitives_list);
288326
}
@@ -494,8 +532,8 @@ class VprContext : public Context {
494532
const ClusteringContext& clustering() const { return clustering_; }
495533
ClusteringContext& mutable_clustering() { return clustering_; }
496534

497-
const ClusteringHelperContext& helper() const { return helper_; }
498-
ClusteringHelperContext& mutable_helper() { return helper_; }
535+
const ClusteringHelperContext& cl_helper() const { return helper_; }
536+
ClusteringHelperContext& mutable_cl_helper() { return helper_; }
499537

500538
const PlacementContext& placement() const { return placement_; }
501539
PlacementContext& mutable_placement() { return placement_; }

vpr/src/base/vpr_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,4 @@ void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_s
263263
free(cluster_placement_stats_list[index].valid_primitives);
264264
}
265265
free(cluster_placement_stats_list);
266-
}
266+
}

vpr/src/base/vpr_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,14 @@ typedef vtr::vector<ClusterBlockId, std::vector<std::vector<int>>> t_clb_opins_u
16901690

16911691
typedef std::vector<std::map<int, int>> t_arch_switch_fanin;
16921692

1693+
/**
1694+
* @brief Free the linked list that saves all the packing molecules.
1695+
*/
16931696
void free_pack_molecules(t_pack_molecule* list_of_pack_molecules);
1697+
1698+
/**
1699+
* @brief Free the linked lists to placement locations based on status of primitive inside placement stats data structure.
1700+
*/
16941701
void free_cluster_placement_stats(t_cluster_placement_stats* cluster_placement_stats);
16951702

16961703
#endif

vpr/src/pack/cluster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
147147
auto& atom_ctx = g_vpr_ctx.atom();
148148
auto& device_ctx = g_vpr_ctx.mutable_device();
149149
auto& cluster_ctx = g_vpr_ctx.mutable_clustering();
150-
auto& helper_ctx = g_vpr_ctx.mutable_helper();
150+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
151151

152152
helper_ctx.enable_pin_feasibility_filter = packer_opts.enable_pin_feasibility_filter;
153153
helper_ctx.feasible_block_array_size = packer_opts.feasible_block_array_size;

vpr/src/pack/cluster_util.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include "tatum/echo_writer.hpp"
1515
#include "tatum/TimingReporter.hpp"
1616

17+
/**
18+
* @file
19+
* @brief This file includes useful structs and functions for building and modifying clustering
20+
*/
21+
1722
#define AAPACK_MAX_HIGH_FANOUT_EXPLORE 10 /* For high-fanout nets that are ignored, consider a maximum of this many sinks, must be less than packer_opts.feasible_block_array_size */
1823
#define AAPACK_MAX_TRANSITIVE_EXPLORE 40 /* When investigating transitive fanout connections in packing, consider a maximum of this many molecules, must be less than packer_opts.feasible_block_array_size */
1924

@@ -74,7 +79,7 @@ struct t_cluster_progress_stats {
7479
int num_unrelated_clustering_attempts = 0;
7580
};
7681

77-
/* Useful data structures for packing */
82+
/* Useful data structures for creating or modifying clusters */
7883
struct t_clustering_data {
7984
vtr::vector<ClusterBlockId, std::vector<t_intra_lb_net>*> intra_lb_routing;
8085
int* hill_climbing_inputs_avail;
@@ -85,6 +90,7 @@ struct t_clustering_data {
8590
* list of blocks with i inputs to be hooked up via external interconnect. */
8691
t_molecule_link* unclustered_list_head = nullptr;
8792

93+
//Maintaining a linked list of free molecule data for speed
8894
t_molecule_link* memory_pool = nullptr;
8995

9096
/* Does the atom block that drives the output of this atom net also appear as a *

vpr/src/pack/pack.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool try_pack(t_packer_opts* packer_opts,
4242
const t_model* library_models,
4343
float interc_delay,
4444
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs) {
45-
auto& helper_ctx = g_vpr_ctx.mutable_helper();
45+
auto& helper_ctx = g_vpr_ctx.mutable_cl_helper();
4646

4747
std::unordered_set<AtomNetId> is_clock;
4848
std::unordered_map<AtomBlockId, t_pb_graph_node*> expected_lowest_cost_pb_gnode; //The molecules associated with each atom block
@@ -113,10 +113,10 @@ bool try_pack(t_packer_opts* packer_opts,
113113
VTR_LOG("Using inter-cluster delay: %g\n", packer_opts->inter_cluster_net_delay);
114114
}
115115

116-
t_ext_pin_util_targets target_external_pin_util = parse_target_external_pin_util(packer_opts->target_external_pin_util);
116+
helper_ctx.target_external_pin_util = parse_target_external_pin_util(packer_opts->target_external_pin_util);
117117
t_pack_high_fanout_thresholds high_fanout_thresholds = parse_high_fanout_thresholds(packer_opts->high_fanout_threshold);
118118

119-
VTR_LOG("Packing with pin utilization targets: %s\n", target_external_pin_util_to_string(target_external_pin_util).c_str());
119+
VTR_LOG("Packing with pin utilization targets: %s\n", target_external_pin_util_to_string(helper_ctx.target_external_pin_util).c_str());
120120
VTR_LOG("Packing with high fanout thresholds: %s\n", high_fanout_thresholds_to_string(high_fanout_thresholds).c_str());
121121

122122
bool allow_unrelated_clustering = false;
@@ -149,7 +149,7 @@ bool try_pack(t_packer_opts* packer_opts,
149149
allow_unrelated_clustering,
150150
balance_block_type_util,
151151
lb_type_rr_graphs,
152-
target_external_pin_util,
152+
helper_ctx.target_external_pin_util,
153153
high_fanout_thresholds,
154154
attraction_groups,
155155
floorplan_regions_overfull,
@@ -211,7 +211,7 @@ bool try_pack(t_packer_opts* packer_opts,
211211
VTR_LOG("Pack iteration is %d\n", pack_iteration);
212212
attraction_groups.set_att_group_pulls(4);
213213
t_ext_pin_util pin_util(1.0, 1.0);
214-
target_external_pin_util.set_block_pin_util("clb", pin_util);
214+
helper_ctx.target_external_pin_util.set_block_pin_util("clb", pin_util);
215215
}
216216

217217
} else {

vpr/src/pack/prepack.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ void free_pack_pattern(t_pack_patterns* pack_pattern);
1818
t_pack_molecule* alloc_and_load_pack_molecules(t_pack_patterns* list_of_pack_patterns,
1919
std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
2020
const int num_packing_patterns);
21-
2221
#endif

0 commit comments

Comments
 (0)