Skip to content

Commit

Permalink
Merge pull request #6639 from The-OpenROAD-Project-staging/gpl-avoid-…
Browse files Browse the repository at this point in the history
…td-during-rd

gpl: avoid timing-driven during routability
  • Loading branch information
maliberty authored Feb 17, 2025
2 parents 3fc93e0 + 156b736 commit 08d9860
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 359 deletions.
2 changes: 1 addition & 1 deletion src/gpl/src/nesterovBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ bool NesterovBase::checkDivergence()
return isDiverged_;
}

bool NesterovBase::revertDivergence()
bool NesterovBase::revertToSnapshot()
{
if (isConverged_) {
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/gpl/src/nesterovBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,15 @@ class NesterovPlaceVars
float minPreconditioner = 1.0; // MIN_PRE
float initialPrevCoordiUpdateCoef = 100; // z_ref_alpha
float referenceHpwl = 446000000; // refDeltaHpwl
float routabilityCheckOverflow = 0.30;
float routability_end_overflow = 0.30;
float keepResizeBelowOverflow = 0.3;

static const int maxRecursionWlCoef = 10;
static const int maxRecursionInitSLPCoef = 10;

bool timingDrivenMode = true;
int timingDrivenIterCounter = 0;
bool routabilityDrivenMode = true;
bool routability_driven_mode = true;
bool disableRevertIfDiverge = false;

bool debug = false;
Expand Down Expand Up @@ -1067,7 +1067,7 @@ class NesterovBase

bool checkConvergence();
bool checkDivergence();
bool revertDivergence();
bool revertToSnapshot();

void updateDensityCenterCur();
void updateDensityCenterCurSLP();
Expand Down
88 changes: 52 additions & 36 deletions src/gpl/src/nesterovPlace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void NesterovPlace::reset()
wireLengthCoefX_ = wireLengthCoefY_ = 0;
prevHpwl_ = 0;
isDiverged_ = false;
isRoutabilityNeed_ = true;
is_routability_need_ = true;

divergeMsg_ = "";
divergeCode_ = 0;
Expand All @@ -322,9 +322,10 @@ int NesterovPlace::doNesterovPlace(int start_iter)
bool is_routability_snapshot_saved = false;
float route_snapshotA = 0;
float route_snapshot_WlCoefX = 0, route_snapshot_WlCoefY = 0;
bool isDivergeTriedRevert = false;
// bool isDivergeTriedRevert = false;

// divergence snapshot info
bool is_diverge_snapshot_saved = false;
float diverge_snapshot_WlCoefX = 0, diverge_snapshot_WlCoefY = 0;

// backTracking variable.
Expand Down Expand Up @@ -419,6 +420,7 @@ int NesterovPlace::doNesterovPlace(int start_iter)
for (auto& nb : nbVec_) {
nb->snapshot();
}
is_diverge_snapshot_saved = true;
}
}

Expand All @@ -438,8 +440,16 @@ int NesterovPlace::doNesterovPlace(int start_iter)
// timing driven feature
// if virtual, do reweight on timing-critical nets,
// otherwise keep all modifications by rsz.
const bool is_before_routability
= average_overflow_ > routability_save_snapshot_;
const bool is_after_routability
= (average_overflow_ < npVars_.routability_end_overflow
&& !is_routability_need_);
if (npVars_.timingDrivenMode
&& tb_->isTimingNetWeightOverflow(average_overflow_)) {
&& tb_->isTimingNetWeightOverflow(average_overflow_) &&
// do not execute timing-driven if routability is under execution
(is_before_routability || is_after_routability
|| !npVars_.routability_driven_mode)) {
// update db's instance location from current density coordinates
updateDb();

Expand Down Expand Up @@ -530,31 +540,37 @@ int NesterovPlace::doNesterovPlace(int start_iter)
}

if (numDiverge > 0) {
divergeMsg_ = "RePlAce divergence detected. ";
divergeMsg_ += "Re-run with a smaller max_phi_cof value.";
divergeCode_ = 307;
isDiverged_ = true;

// revert back to the original rb solutions
// one more opportunity
if (!isDivergeTriedRevert && rb_->numCall() >= 1) {
// get back to the working rc size
rb_->revertGCellSizeToMinRc();
curA = route_snapshotA;
wireLengthCoefX_ = route_snapshot_WlCoefX;
wireLengthCoefY_ = route_snapshot_WlCoefY;
nbc_->updateWireLengthForceWA(wireLengthCoefX_, wireLengthCoefY_);
for (auto& nb : nbVec_) {
nb->revertDivergence();
}

isDiverged_ = false;
divergeCode_ = 0;
divergeMsg_ = "";
isDivergeTriedRevert = true;
// turn off the RD forcely
isRoutabilityNeed_ = false;
} else if (!npVars_.disableRevertIfDiverge) {
log_->report("Divergence occured in {} regions.", numDiverge);

// TODO: this divergence treatment uses the non-deterministic aspect of
// routability inflation to try one more time if a divergence is detected.
// This feature lost its consistency since we allow for non-virtual timing
// driven iterations. Meaning we would go back to a snapshot without newly
// added instances. A way to maintain this feature is to store two
// snapshots one for routability revert if diverge and try again, and
// another for simply revert if diverge and finish without hitting 0.10
// overflow.
// // revert back to the original rb solutions
// // one more opportunity
// if (!isDivergeTriedRevert && rb_->numCall() >= 1) {
// // get back to the working rc size
// rb_->revertGCellSizeToMinRc();
// curA = route_snapshotA;
// wireLengthCoefX_ = route_snapshot_WlCoefX;
// wireLengthCoefY_ = route_snapshot_WlCoefY;
// nbc_->updateWireLengthForceWA(wireLengthCoefX_, wireLengthCoefY_);
// for (auto& nb : nbVec_) {
// nb->revertToSnapshot();
// }

// isDiverged_ = false;
// divergeCode_ = 0;
// divergeMsg_ = "";
// isDivergeTriedRevert = true;
// // turn off the RD forcely
// is_routability_need_ = false;
// } else
if (!npVars_.disableRevertIfDiverge && is_diverge_snapshot_saved) {
// In case diverged and not in routability mode, finish with min hpwl
// stored since overflow below 0.25
log_->warn(GPL,
Expand All @@ -570,7 +586,7 @@ int NesterovPlace::doNesterovPlace(int start_iter)
wireLengthCoefY_ = diverge_snapshot_WlCoefY;
nbc_->updateWireLengthForceWA(wireLengthCoefX_, wireLengthCoefY_);
for (auto& nb : nbVec_) {
nb->revertDivergence();
nb->revertToSnapshot();
}
isDiverged_ = false;
break;
Expand All @@ -579,8 +595,8 @@ int NesterovPlace::doNesterovPlace(int start_iter)
}
}

if (!is_routability_snapshot_saved && npVars_.routabilityDrivenMode
&& 0.6 >= average_overflow_unscaled_) {
if (!is_routability_snapshot_saved && npVars_.routability_driven_mode
&& routability_save_snapshot_ >= average_overflow_unscaled_) {
route_snapshot_WlCoefX = wireLengthCoefX_;
route_snapshot_WlCoefY = wireLengthCoefY_;
route_snapshotA = curA;
Expand All @@ -594,16 +610,16 @@ int NesterovPlace::doNesterovPlace(int start_iter)
}

// check routability using RUDY or GR
if (npVars_.routabilityDrivenMode && isRoutabilityNeed_
&& npVars_.routabilityCheckOverflow >= average_overflow_unscaled_) {
if (npVars_.routability_driven_mode && is_routability_need_
&& npVars_.routability_end_overflow >= average_overflow_unscaled_) {
// recover the densityPenalty values
// if further routability-driven is needed
std::pair<bool, bool> result = rb_->routability();
isRoutabilityNeed_ = result.first;
is_routability_need_ = result.first;
bool isRevertInitNeeded = result.second;

// if routability is needed
if (isRoutabilityNeed_ || isRevertInitNeeded) {
if (is_routability_need_ || isRevertInitNeeded) {
// cutFillerCoordinates();

// revert back the current density penality
Expand All @@ -614,7 +630,7 @@ int NesterovPlace::doNesterovPlace(int start_iter)
nbc_->updateWireLengthForceWA(wireLengthCoefX_, wireLengthCoefY_);

for (auto& nb : nbVec_) {
nb->revertDivergence();
nb->revertToSnapshot();
nb->resetMinSumOverflow();
}
log_->info(GPL, 89, "Routability: revert back to snapshot");
Expand Down
3 changes: 2 additions & 1 deletion src/gpl/src/nesterovPlace.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class NesterovPlace
int64_t prevHpwl_ = 0;

bool isDiverged_ = false;
bool isRoutabilityNeed_ = true;
bool is_routability_need_ = true;
float routability_save_snapshot_ = 0.6;

std::string divergeMsg_;
int divergeCode_ = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/gpl/src/replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ bool Replace::initNesterovPlace(int threads)
npVars.minPhiCoef = minPhiCoef_;
npVars.maxPhiCoef = maxPhiCoef_;
npVars.referenceHpwl = referenceHpwl_;
npVars.routabilityCheckOverflow = routabilityCheckOverflow_;
npVars.routability_end_overflow = routabilityCheckOverflow_;
npVars.keepResizeBelowOverflow = keepResizeBelowOverflow_;
npVars.initDensityPenalty = initDensityPenalityFactor_;
npVars.initWireLengthCoef = initWireLengthCoef_;
npVars.targetOverflow = overflow_;
npVars.maxNesterovIter = nesterovPlaceMaxIter_;
npVars.timingDrivenMode = timingDrivenMode_;
npVars.routabilityDrivenMode = routabilityDrivenMode_;
npVars.routability_driven_mode = routabilityDrivenMode_;
npVars.debug = gui_debug_;
npVars.debug_pause_iterations = gui_debug_pause_iterations_;
npVars.debug_update_iterations = gui_debug_update_iterations_;
Expand Down
2 changes: 1 addition & 1 deletion src/gpl/src/replace.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ proc global_placement { args } {
if { [info exists keys(-timing_driven_net_reweight_overflow)] } {
set overflow_list $keys(-timing_driven_net_reweight_overflow)
} else {
set overflow_list [list 79 64 49 29 21 15]
set overflow_list [list 79 64 29 21 15]
}

foreach overflow $overflow_list {
Expand Down
2 changes: 1 addition & 1 deletion src/gpl/test/convergence01.ok
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
[INFO GPL-0029] BinSize: ( 1.377 1.350 )
[INFO GPL-0030] NumBins: 64
[NesterovSolve] Iter: 1 overflow: 0.127 HPWL: 397899
[INFO GPL-0100] Timing-driven iteration 1/6, virtual: false.
[INFO GPL-0100] Timing-driven iteration 1/5, virtual: false.
[INFO GPL-0101] Iter: 0, overflow: 0.127, keep rsz at: 0.3
[INFO GPL-0106] Timing-driven: worst slack 6.35e-09
[INFO GPL-0103] Timing-driven: weighted 4 nets.
Expand Down
2 changes: 1 addition & 1 deletion src/gpl/test/gpl_aux.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def global_placement(
if timing_driven_net_reweight_overflow != None:
overflow_list = timing_driven_net_reweight_overflow
else:
overflow_list = [79, 64, 49, 29, 21, 15]
overflow_list = [79, 64, 29, 21, 15]

for ov in overflow_list:
gpl.addTimingNetWeightOverflow(ov)
Expand Down
Loading

0 comments on commit 08d9860

Please sign in to comment.