Skip to content

Commit a4e76d9

Browse files
authored
Merge pull request #725 from os-fpga/finished_packer_fix_merge
finished packer_fix merge
2 parents ef9c265 + 102b8d6 commit a4e76d9

File tree

5 files changed

+39
-425
lines changed

5 files changed

+39
-425
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ FILE(COPY ${PACKER_SRC_DIR}/cluster.cpp
135135
${PACKER_SRC_DIR}/output_clustering.h
136136
${PACKER_SRC_DIR}/cluster_router.cpp
137137
${PACKER_SRC_DIR}/post_routing_pb_pin_fixup.cpp
138-
${PACKER_SRC_DIR}/pack.cpp
139138
DESTINATION
140139
${VPR_DEST_DIR}/src/pack)
141140

include/packer_fix/cluster.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,12 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
9999
const t_analysis_opts& analysis_opts,
100100
const t_arch* arch,
101101
t_pack_molecule* molecule_head,
102-
int num_models,
103102
const std::unordered_set<AtomNetId>& is_clock,
103+
const std::unordered_set<AtomNetId>& is_global,
104104
const std::unordered_map<AtomBlockId, t_pb_graph_node*>& expected_lowest_cost_pb_gnode,
105105
bool allow_unrelated_clustering,
106106
bool balance_block_type_utilization,
107107
std::vector<t_lb_type_rr_node>* lb_type_rr_graphs,
108-
const t_ext_pin_util_targets& ext_pin_util_targets,
109-
const t_pack_high_fanout_thresholds& high_fanout_thresholds,
110108
AttractionInfo& attraction_groups,
111109
bool& floorplan_regions_overfull,
112110
t_clustering_data& clustering_data) {
@@ -237,7 +235,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
237235

238236
auto seed_atoms = initialize_seed_atoms(packer_opts.cluster_seed_type, max_molecule_stats, atom_criticality);
239237

240-
istart = get_highest_gain_seed_molecule(&seedindex, seed_atoms);
238+
istart = get_highest_gain_seed_molecule(seedindex, seed_atoms);
241239

242240
print_pack_status_header();
243241

@@ -405,7 +403,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
405403
clb_index, istart,
406404
num_used_type_instances,
407405
packer_opts.target_device_utilization,
408-
num_models, helper_ctx.max_cluster_size,
406+
helper_ctx.num_models, helper_ctx.max_cluster_size,
409407
arch, packer_opts.device_layout,
410408
lb_type_rr_graphs, &router_data,
411409
detailed_routing_stage, &cluster_ctx.clb_nlist,
@@ -435,11 +433,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
435433
//Progress dot for seed-block
436434
fflush(stdout);
437435

438-
t_ext_pin_util target_ext_pin_util = ext_pin_util_targets.get_pin_util(cluster_ctx.clb_nlist.block_type(clb_index)->name);
439-
int high_fanout_threshold = high_fanout_thresholds.get_threshold(cluster_ctx.clb_nlist.block_type(clb_index)->name);
436+
t_ext_pin_util target_ext_pin_util = helper_ctx.target_external_pin_util.get_pin_util(cluster_ctx.clb_nlist.block_type(clb_index)->name);
437+
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(cluster_ctx.clb_nlist.block_type(clb_index)->name);
440438
update_cluster_stats(istart, clb_index,
441439
is_clock, //Set of clock nets
442-
is_clock, //Set of global nets (currently all clocks)
440+
is_global, //Set of global nets (currently all clocks)
443441
packer_opts.global_clocks,
444442
packer_opts.alpha, packer_opts.beta,
445443
packer_opts.timing_driven, packer_opts.connection_driven,
@@ -505,7 +503,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
505503
helper_ctx.primitives_list,
506504
cluster_stats,
507505
helper_ctx.total_clb_num,
508-
num_models,
506+
helper_ctx.num_models,
509507
helper_ctx.max_cluster_size,
510508
clb_index,
511509
detailed_routing_stage,
@@ -514,6 +512,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
514512
allow_unrelated_clustering,
515513
high_fanout_threshold,
516514
is_clock,
515+
is_global,
517516
timing_info,
518517
router_data,
519518
target_ext_pin_util,
@@ -627,7 +626,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
627626
clb_index, istart,
628627
num_used_type_instances,
629628
packer_opts.target_device_utilization,
630-
num_models, helper_ctx.max_cluster_size,
629+
helper_ctx.num_models, helper_ctx.max_cluster_size,
631630
arch, packer_opts.device_layout,
632631
lb_type_rr_graphs, &router_data,
633632
detailed_routing_stage, &cluster_ctx.clb_nlist,
@@ -657,11 +656,11 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
657656
//Progress dot for seed-block
658657
fflush(stdout);
659658

660-
t_ext_pin_util target_ext_pin_util = ext_pin_util_targets.get_pin_util(cluster_ctx.clb_nlist.block_type(clb_index)->name);
661-
int high_fanout_threshold = high_fanout_thresholds.get_threshold(cluster_ctx.clb_nlist.block_type(clb_index)->name);
659+
t_ext_pin_util target_ext_pin_util = helper_ctx.target_external_pin_util.get_pin_util(cluster_ctx.clb_nlist.block_type(clb_index)->name);
660+
int high_fanout_threshold = helper_ctx.high_fanout_thresholds.get_threshold(cluster_ctx.clb_nlist.block_type(clb_index)->name);
662661
update_cluster_stats(istart, clb_index,
663662
is_clock, //Set of clock nets
664-
is_clock, //Set of global nets (currently all clocks)
663+
is_global, //Set of global nets (currently all clocks)
665664
packer_opts.global_clocks,
666665
packer_opts.alpha, packer_opts.beta,
667666
packer_opts.timing_driven, packer_opts.connection_driven,
@@ -721,7 +720,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
721720
helper_ctx.primitives_list,
722721
cluster_stats,
723722
helper_ctx.total_clb_num,
724-
num_models,
723+
helper_ctx.num_models,
725724
helper_ctx.max_cluster_size,
726725
clb_index,
727726
detailed_routing_stage,
@@ -730,6 +729,7 @@ std::map<t_logical_block_type_ptr, size_t> do_clustering(const t_packer_opts& pa
730729
allow_unrelated_clustering,
731730
high_fanout_threshold,
732731
is_clock,
732+
is_global,
733733
timing_info,
734734
router_data,
735735
target_ext_pin_util,

include/packer_fix/cluster_util.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ void try_fill_cluster(const t_packer_opts& packer_opts,
15191519
bool allow_unrelated_clustering,
15201520
const int& high_fanout_threshold,
15211521
const std::unordered_set<AtomNetId>& is_clock,
1522+
const std::unordered_set<AtomNetId>& is_global,
15221523
const std::shared_ptr<SetupTimingInfo>& timing_info,
15231524
t_lb_router_data* router_data,
15241525
t_ext_pin_util target_ext_pin_util,
@@ -1613,8 +1614,8 @@ void try_fill_cluster(const t_packer_opts& packer_opts,
16131614
attraction_groups);
16141615

16151616
update_cluster_stats(next_molecule, clb_index,
1616-
is_clock, //Set of all clocks
1617-
is_clock, //Set of all global signals (currently clocks)
1617+
is_clock, //Set of all clocks
1618+
is_global, //Set of all global signals (currently clocks)
16181619
packer_opts.global_clocks, packer_opts.alpha, packer_opts.beta, packer_opts.timing_driven,
16191620
packer_opts.connection_driven,
16201621
high_fanout_threshold,
@@ -1664,7 +1665,7 @@ t_pack_molecule* save_cluster_routing_and_pick_new_seed(const t_packer_opts& pac
16641665

16651666
//Pick a new seed
16661667
if (not packer_opts.use_partitioning_in_pack or partitioning_status_NOP()) {
1667-
next_seed = get_highest_gain_seed_molecule(&seedindex, seed_atoms);
1668+
next_seed = get_highest_gain_seed_molecule(seedindex, seed_atoms);
16681669
}
16691670

16701671
if (packer_opts.timing_driven) {
@@ -2124,9 +2125,7 @@ void start_new_cluster(t_cluster_placement_stats* cluster_placement_stats,
21242125

21252126
//Try packing into each candidate type
21262127
bool success = false;
2127-
for (size_t i = 0; i < candidate_types.size(); i++) {
2128-
auto type = candidate_types[i];
2129-
2128+
for (auto type : candidate_types) {
21302129
t_pb* pb = new t_pb;
21312130
pb->pb_graph_node = type->pb_graph_head;
21322131
alloc_and_load_pb_stats(pb, feasible_block_array_size);
@@ -2693,13 +2692,10 @@ t_molecule_stats calc_max_molecules_stats(const t_pack_molecule* molecule_head)
26932692
std::vector<AtomBlockId> initialize_seed_atoms(const e_cluster_seed seed_type,
26942693
const t_molecule_stats& max_molecule_stats,
26952694
const vtr::vector<AtomBlockId, float>& atom_criticality) {
2696-
std::vector<AtomBlockId> seed_atoms;
2695+
auto& atom_ctx = g_vpr_ctx.atom();
26972696

26982697
//Put all atoms in seed list
2699-
auto& atom_ctx = g_vpr_ctx.atom();
2700-
for (auto blk : atom_ctx.nlist.blocks()) {
2701-
seed_atoms.emplace_back(blk);
2702-
}
2698+
std::vector<AtomBlockId> seed_atoms(atom_ctx.nlist.blocks().begin(), atom_ctx.nlist.blocks().end());
27032699

27042700
//Initially all gains are zero
27052701
vtr::vector<AtomBlockId, float> atom_gains(atom_ctx.nlist.blocks().size(), 0.);
@@ -2849,15 +2845,18 @@ std::vector<AtomBlockId> initialize_seed_atoms(const e_cluster_seed seed_type,
28492845
return seed_atoms;
28502846
}
28512847

2852-
t_pack_molecule* get_highest_gain_seed_molecule(int* seedindex, const std::vector<AtomBlockId> seed_atoms) {
2848+
t_pack_molecule* get_highest_gain_seed_molecule(int& seed_index, const std::vector<AtomBlockId>& seed_atoms) {
28532849
auto& atom_ctx = g_vpr_ctx.atom();
28542850

2855-
while (*seedindex < static_cast<int>(seed_atoms.size())) {
2856-
AtomBlockId blk_id = seed_atoms[(*seedindex)++];
2851+
while (seed_index < static_cast<int>(seed_atoms.size())) {
2852+
AtomBlockId blk_id = seed_atoms[seed_index++];
28572853

2854+
// Check if the atom has already been assigned to a cluster
28582855
if (atom_ctx.lookup.atom_clb(blk_id) == ClusterBlockId::INVALID()) {
28592856
t_pack_molecule* best = nullptr;
28602857

2858+
// Iterate over all the molecules associated with the selected atom
2859+
// and select the one with the highest gain
28612860
auto rng = atom_ctx.atom_molecules.equal_range(blk_id);
28622861
for (const auto& kv : vtr::make_range(rng.first, rng.second)) {
28632862
t_pack_molecule* molecule = kv.second;
@@ -3369,11 +3368,15 @@ std::map<const t_model*, std::vector<t_logical_block_type_ptr>> identify_primiti
33693368
auto& device_ctx = g_vpr_ctx.device();
33703369

33713370
std::set<const t_model*> unique_models;
3371+
// Find all logic models used in the netlist
33723372
for (auto blk : atom_nlist.blocks()) {
33733373
auto model = atom_nlist.block_model(blk);
33743374
unique_models.insert(model);
33753375
}
33763376

3377+
/* For each technology-mapped logic model, find logical block types
3378+
* that can accommodate that logic model
3379+
*/
33773380
for (auto model : unique_models) {
33783381
model_candidates[model] = {};
33793382

@@ -3712,6 +3715,11 @@ void init_clb_atoms_lookup(vtr::vector<ClusterBlockId, std::unordered_set<AtomBl
37123715
for (auto atom_blk_id : atom_ctx.nlist.blocks()) {
37133716
ClusterBlockId clb_index = atom_ctx.lookup.atom_clb(atom_blk_id);
37143717

3715-
atoms_lookup[clb_index].insert(atom_blk_id);
3718+
/* if this data structure is being built alongside the clustered netlist */
3719+
/* e.g. when ingesting and legalizing a flat placement solution, some atoms */
3720+
/* may not yet be mapped to a valid clb_index */
3721+
if (clb_index != ClusterBlockId::INVALID()) {
3722+
atoms_lookup[clb_index].insert(atom_blk_id);
3723+
}
37163724
}
37173725
}

include/packer_fix/cluster_util.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void try_fill_cluster(const t_packer_opts& packer_opts,
240240
bool allow_unrelated_clustering,
241241
const int& high_fanout_threshold,
242242
const std::unordered_set<AtomNetId>& is_clock,
243+
const std::unordered_set<AtomNetId>& is_global,
243244
const std::shared_ptr<SetupTimingInfo>& timing_info,
244245
t_lb_router_data* router_data,
245246
t_ext_pin_util target_ext_pin_util,
@@ -415,7 +416,7 @@ std::vector<AtomBlockId> initialize_seed_atoms(const e_cluster_seed seed_type,
415416
const t_molecule_stats& max_molecule_stats,
416417
const vtr::vector<AtomBlockId, float>& atom_criticality);
417418

418-
t_pack_molecule* get_highest_gain_seed_molecule(int* seedindex, const std::vector<AtomBlockId> seed_atoms);
419+
t_pack_molecule* get_highest_gain_seed_molecule(int& seed_index, const std::vector<AtomBlockId>& seed_atoms);
419420

420421
float get_molecule_gain(t_pack_molecule* molecule, std::map<AtomBlockId, float>& blk_gain, AttractGroupId cluster_attraction_group_id, AttractionInfo& attraction_groups, int num_molecule_failures);
421422

0 commit comments

Comments
 (0)