Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions src/rsz/src/RepairSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ bool RepairSetup::repairSetup(const float setup_slack_margin,

float initial_tns = sta_->totalNegativeSlack(max_);
float prev_tns = initial_tns;
// Capture the initial WNS once per repair_timing call; the WNS-stagnation
// gate scales its threshold against |initial_wns_|.
initial_wns_ = sta_->worstSlack(max_);
max_end_repairs_
= violator_collector_->getMaxEndpointCount() * repair_tns_end_percent;
max_end_repairs_ = std::max(max_end_repairs_, 1);
Expand Down Expand Up @@ -982,9 +985,42 @@ void RepairSetup::printProgressFooter() const
"---------------------------------------------------------------");
}

void RepairSetup::resetStagnationTracking()
{
// Initialize best_wns_ to the most-negative finite float so the very first
// worstSlack() sample always wins the max().
best_wns_ = std::numeric_limits<float>::lowest();
wns_stagnation_tripped_ = false;
wns_stagnation_iteration_ = 0;
}

std::string RepairSetup::wnsStagnationReport(const int iteration) const
{
if (!wns_stagnation_tripped_) {
return {};
}
const int digits = 3;
return fmt::format(
"repair_timing: obviously futile - WNS only reached {} after {} passes "
"(initial {}, improvement {}). This is probably an exploration run, "
"not a timing closure run. Aborting with best-effort result.",
delayAsString(best_wns_, digits, sta_),
wns_stagnation_iteration_,
delayAsString(initial_wns_, digits, sta_),
delayAsString(best_wns_ - initial_wns_, digits, sta_));
}

// Terminate progress if incremental fix rate within an opto interval falls
// below the threshold. Bump up the threshold after each large opto
// interval.
// A second, independent "WNS-stagnation" gate also returns true when, after
// the warmup, the best-so-far WNS has failed to improve by a deterministic
// threshold relative to the initial WNS. That detects designs where WNS
// essentially never moves from its starting value — the real signature of
// an "obviously futile" run. Plateaus on legitimate designs (WNS drops by
// orders of magnitude early, then flat-lines while TNS keeps improving) do
// not trip this gate, because best_wns_ has already moved far from
// initial_wns_ by the time the plateau starts.
bool RepairSetup::terminateProgress(const int iteration,
const float initial_tns,
float& prev_tns,
Expand All @@ -995,6 +1031,36 @@ bool RepairSetup::terminateProgress(const int iteration,
const char* phase_name,
const char phase_marker)
{
// WNS-stagnation gate. Sampled every call so the "best so far" tracker
// advances at the same rate as the caller's inner loop (deterministic).
best_wns_ = std::max(best_wns_, sta_->worstSlack(max_));
if (iteration > wns_stagnation_warmup_iterations_) {
const float threshold
= std::max(wns_stagnation_abs_tol_,
wns_stagnation_rel_tol_ * std::fabs(initial_wns_));
if (best_wns_ - initial_wns_ < threshold) {
debugPrint(logger_,
RSZ,
"repair_setup",
1,
"{}{} Phase: Exiting at iteration {} because WNS best-so-far "
"{} only improved {} from initial {} (threshold {}) "
"[endpoint {}/{}]",
phase_name,
phase_marker,
iteration,
delayAsString(best_wns_, 3, sta_),
delayAsString(best_wns_ - initial_wns_, 3, sta_),
delayAsString(initial_wns_, 3, sta_),
delayAsString(threshold, 3, sta_),
endpt_index,
num_endpts);
wns_stagnation_tripped_ = true;
wns_stagnation_iteration_ = iteration;
return true;
}
}

if (iteration % opto_large_interval_ == 0) {
fix_rate_threshold *= 2.0;
}
Expand Down Expand Up @@ -1070,6 +1136,7 @@ void RepairSetup::repairSetup_Legacy(const float setup_slack_margin,
bool two_cons_terminations = false;
printProgress(opto_iteration, false, false, phase_marker);
float fix_rate_threshold = inc_fix_rate_threshold_;
resetStagnationTracking();

const auto& violating_ends = violator_collector_->getViolatingEndpoints();
min_viol_ = -violating_ends.back().second;
Expand Down Expand Up @@ -1340,6 +1407,10 @@ void RepairSetup::repairSetup_Legacy(const float setup_slack_margin,
"LEGACY{} Phase: Exiting due to no TNS progress "
"for two opto cycles",
phase_marker);
const std::string wns_msg = wnsStagnationReport(opto_iteration);
if (!wns_msg.empty()) {
logger_->info(RSZ, 234, "{}", wns_msg);
}
break;
}
} // for each violating endpoint
Expand Down Expand Up @@ -1453,6 +1524,7 @@ void RepairSetup::repairSetup_Wns(const float setup_slack_margin,

overall_no_progress_count_ = 0;
float fix_rate_threshold = inc_fix_rate_threshold_;
resetStagnationTracking();
constexpr int max_no_progress = 4;
const int phase1_start_iteration = opto_iteration;
bool journal_open = false;
Expand Down Expand Up @@ -1654,6 +1726,10 @@ void RepairSetup::repairSetup_Wns(const float setup_slack_margin,
"WNS{} Phase: No TNS progress for {} cycles, exiting",
phase_marker,
overall_no_progress_count_);
const std::string wns_msg = wnsStagnationReport(opto_iteration);
if (!wns_msg.empty()) {
logger_->info(RSZ, 235, "{}", wns_msg);
}
break;
}
}
Expand Down Expand Up @@ -2904,6 +2980,7 @@ void RepairSetup::repairSetup_LastGasp(const OptoParams& params,
bool prev_termination = false;
bool two_cons_terminations = false;
float fix_rate_threshold = inc_fix_rate_threshold_;
resetStagnationTracking();

while (violator_collector_->hasMoreEndpoints()) {
if (max_iterations > 0 && opto_iteration >= max_iterations) {
Expand Down Expand Up @@ -3075,6 +3152,10 @@ void RepairSetup::repairSetup_LastGasp(const OptoParams& params,
"LAST_GASP{} Phase: No TNS progress for two opto cycles, "
"exiting",
phase_marker);
const std::string wns_msg = wnsStagnationReport(opto_iteration);
if (!wns_msg.empty()) {
logger_->info(RSZ, 236, "{}", wns_msg);
}

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.

logger_->info(...) call in every caller site.
It would be better to move the logger_->info(...) call within wnsStagnationReport().
Then wnsStagnationReport() does not require the argument and string return.

break;
}
} // for each violating endpoint
Expand Down
35 changes: 35 additions & 0 deletions src/rsz/src/RepairSetup.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -141,6 +142,11 @@ class RepairSetup : public sta::dbStaState
int num_endpts,
const char* phase_name,
char phase_marker);
// Reset the per-phase WNS-stagnation ring buffer.
void resetStagnationTracking();
// Return the info-log message for a phase-level abort caused by the
// WNS-stagnation gate (empty if that gate did not fire).
std::string wnsStagnationReport(int iteration) const;
Comment thread
oharboe marked this conversation as resolved.
Resolved
bool swapVTCritCells(const OptoParams& params, int& num_viols);
void traverseFaninCone(sta::Vertex* endpoint,
std::unordered_map<sta::Instance*, float>& crit_insts,
Expand Down Expand Up @@ -245,6 +251,35 @@ class RepairSetup : public sta::dbStaState
static constexpr float inc_fix_rate_threshold_
= 0.0001; // default fix rate threshold = 0.01%
static constexpr int max_last_gasp_passes_ = 10;

// WNS-stagnation gate. Compares the best-so-far WNS against the WNS
// captured at the start of repair_timing (initial_wns_). If after the
// warmup the best WNS has improved by less than
// max(wns_stagnation_abs_tol_, wns_stagnation_rel_tol_ * |initial_wns_|),
// terminateProgress() returns true. "No improvement from initial" is the
// real signature of an obviously-futile design; plateaus on legitimate
// designs (WNS bottoms out at a topology limit while TNS keeps
// improving) are *not* caught, because best_wns_ has already moved far
// from initial_wns_. Deterministic (iteration-count based, no wallclock).
static constexpr float wns_stagnation_abs_tol_ = 1.0e-12f; // 1 ps
Comment thread
oharboe marked this conversation as resolved.
Resolved
// 5% of |initial_wns|. Empirically: aes improves WNS by ~50%, clone_flat
// by ~95%, repair_fanout by ~90% of initial; the hopeless.v synthetic only
// moves WNS by ~2% because buffer insertion on a grossly-over-clocked
// design still chips off a little. 5% sits safely in that gap.
static constexpr float wns_stagnation_rel_tol_ = 0.05f;
// Warmup: skip the gate until this many passes have elapsed, so normal
// repair progress on ordinary designs is not short-circuited.
static constexpr int wns_stagnation_warmup_iterations_ = 1000;

sta::Slack initial_wns_ = 0;
// Best (largest / least-negative) WNS observed since the most recent
// resetStagnationTracking(). Reset at the start of each repair phase.
sta::Slack best_wns_ = 0;
// Set by terminateProgress() when the WNS-stagnation gate fires. Consumed
// by the phase-level abort sites to emit a loud info log. Reset by
// resetStagnationTracking().
bool wns_stagnation_tripped_ = false;
int wns_stagnation_iteration_ = 0;
};

} // namespace rsz
1 change: 1 addition & 0 deletions src/rsz/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ TESTS = [
"repair_setup8",
"repair_setup9",
"repair_setup9_hier",
"repair_setup_hopeless",
"repair_setup_sizedown",
"repair_setup_sizeup_match",
"repair_setup_undo1",
Expand Down
1 change: 1 addition & 0 deletions src/rsz/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ or_integration_tests(
repair_hold14
repair_hold15
repair_hold_multi_output_load
repair_setup_hopeless
repair_setup_sizedown
repair_setup_sizeup_match
repair_setup1
Expand Down
16 changes: 16 additions & 0 deletions src/rsz/test/repair_setup_hopeless.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[INFO ODB-0227] LEF file: Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells
[INFO RSZ-0100] Repair move sequence: SizeUpMove
[INFO RSZ-0094] Found 1200 endpoints with setup violations.
[INFO RSZ-0099] Repairing 1200 out of 1200 (100.00%) violating endpoints...
Iter | Removed | Resized | Inserted | Cloned | Pin | Area | WNS | StTNS | EnTNS | Viol | Worst
| Buffers | Gates | Buffers | Gates | Swaps | | | | | Endpts | St/EnPt
------------------------------------------------------------------------------------------------------------------------------
0* | 0 | 0 | 0 | 0 | 0 | +0.0% | -0.142 | -170.6 | -170.6 | 1200 | dst0/D
1* | 0 | 0 | 0 | 0 | 0 | +0.0% | -0.142 | -170.6 | -170.6 | 1200 | dst0/D
[INFO RSZ-0234] repair_timing: obviously futile - WNS only reached -0.142 after 1002 passes (initial -0.142, improvement 0.000). This is probably an exploration run, not a timing closure run. Aborting with best-effort result.
1002* | 0 | 0 | 0 | 0 | 0 | +0.0% | -0.142 | -170.6 | -170.6 | 1200 | dst0/D
[INFO RSZ-0236] repair_timing: obviously futile - WNS only reached -0.142 after 1004 passes (initial -0.142, improvement 0.000). This is probably an exploration run, not a timing closure run. Aborting with best-effort result.
final | 0 | 0 | 0 | 0 | 0 | +0.0% | -0.142 | -170.6 | -170.6 | 1200 | dst0/D
------------------------------------------------------------------------------------------------------------------------------
[WARNING RSZ-0062] Unable to repair all setup violations.
worst slack max -0.14
63 changes: 63 additions & 0 deletions src/rsz/test/repair_setup_hopeless.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# repair_timing on a hopelessly under-clocked design must terminate
# without grinding through the entire endpoint list one futile pass at a
# time. The block below has many independent register-to-register pairs,
# a clock period below clk-to-Q + setup, and dont_use + skip_* tuned so
# no move can improve WNS. Without the WNS-stagnation gate, repair_timing
# walks the whole 1200-endpoint list; with the gate it exits shortly
# after the warmup. The .ok pins the bounded behaviour.

source "helpers.tcl"
read_liberty Nangate45/Nangate45_typ.lib
read_lef Nangate45/Nangate45.lef

set db [ord::get_db]
set tech [$db getTech]
set chip [odb::dbChip_create $db $tech]
set block [odb::dbBlock_create $chip top]
$block setDefUnits 2000
set m1 [$tech findLayer metal1]
set dff [$db findMaster DFF_X2]
set dff_d [$dff findMTerm D]
set dff_q [$dff findMTerm Q]
set dff_ck [$dff findMTerm CK]

set clk_net [odb::dbNet_create $block clk]
set clk_bt [odb::dbBTerm_create $clk_net clk]
$clk_bt setIoType INPUT
set bp [odb::dbBPin_create $clk_bt]
odb::dbBox_create $bp $m1 0 0 100 100
$bp setPlacementStatus LOCKED

set num_pairs 1200
for { set i 0 } { $i < $num_pairs } { incr i } {
set y [expr { $i * 2000 }]
set src [odb::dbInst_create $block $dff "src$i"]
$src setLocation 0 $y
$src setPlacementStatus LOCKED
[$src getITerm $dff_ck] connect $clk_net
set dst [odb::dbInst_create $block $dff "dst$i"]
$dst setLocation 2000 $y
$dst setPlacementStatus LOCKED
[$dst getITerm $dff_ck] connect $clk_net
set n [odb::dbNet_create $block "n$i"]
[$src getITerm $dff_q] connect $n
[$dst getITerm $dff_d] connect $n
}
ord::design_created

create_clock -period 0.001 clk
source Nangate45/Nangate45.rc
set_wire_rc -layer metal3
estimate_parasitics -placement

# DFF_X2 is the largest DFF in Nangate45; with everything but _X1/_X2
# off-limits, SizeUpMove has nothing to size up.
foreach lib_cell [get_lib_cells *] {
if { ![regexp {_X[12]$} [get_name $lib_cell]] } {
set_dont_use $lib_cell
}
}

repair_timing -setup -skip_buffer_removal -skip_pin_swap -skip_gate_cloning \
-skip_buffering
report_worst_slack -max
52 changes: 52 additions & 0 deletions test/orfs/hopeless/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
load("@bazel-orfs//:sweep.bzl", "orfs_sweep")
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//test/orfs:check_same.bzl", "check_same")

package(features = ["layering_check"])

orfs_sweep(
name = "hopeless",
# buildifier: disable=unsorted-dict-items
arguments = {
"CORE_AREA": "2.16 2.16 45.36 45.36",
"DIE_AREA": "0 0 47.52 47.52",
"PLACE_DENSITY": "0.50",
# Clock period far below what the 8-lane × 8-deep add/xor chain can
# ever meet. This is the whole point of the test: the flow must bail
# on an obviously-infeasible target without grinding forever.
"ABC_CLOCK_PERIOD_IN_PS": "50.0",
},
sources = {
"RULES_JSON": [":rules-base.json"],
"SDC_FILE": [":constraint.sdc"],
},
stage = "final",
sweep = {
"b": {},
"base": {},
},
tags = ["manual"],
test_kwargs = {
"tags": ["orfs"],
},
verilog_files = ["hopeless.v"],
)

check_same(
name = "hopeless_idempotent_test",
flow = "hopeless",
tags = ["orfs"],
variant_a = "base",
variant_b = "b",
)

# Asserts the WNS-stagnation gate actually fired on this infeasible design.
# Without this, the flow could "pass" simply because some other termination
# mechanism stopped repair_timing, and the real gate would quietly bit-rot.
sh_test(
name = "hopeless_stagnation_test",
srcs = ["check_stagnation.sh"],
args = ["$(locations :hopeless_base_logs)"],
data = [":hopeless_base_logs"],
tags = ["orfs"],
)
19 changes: 19 additions & 0 deletions test/orfs/hopeless/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hopeless

Regression test for the WNS-stagnation gate in `repair_timing`
(`src/rsz/src/RepairSetup.cc`).

The design is a deliberately deep combinational chain clocked impossibly fast
(see `constraint.sdc` + `ABC_CLOCK_PERIOD_IN_PS` in `BUILD`). With the old
defaults, `repair_timing` would grind forever producing tiny TNS twitches
without moving WNS. With the gate, the phase aborts deterministically after
~1200 iterations of no WNS movement and logs `repair_timing: WNS stuck at ...`.

The test asserts only that the flow completes within the bazel timeout.
QoR is intentionally unchecked — the point is bounded runtime and determinism.

Run:

```
bazelisk test //test/orfs/hopeless:hopeless_final_base_test
```
Loading
Loading