@@ -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+
20272089int 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
0 commit comments