Skip to content

Commit 15de96f

Browse files
authored
Merge pull request #8374 from gudeh/gpl-improve-divergence-detction
gpl: improve divergence detction
2 parents 20419b3 + ba26ca9 commit 15de96f

File tree

2 files changed

+53
-38
lines changed

2 files changed

+53
-38
lines changed

src/gpl/src/nesterovBase.cpp

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ void NesterovBase::initDensity1()
23312331
// bin
23322332
updateGCellDensityCenterLocation(curSLPCoordi_);
23332333

2334-
prevHpwl_ = nbc_->getHpwl();
2334+
prev_hpwl_ = nbc_->getHpwl();
23352335

23362336
// FFT update
23372337
updateDensityForceBin();
@@ -2340,11 +2340,11 @@ void NesterovBase::initDensity1()
23402340
= npVars_->initWireLengthCoef
23412341
/ (static_cast<float>(getBinSizeX() + getBinSizeY()) * 0.5);
23422342

2343-
sumOverflow_ = static_cast<float>(getOverflowArea())
2344-
/ static_cast<float>(getNesterovInstsArea());
2343+
sum_overflow_ = static_cast<float>(getOverflowArea())
2344+
/ static_cast<float>(getNesterovInstsArea());
23452345

2346-
sumOverflowUnscaled_ = static_cast<float>(getOverflowAreaUnscaled())
2347-
/ static_cast<float>(getNesterovInstsArea());
2346+
sum_overflow_unscaled_ = static_cast<float>(getOverflowAreaUnscaled())
2347+
/ static_cast<float>(getNesterovInstsArea());
23482348
}
23492349

23502350
float NesterovBase::initDensity2(float wlCoeffX, float wlCoeffY)
@@ -2359,11 +2359,11 @@ float NesterovBase::initDensity2(float wlCoeffX, float wlCoeffY)
23592359
= (wireLengthGradSum_ / densityGradSum_) * npVars_->initDensityPenalty;
23602360
}
23612361

2362-
sumOverflow_ = static_cast<float>(getOverflowArea())
2363-
/ static_cast<float>(getNesterovInstsArea());
2362+
sum_overflow_ = static_cast<float>(getOverflowArea())
2363+
/ static_cast<float>(getNesterovInstsArea());
23642364

2365-
sumOverflowUnscaled_ = static_cast<float>(getOverflowAreaUnscaled())
2366-
/ static_cast<float>(getNesterovInstsArea());
2365+
sum_overflow_unscaled_ = static_cast<float>(getOverflowAreaUnscaled())
2366+
/ static_cast<float>(getNesterovInstsArea());
23672367

23682368
stepLength_ = getStepLength(
23692369
prevSLPCoordi_, prevSLPSumGrads_, curSLPCoordi_, curSLPSumGrads_);
@@ -2677,21 +2677,22 @@ void NesterovBase::updateNextIter(const int iter)
26772677
= std::max(static_cast<float>(getNesterovInstsArea()),
26782678
fractionOfMaxIters * pb_->nonPlaceInstsArea() * 0.05f);
26792679

2680-
sumOverflow_ = getOverflowArea() / overflowDenominator;
2681-
sumOverflowUnscaled_ = getOverflowAreaUnscaled() / overflowDenominator;
2680+
sum_overflow_ = getOverflowArea() / overflowDenominator;
2681+
sum_overflow_unscaled_ = getOverflowAreaUnscaled() / overflowDenominator;
26822682

26832683
int64_t hpwl = nbc_->getHpwl();
2684-
float phiCoef = getPhiCoef(static_cast<float>(hpwl - prevHpwl_)
2684+
float phiCoef = getPhiCoef(static_cast<float>(hpwl - prev_hpwl_)
26852685
/ npVars_->referenceHpwl);
26862686

2687-
float percentageChange = 0.0;
2687+
float hpwl_percent_change = 0.0;
26882688
if (iter == 0 || (iter) % 10 == 0) {
2689-
if (prevReportedHpwl_ != 0) {
2690-
percentageChange = (static_cast<double>(hpwl - prevReportedHpwl_)
2691-
/ static_cast<double>(prevReportedHpwl_))
2692-
* 100.0;
2689+
if (prev_reported_hpwl_ != 0) {
2690+
hpwl_percent_change = (static_cast<double>(hpwl - prev_reported_hpwl_)
2691+
/ static_cast<double>(prev_reported_hpwl_))
2692+
* 100.0;
26932693
}
2694-
prevReportedHpwl_ = hpwl;
2694+
prev_reported_hpwl_ = hpwl;
2695+
prev_reported_overflow_unscaled_ = sum_overflow_unscaled_;
26952696

26962697
std::string group_name;
26972698
if (pb_->group()) {
@@ -2722,14 +2723,14 @@ void NesterovBase::updateNextIter(const int iter)
27222723
dbBlock* block = pb_->db()->getChip()->getBlock();
27232724
log_->report("{:9d} | {:8.4f} | {:13.6e} | {:+7.2f}% | {:9.2e} | {:>5}",
27242725
iter,
2725-
sumOverflowUnscaled_,
2726+
sum_overflow_unscaled_,
27262727
block->dbuToMicrons(hpwl),
2727-
percentageChange,
2728+
hpwl_percent_change,
27282729
densityPenalty_,
27292730
group_name);
27302731
}
27312732

2732-
debugPrint(log_, GPL, "updateNextIter", 1, "PreviousHPWL: {}", prevHpwl_);
2733+
debugPrint(log_, GPL, "updateNextIter", 1, "PreviousHPWL: {}", prev_hpwl_);
27332734
debugPrint(log_, GPL, "updateNextIter", 1, "NewHPWL: {}", hpwl);
27342735
debugPrint(log_, GPL, "updateNextIter", 1, "PhiCoef: {:g}", phiCoef);
27352736
debugPrint(log_,
@@ -2740,14 +2741,14 @@ void NesterovBase::updateNextIter(const int iter)
27402741
getSecondNorm(curSLPSumGrads_));
27412742
debugPrint(log_, GPL, "updateNextIter", 1, "Phi: {:g}", getSumPhi());
27422743
debugPrint(
2743-
log_, GPL, "updateNextIter", 1, "Overflow: {:g}", sumOverflowUnscaled_);
2744+
log_, GPL, "updateNextIter", 1, "Overflow: {:g}", sum_overflow_unscaled_);
27442745

2745-
prevHpwl_ = hpwl;
2746+
prev_hpwl_ = hpwl;
27462747
densityPenalty_ *= phiCoef;
27472748

2748-
if (iter > 50 && minSumOverflow_ > sumOverflowUnscaled_) {
2749-
minSumOverflow_ = sumOverflowUnscaled_;
2750-
hpwlWithMinSumOverflow_ = prevHpwl_;
2749+
if (iter > 50 && minSumOverflow_ > sum_overflow_unscaled_) {
2750+
minSumOverflow_ = sum_overflow_unscaled_;
2751+
hpwlWithMinSumOverflow_ = prev_hpwl_;
27512752
}
27522753
}
27532754

@@ -2822,7 +2823,7 @@ void NesterovBase::nesterovAdjustPhi()
28222823
// dynamic adjustment for
28232824
// better convergence with
28242825
// large designs
2825-
if (!isMaxPhiCoefChanged_ && sumOverflowUnscaled_ < 0.35f) {
2826+
if (!isMaxPhiCoefChanged_ && sum_overflow_unscaled_ < 0.35f) {
28262827
isMaxPhiCoefChanged_ = true;
28272828
npVars_->maxPhiCoef *= 0.99;
28282829
}
@@ -2849,7 +2850,7 @@ bool NesterovBase::checkConvergence(int gpl_iter_count,
28492850
if (isConverged_) {
28502851
return true;
28512852
}
2852-
if (sumOverflowUnscaled_ <= npVars_->targetOverflow) {
2853+
if (sum_overflow_unscaled_ <= npVars_->targetOverflow) {
28532854
const bool is_power_domain = pb_->group();
28542855
const std::string group_name
28552856
= is_power_domain ? pb_->group()->getName() : "";
@@ -2858,7 +2859,7 @@ bool NesterovBase::checkConvergence(int gpl_iter_count,
28582859

28592860
log_->report("{:9d} | {:8.4f} | {:13.6e} | {:>8} | {:9.2e} | {:>5}",
28602861
final_iter,
2861-
sumOverflowUnscaled_,
2862+
sum_overflow_unscaled_,
28622863
block->dbuToMicrons(nbc_->getHpwl()),
28632864
"", // No % delta
28642865
densityPenalty_,
@@ -2963,12 +2964,25 @@ bool NesterovBase::checkConvergence(int gpl_iter_count,
29632964

29642965
bool NesterovBase::checkDivergence()
29652966
{
2966-
if (sumOverflowUnscaled_ < 0.2f
2967-
&& sumOverflowUnscaled_ - minSumOverflow_ >= 0.02f
2968-
&& hpwlWithMinSumOverflow_ * 1.2f < prevHpwl_) {
2967+
if (sum_overflow_unscaled_ < 0.2f
2968+
&& sum_overflow_unscaled_ - minSumOverflow_ >= 0.02f
2969+
&& hpwlWithMinSumOverflow_ * 1.2f < prev_hpwl_) {
29692970
isDiverged_ = true;
29702971
}
29712972

2973+
// Check if both overflow and HPWL increase
2974+
if (minSumOverflow_ < 0.2f && prev_reported_overflow_unscaled_ > 0
2975+
&& prev_reported_hpwl_ > 0) {
2976+
float overflow_change
2977+
= sum_overflow_unscaled_ - prev_reported_overflow_unscaled_;
2978+
float hpwl_increase = (static_cast<float>(prev_hpwl_ - prev_reported_hpwl_))
2979+
/ static_cast<float>(prev_reported_hpwl_);
2980+
2981+
if (overflow_change >= 0.02f && hpwl_increase >= 0.05f) {
2982+
isDiverged_ = true;
2983+
}
2984+
}
2985+
29722986
return isDiverged_;
29732987
}
29742988

src/gpl/src/nesterovBase.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ class NesterovBase
925925

926926
const std::vector<GCellHandle>& getGCells() const { return nb_gcells_; }
927927

928-
float getSumOverflow() const { return sumOverflow_; }
929-
float getSumOverflowUnscaled() const { return sumOverflowUnscaled_; }
928+
float getSumOverflow() const { return sum_overflow_; }
929+
float getSumOverflowUnscaled() const { return sum_overflow_unscaled_; }
930930
float getBaseWireLengthCoef() const { return baseWireLengthCoef_; }
931931
float getDensityPenalty() const { return densityPenalty_; }
932932

@@ -1210,12 +1210,13 @@ class NesterovBase
12101210
float baseWireLengthCoef_ = 0;
12111211

12121212
// phi is described in ePlace paper.
1213-
float sumOverflow_ = 0;
1214-
float sumOverflowUnscaled_ = 0;
1213+
float sum_overflow_ = 0;
1214+
float sum_overflow_unscaled_ = 0;
1215+
float prev_reported_overflow_unscaled_ = 0;
12151216

12161217
// half-parameter-wire-length
1217-
int64_t prevHpwl_ = 0;
1218-
int64_t prevReportedHpwl_ = 0;
1218+
int64_t prev_hpwl_ = 0;
1219+
int64_t prev_reported_hpwl_ = 0;
12191220

12201221
bool isDiverged_ = false;
12211222

0 commit comments

Comments
 (0)