Skip to content

Commit 01b84d3

Browse files
author
Rongbo Zhang
committed
[pack] Fixed the bug where the number of pop limit stops the search after purposing only the candidate found through connectivity and timing. The causes is the limit not reseting after queue is emptied and refilled with transitive or highfanout candidates.
1 parent 32b263f commit 01b84d3

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
lines changed

vpr/src/pack/greedy_candidate_selector.cpp

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ ClusterGainStats GreedyCandidateSelector::create_cluster_gain_stats(
126126
ClusterGainStats cluster_gain_stats;
127127
cluster_gain_stats.initial_search_for_feasible_blocks = true;
128128
cluster_gain_stats.num_search_for_feasible_blocks_occured = 0;
129+
cluster_gain_stats.num_search_for_feasible_blocks_occurred_limit = packer_opts_.feasible_block_array_size;
129130
cluster_gain_stats.feasible_blocks.clear();
130131
cluster_gain_stats.tie_break_high_fanout_net = AtomNetId::INVALID();
131132
cluster_gain_stats.explore_transitive_fanout = true;
@@ -602,14 +603,26 @@ t_pack_molecule* GreedyCandidateSelector::get_next_candidate_for_cluster(
602603
t_pack_molecule* best_molecule = nullptr;
603604
// checking if there are feasible blocks being proposed
604605
// checking if number of suggestion reached the limit
605-
if (cluster_gain_stats.feasible_blocks.size() > 0 && cluster_gain_stats.num_search_for_feasible_blocks_occured < packer_opts_.feasible_block_array_size) {
606+
if (cluster_gain_stats.feasible_blocks.size() > 0 && cluster_gain_stats.num_search_for_feasible_blocks_occured < cluster_gain_stats.num_search_for_feasible_blocks_occurred_limit) {
606607
best_molecule = cluster_gain_stats.feasible_blocks.pop().first;
607608
if (best_molecule != nullptr) {
608609
cluster_gain_stats.num_search_for_feasible_blocks_occured++;
609610
VTR_ASSERT(!cluster_legalizer.is_mol_clustered(best_molecule));
610611
}
611612
}
612613

614+
// If we have no feasible blocks, or we have reached the limit of number of pops,
615+
// then we need to clear the feasible blocks list and reset the number of pops.
616+
// This ensures that we can continue searching for feasible blocks for the remaining
617+
// steps (2.transitive, 3.high fanout, 4.attraction group).
618+
if (cluster_gain_stats.feasible_blocks.size() == 0 ||
619+
cluster_gain_stats.num_search_for_feasible_blocks_occured >= cluster_gain_stats.num_search_for_feasible_blocks_occurred_limit ||
620+
cluster_gain_stats.feasible_blocks.delete_pending_set.size() == cluster_gain_stats.feasible_blocks.content_set.size()
621+
){
622+
cluster_gain_stats.feasible_blocks.clear();
623+
cluster_gain_stats.num_search_for_feasible_blocks_occured = 0;
624+
}
625+
613626
// If we are allowing unrelated clustering and no molecule has been found,
614627
// get unrelated candidate for cluster.
615628
if (allow_unrelated_clustering_ && best_molecule == nullptr) {
@@ -1032,22 +1045,6 @@ void GreedyCandidateSelector::update_candidate_selector_finalize_cluster(
10321045
}
10331046
}
10341047

1035-
template <typename T_key, typename T_sort>
1036-
LazyPopUniquePriorityQueue<T_key, T_sort>::LazyPopUniquePriorityQueue() {
1037-
// Initialize the priority queue
1038-
heap.clear();
1039-
content_set.clear();
1040-
delete_pending_set.clear();
1041-
}
1042-
1043-
template <typename T_key, typename T_sort>
1044-
LazyPopUniquePriorityQueue<T_key, T_sort>::~LazyPopUniquePriorityQueue() {
1045-
// Clear the priority queue
1046-
heap.clear();
1047-
content_set.clear();
1048-
delete_pending_set.clear();
1049-
}
1050-
10511048
template <typename T_key, typename T_sort>
10521049
void LazyPopUniquePriorityQueue<T_key, T_sort>::push(T_key key, T_sort value){
10531050
// Insert the key and sort value pair into the queue if it is not already present
@@ -1061,6 +1058,7 @@ void LazyPopUniquePriorityQueue<T_key, T_sort>::push(T_key key, T_sort value){
10611058
LazyPopUniquePriorityQueueCompare());
10621059
content_set.insert(key);
10631060
}
1061+
10641062
template <typename T_key, typename T_sort>
10651063
std::pair<T_key,T_sort> LazyPopUniquePriorityQueue<T_key, T_sort>::pop(){
10661064
std::pair<T_key, T_sort> top_pair;
@@ -1085,14 +1083,6 @@ std::pair<T_key,T_sort> LazyPopUniquePriorityQueue<T_key, T_sort>::pop(){
10851083
return top_pair;
10861084
}
10871085

1088-
template <typename T_key, typename T_sort>
1089-
void LazyPopUniquePriorityQueue<T_key, T_sort>::clear() {
1090-
// Clear the priority queue
1091-
heap.clear();
1092-
content_set.clear();
1093-
delete_pending_set.clear();
1094-
}
1095-
10961086
template <typename T_key, typename T_sort>
10971087
void LazyPopUniquePriorityQueue<T_key, T_sort>::remove(T_key key) {
10981088
// If the key is in the priority queue, remove it from the heap and reheapify
@@ -1119,18 +1109,3 @@ void LazyPopUniquePriorityQueue<T_key, T_sort>::remove_at_pop_time(T_key key) {
11191109
}
11201110
}
11211111

1122-
template <typename T_key, typename T_sort>
1123-
bool LazyPopUniquePriorityQueue<T_key, T_sort>::empty() {
1124-
return heap.empty();
1125-
}
1126-
1127-
template <typename T_key, typename T_sort>
1128-
size_t LazyPopUniquePriorityQueue<T_key, T_sort>::size() {
1129-
return heap.size();
1130-
}
1131-
1132-
template <typename T_key, typename T_sort>
1133-
bool LazyPopUniquePriorityQueue<T_key, T_sort>::contains(T_key key) {
1134-
return content_set.find(key) != content_set.end();
1135-
}
1136-

vpr/src/pack/greedy_candidate_selector.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,29 @@ class LazyPopUniquePriorityQueue {
116116
*
117117
* @return True if the priority queue is empty, false otherwise.
118118
*/
119-
bool empty();
119+
bool empty(){
120+
return heap.empty();
121+
}
120122

121123
/**
122124
* @brief Clears the priority queue and the tracking sets.
123125
*
124126
* @return None
125127
*/
126-
void clear();
128+
void clear(){
129+
heap.clear();
130+
content_set.clear();
131+
delete_pending_set.clear();
132+
}
127133

128134
/**
129135
* @brief Get the size of the priority queue.
130136
*
131137
* @return The size of the priority queue.
132138
*/
133-
size_t size();
139+
size_t size(){
140+
return heap.size();
141+
}
134142

135143
/**
136144
* @brief Check if the item refered by the key is in the priority queue.
@@ -139,7 +147,9 @@ class LazyPopUniquePriorityQueue {
139147
* The key of the item.
140148
* @return True if the key is in the priority queue, false otherwise.
141149
*/
142-
bool contains(T_key key);
150+
bool contains(T_key key){
151+
return content_set.find(key) != content_set.end();
152+
}
143153
};
144154

145155
/**
@@ -205,6 +215,9 @@ struct ClusterGainStats {
205215
/// @brief Indicator for the initial search for feasible blocks.
206216
bool initial_search_for_feasible_blocks;
207217

218+
/// @brief Limit for the number of pop.
219+
unsigned num_search_for_feasible_blocks_occurred_limit;
220+
208221
/// @brief Counter for the number of pop.
209222
unsigned num_search_for_feasible_blocks_occured;
210223
};

0 commit comments

Comments
 (0)