Skip to content

Commit b5cc428

Browse files
authored
Merge pull request #8754 from gudeh/gpl-relax-new-divergence-check
gpl: relax new divergence check
2 parents f94468c + 50738a7 commit b5cc428

File tree

12 files changed

+209
-74
lines changed

12 files changed

+209
-74
lines changed

src/gpl/src/nesterovBase.cpp

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ void Bin::setDensity(float density)
573573
density_ = density;
574574
}
575575

576-
void Bin::setTargetDensity(float density)
576+
void Bin::setBinTargetDensity(float density)
577577
{
578578
targetDensity_ = density;
579579
}
@@ -615,7 +615,7 @@ void BinGrid::setLogger(utl::Logger* log)
615615
log_ = log;
616616
}
617617

618-
void BinGrid::setTargetDensity(float density)
618+
void BinGrid::setBinTargetDensity(float density)
619619
{
620620
targetDensity_ = density;
621621
}
@@ -1034,6 +1034,7 @@ NesterovBaseCommon::NesterovBaseCommon(NesterovBaseVars nbVars,
10341034
log_ = log;
10351035
delta_area_ = 0;
10361036
new_gcells_count_ = 0;
1037+
deleted_gcells_count_ = 0;
10371038

10381039
// gCellStor init
10391040
gCellStor_.reserve(pbc_->placeInsts().size());
@@ -1759,7 +1760,7 @@ NesterovBase::NesterovBase(NesterovBaseVars nbVars,
17591760
region_bbox.yMin(),
17601761
region_bbox.xMax(),
17611762
region_bbox.yMax());
1762-
bg_.setTargetDensity(targetDensity_);
1763+
bg_.setBinTargetDensity(targetDensity_);
17631764

17641765
// update binGrid info
17651766
bg_.initBins();
@@ -1774,6 +1775,8 @@ NesterovBase::NesterovBase(NesterovBaseVars nbVars,
17741775

17751776
// update densitySize and densityScale in each gCell
17761777
updateDensitySize();
1778+
1779+
checkConsistency();
17771780
}
17781781

17791782
// virtual filler GCells
@@ -2014,16 +2017,75 @@ void NesterovBase::setTargetDensity(float density)
20142017
{
20152018
assert(omp_get_thread_num() == 0);
20162019
targetDensity_ = density;
2017-
bg_.setTargetDensity(density);
2020+
bg_.setBinTargetDensity(density);
20182021
#pragma omp parallel for num_threads(nbc_->getNumThreads())
20192022
for (auto bin = getBins().begin(); bin < getBins().end(); ++bin) {
20202023
// old-style loop for old OpenMP
2021-
bin->setTargetDensity(density);
2024+
bin->setBinTargetDensity(density);
20222025
}
20232026
// update nonPlaceArea's target denstiy
20242027
bg_.updateBinsNonPlaceArea();
20252028
}
20262029

2030+
void NesterovBase::checkConsistency()
2031+
{
2032+
if (!log_->debugCheck(GPL, "checkConsistency", 1)) {
2033+
return;
2034+
}
2035+
const auto block = pb_->db()->getChip()->getBlock();
2036+
const int64_t tolerance = 10000;
2037+
2038+
const int64_t expected_white_space
2039+
= pb_->getDie().coreArea() - pb_->nonPlaceInstsArea();
2040+
if (std::abs(whiteSpaceArea_ - expected_white_space) > tolerance) {
2041+
log_->warn(utl::GPL, 319, "Inconsistent white space area");
2042+
log_->report(
2043+
"whiteSpaceArea_: {} (expected:{}) | coreArea: {}, "
2044+
"nonPlaceInstsArea: {}",
2045+
block->dbuAreaToMicrons(whiteSpaceArea_),
2046+
block->dbuAreaToMicrons(expected_white_space),
2047+
block->dbuAreaToMicrons(pb_->getDie().coreArea()),
2048+
block->dbuAreaToMicrons(pb_->nonPlaceInstsArea()));
2049+
}
2050+
2051+
const int64_t expected_movable_area = whiteSpaceArea_ * targetDensity_;
2052+
if (std::abs(movableArea_ - expected_movable_area) > tolerance) {
2053+
log_->warn(utl::GPL, 320, "Inconsistent movable area 1");
2054+
log_->report(
2055+
"movableArea_: {} (expected:{}) | whiteSpaceArea_: {}, "
2056+
"targetDensity_: {}",
2057+
block->dbuAreaToMicrons(movableArea_),
2058+
block->dbuAreaToMicrons(expected_movable_area),
2059+
block->dbuAreaToMicrons(whiteSpaceArea_),
2060+
targetDensity_);
2061+
}
2062+
2063+
const int64_t expected_filler_area = movableArea_ - getNesterovInstsArea();
2064+
if (std::abs(totalFillerArea_ - expected_filler_area) > tolerance) {
2065+
log_->warn(utl::GPL, 321, "Inconsistent filler area");
2066+
log_->report(
2067+
"totalFillerArea_: {} (expected:{}) | movableArea_: {}, "
2068+
"getNesterovInstsArea_: {}",
2069+
block->dbuAreaToMicrons(totalFillerArea_),
2070+
block->dbuAreaToMicrons(expected_filler_area),
2071+
block->dbuAreaToMicrons(movableArea_),
2072+
block->dbuAreaToMicrons(getNesterovInstsArea()));
2073+
}
2074+
2075+
float expected_density = movableArea_ * 1.0 / whiteSpaceArea_;
2076+
float density_diff = std::abs(targetDensity_ - expected_density);
2077+
if (density_diff > 1e-6) {
2078+
log_->warn(utl::GPL, 322, "Inconsistent target density");
2079+
log_->report(
2080+
"targetDensity_: {} (expected:{}) | movableArea_: {}, "
2081+
"whiteSpaceArea_: {}",
2082+
targetDensity_,
2083+
expected_density,
2084+
block->dbuAreaToMicrons(movableArea_),
2085+
block->dbuAreaToMicrons(whiteSpaceArea_));
2086+
}
2087+
}
2088+
20272089
int NesterovBase::getBinCntX() const
20282090
{
20292091
return bg_.getBinCntX();
@@ -2364,7 +2426,7 @@ float NesterovBase::initDensity2(float wlCoeffX, float wlCoeffY)
23642426
{
23652427
if (wireLengthGradSum_ == 0) {
23662428
densityPenalty_ = npVars_->initDensityPenalty;
2367-
updatePrevGradient(wlCoeffX, wlCoeffY);
2429+
nbUpdatePrevGradient(wlCoeffX, wlCoeffY);
23682430
}
23692431

23702432
if (wireLengthGradSum_ != 0) {
@@ -2484,7 +2546,7 @@ void NesterovBase::updateGradients(std::vector<FloatPoint>& sumGrads,
24842546
debugPrint(log_, GPL, "updateGrad", 1, "GradSum: {:g}", gradSum);
24852547
}
24862548

2487-
void NesterovBase::updatePrevGradient(float wlCoeffX, float wlCoeffY)
2549+
void NesterovBase::nbUpdatePrevGradient(float wlCoeffX, float wlCoeffY)
24882550
{
24892551
updateGradients(prevSLPSumGrads_,
24902552
prevSLPWireLengthGrads_,
@@ -2493,7 +2555,7 @@ void NesterovBase::updatePrevGradient(float wlCoeffX, float wlCoeffY)
24932555
wlCoeffY);
24942556
}
24952557

2496-
void NesterovBase::updateCurGradient(float wlCoeffX, float wlCoeffY)
2558+
void NesterovBase::nbUpdateCurGradient(float wlCoeffX, float wlCoeffY)
24972559
{
24982560
updateGradients(curSLPSumGrads_,
24992561
curSLPWireLengthGrads_,
@@ -2502,7 +2564,7 @@ void NesterovBase::updateCurGradient(float wlCoeffX, float wlCoeffY)
25022564
wlCoeffY);
25032565
}
25042566

2505-
void NesterovBase::updateNextGradient(float wlCoeffX, float wlCoeffY)
2567+
void NesterovBase::nbUpdateNextGradient(float wlCoeffX, float wlCoeffY)
25062568
{
25072569
updateGradients(nextSLPSumGrads_,
25082570
nextSLPWireLengthGrads_,
@@ -2553,12 +2615,6 @@ void NesterovBase::updateSingleGradient(
25532615
= nbc_->getWireLengthGradientWA(gCell, wlCoeffX, wlCoeffY);
25542616
densityGrads[gCellIndex] = getDensityGradient(gCell);
25552617

2556-
wireLengthGradSum_ += std::fabs(wireLengthGrads[gCellIndex].x);
2557-
wireLengthGradSum_ += std::fabs(wireLengthGrads[gCellIndex].y);
2558-
2559-
densityGradSum_ += std::fabs(densityGrads[gCellIndex].x);
2560-
densityGradSum_ += std::fabs(densityGrads[gCellIndex].y);
2561-
25622618
sumGrads[gCellIndex].x = wireLengthGrads[gCellIndex].x
25632619
+ densityPenalty_ * densityGrads[gCellIndex].x;
25642620
sumGrads[gCellIndex].y = wireLengthGrads[gCellIndex].y
@@ -2975,6 +3031,7 @@ bool NesterovBase::checkDivergence()
29753031
&& sum_overflow_unscaled_ - minSumOverflow_ >= 0.02f
29763032
&& hpwlWithMinSumOverflow_ * 1.2f < prev_hpwl_) {
29773033
isDiverged_ = true;
3034+
log_->warn(GPL, 323, "Divergence detected between consecutive iterations");
29783035
}
29793036

29803037
// Check if both overflow and HPWL increase
@@ -2985,8 +3042,17 @@ bool NesterovBase::checkDivergence()
29853042
float hpwl_increase = (static_cast<float>(prev_hpwl_ - prev_reported_hpwl_))
29863043
/ static_cast<float>(prev_reported_hpwl_);
29873044

2988-
if (overflow_change >= 0.02f && hpwl_increase >= 0.05f) {
3045+
const float overflow_acceptance = 0.05f;
3046+
const float hpwl_acceptance = 0.25f;
3047+
if (overflow_change >= overflow_acceptance
3048+
&& hpwl_increase >= hpwl_acceptance) {
29893049
isDiverged_ = true;
3050+
log_->warn(GPL,
3051+
324,
3052+
"Divergence detected between reported values. Overflow "
3053+
"change: {:g}, HPWL increase: {:g}%.",
3054+
overflow_change,
3055+
hpwl_increase * 100.0f);
29903056
}
29913057
}
29923058

@@ -3333,7 +3399,7 @@ std::pair<odb::dbInst*, size_t> NesterovBaseCommon::destroyCbkGCell(
33333399
int64_t area_change = static_cast<int64_t>(gCellStor_.back().dx())
33343400
* static_cast<int64_t>(gCellStor_.back().dy());
33353401
delta_area_ -= area_change;
3336-
new_gcells_count_--;
3402+
deleted_gcells_count_++;
33373403

33383404
gCellStor_.pop_back();
33393405
minRcCellSize_.pop_back();
@@ -3451,10 +3517,8 @@ void NesterovBase::cutFillerCells(int64_t inflation_area)
34513517
+ totalFillerArea_ + remainingInflationArea;
34523518
setTargetDensity(static_cast<float>(totalGCellArea)
34533519
/ static_cast<float>(getWhiteSpaceArea()));
3454-
3455-
float newTargetDensity = static_cast<float>(totalGCellArea)
3456-
/ static_cast<float>(getWhiteSpaceArea());
3457-
log_->info(GPL, 79, "New target density: {}", newTargetDensity);
3520+
movableArea_ = whiteSpaceArea_ * targetDensity_;
3521+
log_->info(GPL, 79, "New target density: {}", targetDensity_);
34583522
}
34593523
}
34603524

src/gpl/src/nesterovBase.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
#pragma once
55

6+
#include <cmath>
67
#include <cstddef>
78
#include <cstdint>
89
#include <cstdio>
10+
#include <cstdlib>
911
#include <deque>
1012
#include <fstream>
1113
#include <memory>
@@ -21,6 +23,7 @@
2123
#include "placerBase.h"
2224
#include "point.h"
2325
#include "routeBase.h"
26+
#include "utl/Logger.h"
2427
namespace odb {
2528
class dbInst;
2629
class dbITerm;
@@ -538,7 +541,7 @@ class Bin
538541
float getDensity() const;
539542

540543
void setDensity(float density);
541-
void setTargetDensity(float density);
544+
void setBinTargetDensity(float density);
542545
void setElectroForce(float electroForceX, float electroForceY);
543546
void setElectroPhi(float phi);
544547

@@ -673,7 +676,7 @@ class BinGrid
673676
void setLogger(utl::Logger* log);
674677
void setRegionPoints(int lx, int ly, int ux, int uy);
675678
void setBinCnt(int binCntX, int binCntY);
676-
void setTargetDensity(float density);
679+
void setBinTargetDensity(float density);
677680
void updateBinsGCellDensityArea(const std::vector<GCellHandle>& cells);
678681
void setNumThreads(int num_threads) { num_threads_ = num_threads; }
679682

@@ -871,8 +874,13 @@ class NesterovBaseCommon
871874
// are implemented.
872875
int64_t getDeltaArea() { return delta_area_; }
873876
void resetDeltaArea() { delta_area_ = 0; }
874-
int64_t getNewGcellsCount() { return new_gcells_count_; }
875-
void resetNewGcellsCount() { new_gcells_count_ = 0; }
877+
int getNewGcellsCount() { return new_gcells_count_; }
878+
int getDeletedGcellsCount() { return deleted_gcells_count_; }
879+
void resetNewGcellsCount()
880+
{
881+
new_gcells_count_ = 0;
882+
deleted_gcells_count_ = 0;
883+
}
876884

877885
private:
878886
NesterovBaseVars nbVars_;
@@ -907,6 +915,7 @@ class NesterovBaseCommon
907915
int num_threads_;
908916
int64_t delta_area_;
909917
int new_gcells_count_;
918+
int deleted_gcells_count_;
910919
nesterovDbCbk* db_cbk_{nullptr};
911920
};
912921

@@ -960,6 +969,8 @@ class NesterovBase
960969
int64_t getMovableArea() const;
961970
int64_t getTotalFillerArea() const;
962971

972+
void setMovableArea(int64_t area) { movableArea_ = area; }
973+
963974
// update
964975
// fillerArea, whiteSpaceArea, movableArea
965976
// and totalFillerArea after changing gCell's size
@@ -992,6 +1003,7 @@ class NesterovBase
9921003
float getTargetDensity() const;
9931004

9941005
void setTargetDensity(float targetDensity);
1006+
void checkConsistency();
9951007

9961008
// RD can shrink the number of fillerCells.
9971009
void cutFillerCells(int64_t targetFillerArea);
@@ -1030,9 +1042,9 @@ class NesterovBase
10301042
float wlCoeffX,
10311043
float wlCoeffY);
10321044

1033-
void updatePrevGradient(float wlCoeffX, float wlCoeffY);
1034-
void updateCurGradient(float wlCoeffX, float wlCoeffY);
1035-
void updateNextGradient(float wlCoeffX, float wlCoeffY);
1045+
void nbUpdatePrevGradient(float wlCoeffX, float wlCoeffY);
1046+
void nbUpdateCurGradient(float wlCoeffX, float wlCoeffY);
1047+
void nbUpdateNextGradient(float wlCoeffX, float wlCoeffY);
10361048

10371049
// Used for updates based on callbacks
10381050
void updateSingleGradient(size_t gCellIndex,
@@ -1064,6 +1076,7 @@ class NesterovBase
10641076
bool checkConvergence(int gpl_iter_count,
10651077
int routability_gpl_iter_count,
10661078
RouteBase* rb);
1079+
10671080
bool checkDivergence();
10681081
void saveSnapshot();
10691082
bool revertToSnapshot();

0 commit comments

Comments
 (0)