Skip to content

mpl: Improve macro-placer simulated annealing robustness and packing quality - #12098

Open
erendn wants to merge 5 commits into
The-OpenROAD-Project:masterfrom
erendn:mpl_annealer_robustness
Open

erendn wants to merge 5 commits into
The-OpenROAD-Project:masterfrom
erendn:mpl_annealer_robustness

Conversation

@erendn

@erendn erendn commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

This improves mpl (HierRTLMP) simulated annealing robustness, packing quality, and determinism across cluster placement (SACoreSoftMacro) and hard macro placement (SACoreHardMacro):

  1. Per-Move Evaluation, -random_seed, and Diagnostic MPL-0003:
  • Refactors SimulatedAnnealingCore::perturb() so every candidate move (packFloorplan(), singleSeqSwap(), doubleSeqSwap(), resizeOneCluster()) immediately calls packFloorplan(), keeping macro coordinates and width_/height_ synchronized with the Sequence Pair after every perturbation.
  • Replaces the single-solution results_saved_ overwrite with true best-ever best_result_ tracking (best_cost_, best_pre_cost_, best_norm_*, best_seq_, best_macros_) updated whenever a valid/improved state is discovered and restored via useBestResult().
  • Adds -random_seed (default 1) to rtl_macro_placer to thread deterministic base seeds across all SA workers without static RNG state, ensuring repeatable back-to-back runs within a single OpenROAD session.
  • Expands MPL-0003 (SACoreSoftMacro::printResults()) to report exact cluster area vs. outline area (in $\mu\text{m}^2$) and excess percentage on failure.
  1. CP-SAT Packing Oracle & Annealer Test Harness:
  • Adds an exact OR-Tools CP-SAT 2D non-overlapping rectangle packing oracle (PackingOracle, //src/mpl/test:mpl_packing_oracle) with disjunctive interval constraints and a fast deadspace pre-filter.
  • Adds a 60-instance deterministic packing corpus (src/mpl/test/testcases/packing_corpus.txt) and GTest suites (mpl_annealer_core_unittest, mpl_annealer_packing_unittest).
  1. Relative Cooling Schedule, Patience Early-Stopping, and Incremental Wirelength:
  • Replaces the step-based geometric cooling schedule with a relative progress-based geometric cooling schedule ($T(s) = T_{\text{init}} \cdot (T_{\text{min}} / T_{\text{init}})^{s/N}$) and bounded stagnation/patience early-stopping ($\max(500, \lceil 0.25 \cdot N \rceil)$ steps) gated on outline validity.
  • Adds an $O(\text{incident nets})$ incremental wirelength delta cache (NetEndpointEntry, macro_to_nets_, cached_net_hpwl_) for swap and resize moves while keeping centralized full-recomputation verification in calNormCost().
  1. Multi-Seed Cluster Placement, Fallback Recovery, and Common-Cost Candidate Selection:
  • Expands HierRTLMP::runCoarseShaping() tilings with exact deadspace-free bounding boxes ($\sum A_i$) when child shapes have zero deadspace.
  • Replaces the single-run placeMacro retry loop in HierRTLMP::updateMacroClusters() with a deterministic OpenMP parallel multi-seed sweep across valid utilization indices and 3 deterministic seeds per index, plus a two-stage high-budget fallback (2x steps with 1.5x outline penalty, then 4x steps with 2.0x outline penalty) when no outline-valid placement is found.
  • Adds selectBestCandidateByCommonCost() so candidate SA workers with heterogeneous per-worker normalization baselines (norm_area_penalty_, norm_wl_, norm_guidance_cost_, norm_fence_cost_, norm_ macro_blockage_cost_, norm_notch_cost_) are compared on a unified common normalization baseline rather than raw per-worker normalized costs.

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation update

Impact

  • CLI / Tcl: Adds optional -random_seed integer argument (default 1) to rtl_macro_placer. Existing scripts run unchanged.
  • Determinism: Calling rtl_macro_placer multiple times in the same OpenROAD session now produces identical placements (//src/mpl/test:rerun1-tcl_test).
  • Diagnostics: MPL-0003 now prints cluster area vs. outline area in $\mu\text{m}^2$ and excess percentage; adds MPL-0081, MPL-0082, and MPL-0083 for -random_seed validation and fallback recovery reporting.
  • QoR & Runtime:
    • Improves packing feasibility on the 60-instance CP-SAT feasible benchmark corpus (mpl_annealer_packing_unittest) to 95.0% (SACoreHardMacro) and 91.7% (SACoreSoftMacro).
    • Across 16 macro-containing designs in OpenROAD-flow-scripts (asap7, gf180, ihp-sg13g2, nangate45, sky130hd, sky130hs), mpl completes with 0 errors, reduces mean mpl runtime by ~41% via patience early-stopping and incremental wirelength evaluation, and reduces post-MPL macro HPWL by up to 27.6% (nangate45/mempool_group) and 19.7% (nangate45/bp_fe).

Verification

  • I have verified that the local build succeeds (./etc/Build.sh).
  • I have run the relevant tests and they pass.
  • My code follows the repository's formatting guidelines.
  • I have included tests to prevent regressions.
  • I have signed my commits (DCO).

Related Issues

#11807

- Save and restore movable macro state in pre-allocated member buffers
  in SACoreSoftMacro and SACoreHardMacro, preserving int64_t area_
  bit-identically after setWidth, setHeight, or resizeRandomly with
  zero per-move allocations.
- Replace O(n^2) prefix-maximum packing in
  SimulatedAnnealingCore::packFloorplan with an O(n log n)
  prefix-maximum Fenwick tree and backward Y pass using pre-allocated
  buffers.
- Reuse pre-allocated member buffers in
  SACoreSoftMacro::fillCoordsLists and calNotchPenalty, and precompute
  nets_weight_sum_ and flat IO cluster constraints in
  SimulatedAnnealingCore.
- Report macro area as a percentage of outline area in MPL-0003 when
  no valid tilings are found.
- Expose -random_seed <seed> on rtl_macro_placer and add unit/Tcl
  tests.

Signed-off-by: Eren Dogan <erendogan@google.com>
- Add testonly packing_oracle library (PackingOracle.h,
  PackingOracle.cpp) using OR-Tools CP-SAT AddNoOverlap2D with fixed
  intervals, discrete shape literals, and floor-division bounds
  (A - w < w * h <= A) for soft macros.
- Add packing problem text serializer/deserializer and benchmark
  corpus (testcases/packing_corpus.txt).
- Implement SoftPackingHarness and HardPackingHarness inverse adapters
  and mpl_annealer_packing_unittest.

Signed-off-by: Eren Dogan <erendogan@google.com>
- Expose -anneal_end_acceptance <p> and -anneal_patience <f> on
  rtl_macro_placer with range validation (MPL-0081, MPL-0082) and
  per-session reset.
- Derive min_t from init_temperature_ and anneal_end_acceptance_ so
  geometric cooling spans a fixed number of acceptance-probability
  decades, and stop early after t_freeze when best_step stalls for
  ceil(f * max_num_step_) steps.
- Track is_best_result_valid_ in SimulatedAnnealingCore and restore
  both widths and heights in SACoreSoftMacro::useBestResult.
- Maintain a macro-to-net adjacency index for incremental
  O(|touched_nets|) wirelength updates when at most half of the
  movable macros move.

Signed-off-by: Eren Dogan <erendogan@google.com>
- Add copyNormalizationFactorsFrom, setWeights, and
  selectBestCandidateByCommonCost to compare candidate annealers under
  a shared normalization baseline and common SACoreWeights.
- Expose -placement_seeds <N> on rtl_macro_placer (MPL-0083) to run N
  seeds per utilization level in HierRTLMP::placeChildren in
  deterministic thread batches and rank valid candidates in
  placeChildren and placeMacros by common cost.
- Add unit tests and Tcl regression checks for multi-seed selection
  and thread-count determinism.

Signed-off-by: Eren Dogan <erendogan@google.com>
@erendn
erendn requested a review from a team as a code owner November 2, 2026 21:18
@erendn
erendn requested a review from joaomai November 2, 2026 21:18
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@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 several enhancements to the macro placer, including an O(n log n) Fenwick tree-based floorplan packing algorithm, incremental wirelength calculations, relative cooling schedules, and multi-seed simulated annealing with common-cost candidate selection. It also exposes new parameters (-random_seed, -anneal_end_acceptance, -anneal_patience, and -placement_seeds) to the Tcl interface and adds comprehensive unit tests. A critical issue was identified in runSingleSeedClusterPlacement where run_id is never incremented, which prevents the exploration of higher utilization levels when running with fewer threads.

Comment thread src/mpl/src/hier_rtlmp.cpp Resolved
@oharboe

oharboe commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@joaomai I added a CP SAT solver too to have a ground truth... It adds code and perhaps not part of production code, but this is the second time someone found CP SAT ground truth useful for evaluation RTL MP.

Signed-off-by: Eren Dogan <erendogan@google.com>
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.

2 participants