Skip to content

Commit b6217be

Browse files
committed
Refactored the functions that add cluster molecule candidates by moving repetitive code into a helper function
1 parent 59afa1c commit b6217be

File tree

1 file changed

+26
-52
lines changed

1 file changed

+26
-52
lines changed

vpr/src/pack/cluster.cpp

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
316316
int transitive_fanout_threshold,
317317
const int feasible_block_array_size);
318318

319+
bool check_free_primitives_for_molecule_atoms(t_pack_molecule* molecule, t_cluster_placement_stats* cluster_placement_stats_ptr);
320+
319321
static t_pack_molecule* get_molecule_for_cluster(t_pb* cur_pb,
320322
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,
321323
AttractionInfo& attraction_groups,
@@ -2480,19 +2482,7 @@ void add_cluster_molecule_candidates_by_connectivity_and_timing(t_pb* cur_pb,
24802482
for (const auto& kv : vtr::make_range(rng.first, rng.second)) {
24812483
t_pack_molecule* molecule = kv.second;
24822484
if (molecule->valid) {
2483-
bool success = true;
2484-
for (int j = 0; j < get_array_size_of_molecule(molecule); j++) {
2485-
if (molecule->atom_block_ids[j]) {
2486-
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[j]) == ClusterBlockId::INVALID());
2487-
auto blk_id2 = molecule->atom_block_ids[j];
2488-
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id2)) {
2489-
/* TODO: debating whether to check if placement exists for molecule
2490-
* (more robust) or individual atom blocks (faster) */
2491-
success = false;
2492-
break;
2493-
}
2494-
}
2495-
}
2485+
bool success = check_free_primitives_for_molecule_atoms(molecule, cluster_placement_stats_ptr);
24962486
if (success) {
24972487
add_molecule_to_pb_stats_candidates(molecule,
24982488
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size);
@@ -2529,19 +2519,7 @@ void add_cluster_molecule_candidates_by_highfanout_connectivity(t_pb* cur_pb,
25292519
for (const auto& kv : vtr::make_range(rng.first, rng.second)) {
25302520
t_pack_molecule* molecule = kv.second;
25312521
if (molecule->valid) {
2532-
bool success = true;
2533-
for (int j = 0; j < get_array_size_of_molecule(molecule); j++) {
2534-
if (molecule->atom_block_ids[j]) {
2535-
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[j]) == ClusterBlockId::INVALID());
2536-
auto blk_id2 = molecule->atom_block_ids[j];
2537-
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id2)) {
2538-
/* TODO: debating whether to check if placement exists for molecule (more
2539-
* robust) or individual atom blocks (faster) */
2540-
success = false;
2541-
break;
2542-
}
2543-
}
2544-
}
2522+
bool success = check_free_primitives_for_molecule_atoms(molecule, cluster_placement_stats_ptr);
25452523
if (success) {
25462524
add_molecule_to_pb_stats_candidates(molecule,
25472525
cur_pb->pb_stats->gain, cur_pb, std::min(feasible_block_array_size, AAPACK_MAX_HIGH_FANOUT_EXPLORE));
@@ -2573,19 +2551,7 @@ void add_cluster_molecule_candidates_by_attraction_group(t_pb* cur_pb,
25732551
for (const auto& kv : vtr::make_range(rng.first, rng.second)) {
25742552
t_pack_molecule* molecule = kv.second;
25752553
if (molecule->valid) {
2576-
bool success = true;
2577-
for (int i_atom = 0; i_atom < get_array_size_of_molecule(molecule); i_atom++) {
2578-
if (molecule->atom_block_ids[i_atom]) {
2579-
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[i_atom]) == ClusterBlockId::INVALID());
2580-
auto blk_id2 = molecule->atom_block_ids[i_atom];
2581-
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id2)) {
2582-
/* TODO: debating whether to check if placement exists for molecule
2583-
* (more robust) or individual atom blocks (faster) */
2584-
success = false;
2585-
break;
2586-
}
2587-
}
2588-
}
2554+
bool success = check_free_primitives_for_molecule_atoms(molecule, cluster_placement_stats_ptr);
25892555
if (success) {
25902556
add_molecule_to_pb_stats_candidates(molecule,
25912557
cur_pb->pb_stats->gain, cur_pb, feasible_block_array_size);
@@ -2620,19 +2586,7 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
26202586
for (const auto& transitive_candidate : cur_pb->pb_stats->transitive_fanout_candidates) {
26212587
t_pack_molecule* molecule = transitive_candidate.second;
26222588
if (molecule->valid) {
2623-
bool success = true;
2624-
for (int j = 0; j < get_array_size_of_molecule(molecule); j++) {
2625-
if (molecule->atom_block_ids[j]) {
2626-
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[j]) == ClusterBlockId::INVALID());
2627-
auto blk_id = molecule->atom_block_ids[j];
2628-
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id)) {
2629-
/* TODO: debating whether to check if placement exists for molecule (more
2630-
* robust) or individual atom blocks (faster) */
2631-
success = false;
2632-
break;
2633-
}
2634-
}
2635-
}
2589+
bool success = check_free_primitives_for_molecule_atoms(molecule, cluster_placement_stats_ptr);
26362590
if (success) {
26372591
add_molecule_to_pb_stats_candidates(molecule,
26382592
cur_pb->pb_stats->gain, cur_pb, std::min(feasible_block_array_size, AAPACK_MAX_TRANSITIVE_EXPLORE));
@@ -2641,6 +2595,26 @@ void add_cluster_molecule_candidates_by_transitive_connectivity(t_pb* cur_pb,
26412595
}
26422596
}
26432597

2598+
bool check_free_primitives_for_molecule_atoms(t_pack_molecule* molecule, t_cluster_placement_stats* cluster_placement_stats_ptr) {
2599+
auto& atom_ctx = g_vpr_ctx.atom();
2600+
bool success = true;
2601+
2602+
for (int i_atom = 0; i_atom < get_array_size_of_molecule(molecule); i_atom++) {
2603+
if (molecule->atom_block_ids[i_atom]) {
2604+
VTR_ASSERT(atom_ctx.lookup.atom_clb(molecule->atom_block_ids[i_atom]) == ClusterBlockId::INVALID());
2605+
auto blk_id2 = molecule->atom_block_ids[i_atom];
2606+
if (!exists_free_primitive_for_atom_block(cluster_placement_stats_ptr, blk_id2)) {
2607+
/* TODO: debating whether to check if placement exists for molecule
2608+
* (more robust) or individual atom blocks (faster) */
2609+
success = false;
2610+
break;
2611+
}
2612+
}
2613+
}
2614+
2615+
return success;
2616+
}
2617+
26442618
/*****************************************/
26452619
static t_pack_molecule* get_molecule_for_cluster(t_pb* cur_pb,
26462620
const std::multimap<AtomBlockId, t_pack_molecule*>& atom_molecules,

0 commit comments

Comments
 (0)