Skip to content

(Discarded) rsz: WNS stagnation logic enhancement based on PR 10248 - #10284

Closed
openroad-ci wants to merge 18 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-pr-10248-add-unit-test
Closed

openroad-ci wants to merge 18 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:secure-pr-10248-add-unit-test

Conversation

@openroad-ci

Copy link
Copy Markdown
Member

This PR is based on the latest head of the original public PR:

The only additional change on top of that PR is the failing-test rebaseline commit:

  • 1dfe516 rsz: update repair hold multi-output golden

This updates only src/rsz/test/repair_hold_multi_output_load.ok for the current timing output. The previously local repair_setup_stagnation test commit was intentionally excluded because PR #10248 already added a similar repair_setup_hopeless unit test.

Verification:

bazel test --cache_test_results=no --test_output=errors //src/rsz/test:repair_hold_multi_output_load-tcl_test

Result: PASSED

oharboe and others added 9 commits April 24, 2026 10:31
Adds a deterministic WNS-stagnation gate to RepairSetup::terminateProgress().
Best-so-far WNS is sampled every pass into a 200-pass ring buffer; if the
best observed value has not improved by max(1 ps, 0.5% * |initial_wns|)
over a full window, the gate returns true. Combined with the existing
two-consecutive-termination rule this aborts the phase after ~1200 passes
of no WNS movement on designs where tiny TNS twitches would otherwise keep
the optimizer running forever.

Motivated by automated architectural-exploration flows where the .sdc is
held at an ambitious target while RTL evolves. Without this, a WNS gap of
hundreds of ps grinds repair_timing for hours producing no useful movement
and forcing users to guess SETUP_SLACK_MARGIN values to stop it. The gate
fires only when no reasonable user would disagree that further effort is
futile (1 ps absolute floor keeps tape-out grind untouched; the TNS
fix-rate gate still owns termination near closure).

On trip, a single loud INFO log (RSZ-0234/235/236) names the best-effort
WNS and notes this is probably an exploration run. No new Tcl flag, no
new ORFS env var - hardcoded conservative defaults.

New test test/orfs/hopeless/ synthesizes 8 parallel 8-deep arithmetic
pipelines on asap7 with a 50 ps clock and asserts both that the flow
completes and that the gate log message appears (sh_test + grep). A
check_same idempotent test guards the determinism property.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
- RepairSetup.hh: include <cstddef> for size_t and <string> for
  std::string (include-cleaner warnings from clang-tidy CI bot).
- RepairSetup.hh / RepairSetup.cc: name the stagnation-gate warmup
  threshold wns_stagnation_warmup_iterations_ instead of the bare 1000
  literal, matching the style of the other tunables in this class.

Not applied: gemini-code-assist's suggestion to change
wns_stagnation_abs_tol_ from 1.0e-12f to 1.0e-3f. sta::Slack is
measured in seconds (see src/sta/include/sta/Units.hh:73 "Sta internal
units are always seconds, ..."), so 1.0e-12 s is 1 ps, which is the
intended value. 1.0e-3 s would be 1 ms and would disable the gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Wrap long sta::Slack initialization line that clang-format flagged on
PR The-OpenROAD-Project#10248 after the gemini-code-assist suggestion was applied via the
GitHub UI.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
The sliding-window check (window_best - window_oldest over 200 passes)
mis-classified plateaus as futility: any real design whose WNS drops
dramatically early then flat-lines at a topology-bound floor while TNS
keeps improving (aes, clone_flat, repair_fanout*) tripped the gate and
aborted repair_timing too early, leaving worse max_cap/max_slew slack
and different .ok-file output.

Replace with best_wns_ever vs initial_wns_: only fire when WNS has
effectively never moved from its starting value, which is the real
signature of an obviously-futile run.

Also bump rel_tol 0.5% -> 5%. Empirically aes improves WNS by ~50% of
initial, clone_flat by ~95%, repair_fanout by ~90%; the hopeless.v
synthetic only moves WNS by ~2% because buffer insertion chips
something off even a grossly-over-clocked design. 5% sits in the gap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Tiny TCL unit test exercising the WNS-stagnation gate added in this PR
without scraping log strings.  It builds a flat block of 1200
register-to-register pairs (DFF_X2 driver -> DFF_X2 sink, no logic in
between), holds the cell library to _X1 / _X2 sizes, and sets a 1 ps
clock period so that no SizeUpMove / BufferMove / pin-swap / clone /
split-load / unbuffer move can improve WNS.  The endpoint count is
chosen so the inner-loop counter passes the gate's warmup before the
legacy phase has visited every endpoint.

Without the gate the same .tcl runs to iteration 1200 (one futile pass
per endpoint); with the gate it exits at iteration 1002 and the .ok
diverges, so the test fails without the fix and passes with it.

Replaces the orfs-based test/orfs/hopeless gate-coverage check that
maliberty asked to convert into a repair_setup-only unit test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>

# Conflicts:
#	src/rsz/test/CMakeLists.txt
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a 'WNS-stagnation' gate to the repair_timing flow in RepairSetup. This mechanism detects and aborts 'obviously futile' optimization runs where the Worst Negative Slack (WNS) fails to improve significantly after a warmup period, preventing the tool from grinding indefinitely on infeasible designs. The changes include new tracking methods in RepairSetup, updated logging, and a new regression test suite to verify the gate's behavior. I have no further feedback to provide.

This reverts commit 1dfe516.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…ate/OpenROAD into secure-pr-10248-add-unit-test

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

The window-improvement and threshold values are pure functions of
already-stored state (best_wns_, ring buffer, initial_wns_). Compute
them locally in terminateProgress() and recompute on demand in
wnsStagnationReport() instead of mirroring them on the class.

Removes 2 members and the "result-cached-for-display" smell.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@jhkim-pii

jhkim-pii commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

@jhkim-pii

jhkim-pii commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

@oharboe
There are two issues.

1. WNS impact

  • Current WNS stagnation threshold 200 pass affects setup WNS (some designs showed better WNS while some other designs showed worse WNS in the dashboard).
  • 200 pass threshold is insufficient??? Need more investigation.
    --> Found the reason.
    • Repair setup is used at multiple stages (floorplan, placement, cts, ...).
    • The different optimization result in an early stage (e.g., floorplan) leads to different placement and different finish QoR.

2. TNS degradation

  • WNS stagnation checker does not consider the TNS improvement. So it causes TNS degradation.
  • I think WNS stagnation checker should not be enabled for LEGACY and LAST_GASP phases because it hurts TNS.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
…-unit-test

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>

# Conflicts:
#	src/rsz/test/CMakeLists.txt
@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@jhkim-pii

jhkim-pii commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

@oharboe I enabled your WNS stagnation checker for WNS phase only. If you do not take care of TNS, you can run repair_timing w/ WNS phase configuration. If it cannot satisfy your needs, please share your thoughts.

@oharboe

oharboe commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

@oharboe I enabled your WNS stagnation checker for WNS phase only. If you do not take care of TNS, you can run repair_timing w/ WNS phase configuration. If it cannot satisfy your needs, please share your thoughts.

Yes, I only have this problem when WNS < 0.

@jhkim-pii

Copy link
Copy Markdown
Contributor

@oharboe
It looks like my explanation was insufficient.

  1. The current WNS stagnation checker only monitors the WNS. It terminates the optimization if there is less than 0.5% WNS enhancement over 200 iterations.
  2. Originally, WNS stagnation checker was enabled for LEGACY, LAST_GASP, and WNS phases.
  3. LEGACY & LAST_GASP phases should improve both WNS & TNS.
  4. But the early termination by WNS monitoring can hurt TNS in some designs. Some designs still have room to improve TNS further, but the WNS stagnation checker eliminates the TNS improvement opportunity.
  5. So I applied the WNS stagnation checker only for WNS phase. It means that WNS stagnation checker is disabled in LEGACY & LAST_GASP policies.

I want to clarify these things.
A. In your experiment, are you interested in WNS only? (do not care how bad the TNS is)
If it is true, I think you can use WNS phase instead of LEGACY to ignore TNS.

B. If you care the TNS too, then the TNS monitoring logic enhancement is required.

So I wonder if you are ok w/ WNS phase (repair_timing -setup -phases "WNS"). Then, current version in this PR would be sufficient.

@oharboe

oharboe commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

When it is clearly hopeless to close timing(WNS=0), then I want the quick wins in WNS and TNS and then terminate. Terminating quickly is more important than the exact improvements in WNS and TNS, we just want to fix pathological fanout things that are quick to fix(such as pathological fanout?).

@jhkim-pii

Copy link
Copy Markdown
Contributor

I see. If repair_timing -setup -phases "WNS" with this PR cannot resolve your issue, please let us know.
We can find another solution (e.g., another TNS stagnation checking logic, apply multi-threading for faster runtime at the expense of small QoR loss, ...).

@oharboe

oharboe commented May 1, 2026

Copy link
Copy Markdown
Collaborator

I see. If repair_timing -setup -phases "WNS" with this PR cannot resolve your issue, please let us know. We can find another solution (e.g., another TNS stagnation checking logic, apply multi-threading for faster runtime at the expense of small QoR loss, ...).

Do I have to configure something or change options?

The change I made originally would do this without configuration, which is important for the automated design space exploration and I think a better user experience overall.

@jhkim-pii

jhkim-pii commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

@oharboe To use the WNS phase, you should change option.

Default phases:

  • repair_timing -setup ...
  • It runs two phases "LEGACY LAST_GASP".
  • Stop if TNS enhancement is small.

WNS phase:

  • repair_timing -setup -phases "WNS"...
  • It runs one phase "WNS".
  • Stop if WNS enhancement is small (by this PR changes). No TNS monitoring.

Default phases vs. WNS phase

  • This chart shows the stop timings in repair_setup_hopeless.tcl regression
  • Not that much differences.
  • 0.1 is the minimum granularity. So the TNS chart shows step graphs.
image

In your design, how many iterations are executed until the termination by no TNS improvement?

@oharboe

oharboe commented May 6, 2026

Copy link
Copy Markdown
Collaborator

@jhkim-pii Can we change the naming of the options to describe intent of the user instead of instructing repair_timing what to do?

@jhkim-pii

Copy link
Copy Markdown
Contributor

@jhkim-pii Can we change the naming of the options to describe intent of the user instead of instructing repair_timing what to do?

Could you please give an example?

I guess you may want this.

  repair_timing -setup -goal wns            // Try to achieve the best WNS. Do not care TNS
  repair_timing -setup -goal tns             // Try to achieve the best TNS
  repair_timing -setup -goal runtime     // Fast runtime by allowing QoR loss
  ...

@oharboe

oharboe commented May 7, 2026

Copy link
Copy Markdown
Collaborator

How about using last gasp?

I want best WNS but -skip_last_gasp and a new -skip_stagnation_check

Or do we need to distinguish between -skip_last_gasp and -skip_stagnation_check?

I'm not into the details enough to judge.

@oharboe

oharboe commented May 7, 2026

Copy link
Copy Markdown
Collaborator

I asked Gemini for some help to say something about this PR because I'm not up to speed on all the concerns. It was helpful for me, so I thought I would share.

Overview

The logic introduced in PR #10284 (and #10248) represents a fundamental departure from traditional EDA principles. While the intent is to improve "No-Human-In-Loop" autonomy, the implementation creates a "weird" entanglement of physical constraints, heuristic proxies, and resource management that violates the Principle of Least Astonishment (POLA).


1. The Category Error: WNS vs. TNS

The PR treats WNS (Worst Negative Slack) and TNS (Total Negative Slack) as interchangeable signals for optimization "progress." In physical design, they serve entirely different masters:

  • WNS is a Physical Constraint: It is binary. If WNS < 0, the silicon does not work at the target frequency. It is the "Hard Truth."
  • TNS is an Economic Proxy: It represents "Closure Debt." High TNS predicts a future penalty in area, power, and congestion (due to required buffering). It is a "Heuristic Gradient."

The Problem: Using TNS "stagnation" to kill a process that might still be improving WNS is logically flawed. A designer may be perfectly willing to spend 2 hours of runtime to fix the final 10ps of WNS on a single critical path, even if 10,000 other non-critical paths (TNS) haven't moved an inch.


2. Orthogonality: Runtime is a Budget, Not a Goal

Runtime capping and optimization goals are orthogonal concerns.

  • Optimization Goal: "Make the chip meet timing."
  • Resource Constraint: "Don't take more than 30 minutes."

By baking "stagnation detection" and "runtime timeouts" directly into the resizer's internal logic, the tool is making executive decisions on behalf of the user without transparency.

  • If a tool stops, it should be because it reached the goal or the user-defined budget was hit.
  • Stopping because the tool "felt" like it wasn't making enough progress on a secondary KPI (TNS) is unpredictable behavior.

3. Cognitive Load and the "Stunned" User

The proliferation of "if/then/else" logic regarding when to stop or pivot increases the cognitive load to a breaking point. When a tool exposes its internal heuristics as configurable knobs, it shifts the burden of understanding from the developer to the designer.

  • Decision Fatigue: When faced with a "bizillion" options (TNS weightings, stagnation thresholds, runtime caps), users stop caring. They default to the "black box" and lose the ability to debug the result when it fails.
  • Implementation Leakage: This PR is a case of implementation details (how the code manages its own loops) leaking into the user interface.

4. Guidance for a Better Product Approach

To align with industry-standard expectations and minimize user "stunning," the following changes are recommended:

  1. Decouple Intent from Implementation: Replace internal thresholds with user-facing Effort Profiles (e.g., set_optimization_effort -level [exploratory|standard|signoff]).
  2. Explicit Budgeting: If runtime must be capped, use an explicit -time_limit flag. Don't hide it behind a stagnation heuristic.
  3. Transparent Exits: When the tool exits early, the log must state the exact reason (e.g., "Exiting: TNS stagnation detected. WNS remains at -50ps. Suggest floorplan modification.").
  4. Prioritize the Physical: Never allow TNS stagnation to preempt a WNS-improving run unless explicitly instructed by a "Fast/Exploratory" mode.

Conclusion

PR #10284 attempts to solve a performance problem by introducing an "Uncanny Valley" of automation—where the tool acts "smart" but in a way that is opaque and technically inconsistent. For OpenROAD to be a professional-grade tool, it must respect the distinction between physical requirements (WNS) and resource budgets (Runtime).

@jhkim-pii

jhkim-pii commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

@oharboe
Gemini's answer broadens the scope of the discussion (e.g., effort level, -time_limit, ...).

I want to focus on this.

Needs

  • It looks like you want to consider both WNS and TNS, and want early stop feature when there is no substantial improvement of WNS and TNS.
  • WNS improvement typically occurs with TNS improvement, which means that early stop is needed if TNS improvement becomes small
  • Thus, monitoring TNS stagnation is sufficient. No need to monitor WNS stagnation if TNS improvement is needed.
  • WNS stagnation checker is meaningful when WNS is the only focus (TNS is out of focus).
  • Therefore, if you want to consider both WNS and TNS, WNS stagnation checker is not needed.
    - So let's discuss about the TNS stagnation checker for early termination.

Please correct me if I misunderstood anything.

Prerequisite: Optimization iteration loop

  • Default phases = LEGACY + LAST_GASP
  • Optimization iteration loop (same for LEGACY and LAST_GASP phase)
RepairSetup::repairSetup_Legacy() or repairSetup_LastGasp()
  ...
  violator_collector_->init(setup_slack_margin);   // Gather violated endpoints

  while (violator_collector_->hasMoreEndpoints()) {  // Loop until all violated endpoints are visited
    violator_collector_->advanceToNextEndpoint();
    sta::Vertex* end = violator_collector_->getCurrentEndpoint();

    while (pass <= max_passes) {    // pass means a repairEndpoint() attempt within the selected endpoint
      opto_iteration++;      // iteration means a single repairEndpoint() attempt
      
      terminationCheckLogic   // early termination if TNS improvement is less than threshold for 2 x 100 iterations

      ...
      repairEndpoint(end->pin(), ...);
      ...
    }
  }
  • Note that a single iteration means a single repairEndpoint() attempt.

Existing TNS stagnation checker

There is such TNS stagnation checking logic already (regardless of this PR).

  1. No early termination for the initial 1000 iterations.
  2. After 1000 iterations, TNS improvement is checked with a threshold for each 100 iterations.
  3. If there is no TNS improvement for two consecutive 100 iterations (= 200 iterations), terminate early.

repair_setup_hopeless.tcl example

For the default phases (LEGACY + LAST_GASP), repair_setup_hopeless.tcl is executed as follows.

Early termination decision history

Iteration 1249: LEGACY phase finished after visiting all the violated endpoint (= no early termination)
Iteration 1250: LAST_GASP begins
Iteration 1350: 100 iterations passed in LAST_GASP. First TNS no-improvement checkpoint.
Iteration 1450: Second TNS no-improvement checkpoint. No TNS improvement for 200 iterations --> Early termination!!

TNS improvement decision threshold history

Initial TNS = -83.6
Iteration 0~999: TNS = -83.6 -> -83.3, threshold = 0.01% (0.00836)

  • Initial threshold value is 0.01% (= 0.00836).
  • Actual TNS improvement is -0.3 // TNS improvement > threshold --> No early termination

Iteration 1000: TNS = -83.3, threshold = 0.01% -> 0.02% (0.01672)

  • Threshold grows by 2x for each 1000 iteration.
  • TNS is improved more than the threshold.

Iteration 1249: LEGACY phase finished. TNS = -83.2, threshold = 0.02%
Iteration 1250: LAST_GASP phase begins. TNS = -83.2, threshold = 0.01% (Reset to the initial value)
Iteration 1350: TNS = -83.2 -> -83.2, threshold = 0.01%. --> No TNS improvement for 100 iteration (1st trigger)
Iteration 1450: TNS = -83.2 -> -83.2, threshold = 0.01%. --> No TNS improvement for 100 iteration (2nd trigger)
--> Early termination!!!

My questions

You said that some designs took long runtime w/ small TNS twitches.
How many iterations the design used? At what iteration do you want to stop early?

  • If you want to reduce the runtime, using a larger initial TNS improvement threshold (e.g., 0.1%) can be a solution. Note that current initial threshold is 0.01%.

If you want to monitor the both WNS and TNS, this PR is not needed. Possibly, the threshold tuning is enough.
If you want to monitor the WNS only and ignore TNS, this PR can help. But -phases WNS option is needed because the default behavior is to monitor TNS stagnation.

@oharboe

oharboe commented May 7, 2026

Copy link
Copy Markdown
Collaborator

@jhkim-pii I think I owe you a test case, I will see about sharing one privately. Would that be the best way forward? I don't have specific recommendations, Claude hacked away at my problem and tried to come up with something that a) fixed my problem b) didn't break anything.

However, as we often find: better to provide a test case...

Thoughts?

@jhkim-pii

Copy link
Copy Markdown
Contributor

@jhkim-pii I think I owe you a test case, I will see about sharing one privately. Would that be the best way forward? I don't have specific recommendations, Claude hacked away at my problem and tried to come up with something that a) fixed my problem b) didn't break anything.

However, as we often find: better to provide a test case...

Thoughts?

Yeah. Sharing the problematic test case will make things clear.
Also, please share the current long runtime and the desired runtime.

@jhkim-pii jhkim-pii changed the title rsz: update failing test golden on PR 10248 (Discarded) rsz: WNS stagnation logic enhancement based on PR 10248 Jun 29, 2026
@jhkim-pii

Copy link
Copy Markdown
Contributor

The root-cause was fixed by #10571.

@jhkim-pii jhkim-pii closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants