Skip to content

Commit 798811b

Browse files
Merge pull request #2823 from AlexandreSinger/feature-packer-clusterer-cleanup
[Packer] Clean Up Clustering Algorithm
2 parents 37e2cdb + 0f4842d commit 798811b

12 files changed

+710
-680
lines changed

vpr/src/base/SetupVPR.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,6 @@ void SetupPackerOpts(const t_options& Options,
552552

553553
//TODO: document?
554554
PackerOpts->global_clocks = true; /* DEFAULT */
555-
PackerOpts->hill_climbing_flag = false; /* DEFAULT */
556555

557556
PackerOpts->allow_unrelated_clustering = Options.allow_unrelated_clustering;
558557
PackerOpts->connection_driven = Options.connection_driven_clustering;

vpr/src/base/ShowSetup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,6 @@ static void ShowPackerOpts(const t_packer_opts& PackerOpts) {
706706
}
707707
VTR_LOG("PackerOpts.connection_driven: %s", (PackerOpts.connection_driven ? "true\n" : "false\n"));
708708
VTR_LOG("PackerOpts.global_clocks: %s", (PackerOpts.global_clocks ? "true\n" : "false\n"));
709-
VTR_LOG("PackerOpts.hill_climbing_flag: %s", (PackerOpts.hill_climbing_flag ? "true\n" : "false\n"));
710709
VTR_LOG("PackerOpts.inter_cluster_net_delay: %f\n", PackerOpts.inter_cluster_net_delay);
711710
VTR_LOG("PackerOpts.timing_driven: %s", (PackerOpts.timing_driven ? "true\n" : "false\n"));
712711
VTR_LOG("PackerOpts.target_external_pin_util: %s", vtr::join(PackerOpts.target_external_pin_util, " ").c_str());

vpr/src/base/vpr_types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ struct t_packer_opts {
790790
std::string sdc_file_name;
791791
std::string output_file;
792792
bool global_clocks;
793-
bool hill_climbing_flag;
794793
bool timing_driven;
795794
enum e_cluster_seed cluster_seed_type;
796795
float alpha;

vpr/src/pack/attraction_groups.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "attraction_groups.h"
2+
#include "globals.h"
23

34
AttractionInfo::AttractionInfo(bool attraction_groups_on) {
45
const auto& floorplanning_ctx = g_vpr_ctx.floorplanning();

vpr/src/pack/attraction_groups.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#include "vtr_strong_id.h"
1212
#include "vtr_vector.h"
13-
#include "atom_netlist.h"
14-
#include "globals.h"
13+
#include "atom_netlist_fwd.h"
1514

1615
/**
1716
* @file
@@ -78,7 +77,7 @@ class AttractionInfo {
7877

7978
void add_attraction_group(const AttractionGroup& group_info);
8079

81-
int num_attraction_groups();
80+
int num_attraction_groups() const;
8281

8382
int get_att_group_pulls() const;
8483

@@ -118,7 +117,7 @@ inline void AttractionInfo::set_atom_attraction_group(const AtomBlockId atom_id,
118117
attraction_groups[group_id].group_atoms.push_back(atom_id);
119118
}
120119

121-
inline int AttractionInfo::num_attraction_groups() {
120+
inline int AttractionInfo::num_attraction_groups() const {
122121
return attraction_groups.size();
123122
}
124123

vpr/src/pack/cluster_legalizer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,13 @@ class ClusterLegalizer {
421421
return cluster.pr;
422422
}
423423

424+
/// @brief Gets the current number of molecules in the cluster.
425+
inline size_t get_num_molecules_in_cluster(LegalizationClusterId cluster_id) const {
426+
VTR_ASSERT_SAFE(cluster_id.is_valid() && (size_t)cluster_id < legalization_clusters_.size());
427+
const LegalizationCluster& cluster = legalization_clusters_[cluster_id];
428+
return cluster.molecules.size();
429+
}
430+
424431
/// @brief Gets the ID of the cluster that contains the given atom block.
425432
inline LegalizationClusterId get_atom_cluster(AtomBlockId blk_id) const {
426433
VTR_ASSERT_SAFE(blk_id.is_valid() && (size_t)blk_id < atom_cluster_.size());

vpr/src/pack/cluster_util.cpp

Lines changed: 68 additions & 321 deletions
Large diffs are not rendered by default.

vpr/src/pack/cluster_util.h

Lines changed: 27 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CLUSTER_UTIL_H
22
#define CLUSTER_UTIL_H
33

4+
#include <unordered_set>
45
#include <vector>
56
#include "cluster_legalizer.h"
67
#include "pack_types.h"
@@ -63,18 +64,9 @@ struct t_molecule_stats {
6364
int num_used_ext_outputs = 0; //Number of *used external* output pins across all primitives in molecule
6465
};
6566

66-
struct t_cluster_progress_stats {
67-
int num_molecules = 0;
68-
int num_molecules_processed = 0;
69-
int mols_since_last_print = 0;
70-
int blocks_since_last_analysis = 0;
71-
int num_unrelated_clustering_attempts = 0;
72-
};
73-
7467
/* Useful data structures for creating or modifying clusters */
7568
struct t_clustering_data {
76-
int* hill_climbing_inputs_avail;
77-
69+
int unclustered_list_head_size = 0;
7870
/* Keeps a linked list of the unclustered blocks to speed up looking for *
7971
* unclustered blocks with a certain number of *external* inputs. *
8072
* [0..lut_size]. Unclustered_list_head[i] points to the head of the *
@@ -83,16 +75,6 @@ struct t_clustering_data {
8375

8476
//Maintaining a linked list of free molecule data for speed
8577
t_molecule_link* memory_pool = nullptr;
86-
87-
/* Does the atom block that drives the output of this atom net also appear as a *
88-
* receiver (input) pin of the atom net? If so, then by how much?
89-
*
90-
* This is used in the gain routines to avoid double counting the connections from *
91-
* the current cluster to other blocks (hence yielding better clusterings). *
92-
* The only time an atom block should connect to the same atom net *
93-
* twice is when one connection is an output and the other is an input, *
94-
* so this should take care of all multiple connections. */
95-
std::unordered_map<AtomNetId, int> net_output_feeds_driving_block_input;
9678
};
9779

9880
/***********************************/
@@ -112,8 +94,7 @@ void calc_init_packing_timing(const t_packer_opts& packer_opts,
11294
/*
11395
* @brief Free the clustering data structures.
11496
*/
115-
void free_clustering_data(const t_packer_opts& packer_opts,
116-
t_clustering_data& clustering_data);
97+
void free_clustering_data(t_clustering_data& clustering_data);
11798

11899
/*
119100
* @brief Check clustering legality and output it.
@@ -154,8 +135,6 @@ void remove_molecule_from_pb_stats_candidates(t_pack_molecule* molecule,
154135
void alloc_and_init_clustering(const t_molecule_stats& max_molecule_stats,
155136
const Prepacker& prepacker,
156137
t_clustering_data& clustering_data,
157-
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input,
158-
int& unclustered_list_head_size,
159138
int num_molecules);
160139

161140
/*
@@ -195,8 +174,7 @@ void print_pack_status_header();
195174
/*
196175
* @brief Incrementally print progress updates during clustering.
197176
*/
198-
void print_pack_status(int num_clb,
199-
int tot_num_molecules,
177+
void print_pack_status(int tot_num_molecules,
200178
int num_molecules_processed,
201179
int& mols_since_last_print,
202180
int device_width,
@@ -212,42 +190,6 @@ void print_pack_status(int num_clb,
212190
void rebuild_attraction_groups(AttractionInfo& attraction_groups,
213191
const ClusterLegalizer& cluster_legalizer);
214192

215-
/*
216-
* @brief Try to pack next_molecule into the given cluster. If this succeeds
217-
* prepares the next_molecule with a new value to pack next iteration.
218-
*
219-
* This method will print the pack status and update the cluster stats.
220-
*/
221-
void try_fill_cluster(ClusterLegalizer& cluster_legalizer,
222-
const Prepacker& prepacker,
223-
const t_packer_opts& packer_opts,
224-
t_pack_molecule*& prev_molecule,
225-
t_pack_molecule*& next_molecule,
226-
int& num_same_molecules,
227-
t_cluster_progress_stats& cluster_stats,
228-
int num_clb,
229-
const LegalizationClusterId legalization_cluster_id,
230-
AttractionInfo& attraction_groups,
231-
vtr::vector<LegalizationClusterId, std::vector<AtomNetId>>& clb_inter_blk_nets,
232-
bool allow_unrelated_clustering,
233-
const int& high_fanout_threshold,
234-
const std::unordered_set<AtomNetId>& is_clock,
235-
const std::unordered_set<AtomNetId>& is_global,
236-
const std::shared_ptr<SetupTimingInfo>& timing_info,
237-
e_block_pack_status& block_pack_status,
238-
t_molecule_link* unclustered_list_head,
239-
const int& unclustered_list_head_size,
240-
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input,
241-
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
242-
243-
void store_cluster_info_and_free(const t_packer_opts& packer_opts,
244-
const LegalizationClusterId clb_index,
245-
const t_logical_block_type_ptr logic_block_type,
246-
const t_pb_type* le_pb_type,
247-
std::vector<int>& le_count,
248-
const ClusterLegalizer& cluster_legalizer,
249-
vtr::vector<LegalizationClusterId, std::vector<AtomNetId>>& clb_inter_blk_nets);
250-
251193
void update_connection_gain_values(const AtomNetId net_id,
252194
const AtomBlockId clustered_blk_id,
253195
t_pb* cur_pb,
@@ -260,7 +202,7 @@ void update_timing_gain_values(const AtomNetId net_id,
260202
enum e_net_relation_to_clustered_block net_relation_to_clustered_block,
261203
const SetupTimingInfo& timing_info,
262204
const std::unordered_set<AtomNetId>& is_global,
263-
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input);
205+
const std::unordered_set<AtomNetId>& net_output_feeds_driving_block_input);
264206

265207
/*
266208
* @brief Updates the marked data structures, and if gain_flag is GAIN, the gain
@@ -281,7 +223,7 @@ void mark_and_update_partial_gain(const AtomNetId net_id,
281223
const SetupTimingInfo& timing_info,
282224
const std::unordered_set<AtomNetId>& is_global,
283225
const int high_fanout_net_threshold,
284-
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input);
226+
const std::unordered_set<AtomNetId>& net_output_feeds_driving_block_input);
285227

286228
/*
287229
* @brief Updates the total gain array to reflect the desired tradeoff between
@@ -309,24 +251,7 @@ void update_cluster_stats(const t_pack_molecule* molecule,
309251
const int high_fanout_net_threshold,
310252
const SetupTimingInfo& timing_info,
311253
AttractionInfo& attraction_groups,
312-
std::unordered_map<AtomNetId, int>& net_output_feeds_driving_block_input);
313-
314-
/*
315-
* @brief Given a starting seed block, start_new_cluster determines the next
316-
* cluster type to use.
317-
*
318-
* It expands the FPGA if it cannot find a legal cluster for the atom block
319-
*/
320-
void start_new_cluster(ClusterLegalizer& cluster_legalizer,
321-
LegalizationClusterId& legalization_cluster_id,
322-
t_pack_molecule* molecule,
323-
std::map<t_logical_block_type_ptr, size_t>& num_used_type_instances,
324-
const float target_device_utilization,
325-
const t_arch* arch,
326-
const std::string& device_layout_name,
327-
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types,
328-
int verbosity,
329-
bool balance_block_type_utilization);
254+
const std::unordered_set<AtomNetId>& net_output_feeds_driving_block_input);
330255

331256
/*
332257
* @brief Get candidate molecule to pack into currently open cluster
@@ -351,7 +276,7 @@ t_pack_molecule* get_highest_gain_molecule(t_pb* cur_pb,
351276
bool prioritize_transitive_connectivity,
352277
int transitive_fanout_threshold,
353278
const int feasible_block_array_size,
354-
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
279+
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
355280

356281
/*
357282
* @brief Add molecules with strong connectedness to the current cluster to the
@@ -392,7 +317,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
392317
AttractionInfo& attraction_groups,
393318
const int feasible_block_array_size,
394319
LegalizationClusterId clb_index,
395-
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
320+
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
396321

397322
/*
398323
* @brief Add molecules based on transitive connections (eg. 2 hops away) with
@@ -421,7 +346,7 @@ t_pack_molecule* get_molecule_for_cluster(t_pb* cur_pb,
421346
int verbosity,
422347
t_molecule_link* unclustered_list_head,
423348
const int& unclustered_list_head_size,
424-
std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
349+
const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
425350

426351
/*
427352
* @brief Calculates molecule statistics for a single molecule.
@@ -455,6 +380,12 @@ void load_transitive_fanout_candidates(LegalizationClusterId cluster_index,
455380

456381
std::map<const t_model*, std::vector<t_logical_block_type_ptr>> identify_primitive_candidate_block_types();
457382

383+
/**
384+
* @brief Identify which nets in the atom netlist are driven by the same atom
385+
* block that they appear as a receiver (input) pin of.
386+
*/
387+
std::unordered_set<AtomNetId> identify_net_output_feeds_driving_block_input(const AtomNetlist& atom_netlist);
388+
458389
/**
459390
* @brief This function update the pb_type_count data structure by incrementing
460391
* the number of used pb_types in the given packed cluster t_pb
@@ -465,7 +396,12 @@ size_t update_pb_type_count(const t_pb* pb, std::map<t_pb_type*, int>& pb_type_c
465396
* @brief This function updates the le_count data structure from the given
466397
* packed cluster.
467398
*/
468-
void update_le_count(const t_pb* pb, const t_logical_block_type_ptr logic_block_type, const t_pb_type* le_pb_type, std::vector<int>& le_count);
399+
void update_le_count(const t_pb* pb,
400+
const t_logical_block_type_ptr logic_block_type,
401+
const t_pb_type* le_pb_type,
402+
int& num_logic_le,
403+
int& num_reg_le,
404+
int& num_logic_and_reg_le);
469405

470406
void print_pb_type_count_recurr(t_pb_type* type, size_t max_name_chars, size_t curr_depth, std::map<t_pb_type*, int>& pb_type_count);
471407

@@ -478,7 +414,7 @@ void print_pb_type_count(const ClusteredNetlist& clb_nlist);
478414
* @brief This function identifies the logic block type which is defined by the
479415
* block type which has a lut primitive.
480416
*/
481-
t_logical_block_type_ptr identify_logic_block_type(std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
417+
t_logical_block_type_ptr identify_logic_block_type(const std::map<const t_model*, std::vector<t_logical_block_type_ptr>>& primitive_candidate_block_types);
482418

483419
/*
484420
* @brief This function returns the pb_type that is similar to Logic Element (LE)
@@ -499,7 +435,10 @@ bool pb_used_for_blif_model(const t_pb* pb, const std::string& blif_model_name);
499435
/*
500436
* @brief Print the LE count data strurture.
501437
*/
502-
void print_le_count(std::vector<int>& le_count, const t_pb_type* le_pb_type);
438+
void print_le_count(int num_logic_le,
439+
int num_reg_le,
440+
int num_logic_and_reg_le,
441+
const t_pb_type* le_pb_type);
503442

504443
/*
505444
* @brief Given a pointer to a pb in a cluster, this routine returns a pointer

0 commit comments

Comments
 (0)