Skip to content

Commit b7af89d

Browse files
Change GreedySeedSelector to work with molecules instead of atoms
1 parent 634f6b9 commit b7af89d

File tree

4 files changed

+63
-62
lines changed

4 files changed

+63
-62
lines changed

vpr/src/pack/greedy_clusterer.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
144144
pre_cluster_timing_manager_);
145145

146146
// Pick the first seed molecule.
147-
PackMoleculeId seed_mol_id = seed_selector.get_next_seed(prepacker,
148-
cluster_legalizer);
147+
PackMoleculeId seed_mol_id = seed_selector.get_next_seed(cluster_legalizer);
149148

150149
/****************************************************************
151150
* Clustering
@@ -213,8 +212,7 @@ GreedyClusterer::do_clustering(ClusterLegalizer& cluster_legalizer,
213212
cluster_legalizer);
214213

215214
// Pick new seed.
216-
seed_mol_id = seed_selector.get_next_seed(prepacker,
217-
cluster_legalizer);
215+
seed_mol_id = seed_selector.get_next_seed(cluster_legalizer);
218216
}
219217

220218
// If this architecture has LE physical block, report its usage.

vpr/src/pack/greedy_seed_selector.cpp

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <algorithm>
1111
#include <cmath>
12+
#include <limits>
13+
#include <vector>
1214
#include "PreClusterTimingManager.h"
1315
#include "atom_netlist.h"
1416
#include "cluster_legalizer.h"
@@ -129,11 +131,12 @@ static inline float get_seed_gain(AtomBlockId blk_id,
129131
* criticalities.
130132
*/
131133
static inline void print_seed_gains(const char* fname,
132-
const std::vector<AtomBlockId>& seed_atoms,
133-
const vtr::vector<AtomBlockId, float>& atom_gain,
134+
const std::vector<PackMoleculeId>& seed_mols,
135+
const vtr::vector<PackMoleculeId, float>& molecule_gain,
134136
const vtr::vector<AtomBlockId, float>& atom_criticality,
135137
const AtomNetlist& atom_netlist,
136-
const LogicalModels& models) {
138+
const LogicalModels& models,
139+
const Prepacker& prepacker) {
137140
FILE* fp = vtr::fopen(fname, "w");
138141

139142
// For pretty formatting determine the maximum name length
@@ -148,16 +151,18 @@ static inline void print_seed_gains(const char* fname,
148151

149152
fprintf(fp, "%-*s %-*s %8s %8s\n", max_name_len, "atom_block_name", max_type_len, "atom_block_type", "gain", "criticality");
150153
fprintf(fp, "\n");
151-
for (auto blk_id : seed_atoms) {
152-
std::string name = atom_netlist.block_name(blk_id);
153-
fprintf(fp, "%-*s ", max_name_len, name.c_str());
154+
for (auto mol_id : seed_mols) {
155+
for (AtomBlockId blk_id : prepacker.get_molecule(mol_id).atom_block_ids) {
156+
std::string name = atom_netlist.block_name(blk_id);
157+
fprintf(fp, "%-*s ", max_name_len, name.c_str());
154158

155-
std::string model_name = models.model_name(atom_netlist.block_model(blk_id));
156-
fprintf(fp, "%-*s ", max_type_len, model_name.c_str());
159+
std::string model_name = models.model_name(atom_netlist.block_model(blk_id));
160+
fprintf(fp, "%-*s ", max_type_len, model_name.c_str());
157161

158-
fprintf(fp, "%*f ", std::max((int)strlen("gain"), 8), atom_gain[blk_id]);
159-
fprintf(fp, "%*f ", std::max((int)strlen("criticality"), 8), atom_criticality[blk_id]);
160-
fprintf(fp, "\n");
162+
fprintf(fp, "%*f ", std::max((int)strlen("gain"), 8), molecule_gain[mol_id]);
163+
fprintf(fp, "%*f ", std::max((int)strlen("criticality"), 8), atom_criticality[blk_id]);
164+
fprintf(fp, "\n");
165+
}
161166
}
162167

163168
fclose(fp);
@@ -169,8 +174,8 @@ GreedySeedSelector::GreedySeedSelector(const AtomNetlist& atom_netlist,
169174
const t_molecule_stats& max_molecule_stats,
170175
const LogicalModels& models,
171176
const PreClusterTimingManager& pre_cluster_timing_manager)
172-
: seed_atoms_(atom_netlist.blocks().begin(), atom_netlist.blocks().end()) {
173-
// Seed atoms list is initialized with all atoms in the atom netlist.
177+
: seed_mols_(prepacker.molecules().begin(), prepacker.molecules().end()) {
178+
// Seed molecule list is initialized with all molecule in the netlist.
174179

175180
// Pre-compute the criticality of each atom
176181
// Default criticalities set to zero (e.g. if not timing driven)
@@ -183,20 +188,31 @@ GreedySeedSelector::GreedySeedSelector(const AtomNetlist& atom_netlist,
183188
}
184189
}
185190

186-
// Maintain a lookup table of the seed gain for each atom. This will be
187-
// used to sort the seed atoms.
191+
// Maintain a lookup table of the seed gain for each molecule. This will be
192+
// used to sort the seed molecules.
188193
// Initially all gains are zero.
189-
vtr::vector<AtomBlockId, float> atom_gains(atom_netlist.blocks().size(), 0.f);
190-
191-
// Get the seed gain of each atom.
192-
for (AtomBlockId blk_id : atom_netlist.blocks()) {
193-
atom_gains[blk_id] = get_seed_gain(blk_id,
194-
atom_netlist,
195-
prepacker,
196-
models,
197-
seed_type,
198-
max_molecule_stats,
199-
atom_criticality);
194+
vtr::vector<PackMoleculeId, float> molecule_gains(seed_mols_.size(), 0.f);
195+
196+
// Get the seed gain of each molecule.
197+
for (PackMoleculeId mol_id : seed_mols_) {
198+
// Gain of each molecule is the maximum gain of its atoms
199+
float mol_gain = std::numeric_limits<float>::lowest();
200+
const std::vector<AtomBlockId>& molecule_atoms = prepacker.get_molecule(mol_id).atom_block_ids;
201+
for (AtomBlockId blk_id : molecule_atoms) {
202+
// If the molecule does not fit the entire pack pattern, it's possible to have invalid block ids in the molecule_atoms vector
203+
if (blk_id == AtomBlockId::INVALID()) {
204+
continue;
205+
}
206+
float atom_gain = get_seed_gain(blk_id,
207+
atom_netlist,
208+
prepacker,
209+
models,
210+
seed_type,
211+
max_molecule_stats,
212+
atom_criticality);
213+
mol_gain = std::max(mol_gain, atom_gain);
214+
}
215+
molecule_gains[mol_id] = mol_gain;
200216
}
201217

202218
// Sort seeds in descending order of seed gain (i.e. highest seed gain first)
@@ -207,47 +223,42 @@ GreedySeedSelector::GreedySeedSelector(const AtomNetlist& atom_netlist,
207223
// std::sort which does not specify how equal values are handled). Using a stable
208224
// sort ensures that regardless of the underlying sorting algorithm the same seed
209225
// order is produced regardless of compiler.
210-
auto by_descending_gain = [&](const AtomBlockId lhs, const AtomBlockId rhs) {
211-
return atom_gains[lhs] > atom_gains[rhs];
226+
auto by_descending_gain = [&](const PackMoleculeId lhs, const PackMoleculeId rhs) {
227+
return molecule_gains[lhs] > molecule_gains[rhs];
212228
};
213-
std::stable_sort(seed_atoms_.begin(), seed_atoms_.end(), by_descending_gain);
229+
std::stable_sort(seed_mols_.begin(), seed_mols_.end(), by_descending_gain);
214230

215231
// Print the seed gains if requested.
216232
if (getEchoEnabled() && isEchoFileEnabled(E_ECHO_CLUSTERING_BLOCK_CRITICALITIES)) {
217233
print_seed_gains(getEchoFileName(E_ECHO_CLUSTERING_BLOCK_CRITICALITIES),
218-
seed_atoms_, atom_gains, atom_criticality, atom_netlist, models);
234+
seed_mols_, molecule_gains, atom_criticality, atom_netlist, models, prepacker);
219235
}
220236

221237
// Set the starting seed index (the index of the first molecule to propose).
222238
// The index of the first seed to propose is the first molecule in the
223-
// seed atoms vector (i.e. the one with the highest seed gain).
239+
// seed molecules vector (i.e. the one with the highest seed gain).
224240
seed_index_ = 0;
225241
}
226242

227-
PackMoleculeId GreedySeedSelector::get_next_seed(const Prepacker& prepacker,
228-
const ClusterLegalizer& cluster_legalizer) {
229-
while (seed_index_ < seed_atoms_.size()) {
230-
// Get the current seed atom at the seed index and increment the
243+
PackMoleculeId GreedySeedSelector::get_next_seed(const ClusterLegalizer& cluster_legalizer) {
244+
while (seed_index_ < seed_mols_.size()) {
245+
// Get the current seed molecule at the seed index and increment the
231246
// seed index.
232247
// All previous seed indices have been either proposed already or
233248
// are already clustered. This process assumes that once an atom
234249
// is clustered it will never become unclustered.
235-
AtomBlockId seed_blk_id = seed_atoms_[seed_index_++];
250+
PackMoleculeId seed_molecule_id = seed_mols_[seed_index_++];
236251

237-
// If this atom has been clustered, it cannot be proposed as a seed.
252+
// If this molecule has been clustered, it cannot be proposed as a seed.
238253
// Skip to the next seed.
239-
if (cluster_legalizer.is_atom_clustered(seed_blk_id))
254+
if (cluster_legalizer.is_mol_clustered(seed_molecule_id)) {
240255
continue;
241-
242-
// Get the molecule that contains this atom and return it as the
243-
// next seed.
244-
PackMoleculeId seed_molecule_id = prepacker.get_atom_molecule(seed_blk_id);
245-
VTR_ASSERT(!cluster_legalizer.is_mol_clustered(seed_molecule_id));
256+
}
246257
return seed_molecule_id;
247258
}
248259

249260
// If the previous loop does not return a molecule, it implies that all
250-
// atoms have been clustered or have already been proposed as a seed.
261+
// molecule have been clustered or have already been proposed as a seed.
251262
// Return nullptr to signify that there are no further seeds.
252263
return PackMoleculeId::INVALID();
253264
}

vpr/src/pack/greedy_seed_selector.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,24 @@ class GreedySeedSelector {
6868
* This method assumes that once a molecule is clustered, it will never be
6969
* unclustered.
7070
*
71-
* @param prepacker
72-
* The prepacker object that stores the molecules.
7371
* @param cluster_legalizer
7472
* The cluster legalizer object that is used to create the
7573
* clusters. This is used to check if a molecule has already
7674
* been clustered or not.
7775
*/
78-
PackMoleculeId get_next_seed(const Prepacker& prepacker,
79-
const ClusterLegalizer& cluster_legalizer);
76+
PackMoleculeId get_next_seed(const ClusterLegalizer& cluster_legalizer);
8077

81-
// TODO: Maybe create an update_seed_gains method to update the seed atoms
78+
// TODO: Maybe create an update_seed_gains method to update the seed molecules
8279
// list using current clustering information.
8380

8481
private:
85-
/// @brief The index of the next seed to propose in the seed_atoms vector.
82+
/// @brief The index of the next seed to propose in the seed_mols_ vector.
8683
/// This is set to 0 in the constructor and incremented as more seeds
8784
/// are proposed.
8885
size_t seed_index_;
8986

90-
/// @brief A list of seed atoms, sorted in decreasing order of gain. This
87+
/// @brief A list of seed molecules, sorted in decreasing order of gain. This
9188
/// is computed in the constructor and is traversed when a new seed
9289
/// is being proposed.
93-
// FIXME: This should really be seed molecules. It looks like the only
94-
// reason it isn't is because of the atom criticality. May want to
95-
// create the concept of molecule criticality. Currently, the max
96-
// criticality of any block in the molecule is technically being
97-
// used.
98-
std::vector<AtomBlockId> seed_atoms_;
90+
std::vector<PackMoleculeId> seed_mols_;
9991
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
arch circuit script_params vtr_flow_elapsed_time vtr_max_mem_stage vtr_max_mem error odin_synth_time max_odin_mem parmys_synth_time max_parmys_mem abc_depth abc_synth_time abc_cec_time abc_sec_time max_abc_mem ace_time max_ace_mem num_clb num_io num_memories num_mult vpr_status vpr_revision vpr_build_info vpr_compiler vpr_compiled hostname rundir max_vpr_mem num_primary_inputs num_primary_outputs num_pre_packed_nets num_pre_packed_blocks num_netlist_clocks num_post_packed_nets num_post_packed_blocks device_width device_height device_grid_tiles device_limiting_resources device_name pack_mem pack_time placed_wirelength_est total_swap accepted_swap rejected_swap aborted_swap place_mem place_time place_quench_time placed_CPD_est placed_setup_TNS_est placed_setup_WNS_est placed_geomean_nonvirtual_intradomain_critical_path_delay_est place_delay_matrix_lookup_time place_quench_timing_analysis_time place_quench_sta_time place_total_timing_analysis_time place_total_sta_time ap_mem ap_time ap_full_legalizer_mem ap_full_legalizer_time min_chan_width routed_wirelength min_chan_width_route_success_iteration logic_block_area_total logic_block_area_used min_chan_width_routing_area_total min_chan_width_routing_area_per_tile min_chan_width_route_time min_chan_width_total_timing_analysis_time min_chan_width_total_sta_time crit_path_num_rr_graph_nodes crit_path_num_rr_graph_edges crit_path_collapsed_nodes crit_path_routed_wirelength crit_path_route_success_iteration crit_path_total_nets_routed crit_path_total_connections_routed crit_path_total_heap_pushes crit_path_total_heap_pops critical_path_delay geomean_nonvirtual_intradomain_critical_path_delay setup_TNS setup_WNS hold_TNS hold_WNS crit_path_routing_area_total crit_path_routing_area_per_tile router_lookahead_computation_time crit_path_route_time crit_path_create_rr_graph_time crit_path_create_intra_cluster_rr_graph_time crit_path_tile_lookahead_computation_time crit_path_router_lookahead_computation_time crit_path_total_timing_analysis_time crit_path_total_sta_time
22
timing/k6_N10_mem32K_40nm.xml stereovision3.v common 2.02 vpr 67.00 MiB 0.08 10496 -1 -1 4 0.20 -1 -1 36452 -1 -1 19 11 0 0 success v8.0.0-12163-g0dba7016b-dirty Release VTR_ASSERT_LEVEL=2 GNU 11.4.0 on Linux-6.8.0-51-generic x86_64 2025-02-19T17:54:19 haydar-Precision-5820-Tower /home/haydar/vtr-verilog-to-routing 68608 11 30 262 292 2 99 60 7 7 49 clb auto 27.4 MiB 0.11 419 1815 318 1436 61 67.0 MiB 0.04 0.00 1.93141 -140.772 -1.93141 1.88461 0.01 0.000706488 0.000606458 0.0228093 0.0209659 -1 -1 -1 -1 8 283 18 1.07788e+06 1.02399e+06 -1 -1 0.38 0.186498 0.171178 2100 3116 -1 280 18 572 1139 59841 29637 1.93141 1.88461 -140.772 -1.93141 0 0 -1 -1 0.00 0.07 0.00 -1 -1 0.00 0.0346595 0.0310733
3-
nonuniform_chan_width/k6_N10_mem32K_40nm_nonuniform.xml stereovision3.v common 2.04 vpr 66.32 MiB 0.07 10496 -1 -1 4 0.26 -1 -1 36580 -1 -1 19 11 0 0 success v8.0.0-12163-g0dba7016b-dirty Release VTR_ASSERT_LEVEL=2 GNU 11.4.0 on Linux-6.8.0-51-generic x86_64 2025-02-19T17:54:19 haydar-Precision-5820-Tower /home/haydar/vtr-verilog-to-routing 67916 11 30 262 292 2 99 60 7 7 49 clb auto 27.3 MiB 0.08 428 1698 248 1401 49 66.3 MiB 0.04 0.00 1.93141 -140.772 -1.93141 1.88461 0.01 0.000764131 0.000648712 0.0183265 0.0161998 -1 -1 -1 -1 10 297 21 1.07788e+06 1.02399e+06 -1 -1 0.45 0.176554 0.15406 2100 3116 -1 286 18 539 1058 53794 27022 1.93141 1.88461 -140.772 -1.93141 0 0 -1 -1 0.00 0.08 0.00 -1 -1 0.00 0.0402826 0.0356284
3+
nonuniform_chan_width/k6_N10_mem32K_40nm_nonuniform.xml stereovision3.v common 2.04 vpr 66.32 MiB 0.07 10496 -1 -1 4 0.26 -1 -1 36580 -1 -1 19 11 0 0 success v8.0.0-12163-g0dba7016b-dirty Release VTR_ASSERT_LEVEL=2 GNU 11.4.0 on Linux-6.8.0-51-generic x86_64 2025-02-19T17:54:19 haydar-Precision-5820-Tower /home/haydar/vtr-verilog-to-routing 67916 11 30 262 292 2 99 60 7 7 49 clb auto 27.3 MiB 0.08 428 1698 248 1401 49 66.3 MiB 0.04 0.00 1.93141 -140.772 -1.93141 1.88461 0.01 0.000764131 0.000648712 0.0183265 0.0161998 -1 -1 -1 -1 14 297 21 1.07788e+06 1.02399e+06 -1 -1 0.45 0.176554 0.15406 2100 3116 -1 286 18 539 1058 53794 27022 1.93141 1.88461 -140.772 -1.93141 0 0 -1 -1 0.00 0.08 0.00 -1 -1 0.00 0.0402826 0.0356284
44
nonuniform_chan_width/k6_N10_mem32K_40nm_pulse.xml stereovision3.v common 1.99 vpr 66.21 MiB 0.09 10368 -1 -1 4 0.24 -1 -1 36668 -1 -1 19 11 0 0 success v8.0.0-12163-g0dba7016b-dirty Release VTR_ASSERT_LEVEL=2 GNU 11.4.0 on Linux-6.8.0-51-generic x86_64 2025-02-19T17:54:19 haydar-Precision-5820-Tower /home/haydar/vtr-verilog-to-routing 67800 11 30 262 292 2 99 60 7 7 49 clb auto 27.1 MiB 0.09 447 1815 292 1481 42 66.2 MiB 0.07 0.00 1.93141 -140.772 -1.93141 1.88461 0.01 0.00090328 0.000782565 0.0181809 0.0161296 -1 -1 -1 -1 16 296 17 1.07788e+06 1.02399e+06 -1 -1 0.25 0.115099 0.100427 2100 3116 -1 300 17 545 1102 57605 27890 1.93141 1.88461 -140.772 -1.93141 0 0 -1 -1 0.00 0.12 0.01 -1 -1 0.00 0.0397962 0.0356125

0 commit comments

Comments
 (0)