From b1a5914029ea4951ddcf187ca6f0f20599b5d5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 10:41:23 +0200 Subject: [PATCH 01/11] flow: E12 clustered global-place scorer for macro-placement selection (draft) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A macro placement is a draw from a distribution, not an optimum. Seeding RTL-MP on asap7 swerv_wrapper gives 24 placements whose downstream macro-path timing spans ~300ps, and the placer's own annealing cost cannot tell which is which -- it predicts area, not period. Selection therefore needs a score measured after the fact. The established one is a fast non-timing-driven global placement over every standard cell (the "flat" rung), which ranks the ground truth -- macro-path mean at global route, after the entire production tail -- at Spearman rho +0.72 [0.48, 0.84]. E12 asks whether that placement can run on RTL-MP's own std-cell clusters instead, roughly an order of magnitude fewer movables, and still rank. Ranking accuracy is the only requirement: a scorer that is uniformly optimistic ranks perfectly, so rank inversions are the enemy and absolute error never was. One pre-registered criterion decides it: rho(clustered) must land inside the flat rung's interval on the macro-path KPI. A failing verdict is the deliverable just as much as a passing one -- since the truth includes repair/CTS/route, rho(clustered) minus rho(flat) *is* the measured price of the abstraction. It turns out both halves already exist in OpenROAD, so nothing here implements a field solver -- deliberately, because the thing being graded has to be the solver that would ship, not a model of it: placement_cluster {inst ...} makes N instances one movable, and gpl measures pin offsets against the cluster centre, so intra-cluster nets collapse and inter-cluster nets are measured centre-to-centre -- bundled nets, free global_placement -overflow stops the Nesterov solve early rtl_macro_placer -keep_clustering_data commits the cluster tree to odb as dbGroups that gpl ignores The score is half-perimeter wirelength read out of odb in exact integer DBU (dbNet::getTermBBox), so it needs no OpenROAD change and is thread-count invariant by construction rather than by discipline. Scoring is report-only: one candidate per process, because gpl's Replace::reset() does not clear its cluster list and gpl does write GCell locations back. Three steps plus a gate, all under flow/test/macro_e12: macro_e12.tcl regenerate the 24 candidates and re-measure them flat. The candidate placements were never archived, only their scores, so this is also the rig check: until the regenerated flat scores reproduce the archive, any clustered number is measuring the rig. dump_clusters.tcl RTL-MP's cluster partition, once, from the shared base floorplan -- via ORFS's own macro_place stage, so the partition is the one production RTL-MP builds. score_clustered.tcl the clustered rung, plus a free second readout over the macro cone only. grade_e12.py rho + bootstrap CI per KPI, and the verdict. Deriving the coarsening once and sharing it across candidates is not only a saving: every candidate is then scored through the identical distortion, and common-mode distortion does not create rank inversions. A partition re-derived per candidate would, and must not be used. The five carried OpenROAD patches make the population generatable at all -- seedable (0002), re-entrant (0001), round-tripping (0003), injection equivalent to production (0004) -- plus a thread-invariant density scatter (0005). They come from the public bazel-orfs macro-selector branch and apply cleanly and in order at the commit the tools/OpenROAD gitlink already records, which is byte-identical in src/mpl, src/gpl, src/par and src/odb/src to the commit the archived reference numbers were measured at. Since local_path_override cannot apply patches, openroad is fetched via git_override pinned to that same commit, exactly as ORFS did while carrying the single-process flow fixes; revert to local_path_override when these land upstream. Verified: * the patched OpenROAD builds through git_override, and the four regressions the patches ship all pass -- random_seed1, macro_placement_round_trip1, all_fixed_macros1, mt_invariance01 * //flow/test/macro_e12 loads and its gate test passes, including five published numbers recomputed from the committed archive (+0.72, +0.82, +0.57, +0.65, +0.47) -- which is what pins the gate to the right column rather than a friendlier neighbouring one * every Tcl/odb/gpl API the scorer uses was probed against a real binary rather than assumed Not yet run: the campaign itself. The flow targets are tags = ["manual"] (ORFS CI does not run bazel), and the README pre-registers the configuration, the early-kill criteria and the determinism check to run before spending it. Not included, by design: rtl_macro_placer -candidates k. That belongs in OpenROAD, and it is planned only if this gate passes -- which is the entire reason the gate exists. Signed-off-by: Øyvind Harboe --- MODULE.bazel | 71 ++- flow/test/macro_e12/BUILD | 118 ++++ flow/test/macro_e12/README.md | 173 ++++++ flow/test/macro_e12/dump_clusters.tcl | 133 +++++ flow/test/macro_e12/e12_lib.tcl | 267 +++++++++ flow/test/macro_e12/e12_stats.py | 61 ++ flow/test/macro_e12/extract_lib.tcl | 186 +++++++ flow/test/macro_e12/grade_e12.py | 394 +++++++++++++ flow/test/macro_e12/grade_e12_test.py | 315 +++++++++++ flow/test/macro_e12/macro_e12.tcl | 254 +++++++++ flow/test/macro_e12/score_clustered.tcl | 240 ++++++++ flow/test/macro_e12/score_vs_flow_swerv.json | 382 +++++++++++++ .../0001-mpl-fix-rerun-segfault.patch | 45 ++ .../openroad/0002-mpl-add-random_seed.patch | 358 ++++++++++++ ...-mpl-keep-snapped-macros-inside-core.patch | 524 ++++++++++++++++++ ...seed-std-cells-when-all-macros-fixed.patch | 229 ++++++++ ...d-invariant-parallel-density-scatter.patch | 349 ++++++++++++ patches/openroad/BUILD.bazel | 9 + 18 files changed, 4105 insertions(+), 3 deletions(-) create mode 100644 flow/test/macro_e12/BUILD create mode 100644 flow/test/macro_e12/README.md create mode 100644 flow/test/macro_e12/dump_clusters.tcl create mode 100644 flow/test/macro_e12/e12_lib.tcl create mode 100644 flow/test/macro_e12/e12_stats.py create mode 100644 flow/test/macro_e12/extract_lib.tcl create mode 100644 flow/test/macro_e12/grade_e12.py create mode 100644 flow/test/macro_e12/grade_e12_test.py create mode 100644 flow/test/macro_e12/macro_e12.tcl create mode 100644 flow/test/macro_e12/score_clustered.tcl create mode 100644 flow/test/macro_e12/score_vs_flow_swerv.json create mode 100644 patches/openroad/0001-mpl-fix-rerun-segfault.patch create mode 100644 patches/openroad/0002-mpl-add-random_seed.patch create mode 100644 patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch create mode 100644 patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch create mode 100644 patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch create mode 100644 patches/openroad/BUILD.bazel diff --git a/MODULE.bazel b/MODULE.bazel index 025933432f..bcc6e41f6f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -65,11 +65,76 @@ single_version_override( version = "3.8.2.bcr.7", ) - +# openroad is normally consumed straight from the tools/OpenROAD +# submodule via local_path_override. While the E12 macro-placement +# experiment carries OpenROAD patches in //patches/openroad +# (local_path_override does not accept patches), it is fetched via +# git_override instead, pinned to the exact commit the submodule +# gitlink records so make (submodule) and bazel (fetched + patched) +# build the same base. Note that bazel builds the fetched source, not +# the live submodule tree, while this override is in place; revert to +# local_path_override when the patches land upstream. +# +# All five patches originate on the public bazel-orfs `macro-selector` +# branch (patches/0040-0043, 0045) and apply cleanly and in order at +# the pinned commit. src/mpl, src/gpl, src/par and src/odb/src are +# byte-identical between the pinned commit and OpenROAD 3ca581e38, +# which is the commit the archived swerv_wrapper measurements in +# flow/test/macro_e12/score_vs_flow_swerv.json were taken at -- that +# is what makes those numbers a valid reference here. +# +# patches/openroad/0001-mpl-fix-rerun-segfault.patch: +# HierRTLMP::run() ends with clear(), which destroys the physical +# hierarchy tree that was only ever built in the constructor, so a +# second rtl_macro_placer in one process handed a null tree to the +# clustering engine and crashed. Recreates the tree lazily. Required +# for generating many candidates in one process. +# OpenROAD issue #11277. +# +# patches/openroad/0002-mpl-add-random_seed.patch: +# adds `rtl_macro_placer -random_seed`, defaulting to the previously +# hard-coded 0 so stock behaviour is unchanged. Same seed reproduces +# the placement; different seeds explore different annealing +# trajectories. This is what turns the macro placer into a +# deterministic candidate generator instead of requiring CORE_AREA or +# cost-weight perturbation to obtain distinct placements. +# No upstream issue: a feature, to be proposed separately. +# +# patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch: +# the Snapper picked the track position closest to the pin centre, +# rounding up, which pushed top/right-edge macros past the core; +# place_macro then rejected the placer's own -write_macro_placement +# output with MPL-0034, so a selected placement could not be +# re-injected via MACRO_PLACEMENT_TCL. OpenROAD issue #11278. +# +# patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch: +# when every macro was fixed, run() skipped the whole pipeline +# including generateTemporaryStdCellsPlacement() and the macro soft +# blockages, so a re-injected placement diverged (~2% achieved +# period) from the run that generated it despite bit-identical macro +# geometry. OpenROAD issue #11279. +# +# patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch: +# BinGrid's density scatter was serial at any -threads. Parallelises +# it while accumulating into the bins' existing int64_t fields via +# std::atomic_ref with relaxed ordering: each addend is truncated to +# int64 before adding, so the sum is over a fixed multiset and is +# bit-identical at any thread count. Ships an mt_invariance +# integration test. OpenROAD PR #11262. bazel_dep(name = "openroad", dev_dependency = True) -local_path_override( +git_override( module_name = "openroad", - path = "tools/OpenROAD", + commit = "4b704bb69321203e5bf5db74182bfae9e8721d1e", + init_submodules = True, + patch_strip = 1, + patches = [ + "//patches/openroad:0001-mpl-fix-rerun-segfault.patch", + "//patches/openroad:0002-mpl-add-random_seed.patch", + "//patches/openroad:0003-mpl-keep-snapped-macros-inside-core.patch", + "//patches/openroad:0004-mpl-seed-std-cells-when-all-macros-fixed.patch", + "//patches/openroad:0005-gpl-thread-invariant-parallel-density-scatter.patch", + ], + remote = "https://github.com/The-OpenROAD-Project/OpenROAD.git", ) bazel_dep(name = "qt-bazel", dev_dependency = True) diff --git a/flow/test/macro_e12/BUILD b/flow/test/macro_e12/BUILD new file mode 100644 index 0000000000..91978716c1 --- /dev/null +++ b/flow/test/macro_e12/BUILD @@ -0,0 +1,118 @@ +"""E12: does a clustered global placement rank macro-placement candidates? + +Every flow-running target here is tags = ["manual"]: the candidate +generation is a ~25 minute job on a 24-core machine and none of it +belongs in an automatic build. The one non-manual target is the gate's +unit test, which runs in about a second on committed fixtures and needs +no OpenROAD at all. + +See README.md for the pre-registered configuration and the protocol. +""" + +load("@bazel-orfs//:openroad.bzl", "orfs_run_executable") +load("@orfs_designs//:designs.bzl", "DESIGNS") +load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") + +SWERV = DESIGNS["asap7/swerv_wrapper"] + +SWERV_SYNTH = "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth" + +# The helper Tcl travels as `data`, which orfs_run_executable stages +# alongside `script`, so each driver sources it as a sibling. +# e12_lib.tcl is shared by all three drivers; extract_lib.tcl is the +# vendored instrument the archived reference numbers were measured with. +E12_DATA = [ + "e12_lib.tcl", + "extract_lib.tcl", +] + +# The design's own source files (SDC, LEFs, LIBs, io.tcl) reach the flow +# through `data` too: the drivers run real ORFS stage scripts, which read +# them by the variable names the config.mk sets. +E12_DESIGN_DATA = [ + label + for labels in SWERV["sources"].values() + for label in labels +] + +# Step 0: regenerate the 24-candidate population and re-measure it with +# the flat scorer. Writes cand_s.{json,place.tcl,odb} plus +# base_floorplan.odb into $E12_OUT_DIR. This is also the rig check: the +# regenerated flat scores must reproduce the archive. +# +# All four flow targets are `bazelisk run` executables taking KEY=VALUE +# overrides, rather than build-time actions with declared outputs. That +# matches what they are -- a manual campaign whose evidence directory is +# an input to analysis, not a build artifact -- and it is what lets the +# reduction-axis sweeps vary E12_* without a target per value. +orfs_run_executable( + name = "swerv_candidates", + src = SWERV_SYNTH, + arguments = SWERV["arguments"], + cmd = "run", + data = E12_DATA + E12_DESIGN_DATA, + script = "macro_e12.tcl", + tags = ["manual"], +) + +# Step 1: dump RTL-MP's cluster partition from the base floorplan, once. +orfs_run_executable( + name = "swerv_dump_clusters", + src = SWERV_SYNTH, + arguments = SWERV["arguments"], + cmd = "run", + data = E12_DATA + E12_DESIGN_DATA, + script = "dump_clusters.tcl", + tags = ["manual"], +) + +# Step 2: score one candidate with the clustered rung. E12_TAG selects +# the candidate; one candidate per process is mandatory, so the sweep +# over candidates is a loop over invocations of this target rather than +# an inner loop. +orfs_run_executable( + name = "swerv_score_clustered", + src = SWERV_SYNTH, + arguments = SWERV["arguments"], + cmd = "run", + data = E12_DATA + E12_DESIGN_DATA, + script = "score_clustered.tcl", + tags = ["manual"], +) + +py_library( + name = "e12_stats", + srcs = ["e12_stats.py"], + imports = ["."], +) + +py_library( + name = "grade_e12_lib", + srcs = ["grade_e12.py"], + imports = ["."], + deps = [":e12_stats"], +) + +# Step 3: the gate. Reads the committed archive plus the run's evidence +# directory, prints the rho table and writes the verdict. +py_binary( + name = "grade_e12", + srcs = ["grade_e12.py"], + data = ["score_vs_flow_swerv.json"], + tags = ["manual"], + deps = [":e12_stats"], +) + +# The gate's own tests: the pass/fail logic on synthetic fixtures, plus +# five published numbers recomputed from the committed archive. Fast, and +# the only target here that is not manual. +py_test( + name = "grade_e12_test", + size = "small", + srcs = ["grade_e12_test.py"], + data = ["score_vs_flow_swerv.json"], + deps = [ + ":e12_stats", + ":grade_e12_lib", + ], +) diff --git a/flow/test/macro_e12/README.md b/flow/test/macro_e12/README.md new file mode 100644 index 0000000000..ba2eb1a186 --- /dev/null +++ b/flow/test/macro_e12/README.md @@ -0,0 +1,173 @@ +# E12: a clustered global-place scorer for macro-placement selection + +## The question + +A macro placement is a draw from a distribution, not an optimum. Seeding +RTL-MP (`rtl_macro_placer -random_seed`) on asap7 `swerv_wrapper` gives 24 +placements whose downstream macro-path timing spans ~300 ps, and the +placer's own annealing cost cannot tell which is which: it predicts area, +not period. Selection therefore needs a *score* measured after the fact. + +The established score is a fast global placement over every standard +cell, timing- and routability-driven off — the **flat** rung. It ranks +the ground truth (macro-path mean, measured at global route after the +entire production tail) at Spearman **rho +0.72 [0.48, 0.84]**. + +**E12 asks whether that placement can be run on RTL-MP's own std-cell +clusters instead** — roughly an order of magnitude fewer movables — and +still rank. Ranking is the only requirement. A scorer that is uniformly +20% optimistic ranks perfectly; rank inversions are the enemy, absolute +error never was. + +## The gate + +One criterion, fixed before the first run: + +> rho(clustered HPWL vs grt `macro_paths_mean`) must land inside the flat +> scorer's interval, **[0.48, 0.84]**, over all 24 candidates. + +A failing verdict is a result. The truth includes +`repair_design`/`repair_timing`/CTS/route, so rho(clustered) − rho(flat) +*is* the measured price of the abstraction, repair-blindness included. +Note that a clustered netlist forfeits the repair rung structurally — +`repair_timing` works on real cells, not soft clusters — so any gap gets +closed by field surrogates or by promoting survivors to the flat rung, +never by running repair on clusters. + +Two gates run in order, and gate 0 comes first for a reason: the +candidate placements were never archived, only their scores, so this +experiment regenerates them. Until the regenerated flat scores reproduce +the archived ones, any clustered number is measuring the rig. + +| Gate | Question | Failure means | +|---|---|---| +| 0 | Do the regenerated flat scores reproduce `score_vs_flow_swerv.json` exactly? | The rig drifted (different OpenROAD, lost patch, different floorplan). Stop. | +| 1 | Is rho(clustered) inside [0.48, 0.84] over 24/24 candidates? | The reduction costs ranking accuracy. Report it. | + +## Pre-registered configuration + +At n = 24 a Spearman interval is roughly ±0.2 wide, so choosing the best +of several settings after seeing the numbers would be selection on noise +and would void the gate. **These values define the gate run:** + +| Setting | Value | Why it is not a knob | +|---|---|---| +| `E12_HALO_HOPS` | 1 | Cells within one hop of a macro pin stay individual movables. Clustering smears exactly the pin geometry the live KPI reads; the hop count is a small integer, not a searched value. | +| `E12_OVERFLOW` | 0.6 | A dimensionless placement invariant. Ranking power was measured to saturate by overflow ~0.6, so the convergence tail buys nothing. Validated once, against archived trajectories. | +| `E12_LARGE_NET_THRESHOLD` | 50 | The value RTL-MP's own clustering uses to ignore global nets. Mirrored rather than chosen. | +| `E12_BIN_GRID_COUNT` | 0 (gpl's own default) | Not tuned for the gate run. | +| cluster level | leaf clusters only | Interior nodes of the hierarchy would double-count their descendants. | +| score readout | full signal-net HPWL | The flat rung's scalar, for a like-for-like comparison. | +| build | non-GPU | Determinism holds only there; the GPU HPWL/scatter backends are documented as thread-order tolerant. | + +Everything else — hops 0 and 2, the macro cone readout, `-bin_grid_count` +sweeps, `-disable_pin_density_adjust`, filler coarsening, net bundling — +is **exploratory**, reported as a rho-versus-cost curve. A setting that +beats the primary earns a second, pre-registered confirmation run; it +does not get retroactively promoted. + +## Why the coarsening is applied once, on the base floorplan + +The cluster partition comes from connectivity and module hierarchy, not +from macro positions, so it is derived once from the shared base +floorplan and reused by every candidate. That is not only a saving. It +means every candidate is scored through the *identical* coarsening, so +the distortion the reduction introduces is common-mode — and common-mode +distortion does not create rank inversions. A partition re-derived per +candidate would, and must not be used however tempting. + +## Running it + +Every flow target is a `bazelisk run` executable taking `KEY=VALUE` +overrides, and every one of them needs `E12_OUT_DIR` — the evidence +directory is an input to the analysis, not a build artifact, so it is +named explicitly rather than declared as an output. + +```sh +EV=$PWD/e12_evidence # anywhere outside the source tree +mkdir -p "$EV" + +# Step 0 -- regenerate the 24 candidates and re-measure them flat (~25 min +# on a 24-core machine). Writes cand_s.{json,place.tcl,odb} and +# base_floorplan.odb. +bazelisk run //flow/test/macro_e12:swerv_candidates -- E12_OUT_DIR=$EV + +# Step 1 -- dump RTL-MP's cluster partition from the base floorplan, once. +bazelisk run //flow/test/macro_e12:swerv_dump_clusters -- E12_OUT_DIR=$EV + +# Step 2 -- score ONE candidate per process. This is mandatory, not +# stylistic: gpl's Replace::reset() does not clear its cluster list, and +# gpl writes GCell locations back into odb, so process isolation is what +# makes scoring report-only. +for seed in $(seq 0 23); do + bazelisk run //flow/test/macro_e12:swerv_score_clustered -- \ + E12_OUT_DIR=$EV E12_TAG=cand_s$seed +done + +# Step 3 -- the verdict. +bazelisk run //flow/test/macro_e12:grade_e12 -- \ + --truth $PWD/flow/test/macro_e12/score_vs_flow_swerv.json \ + --evidence-dir $EV --out $EV/e12_verdict.json +``` + +### Check seed 0 before spending the campaign + +Score one candidate and read it against the early-kill criteria: +**overflow never reaching 0.6**, or gpl reporting divergence. A diverged +candidate must be recorded as a failure and never scored — gpl silently +reverts to its minimum-HPWL snapshot, which yields a number that looks +like a score and is not one. + +Read `clusters_declared` and `clustered_insts` in the leaf at the same +time. If the movable count barely fell, the reduction is being cancelled +somewhere and there is no point measuring 24 of them yet. + +### The determinism check, before the campaign and not after + +The scores must be bit-identical across thread counts. That should hold +by construction — gpl's density scatter accumulates into int64 bins, so +the sum is over a fixed multiset — but "should" is not a measurement: + +```sh +for t in 1 2 8 8; do + bazelisk run //flow/test/macro_e12:swerv_score_clustered -- \ + E12_OUT_DIR=$EV E12_TAG=cand_s0 E12_THREADS=$t + mv $EV/cand_s0.clustered.json $EV/cand_s0.t$t.$RANDOM.json +done +# hpwl_dbu and cone_hpwl_dbu must be identical in all four files. +grep -h '"hpwl_dbu"\|"cone_hpwl_dbu"' $EV/cand_s0.t*.json | sort -u +``` + +Two runs at t=8 are included on purpose: they separate genuine +thread-count sensitivity from plain run-to-run irreproducibility. + +The gate's own logic is tested without OpenROAD at all: + +```sh +bazelisk test //flow/test/macro_e12:grade_e12_test +``` + +That test also recomputes five published numbers from the committed +archive (+0.72, +0.82, +0.57, +0.65, +0.47). If it fails, the archive or +the statistics moved and every E12 number is void. + +## Files + +| File | Role | +|---|---| +| `macro_e12.tcl` | Step 0: candidate generation plus the flat control rung. | +| `dump_clusters.tcl` | Step 1: RTL-MP's cluster partition, from `-keep_clustering_data`. | +| `score_clustered.tcl` | Step 2: the clustered scorer. | +| `e12_lib.tcl` | Shared helpers: the macro-pin BFS, the HPWL readout, leaf writing. | +| `extract_lib.tcl` | The KPI instrument, vendored verbatim. Do not "improve" it: the archived numbers were measured with it. | +| `grade_e12.py` | Step 3: the gate. | +| `e12_stats.py` | Spearman and bootstrap CI, vendored verbatim, stdlib only. | +| `score_vs_flow_swerv.json` | The committed archive: 24 candidates, ground truth and flat score. | + +## What is deliberately not here + +`rtl_macro_placer -candidates k` — clustering once, racing k seeded +anneals in-process under a knob-free dominance rule and committing +exactly one winner — is the point of all this, and it belongs in +OpenROAD rather than in an ORFS patch. It is planned only if this gate +passes, which is the whole reason the gate exists. diff --git a/flow/test/macro_e12/dump_clusters.tcl b/flow/test/macro_e12/dump_clusters.tcl new file mode 100644 index 0000000000..e49348e97a --- /dev/null +++ b/flow/test/macro_e12/dump_clusters.tcl @@ -0,0 +1,133 @@ +# E12 step 1: dump RTL-MP's std-cell cluster partition, once. +# +# RTL-MP already builds a physical hierarchy -- std-cell clusters and +# bundled nets -- as the model its annealer works on. E12 reuses that +# partition as the scoring netlist instead of inventing one, so the +# clustered scorer grades the same abstraction the macro placer itself +# reasons about. +# +# rtl_macro_placer -keep_clustering_data commits the cluster tree to odb +# as a nested dbGroup tree that partitions the instances (VISUAL_DEBUG +# groups, which gpl ignores because they carry no region). Walking those +# groups is therefore the whole extraction: no new OpenROAD code, and no +# reimplementation of the clustering. +# +# This runs on the *base floorplan*, before any candidate's macro +# placement. Clustering is derived from connectivity and module +# hierarchy, not from macro positions, so one partition serves all +# candidates. That matters beyond saving time: because every candidate is +# scored through the identical coarsening, the distortion the reduction +# introduces is common-mode, and common-mode distortion does not create +# rank inversions. A partition re-derived per candidate would. + +set e12_dir [file dirname [file normalize [info script]]] +source [file join $e12_dir e12_lib.tcl] + +set ::e12_out [e12_env E12_OUT_DIR [e12_env RUN_OUTPUT_DIR ""]] +if { $::e12_out eq "" } { + error "dump_clusters: set E12_OUT_DIR or declare out_dir" +} +file mkdir $::e12_out + +set ::e12_work [e12_env E12_WORK [file join $::env(WORK_HOME) e12_work]] +set base_odb [e12_env E12_BASE_ODB [file join $::e12_out base_floorplan.odb]] +if { ![file exists $base_odb] } { + error "dump_clusters: no base floorplan at $base_odb;\ + run the macro_e12 candidate generation first" +} + +set ::env(KEEP_VARS) 1 +set ::env(SKIP_REPORT_METRICS) 1 +e12_redirect clusters + +# Stage the archived base floorplan under the stem ORFS's macro_place +# stage loads, and let the stage script do the loading: load_design also +# reads liberty, the SDC and the platform setup, none of which a bare +# read_db would do. +foreach ext {odb sdc} { + file copy -force [file rootname $base_odb].$ext \ + [file join $::env(RESULTS_DIR) 2_1_floorplan.$ext] +} + +# A full RTL-MP run is required: -keep_clustering_data only commits the +# tree that the run actually builds. Run it through ORFS's own +# macro_place.tcl rather than calling the placer directly, so the halos, +# target utilization and blockage settings are the production ones -- a +# partition built under different settings would not be the partition the +# production placer reasons about, and the whole premise of E12 is that it +# reuses RTL-MP's own abstraction. +# +# The resulting macro placement is discarded; this process never writes +# the design back. +e12_wrap_placer [list -keep_clustering_data] +set t0 [clock clicks -milliseconds] +if { [catch { e12_step macro_place.tcl } err] } { + error "dump_clusters: macro placement failed: $err\n\ + note MPL-0049 is raised if any instance is left ungrouped" +} +set mpl_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + +set block [ord::get_db_block] + +# Emit leaf groups only. A dbGroup tree node whose children are groups +# is an interior level of the hierarchy; its instances are already +# accounted for by its descendants, so folding it in would double-count. +proc e12_leaf_groups { groups } { + set leaves {} + foreach group $groups { + set children [$group getGroups] + if { [llength $children] == 0 } { + lappend leaves $group + } else { + lappend leaves {*}[e12_leaf_groups $children] + } + } + return $leaves +} + +set leaves [e12_leaf_groups [$block getGroups]] + +# Sort by group name, and instances within a group by odb id, so the file +# is a pure function of the database. +set rows {} +set grouped 0 +foreach group $leaves { + set name [$group getName] + set ids {} + foreach inst [$group getInsts] { + lappend ids [$inst getId] + } + foreach id [lsort -integer -unique $ids] { + set inst [odb::dbInst_getInst $block $id] + lappend rows [list $name $id [$inst getName]] + incr grouped + } +} +set rows [lsort -index 1 -integer [lsort -index 0 -ascii $rows]] + +set fp [open [file join $::e12_out clusters.txt] w] +puts $fp "# " +puts $fp "# leaf clusters from rtl_macro_placer -keep_clustering_data" +foreach row $rows { + puts $fp [join $row " "] +} +close $fp + +# Coverage report. gpl only clusters what it is handed, so an instance +# missing from the partition silently stays a movable of its own; saying +# so out loud is what keeps the reduction ratio honest. +set movable 0 +foreach inst [$block getInsts] { + if { [[$inst getMaster] isBlock] || [$inst isFixed] } { + continue + } + incr movable +} +e12_write_leaf [file join $::e12_out clusters.json] [list \ + leaf_clusters [llength $leaves] \ + grouped_insts $grouped \ + movable_insts $movable \ + mpl_s $mpl_s] +puts "e12: [llength $leaves] leaf clusters covering\ + $grouped of $movable movable instances (${mpl_s}s)" +exit 0 diff --git a/flow/test/macro_e12/e12_lib.tcl b/flow/test/macro_e12/e12_lib.tcl new file mode 100644 index 0000000000..2494d3ab81 --- /dev/null +++ b/flow/test/macro_e12/e12_lib.tcl @@ -0,0 +1,267 @@ +# Shared helpers for the E12 clustered-scorer experiment. +# +# E12 asks whether a global placement run on RTL-MP's own std-cell +# clusters -- rather than on every std cell -- still ranks macro +# placement candidates as well as the flat scorer does. Ranking accuracy +# is the only requirement: a scorer that is uniformly optimistic ranks +# perfectly, so absolute error is not the enemy, rank inversions are. +# +# Everything here is report-only. Scores are read out of odb after +# global placement; nothing is written back to the design database, and +# each candidate is scored in its own process (gpl's Replace::reset() +# does not clear the cluster list, and gpl does write GCell locations +# back to odb, so process isolation is what makes scoring side-effect +# free). + +# -------------------------------------------------------------------- +# Environment and bookkeeping. + +proc e12_env { name default } { + if { [info exists ::env($name)] && $::env($name) ne "" } { + return $::env($name) + } + return $default +} + +# Point the ORFS per-stage directories at a per-tag work area so +# candidates cannot overwrite each other's intermediate files. +proc e12_redirect { tag } { + set base [file join $::e12_work $tag] + foreach {var sub} {RESULTS_DIR results REPORTS_DIR reports + LOG_DIR logs OBJECTS_DIR objects} { + set dir [file join $base $sub] + file mkdir $dir + set ::env($var) $dir + } + return $base +} + +proc e12_step { script } { + set t0 [clock clicks -milliseconds] + uplevel #0 [list source [file join $::env(SCRIPTS_DIR) $script]] + set s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + puts "e12: $script done in ${s}s" + return $s +} + +proc e12_vmhwm_kb { } { + if { + [catch { + set fp [open /proc/self/status r] + set status [read $fp] + close $fp + regexp {VmHWM:\s+(\d+) kB} $status -> kb + }] + } { + return 0 + } + return $kb +} + +# Append extra arguments to the exact argument list ORFS's +# macro_place_util.tcl constructs. RTLMP_ARGS would REPLACE that list, +# dropping halos and target_util, which would silently change what is +# being measured; wrapping the command keeps every ORFS argument and adds +# only what the experiment needs. +# +# Both users go through here on purpose. The candidate generator adds +# -random_seed, and the cluster dump adds -keep_clustering_data: the +# partition has to be the one *production* RTL-MP builds, so it must be +# produced by the production argument list too. +proc e12_wrap_placer { extra } { + if { [info commands e12_real_rtl_macro_placer] eq "" } { + rename rtl_macro_placer e12_real_rtl_macro_placer + proc rtl_macro_placer { args } { + e12_real_rtl_macro_placer {*}$args {*}$::e12_placer_extra + } + } + set ::e12_placer_extra $extra +} + +# -------------------------------------------------------------------- +# Netlist queries. +# +# All of these iterate in a deterministic order (sorted by odb id) and +# return sorted id lists, so every derived set is a pure function of the +# database and not of pointer or hash order. + +proc e12_is_supply { sig_type } { + return [expr { $sig_type eq "POWER" || $sig_type eq "GROUND" }] +} + +# Nets a scoring pass should look at: real signal nets, skipping the +# oversized ones RTL-MP itself ignores when it builds its clustered +# model (ClusteringEngine::isValidNet / large_net_threshold). +proc e12_signal_nets { block { large_net_threshold 0 } } { + set nets {} + foreach net [$block getNets] { + if { [$net isSpecial] } { + continue + } + if { [e12_is_supply [$net getSigType]] } { + continue + } + if { + $large_net_threshold > 0 + && [$net getTermCount] > $large_net_threshold + } { + continue + } + lappend nets $net + } + return $nets +} + +# Half-perimeter wirelength over a net list, in exact integer DBU. +# +# dbNet::getTermBBox is the bounding box of the net's physical terminal +# locations, which is what gpl minimizes and what odb's own +# WireLengthEvaluator sums. Tcl integers are arbitrary precision and +# integer addition is associative, so the result is independent of +# iteration order and of thread count -- the determinism requirement is +# satisfied by construction rather than by discipline. +proc e12_hpwl_dbu { nets } { + set hpwl 0 + foreach net $nets { + set bbox [$net getTermBBox] + set hpwl [expr { $hpwl + [$bbox dx] + [$bbox dy] }] + } + return $hpwl +} + +# Breadth-first expansion outward from macro pins. +# +# Returns a dict with, per hop level 1..hops, the movable instances +# reached at that level, plus the accumulated net set at each level. +# Two consumers, one traversal: +# +# halo-flat coarsening -- the instances within 1-2 hops of a macro pin +# stay individual movables instead of being folded into a cluster, +# because clustering smears exactly the pin geometry the live KPI +# (the macro-path timing aggregate) reads. +# +# macro-cone scoring -- HPWL summed over only the nets in the cone, +# because a score dominated by wirelength the KPI never looks at is a +# score spending its resolution in the wrong place. +proc e12_macro_bfs { block hops { large_net_threshold 0 } } { + set macro_ids {} + foreach inst [$block getInsts] { + if { [[$inst getMaster] isBlock] } { + lappend macro_ids [$inst getId] + } + } + set macro_ids [lsort -integer -unique $macro_ids] + + # seen_inst: every instance already assigned to a level, so a later hop + # cannot claim it again. seen_net: likewise for nets. + set seen_inst {} + foreach id $macro_ids { + dict set seen_inst $id 1 + } + set seen_net {} + set frontier {} + foreach id $macro_ids { + lappend frontier [odb::dbInst_getInst $block $id] + } + + set result [dict create macros $macro_ids] + set cone_nets {} + + # Level 0 is the macros themselves: its nets are the ones incident to a + # macro pin, which is the cone even when no instance is kept flat. The + # loop therefore collects nets first and expands second, so hops = 0 is + # a meaningful configuration (cluster everything, cone still defined) + # rather than an empty result. + for { set hop 0 } { $hop <= $hops } { incr hop } { + set reached {} + foreach inst $frontier { + foreach iterm [$inst getITerms] { + set net [$iterm getNet] + if { $net eq "NULL" || $net eq "" } { + continue + } + if { [$net isSpecial] || [e12_is_supply [$net getSigType]] } { + continue + } + if { + $large_net_threshold > 0 + && [$net getTermCount] > $large_net_threshold + } { + continue + } + set net_id [$net getId] + if { ![dict exists $seen_net $net_id] } { + dict set seen_net $net_id 1 + lappend cone_nets $net_id + } + lappend reached $net + } + } + dict set result cone_nets$hop [lsort -integer -unique $cone_nets] + if { $hop == $hops } { + break + } + + set next_ids {} + foreach net $reached { + foreach other [$net getITerms] { + set other_inst [$other getInst] + set other_id [$other_inst getId] + if { [dict exists $seen_inst $other_id] } { + continue + } + if { [[$other_inst getMaster] isBlock] || [$other_inst isFixed] } { + continue + } + dict set seen_inst $other_id 1 + lappend next_ids $other_id + } + } + set next_ids [lsort -integer -unique $next_ids] + dict set result hop[expr { $hop + 1 }] $next_ids + set frontier {} + foreach id $next_ids { + lappend frontier [odb::dbInst_getInst $block $id] + } + } + return $result +} + +# The halo-flat instance set: everything within $hops of a macro pin. +proc e12_halo_flat_ids { bfs hops } { + set ids {} + for { set hop 1 } { $hop <= $hops } { incr hop } { + if { [dict exists $bfs hop$hop] } { + lappend ids {*}[dict get $bfs hop$hop] + } + } + return [lsort -integer -unique $ids] +} + +# -------------------------------------------------------------------- +# Score readout. + +# Every score record carries the cost side of the measurement next to +# the ranking side, so the ranking-accuracy-vs-cost curve can be drawn +# from the evidence rather than estimated. num_gcells/num_fillers come +# from gpl's own log, which is the only place they are reported. +proc e12_write_leaf { path fields } { + set fp [open $path w] + puts $fp "{" + set n [llength $fields] + set i 0 + foreach {key value} $fields { + incr i 2 + set comma [expr { $i < $n ? "," : "" }] + if { + [string is entier -strict $value] + || [string is double -strict $value] + } { + puts $fp " \"$key\": $value$comma" + } else { + puts $fp " \"$key\": \"$value\"$comma" + } + } + puts $fp "}" + close $fp +} diff --git a/flow/test/macro_e12/e12_stats.py b/flow/test/macro_e12/e12_stats.py new file mode 100644 index 0000000000..3c4529f9d3 --- /dev/null +++ b/flow/test/macro_e12/e12_stats.py @@ -0,0 +1,61 @@ +"""Rank-correlation statistics for the E12 clustered-scorer gate. + +Candidate selection is a ranking problem, so the figure of merit is +Spearman's rho, not any absolute error: a scorer that is uniformly +optimistic ranks perfectly. With n = 24 a point estimate alone would +overclaim, so every rho is reported with a bootstrap 95% interval. + +These three functions are vendored verbatim from the public bazel-orfs +`macro-selector` branch, test/estimation_ladder/score_vs_flow.py, which +produced the archived reference numbers in score_vs_flow_swerv.json. +Identical code is the point: a reimplementation, however faithful, would +make "rho reproduces the archive" untestable. Do not rewrite them here. +Stdlib only, deliberately -- ORFS's flow/util requirements carry neither +scipy nor numpy. +""" + +import math +import random + + +def rankdata(values): + order = sorted(range(len(values)), key=lambda i: values[i]) + ranks = [0.0] * len(values) + i = 0 + while i < len(order): + j = i + while j + 1 < len(order) and values[order[j + 1]] == values[order[i]]: + j += 1 + mean_rank = (i + j) / 2.0 + 1.0 + for k in range(i, j + 1): + ranks[order[k]] = mean_rank + i = j + 1 + return ranks + + +def spearman(x, y): + rx, ry = rankdata(x), rankdata(y) + n = len(rx) + mx = sum(rx) / n + my = sum(ry) / n + num = sum((a - mx) * (b - my) for a, b in zip(rx, ry)) + dx = math.sqrt(sum((a - mx) ** 2 for a in rx)) + dy = math.sqrt(sum((b - my) ** 2 for b in ry)) + if dx == 0 or dy == 0: + return float("nan") + return num / (dx * dy) + + +def spearman_ci(x, y, n_boot=4000, seed=0): + rng = random.Random(seed) + n = len(x) + rhos = [] + for _ in range(n_boot): + idx = [rng.randrange(n) for _ in range(n)] + rho = spearman([x[i] for i in idx], [y[i] for i in idx]) + if not math.isnan(rho): + rhos.append(rho) + rhos.sort() + lo = rhos[int(0.025 * len(rhos))] + hi = rhos[int(0.975 * len(rhos)) - 1] + return lo, hi diff --git a/flow/test/macro_e12/extract_lib.tcl b/flow/test/macro_e12/extract_lib.tcl new file mode 100644 index 0000000000..c1e0ff497b --- /dev/null +++ b/flow/test/macro_e12/extract_lib.tcl @@ -0,0 +1,186 @@ +# KPI extraction instrument, vendored verbatim (modulo formatting) from +# the public bazel-orfs `macro-selector` branch, +# test/estimation_ladder/extract_lib.tcl. +# +# The archived swerv_wrapper reference numbers in +# score_vs_flow_swerv.json were measured with this exact sampling logic. +# A study that compares spreads across ensembles is only as good as the +# identity of its measurement, so this file must not be "improved" here: +# any change to it invalidates the comparison against those numbers. + +# Record a path once, tagged with whether it touches a macro pin. +# Returns 1 if the path was new, 0 if it was a duplicate. +proc extract_add_path { sel_var seen_var clk_period path is_macro } { + upvar 1 $sel_var selected $seen_var seen + set sp [get_full_name [get_property $path startpoint]] + set ep [get_full_name [get_property $path endpoint]] + if { [dict exists $seen "$sp|$ep"] } { return 0 } + dict set seen "$sp|$ep" 1 + set slack [get_property $path slack] + set period [expr { $clk_period - $slack }] + lappend selected [list $sp $ep $period $is_macro] + return 1 +} + +# Macro pins as OpenSTA names them. ODB escapes Verilog identifiers and +# OpenSTA does not, so the escapes have to come out or nothing matches. +proc extract_macro_pin_names { } { + set blk [ord::get_db_block] + set outs {} + set ins {} + foreach inst [$blk getInsts] { + if { ![[$inst getMaster] isBlock] } { continue } + set iname [string map {"\\" ""} [$inst getName]] + foreach it [$inst getITerms] { + if { [$it getSigType] ne "SIGNAL" } { continue } + set pin "$iname/[[$it getMTerm] getName]" + if { [$it getIoType] eq "OUTPUT" } { + lappend outs $pin + } else { + lappend ins $pin + } + } + } + return [list $outs $ins] +} + +# Sample the worst 25% of the min_period range plus the macro paths, +# de-duplicated by endpoint pair. Requires the design in memory with +# parasitics already estimated. Returns a dict: +# clock_period the period read back from STA (so a perturbed clock +# is reported as perturbed -- the nudge-landed guard) +# wns worst reg2reg slack +# paths list of {start end min_period is_macro} +proc extract_sample_paths { } { + # The reg2reg path group is defined by the platform SDC. Note that a + # "register" can be a macro, not just a flip-flop. + set wns_path [find_timing_paths -path_group reg2reg -sort_by_slack \ + -group_path_count 1] + if { [llength $wns_path] == 0 } { + error "No reg2reg timing paths found!" + } + set wns [get_property [lindex $wns_path 0] slack] + set clk_period [get_property [lindex [get_clocks] 0] period] + + puts "WNS: $wns, Clock Period: $clk_period" + + # Sample the worst 25% of the min_period range. min_period = + # clk_period - slack, so the window [0.75 * max_period, max_period] + # maps to slacks in [wns, wns + 0.25 * max_period]. + set max_period [expr { $clk_period - $wns }] + set num_buckets 10 + set paths_per_bucket 10 + set step [expr { 0.25 * $max_period / $num_buckets }] + set selected {} + set seen [dict create] + + for { set i 0 } { $i < $num_buckets } { incr i } { + set b_min [expr { $wns + ($i * $step) }] + set b_max [expr { $wns + (($i + 1) * $step) }] + + set paths [find_timing_paths -path_group reg2reg \ + -slack_min $b_min -slack_max $b_max \ + -sort_by_slack -group_path_count $paths_per_bucket] + foreach path $paths { + extract_add_path selected seen $clk_period $path 0 + } + } + + # The general spread above is worst-slack driven, and on a design that + # is an array of macros it turns out to contain almost no macro pins + # at all -- two paths in ninety-nine. That characterises the design by + # its top-level flop-to-flop logic and leaves the very thing the + # design exists to exercise unmeasured, so sample the macro paths + # explicitly as well and tag them, rather than hoping they fall out of + # a slack ranking. + lassign [extract_macro_pin_names] macro_outs macro_ins + # Enough macro paths to support a study of their own rather than a tag + # on a handful: they are a separate population with their own error + # structure, and twenty-eight is too few to rank or fit anything on. + set macro_target 80 + set macro_added 0 + puts "Macro pins: [llength $macro_outs] outputs, [llength $macro_ins] inputs" + + foreach {dir pins} [list -from $macro_outs -to $macro_ins] { + if { [llength $pins] == 0 } { continue } + if { + [catch { + set paths [find_timing_paths $dir $pins -path_group reg2reg \ + -sort_by_slack -group_path_count $macro_target] + } err] + } { + puts "WARNING: macro path query $dir failed: $err" + continue + } + foreach path $paths { + incr macro_added [extract_add_path selected seen $clk_period $path 1] + } + } + puts "Sampled $macro_added macro paths in addition to the general spread." + + if { [llength $selected] < 20 } { + error "Found only [llength $selected] unique reg2reg paths in the\ + worst-25% window. Design is too trivial." + } + set n_macro 0 + foreach pt $selected { incr n_macro [lindex $pt 3] } + puts "Sampled [llength $selected] reg2reg paths ($n_macro touching a macro pin)." + + return [dict create clock_period $clk_period wns $wns paths $selected] +} + +# Area from the ODB rather than report_design_area's printed line, so the +# number is a value and not a regex. Split std cell vs macro: the macros +# never change across a variance ensemble, while the repair stages buy +# timing with std-cell area -- which is exactly the trade a period-only +# KPI cannot see. +proc extract_design_area { } { + set blk [ord::get_db_block] + set dbu [$blk getDbUnitsPerMicron] + set scale [expr { double($dbu) * double($dbu) }] + set stdcell_um2 0.0 + set macro_um2 0.0 + set n_stdcell 0 + set n_macro 0 + foreach inst [$blk getInsts] { + set master [$inst getMaster] + set a [expr { [$master getWidth] * double([$master getHeight]) / $scale }] + if { [$master isBlock] } { + set macro_um2 [expr { $macro_um2 + $a }] + incr n_macro + } elseif { [$master isCore] } { + set stdcell_um2 [expr { $stdcell_um2 + $a }] + incr n_stdcell + } + } + return [dict create \ + stdcell_um2 $stdcell_um2 \ + macro_um2 $macro_um2 \ + num_stdcells $n_stdcell \ + num_macros $n_macro] +} + +# The "paths" JSON fragment shared by extract.tcl and the walk's leaves: +# same schema, so achieved() and every other consumer reads both. +proc extract_paths_json { paths } { + set lines {} + foreach pt $paths { + lappend lines " {\"start\": \"[lindex $pt 0]\", \"end\":\ +\"[lindex $pt 1]\", \"min_period\": [lindex $pt 2], \"macro_path\":\ +[lindex $pt 3]}" + } + return "\[\n[join $lines ",\n"]\n\]" +} + +# The area/power JSON fragment. Power is recorded equal to the std-cell +# area for now: the PPA KPI is three-dimensional, but a credible power +# number needs switching activity the flow does not have at grt. +# TODO(power): replace with a real power figure (e.g. report_power under +# a stated activity assumption) once the study needs it. +proc extract_ppa_json { area } { + return "\"area\": {\"stdcell_um2\": [dict get $area stdcell_um2],\ + \"macro_um2\": [dict get $area macro_um2],\ + \"num_stdcells\": [dict get $area num_stdcells],\ + \"num_macros\": [dict get $area num_macros]},\n\"power_todo\":\ + [dict get $area stdcell_um2]" +} diff --git a/flow/test/macro_e12/grade_e12.py b/flow/test/macro_e12/grade_e12.py new file mode 100644 index 0000000000..69d2b95497 --- /dev/null +++ b/flow/test/macro_e12/grade_e12.py @@ -0,0 +1,394 @@ +#!/usr/bin/env python3 +"""The E12 gate: does a clustered global placement rank as well as a flat one? + +Background. Macro placement candidates are generated by seeding RTL-MP +(`rtl_macro_placer -random_seed`) and then *scored*, because the placer's +own annealing cost predicts area rather than period. The established +scorer is a fast non-timing-driven global placement over every standard +cell -- the "flat" rung. On the archived asap7 swerv_wrapper population +of 24 candidates it ranks the ground truth (the macro-path timing +aggregate measured at global route, after the entire production tail) at +Spearman rho +0.72 with a bootstrap interval of [0.48, 0.84]. + +E12 asks whether that placement can be run on RTL-MP's own std-cell +clusters instead -- roughly an order of magnitude fewer movables -- and +still rank. This script decides it, on one pre-registered criterion: + + rho(clustered score vs grt macro_paths_mean) must land inside the + flat scorer's interval, [0.48, 0.84]. + +A failing verdict is a result, not a defect: it prices the reduction. +Because the truth includes repair_design/repair_timing/CTS/route, +rho(clustered) - rho(flat) *is* the measured cost of the abstraction, +repair-blindness and all. + +Two gates, in order. Gate 0 checks the rig: the candidates are +regenerated here, so the regenerated flat scores must reproduce the +archived ones before any clustered number means anything. Gate 1 is the +criterion above. Gate 0 failing means the rig is being measured, not E12. + +Inputs: + --truth score_vs_flow_swerv.json -- the committed archive: + per candidate, `grt` (ground truth) and `proxy` (the + flat score that was measured alongside it) + --evidence-dir the run's leaves: cand_s.json (flat, from + macro_e12.tcl) and cand_s.clustered.json (from + score_clustered.tcl) + --out verdict JSON +""" + +import argparse +import json +import os +import sys + +from e12_stats import spearman, spearman_ci + +# The flat scorer's measured interval on the macro-path KPI. Not a +# tunable: it is the published reference this experiment is graded +# against, and moving it would move the goalposts. +# +# Specifically this is the interval of REFERENCE_VARIANT below, i.e. +# rho(flat proxy's general-path aggregate, grt macro_paths_mean) = +# +0.72 [0.48, 0.84]. Recomputing it from the committed archive is a +# unit test, not an act of faith. Note that the flat proxy's *macro*-path +# aggregate ranks the same truth better still, +0.82 [0.61, 0.92]; the +# conservative scalar is used as the reference on purpose, because the +# clustered rung's score is a wirelength scalar rather than an STA +# aggregate and the published HPWL-only floor (+0.67) sits inside this +# interval. +FLAT_CI = (0.48, 0.84) + +REFERENCE_VARIANT = "archive_flat_wq25" + +# Ground-truth KPIs, from the archive's `grt` block. The gate rides on +# macro_paths_mean; the rest are reported because a scorer that ranks the +# wrong KPI well is worth knowing about. +TRUTH_KPIS = ("macro_paths_mean", "achieved", "general_paths_mean", "stdcell_um2") + +GATE_KPI = "macro_paths_mean" + +CLUSTERED_SUFFIX = ".clustered.json" + +# Score variants. Each is (label, source, field), where source picks the +# per-candidate record to read the field out of. Every variant is +# oriented so that *lower is better*, which is why they are all expected +# to correlate positively with the period KPIs. +VARIANTS = ( + ("archive_flat_wq25", "archive_proxy", "wq25"), + ("archive_flat_macro_mean", "archive_proxy", "macro_mean"), + ("archive_objective", "archive_objective", "objective_fixed_norm"), + ("regen_flat_wq25", "flat", "wq25"), + ("regen_flat_macro_mean", "flat", "macro_mean"), + ("regen_flat_hpwl", "flat", "hpwl_dbu"), + ("clustered_hpwl", "clustered", "hpwl_dbu"), + ("clustered_cone_hpwl", "clustered", "cone_hpwl_dbu"), +) + +# Fields whose regeneration gate 0 checks per candidate. Both are STA +# aggregates the flat rung reports, so both must come back identical if +# `-random_seed` really made the candidate reproducible. +REPRODUCED_FIELDS = ("wq25", "macro_mean") + +# Cost fields worth carrying next to the ranking, so the +# accuracy-vs-cost curve can be drawn from the evidence rather than +# estimated. The counts are what make the claimed reduction checkable. +COST_FIELDS = ( + "gpl_s", + "clusters_declared", + "clustered_insts", + "halo_flat_insts", + "signal_nets", + "cone_nets", + "vmhwm_kb", +) + + +def load_json(path): + with open(path, encoding="utf-8") as handle: + return json.load(handle) + + +def load_leaves(evidence_dir, suffix, exclude=()): + """Per-candidate leaves, keyed by tag. + + `exclude` keeps the flat leaves (cand_s0.json) from also matching the + clustered ones (cand_s0.clustered.json), which share the .json tail. + """ + leaves = {} + if not os.path.isdir(evidence_dir): + return leaves + for name in sorted(os.listdir(evidence_dir)): + if not name.endswith(suffix): + continue + if any(name.endswith(other) for other in exclude): + continue + tag = name[: -len(suffix)] + leaves[tag] = load_json(os.path.join(evidence_dir, name)) + return leaves + + +def collect(truth, flat, clustered): + """Per-tag records, one dict per source, over the common tags only.""" + archive = truth["candidates"] + tags = sorted(set(archive) & set(flat) & set(clustered)) if clustered else [] + if not tags: + # Gate 0 can be evaluated before any clustered leaf exists. + tags = sorted(set(archive) & set(flat)) + return tags, { + "grt": {t: archive[t]["grt"] for t in tags}, + "archive_proxy": {t: archive[t]["proxy"] for t in tags}, + "archive_objective": { + t: {"objective_fixed_norm": archive[t]["objective_fixed_norm"]} + for t in tags + if "objective_fixed_norm" in archive[t] + }, + "flat": {t: flat[t] for t in tags if t in flat}, + "clustered": {t: clustered[t] for t in tags if t in clustered}, + } + + +def rho_table(tags, sources, n_boot): + """rho and CI for every (variant, truth KPI) pair that has data.""" + table = {} + for label, source, field in VARIANTS: + records = sources.get(source, {}) + usable = [t for t in tags if t in records and field in records[t]] + if len(usable) < 3: + continue + scores = [records[t][field] for t in usable] + per_kpi = {} + for kpi in TRUTH_KPIS: + truth_vals = [sources["grt"][t][kpi] for t in usable] + rho = spearman(scores, truth_vals) + low, high = spearman_ci(scores, truth_vals, n_boot=n_boot) + per_kpi[kpi] = {"rho": rho, "ci": [low, high]} + table[label] = {"n": len(usable), "kpi": per_kpi} + return table + + +def cost_table(tags, sources): + """Mean of each cost field, per source, over the candidates that have it.""" + costs = {} + for source in ("flat", "clustered"): + records = sources.get(source, {}) + per_field = {} + for field in COST_FIELDS: + values = [ + records[t][field] for t in tags if t in records and field in records[t] + ] + if values: + per_field[field] = sum(values) / len(values) + if per_field: + costs[source] = per_field + return costs + + +def gate_zero(tags, sources, tolerance): + """Did the regenerated flat scores reproduce the archived ones? + + Reproduction is checked on ranking (rho against the same truth) and, + more strictly, per candidate: the point of `-random_seed` is that a + candidate is reproducible, so a mismatch means the rig drifted -- + a different OpenROAD, a different floorplan, a lost patch -- and + every downstream number would be measuring that instead of E12. + """ + flat = sources.get("flat", {}) + archive = sources.get("archive_proxy", {}) + usable = [t for t in tags if t in flat and t in archive] + mismatches = [] + for tag in usable: + for field in REPRODUCED_FIELDS: + want = archive[tag].get(field) + got = flat[tag].get(field) + if want is None or got is None: + mismatches.append( + {"tag": tag, "field": field, "reason": "value missing"} + ) + continue + if want == 0: + continue + relative = abs(got - want) / abs(want) + if relative > tolerance: + mismatches.append( + { + "tag": tag, + "field": field, + "archived": want, + "regenerated": got, + "relative_error": relative, + } + ) + return { + "candidates_compared": len(usable), + "fields_compared": list(REPRODUCED_FIELDS), + "relative_tolerance": tolerance, + "mismatches": mismatches, + "pass": bool(usable) and not mismatches, + } + + +def gate_one(table, expected_n): + """The E12 criterion itself.""" + entry = table.get("clustered_hpwl") + if entry is None: + return { + "pass": False, + "reason": "no clustered scores present", + } + stats = entry["kpi"][GATE_KPI] + rho = stats["rho"] + inside = FLAT_CI[0] <= rho <= FLAT_CI[1] + complete = entry["n"] == expected_n + return { + "kpi": GATE_KPI, + "rho": rho, + "ci": stats["ci"], + "flat_ci": list(FLAT_CI), + "n": entry["n"], + "expected_n": expected_n, + "inside_flat_ci": inside, + "population_complete": complete, + "pass": bool(inside and complete), + } + + +def diverged_tags(sources): + return sorted( + tag + for tag, record in sources.get("clustered", {}).items() + if record.get("diverged") + ) + + +def format_report(verdict): + lines = [] + gate0 = verdict["gate_0_rig_check"] + lines.append( + "Gate 0 (rig check): {} -- {} candidates compared, {} mismatches".format( + "PASS" if gate0["pass"] else "FAIL", + gate0["candidates_compared"], + len(gate0["mismatches"]), + ) + ) + for bad in gate0["mismatches"][:5]: + lines.append(" {}".format(bad)) + + lines.append("") + lines.append("rho vs ground truth (n, then per KPI):") + header = " {:<26} {:>3}".format("variant", "n") + for kpi in TRUTH_KPIS: + header += " {:>26}".format(kpi) + lines.append(header) + for label, entry in verdict["rho"].items(): + row = " {:<26} {:>3}".format(label, entry["n"]) + for kpi in TRUTH_KPIS: + stats = entry["kpi"][kpi] + row += " {:>+8.2f} [{:>+6.2f},{:>+6.2f}]".format( + stats["rho"], stats["ci"][0], stats["ci"][1] + ) + lines.append(row) + + if verdict["cost"]: + lines.append("") + lines.append("mean cost per candidate:") + for source, fields in verdict["cost"].items(): + lines.append(" {}:".format(source)) + for field, value in fields.items(): + lines.append(" {:<20} {:.2f}".format(field, value)) + + if verdict["diverged"]: + lines.append("") + lines.append("DIVERGED (not scorable): {}".format(verdict["diverged"])) + + gate1 = verdict["gate_1_e12"] + lines.append("") + if "reason" in gate1: + lines.append("Gate 1 (E12): FAIL -- {}".format(gate1["reason"])) + else: + lines.append( + "Gate 1 (E12): {} -- rho(clustered_hpwl vs {}) = " + "{:+.2f} [{:+.2f}, {:+.2f}], flat interval " + "[{:+.2f}, {:+.2f}], n = {}/{}".format( + "PASS" if gate1["pass"] else "FAIL", + gate1["kpi"], + gate1["rho"], + gate1["ci"][0], + gate1["ci"][1], + gate1["flat_ci"][0], + gate1["flat_ci"][1], + gate1["n"], + gate1["expected_n"], + ) + ) + return "\n".join(lines) + + +def build_verdict(truth, flat, clustered, expected_n, n_boot, tolerance): + tags, sources = collect(truth, flat, clustered) + table = rho_table(tags, sources, n_boot) + return { + "design": truth.get("design"), + "population": truth.get("population"), + "tags": tags, + "rho": table, + "cost": cost_table(tags, sources), + "diverged": diverged_tags(sources), + "gate_0_rig_check": gate_zero(tags, sources, tolerance), + "gate_1_e12": gate_one(table, expected_n), + } + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--truth", + required=True, + help="score_vs_flow_swerv.json, the committed archive", + ) + parser.add_argument( + "--evidence-dir", + required=True, + help="directory holding cand_s*.json and cand_s*.clustered.json", + ) + parser.add_argument("--out", help="write the verdict JSON here") + parser.add_argument( + "--expected-n", + type=int, + default=24, + help="candidates the gate requires (default: the archived 24)", + ) + parser.add_argument("--n-boot", type=int, default=4000) + parser.add_argument( + "--tolerance", + type=float, + default=1e-6, + help="relative tolerance for gate 0 reproduction", + ) + parser.add_argument( + "--allow-fail", + action="store_true", + help="report the verdict but exit 0 even if a gate fails", + ) + args = parser.parse_args(argv) + + verdict = build_verdict( + load_json(args.truth), + load_leaves(args.evidence_dir, ".json", exclude=(CLUSTERED_SUFFIX,)), + load_leaves(args.evidence_dir, CLUSTERED_SUFFIX), + args.expected_n, + args.n_boot, + args.tolerance, + ) + print(format_report(verdict)) + if args.out: + with open(args.out, "w", encoding="utf-8") as handle: + json.dump(verdict, handle, indent=1, sort_keys=True) + handle.write("\n") + + passed = verdict["gate_0_rig_check"]["pass"] and verdict["gate_1_e12"]["pass"] + return 0 if (passed or args.allow_fail) else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/flow/test/macro_e12/grade_e12_test.py b/flow/test/macro_e12/grade_e12_test.py new file mode 100644 index 0000000000..3da0e4cd15 --- /dev/null +++ b/flow/test/macro_e12/grade_e12_test.py @@ -0,0 +1,315 @@ +#!/usr/bin/env python3 +"""Unit tests for the E12 gate. + +These run in milliseconds on synthetic fixtures: the point is that the +gate's arithmetic and its pass/fail logic are testable without a flow +run, so a wrong verdict is caught here rather than after a 25-minute +campaign. The one test that touches real data checks that the committed +archive still reproduces the published rho of +0.72 [0.48, 0.84] -- if +that ever fails, the archive or the statistics moved and every E12 +number is void. +""" + +import json +import math +import os +import tempfile +import unittest + +import grade_e12 +from e12_stats import spearman, spearman_ci + +ARCHIVE = os.path.join(os.path.dirname(__file__), "score_vs_flow_swerv.json") + + +def make_truth(n, macro_paths, proxy_macro_mean=None): + """A minimal archive: n candidates with the given truth values.""" + candidates = {} + for i in range(n): + candidates["cand_s%d" % i] = { + "grt": { + "macro_paths_mean": macro_paths[i], + "achieved": 1000.0 + i, + "general_paths_mean": 900.0 + i, + "stdcell_um2": 10000.0 + i, + }, + "proxy": { + "macro_mean": ( + macro_paths[i] if proxy_macro_mean is None else proxy_macro_mean[i] + ), + "wq25": ( + macro_paths[i] if proxy_macro_mean is None else proxy_macro_mean[i] + ), + }, + } + return {"design": "synthetic", "candidates": candidates} + + +def make_leaves(n, flat_macro_mean, clustered_hpwl, diverged=()): + flat = {} + clustered = {} + for i in range(n): + tag = "cand_s%d" % i + flat[tag] = { + "tag": tag, + "macro_mean": flat_macro_mean[i], + "wq25": flat_macro_mean[i], + "hpwl_dbu": 1000 + i, + "gpl_s": 70.0, + } + clustered[tag] = { + "tag": tag, + "hpwl_dbu": clustered_hpwl[i], + "cone_hpwl_dbu": clustered_hpwl[i] // 2, + "diverged": 1 if tag in diverged else 0, + "gpl_s": 20.0, + "clusters_declared": 500, + } + return flat, clustered + + +class TestStats(unittest.TestCase): + def test_perfect_and_inverted_ranking(self): + xs = list(range(10)) + self.assertAlmostEqual(spearman(xs, xs), 1.0) + self.assertAlmostEqual(spearman(xs, list(reversed(xs))), -1.0) + + def test_uniform_optimism_ranks_perfectly(self): + """The premise the whole approach rests on.""" + truth = [10.0, 20.0, 30.0, 40.0] + optimistic = [0.8 * v for v in truth] + self.assertAlmostEqual(spearman(optimistic, truth), 1.0) + + def test_constant_score_is_nan_not_zero(self): + """A scorer that returns one value for every candidate ranks nothing. + + rho is undefined there, and it must surface as NaN rather than as + 0.0 -- a silent 0.0 would read as "uncorrelated" and could be + mistaken for a measurement. + """ + rho = spearman([1, 1, 1, 1], [1, 2, 3, 4]) + self.assertTrue(math.isnan(rho)) + + def test_ci_is_deterministic_and_brackets_rho(self): + xs = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8] + ys = [2, 7, 1, 8, 2, 8, 1, 8, 2, 8, 4, 5] + first = spearman_ci(xs, ys, n_boot=200) + second = spearman_ci(xs, ys, n_boot=200) + self.assertEqual(first, second) + low, high = first + self.assertLessEqual(low, high) + + +class TestGateZero(unittest.TestCase): + def test_exact_reproduction_passes(self): + values = [100.0 + i for i in range(24)] + truth = make_truth(24, values) + flat, clustered = make_leaves(24, values, list(range(24))) + verdict = grade_e12.build_verdict(truth, flat, clustered, 24, 100, 1e-6) + self.assertTrue(verdict["gate_0_rig_check"]["pass"]) + self.assertEqual(verdict["gate_0_rig_check"]["candidates_compared"], 24) + + def test_drifted_candidate_fails_and_is_named(self): + values = [100.0 + i for i in range(24)] + drifted = list(values) + drifted[7] = values[7] * 1.05 + truth = make_truth(24, values) + flat, clustered = make_leaves(24, drifted, list(range(24))) + verdict = grade_e12.build_verdict(truth, flat, clustered, 24, 100, 1e-6) + gate0 = verdict["gate_0_rig_check"] + self.assertFalse(gate0["pass"]) + self.assertEqual(sorted({m["tag"] for m in gate0["mismatches"]}), ["cand_s7"]) + + def test_no_candidates_is_a_failure_not_a_pass(self): + truth = make_truth(4, [1.0, 2.0, 3.0, 4.0]) + verdict = grade_e12.build_verdict(truth, {}, {}, 4, 100, 1e-6) + self.assertFalse(verdict["gate_0_rig_check"]["pass"]) + + +class TestGateOne(unittest.TestCase): + def _verdict(self, clustered_hpwl, expected_n=24, diverged=()): + values = [100.0 + i for i in range(24)] + truth = make_truth(24, values) + flat, clustered = make_leaves(24, values, clustered_hpwl, diverged) + return grade_e12.build_verdict(truth, flat, clustered, expected_n, 200, 1e-6) + + def test_perfectly_ranking_clustered_score_is_above_the_interval(self): + """rho = 1.0 is outside [0.48, 0.84], so it must not pass silently. + + The criterion is "indistinguishable from flat", not "at least as + good as flat": a score that ranks the archive perfectly on n = 24 + is a signal to check for leakage, not to celebrate. + """ + verdict = self._verdict(list(range(24))) + gate1 = verdict["gate_1_e12"] + self.assertAlmostEqual(gate1["rho"], 1.0) + self.assertFalse(gate1["inside_flat_ci"]) + self.assertFalse(gate1["pass"]) + + def test_score_inside_the_flat_interval_passes(self): + # Swap enough neighbouring pairs to land rho in [0.48, 0.84]. + order = list(range(24)) + for i in range(0, 24, 2): + order[i], order[i + 1] = order[i + 1], order[i] + order[0], order[17] = order[17], order[0] + order[3], order[20] = order[20], order[3] + verdict = self._verdict(order) + gate1 = verdict["gate_1_e12"] + self.assertTrue( + grade_e12.FLAT_CI[0] <= gate1["rho"] <= grade_e12.FLAT_CI[1], + "fixture rho %.3f outside the interval it is meant to hit" % gate1["rho"], + ) + self.assertTrue(gate1["pass"]) + + def test_inverted_score_fails(self): + verdict = self._verdict(list(reversed(range(24)))) + self.assertLess(verdict["gate_1_e12"]["rho"], 0) + self.assertFalse(verdict["gate_1_e12"]["pass"]) + + def test_short_population_fails_even_with_good_rho(self): + verdict = self._verdict(list(range(24)), expected_n=30) + gate1 = verdict["gate_1_e12"] + self.assertFalse(gate1["population_complete"]) + self.assertFalse(gate1["pass"]) + + def test_missing_clustered_scores_fail_with_a_reason(self): + values = [100.0 + i for i in range(24)] + truth = make_truth(24, values) + flat, _ = make_leaves(24, values, list(range(24))) + verdict = grade_e12.build_verdict(truth, flat, {}, 24, 100, 1e-6) + self.assertFalse(verdict["gate_1_e12"]["pass"]) + self.assertIn("reason", verdict["gate_1_e12"]) + + def test_divergence_is_surfaced(self): + verdict = self._verdict(list(range(24)), diverged=("cand_s3",)) + self.assertEqual(verdict["diverged"], ["cand_s3"]) + + +class TestLeafLoading(unittest.TestCase): + def test_clustered_leaves_do_not_masquerade_as_flat(self): + with tempfile.TemporaryDirectory() as tmp: + for name, body in ( + ("cand_s0.json", {"tag": "cand_s0", "macro_mean": 1.0}), + ("cand_s0.clustered.json", {"tag": "cand_s0", "hpwl_dbu": 2}), + ): + with open(os.path.join(tmp, name), "w", encoding="utf-8") as fp: + json.dump(body, fp) + flat = grade_e12.load_leaves( + tmp, ".json", exclude=(grade_e12.CLUSTERED_SUFFIX,) + ) + clustered = grade_e12.load_leaves(tmp, grade_e12.CLUSTERED_SUFFIX) + self.assertEqual(sorted(flat), ["cand_s0"]) + self.assertEqual(sorted(clustered), ["cand_s0"]) + + +class TestCommittedArchive(unittest.TestCase): + """The archive is the reference; guard the number it is referenced for.""" + + def setUp(self): + if not os.path.exists(ARCHIVE): + self.skipTest("archive fixture not present") + with open(ARCHIVE, encoding="utf-8") as handle: + self.truth = json.load(handle) + self.tags = sorted(self.truth["candidates"]) + + def _rho(self, block, field, kpi): + """rho and CI between a score column and a ground-truth KPI. + + `block` is the per-candidate sub-dict holding the score, or None + when the score sits directly on the candidate record. + """ + candidates = self.truth["candidates"] + scores = [ + candidates[t][block][field] if block else candidates[t][field] + for t in self.tags + ] + truth = [candidates[t]["grt"][kpi] for t in self.tags] + low, high = spearman_ci(scores, truth) + return spearman(scores, truth), low, high + + def test_population_is_the_published_24(self): + self.assertEqual(len(self.truth["candidates"]), 24) + + def test_flat_scorer_reproduces_published_rho_and_interval(self): + """rho(proxy wq25, grt macro_paths_mean) == +0.72 [0.48, 0.84]. + + This exact pairing is the one the published figure reports, and + grade_e12.FLAT_CI is its interval. Pinning it here is what stops + the gate from being silently re-based on a different column -- + the archive holds several score columns, and a neighbouring one + (proxy macro_mean) sits a full 0.09 higher. + """ + rho, low, high = self._rho("proxy", "wq25", "macro_paths_mean") + self.assertAlmostEqual(rho, 0.72, delta=0.005) + self.assertAlmostEqual(low, grade_e12.FLAT_CI[0], delta=0.005) + self.assertAlmostEqual(high, grade_e12.FLAT_CI[1], delta=0.005) + + def test_corroborating_published_numbers(self): + """Three more published numbers off the same archive. + + If these reproduce alongside the reference, the archive and the + statistics really are the ones the published figure was made + with -- a far stronger check than any single correlation. + """ + # The in-anneal objective, published at +0.57 [0.24, 0.79]: the + # cost function ranks the truth materially worse than a measured + # placement does, which is why selection is not left to it. + rho, low, high = self._rho(None, "objective_fixed_norm", "macro_paths_mean") + self.assertAlmostEqual(rho, 0.57, delta=0.01) + self.assertAlmostEqual(low, 0.24, delta=0.01) + self.assertAlmostEqual(high, 0.79, delta=0.01) + + # Score versus area, published at +0.65 (proxy) and +0.47 + # (objective): the fog flattens period by spending area. + rho, _, _ = self._rho("proxy", "wq25", "stdcell_um2") + self.assertAlmostEqual(rho, 0.65, delta=0.01) + rho, _, _ = self._rho(None, "objective_fixed_norm", "stdcell_um2") + self.assertAlmostEqual(rho, 0.47, delta=0.02) + + def test_period_column_is_interchangeable_with_the_reference(self): + """The reference scalar is not a fragile choice of column. + + proxy `period` and proxy `wq25` differ by construction but rank + the truth within 0.01 of each other on identical intervals, so + the +0.72 reference is a property of the flat rung rather than of + which of its two aggregates was tabulated. + """ + ref_rho, ref_low, ref_high = self._rho("proxy", "wq25", "macro_paths_mean") + alt_rho, alt_low, alt_high = self._rho("proxy", "period", "macro_paths_mean") + self.assertAlmostEqual(alt_rho, ref_rho, delta=0.01) + self.assertAlmostEqual(alt_low, ref_low, delta=0.01) + self.assertAlmostEqual(alt_high, ref_high, delta=0.01) + + def test_macro_path_scalar_ranks_better_than_the_reference(self): + """Load-bearing for reading the verdict, so pinned here. + + The reference is the conservative scalar. A clustered score + landing at, say, +0.75 is inside the gate yet still below what + the flat rung's best scalar achieves; the verdict table reports + both columns so that distinction stays visible instead of being + buried by a pass. + """ + reference, _, _ = self._rho("proxy", "wq25", "macro_paths_mean") + best, best_low, _ = self._rho("proxy", "macro_mean", "macro_paths_mean") + self.assertGreater(best, reference) + self.assertAlmostEqual(best, 0.82, delta=0.01) + self.assertGreater(best_low, grade_e12.FLAT_CI[0]) + + def test_period_at_this_utilization_is_placement_insensitive(self): + """Why the gate rides on the macro-path KPI and not on period. + + At this utilization every candidate ties on achieved period -- + the whole population fits inside the design's own noise band -- + so a scorer graded on period would be graded on noise. The + macro-path aggregate is the KPI that actually moves. + """ + candidates = self.truth["candidates"] + delta_tie = self.truth["delta_tie"]["achieved"] + achieved = [candidates[t]["grt"]["achieved"] for t in self.tags] + macro = [candidates[t]["grt"]["macro_paths_mean"] for t in self.tags] + self.assertLess(max(achieved) - min(achieved), delta_tie) + self.assertGreater(max(macro) - min(macro), delta_tie) + + +if __name__ == "__main__": + unittest.main() diff --git a/flow/test/macro_e12/macro_e12.tcl b/flow/test/macro_e12/macro_e12.tcl new file mode 100644 index 0000000000..da90533297 --- /dev/null +++ b/flow/test/macro_e12/macro_e12.tcl @@ -0,0 +1,254 @@ +# E12 step 0: regenerate the candidate population and re-measure it with +# the flat scorer. +# +# Why this step exists at all. The E12 question is whether a *clustered* +# global placement ranks macro-placement candidates as well as a flat +# one. The reference it is graded against is a committed archive of 24 +# swerv_wrapper candidates scored by the flat rung and then carried +# through the full production tail to global route +# (score_vs_flow_swerv.json). The candidate placements themselves were +# never committed, so they have to be regenerated here -- and nothing +# downstream is interpretable until the regenerated flat scores +# reproduce the archived ones. This script is therefore both the +# candidate generator and the rig check. +# +# The population comes from rtl_macro_placer -random_seed 0..k-1: the +# macro placer is used as a distribution generator, not as an optimizer. +# Its annealing cost picks the better of two of its own placements at +# roughly coin-flip probability, so the selection intelligence has to +# live in a score measured after the fact, not in the cost function. +# +# One production floorplan spine is shared; candidates diverge only at +# macro_place, so the fork copy-on-write snapshot pays for the whole +# shared prefix. Two execution shapes, selected by E12_SERIAL_THREADS: +# +# 0 (default) fork -jobs $E12_JOBS: candidates in parallel, +# single-threaded each (a fork child must not raise its +# own thread count). +# N > 0 no fork: candidates run sequentially in the parent with +# set_thread_count N. Kept because it is the only shape +# that can be compared against the clustered scorer's +# threading behaviour. + +source $::env(ORFS_FORK_TCL) +set e12_dir [file dirname [file normalize [info script]]] +source [file join $e12_dir e12_lib.tcl] +source [file join $e12_dir extract_lib.tcl] + +set ::e12_out [e12_env E12_OUT_DIR [e12_env RUN_OUTPUT_DIR ""]] +if { $::e12_out eq "" } { + error "macro_e12: set E12_OUT_DIR or declare out_dir" +} +set ::e12_work [e12_env E12_WORK [file join $::env(WORK_HOME) e12_work]] +set ::e12_k [e12_env E12_K 24] +set ::e12_jobs [e12_env E12_JOBS 12] +set ::e12_serial_threads [e12_env E12_SERIAL_THREADS 0] +set ::e12_fork_opts [list -timeout [e12_env E12_CHILD_TIMEOUT 14400]] +file mkdir $::e12_out + +set ::env(KEEP_VARS) 1 +set ::env(SKIP_REPORT_METRICS) 1 + +# -------------------------------------------------------------------- +# The flat scoring rung, kept as the control. +# +# Non-timing-driven and non-routability-driven on purpose: the score is +# a measurement taken on the far side of the fog, and it prices density +# and congestion implicitly by actually doing the placement. The STA +# readout is retained here only because the archived reference numbers +# include it -- for ranking it is known to be droppable (raw HPWL alone +# ranks the ground truth nearly as well). +proc e12_score_flat { } { + set t0 [clock clicks -milliseconds] + if { ![info exists ::e12_pins_placed] } { + if { [e12_env IO_CONSTRAINTS ""] ne "" } { + uplevel #0 [list source $::env(IO_CONSTRAINTS)] + } + place_pins -hor_layers $::env(IO_PLACER_H) \ + -ver_layers $::env(IO_PLACER_V) + set ::e12_pins_placed 1 + } + set cell_pad [e12_env CELL_PAD_IN_SITES_GLOBAL_PLACEMENT 0] + set gp_args [list -density [place_density_with_lb_addon] \ + -pad_left $cell_pad -pad_right $cell_pad \ + -force_center_initial_place] + global_placement {*}$gp_args + set gpl_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + + # The HPWL readout the clustered scorer will use, measured here too so + # the two rungs are compared on the same scalar as well as on the STA + # aggregates. + set block [ord::get_db_block] + set hpwl_dbu [e12_hpwl_dbu [e12_signal_nets $block]] + + set t0 [clock clicks -milliseconds] + estimate_parasitics -placement + set_propagated_clock [all_clocks] + set sample [extract_sample_paths] + set sta_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + + set wq25_sum 0.0 + set wq25_n 0 + set macro_sum 0.0 + set macro_n 0 + foreach pt [dict get $sample paths] { + set period [lindex $pt 2] + if { [lindex $pt 3] } { + set macro_sum [expr { $macro_sum + $period }] + incr macro_n + } else { + set wq25_sum [expr { $wq25_sum + $period }] + incr wq25_n + } + } + + return [dict create \ + clock_period [dict get $sample clock_period] \ + wns [dict get $sample wns] \ + period [expr { [dict get $sample clock_period] - [dict get $sample wns] }] \ + wq25 [expr { $wq25_n ? $wq25_sum / $wq25_n : 0.0 }] \ + macro_mean [expr { $macro_n ? $macro_sum / $macro_n : 0.0 }] \ + hpwl_dbu $hpwl_dbu \ + gpl_s $gpl_s \ + sta_s $sta_s \ + sample $sample] +} + +# One candidate: seeded production macro placement, then the flat rung. +# Runs inside a fork child (parallel shape) or inline in the parent +# (serial shape). +proc e12_candidate { seed } { + set tag cand_s$seed + e12_redirect $tag + e12_wrap_placer [list -random_seed $seed] + set t0 [clock clicks -milliseconds] + e12_step macro_place.tcl + set place_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + + # Archive the production macro-placement script and the post-macro + # database. The clustered scorer reads the .odb back rather than + # regenerating the candidate, so generation is paid exactly once. + file copy -force \ + [file join $::env(RESULTS_DIR) 2_2_floorplan_macro.tcl] \ + [file join $::e12_out $tag.place.tcl] + write_db [file join $::e12_out $tag.odb] + + set score [e12_score_flat] + e12_write_leaf [file join $::e12_out $tag.json] [list \ + tag $tag \ + seed $seed \ + time_unit "[sta::unit_scale_abbreviation time][sta::unit_suffix time]" \ + clock_period [dict get $score clock_period] \ + wns [dict get $score wns] \ + period [dict get $score period] \ + wq25 [dict get $score wq25] \ + macro_mean [dict get $score macro_mean] \ + hpwl_dbu [dict get $score hpwl_dbu] \ + macro_place_s $place_s \ + gpl_s [dict get $score gpl_s] \ + sta_s [dict get $score sta_s] \ + vmhwm_kb [e12_vmhwm_kb]] + puts "e12: leaf $tag done (macro_place ${place_s}s,\ + gpl [dict get $score gpl_s]s)" +} + +# In-parent reset between serial candidates: macros back to unfixed and +# unplaced, standard cells and pins unplaced, macro soft blockages gone. +# Fork children never need this -- each inherits the pristine +# post-floorplan snapshot. +proc e12_reset_placement { } { + set blk [ord::get_db_block] + foreach inst [$blk getInsts] { + if { [[$inst getMaster] isBlock] } { + $inst setPlacementStatus NONE + $inst setOrient R0 + $inst setLocation 0 0 + } elseif { [$inst isPlaced] } { + $inst setPlacementStatus NONE + } + } + foreach blockage [$blk getBlockages] { + odb::dbBlockage_destroy $blockage + } + foreach bterm [$blk getBTerms] { + foreach bpin [$bterm getBPins] { + odb::dbBPin_destroy $bpin + } + } + unset -nocomplain ::e12_pins_placed + unset_propagated_clock [all_clocks] +} + +# -------------------------------------------------------------------- +# The walk. + +set seeds {} +for { set i 0 } { $i < $::e12_k } { incr i } { + lappend seeds $i +} +puts "e12: [llength $seeds] candidates,\ + [expr { + $::e12_serial_threads > 0 ? + "serial with $::e12_serial_threads threads" : + "fork -jobs $::e12_jobs" +}]" + +e12_redirect spine +file copy -force $::env(ODB_FILE) \ + [file join $::env(RESULTS_DIR) 1_synth.odb] +file copy -force [file rootname $::env(ODB_FILE)].sdc \ + [file join $::env(RESULTS_DIR) 1_synth.sdc] +set t0 [clock clicks -milliseconds] +e12_step floorplan.tcl +set ::e12_prefix_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + +# The base floorplan, before any candidate's macro placement: the +# clustered scorer's cluster partition is derived from this, once, and +# shared by every candidate. That sharing is what makes the reduction +# common-mode across candidates, which is what protects the ranking. +# +# Archived as the .odb/.sdc pair ORFS's own load_design expects, because +# the later steps re-enter through the ORFS stage machinery rather than +# calling read_db themselves -- a bare read_db would skip liberty and SDC +# setup and leave the ORFS helper procs undefined. +foreach ext {odb sdc} { + file copy -force \ + [file join $::env(RESULTS_DIR) 2_1_floorplan.$ext] \ + [file join $::e12_out base_floorplan.$ext] +} + +set failed {} +if { $::e12_serial_threads > 0 } { + set_thread_count $::e12_serial_threads + foreach seed $seeds { + if { [catch { e12_candidate $seed } err] } { + puts stderr "e12: candidate s$seed failed: $err" + lappend failed s$seed + } + e12_reset_placement + } +} else { + set statuses [fork -jobs $::e12_jobs {*}$::e12_fork_opts seed $seeds { + e12_candidate $seed + }] + dict for {seed code} $statuses { + if { $code != 0 } { + puts stderr "e12: candidate s$seed failed with status $code;\ + its outputs are missing" + lappend failed s$seed + } + } +} + +set scored 0 +foreach seed $seeds { + if { [file exists [file join $::e12_out cand_s$seed.json]] } { + incr scored + } +} +puts "e12: $scored/[llength $seeds] candidates scored,\ + prefix ${::e12_prefix_s}s" +if { $scored == 0 } { + error "macro_e12: no candidate produced a score" +} +exit 0 diff --git a/flow/test/macro_e12/score_clustered.tcl b/flow/test/macro_e12/score_clustered.tcl new file mode 100644 index 0000000000..183a1910b5 --- /dev/null +++ b/flow/test/macro_e12/score_clustered.tcl @@ -0,0 +1,240 @@ +# E12 step 2: the clustered scorer. +# +# Score one candidate by spreading RTL-MP's std-cell clusters around that +# candidate's fixed macros and reading half-perimeter wirelength. The +# whole solve is stock gpl: +# +# placement_cluster {inst ...} makes N instances one movable +# (gpl builds one GCell per cluster and +# measures pin offsets against the +# cluster centre, so intra-cluster nets +# collapse and inter-cluster nets are +# measured centre-to-centre -- bundled +# nets, for free) +# global_placement -overflow stops the Nesterov solve early +# +# Nothing here reimplements a field solver, which is deliberate: the +# object being graded has to be the solver that would actually ship, not +# a model of it. +# +# Macros stay fixed instances with their real masters, so macro pin +# geometry is exact. Clustering would otherwise smear precisely the pins +# the live KPI reads. The instances within E12_HALO_HOPS of a macro pin +# are additionally kept out of every cluster, so they remain individual +# movables with exact offsets -- halo-flat coarsening, expressed purely +# as an omission. +# +# Report-only: the score is read out of odb after the solve and this +# process exits. It never writes the design back. One candidate per +# process is mandatory, not stylistic -- gpl's Replace::reset() does not +# clear its cluster list, and gpl does write GCell locations into odb. + +set e12_dir [file dirname [file normalize [info script]]] +source [file join $e12_dir e12_lib.tcl] + +set ::e12_out [e12_env E12_OUT_DIR [e12_env RUN_OUTPUT_DIR ""]] +if { $::e12_out eq "" } { + error "score_clustered: set E12_OUT_DIR or declare out_dir" +} +set tag [e12_env E12_TAG ""] +if { $tag eq "" } { + error "score_clustered: set E12_TAG to the candidate tag (eg cand_s0)" +} +set ::e12_work [e12_env E12_WORK [file join $::env(WORK_HOME) e12_work]] +set cand_odb [e12_env E12_CAND_ODB [file join $::e12_out $tag.odb]] +set base_sdc [e12_env E12_BASE_SDC [file join $::e12_out base_floorplan.sdc]] +set clusters_txt [e12_env E12_CLUSTERS [file join $::e12_out clusters.txt]] +foreach f [list $cand_odb $base_sdc $clusters_txt] { + if { ![file exists $f] } { + error "score_clustered: missing $f" + } +} + +# Pre-registered primary configuration. These are not per-design knobs: +# the hop count is a small integer justified by the fidelity argument +# above, the overflow target is a dimensionless placement invariant +# validated once against the archived trajectories, and the large-net +# threshold mirrors the value RTL-MP's own clustering uses. See README.md +# -- any run that departs from these is exploratory, not a gate result. +set hops [e12_env E12_HALO_HOPS 1] +set overflow [e12_env E12_OVERFLOW 0.6] +set large_net [e12_env E12_LARGE_NET_THRESHOLD 50] +set bin_grid_count [e12_env E12_BIN_GRID_COUNT 0] + +# Thread count is a determinism control, not a tuning knob: the same +# candidate scored at different thread counts must produce a +# bit-identical score. gpl's density scatter accumulates into int64 bins, +# so the sum is over a fixed multiset and is thread-count invariant by +# construction; this exists so that claim is checked rather than assumed. +set threads [e12_env E12_THREADS 0] +if { $threads > 0 } { + set_thread_count $threads +} + +# Enter through ORFS's own loading path rather than calling read_db: +# load_design also reads liberty, the SDC and the platform setup, and +# load.tcl is where the ORFS helper procs this script uses come from +# (place_density_with_lb_addon among them). The candidate is staged under +# the stem the macro-placement stage writes, and its SDC is the base +# floorplan's -- macro placement does not change constraints. +set ::env(KEEP_VARS) 1 +set ::env(SKIP_REPORT_METRICS) 1 +e12_redirect $tag +source $::env(SCRIPTS_DIR)/load.tcl +set stem 2_2_floorplan_macro +file copy -force $cand_odb [file join $::env(RESULTS_DIR) $stem.odb] +file copy -force $base_sdc [file join $::env(RESULTS_DIR) $stem.sdc] +load_design $stem.odb $stem.sdc + +set block [ord::get_db_block] + +# -------------------------------------------------------------------- +# Halo-flat set and the macro cone, from one traversal. + +set t0 [clock clicks -milliseconds] +set bfs [e12_macro_bfs $block $hops $large_net] +set halo_ids [e12_halo_flat_ids $bfs $hops] +set macro_ids [dict get $bfs macros] +set cone_net_ids [dict get $bfs cone_nets$hops] +set bfs_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + +set excluded {} +foreach id $halo_ids { + dict set excluded $id 1 +} +foreach id $macro_ids { + dict set excluded $id 1 +} + +# -------------------------------------------------------------------- +# Declare the clusters. + +set t0 [clock clicks -milliseconds] +set fp [open $clusters_txt r] +set cluster_members [dict create] +set cluster_order {} +set unresolved 0 +while { [gets $fp line] >= 0 } { + if { [string index $line 0] eq "#" || [string trim $line] eq "" } { + continue + } + set cname [lindex $line 0] + # The instance name is the remainder of the line, not just field 3, so + # a name containing a space cannot silently truncate. + set iname [join [lrange $line 2 end] " "] + + # Match by name, not by odb id. clusters.txt is written from the base + # floorplan database and consumed against a candidate's, and while + # macro placement creates no instances, an id is an internal handle + # whose stability across databases is not something to bet a + # measurement on. Names come from the netlist and are stable by + # construction. + set inst [$block findInst $iname] + if { $inst eq "NULL" || $inst eq "" } { + incr unresolved + continue + } + if { [dict exists $excluded [$inst getId]] } { + continue + } + if { [[$inst getMaster] isBlock] || [$inst isFixed] } { + continue + } + if { ![dict exists $cluster_members $cname] } { + lappend cluster_order $cname + } + dict lappend cluster_members $cname $inst +} +close $fp + +# An unresolved name means the partition and the candidate disagree about +# the netlist, which would silently leave those cells as their own +# movables and quietly weaken the reduction. Fail instead. +if { $unresolved > 0 } { + error "score_clustered: $unresolved instance names in $clusters_txt\ + do not exist in $cand_odb -- the cluster partition and the candidate\ + were not built from the same netlist" +} + +# A cluster of one instance is not a reduction, it is just a rename, and +# gpl logs one message per declared cluster; skip them. +set declared 0 +set clustered_insts 0 +foreach cname [lsort -ascii $cluster_order] { + set members [dict get $cluster_members $cname] + if { [llength $members] < 2 } { + continue + } + gpl::placement_cluster_cmd $members + incr declared + incr clustered_insts [llength $members] +} +set cluster_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] +puts "e12: $tag declared $declared clusters over $clustered_insts\ + instances, $hops-hop halo keeps [llength $halo_ids] flat" + +# -------------------------------------------------------------------- +# The solve. + +set cell_pad [e12_env CELL_PAD_IN_SITES_GLOBAL_PLACEMENT 0] +set gp_args [list -density [place_density_with_lb_addon] \ + -pad_left $cell_pad -pad_right $cell_pad \ + -force_center_initial_place \ + -overflow $overflow] +if { $bin_grid_count > 0 } { + lappend gp_args -bin_grid_count $bin_grid_count +} + +set t0 [clock clicks -milliseconds] +set diverged 0 +if { [catch { global_placement {*}$gp_args } err] } { + puts stderr "e12: $tag global_placement failed: $err" + set diverged 1 +} +set gpl_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + +# -------------------------------------------------------------------- +# Readout. +# +# Two scores off the same final placement. Full HPWL is the flat rung's +# scalar. Macro-cone HPWL restricts the sum to the nets within the halo +# BFS, on the argument that a score whose magnitude is dominated by +# wirelength the KPI never reads is spending its resolution in the wrong +# place. Which of the two ranks better is a measurement, not a +# preference, and it costs one extra pass over odb. +set all_nets [e12_signal_nets $block] +set hpwl_dbu [e12_hpwl_dbu $all_nets] + +set cone_nets {} +foreach id $cone_net_ids { + set net [odb::dbNet_getNet $block $id] + if { $net ne "NULL" && $net ne "" } { + lappend cone_nets $net + } +} +set cone_hpwl_dbu [e12_hpwl_dbu $cone_nets] + +e12_write_leaf [file join $::e12_out $tag.clustered.json] [list \ + tag $tag \ + hpwl_dbu $hpwl_dbu \ + cone_hpwl_dbu $cone_hpwl_dbu \ + diverged $diverged \ + halo_hops $hops \ + overflow_target $overflow \ + bin_grid_count $bin_grid_count \ + large_net_threshold $large_net \ + threads $threads \ + clusters_declared $declared \ + clustered_insts $clustered_insts \ + halo_flat_insts [llength $halo_ids] \ + macros [llength $macro_ids] \ + signal_nets [llength $all_nets] \ + cone_nets [llength $cone_nets] \ + bfs_s $bfs_s \ + cluster_s $cluster_s \ + gpl_s $gpl_s \ + vmhwm_kb [e12_vmhwm_kb]] + +puts "e12: $tag hpwl $hpwl_dbu dbu, cone $cone_hpwl_dbu dbu,\ + gpl ${gpl_s}s, diverged $diverged" +exit 0 diff --git a/flow/test/macro_e12/score_vs_flow_swerv.json b/flow/test/macro_e12/score_vs_flow_swerv.json new file mode 100644 index 0000000000..1ea6f94280 --- /dev/null +++ b/flow/test/macro_e12/score_vs_flow_swerv.json @@ -0,0 +1,382 @@ +{ + "design": "swerv_wrapper (asap7)", + "population": "rtl_macro_placer -random_seed 0..23, one shared floorplan", + "normalization_base": "cand_s0 raw components", + "delta_tie": { + "achieved": 48.804872122250636, + "area": 472.52457168032174, + "mean": 26.481924665233148, + "p90": 64.2260198752228, + "p95": 49.84886571983408, + "p99": 57.4838567749464, + "power_todo": 472.52457168032174, + "ppa_geomean": 201.5070523793134, + "top10_mean": 57.35000360101685, + "top20_mean": 52.85615234117055, + "top5_mean": 55.119849948555206, + "trimmed_mean_10": 28.210755009513864 + }, + "determinism": "24/24 generate-pass place.tcl bit-identical to the selector run's, across the 0045 binary change", + "candidates": { + "cand_s0": { + "grt": { + "achieved": 1582.748911, + "general_paths_mean": 1403.8184252899998, + "macro_paths_mean": 1235.9457100191082, + "stdcell_um2": 15087.529799993243, + "tail_s": 7421.937 + }, + "proxy": { + "wq25": 2785.7330548953487, + "macro_mean": 2124.174553075, + "period": 3160.3577880000003 + }, + "objective_fixed_norm": 210.1 + }, + "cand_s1": { + "grt": { + "achieved": 1595.192956, + "general_paths_mean": 1415.19914468, + "macro_paths_mean": 1081.4538572115384, + "stdcell_um2": 14877.57779999275, + "tail_s": 7340.781999999999 + }, + "proxy": { + "wq25": 1679.0540383595505, + "macro_mean": 1201.8567669485294, + "period": 1919.251617 + }, + "objective_fixed_norm": 155.23807531128625 + }, + "cand_s2": { + "grt": { + "achieved": 1596.26521, + "general_paths_mean": 1416.16698451, + "macro_paths_mean": 1123.4850838227849, + "stdcell_um2": 14895.175859992914, + "tail_s": 7344.59 + }, + "proxy": { + "wq25": 1624.24137036, + "macro_mean": 1239.0146795746266, + "period": 1831.880066 + }, + "objective_fixed_norm": 203.29521073099892 + }, + "cand_s3": { + "grt": { + "achieved": 1594.025224, + "general_paths_mean": 1414.3968785099999, + "macro_paths_mean": 1308.17736188125, + "stdcell_um2": 14940.98621999304, + "tail_s": 5878.121999999999 + }, + "proxy": { + "wq25": 2315.489884940476, + "macro_mean": 1978.3974542125022, + "period": 2642.493774 + }, + "objective_fixed_norm": 221.88486263286165 + }, + "cand_s4": { + "grt": { + "achieved": 1598.979483, + "general_paths_mean": 1418.7036669600002, + "macro_paths_mean": 1107.137686386076, + "stdcell_um2": 14757.482339992594, + "tail_s": 6005.616 + }, + "proxy": { + "wq25": 1697.4712668470586, + "macro_mean": 1504.1807767115388, + "period": 1932.696747 + }, + "objective_fixed_norm": 167.67815829627295 + }, + "cand_s5": { + "grt": { + "achieved": 1597.65965, + "general_paths_mean": 1417.2118528100002, + "macro_paths_mean": 1240.990822103896, + "stdcell_um2": 14886.661139992899, + "tail_s": 5985.956 + }, + "proxy": { + "wq25": 2248.4200519625006, + "macro_mean": 1786.3618813999994, + "period": 2576.470825 + }, + "objective_fixed_norm": 158.6009501020616 + }, + "cand_s6": { + "grt": { + "achieved": 1594.705347, + "general_paths_mean": 1414.7081479, + "macro_paths_mean": 1263.7041177350993, + "stdcell_um2": 14844.116699992686, + "tail_s": 5924.09 + }, + "proxy": { + "wq25": 2171.54877198, + "macro_mean": 1929.5214547812502, + "period": 2461.076355 + }, + "objective_fixed_norm": 213.01561734250174 + }, + "cand_s7": { + "grt": { + "achieved": 1588.861355, + "general_paths_mean": 1408.2736799900001, + "macro_paths_mean": 1275.835121673077, + "stdcell_um2": 14839.39277999264, + "tail_s": 5702.396000000001 + }, + "proxy": { + "wq25": 2422.3405354057973, + "macro_mean": 1939.7175586750004, + "period": 2757.612305 + }, + "objective_fixed_norm": 164.82517049708605 + }, + "cand_s8": { + "grt": { + "achieved": 1595.647481, + "general_paths_mean": 1414.06416133, + "macro_paths_mean": 1148.860766, + "stdcell_um2": 14879.852279992965, + "tail_s": 5841.294 + }, + "proxy": { + "wq25": 1642.6493030918361, + "macro_mean": 1432.0329670838712, + "period": 1855.6187439999999 + }, + "objective_fixed_norm": 145.5630043623018 + }, + "cand_s9": { + "grt": { + "achieved": 1590.666355, + "general_paths_mean": 1411.28152134, + "macro_paths_mean": 1142.684771012658, + "stdcell_um2": 14799.006179992599, + "tail_s": 5847.888999999999 + }, + "proxy": { + "wq25": 1707.6986122413803, + "macro_mean": 1422.9825081301371, + "period": 1954.35321 + }, + "objective_fixed_norm": 155.38060771475108 + }, + "cand_s10": { + "grt": { + "achieved": 1575.92992, + "general_paths_mean": 1398.42421444, + "macro_paths_mean": 1045.3085161910828, + "stdcell_um2": 14804.692379992743, + "tail_s": 7371.063 + }, + "proxy": { + "wq25": 1561.9627739247314, + "macro_mean": 1147.4310488653841, + "period": 1776.219147 + }, + "objective_fixed_norm": 130.3560730617159 + }, + "cand_s11": { + "grt": { + "achieved": 1585.957011, + "general_paths_mean": 1407.21875284, + "macro_paths_mean": 1188.33613418239, + "stdcell_um2": 15074.072459993218, + "tail_s": 7101.718 + }, + "proxy": { + "wq25": 1835.7560257127668, + "macro_mean": 1516.627099319728, + "period": 2076.721649 + }, + "objective_fixed_norm": 198.02795323946958 + }, + "cand_s12": { + "grt": { + "achieved": 1576.806774, + "general_paths_mean": 1398.7534094848486, + "macro_paths_mean": 1183.3355096792452, + "stdcell_um2": 14896.385999992777, + "tail_s": 7273.522 + }, + "proxy": { + "wq25": 1767.4649063333331, + "macro_mean": 1391.8813344379082, + "period": 1996.806366 + }, + "objective_fixed_norm": 277.70194392328966 + }, + "cand_s13": { + "grt": { + "achieved": 1583.464783, + "general_paths_mean": 1403.28210628, + "macro_paths_mean": 1218.7480005350317, + "stdcell_um2": 14920.67627999287, + "tail_s": 7062.302 + }, + "proxy": { + "wq25": 2526.7118175797095, + "macro_mean": 1897.7819729187493, + "period": 2880.826416 + }, + "objective_fixed_norm": 170.80083453756492 + }, + "cand_s14": { + "grt": { + "achieved": 1599.745537, + "general_paths_mean": 1418.8605809, + "macro_paths_mean": 1107.614842899371, + "stdcell_um2": 14819.899319992739, + "tail_s": 7094.92 + }, + "proxy": { + "wq25": 1821.6865765567009, + "macro_mean": 1602.7377526535945, + "period": 2065.885223 + }, + "objective_fixed_norm": 145.9421042740381 + }, + "cand_s15": { + "grt": { + "achieved": 1590.503819, + "general_paths_mean": 1411.7665251414141, + "macro_paths_mean": 1096.2743299625001, + "stdcell_um2": 15000.297659993184, + "tail_s": 6969.194 + }, + "proxy": { + "wq25": 1771.913401646465, + "macro_mean": 1358.6593544266668, + "period": 1998.766235 + }, + "objective_fixed_norm": 138.6160664732022 + }, + "cand_s16": { + "grt": { + "achieved": 1597.029265, + "general_paths_mean": 1416.3015742900002, + "macro_paths_mean": 1152.1485191582278, + "stdcell_um2": 14728.132799992462, + "tail_s": 6435.919 + }, + "proxy": { + "wq25": 1545.3409990300006, + "macro_mean": 1510.885217171052, + "period": 1743.516525 + }, + "objective_fixed_norm": 163.74623541028078 + }, + "cand_s17": { + "grt": { + "achieved": 1590.832666, + "general_paths_mean": 1411.1411350800001, + "macro_paths_mean": 1118.133133819355, + "stdcell_um2": 14830.513559992642, + "tail_s": 7384.843000000001 + }, + "proxy": { + "wq25": 1567.7535892959181, + "macro_mean": 1276.4188487852343, + "period": 1774.731674 + }, + "objective_fixed_norm": 174.29403438699907 + }, + "cand_s18": { + "grt": { + "achieved": 1591.6942, + "general_paths_mean": 1413.0539344242425, + "macro_paths_mean": 1303.4163075597485, + "stdcell_um2": 15145.42697999324, + "tail_s": 7031.942000000001 + }, + "proxy": { + "wq25": 2056.802091085107, + "macro_mean": 1866.2958056312496, + "period": 2325.960083 + }, + "objective_fixed_norm": 209.6768066623127 + }, + "cand_s19": { + "grt": { + "achieved": 1584.609644, + "general_paths_mean": 1405.26813299, + "macro_paths_mean": 1293.14624963522, + "stdcell_um2": 14898.572999992715, + "tail_s": 7361.876 + }, + "proxy": { + "wq25": 2756.0829234117646, + "macro_mean": 2406.4038558937496, + "period": 3153.487305 + }, + "objective_fixed_norm": 189.6622999081752 + }, + "cand_s20": { + "grt": { + "achieved": 1597.625011, + "general_paths_mean": 1415.98507951, + "macro_paths_mean": 1036.9591125625, + "stdcell_um2": 14772.82049999264, + "tail_s": 6978.277 + }, + "proxy": { + "wq25": 1637.4834353400001, + "macro_mean": 1238.9324906554052, + "period": 1847.955872 + }, + "objective_fixed_norm": 182.84016487561001 + }, + "cand_s21": { + "grt": { + "achieved": 1591.736388, + "general_paths_mean": 1410.3088532653062, + "macro_paths_mean": 1107.3502923464052, + "stdcell_um2": 14814.708839992754, + "tail_s": 7358.391 + }, + "proxy": { + "wq25": 1736.6384767676773, + "macro_mean": 1346.2244227857145, + "period": 1956.372833 + }, + "objective_fixed_norm": 170.13715597354312 + }, + "cand_s22": { + "grt": { + "achieved": 1579.346743, + "general_paths_mean": 1398.90299222, + "macro_paths_mean": 1333.570405567742, + "stdcell_um2": 14933.769119992918, + "tail_s": 7267.501 + }, + "proxy": { + "wq25": 1927.9062034193557, + "macro_mean": 1791.250751401274, + "period": 2180.747925 + }, + "objective_fixed_norm": 193.43760611031072 + }, + "cand_s23": { + "grt": { + "achieved": 1577.998266, + "general_paths_mean": 1399.5887477299998, + "macro_paths_mean": 1226.4607230375, + "stdcell_um2": 14832.277739992678, + "tail_s": 5830.857 + }, + "proxy": { + "wq25": 1727.5670958315789, + "macro_mean": 1331.175906175676, + "period": 1960.101959 + }, + "objective_fixed_norm": 182.8388841444474 + } + } +} \ No newline at end of file diff --git a/patches/openroad/0001-mpl-fix-rerun-segfault.patch b/patches/openroad/0001-mpl-fix-rerun-segfault.patch new file mode 100644 index 0000000000..19bde3d5e7 --- /dev/null +++ b/patches/openroad/0001-mpl-fix-rerun-segfault.patch @@ -0,0 +1,45 @@ +From 672f4bdd6e411703b76b9a5c176f5283e3bff3dc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Sun, 30 Aug 2026 22:51:43 +0200 +Subject: [PATCH 1/4] mpl: fix segfault when rtl_macro_placer is invoked more + than once +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +HierRTLMP::run() ends by calling clear(), which destroys the physical +hierarchy tree. The tree was only ever created in the constructor, so a +second rtl_macro_placer invocation in the same process handed a null +tree to the clustering engine and crashed. Recreate the tree in init() +and reset the stale skip_macro_placement_ flag so every place() call is +self-contained. + +Covered by the new random_seed1 regression test, which runs the placer +three times in one process. + +Signed-off-by: Øyvind Harboe +--- + src/mpl/src/hier_rtlmp.cpp | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp +index f25b865895..bea60cb8ba 100644 +--- a/src/mpl/src/hier_rtlmp.cpp ++++ b/src/mpl/src/hier_rtlmp.cpp +@@ -306,6 +306,13 @@ void HierRTLMP::blockMacroChannels() + + void HierRTLMP::init() + { ++ // run() ends by destroying the tree, so a new one is needed to ++ // make a subsequent run possible. ++ if (!tree_) { ++ tree_ = std::make_unique(); ++ } ++ skip_macro_placement_ = false; ++ + block_ = db_->getChip()->getBlock(); + clustering_engine_ = std::make_unique( + block_, logger_, tritonpart_, graphics_.get()); +-- +2.53.0 + diff --git a/patches/openroad/0002-mpl-add-random_seed.patch b/patches/openroad/0002-mpl-add-random_seed.patch new file mode 100644 index 0000000000..1c9e53e3d9 --- /dev/null +++ b/patches/openroad/0002-mpl-add-random_seed.patch @@ -0,0 +1,358 @@ +From ac1b74a3e641d03954cd221ee06665046a6aae4d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Sun, 30 Aug 2026 22:51:57 +0200 +Subject: [PATCH 2/4] mpl: add -random_seed to rtl_macro_placer +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Seed the simulated annealing random number generators from a new +-random_seed argument (default 0, the previous hard-coded value, so +existing behavior is unchanged). Runs with the same seed reproduce the +same macro placement; different seeds explore different annealing +trajectories. + +This turns rtl_macro_placer into a deterministic candidate generator: +a population of macro placements can be produced by sweeping seeds and +the winner rematerialized exactly by re-running its seed, instead of +perturbing CORE_AREA or the cost weights to obtain distinct placements. + +The new random_seed1 regression test checks that the same seed is +reproducible and that a different seed yields a distinct placement. + +Signed-off-by: Øyvind Harboe +--- + src/mpl/README.md | 2 + + src/mpl/include/mpl/rtl_mp.h | 1 + + src/mpl/src/hier_rtlmp.cpp | 7 ++++ + src/mpl/src/hier_rtlmp.h | 7 ++-- + src/mpl/src/mpl.i | 6 +++ + src/mpl/src/mpl.tcl | 8 ++++ + src/mpl/src/rtl_mp.cpp | 5 +++ + src/mpl/test/BUILD | 5 +++ + src/mpl/test/CMakeLists.txt | 1 + + src/mpl/test/random_seed1.ok | 51 +++++++++++++++++++++++++ + src/mpl/test/random_seed1.tcl | 70 +++++++++++++++++++++++++++++++++++ + 11 files changed, 160 insertions(+), 3 deletions(-) + create mode 100644 src/mpl/test/random_seed1.ok + create mode 100644 src/mpl/test/random_seed1.tcl + +diff --git a/src/mpl/README.md b/src/mpl/README.md +index 7455e83919..b9625a9b5f 100644 +--- a/src/mpl/README.md ++++ b/src/mpl/README.md +@@ -42,6 +42,7 @@ rtl_macro_placer + [-soft_blockage_weight soft_blockage_weight] + [-target_util target_util] + [-min_ar min_ar] ++ [-random_seed random_seed] + [-report_directory report_directory] + [-write_macro_placement file_name] + [-keep_clustering_data] +@@ -63,6 +64,7 @@ rtl_macro_placer + | `-fence_lx`, `-fence_ly`, `-fence_ux`, `-fence_uy` | Defines the global fence bounding box coordinates. The default values are the core area coordinates). | + | `-target_util` | Specifies the target utilization. The allowed values are floats and the default value is `0.25`. | + | `-min_ar` | Specifies the minimum aspect ratio $a$, or the ratio of its width to height of a `StandardCellCluster` from $[a, \frac{1}{a}]$. The allowed values are floats, and the default value is `0.33`. | ++| `-random_seed` | Seed for the simulated annealing random number generators. Runs with the same seed are deterministic; different seeds generate different placement candidates. The allowed values are integers, and the default value is `0`. | + | `-report_directory` | Save reports to this directory. | + | `-write_macro_placement` | Generates a file with the design's macro placement in the format of calls for the `place_macro` command. | + | `-keep_clustering_data` | Save the hierarchy generated by MPL's clustering engine in the form of dbGroups inside ODB. | +diff --git a/src/mpl/include/mpl/rtl_mp.h b/src/mpl/include/mpl/rtl_mp.h +index 1b4cadb4fe..18861e0c09 100644 +--- a/src/mpl/include/mpl/rtl_mp.h ++++ b/src/mpl/include/mpl/rtl_mp.h +@@ -77,6 +77,7 @@ class MacroPlacer + std::vector findOverlappedMacros(odb::dbInst* macro); + + void setMacroPlacementFile(const std::string& file_name); ++ void setRandomSeed(int seed); + void addGuidanceRegion(odb::dbInst* macro, odb::Rect region); + void setBaseHalo(int left, int bottom, int right, int top); + void setMacroHalo(odb::dbInst* macro, +diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp +index bea60cb8ba..5300665a1c 100644 +--- a/src/mpl/src/hier_rtlmp.cpp ++++ b/src/mpl/src/hier_rtlmp.cpp +@@ -216,6 +216,13 @@ void HierRTLMP::setUseFullHalo(bool use_full_halo) + // Attempts macro flipping to improve WR. + void HierRTLMP::run() + { ++ debugPrint(logger_, ++ MPL, ++ "hierarchical_macro_placement", ++ 1, ++ "Random seed: {}", ++ random_seed_); ++ + runMultilevelAutoclustering(); + if (skip_macro_placement_) { + logger_->info(MPL, 13, "Skipping macro placement."); +diff --git a/src/mpl/src/hier_rtlmp.h b/src/mpl/src/hier_rtlmp.h +index 4affb51393..b12e7c671b 100644 +--- a/src/mpl/src/hier_rtlmp.h ++++ b/src/mpl/src/hier_rtlmp.h +@@ -118,6 +118,7 @@ class HierRTLMP + void setDebugTargetClusterId(int target_cluster_id); + + void setNumThreads(int threads) { num_threads_ = threads; } ++ void setRandomSeed(int seed) { random_seed_ = seed; } + void setMacroPlacementFile(const std::string& file_name); + void writeMacroPlacement(const std::string& file_name); + +@@ -278,9 +279,9 @@ class HierRTLMP + std::string report_directory_; + std::string macro_placement_file_; + +- const int num_runs_ = 10; // number of runs for SA +- int num_threads_ = 10; // number of threads +- const int random_seed_ = 0; // random seed for deterministic ++ const int num_runs_ = 10; // number of runs for SA ++ int num_threads_ = 10; // number of threads ++ int random_seed_ = 0; // random seed for deterministic + + float target_utilization_{0.0}; + float min_ar_ = 0.3; // the aspect ratio range for StdCellCluster (min_ar_, 1 +diff --git a/src/mpl/src/mpl.i b/src/mpl/src/mpl.i +index 7f8c7bc1df..761b17ccdd 100644 +--- a/src/mpl/src/mpl.i ++++ b/src/mpl/src/mpl.i +@@ -169,6 +169,12 @@ set_macro_placement_file(std::string file_name) + getMacroPlacer()->setMacroPlacementFile(file_name); + } + ++void ++set_random_seed(int seed) ++{ ++ getMacroPlacer()->setRandomSeed(seed); ++} ++ + void + block_macro_channels() + { +diff --git a/src/mpl/src/mpl.tcl b/src/mpl/src/mpl.tcl +index d9ff4939a4..a5eacb624b 100644 +--- a/src/mpl/src/mpl.tcl ++++ b/src/mpl/src/mpl.tcl +@@ -26,6 +26,7 @@ sta::define_cmd_args "rtl_macro_placer" { -max_num_macro max_num_macro \ + -soft_blockage_weight soft_blockage_weight \ + -target_util target_util \ + -min_ar min_ar \ ++ -random_seed random_seed \ + -report_directory report_directory \ + -write_macro_placement file_name \ + -keep_clustering_data \ +@@ -42,6 +43,7 @@ proc rtl_macro_placer { args } { + -macro_blockage_weight \ + -soft_blockage_weight -target_util \ + -min_ar \ ++ -random_seed \ + -report_directory \ + -write_macro_placement } \ + flags {-keep_clustering_data -use_full_halo} +@@ -79,6 +81,7 @@ proc rtl_macro_placer { args } { + set soft_blockage_weight 10.0 + set target_util 0.25 + set min_ar 0.33 ++ set random_seed 0 + set report_directory "hier_rtlmp" + + if { [info exists keys(-max_num_macro)] } { +@@ -181,6 +184,11 @@ proc rtl_macro_placer { args } { + if { [info exists keys(-min_ar)] } { + set min_ar $keys(-min_ar) + } ++ if { [info exists keys(-random_seed)] } { ++ set random_seed $keys(-random_seed) ++ sta::check_integer "-random_seed" $random_seed ++ } ++ mpl::set_random_seed $random_seed + if { [info exists keys(-report_directory)] } { + set report_directory $keys(-report_directory) + } +diff --git a/src/mpl/src/rtl_mp.cpp b/src/mpl/src/rtl_mp.cpp +index b429aca9d1..4d39548511 100644 +--- a/src/mpl/src/rtl_mp.cpp ++++ b/src/mpl/src/rtl_mp.cpp +@@ -245,6 +245,11 @@ void MacroPlacer::setMacroPlacementFile(const std::string& file_name) + hier_rtlmp_->setMacroPlacementFile(file_name); + } + ++void MacroPlacer::setRandomSeed(const int seed) ++{ ++ hier_rtlmp_->setRandomSeed(seed); ++} ++ + void MacroPlacer::setDebug(std::unique_ptr& graphics) + { + hier_rtlmp_->setDebug(graphics); +diff --git a/src/mpl/test/BUILD b/src/mpl/test/BUILD +index b3bac2cf31..8be0fa4d60 100644 +--- a/src/mpl/test/BUILD ++++ b/src/mpl/test/BUILD +@@ -48,6 +48,7 @@ COMPULSORY_TESTS = [ + "orientation_improve3", + "place_macro_right_angle_rotation", + "placement_blockages1", ++ "random_seed1", + "unfixed_cells_dont_fit_in_core", + ] + +@@ -243,6 +244,10 @@ filegroup( + "testcases/macro_only.lef", + "testcases/placement_blockages1.def", + ], ++ "random_seed1": [ ++ "testcases/halos1.def", ++ "testcases/orientation_improve1.lef", ++ ], + "unfixed_cells_dont_fit_in_core": [ + "testcases/macro_only.lef", + "testcases/unfixed_cells_dont_fit_in_core.def", +diff --git a/src/mpl/test/CMakeLists.txt b/src/mpl/test/CMakeLists.txt +index 08746228a6..9d50fb8b50 100644 +--- a/src/mpl/test/CMakeLists.txt ++++ b/src/mpl/test/CMakeLists.txt +@@ -33,6 +33,7 @@ or_integration_tests( + unfixed_cells_dont_fit_in_core + place_macro_right_angle_rotation + placement_blockages1 ++ random_seed1 + halos1 + halos2 + halos3 +diff --git a/src/mpl/test/random_seed1.ok b/src/mpl/test/random_seed1.ok +new file mode 100644 +index 0000000000..7d9ed7f762 +--- /dev/null ++++ b/src/mpl/test/random_seed1.ok +@@ -0,0 +1,51 @@ ++[INFO ODB-0227] LEF file: ./Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells ++[INFO ODB-0227] LEF file: ./testcases/orientation_improve1.lef, created 10 library cells ++[INFO ODB-0128] Design: boundary_push1 ++[INFO ODB-0131] Created 152 components and 904 component-terminals. ++Die Area: (0.00, 0.00) (220.02, 221.20), Floorplan Area: (0.00, 0.00) (220.02, 221.20) ++ Number of std cell instances: 150 ++ Area of std cell instances: 678.30 ++ Number of macros: 2 ++ Macros to be placed: 2 ++ Area of macros: 20000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 21029.40 ++ Area of std cell instances + Area of macros: 20678.30 ++ Floorplan area: 48668.42 ++ Design Utilization: 0.42 ++ Floorplan Utilization: 0.02 ++ Manufacturing Grid: 10 ++ ++[WARNING MPL-0026] Design has no IO pins! ++Die Area: (0.00, 0.00) (220.02, 221.20), Floorplan Area: (0.00, 0.00) (220.02, 221.20) ++ Number of std cell instances: 150 ++ Area of std cell instances: 678.30 ++ Number of macros: 2 ++ Macros to be placed: 2 ++ Area of macros: 20000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 21029.40 ++ Area of std cell instances + Area of macros: 20678.30 ++ Floorplan area: 48668.42 ++ Design Utilization: 0.42 ++ Floorplan Utilization: 0.02 ++ Manufacturing Grid: 10 ++ ++[WARNING MPL-0026] Design has no IO pins! ++Die Area: (0.00, 0.00) (220.02, 221.20), Floorplan Area: (0.00, 0.00) (220.02, 221.20) ++ Number of std cell instances: 150 ++ Area of std cell instances: 678.30 ++ Number of macros: 2 ++ Macros to be placed: 2 ++ Area of macros: 20000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 21029.40 ++ Area of std cell instances + Area of macros: 20678.30 ++ Floorplan area: 48668.42 ++ Design Utilization: 0.42 ++ Floorplan Utilization: 0.02 ++ Manufacturing Grid: 10 ++ ++[WARNING MPL-0026] Design has no IO pins! ++same seed is reproducible: 1 ++different seed is distinct: 1 +diff --git a/src/mpl/test/random_seed1.tcl b/src/mpl/test/random_seed1.tcl +new file mode 100644 +index 0000000000..eefa088d17 +--- /dev/null ++++ b/src/mpl/test/random_seed1.tcl +@@ -0,0 +1,70 @@ ++# Test that -random_seed makes rtl_macro_placer a deterministic candidate ++# generator: the same seed must reproduce the macro placement exactly and ++# a different seed must explore a different annealing trajectory. ++source "helpers.tcl" ++ ++read_lef "./Nangate45/Nangate45.lef" ++read_lef "./testcases/orientation_improve1.lef" ++ ++read_def "./testcases/halos1.def" ++ ++set_thread_count 0 ++ ++# Restore the macros to their pre-placement state so that the placer ++# can be run repeatedly on the same design. ++proc save_macro_state { } { ++ set state {} ++ foreach inst [[ord::get_db_block] getInsts] { ++ if { [[$inst getMaster] isBlock] } { ++ lappend state $inst [$inst getPlacementStatus] [$inst getOrient] \ ++ [$inst getLocation] ++ } ++ } ++ return $state ++} ++ ++proc restore_macro_state { state } { ++ foreach { inst status orient location } $state { ++ $inst setPlacementStatus $status ++ $inst setOrient $orient ++ $inst setLocation [lindex $location 0] [lindex $location 1] ++ } ++ ++ # Remove the soft blockages created around the macros placed by ++ # the previous run. ++ foreach blockage [[ord::get_db_block] getBlockages] { ++ odb::dbBlockage_destroy $blockage ++ } ++} ++ ++proc place_with_seed { seed placement_file initial_state } { ++ restore_macro_state $initial_state ++ rtl_macro_placer -random_seed $seed \ ++ -report_directory [make_result_dir] \ ++ -write_macro_placement $placement_file ++} ++ ++proc placements_equal { file1 file2 } { ++ set stream1 [open $file1 r] ++ set content1 [read $stream1] ++ close $stream1 ++ ++ set stream2 [open $file2 r] ++ set content2 [read $stream2] ++ close $stream2 ++ ++ return [expr { $content1 eq $content2 }] ++} ++ ++set initial_state [save_macro_state] ++ ++set seed1_first [make_result_file random_seed1_seed1_first.tcl] ++set seed1_second [make_result_file random_seed1_seed1_second.tcl] ++set seed0 [make_result_file random_seed1_seed0.tcl] ++ ++place_with_seed 1 $seed1_first $initial_state ++place_with_seed 1 $seed1_second $initial_state ++place_with_seed 0 $seed0 $initial_state ++ ++puts "same seed is reproducible: [placements_equal $seed1_first $seed1_second]" ++puts "different seed is distinct: [expr { ![placements_equal $seed1_first $seed0] }]" +-- +2.53.0 + diff --git a/patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch b/patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch new file mode 100644 index 0000000000..29574e914f --- /dev/null +++ b/patches/openroad/0003-mpl-keep-snapped-macros-inside-core.patch @@ -0,0 +1,524 @@ +From 1af76cfd50ce32140fc8fdc0d566b9dcafb0fe4a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Sun, 30 Aug 2026 23:03:00 +0200 +Subject: [PATCH 3/4] mpl: keep snapped macros inside the core +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The Snapper picked the track (or manufacturing-grid) position closest +to the pin center, rounding up when in doubt. For a macro at the top or +right core edge this moved the macro bounding box slightly past the +core boundary. The residue is invisible to the flow that produced it, +but place_macro rejects such a position with MPL-0034, so the file +written by -write_macro_placement did not round-trip: the placer's own +winner could not be re-injected with MACRO_PLACEMENT_TCL. + +Constrain the track-alignment search to positions that keep the macro +inside the core, and nudge the macro inward by whole manufacturing-grid +steps when no aligned position qualifies (new warning MPL-0078). Fixed +macros are untouched as before. + +The regenerated goldens of boundary_push1, fixed_macros2, halos5 and +orientation_improve1/3 all contained placer-produced macros poking past +the core boundary; their macros now land inside the core, track-aligned +one pitch inward. + +The new macro_placement_round_trip1 test checks the write_macro_placement +-> place_macro round-trip lands every macro exactly where the placer +left it. + +Signed-off-by: Øyvind Harboe +--- + src/mpl/src/snapper.cpp | 83 +++++++++++++++++++- + src/mpl/src/snapper.h | 2 + + src/mpl/test/BUILD | 5 ++ + src/mpl/test/CMakeLists.txt | 1 + + src/mpl/test/boundary_push1.defok | 8 +- + src/mpl/test/cpp/TestSnapper.cpp | 82 +++++++++++++++++++ + src/mpl/test/fixed_macros2.defok | 4 +- + src/mpl/test/halos5.defok | 4 +- + src/mpl/test/macro_placement_round_trip1.ok | 22 ++++++ + src/mpl/test/macro_placement_round_trip1.tcl | 62 +++++++++++++++ + src/mpl/test/orientation_improve1.defok | 4 +- + src/mpl/test/orientation_improve3.defok | 4 +- + 12 files changed, 267 insertions(+), 14 deletions(-) + create mode 100644 src/mpl/test/macro_placement_round_trip1.ok + create mode 100644 src/mpl/test/macro_placement_round_trip1.tcl + +diff --git a/src/mpl/src/snapper.cpp b/src/mpl/src/snapper.cpp +index c7e5837e14..d838a87b6e 100644 +--- a/src/mpl/src/snapper.cpp ++++ b/src/mpl/src/snapper.cpp +@@ -42,6 +42,9 @@ void Snapper::snap(const odb::dbTechLayerDir& target_direction) + if (layers_data_list.empty()) { + alignWithManufacturingGrid(origin); + setOrigin(origin, target_direction); ++ if (!macroStaysInCore(target_direction)) { ++ nudgeMacroIntoCore(target_direction); ++ } + return; + } + +@@ -217,8 +220,8 @@ void Snapper::attemptSnapToExtraPatterns( + odb::dbITerm* snap_pin = layers_data_list[0].pins[0]; + const std::vector& positions = layers_data_list[0].available_positions; + +- int best_index = start_index; +- int best_snapped_pins = 0; ++ int best_index = -1; ++ int best_snapped_pins = -1; + + for (int i = 0; i <= total_attempts; i++) { + int steps = (i % 2 == 1) ? (i + 1) / 2 : -(i / 2); +@@ -231,6 +234,13 @@ void Snapper::attemptSnapToExtraPatterns( + } + snapPinToPosition(snap_pin, positions[current_index], target_direction); + ++ // A position that moves the macro outside the core is rejected by ++ // place_macro, so the placement wouldn't survive a round-trip ++ // through the file written by -write_macro_placement. ++ if (!macroStaysInCore(target_direction)) { ++ continue; ++ } ++ + int snapped_pins = totalAlignedPins(layers_data_list, target_direction); + + if (snapped_pins > best_snapped_pins) { +@@ -242,6 +252,19 @@ void Snapper::attemptSnapToExtraPatterns( + } + } + ++ if (best_index == -1) { ++ // No track-aligned position keeps the macro inside the core. ++ snapPinToPosition(snap_pin, positions[start_index], target_direction); ++ nudgeMacroIntoCore(target_direction); ++ ++ logger_->warn(utl::MPL, ++ 78, ++ "Couldn't align the pins of the macro {} to the track-grid " ++ "while keeping it inside the core.", ++ inst_->getName()); ++ return; ++ } ++ + snapPinToPosition(snap_pin, positions[best_index], target_direction); + + if (best_snapped_pins != total_pins) { +@@ -298,6 +321,62 @@ int Snapper::totalAlignedPins(const LayerDataList& layers_data_list, + return pins_aligned; + } + ++// A degenerate core (no rows created yet) imposes no constraint. ++bool Snapper::macroStaysInCore( ++ const odb::dbTechLayerDir& target_direction) const ++{ ++ const odb::Rect core = inst_->getBlock()->getCoreArea(); ++ if (core.dx() == 0 || core.dy() == 0) { ++ return true; ++ } ++ ++ const odb::Rect bbox = inst_->getBBox()->getBox(); ++ if (target_direction == odb::dbTechLayerDir::VERTICAL) { ++ return bbox.xMin() >= core.xMin() && bbox.xMax() <= core.xMax(); ++ } ++ return bbox.yMin() >= core.yMin() && bbox.yMax() <= core.yMax(); ++} ++ ++// Move the macro the minimum amount of manufacturing-grid units that ++// brings it back inside the core. A macro larger than the core is ++// left untouched. ++void Snapper::nudgeMacroIntoCore(const odb::dbTechLayerDir& target_direction) ++{ ++ const odb::Rect core = inst_->getBlock()->getCoreArea(); ++ const odb::Rect bbox = inst_->getBBox()->getBox(); ++ const int manufacturing_grid ++ = inst_->getDb()->getTech()->getManufacturingGrid(); ++ ++ const bool vertical = target_direction == odb::dbTechLayerDir::VERTICAL; ++ const int macro_min = vertical ? bbox.xMin() : bbox.yMin(); ++ const int macro_max = vertical ? bbox.xMax() : bbox.yMax(); ++ const int core_min = vertical ? core.xMin() : core.yMin(); ++ const int core_max = vertical ? core.xMax() : core.yMax(); ++ ++ if (macro_max - macro_min > core_max - core_min) { ++ return; ++ } ++ ++ int shift = 0; ++ if (macro_max > core_max) { ++ // Align the inward shift to the manufacturing grid, rounding up so ++ // that the macro ends up inside the core. ++ const int overshoot = macro_max - core_max; ++ shift = -((overshoot + manufacturing_grid - 1) / manufacturing_grid) ++ * manufacturing_grid; ++ } else if (macro_min < core_min) { ++ const int overshoot = core_min - macro_min; ++ shift = ((overshoot + manufacturing_grid - 1) / manufacturing_grid) ++ * manufacturing_grid; ++ } ++ ++ if (shift != 0) { ++ const int origin ++ = (vertical ? inst_->getOrigin().x() : inst_->getOrigin().y()) + shift; ++ setOrigin(origin, target_direction); ++ } ++} ++ + void Snapper::alignWithManufacturingGrid(int& origin) + { + const int manufacturing_grid +diff --git a/src/mpl/src/snapper.h b/src/mpl/src/snapper.h +index ea01a21a38..9754c34623 100644 +--- a/src/mpl/src/snapper.h ++++ b/src/mpl/src/snapper.h +@@ -46,6 +46,8 @@ class Snapper + = odb::PtrMap>; + + void snap(const odb::dbTechLayerDir& target_direction); ++ bool macroStaysInCore(const odb::dbTechLayerDir& target_direction) const; ++ void nudgeMacroIntoCore(const odb::dbTechLayerDir& target_direction); + void alignWithManufacturingGrid(int& origin); + void setOrigin(int origin, const odb::dbTechLayerDir& target_direction); + int totalAlignedPins(const LayerDataList& layers_data_list, +diff --git a/src/mpl/test/BUILD b/src/mpl/test/BUILD +index 8be0fa4d60..e9f20addfb 100644 +--- a/src/mpl/test/BUILD ++++ b/src/mpl/test/BUILD +@@ -40,6 +40,7 @@ COMPULSORY_TESTS = [ + "keep_clustering_data1", + "keep_clustering_data2", + "macro_only", ++ "macro_placement_round_trip1", + "macros_without_pins1", + "mixed_ios1", + "no_unfixed_macros", +@@ -207,6 +208,10 @@ filegroup( + "testcases/macro_only.lib", + "testcases/macro_only.v", + ], ++ "macro_placement_round_trip1": [ ++ "testcases/halos1.def", ++ "testcases/orientation_improve1.lef", ++ ], + "macros_without_pins1": [ + "Nangate45_io/dummy_pads.lef", + "testcases/macros_without_pins1.def", +diff --git a/src/mpl/test/CMakeLists.txt b/src/mpl/test/CMakeLists.txt +index 9d50fb8b50..7b3e67ce7a 100644 +--- a/src/mpl/test/CMakeLists.txt ++++ b/src/mpl/test/CMakeLists.txt +@@ -29,6 +29,7 @@ or_integration_tests( + fixed_macros1 + fixed_macros2 + fixed_covers ++ macro_placement_round_trip1 + macros_without_pins1 + unfixed_cells_dont_fit_in_core + place_macro_right_angle_rotation +diff --git a/src/mpl/test/boundary_push1.defok b/src/mpl/test/boundary_push1.defok +index 42e9c46693..9e5716bad5 100644 +--- a/src/mpl/test/boundary_push1.defok ++++ b/src/mpl/test/boundary_push1.defok +@@ -183,10 +183,10 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ; + TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ; + TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ; + COMPONENTS 4 ; +- - MACRO_1 HM_100x100_1x1 + FIXED ( 240040 242530 ) S ; ++ - MACRO_1 HM_100x100_1x1 + FIXED ( 240040 242250 ) S ; + - MACRO_2 HM_100x100_1x1 + FIXED ( 240040 330 ) S ; + - MACRO_3 HM_100x100_1x1 + FIXED ( 0 330 ) S ; +- - MACRO_4 HM_100x100_1x1 + FIXED ( 0 242530 ) S ; ++ - MACRO_4 HM_100x100_1x1 + FIXED ( 0 242250 ) S ; + END COMPONENTS + PINS 4 ; + - io_1 + NET io_1 + DIRECTION INPUT + USE SIGNAL ; +@@ -196,9 +196,9 @@ PINS 4 ; + END PINS + BLOCKAGES 4 ; + - PLACEMENT + SOFT + COMPONENT MACRO_3 RECT ( 0 190 ) ( 200000 200470 ) ; +- - PLACEMENT + SOFT + COMPONENT MACRO_4 RECT ( 0 242390 ) ( 200000 442670 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_4 RECT ( 0 242110 ) ( 200000 442390 ) ; + - PLACEMENT + SOFT + COMPONENT MACRO_2 RECT ( 240040 190 ) ( 440040 200470 ) ; +- - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 240040 242390 ) ( 440040 442670 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 240040 242110 ) ( 440040 442390 ) ; + END BLOCKAGES + NETS 4 ; + - io_1 ( PIN io_1 ) + USE SIGNAL ; +diff --git a/src/mpl/test/cpp/TestSnapper.cpp b/src/mpl/test/cpp/TestSnapper.cpp +index 3c1d0b661c..572e0e7c0f 100644 +--- a/src/mpl/test/cpp/TestSnapper.cpp ++++ b/src/mpl/test/cpp/TestSnapper.cpp +@@ -490,5 +490,87 @@ TEST_F(TestSnapper, SingleLayerWithUnalignablePinThrowsException) + } + } + ++// The snap to the manufacturing grid must not move the macro outside ++// the core: rounding up at the top/right core edge is compensated by ++// an inward nudge. ++TEST_F(TestSnapper, StaysInCoreManufacturingGrid) ++{ ++ db_->getTech()->setManufacturingGrid(10); ++ db_->getChip()->getBlock()->setCoreArea(odb::Rect(0, 0, 1000, 1000)); ++ ++ odb::dbMaster* macro_master ++ = odb::dbMaster::create(db_->findLib("lib"), "macro_master"); ++ macro_master->setWidth(200); ++ macro_master->setHeight(300); ++ macro_master->setType(odb::dbMasterType::BLOCK); ++ macro_master->setFrozen(); ++ ++ odb::dbInst* macro ++ = odb::dbInst::create(db_->getChip()->getBlock(), macro_master, "macro"); ++ macro->setOrigin(814, 719); ++ snapper_->setMacro(macro); ++ snapper_->snapMacro(); ++ ++ // Rounding 814 to 810 leaves the right edge at 1010, outside the ++ // core, so the macro is nudged one manufacturing-grid step inward. ++ EXPECT_EQ(macro->getOrigin().x(), 800); ++ // Rounding 719 to 720 leaves the top edge at 1020, outside the ++ // core, so the macro is nudged two manufacturing-grid steps inward. ++ EXPECT_EQ(macro->getOrigin().y(), 700); ++} ++ ++// The track-aligned snap must choose a position that keeps the macro ++// inside the core even when a closer track position exists outside. ++TEST_F(TestSnapper, StaysInCoreTrackAligned) ++{ ++ db_->getTech()->setManufacturingGrid(1); ++ db_->getChip()->getBlock()->setCoreArea(odb::Rect(0, 0, 20000, 11500)); ++ ++ const int track_pitch = 36; ++ odb::dbTechLayer* horizontal_layer = odb::dbTechLayer::create( ++ db_->getTech(), "H1", odb::dbTechLayerType::DEFAULT); ++ horizontal_layer->setDirection(odb::dbTechLayerDir::HORIZONTAL); ++ odb::dbTrackGrid* track ++ = odb::dbTrackGrid::create(db_->getChip()->getBlock(), horizontal_layer); ++ track->addGridPatternY(0, die_height_ / track_pitch, track_pitch); ++ ++ odb::dbMaster* macro_master ++ = odb::dbMaster::create(db_->findLib("lib"), "macro_master"); ++ macro_master->setHeight(10000); ++ macro_master->setWidth(10000); ++ macro_master->setType(odb::dbMasterType::BLOCK); ++ ++ const int pin_height = 20; ++ const int pin_width = 50; ++ ++ const int pin_x = 0; ++ const int pin_y = 0; ++ odb::dbMTerm* mterm = odb::dbMTerm::create( ++ macro_master, "pin", odb::dbIoType::INPUT, odb::dbSigType::SIGNAL); ++ odb::dbMPin* mpin = odb::dbMPin::create(mterm); ++ odb::dbBox::create(mpin, ++ horizontal_layer, ++ pin_x, ++ pin_y, ++ pin_x + pin_height, ++ pin_y + pin_width); ++ ++ macro_master->setFrozen(); ++ ++ odb::dbInst* macro ++ = odb::dbInst::create(db_->getChip()->getBlock(), macro_master, "macro"); ++ macro->setOrigin(1500, 1495); ++ ++ snapper_->setMacro(macro); ++ snapper_->snapMacro(); ++ ++ EXPECT_EQ(macro->getOrigin().x(), 1500); ++ // The nearest track position for the pin center (1520) is 1548, ++ // which puts the origin at 1523 and the top edge at 11523, outside ++ // the core. The track position below (1512, origin 1487) is the ++ // best aligned position that keeps the macro inside the core. ++ EXPECT_EQ(macro->getOrigin().y(), 1487); ++} ++ + } // namespace + } // namespace mpl +diff --git a/src/mpl/test/fixed_macros2.defok b/src/mpl/test/fixed_macros2.defok +index e02b208247..15c5df01cb 100644 +--- a/src/mpl/test/fixed_macros2.defok ++++ b/src/mpl/test/fixed_macros2.defok +@@ -173,7 +173,7 @@ TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ; + TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ; + COMPONENTS 402 ; + - MACRO_1 HM_100x100_1x1 + FIXED ( 0 0 ) N ; +- - MACRO_2 HM_100x100_1x1 + FIXED ( 0 242530 ) S ; ++ - MACRO_2 HM_100x100_1x1 + FIXED ( 0 242250 ) S ; + - _001_ DFF_X1 + PLACED ( 316790 235200 ) N ; + - _002_ DFF_X1 + PLACED ( 316790 235200 ) N ; + - _003_ DFF_X1 + PLACED ( 316790 235200 ) N ; +@@ -577,7 +577,7 @@ COMPONENTS 402 ; + END COMPONENTS + BLOCKAGES 2 ; + - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 0 -140 ) ( 200000 200140 ) ; +- - PLACEMENT + SOFT + COMPONENT MACRO_2 RECT ( 0 242390 ) ( 200000 442670 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_2 RECT ( 0 242110 ) ( 200000 442390 ) ; + END BLOCKAGES + NETS 0 ; + END NETS +diff --git a/src/mpl/test/halos5.defok b/src/mpl/test/halos5.defok +index ce38d0f2c4..1d60a660fa 100644 +--- a/src/mpl/test/halos5.defok ++++ b/src/mpl/test/halos5.defok +@@ -184,7 +184,7 @@ TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ; + TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ; + COMPONENTS 152 ; + - MACRO_1 HM_100x100_1x1 + FIXED ( 15000 20210 ) S + HALO 5000 10000 15000 20000 ; +- - MACRO_2 HM_100x100_1x1 + FIXED ( 0 242530 ) S ; ++ - MACRO_2 HM_100x100_1x1 + FIXED ( 0 242250 ) S ; + - _001_ DFF_X1 + PLACED ( 316790 334800 ) N ; + - _002_ DFF_X1 + PLACED ( 316790 334800 ) N ; + - _003_ DFF_X1 + PLACED ( 316790 334800 ) N ; +@@ -338,7 +338,7 @@ COMPONENTS 152 ; + END COMPONENTS + BLOCKAGES 2 ; + - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 0 210 ) ( 220000 230210 ) ; +- - PLACEMENT + SOFT + COMPONENT MACRO_2 RECT ( 0 242530 ) ( 200000 442530 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_2 RECT ( 0 242250 ) ( 200000 442250 ) ; + END BLOCKAGES + NETS 0 ; + END NETS +diff --git a/src/mpl/test/macro_placement_round_trip1.ok b/src/mpl/test/macro_placement_round_trip1.ok +new file mode 100644 +index 0000000000..371df8dc90 +--- /dev/null ++++ b/src/mpl/test/macro_placement_round_trip1.ok +@@ -0,0 +1,22 @@ ++[INFO ODB-0227] LEF file: ./Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells ++[INFO ODB-0227] LEF file: ./testcases/orientation_improve1.lef, created 10 library cells ++[INFO ODB-0128] Design: boundary_push1 ++[INFO ODB-0131] Created 152 components and 904 component-terminals. ++Die Area: (0.00, 0.00) (220.02, 221.20), Floorplan Area: (0.00, 0.00) (220.02, 221.20) ++ Number of std cell instances: 150 ++ Area of std cell instances: 678.30 ++ Number of macros: 2 ++ Macros to be placed: 2 ++ Area of macros: 20000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 21029.40 ++ Area of std cell instances + Area of macros: 20678.30 ++ Floorplan area: 48668.42 ++ Design Utilization: 0.42 ++ Floorplan Utilization: 0.02 ++ Manufacturing Grid: 10 ++ ++[WARNING MPL-0026] Design has no IO pins! ++[INFO MPL-0035] Macro MACRO_1 placed. Bounding box (7.500um, 0.165um), (107.500um, 100.165um). Orientation R180 ++[INFO MPL-0035] Macro MACRO_2 placed. Bounding box (120.020um, 0.165um), (220.020um, 100.165um). Orientation R180 ++round trip is exact: 1 +diff --git a/src/mpl/test/macro_placement_round_trip1.tcl b/src/mpl/test/macro_placement_round_trip1.tcl +new file mode 100644 +index 0000000000..136bd9a0db +--- /dev/null ++++ b/src/mpl/test/macro_placement_round_trip1.tcl +@@ -0,0 +1,62 @@ ++# Test that the file written by -write_macro_placement round-trips: ++# place_macro must accept every position the macro placer committed ++# (no MPL-0034 out-of-core rejection from snap residue) and land every ++# macro exactly where the placer left it. ++source "helpers.tcl" ++ ++read_lef "./Nangate45/Nangate45.lef" ++read_lef "./testcases/orientation_improve1.lef" ++ ++read_def "./testcases/halos1.def" ++ ++set_thread_count 0 ++ ++proc save_macro_state { } { ++ set state {} ++ foreach inst [[ord::get_db_block] getInsts] { ++ if { [[$inst getMaster] isBlock] } { ++ lappend state $inst [$inst getPlacementStatus] [$inst getOrient] \ ++ [$inst getLocation] ++ } ++ } ++ return $state ++} ++ ++proc restore_macro_state { state } { ++ foreach { inst status orient location } $state { ++ $inst setPlacementStatus $status ++ $inst setOrient $orient ++ $inst setLocation [lindex $location 0] [lindex $location 1] ++ } ++ ++ # Remove the soft blockages created around the macros placed by ++ # the previous run. ++ foreach blockage [[ord::get_db_block] getBlockages] { ++ odb::dbBlockage_destroy $blockage ++ } ++} ++ ++proc macro_locations { } { ++ set locations {} ++ foreach inst [[ord::get_db_block] getInsts] { ++ if { [[$inst getMaster] isBlock] } { ++ lappend locations [$inst getName] [$inst getLocation] [$inst getOrient] ++ } ++ } ++ return $locations ++} ++ ++set initial_state [save_macro_state] ++ ++set placement_file [make_result_file macro_placement_round_trip1.tcl] ++rtl_macro_placer -report_directory [make_result_dir] \ ++ -write_macro_placement $placement_file ++ ++set placed [macro_locations] ++ ++restore_macro_state $initial_state ++source $placement_file ++ ++set injected [macro_locations] ++ ++puts "round trip is exact: [expr { $placed eq $injected }]" +diff --git a/src/mpl/test/orientation_improve1.defok b/src/mpl/test/orientation_improve1.defok +index 47d04dd229..2ff5fd2060 100644 +--- a/src/mpl/test/orientation_improve1.defok ++++ b/src/mpl/test/orientation_improve1.defok +@@ -97,13 +97,13 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ; + TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ; + TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ; + COMPONENTS 1 ; +- - MACRO_1 HM_100x100_1x1 + FIXED ( 21680 21330 ) S ; ++ - MACRO_1 HM_100x100_1x1 + FIXED ( 21680 21050 ) S ; + END COMPONENTS + PINS 1 ; + - io_1 + NET io_1 + DIRECTION INPUT + USE SIGNAL ; + END PINS + BLOCKAGES 1 ; +- - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 21680 21190 ) ( 221680 221470 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 21680 20910 ) ( 221680 221190 ) ; + END BLOCKAGES + NETS 1 ; + - io_1 ( PIN io_1 ) ( MACRO_1 I1 ) + USE SIGNAL ; +diff --git a/src/mpl/test/orientation_improve3.defok b/src/mpl/test/orientation_improve3.defok +index 85be3070a3..0c74706f19 100644 +--- a/src/mpl/test/orientation_improve3.defok ++++ b/src/mpl/test/orientation_improve3.defok +@@ -97,7 +97,7 @@ TRACKS Y 140 DO 282 STEP 3200 LAYER metal9 ; + TRACKS X 190 DO 282 STEP 3200 LAYER metal10 ; + TRACKS Y 140 DO 282 STEP 3200 LAYER metal10 ; + COMPONENTS 1 ; +- - MACRO_1 HM_100x100_1x1 + FIXED ( 21680 21330 ) S ; ++ - MACRO_1 HM_100x100_1x1 + FIXED ( 21680 21050 ) S ; + END COMPONENTS + PINS 1 ; + - io_1 + NET io_1 + DIRECTION INPUT + USE SIGNAL +@@ -106,7 +106,7 @@ PINS 1 ; + + FIXED ( 239930 39900 ) N ; + END PINS + BLOCKAGES 1 ; +- - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 21680 21190 ) ( 221680 221470 ) ; ++ - PLACEMENT + SOFT + COMPONENT MACRO_1 RECT ( 21680 20910 ) ( 221680 221190 ) ; + END BLOCKAGES + NETS 1 ; + - io_1 ( PIN io_1 ) ( MACRO_1 I1 ) + USE SIGNAL ; +-- +2.53.0 + diff --git a/patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch b/patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch new file mode 100644 index 0000000000..dfa4b60aa0 --- /dev/null +++ b/patches/openroad/0004-mpl-seed-std-cells-when-all-macros-fixed.patch @@ -0,0 +1,229 @@ +From f784d0aab8d160ec414af0468a0610bebc31b0f1 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Sun, 30 Aug 2026 23:08:05 +0200 +Subject: [PATCH 4/4] mpl: seed standard cells when all macros are fixed +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +When every macro is fixed, HierRTLMP::run() skipped the whole pipeline, +including generateTemporaryStdCellsPlacement() and the soft blockages +around macros. A full run seeds every standard cell at the center of +its cluster before global placement reads the database, so a macro +placement re-injected through place_macro/MACRO_PLACEMENT_TCL diverged +from the run that generated it (~2% achieved period on designs where +this was measured) even with bit-identical macro geometry. + +Now a design with standard cells goes through clustering, shaping and +the soft-macro annealing even when there are no unfixed macros: the +fixed macros act as fixed obstacles (as they already did in mixed +fixed/unfixed designs), no macro is moved, standard cells are seeded at +their cluster centers and the soft blockages are created, matching what +a generating run leaves behind. Macro-only designs with no standard +cells skip as before. + +The new all_fixed_macros1 test locks every macro and checks that the +standard cells come out placed, no macro moved and the blockages exist. +The no_unfixed_macros golden gains the design-data report block that is +now printed before the skip; its DEF is unchanged. + +Signed-off-by: Øyvind Harboe +--- + src/mpl/src/clusterEngine.cpp | 8 +++-- + src/mpl/src/hier_rtlmp.cpp | 4 ++- + src/mpl/test/BUILD | 5 ++++ + src/mpl/test/CMakeLists.txt | 1 + + src/mpl/test/all_fixed_macros1.ok | 25 ++++++++++++++++ + src/mpl/test/all_fixed_macros1.tcl | 47 ++++++++++++++++++++++++++++++ + src/mpl/test/no_unfixed_macros.ok | 14 +++++++++ + 7 files changed, 101 insertions(+), 3 deletions(-) + create mode 100644 src/mpl/test/all_fixed_macros1.ok + create mode 100644 src/mpl/test/all_fixed_macros1.tcl + +diff --git a/src/mpl/src/clusterEngine.cpp b/src/mpl/src/clusterEngine.cpp +index 332f61cc00..baaa4b59ad 100644 +--- a/src/mpl/src/clusterEngine.cpp ++++ b/src/mpl/src/clusterEngine.cpp +@@ -48,7 +48,12 @@ void ClusteringEngine::run() + { + init(); + +- if (!tree_->has_unfixed_macros) { ++ // With no unfixed macros there is nothing to place, but a design with ++ // standard cells still goes through clustering so that the temporary ++ // standard-cell placement matches the one a run with unfixed macros ++ // would produce - e.g. when a full run's placement is re-injected ++ // with locked macros through place_macro. ++ if (!tree_->has_unfixed_macros && design_metrics_->getNumStdCell() == 0) { + return; + } + +@@ -114,7 +119,6 @@ void ClusteringEngine::init() + if (unfixed_macros.empty()) { + tree_->has_unfixed_macros = false; + logger_->info(MPL, 17, "No unfixed macros."); +- return; + } + + tree_->macro_with_halo_area = computeMacroWithHaloArea(unfixed_macros); +diff --git a/src/mpl/src/hier_rtlmp.cpp b/src/mpl/src/hier_rtlmp.cpp +index 5300665a1c..d9b547f1d5 100644 +--- a/src/mpl/src/hier_rtlmp.cpp ++++ b/src/mpl/src/hier_rtlmp.cpp +@@ -343,7 +343,9 @@ void HierRTLMP::runMultilevelAutoclustering() + clustering_engine_->setHalos(base_halo_, use_full_halo_, macro_to_halo_); + clustering_engine_->run(); + +- if (!tree_->has_unfixed_macros) { ++ // Without a tree there is nothing to place or to seed: the design ++ // has neither unfixed macros nor standard cells. ++ if (!tree_->root) { + skip_macro_placement_ = true; + return; + } +diff --git a/src/mpl/test/BUILD b/src/mpl/test/BUILD +index e9f20addfb..2233dbfbd2 100644 +--- a/src/mpl/test/BUILD ++++ b/src/mpl/test/BUILD +@@ -12,6 +12,7 @@ package(features = ["layering_check"]) + + # From CMakeLists.txt or_integration_tests(TESTS + COMPULSORY_TESTS = [ ++ "all_fixed_macros1", + "boundary_push1", + "centralization1", + "clocked_macro", +@@ -74,6 +75,10 @@ filegroup( + [ + test_name + ".*", + ] + { ++ "all_fixed_macros1": [ ++ "testcases/fixed_macros1.def", ++ "testcases/orientation_improve1.lef", ++ ], + "boundary_push1": [ + "testcases/boundary_push1.def", + "testcases/orientation_improve1.lef", +diff --git a/src/mpl/test/CMakeLists.txt b/src/mpl/test/CMakeLists.txt +index 7b3e67ce7a..a45cec1404 100644 +--- a/src/mpl/test/CMakeLists.txt ++++ b/src/mpl/test/CMakeLists.txt +@@ -1,6 +1,7 @@ + or_integration_tests( + "mpl" + TESTS ++ all_fixed_macros1 + macro_only + no_unfixed_macros + guides1 +diff --git a/src/mpl/test/all_fixed_macros1.ok b/src/mpl/test/all_fixed_macros1.ok +new file mode 100644 +index 0000000000..e60c661cd4 +--- /dev/null ++++ b/src/mpl/test/all_fixed_macros1.ok +@@ -0,0 +1,25 @@ ++[INFO ODB-0227] LEF file: ./Nangate45/Nangate45.lef, created 22 layers, 27 vias, 135 library cells ++[INFO ODB-0227] LEF file: ./testcases/orientation_improve1.lef, created 10 library cells ++[INFO ODB-0128] Design: boundary_push1 ++[INFO ODB-0131] Created 152 components and 904 component-terminals. ++[INFO MPL-0062] Found fixed macro MACRO_1. ++[INFO MPL-0062] Found fixed macro MACRO_2. ++[INFO MPL-0017] No unfixed macros. ++Die Area: (0.00, 0.00) (220.02, 221.20), Floorplan Area: (0.00, 0.00) (220.02, 221.20) ++ Number of std cell instances: 150 ++ Area of std cell instances: 678.30 ++ Number of macros: 2 ++ Macros to be placed: 0 ++ Area of macros: 20000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 0.00 ++ Area of std cell instances + Area of macros: 20678.30 ++ Floorplan area: 48668.42 ++ Design Utilization: 0.42 ++ Floorplan Utilization: 0.02 ++ Manufacturing Grid: 10 ++ ++[WARNING MPL-0026] Design has no IO pins! ++std cells placed: 150 unplaced: 0 ++macros disturbed: 0 ++blockages: 2 +diff --git a/src/mpl/test/all_fixed_macros1.tcl b/src/mpl/test/all_fixed_macros1.tcl +new file mode 100644 +index 0000000000..6866b439fe +--- /dev/null ++++ b/src/mpl/test/all_fixed_macros1.tcl +@@ -0,0 +1,47 @@ ++# Test that a design whose macros are all fixed still gets the ++# temporary standard-cell placement and the soft blockages around the ++# macros, exactly like a run with unfixed macros would produce them. ++# This keeps a placement re-injected through place_macro (e.g. with ++# MACRO_PLACEMENT_TCL) equivalent to the run that generated it. ++source "helpers.tcl" ++ ++read_lef "./Nangate45/Nangate45.lef" ++read_lef "./testcases/orientation_improve1.lef" ++ ++read_def "./testcases/fixed_macros1.def" ++ ++set_thread_count 0 ++ ++set block [ord::get_db_block] ++foreach inst [$block getInsts] { ++ if { [[$inst getMaster] isBlock] } { ++ $inst setPlacementStatus LOCKED ++ } ++} ++ ++rtl_macro_placer -report_directory [make_result_dir] ++ ++set placed 0 ++set unplaced 0 ++foreach inst [$block getInsts] { ++ if { ![[$inst getMaster] isBlock] } { ++ if { [$inst isPlaced] } { ++ incr placed ++ } else { ++ incr unplaced ++ } ++ } ++} ++ ++set macros_moved 0 ++foreach inst [$block getInsts] { ++ if { [[$inst getMaster] isBlock] } { ++ if { [$inst getPlacementStatus] ne "LOCKED" } { ++ incr macros_moved ++ } ++ } ++} ++ ++puts "std cells placed: $placed unplaced: $unplaced" ++puts "macros disturbed: $macros_moved" ++puts "blockages: [llength [$block getBlockages]]" +diff --git a/src/mpl/test/no_unfixed_macros.ok b/src/mpl/test/no_unfixed_macros.ok +index e024bd4877..f1d9da47bc 100644 +--- a/src/mpl/test/no_unfixed_macros.ok ++++ b/src/mpl/test/no_unfixed_macros.ok +@@ -15,5 +15,19 @@ + [INFO MPL-0062] Found fixed macro U8. + [INFO MPL-0062] Found fixed macro U9. + [INFO MPL-0017] No unfixed macros. ++Die Area: (0.00, 0.00) (450.00, 450.00), Floorplan Area: (4.94, 4.20) (444.98, 443.80) ++ Number of std cell instances: 0 ++ Area of std cell instances: 0.00 ++ Number of macros: 10 ++ Macros to be placed: 0 ++ Area of macros: 166000.00 ++ Base halo (L, B, R, T): (0.00, 0.00, 0.00, 0.00) ++ Area of macros with halos: 0.00 ++ Area of std cell instances + Area of macros: 166000.00 ++ Floorplan area: 193441.58 ++ Design Utilization: 0.86 ++ Floorplan Utilization: 0.00 ++ Manufacturing Grid: 10 ++ + [INFO MPL-0013] Skipping macro placement. + No differences found. +-- +2.53.0 + diff --git a/patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch b/patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch new file mode 100644 index 0000000000..b7a355cfa3 --- /dev/null +++ b/patches/openroad/0005-gpl-thread-invariant-parallel-density-scatter.patch @@ -0,0 +1,349 @@ +diff --git a/src/gpl/src/nesterovBase.cpp b/src/gpl/src/nesterovBase.cpp +index 716cb07457..72af8bbcdf 100644 +--- a/src/gpl/src/nesterovBase.cpp ++++ b/src/gpl/src/nesterovBase.cpp +@@ -963,6 +963,49 @@ void BinGrid::updateBinsNonPlaceArea() + } + } + ++// The per-cell density scatter, in place. The bin accumulators are int64_t and ++// each addend is truncated before it is added, so the total is a sum over a ++// fixed multiset of integers -- associative and commutative, hence independent ++// of the order threads reach it, and bit-identical at any thread count. ++// ++// schedule(dynamic) because per-cell cost is its bin-overlap count, which ++// varies by an order of magnitude between a std cell and a macro. ++void BinGrid::scatterDensityAreaInPlace(const std::vector& cells, ++ int parallel_threads) ++{ ++#pragma omp parallel for num_threads(parallel_threads) schedule(dynamic, 128) ++ for (const GCellHandle& cell : cells) { ++ const std::pair pairX = getDensityMinMaxIdxX(cell); ++ const std::pair pairY = getDensityMinMaxIdxY(cell); ++ ++ if (cell->isInstance()) { ++ const bool macro = cell->isMacroInstance(); ++ if (!macro && !cell->isStdInstance()) { ++ continue; ++ } ++ for (int y = pairY.first; y < pairY.second; y++) { ++ for (int x = pairX.first; x < pairX.second; x++) { ++ Bin& bin = bins_[y * binCntX_ + x]; ++ float scaledArea ++ = getOverlapDensityArea(bin, cell) * cell->getDensityScale(); ++ if (macro) { ++ scaledArea *= bin.getTargetDensity(); ++ } ++ bin.atomicAddInstPlacedAreaUnscaled(static_cast(scaledArea)); ++ } ++ } ++ } else if (cell->isFiller()) { ++ for (int y = pairY.first; y < pairY.second; y++) { ++ for (int x = pairX.first; x < pairX.second; x++) { ++ Bin& bin = bins_[y * binCntX_ + x]; ++ bin.atomicAddFillerArea(static_cast( ++ getOverlapDensityArea(bin, cell) * cell->getDensityScale())); ++ } ++ } ++ } ++ } ++} ++ + // Core Part + void BinGrid::updateBinsGCellDensityArea(const std::vector& cells, + int parallel_threads) +@@ -973,12 +1016,12 @@ void BinGrid::updateBinsGCellDensityArea(const std::vector& cells, + bin.setFillerArea(0); + } + +- // The per-cell scatter below is the dominant host hotspot of the global +- // placer. On the GPU path it dwarfs everything else (the device sits idle +- // while this runs serially), and that path already tolerates a few-ULP, +- // thread-order-dependent result. So parallelize it there, accumulating +- // per-bin areas into flat buffers with atomics. The CPU-only path keeps the +- // serial branch for bit-stable regression goldens. ++ // A single scatter implementation for every CPU case, threaded or not, so ++ // that every existing test exercises the code that threaded runs use. ++#ifdef ENABLE_GPU ++ // The device build keeps its pre-existing flat-buffer scatter for threaded ++ // runs: that one is thread-order-dependent, and this change cannot ++ // re-verify the device path. + if (parallel_threads > 1) { + const int nbins = static_cast(bins_.size()); + std::vector inst_area(nbins, 0.0f); +@@ -1023,50 +1066,11 @@ void BinGrid::updateBinsGCellDensityArea(const std::vector& cells, + bins_[b].setFillerArea(filler_area[b]); + } + } else { +- for (auto& cell : cells) { +- std::pair pairX = getDensityMinMaxIdxX(cell); +- std::pair pairY = getDensityMinMaxIdxY(cell); +- +- // The following function is critical runtime hotspot +- // for global placer. +- // +- if (cell->isInstance()) { +- // macro should have +- // scale-down with target-density +- if (cell->isMacroInstance()) { +- for (int y = pairY.first; y < pairY.second; y++) { +- for (int x = pairX.first; x < pairX.second; x++) { +- Bin& bin = bins_[y * binCntX_ + x]; +- +- const float scaledAvea = getOverlapDensityArea(bin, cell) +- * cell->getDensityScale() +- * bin.getTargetDensity(); +- bin.addInstPlacedAreaUnscaled(scaledAvea); +- } +- } +- } +- // normal cells +- else if (cell->isStdInstance()) { +- for (int y = pairY.first; y < pairY.second; y++) { +- for (int x = pairX.first; x < pairX.second; x++) { +- Bin& bin = bins_[y * binCntX_ + x]; +- const float scaledArea +- = getOverlapDensityArea(bin, cell) * cell->getDensityScale(); +- bin.addInstPlacedAreaUnscaled(scaledArea); +- } +- } +- } +- } else if (cell->isFiller()) { +- for (int y = pairY.first; y < pairY.second; y++) { +- for (int x = pairX.first; x < pairX.second; x++) { +- Bin& bin = bins_[y * binCntX_ + x]; +- bin.addFillerArea(getOverlapDensityArea(bin, cell) +- * cell->getDensityScale()); +- } +- } +- } +- } ++ scatterDensityAreaInPlace(cells, 1); + } ++#else ++ scatterDensityAreaInPlace(cells, parallel_threads); ++#endif + + odb::dbBlock* block = pb_->db()->getChip()->getBlock(); + sumOverflowArea_ = 0; +@@ -3143,19 +3147,24 @@ void NesterovBase::updateGCellDensityCenterLocation( + for (int idx = 0; idx < coordis.size(); ++idx) { + nb_gcells_[idx]->setDensityCenterLocation(coordis[idx].x, coordis[idx].y); + } +- int scatter_threads = 1; + #ifdef ENABLE_GPU ++ int scatter_threads = 1; + // Host coords changed — the device copy is no longer authoritative until + // the next commitCoordsToDeviceState (sticky-freshness contract). + if (nbc_->getDeviceState()) { + nbc_->getDeviceState()->invalidateCoords(); + } +- // GPU path tolerates non-deterministic float ordering; parallelize the +- // density scatter (the dominant host cost) there. CPU-only stays serial +- // (scatter_threads == 1) so its regression goldens stay bit-stable. ++ // Only the device build takes the flat-buffer scatter, which is ++ // thread-order-dependent; without a device it stays serial. + if (nb_device_ctx_ != nullptr) { + scatter_threads = static_cast(nbc_->getNumThreads()); + } ++#else ++ // Order-independent in place (integer accumulators, truncated addends), so ++ // threading it does not change the result. nbc_ is the thread count every ++ // other parallel loop in gpl uses; BinGrid::num_threads_ is not it -- ++ // BinGrid::setNumThreads() has no callers, so it is always 1. ++ const int scatter_threads = static_cast(nbc_->getNumThreads()); + #endif + bg_.updateBinsGCellDensityArea(nb_gcells_, scatter_threads); + } +diff --git a/src/gpl/src/nesterovBase.h b/src/gpl/src/nesterovBase.h +index f513616519..81915b005a 100644 +--- a/src/gpl/src/nesterovBase.h ++++ b/src/gpl/src/nesterovBase.h +@@ -3,6 +3,7 @@ + + #pragma once + ++#include + #include + #include + #include +@@ -588,9 +589,11 @@ class Bin + void addNonPlaceArea(int64_t area); + void addInstPlacedArea(int64_t area); + void addFillerArea(int64_t area); ++ void atomicAddFillerArea(int64_t area); + + void addNonPlaceAreaUnscaled(int64_t area); + void addInstPlacedAreaUnscaled(int64_t area); ++ void atomicAddInstPlacedAreaUnscaled(int64_t area); + + int64_t getBinArea() const; + int64_t getNonPlaceArea() const { return nonPlaceArea_; } +@@ -695,6 +698,26 @@ inline void Bin::addFillerArea(int64_t area) + fillerArea_ += area; + } + ++// For the threaded density scatter. The accumulators are integers and each ++// addend is truncated before it is added, so the sum is over a fixed multiset ++// of integers -- associative and commutative, hence independent of the order ++// threads reach it. Relaxed suffices: we need atomicity, not ordering, and the ++// result is consumed only after the parallel region's implicit barrier. ++// atomic_ref rather than an atomic member so the field stays a plain int64_t: ++// Bin remains trivially copyable for its vector, and the serial path keeps its ++// non-atomic add. ++inline void Bin::atomicAddInstPlacedAreaUnscaled(int64_t area) ++{ ++ std::atomic_ref ref(instPlacedAreaUnscaled_); ++ ref.fetch_add(area, std::memory_order_relaxed); ++} ++ ++inline void Bin::atomicAddFillerArea(int64_t area) ++{ ++ std::atomic_ref ref(fillerArea_); ++ ref.fetch_add(area, std::memory_order_relaxed); ++} ++ + // + // The bin can be non-uniform because of + // "integer" coordinates +@@ -712,6 +735,8 @@ class BinGrid + void setBinTargetDensity(float density); + void updateBinsGCellDensityArea(const std::vector& cells, + int parallel_threads = 1); ++ void scatterDensityAreaInPlace(const std::vector& cells, ++ int parallel_threads); + void setNumThreads(int num_threads) { num_threads_ = num_threads; } + + void initBins(); +diff --git a/src/gpl/test/BUILD b/src/gpl/test/BUILD +index 2af65d4bed..3c85888b38 100644 +--- a/src/gpl/test/BUILD ++++ b/src/gpl/test/BUILD +@@ -21,6 +21,7 @@ TESTS = [ + "mbff_orig_name", + "mbff_clock_power_off", + "mbff_clock_power_on", ++ "mt_invariance01", + "nograd01", + "simple01", + "simple01-obs", +diff --git a/src/gpl/test/CMakeLists.txt b/src/gpl/test/CMakeLists.txt +index 56b18be4e6..5f6d280765 100644 +--- a/src/gpl/test/CMakeLists.txt ++++ b/src/gpl/test/CMakeLists.txt +@@ -11,6 +11,7 @@ or_integration_tests( + mbff_orig_name + mbff_clock_power_off + mbff_clock_power_on ++ mt_invariance01 + convergence01 + core01 + density01 +diff --git a/src/gpl/test/mt_invariance01.ok b/src/gpl/test/mt_invariance01.ok +new file mode 100644 +index 0000000000..b6d9f548ef +--- /dev/null ++++ b/src/gpl/test/mt_invariance01.ok +@@ -0,0 +1,81 @@ ++[INFO ODB-0227] LEF file: ./nangate45.lef, created 22 layers, 27 vias, 134 library cells ++[INFO ODB-0128] Design: gcd ++[INFO ODB-0130] Created 54 pins. ++[INFO ODB-0131] Created 294 components and 1656 component-terminals. ++[INFO ODB-0133] Created 364 nets and 1068 connections. ++[INFO GPL-0001] ---- Initialize GPL Main Data Structures ++[INFO GPL-0002] DBU: 2000 ++[INFO GPL-0003] SiteSize: ( 0.190 1.400 ) um ++[INFO GPL-0004] CoreBBox: ( 1.140 1.120 ) ( 35.150 34.720 ) um ++[INFO GPL-0016] Core area: 1142.736 um^2 ++[INFO GPL-0036] Movable instances area: 569.772 um^2 ++[INFO GPL-0037] Total instances area: 569.772 um^2 ++[INFO GPL-0035] Pin density area adjust: 49.963 um^2 ++[INFO GPL-0032] ---- Initialize Region: Top-level ++[INFO GPL-0006] Number of instances: 294 ++[INFO GPL-0007] Movable instances: 294 ++[INFO GPL-0008] Fixed instances: 0 ++[INFO GPL-0009] Dummy instances: 0 ++[INFO GPL-0010] Number of nets: 364 ++[INFO GPL-0011] Number of pins: 1122 ++[INFO GPL-0012] Die BBox: ( 0.000 0.000 ) ( 36.290 35.840 ) um ++[INFO GPL-0013] Placement BBox: ( 1.140 1.120 ) ( 35.150 34.720 ) um ++[INFO GPL-0014] Region name: top-level. ++[INFO GPL-0015] Region area: 1142.736 um^2 ++[INFO GPL-0017] Fixed instances area: 0.000 um^2 ++[INFO GPL-0018] Movable instances area: 619.735 um^2 ++[INFO GPL-0019] Utilization: 54.233 % ++[INFO GPL-0020] Standard cells area: 619.735 um^2 ++[INFO GPL-0021] Large instances area: 0.000 um^2 ++[INFO GPL-0005] ---- Execute Conjugate Gradient Initial Placement. ++[INFO GPL-0051] Source of initial instance position counters: ++ Odb location = 0 Core center = 294 Region center = 0 ++[INFO GPL-0033] ---- Initialize Nesterov Region: Top-level ++[INFO GPL-0023] Placement target density: 0.6000 ++[INFO GPL-0024] Movable insts average area: 2.108 um^2 ++[INFO GPL-0025] Ideal bin area: 3.513 um^2 ++[INFO GPL-0026] Ideal bin count: 325 ++[INFO GPL-0027] Total bin area: 1142.736 um^2 ++[INFO GPL-0028] Bin count (X, Y): 16 , 16 ++[INFO GPL-0029] Bin size (W * H): 2.126 * 2.100 um ++[INFO GPL-0030] Number of bins: 256 ++[INFO GPL-0084] ---- Execute Nesterov Global Placement. ++[INFO GPL-0031] HPWL: Half-Perimeter Wirelength ++Iteration | Overflow | HPWL (um) | HPWL(%) | Penalty | Group ++--------------------------------------------------------------- ++ 0 | 0.8471 | 2.124479e+03 | +0.00% | 2.36e-11 | ++ 10 | 0.7302 | 2.459177e+03 | +15.75% | 3.84e-11 | ++ 20 | 0.7311 | 2.451608e+03 | -0.31% | 6.26e-11 | ++ 30 | 0.7279 | 2.459456e+03 | +0.32% | 1.02e-10 | ++ 40 | 0.7215 | 2.470071e+03 | +0.43% | 1.66e-10 | ++ 50 | 0.7131 | 2.485809e+03 | +0.64% | 2.71e-10 | ++ 60 | 0.7026 | 2.508582e+03 | +0.92% | 4.41e-10 | ++ 70 | 0.6843 | 2.539997e+03 | +1.25% | 7.18e-10 | ++ 80 | 0.6603 | 2.573686e+03 | +1.33% | 1.17e-09 | ++ 90 | 0.6306 | 2.614474e+03 | +1.58% | 1.91e-09 | ++ 100 | 0.5952 | 2.659126e+03 | +1.71% | 3.10e-09 | ++ 110 | 0.5496 | 2.695956e+03 | +1.39% | 5.06e-09 | ++ 120 | 0.4990 | 2.714812e+03 | +0.70% | 8.24e-09 | ++ 130 | 0.4450 | 2.705711e+03 | -0.34% | 1.34e-08 | ++ 140 | 0.3858 | 2.688052e+03 | -0.65% | 2.19e-08 | ++ 150 | 0.3384 | 2.704224e+03 | +0.60% | 3.52e-08 | ++ 160 | 0.3051 | 2.724860e+03 | +0.76% | 5.19e-08 | ++ 170 | 0.2804 | 2.753178e+03 | +1.04% | 7.65e-08 | ++ 180 | 0.2450 | 2.773965e+03 | +0.76% | 1.13e-07 | ++ 190 | 0.2171 | 2.801530e+03 | +0.99% | 1.66e-07 | ++ 200 | 0.1864 | 2.822570e+03 | +0.75% | 2.44e-07 | ++ 210 | 0.1637 | 2.843765e+03 | +0.75% | 3.60e-07 | ++ 220 | 0.1368 | 2.861595e+03 | +0.63% | 5.31e-07 | ++ 230 | 0.1105 | 2.874573e+03 | +0.45% | 7.82e-07 | ++ 237 | 0.0989 | 2.881644e+03 | | 1.07e-06 | ++--------------------------------------------------------------- ++[INFO GPL-1001] Global placement finished at iteration 237 ++[INFO GPL-1002] Placed Cell Area 619.7347 ++[INFO GPL-1003] Available Free Area 1142.7360 ++[INFO GPL-1004] Minimum Feasible Density 0.5500 (cell_area / free_area) ++[INFO GPL-1006] Suggested Target Densities: ++[INFO GPL-1007] - For 90% usage of free space: 0.6026 ++[INFO GPL-1008] - For 80% usage of free space: 0.6779 ++[INFO GPL-1014] Final placement area: 619.73 (+0.00%) ++[INFO GPL-1018] Final HPWL (um): 2886.89 ++No differences found. +diff --git a/src/gpl/test/mt_invariance01.tcl b/src/gpl/test/mt_invariance01.tcl +new file mode 100644 +index 0000000000..2a96daac3b +--- /dev/null ++++ b/src/gpl/test/mt_invariance01.tcl +@@ -0,0 +1,15 @@ ++# Global placement must be bit-identical at any thread count. The density ++# scatter accumulates into the integer bin fields with each addend truncated ++# before it is added, so the sum is order-independent; this asserts that by ++# running core01 threaded against core01's single-threaded golden. ++source helpers.tcl ++set test_name mt_invariance01 ++read_lef ./nangate45.lef ++read_def ./core01.def ++ ++set_thread_count 8 ++global_placement -density 0.6 -init_density_penalty 0.01 -skip_initial_place ++ ++set def_file [make_result_file $test_name.def] ++write_def $def_file ++diff_file $def_file core01.defok diff --git a/patches/openroad/BUILD.bazel b/patches/openroad/BUILD.bazel new file mode 100644 index 0000000000..698cafd0f9 --- /dev/null +++ b/patches/openroad/BUILD.bazel @@ -0,0 +1,9 @@ +"""OpenROAD fixes carried as git_override patches. + +The openroad module is fetched via git_override (with submodules) and +these patches are applied on top; they may therefore also patch +submodule content such as src/sta. Drop each file when the fix lands +upstream and the pinned commit is bumped past it. +""" + +exports_files(glob(["*.patch"])) From b56e673ff6837ae5fafb171368edfba0a028b521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 11:27:11 +0200 Subject: [PATCH 02/11] flow: E12 falls back to serial when bazel-orfs has no fork facility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found while preparing to actually run the probe: macro_e12.tcl opened with an unconditional `source $::env(ORFS_FORK_TCL)`, and the bazel-orfs commit ORFS pins has no fork facility at all -- no fork/ directory, no ORFS_FORK_TCL, no fork_attrs(). The script would have died on its first line, before doing anything. Detect it and fall back to the serial arm, which already existed for the threading comparison. This is a throughput difference, not a measurement difference -- the same candidates, the same scores, one at a time -- but it is a large one: the upstream campaign measured 65 candidates/h forked against 23.8 serial, because generation dominates and RTL-MP is thread-insensitive. Say so where someone is about to ask for 24 candidates, and point at E12_K=1 as the way to exercise the pipeline first. Bumping bazel-orfs to get fork back would be the alternative, but that is an ORFS-wide change in service of one experiment's throughput, and the serial arm measures the same thing. Signed-off-by: Øyvind Harboe --- flow/test/macro_e12/README.md | 15 ++++++-- flow/test/macro_e12/macro_e12.tcl | 58 +++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/flow/test/macro_e12/README.md b/flow/test/macro_e12/README.md index ba2eb1a186..b2d2819251 100644 --- a/flow/test/macro_e12/README.md +++ b/flow/test/macro_e12/README.md @@ -87,11 +87,20 @@ named explicitly rather than declared as an output. EV=$PWD/e12_evidence # anywhere outside the source tree mkdir -p "$EV" -# Step 0 -- regenerate the 24 candidates and re-measure them flat (~25 min -# on a 24-core machine). Writes cand_s.{json,place.tcl,odb} and -# base_floorplan.odb. +# Step 0 -- regenerate the candidates and re-measure them flat. Writes +# cand_s.{json,place.tcl,odb} and base_floorplan.{odb,sdc}. +# +# Candidates run SERIALLY on the bazel-orfs pin ORFS currently uses: the +# fork facility that makes them cheap is not present, and the script +# detects that and falls back rather than failing. The upstream campaign +# measured 65 candidates/h forked against 23.8 serial, so budget hours +# rather than the ~25 minutes a forked run takes -- or start with E12_K=1. bazelisk run //flow/test/macro_e12:swerv_candidates -- E12_OUT_DIR=$EV +# Probe first. One candidate is enough to exercise every step below, and +# it is what the pre-campaign checks need. +bazelisk run //flow/test/macro_e12:swerv_candidates -- E12_OUT_DIR=$EV E12_K=1 + # Step 1 -- dump RTL-MP's cluster partition from the base floorplan, once. bazelisk run //flow/test/macro_e12:swerv_dump_clusters -- E12_OUT_DIR=$EV diff --git a/flow/test/macro_e12/macro_e12.tcl b/flow/test/macro_e12/macro_e12.tcl index da90533297..a3f20ceac2 100644 --- a/flow/test/macro_e12/macro_e12.tcl +++ b/flow/test/macro_e12/macro_e12.tcl @@ -19,18 +19,38 @@ # live in a score measured after the fact, not in the cost function. # # One production floorplan spine is shared; candidates diverge only at -# macro_place, so the fork copy-on-write snapshot pays for the whole -# shared prefix. Two execution shapes, selected by E12_SERIAL_THREADS: +# macro_place, so a copy-on-write snapshot would pay for the whole shared +# prefix. Two execution shapes, selected by E12_SERIAL_THREADS: # -# 0 (default) fork -jobs $E12_JOBS: candidates in parallel, -# single-threaded each (a fork child must not raise its -# own thread count). +# 0 fork -jobs $E12_JOBS: candidates in parallel, +# single-threaded each (a fork child must not raise its own +# thread count). Requires bazel-orfs's fork facility. # N > 0 no fork: candidates run sequentially in the parent with -# set_thread_count N. Kept because it is the only shape -# that can be compared against the clustered scorer's -# threading behaviour. +# set_thread_count N. +# +# The fork facility is not in every bazel-orfs pin -- notably not in the +# one ORFS currently pins -- so when it is missing this falls back to the +# serial arm automatically. That is a throughput difference, not a +# measurement difference: the upstream campaign measured 65 candidates/h +# forked against 23.8 serial, because generation dominates and RTL-MP is +# thread-insensitive. Budget accordingly before asking for 24 of them. + +# The fork facility is optional. It is what makes many candidates cheap +# -- they share the whole floorplan prefix through a copy-on-write +# snapshot -- but it lives in bazel-orfs and is not present in every pin, +# so its absence must degrade to the serial arm rather than crash. The +# serial arm is not a lesser measurement: it produces the same scores, +# one at a time (see e12_reset_placement for what it has to undo by hand +# that a fork child gets for free). +set ::e12_have_fork 0 +if { + [info exists ::env(ORFS_FORK_TCL)] + && [file exists $::env(ORFS_FORK_TCL)] +} { + source $::env(ORFS_FORK_TCL) + set ::e12_have_fork 1 +} -source $::env(ORFS_FORK_TCL) set e12_dir [file dirname [file normalize [info script]]] source [file join $e12_dir e12_lib.tcl] source [file join $e12_dir extract_lib.tcl] @@ -42,7 +62,12 @@ if { $::e12_out eq "" } { set ::e12_work [e12_env E12_WORK [file join $::env(WORK_HOME) e12_work]] set ::e12_k [e12_env E12_K 24] set ::e12_jobs [e12_env E12_JOBS 12] +# 0 means "use fork if it is available". A positive value, or the absence +# of fork, selects the serial arm with that many threads. set ::e12_serial_threads [e12_env E12_SERIAL_THREADS 0] +if { !$::e12_have_fork && $::e12_serial_threads == 0 } { + set ::e12_serial_threads 1 +} set ::e12_fork_opts [list -timeout [e12_env E12_CHILD_TIMEOUT 14400]] file mkdir $::e12_out @@ -186,12 +211,15 @@ set seeds {} for { set i 0 } { $i < $::e12_k } { incr i } { lappend seeds $i } -puts "e12: [llength $seeds] candidates,\ - [expr { - $::e12_serial_threads > 0 ? - "serial with $::e12_serial_threads threads" : - "fork -jobs $::e12_jobs" -}]" +if { $::e12_serial_threads > 0 } { + set shape "serial with $::e12_serial_threads threads" + if { !$::e12_have_fork } { + append shape " (fork unavailable in this bazel-orfs pin)" + } +} else { + set shape "fork -jobs $::e12_jobs" +} +puts "e12: [llength $seeds] candidates, $shape" e12_redirect spine file copy -force $::env(ODB_FILE) \ From 3ad77a0e6cd7b75c752ef0093a199a3083593735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 12:32:11 +0200 Subject: [PATCH 03/11] bazel: drop the empty patches/tcl_lang package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4969ea785 removed the tclZipfs patch when it landed in BCR tcl_lang, but left behind patches/tcl_lang/BUILD.bazel, whose only content is `exports_files(glob(["*.patch"]))` over a directory that now has no patches. glob() disallows empty matches by default, so any target pattern that has to parse this package fails: ERROR: package contains errors: patches/tcl_lang Error in glob: glob pattern '*.patch' didn't match anything Building a named target never touches it, which is why this went unnoticed -- but `bazelisk build //...` and `bazelisk test //...` cannot parse the repository at all. Nothing references //patches/tcl_lang (the @tcl_lang// references elsewhere are the external module), so remove the directory rather than papering over it with allow_empty. Signed-off-by: Øyvind Harboe --- patches/tcl_lang/BUILD.bazel | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 patches/tcl_lang/BUILD.bazel diff --git a/patches/tcl_lang/BUILD.bazel b/patches/tcl_lang/BUILD.bazel deleted file mode 100644 index 73513a9ed2..0000000000 --- a/patches/tcl_lang/BUILD.bazel +++ /dev/null @@ -1,7 +0,0 @@ -"""tcl_lang fixes carried as single_version_override patches. - -Mirrored from tools/OpenROAD/bazel/tcl-patches (overrides are -root-honored only). Drop when tools/OpenROAD drops its copy. -""" - -exports_files(glob(["*.patch"])) From e2143f01915810ba7af20dae5bc797eb3fec9909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 12:38:02 +0200 Subject: [PATCH 04/11] bazel: bump bazel-orfs for OpenROAD-SYN synthesis support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every design whose config.mk sets SYNTH_USE_SYN=1 -- gcd and swerv_wrapper among them -- fails its bazel synth on the previous pin: sv_elaborate -D SYNTHESIS ... --top gcd --std=1364-2005 error: no input files [ERROR SYN-0001] Elaboration failed. VERILOG_FILES arrives empty. bazel-orfs empties it for the synth action on purpose -- the yosys path synthesises from canonicalized RTLIL and the sources are deliberately not among that action's inputs -- but OpenROAD-SYN elaborates the sources directly and has no canonicalize step, so it gets nothing. The previous pin (6ebadeb4) predates bazel-orfs 4254fc9 "synth: support OpenROAD-SYN engine (SYNTH_USE_SYN=1)", which is what teaches the synth action the difference. Bump to ca4e9dd, the last commit before bazel-orfs 9bc8c74 "migrate from local verilog submodule to rules_chisel" deletes the verilog/ subtree that @bazel-orfs-verilog is built from (strip_prefix = "verilog"). Going further means migrating ORFS to rules_chisel, and bazel-orfs main has additionally moved to Bazel 9.1.1 while ORFS is on 8.6.0. Note //fork lands only after that removal and so is still out of reach here. Verified by differential analysis rather than by hope: `bazelisk build --nobuild --keep_going //...` produces a byte-identical set of failures before and after the bump, so the 68 commits introduce no new analysis breakage. Those remaining failures are pre-existing on master and are left alone here: * //flow/designs/asap7/gcd:gcd_single_flow references :gcd_yosys_synth, which no rule emits at either pin * //flow/designs/nangate45/mempool_group:mempool_group_synth hits visibility errors on //flow/designs/src/mempool_group/rtl sources //flow/designs/asap7/gcd:gcd_synth now builds through to 1_synth.odb. Signed-off-by: Øyvind Harboe --- MODULE.bazel | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index bcc6e41f6f..c24284cd8f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -155,7 +155,23 @@ bazel_dep(name = "bazel-orfs", version = "0.0.1") bazel_dep(name = "bazel-orfs-verilog", dev_dependency = True) -BAZEL_ORFS_COMMIT = "6ebadeb4be5c9ada103081c9a5e668c014126616" +# Bumped past bazel-orfs 4254fc9 "synth: support OpenROAD-SYN engine +# (SYNTH_USE_SYN=1)". The previous pin predated that support, so every +# design whose config.mk sets SYNTH_USE_SYN=1 -- gcd and swerv_wrapper +# among them -- failed its bazel synth with `sv_elaborate ... error: no +# input files`. bazel-orfs empties VERILOG_FILES for the synth action +# because the yosys path reads canonicalized RTLIL instead and the +# sources are not among that action's inputs; OpenROAD-SYN elaborates the +# sources directly and has no canonicalize step, so it needs them. +# +# This is the last commit before bazel-orfs 9bc8c74 "migrate from local +# verilog submodule to rules_chisel", which deletes the verilog/ subtree +# that @bazel-orfs-verilog is built from below (strip_prefix = "verilog"). +# Going further therefore means migrating ORFS to rules_chisel, which is +# its own change. Note that bazel-orfs's //fork facility lands only after +# that removal, so it is still unavailable here -- flow/test/macro_e12 +# detects its absence and runs candidates serially. +BAZEL_ORFS_COMMIT = "ca4e9dd41e0f2e7ab3174535dab4fc7c680b1085" BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git" From ec114b5afbac17b260795a24c20a851eb8837048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 12:42:25 +0200 Subject: [PATCH 05/11] flow: spell swerv_wrapper's clkgate model as a resolved path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit asap7/swerv_wrapper's bazel synthesis failed at elaboration: swerv_wrapper.sv2v.v:32:1: error: unknown module 'OPENROAD_CLKGATE' OPENROAD_CLKGATE clkgate ( The sv2v'd RTL instantiates OPENROAD_CLKGATE directly, so the clkgate mapping model is a plain source file and config.mk duly lists it in VERILOG_FILES -- as $(CLKGATE_MAP_FILE), which expands through $(PRIMARY_VT_TAG) -> $(PRIMARY_VT) -> $(word 1, $(VT_LIST)). bazel-orfs's config.mk parser cannot evaluate make functions, so any VERILOG_FILES entry containing "$(" is dropped when the list is turned into bazel labels. Under make the file is present and everything works; under bazel the module definition silently disappears and the failure surfaces much later, at elaboration. Spelling the path out is what makes it a label the parser can resolve. Note this is a general trap, not a swerv quirk: any design putting a make-computed path in VERILOG_FILES is broken under bazel the same way, and the symptom is an undefined module rather than a missing file. The value written here is what $(CLKGATE_MAP_FILE) already expands to for the platform's default PRIMARY_VT (RVT), verified with `make print-VERILOG_FILES`: the make flow sees the identical three files before and after, so only the bazel path changes. The comment records that the literal has to be kept in step with that default and with ASAP7_USE_VT should this design ever set it. With this, //flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth builds through to 1_synth.odb (design area 47979 um^2). Signed-off-by: Øyvind Harboe --- flow/designs/asap7/swerv_wrapper/config.mk | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/flow/designs/asap7/swerv_wrapper/config.mk b/flow/designs/asap7/swerv_wrapper/config.mk index f5b1745e48..1a923ad9af 100644 --- a/flow/designs/asap7/swerv_wrapper/config.mk +++ b/flow/designs/asap7/swerv_wrapper/config.mk @@ -44,9 +44,18 @@ export SYNTH_KEEP_MODULES ?= \ export LIB_MODEL = CCS +# The sv2v'd RTL instantiates OPENROAD_CLKGATE directly, so the clkgate +# mapping model is a source file rather than a synthesis techmap input. +# Spelled as a resolved path on purpose: bazel-orfs's config.mk parser +# cannot evaluate the make functions behind $(PRIMARY_VT_TAG), so +# $(CLKGATE_MAP_FILE) is dropped when the file list is turned into bazel +# labels, and elaboration then fails with `unknown module +# 'OPENROAD_CLKGATE'`. This path is what $(CLKGATE_MAP_FILE) expands to +# for the platform's default PRIMARY_VT (RVT); it must be kept in step +# with that default, and with ASAP7_USE_VT if this design ever sets it. export VERILOG_FILES = $(DESIGN_HOME)/src/swerv/swerv_wrapper.sv2v.v \ $(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/macros.v \ - $(CLKGATE_MAP_FILE) + $(PLATFORM_DIR)/yoSys/cells_clkgate_R.v export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/constraint.sdc export ADDITIONAL_LEFS = $(sort $(wildcard $(DESIGN_HOME)/$(PLATFORM)/swerv_wrapper/lef/*.lef)) From 9394ac38d01a60a9e8a1ce62a5aa9a16996b563f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 12:55:24 +0200 Subject: [PATCH 06/11] flow: fix E12's cluster dump to read a partition, not a double count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First real run of the cluster dump reported "32 leaf clusters covering 203718 of 101831 movable instances" -- more instances than the design has, by exactly 2x. dbBlock::getGroups() returns EVERY group in the block, not just the roots of the tree, so recursing into children from each entry reaches every leaf twice: once as its own starting point (it has no children, so it looks like a leaf) and once via its parent. Select leaves directly from the flat list instead; no recursion is needed. This mattered more than a wrong log line. gpl::placement_cluster_cmd accepts repeated declarations of the same instance without complaint and keeps the last, so the scorer would have run happily on a cluster model that was not a partition of the netlist, and produced numbers that looked entirely reasonable. Replace the count with a check that actually holds the invariant -- fail if any instance is assigned to two clusters -- and report coverage over the population the scorer will really cluster (movable, non-macro) rather than a raw total. After the fix, on asap7/swerv_wrapper: 16 leaf clusters, 101831 of 101831 movable instances covered, plus the 28 macros the tree also carries and the scorer filters out. Also expose the design's synth stage to the experiment. orfs_design leaves flow targets package-private and ORFS's design() has no visibility passthrough, so //flow/test/macro_e12 could not consume swerv_wrapper_synth at all. Add a narrow alias visible to that one package rather than widening the whole flow-target family. Signed-off-by: Øyvind Harboe --- flow/designs/asap7/swerv_wrapper/BUILD | 10 +++ flow/test/macro_e12/BUILD | 2 +- flow/test/macro_e12/dump_clusters.tcl | 108 ++++++++++++++++--------- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/flow/designs/asap7/swerv_wrapper/BUILD b/flow/designs/asap7/swerv_wrapper/BUILD index 527d6542e1..3218f12ee2 100644 --- a/flow/designs/asap7/swerv_wrapper/BUILD +++ b/flow/designs/asap7/swerv_wrapper/BUILD @@ -1,3 +1,13 @@ load("//flow/designs:design.bzl", "design") design(config = "config.mk") + +# The E12 macro-placement experiment (//flow/test/macro_e12) drives this +# design's flow from its synthesis output. design() leaves the flow +# targets package-private, so expose just the synth stage to that one +# package rather than widening the whole family. +alias( + name = "swerv_wrapper_synth_for_e12", + actual = ":swerv_wrapper_synth", + visibility = ["//flow/test/macro_e12:__pkg__"], +) diff --git a/flow/test/macro_e12/BUILD b/flow/test/macro_e12/BUILD index 91978716c1..0a0530d1a3 100644 --- a/flow/test/macro_e12/BUILD +++ b/flow/test/macro_e12/BUILD @@ -15,7 +15,7 @@ load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") SWERV = DESIGNS["asap7/swerv_wrapper"] -SWERV_SYNTH = "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth" +SWERV_SYNTH = "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth_for_e12" # The helper Tcl travels as `data`, which orfs_run_executable stages # alongside `script`, so each driver sources it as a sibling. diff --git a/flow/test/macro_e12/dump_clusters.tcl b/flow/test/macro_e12/dump_clusters.tcl index e49348e97a..3ca84606c6 100644 --- a/flow/test/macro_e12/dump_clusters.tcl +++ b/flow/test/macro_e12/dump_clusters.tcl @@ -69,39 +69,72 @@ set mpl_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] set block [ord::get_db_block] -# Emit leaf groups only. A dbGroup tree node whose children are groups -# is an interior level of the hierarchy; its instances are already -# accounted for by its descendants, so folding it in would double-count. -proc e12_leaf_groups { groups } { - set leaves {} - foreach group $groups { - set children [$group getGroups] - if { [llength $children] == 0 } { - lappend leaves $group - } else { - lappend leaves {*}[e12_leaf_groups $children] - } +# Leaf groups only: an interior node's instances are already accounted +# for by its descendants. +# +# dbBlock::getGroups() returns EVERY group in the block, not just the +# roots of the tree, so recursing from each entry reaches the same leaf +# through itself and through each of its ancestors -- which silently +# counted every instance twice on swerv_wrapper (203718 rows for 101831 +# movables). Select leaves directly from the flat list instead; no +# recursion is needed or wanted. +set leaves {} +foreach group [$block getGroups] { + if { [llength [$group getGroups]] == 0 } { + lappend leaves $group } - return $leaves } -set leaves [e12_leaf_groups [$block getGroups]] - -# Sort by group name, and instances within a group by odb id, so the file -# is a pure function of the database. -set rows {} -set grouped 0 -foreach group $leaves { - set name [$group getName] - set ids {} +# Build the assignment and check it really is a partition. A cluster +# model that double-assigns an instance is not a coarsening of the +# netlist, and gpl would take the last declaration silently, so this +# fails loudly instead. +set assignment [dict create] +set conflicts {} +foreach group [lsort -command {apply {{a b} {string compare [$a getName] [$b getName]}}} $leaves] { + set cname [$group getName] foreach inst [$group getInsts] { - lappend ids [$inst getId] + set iname [$inst getName] + if { [dict exists $assignment $iname] } { + set previous [lindex [dict get $assignment $iname] 0] + if { $previous ne $cname } { + lappend conflicts "$iname in $previous and $cname" + } + continue + } + dict set assignment $iname [list $cname [$inst getId]] } - foreach id [lsort -integer -unique $ids] { - set inst [odb::dbInst_getInst $block $id] - lappend rows [list $name $id [$inst getName]] - incr grouped +} +if { [llength $conflicts] > 0 } { + error "dump_clusters: [llength $conflicts] instances assigned to more\ + than one cluster, e.g. [lindex $conflicts 0]" +} + +# Coverage is measured over the instances the scorer will actually +# cluster -- movable, non-macro -- because that is the population the +# reduction ratio is about. Macros appear in the tree too and are +# harmless here: the scorer filters them out. +set movable 0 +set covered 0 +set uncovered {} +foreach inst [$block getInsts] { + if { [[$inst getMaster] isBlock] || [$inst isFixed] } { + continue } + incr movable + if { [dict exists $assignment [$inst getName]] } { + incr covered + } elseif { [llength $uncovered] < 5 } { + lappend uncovered [$inst getName] + } +} + +# Sorted by cluster name, then by odb id within a cluster, so the file is +# a pure function of the database. +set rows {} +dict for {iname entry} $assignment { + lassign $entry cname id + lappend rows [list $cname $id $iname] } set rows [lsort -index 1 -integer [lsort -index 0 -ascii $rows]] @@ -113,21 +146,16 @@ foreach row $rows { } close $fp -# Coverage report. gpl only clusters what it is handed, so an instance -# missing from the partition silently stays a movable of its own; saying -# so out loud is what keeps the reduction ratio honest. -set movable 0 -foreach inst [$block getInsts] { - if { [[$inst getMaster] isBlock] || [$inst isFixed] } { - continue - } - incr movable -} e12_write_leaf [file join $::e12_out clusters.json] [list \ leaf_clusters [llength $leaves] \ - grouped_insts $grouped \ + clustered_insts [dict size $assignment] \ movable_insts $movable \ + movable_covered $covered \ mpl_s $mpl_s] -puts "e12: [llength $leaves] leaf clusters covering\ - $grouped of $movable movable instances (${mpl_s}s)" +puts "e12: [llength $leaves] leaf clusters, [dict size $assignment]\ + instances assigned, $covered of $movable movable instances covered\ + (${mpl_s}s)" +if { [llength $uncovered] > 0 } { + puts "e12: uncovered movables (first few): $uncovered" +} exit 0 From 26015ca6a8af479fe54de5213537cf173917978c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 13:39:21 +0200 Subject: [PATCH 07/11] flow: make nangate45/tinyRocket build under bazel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two independent problems, both hit by any design that uses hierarchical synthesis without a pinned keep-module list. tinyRocket is the first such design anyone has built under bazel, so it is where they surfaced. 1. bazel-orfs patch: orfs_design() sizes SYNTH_NUM_PARTITIONS from SYNTH_KEEP_MODULES with Starlark's split() and no separator, which is a Python-ism -- Starlark requires one. So a design setting both SYNTH_HIERARCHICAL=1 and SYNTH_KEEP_MODULES fails at analysis: Error in split: split() missing 1 required positional argument: sep Splitting on runs of whitespace is what the count actually needs, since a config.mk list arrives spread over backslash-continued lines and split(" ") alone would count the continuations as entries. Carried as //patches/bazel-orfs until it lands upstream. Note swerv_wrapper does not hit this: it reaches hierarchy through SYNTH_USE_SYN + OPENROAD_HIERARCHICAL and never sets SYNTH_HIERARCHICAL. 2. Pin tinyRocket's SYNTH_KEEP_MODULES (46 modules, captured from the discovery step's own kept_modules.json). This is not tidying. Parallel synthesis declares one per-module re-canonicalization action per kept module, so bazel needs those module names at analysis time. When the list is only discovered inside a build action, bazel still emits the partition actions but no per-module checkpoints exist to feed them, and all 32 partitions fail identically with ERROR: per-module checkpoint missing: partition__canonical.rtlil Under make the pin is redundant -- discovery runs and finds the same list -- so the flow's behaviour is unchanged there. The comment records how to recapture the list if the RTL or SYNTH_MINIMUM_KEEP_SIZE moves. Flattening synthesis would have dodged both, and would have been the wrong fix: RTL-MP builds its clustering from dbModule hierarchy, so a flat tinyRocket has no hierarchy for a macro-placement experiment to consume. //flow/designs/nangate45/tinyRocket:RocketTile_synth now builds (65s). Chosen as the fast-flush design for the E12 pipeline: real checked-in fakeram macros in two sizes, hierarchy preserved, nangate45, and small enough to exercise every stage including the production tail. Signed-off-by: Øyvind Harboe --- MODULE.bazel | 12 ++++ flow/designs/nangate45/tinyRocket/config.mk | 68 +++++++++++++++++++ ...-keep-modules-across-continued-lines.patch | 35 ++++++++++ patches/bazel-orfs/BUILD.bazel | 7 ++ 4 files changed, 122 insertions(+) create mode 100644 patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch create mode 100644 patches/bazel-orfs/BUILD.bazel diff --git a/MODULE.bazel b/MODULE.bazel index c24284cd8f..8f3054583d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -176,9 +176,21 @@ BAZEL_ORFS_COMMIT = "ca4e9dd41e0f2e7ab3174535dab4fc7c680b1085" BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git" # To bump version, run: bazelisk run @bazel-orfs//:bump +# patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch: +# orfs_design() sizes SYNTH_NUM_PARTITIONS from SYNTH_KEEP_MODULES using +# Starlark's split() with no separator, which is a Python-ism -- Starlark +# requires one. Any design setting both SYNTH_HIERARCHICAL=1 and +# SYNTH_KEEP_MODULES therefore fails at analysis with "split() missing 1 +# required positional argument: sep". Splitting on runs of whitespace is +# what the count actually needs, because a config.mk list is spread over +# backslash-continued lines. git_override( module_name = "bazel-orfs", commit = BAZEL_ORFS_COMMIT, + patch_strip = 1, + patches = [ + "//patches/bazel-orfs:0001-design-count-keep-modules-across-continued-lines.patch", + ], remote = BAZEL_ORFS_REMOTE, ) diff --git a/flow/designs/nangate45/tinyRocket/config.mk b/flow/designs/nangate45/tinyRocket/config.mk index d86621ba34..fcfda9d391 100644 --- a/flow/designs/nangate45/tinyRocket/config.mk +++ b/flow/designs/nangate45/tinyRocket/config.mk @@ -5,6 +5,74 @@ export PLATFORM = nangate45 export SYNTH_HIERARCHICAL = 1 export SYNTH_MINIMUM_KEEP_SIZE ?= 5000 +# SYNTH_KEEP_MODULES is a captured list of the modules the +# keep-hierarchy discovery step selects at SYNTH_MINIMUM_KEEP_SIZE +# above. +# +# Under make it is redundant: discovery runs and finds the same list. +# Under bazel it is REQUIRED. Parallel synthesis declares one +# per-module re-canonicalization action per kept module, so bazel needs +# the module names at analysis time. When the list is only discovered +# inside a build action, bazel still emits the partition actions but no +# per-module checkpoints exist for them, and every partition fails with +# +# ERROR: per-module checkpoint missing: \ +# partition__canonical.rtlil +# +# Recapture after changing the RTL or SYNTH_MINIMUM_KEEP_SIZE, then sort: +# +# make DESIGN_CONFIG=./designs/nangate45/tinyRocket/config.mk \ +# SYNTH_KEEP_MODULES= clean_synth synth +# jq -r '.modules | sort | join(" ")' \ +# results/nangate45/RocketTile/base/kept_modules.json +export SYNTH_KEEP_MODULES ?= \ + ALU \ + AMOALU \ + BreakpointUnit \ + CSRFile \ + DCache \ + DCacheDataArray \ + DCacheModuleanon2 \ + DCacheModuleanon3 \ + Frontend \ + HellaCacheArbiter \ + IBuf \ + ICache \ + IntSyncCrossingSink \ + IntSyncCrossingSink_1 \ + IntSyncCrossingSink_2 \ + IntXbar_4 \ + MulDiv \ + PMPChecker \ + PTW \ + PlusArgTimeout \ + Queue_38 \ + Queue_39 \ + Queue_40 \ + Queue_41 \ + RVCExpander \ + Repeater_5 \ + Rocket \ + RocketTile \ + ScratchpadSlavePort \ + ShiftQueue \ + SynchronizerShiftReg_w1_d3 \ + TLB \ + TLB_1 \ + TLBuffer_10 \ + TLBuffer_11 \ + TLFragmenter_5 \ + TLMonitor_35 \ + TLMonitor_36 \ + TLXbar_8 \ + TLXbar_9 \ + data_arrays_0 \ + data_arrays_0_0 \ + data_arrays_0_0_ext \ + data_arrays_0_ext \ + tag_array \ + tag_array_ext + export VERILOG_FILES = $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/AsyncResetReg.v \ $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider2.v \ $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider3.v \ diff --git a/patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch b/patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch new file mode 100644 index 0000000000..04a0f2087f --- /dev/null +++ b/patches/bazel-orfs/0001-design-count-keep-modules-across-continued-lines.patch @@ -0,0 +1,35 @@ +diff --git a/private/orfs_design.bzl b/private/orfs_design.bzl +index e85b80b..0ac66f0 100644 +--- a/private/orfs_design.bzl ++++ b/private/orfs_design.bzl +@@ -51,6 +51,19 @@ def _convert_sources(sources, pkg): + result[var] = converted + return result + ++def _split_whitespace(value): ++ """Split on any run of whitespace, dropping empties. ++ ++ Starlark's split() requires an explicit separator and has no ++ whitespace-splitting form, so a config.mk list that is spread over ++ several backslash-continued lines cannot be counted with a single ++ split(" "): the continuations leave newlines and runs of spaces that ++ would be counted as empty entries. ++ """ ++ for whitespace in ["\n", "\t", "\r"]: ++ value = value.replace(whitespace, " ") ++ return [word for word in value.split(" ") if word] ++ + def orfs_design(name = None, config = "config.mk", platform = None, design = None, designs = None, mock_openroad = None, mock_yosys = None, user_arguments = [], user_sources = [], local_arguments = [], blender = False, extra = None): # buildifier: disable=unused-variable + """Create orfs_flow() targets for a design based on its parsed config.mk. + +@@ -233,7 +246,9 @@ def orfs_design(name = None, config = "config.mk", platform = None, design = Non + if "SYNTH_NUM_PARTITIONS" not in arguments: + keep_modules = arguments.get("SYNTH_KEEP_MODULES", "") + if keep_modules: +- arguments["SYNTH_NUM_PARTITIONS"] = str(len(keep_modules.split())) ++ arguments["SYNTH_NUM_PARTITIONS"] = str( ++ len(_split_whitespace(keep_modules)), ++ ) + else: + arguments["SYNTH_NUM_PARTITIONS"] = "32" + diff --git a/patches/bazel-orfs/BUILD.bazel b/patches/bazel-orfs/BUILD.bazel new file mode 100644 index 0000000000..111464e9c9 --- /dev/null +++ b/patches/bazel-orfs/BUILD.bazel @@ -0,0 +1,7 @@ +"""bazel-orfs fixes carried as git_override patches. + +Drop each file when the fix lands upstream and BAZEL_ORFS_COMMIT is +bumped past it. +""" + +exports_files(glob(["*.patch"])) From 073aa90054a48187a1a82640a3faf8fd9c619922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 14:37:36 +0200 Subject: [PATCH 08/11] flow: E12 truth stage, design ladder, and a gate that can say "inconclusive" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the one pipeline stage that had never executed anywhere, and then uses it -- which immediately found three real bugs and one flaw in the gate itself. evaluate.tcl: the truth measurement. Carries a candidate through the production tail in flow.tcl's own order (tapcell, pdn, global_place_skip_io, io_placement, global_place, resize, detail_place, cts, global_route), entered where a candidate archive begins. It sources ORFS's own stage scripts rather than reimplementing them, which is what makes this the production tail and not an approximation, and stays report-only via WRITE_ODB_AND_SDC_EACH_STAGE=0. Leaves use the archive's `grt` field names so a re-measured truth is a drop-in for the archived one rather than a second schema. grade_e12.py learns --truth-dir for those leaves. With a re-measured truth there is no archived score to reproduce, so gate 0 is vacuous rather than passing -- decided from the truth source itself, because the first attempt also swallowed the "run produced nothing" case. The BUILD is now a ladder rather than one design: E12_DESIGNS x E12_STAGES emits four executables each for nangate45/tinyRocket (mechanics: 2 macros, ~6 min tail) and asap7/swerv_wrapper (the real population: 28 macros, hours per candidate). An experiment is flushed on the cheap design and repeated on the expensive one without edits. Bugs the flush found, all of which would have cost hours each to find on swerv: * score_clustered inherited unplaced IO. The candidate .odb is ORFS's 2_2_floorplan_macro output, so gpl refused it with GPL-0326. The scorer now places pins itself, which also keeps both rungs measuring the same configuration. * HPWL came back NEGATIVE (-368716188153). Unplaced terminals make getTermBBox return an inverted rectangle with negative dx/dy. It was only obvious because it went below zero; on a partially placed design the same bug yields a plausible number. Now guarded. * clusters.txt did not round-trip. odb names carry escaped Verilog identifiers (buffer/Queue/_T_address\[0\]\[0\]$_DFFE_PP_$), and a whitespace-joined line read back with Tcl LIST parsing has its escapes interpreted, so \[ arrived as [ and 3751 of 29069 lookups missed. Tab-delimited fields split with `split` are raw strings and survive. Note the partition check added earlier is what caught this: without it gpl would have accepted a cluster model missing 13% of the design and produced a perfectly plausible score. And the gate flaw, which is the most valuable find: on the four-candidate smoke population it reported Gate 1 (E12): PASS -- rho = +0.80 [-1.00, +1.00] A bootstrap interval spanning the entire range says nothing, yet any rho at all would "land inside" the flat scorer's interval by accident. That is exactly the false confidence pre-registration is meant to prevent. Gate 1 now requires three things -- rho inside the interval, the population complete, and the interval clear of zero, which is the campaign's own E1 criterion -- and reports "inconclusive" when the measurement is uninformative, because that is neither a pass nor a failure. The archive itself passes the new test (0.72, lo = 0.48), and the pass fixture was retargeted to that operating point rather than an artificial extreme. tinyRocket verdict committed as evidence of the flush, not as a result: n=4 with no measured noise band, so its rho is uninterpretable by construction. Signed-off-by: Øyvind Harboe --- flow/test/macro_e12/BUILD | 115 ++++----- flow/test/macro_e12/dump_clusters.tcl | 14 +- flow/test/macro_e12/e12_lib.tcl | 16 +- .../macro_e12/e12_verdict_tinyRocket.json | 218 ++++++++++++++++++ flow/test/macro_e12/evaluate.tcl | 122 ++++++++++ flow/test/macro_e12/grade_e12.py | 107 ++++++++- flow/test/macro_e12/grade_e12_test.py | 119 +++++++++- flow/test/macro_e12/score_clustered.tcl | 28 ++- 8 files changed, 660 insertions(+), 79 deletions(-) create mode 100644 flow/test/macro_e12/e12_verdict_tinyRocket.json create mode 100644 flow/test/macro_e12/evaluate.tcl diff --git a/flow/test/macro_e12/BUILD b/flow/test/macro_e12/BUILD index 0a0530d1a3..2fc61af460 100644 --- a/flow/test/macro_e12/BUILD +++ b/flow/test/macro_e12/BUILD @@ -13,72 +13,77 @@ load("@bazel-orfs//:openroad.bzl", "orfs_run_executable") load("@orfs_designs//:designs.bzl", "DESIGNS") load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") -SWERV = DESIGNS["asap7/swerv_wrapper"] +# The design ladder. Every design here gets the same four executables, so +# an experiment can be flushed on a cheap design and then repeated on an +# expensive one without editing anything. +# +# tinyRocket mechanics. Two macros and a ~6 minute production tail, so +# the whole chain -- generation, scoring, truth, verdict -- +# runs in minutes. Its candidate population is too small to +# rank, so a rho from it means nothing; it exists to prove +# the pipeline executes. +# swerv the real population: 28 macros, and the design the +# archived reference numbers were measured on. Hours per +# candidate for the truth stage. +E12_DESIGNS = { + "tinyRocket": "nangate45/tinyRocket", + "swerv": "asap7/swerv_wrapper", +} -SWERV_SYNTH = "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth_for_e12" +# Per-design synth target, exposed to this package by a narrow alias in +# the design's own BUILD (orfs_design leaves flow targets +# package-private and ORFS's design() has no visibility passthrough). +E12_SYNTH = { + "tinyRocket": "//flow/designs/nangate45/tinyRocket:RocketTile_synth_for_e12", + "swerv": "//flow/designs/asap7/swerv_wrapper:swerv_wrapper_synth_for_e12", +} # The helper Tcl travels as `data`, which orfs_run_executable stages # alongside `script`, so each driver sources it as a sibling. -# e12_lib.tcl is shared by all three drivers; extract_lib.tcl is the -# vendored instrument the archived reference numbers were measured with. +# e12_lib.tcl is shared by all drivers; extract_lib.tcl is the vendored +# instrument the archived reference numbers were measured with. E12_DATA = [ "e12_lib.tcl", "extract_lib.tcl", ] -# The design's own source files (SDC, LEFs, LIBs, io.tcl) reach the flow -# through `data` too: the drivers run real ORFS stage scripts, which read -# them by the variable names the config.mk sets. -E12_DESIGN_DATA = [ - label - for labels in SWERV["sources"].values() - for label in labels -] +# Each stage of the pipeline, as script -> target suffix. +E12_STAGES = { + "macro_e12.tcl": "candidates", + "dump_clusters.tcl": "dump_clusters", + "score_clustered.tcl": "score_clustered", + "evaluate.tcl": "evaluate", +} -# Step 0: regenerate the 24-candidate population and re-measure it with -# the flat scorer. Writes cand_s.{json,place.tcl,odb} plus -# base_floorplan.odb into $E12_OUT_DIR. This is also the rig check: the -# regenerated flat scores must reproduce the archive. -# -# All four flow targets are `bazelisk run` executables taking KEY=VALUE -# overrides, rather than build-time actions with declared outputs. That -# matches what they are -- a manual campaign whose evidence directory is -# an input to analysis, not a build artifact -- and it is what lets the +# Four `bazelisk run` executables per design, taking KEY=VALUE overrides, +# rather than build-time actions with declared outputs. That matches what +# they are -- a manual campaign whose evidence directory is an input to +# analysis, not a build artifact -- and it is what lets the # reduction-axis sweeps vary E12_* without a target per value. -orfs_run_executable( - name = "swerv_candidates", - src = SWERV_SYNTH, - arguments = SWERV["arguments"], - cmd = "run", - data = E12_DATA + E12_DESIGN_DATA, - script = "macro_e12.tcl", - tags = ["manual"], -) - -# Step 1: dump RTL-MP's cluster partition from the base floorplan, once. -orfs_run_executable( - name = "swerv_dump_clusters", - src = SWERV_SYNTH, - arguments = SWERV["arguments"], - cmd = "run", - data = E12_DATA + E12_DESIGN_DATA, - script = "dump_clusters.tcl", - tags = ["manual"], -) - -# Step 2: score one candidate with the clustered rung. E12_TAG selects -# the candidate; one candidate per process is mandatory, so the sweep -# over candidates is a loop over invocations of this target rather than -# an inner loop. -orfs_run_executable( - name = "swerv_score_clustered", - src = SWERV_SYNTH, - arguments = SWERV["arguments"], - cmd = "run", - data = E12_DATA + E12_DESIGN_DATA, - script = "score_clustered.tcl", - tags = ["manual"], -) +# +# candidates regenerate the population and score it flat. Also the +# rig check when grading against the archive. +# dump_clusters RTL-MP's cluster partition, once, from the base +# floorplan. +# score_clustered the clustered rung, one candidate per process. +# evaluate the production tail to grt: the truth. +[ + orfs_run_executable( + name = "%s_%s" % (short, suffix), + src = E12_SYNTH[short], + arguments = DESIGNS[full]["arguments"], + cmd = "run", + data = E12_DATA + [ + label + for labels in DESIGNS[full]["sources"].values() + for label in labels + ], + script = script, + tags = ["manual"], + ) + for short, full in E12_DESIGNS.items() + for script, suffix in E12_STAGES.items() +] py_library( name = "e12_stats", diff --git a/flow/test/macro_e12/dump_clusters.tcl b/flow/test/macro_e12/dump_clusters.tcl index 3ca84606c6..4eea7253b9 100644 --- a/flow/test/macro_e12/dump_clusters.tcl +++ b/flow/test/macro_e12/dump_clusters.tcl @@ -138,11 +138,21 @@ dict for {iname entry} $assignment { } set rows [lsort -index 1 -integer [lsort -index 0 -ascii $rows]] +# Tab-delimited, and written field by field rather than with join. +# +# odb instance names contain escaped Verilog identifiers such as +# buffer/Queue/_T_address\[0\]\[0\]$_DFFE_PP_$ +# and a whitespace-joined line read back with Tcl LIST parsing has its +# backslash escapes interpreted, so \[ arrives as [ and the name no +# longer matches the database. Tab-delimited fields split with `split` +# are raw strings and survive the round trip; a tab cannot occur in an +# odb name. set fp [open [file join $::e12_out clusters.txt] w] -puts $fp "# " +puts $fp "# cluster_name\tinst_id\tinst_name (tab-delimited)" puts $fp "# leaf clusters from rtl_macro_placer -keep_clustering_data" foreach row $rows { - puts $fp [join $row " "] + lassign $row cname id iname + puts $fp "$cname\t$id\t$iname" } close $fp diff --git a/flow/test/macro_e12/e12_lib.tcl b/flow/test/macro_e12/e12_lib.tcl index 2494d3ab81..3b01ed56f4 100644 --- a/flow/test/macro_e12/e12_lib.tcl +++ b/flow/test/macro_e12/e12_lib.tcl @@ -123,8 +123,22 @@ proc e12_signal_nets { block { large_net_threshold 0 } } { proc e12_hpwl_dbu { nets } { set hpwl 0 foreach net $nets { + # A net whose terminals have no physical location yields an inverted + # (empty) rectangle, whose dx/dy are negative. Summing those blindly + # produced a NEGATIVE total on the first real run -- a number that is + # obviously wrong, but only obviously so because it went below zero; + # a partially placed design would have quietly produced a plausible + # one. Require a real two-terminal net and a non-inverted box. + if { [$net getTermCount] < 2 } { + continue + } set bbox [$net getTermBBox] - set hpwl [expr { $hpwl + [$bbox dx] + [$bbox dy] }] + set dx [$bbox dx] + set dy [$bbox dy] + if { $dx < 0 || $dy < 0 } { + continue + } + set hpwl [expr { $hpwl + $dx + $dy }] } return $hpwl } diff --git a/flow/test/macro_e12/e12_verdict_tinyRocket.json b/flow/test/macro_e12/e12_verdict_tinyRocket.json new file mode 100644 index 0000000000..8eade1c80d --- /dev/null +++ b/flow/test/macro_e12/e12_verdict_tinyRocket.json @@ -0,0 +1,218 @@ +{ + "cost": { + "clustered": { + "clustered_insts": 28887.0, + "clusters_declared": 13.0, + "cone_nets": 499.0, + "gpl_s": 2.7975000000000003, + "halo_flat_insts": 180.0, + "signal_nets": 35002.0, + "vmhwm_kb": 212762.0 + }, + "flat": { + "gpl_s": 8.19725, + "vmhwm_kb": 357502.0 + } + }, + "design": "re-measured", + "diverged": [], + "gate_0_rig_check": { + "candidates_compared": 0, + "mismatches": [], + "not_applicable": "truth source carries no archived scores", + "pass": true + }, + "gate_1_e12": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "ci_clear_of_zero": false, + "expected_n": 4, + "flat_ci": [ + 0.48, + 0.84 + ], + "inside_flat_ci": true, + "kpi": "macro_paths_mean", + "n": 4, + "pass": false, + "population_complete": true, + "rho": 0.7999999999999998, + "verdict": "inconclusive" + }, + "population": null, + "rho": { + "clustered_cone_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.3999999999999999 + }, + "general_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.19999999999999996 + }, + "macro_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": 0.7999999999999998 + }, + "stdcell_um2": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.7999999999999998 + } + }, + "n": 4 + }, + "clustered_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.3999999999999999 + }, + "general_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.19999999999999996 + }, + "macro_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": 0.7999999999999998 + }, + "stdcell_um2": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.7999999999999998 + } + }, + "n": 4 + }, + "regen_flat_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.19999999999999996 + }, + "general_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.3999999999999999 + }, + "macro_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.5999999999999999 + }, + "stdcell_um2": { + "ci": [ + 0.9999999999999998, + 1.0000000000000002 + ], + "rho": 0.9999999999999998 + } + }, + "n": 4 + }, + "regen_flat_macro_mean": { + "kpi": { + "achieved": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.19999999999999996 + }, + "general_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.3999999999999999 + }, + "macro_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.5999999999999999 + }, + "stdcell_um2": { + "ci": [ + 0.9999999999999998, + 1.0000000000000002 + ], + "rho": 0.9999999999999998 + } + }, + "n": 4 + }, + "regen_flat_wq25": { + "kpi": { + "achieved": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": 0.7999999999999998 + }, + "general_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": 0.3999999999999999 + }, + "macro_paths_mean": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": -0.3999999999999999 + }, + "stdcell_um2": { + "ci": [ + -1.0000000000000002, + 1.0000000000000002 + ], + "rho": 0.3999999999999999 + } + }, + "n": 4 + } + }, + "tags": [ + "cand_s0", + "cand_s1", + "cand_s2", + "cand_s3" + ] +} diff --git a/flow/test/macro_e12/evaluate.tcl b/flow/test/macro_e12/evaluate.tcl new file mode 100644 index 0000000000..dd2329d584 --- /dev/null +++ b/flow/test/macro_e12/evaluate.tcl @@ -0,0 +1,122 @@ +# E12 truth measurement: carry one candidate through the entire +# production tail and report what the flow actually delivered. +# +# This is the ground truth every score is graded against, and the reason +# it must be the whole tail rather than a shortcut: a scorer that only +# has to beat a placement-time estimate can be right for the wrong +# reasons. repair_design, repair_timing, CTS and global routing all get +# to respond to a macro placement, so the difference between a score and +# this number is the price of predicting instead of running. +# +# The stage sequence mirrors flow.tcl, entered at the point a candidate +# archive begins: the candidate .odb is ORFS's 2_2_floorplan_macro +# output, so the tail is tapcell through global_route. Reusing ORFS's own +# stage scripts rather than reimplementing them is what makes this the +# production tail and not an approximation of one. +# +# Report-only, like the scorers: WRITE_ODB_AND_SDC_EACH_STAGE=0 makes the +# stage scripts' own write helpers no-ops and nothing is written back. + +set e12_dir [file dirname [file normalize [info script]]] +source [file join $e12_dir e12_lib.tcl] +source [file join $e12_dir extract_lib.tcl] + +set ::e12_out [e12_env E12_OUT_DIR [e12_env RUN_OUTPUT_DIR ""]] +if { $::e12_out eq "" } { + error "evaluate: set E12_OUT_DIR or declare out_dir" +} +set tag [e12_env E12_TAG ""] +if { $tag eq "" } { + error "evaluate: set E12_TAG to the candidate tag (eg cand_s0)" +} +set ::e12_work [e12_env E12_WORK [file join $::env(WORK_HOME) e12_work]] +set cand_odb [e12_env E12_CAND_ODB [file join $::e12_out $tag.odb]] +set base_sdc [e12_env E12_BASE_SDC [file join $::e12_out base_floorplan.sdc]] +foreach f [list $cand_odb $base_sdc] { + if { ![file exists $f] } { + error "evaluate: missing $f" + } +} + +set ::env(KEEP_VARS) 1 +set ::env(SKIP_REPORT_METRICS) 1 +set ::env(WRITE_ODB_AND_SDC_EACH_STAGE) 0 + +e12_redirect eval_$tag +source $::env(SCRIPTS_DIR)/load.tcl + +set stem 2_2_floorplan_macro +file copy -force $cand_odb [file join $::env(RESULTS_DIR) $stem.odb] +file copy -force $base_sdc [file join $::env(RESULTS_DIR) $stem.sdc] +load_design $stem.odb $stem.sdc + +# The production tail, in flow.tcl's order. +set tail { + tapcell.tcl + pdn.tcl + global_place_skip_io.tcl + io_placement.tcl + global_place.tcl + resize.tcl + detail_place.tcl + cts.tcl + global_route.tcl +} + +set t0 [clock clicks -milliseconds] +set stage_s [dict create] +foreach script $tail { + set s [e12_step $script] + dict set stage_s [file rootname $script] $s +} +set tail_s [expr { ([clock clicks -milliseconds] - $t0) / 1000.0 }] + +# global_route.tcl leaves propagated clocks and global-routing parasitics +# in place, which is exactly the state the KPI instrument expects, so the +# measurement is of the routed design rather than a re-estimate. +set sample [extract_sample_paths] +set area [extract_design_area] + +set general_sum 0.0 +set general_n 0 +set macro_sum 0.0 +set macro_n 0 +foreach pt [dict get $sample paths] { + set period [lindex $pt 2] + if { [lindex $pt 3] } { + set macro_sum [expr { $macro_sum + $period }] + incr macro_n + } else { + set general_sum [expr { $general_sum + $period }] + incr general_n + } +} + +# Field names match the committed archive's `grt` block so a re-measured +# truth is a drop-in replacement for it rather than a second schema. +e12_write_leaf [file join $::e12_out $tag.grt.json] [list \ + tag $tag \ + time_unit "[sta::unit_scale_abbreviation time][sta::unit_suffix time]" \ + clock_period [dict get $sample clock_period] \ + wns [dict get $sample wns] \ + achieved [expr { [dict get $sample clock_period] - [dict get $sample wns] }] \ + general_paths_mean [expr { $general_n ? $general_sum / $general_n : 0.0 }] \ + macro_paths_mean [expr { $macro_n ? $macro_sum / $macro_n : 0.0 }] \ + general_paths $general_n \ + macro_paths $macro_n \ + stdcell_um2 [dict get $area stdcell_um2] \ + macro_um2 [dict get $area macro_um2] \ + num_stdcells [dict get $area num_stdcells] \ + num_macros [dict get $area num_macros] \ + tail_s $tail_s \ + vmhwm_kb [e12_vmhwm_kb]] + +set achieved [expr { [dict get $sample clock_period] - [dict get $sample wns] }] +set macro_mean [expr { $macro_n ? $macro_sum / $macro_n : 0.0 }] +puts "e12: $tag truth achieved [format %.1f $achieved],\ + macro_paths_mean [format %.1f $macro_mean], tail ${tail_s}s" +foreach script $tail { + set stem [file rootname $script] + puts "e12: [format %-24s $stem] [dict get $stage_s $stem]s" +} +exit 0 diff --git a/flow/test/macro_e12/grade_e12.py b/flow/test/macro_e12/grade_e12.py index 69d2b95497..b412334937 100644 --- a/flow/test/macro_e12/grade_e12.py +++ b/flow/test/macro_e12/grade_e12.py @@ -70,6 +70,8 @@ CLUSTERED_SUFFIX = ".clustered.json" +TRUTH_SUFFIX = ".grt.json" + # Score variants. Each is (label, source, field), where source picks the # per-candidate record to read the field out of. Every variant is # oriented so that *lower is better*, which is why they are all expected @@ -128,6 +130,19 @@ def load_leaves(evidence_dir, suffix, exclude=()): return leaves +def truth_from_leaves(leaves): + """Shape re-measured truth like the committed archive. + + evaluate.tcl writes the same field names the archive's `grt` block + uses, so a truth measured here is a drop-in replacement rather than a + second schema the gate has to understand. + """ + return { + "design": "re-measured", + "candidates": {tag: {"grt": rec} for tag, rec in leaves.items()}, + } + + def collect(truth, flat, clustered): """Per-tag records, one dict per source, over the common tags only.""" archive = truth["candidates"] @@ -137,7 +152,9 @@ def collect(truth, flat, clustered): tags = sorted(set(archive) & set(flat)) return tags, { "grt": {t: archive[t]["grt"] for t in tags}, - "archive_proxy": {t: archive[t]["proxy"] for t in tags}, + "archive_proxy": { + t: archive[t]["proxy"] for t in tags if "proxy" in archive[t] + }, "archive_objective": { t: {"objective_fixed_norm": archive[t]["objective_fixed_norm"]} for t in tags @@ -184,7 +201,7 @@ def cost_table(tags, sources): return costs -def gate_zero(tags, sources, tolerance): +def gate_zero(tags, sources, tolerance, has_archived_scores=True): """Did the regenerated flat scores reproduce the archived ones? Reproduction is checked on ranking (rho against the same truth) and, @@ -196,6 +213,18 @@ def gate_zero(tags, sources, tolerance): flat = sources.get("flat", {}) archive = sources.get("archive_proxy", {}) usable = [t for t in tags if t in flat and t in archive] + if not has_archived_scores: + # A re-measured truth carries no archived score to reproduce, so + # the rig check has nothing to compare against and is vacuous + # rather than failing. This is decided from the truth source + # itself, not from an empty intersection -- a run that produced no + # candidates must still fail below. + return { + "candidates_compared": 0, + "not_applicable": "truth source carries no archived scores", + "mismatches": [], + "pass": True, + } mismatches = [] for tag in usable: for field in REPRODUCED_FIELDS: @@ -229,27 +258,54 @@ def gate_zero(tags, sources, tolerance): def gate_one(table, expected_n): - """The E12 criterion itself.""" + """The E12 criterion itself. + + Three conditions, not one. A rho landing inside the flat scorer's + interval is necessary but says nothing on its own: on a four-candidate + population the bootstrap interval spans [-1, +1], and any rho at all + would "land inside" by accident. So the measurement must also be + informative in its own right -- the campaign's E1 criterion is a rho + "with CI clear of zero" -- and the population must be the one that was + pre-registered. + + A measurement that is not informative is reported as inconclusive + rather than as a pass or a failure, because it is neither: nothing was + learned about the scorer. + """ entry = table.get("clustered_hpwl") if entry is None: return { "pass": False, + "verdict": "fail", "reason": "no clustered scores present", } stats = entry["kpi"][GATE_KPI] rho = stats["rho"] + low, high = stats["ci"] inside = FLAT_CI[0] <= rho <= FLAT_CI[1] complete = entry["n"] == expected_n + # "Clear of zero" in the direction the score is supposed to predict: + # lower score should mean lower (better) period, so a useful result + # has an interval entirely above zero. + informative = low > 0.0 + if not informative: + verdict = "inconclusive" + elif inside and complete: + verdict = "pass" + else: + verdict = "fail" return { "kpi": GATE_KPI, "rho": rho, - "ci": stats["ci"], + "ci": [low, high], "flat_ci": list(FLAT_CI), "n": entry["n"], "expected_n": expected_n, "inside_flat_ci": inside, "population_complete": complete, - "pass": bool(inside and complete), + "ci_clear_of_zero": informative, + "verdict": verdict, + "pass": verdict == "pass", } @@ -310,7 +366,7 @@ def format_report(verdict): "Gate 1 (E12): {} -- rho(clustered_hpwl vs {}) = " "{:+.2f} [{:+.2f}, {:+.2f}], flat interval " "[{:+.2f}, {:+.2f}], n = {}/{}".format( - "PASS" if gate1["pass"] else "FAIL", + gate1["verdict"].upper(), gate1["kpi"], gate1["rho"], gate1["ci"][0], @@ -321,6 +377,11 @@ def format_report(verdict): gate1["expected_n"], ) ) + if gate1["verdict"] == "inconclusive": + lines.append( + " the interval does not clear zero, so this measures " + "nothing about the scorer" + ) return "\n".join(lines) @@ -334,7 +395,14 @@ def build_verdict(truth, flat, clustered, expected_n, n_boot, tolerance): "rho": table, "cost": cost_table(tags, sources), "diverged": diverged_tags(sources), - "gate_0_rig_check": gate_zero(tags, sources, tolerance), + "gate_0_rig_check": gate_zero( + tags, + sources, + tolerance, + has_archived_scores=any( + "proxy" in record for record in truth["candidates"].values() + ), + ), "gate_1_e12": gate_one(table, expected_n), } @@ -343,9 +411,15 @@ def main(argv=None): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( "--truth", - required=True, help="score_vs_flow_swerv.json, the committed archive", ) + parser.add_argument( + "--truth-dir", + help=( + "directory of .grt.json leaves from evaluate.tcl, used " + "instead of --truth when the truth is re-measured here" + ), + ) parser.add_argument( "--evidence-dir", required=True, @@ -372,9 +446,22 @@ def main(argv=None): ) args = parser.parse_args(argv) + if not args.truth and not args.truth_dir: + parser.error("one of --truth or --truth-dir is required") + if args.truth_dir: + truth = truth_from_leaves(load_leaves(args.truth_dir, TRUTH_SUFFIX)) + if not truth["candidates"]: + parser.error("no %s leaves in %s" % (TRUTH_SUFFIX, args.truth_dir)) + else: + truth = load_json(args.truth) + verdict = build_verdict( - load_json(args.truth), - load_leaves(args.evidence_dir, ".json", exclude=(CLUSTERED_SUFFIX,)), + truth, + load_leaves( + args.evidence_dir, + ".json", + exclude=(CLUSTERED_SUFFIX, TRUTH_SUFFIX), + ), load_leaves(args.evidence_dir, CLUSTERED_SUFFIX), args.expected_n, args.n_boot, diff --git a/flow/test/macro_e12/grade_e12_test.py b/flow/test/macro_e12/grade_e12_test.py index 3da0e4cd15..7b4296d0d7 100644 --- a/flow/test/macro_e12/grade_e12_test.py +++ b/flow/test/macro_e12/grade_e12_test.py @@ -147,20 +147,78 @@ def test_perfectly_ranking_clustered_score_is_above_the_interval(self): self.assertFalse(gate1["pass"]) def test_score_inside_the_flat_interval_passes(self): - # Swap enough neighbouring pairs to land rho in [0.48, 0.84]. - order = list(range(24)) - for i in range(0, 24, 2): - order[i], order[i + 1] = order[i + 1], order[i] - order[0], order[17] = order[17], order[0] - order[3], order[20] = order[20], order[3] - verdict = self._verdict(order) + """A rho inside the interval AND informative is a pass. + + This ordering was chosen to land where the real reference lands -- + rho 0.74, CI [0.49, 0.84] against the archive's 0.72 [0.48, 0.84] + -- so the fixture exercises the gate at its actual operating + point rather than at an artificial extreme. + """ + order = [ + 5, + 0, + 2, + 9, + 3, + 11, + 4, + 14, + 6, + 10, + 1, + 7, + 20, + 19, + 8, + 22, + 13, + 12, + 23, + 17, + 18, + 21, + 15, + 16, + ] + values = [100.0 + i for i in range(24)] + truth = make_truth(24, values) + flat, clustered = make_leaves(24, values, order) + verdict = grade_e12.build_verdict(truth, flat, clustered, 24, 400, 1e-6) gate1 = verdict["gate_1_e12"] self.assertTrue( grade_e12.FLAT_CI[0] <= gate1["rho"] <= grade_e12.FLAT_CI[1], "fixture rho %.3f outside the interval it is meant to hit" % gate1["rho"], ) + self.assertTrue(gate1["ci_clear_of_zero"]) + self.assertEqual(gate1["verdict"], "pass") self.assertTrue(gate1["pass"]) + def test_uninformative_interval_is_inconclusive_not_pass(self): + """The failure mode the four-candidate smoke run exposed. + + With a tiny population the bootstrap interval spans [-1, +1], so + a rho can land inside the flat scorer's interval purely by + accident. That is not a pass and it is not a failure -- nothing + was measured -- so the gate must say so. + """ + values = [100.0 + i for i in range(4)] + truth = make_truth(4, values) + flat, clustered = make_leaves(4, values, [0, 1, 3, 2]) + verdict = grade_e12.build_verdict(truth, flat, clustered, 4, 200, 1e-6) + gate1 = verdict["gate_1_e12"] + self.assertFalse(gate1["ci_clear_of_zero"]) + self.assertEqual(gate1["verdict"], "inconclusive") + self.assertFalse(gate1["pass"]) + + def test_informative_interval_can_still_pass(self): + """A wide population with a real signal keeps passing.""" + verdict = self._verdict(list(range(24))) + gate1 = verdict["gate_1_e12"] + self.assertTrue(gate1["ci_clear_of_zero"]) + # rho = 1.0 is above the flat interval, so this is a fail rather + # than inconclusive -- the point is that it is decided, not vague. + self.assertEqual(gate1["verdict"], "fail") + def test_inverted_score_fails(self): verdict = self._verdict(list(reversed(range(24)))) self.assertLess(verdict["gate_1_e12"]["rho"], 0) @@ -185,6 +243,53 @@ def test_divergence_is_surfaced(self): self.assertEqual(verdict["diverged"], ["cand_s3"]) +class TestRemeasuredTruth(unittest.TestCase): + """Truth measured here, rather than read from the archive.""" + + def test_leaves_shape_like_the_archive(self): + leaves = { + "cand_s%d" + % i: { + "macro_paths_mean": 100.0 + i, + "achieved": 1000.0 + i, + "general_paths_mean": 900.0 + i, + "stdcell_um2": 10000.0 + i, + } + for i in range(4) + } + truth = grade_e12.truth_from_leaves(leaves) + self.assertEqual(sorted(truth["candidates"]), sorted(leaves)) + self.assertEqual( + truth["candidates"]["cand_s0"]["grt"]["macro_paths_mean"], 100.0 + ) + + def test_rig_check_is_vacuous_not_failing(self): + """No archived score to reproduce, so gate 0 must not block.""" + leaves = { + "cand_s%d" + % i: { + "macro_paths_mean": 100.0 + i, + "achieved": 1000.0 + i, + "general_paths_mean": 900.0 + i, + "stdcell_um2": 10000.0 + i, + } + for i in range(4) + } + flat, clustered = make_leaves(4, [100.0 + i for i in range(4)], list(range(4))) + verdict = grade_e12.build_verdict( + grade_e12.truth_from_leaves(leaves), flat, clustered, 4, 100, 1e-6 + ) + gate0 = verdict["gate_0_rig_check"] + self.assertTrue(gate0["pass"]) + self.assertIn("not_applicable", gate0) + + def test_empty_run_still_fails_the_rig_check(self): + """The vacuous path must not swallow a run that produced nothing.""" + truth = make_truth(4, [1.0, 2.0, 3.0, 4.0]) + verdict = grade_e12.build_verdict(truth, {}, {}, 4, 100, 1e-6) + self.assertFalse(verdict["gate_0_rig_check"]["pass"]) + + class TestLeafLoading(unittest.TestCase): def test_clustered_leaves_do_not_masquerade_as_flat(self): with tempfile.TemporaryDirectory() as tmp: diff --git a/flow/test/macro_e12/score_clustered.tcl b/flow/test/macro_e12/score_clustered.tcl index 183a1910b5..e88c68183a 100644 --- a/flow/test/macro_e12/score_clustered.tcl +++ b/flow/test/macro_e12/score_clustered.tcl @@ -88,6 +88,21 @@ load_design $stem.odb $stem.sdc set block [ord::get_db_block] +# Place the IO pins. +# +# The candidate .odb is the post-macro-placement database, which is +# exactly what ORFS's 2_2_floorplan_macro stage produces and therefore +# has unplaced top-level ports; gpl refuses to run on it (GPL-0326, "{} +# toplevel port is not placed"). The flat rung places pins as part of +# scoring for the same reason, so doing it here keeps the two rungs +# measuring the same configuration rather than making the candidate +# archive carry scoring state. +if { [e12_env IO_CONSTRAINTS ""] ne "" } { + uplevel #0 [list source $::env(IO_CONSTRAINTS)] +} +place_pins -hor_layers $::env(IO_PLACER_H) \ + -ver_layers $::env(IO_PLACER_V) + # -------------------------------------------------------------------- # Halo-flat set and the macro cone, from one traversal. @@ -118,10 +133,15 @@ while { [gets $fp line] >= 0 } { if { [string index $line 0] eq "#" || [string trim $line] eq "" } { continue } - set cname [lindex $line 0] - # The instance name is the remainder of the line, not just field 3, so - # a name containing a space cannot silently truncate. - set iname [join [lrange $line 2 end] " "] + # split on the tab delimiter rather than treating the line as a Tcl + # list: list parsing interprets backslash escapes, and odb names carry + # escaped Verilog identifiers (\[0\] and the like). Reading such a name + # as a list turns \[ into [ and the lookup silently misses -- 3751 of + # 29069 names on tinyRocket, which is why the partition check below + # exists. + set fields [split $line "\t"] + set cname [lindex $fields 0] + set iname [lindex $fields 2] # Match by name, not by odb id. clusters.txt is written from the base # floorplan database and consumed against a candidate's, and while From 78f13af3985add98f871f2136d02d757e73dc5dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 21:40:38 +0200 Subject: [PATCH 09/11] flow: E12 measured -- the clustered rung tracks flat 4.3x cheaper, and the archive cannot anchor it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two results from running the apparatus on the full asap7/swerv_wrapper population (k=24, all converged) plus the tinyRocket flush. The necessary condition holds. rho(clustered HPWL, flat HPWL) = +0.66 [+0.36, +0.86] over 24 candidates, at 14.7 s against the flat rung's 63.0 s and 0.87 GB against 2.40 GB. The interval is clear of zero, so the clustered abstraction really does carry a substantial part of the flat rung's wirelength signal at roughly a quarter of the cost. It is not a faithful reproduction -- a third of the rank information is gone -- and it tracks flat HPWL (+0.66) far better than the flat STA aggregate (+0.23, interval includes zero), which is what a wirelength score should do. That measurement needs no ground truth, which is the point of adding it: the flat rung is the thing already shown to predict the flow, so a clustered rung that failed to track it could be rejected without spending days on a truth run. It did not fail. The archive cannot serve as truth here, and this is now measured rather than argued: archive's own wq25 vs archived macro_paths_mean: +0.72 [+0.48, +0.84] regenerated wq25 vs archived macro_paths_mean: -0.42 [-0.75, +0.00] The archive is internally consistent -- its own column reproduces the published figure exactly -- but the regenerated scores anti-correlate with it, and the regenerated/archived ratio scatters 0.574 to 2.093 (stdev 0.357). So it is not a calibration offset: seed N here produces a different placement than seed N did in the campaign, and the archived grt values do not describe our candidates. An earlier reading of "a uniform 0.66 factor" was an artifact of having only one candidate. ORFS and OpenROAD are ruled out as causes (identical to the campaign's be0dca0b and 3ca581e38 pins respectively, the latter with zero source diffs and the same src/sta). What remains is the campaign's much newer bazel-orfs and its synth-pipeline commits, which would change the OpenROAD-SYN netlist. Consequently Gate 1 is correctly INCONCLUSIVE, and any grt-anchored verdict now depends on re-measuring truth here -- which evaluate.tcl does, at roughly 5 hours per swerv candidate on this host. Also recorded: the divergence at the pre-registered default is a granularity mismatch rather than a defect. gpl sizes bins from average dbInst area, correct for the regime placement_cluster was built for ("a small group of gates", members "all placed at the center"), while RTL-MP's leaf clustering deliberately targets 10183-50915 cells per cluster. tinyRocket converges at the default with 13 clusters, so it is the granularity that diverges, not clustering as such. The 24 swerv runs therefore use E12_BIN_GRID_COUNT=8, disclosed as a knob and reported as exploratory rather than as a gate result. Signed-off-by: Øyvind Harboe --- flow/test/macro_e12/README.md | 85 +++ flow/test/macro_e12/e12_verdict_swerv.json | 729 +++++++++++++++++++++ flow/test/macro_e12/grade_e12.py | 104 +++ 3 files changed, 918 insertions(+) create mode 100644 flow/test/macro_e12/e12_verdict_swerv.json diff --git a/flow/test/macro_e12/README.md b/flow/test/macro_e12/README.md index b2d2819251..3a185cfe65 100644 --- a/flow/test/macro_e12/README.md +++ b/flow/test/macro_e12/README.md @@ -160,6 +160,91 @@ That test also recomputes five published numbers from the committed archive (+0.72, +0.82, +0.57, +0.65, +0.47). If it fails, the archive or the statistics moved and every E12 number is void. +## Measured so far + +Run on an 8C/16T host, serial (bazel-orfs's //fork is unreachable from +any pin ORFS can currently take). + +### The apparatus works end to end + +Flushed on nangate45/tinyRocket, k=4: candidate generation (4 distinct +placements), flat scoring, cluster dump (15 leaves, 29067/29067 movable +instances covered), clustered scoring (no divergence at default bins), +production tail to grt, verdict. ~30 minutes for the whole chain. +`e12_verdict_tinyRocket.json` is committed as evidence of the flush, not +as a result: n=4 with no measured noise band, so its rho is +uninterpretable and the gate correctly calls it inconclusive. + +### The clustered rung tracks the flat rung, and is 4.3x cheaper + +asap7/swerv_wrapper, k=24, all 24 converged (`e12_verdict_swerv.json`): + +| | rho vs flat HPWL | cost | peak RSS | +|---|---|---|---| +| flat rung | -- | 63.0 s | 2.40 GB | +| clustered rung | **+0.66 [+0.36, +0.86]** | **14.7 s** | 0.87 GB | + +The interval is clear of zero, so the necessary condition holds: the +clustered abstraction carries a substantial part of the flat rung's +wirelength signal at roughly a quarter of the cost. It is not a faithful +reproduction -- a third of the rank information is gone -- and it tracks +the flat rung's *HPWL* (+0.66) far better than its STA aggregate +(+0.23, interval includes zero), which is what one would expect of a +wirelength score. + +Caveat, disclosed: those 24 runs use `E12_BIN_GRID_COUNT=8`, because the +pre-registered default diverges on this design (see below). That is a +number tuned to this design's cluster count, so it is a knob, and this is +an exploratory measurement rather than a gate result. + +### The archive cannot serve as ground truth here + +This is now measured rather than argued. Pairing the *regenerated* scores +against the *archived* grt truth gives: + +| score column | rho vs archived `macro_paths_mean` | +|---|---| +| archive's own `wq25` | **+0.72 [+0.48, +0.84]** (reproduces the published figure) | +| regenerated `wq25` | **-0.42 [-0.75, +0.00]** | +| regenerated `macro_mean` | -0.43 [-0.75, -0.00] | + +The archive is internally consistent -- its own score column reproduces +the published +0.72 exactly -- but our regenerated scores anti-correlate +with it. The regenerated/archived score ratio scatters from 0.574 to +2.093 (stdev 0.357), so this is not a calibration offset: seed N here +produces a genuinely different placement than seed N did in the campaign, +and the archived truth therefore does not describe our candidates. + +Ruled out as causes: ORFS (identical to the campaign's `be0dca0b` pin +apart from the clkgate fix) and OpenROAD (zero source diffs against the +campaign's `3ca581e38`, same `src/sta`). The remaining difference is the +campaign's much newer bazel-orfs, which carries several synth-pipeline +commits and would change the OpenROAD-SYN netlist. + +**Consequence: any grt-anchored verdict needs the truth re-measured on +this setup.** `evaluate.tcl` does that, and `grade_e12.py --truth-dir` +consumes it. On swerv that is roughly 5 hours per candidate here. + +### The clustered solve diverges at the pre-registered default on swerv + +Overflow floors at 0.92 for 2175 iterations while the density penalty +climbs from 6.9e-14 to 4.1e+28, then the step length goes Inf/NaN +(GPL-0305). With bins matched to cluster size it converges in 227 +iterations. + +The cause is a granularity mismatch, not a defect: `BinGrid::initBins()` +sizes bins from the average **dbInst** area, which is correct for the +regime `placement_cluster` was built for -- its commit describes "a small +group of gates" whose members are "all placed at the center of the +cluster", and notes small clusters give better results. RTL-MP's leaf +clusters are the opposite: `min_num_macros_for_multilevel = 150` forces +`max_level = 1` on this design and `base_min_std_cell` targets +10183-50915 cells per cluster, so 7 clusters hold 98.6% of the instances. +Both tools behave as their authors intended; E12 straddles the seam. + +Note tinyRocket converges at the default with 13 clusters, so the +divergence is a property of the granularity, not of clustering per se. + ## Files | File | Role | diff --git a/flow/test/macro_e12/e12_verdict_swerv.json b/flow/test/macro_e12/e12_verdict_swerv.json new file mode 100644 index 0000000000..bedc099138 --- /dev/null +++ b/flow/test/macro_e12/e12_verdict_swerv.json @@ -0,0 +1,729 @@ +{ + "agreement": { + "clustered_cone_hpwl_vs_regen_flat_hpwl": { + "ci": [ + -0.14835886214442015, + 0.7032144429766622 + ], + "n": 24, + "rho": 0.3269565217391304, + "tracks": false + }, + "clustered_cone_hpwl_vs_regen_flat_wq25": { + "ci": [ + -0.08651734738691261, + 0.6747040771591407 + ], + "n": 24, + "rho": 0.3452173913043478, + "tracks": false + }, + "clustered_hpwl_vs_regen_flat_hpwl": { + "ci": [ + 0.355857832382624, + 0.8615249780893954 + ], + "n": 24, + "rho": 0.6634782608695652, + "tracks": true + }, + "clustered_hpwl_vs_regen_flat_wq25": { + "ci": [ + -0.19388646288209607, + 0.6454025516937968 + ], + "n": 24, + "rho": 0.23478260869565218, + "tracks": false + } + }, + "cost": { + "clustered": { + "clustered_insts": 100373.0, + "clusters_declared": 7.0, + "cone_nets": 2940.0, + "gpl_s": 14.665958333333334, + "halo_flat_insts": 1458.0, + "signal_nets": 103315.0, + "vmhwm_kb": 870160.1666666666 + }, + "flat": { + "gpl_s": 63.00975, + "vmhwm_kb": 2399772.1666666665 + } + }, + "design": "swerv_wrapper (asap7)", + "diverged": [], + "gate_0_rig_check": { + "candidates_compared": 24, + "fields_compared": [ + "wq25", + "macro_mean" + ], + "mismatches": [ + { + "archived": 2785.7330548953487, + "field": "wq25", + "regenerated": 1835.9894069387763, + "relative_error": 0.34093132013765454, + "tag": "cand_s0" + }, + { + "archived": 2124.174553075, + "field": "macro_mean", + "regenerated": 1404.8728822571431, + "relative_error": 0.33862644186965735, + "tag": "cand_s0" + }, + { + "archived": 1679.0540383595505, + "field": "wq25", + "regenerated": 2270.193169986301, + "relative_error": 0.3520667698130183, + "tag": "cand_s1" + }, + { + "archived": 1201.8567669485294, + "field": "macro_mean", + "regenerated": 1968.649762654088, + "relative_error": 0.6380069712070748, + "tag": "cand_s1" + }, + { + "archived": 1561.9627739247314, + "field": "wq25", + "regenerated": 3269.8423583999997, + "relative_error": 1.0934188784691026, + "tag": "cand_s10" + }, + { + "archived": 1147.4310488653841, + "field": "macro_mean", + "regenerated": 2196.354012881252, + "relative_error": 0.914149015797573, + "tag": "cand_s10" + }, + { + "archived": 1835.7560257127668, + "field": "wq25", + "regenerated": 1968.6606257594926, + "relative_error": 0.07239774686024691, + "tag": "cand_s11" + }, + { + "archived": 1516.627099319728, + "field": "macro_mean", + "regenerated": 1780.4130396687506, + "relative_error": 0.1739293333656915, + "tag": "cand_s11" + }, + { + "archived": 1767.4649063333331, + "field": "wq25", + "regenerated": 1953.3693447547173, + "relative_error": 0.10518140289814824, + "tag": "cand_s12" + }, + { + "archived": 1391.8813344379082, + "field": "macro_mean", + "regenerated": 1520.9488859874998, + "relative_error": 0.09272884717698562, + "tag": "cand_s12" + }, + { + "archived": 2526.7118175797095, + "field": "wq25", + "regenerated": 3990.747663228571, + "relative_error": 0.5794233578450725, + "tag": "cand_s13" + }, + { + "archived": 1897.7819729187493, + "field": "macro_mean", + "regenerated": 2575.3518759624994, + "relative_error": 0.3570325320361547, + "tag": "cand_s13" + }, + { + "archived": 1821.6865765567009, + "field": "wq25", + "regenerated": 2260.7875883333327, + "relative_error": 0.24104092187285467, + "tag": "cand_s14" + }, + { + "archived": 1602.7377526535945, + "field": "macro_mean", + "regenerated": 1704.4136826375004, + "relative_error": 0.06343890621879018, + "tag": "cand_s14" + }, + { + "archived": 1771.913401646465, + "field": "wq25", + "regenerated": 2359.926252985714, + "relative_error": 0.3318519126233069, + "tag": "cand_s15" + }, + { + "archived": 1358.6593544266668, + "field": "macro_mean", + "regenerated": 1829.3211365062502, + "relative_error": 0.34641632617190893, + "tag": "cand_s15" + }, + { + "archived": 1545.3409990300006, + "field": "wq25", + "regenerated": 2965.8702938, + "relative_error": 0.9192335514696468, + "tag": "cand_s16" + }, + { + "archived": 1510.885217171052, + "field": "macro_mean", + "regenerated": 2193.2354011000007, + "relative_error": 0.45162278125042876, + "tag": "cand_s16" + }, + { + "archived": 1567.7535892959181, + "field": "wq25", + "regenerated": 2049.93610927551, + "relative_error": 0.3075626956122237, + "tag": "cand_s17" + }, + { + "archived": 1276.4188487852343, + "field": "macro_mean", + "regenerated": 1701.715664618751, + "relative_error": 0.3331953427656375, + "tag": "cand_s17" + }, + { + "archived": 2056.802091085107, + "field": "wq25", + "regenerated": 1581.7219211758243, + "relative_error": 0.23098001113886685, + "tag": "cand_s18" + }, + { + "archived": 1866.2958056312496, + "field": "macro_mean", + "regenerated": 1176.5637018733337, + "relative_error": 0.3695727663732402, + "tag": "cand_s18" + }, + { + "archived": 2756.0829234117646, + "field": "wq25", + "regenerated": 1580.8045623225808, + "relative_error": 0.42643069666216815, + "tag": "cand_s19" + }, + { + "archived": 2406.4038558937496, + "field": "macro_mean", + "regenerated": 1328.8919312562498, + "relative_error": 0.44776853311569637, + "tag": "cand_s19" + }, + { + "archived": 1624.24137036, + "field": "wq25", + "regenerated": 1705.370984380435, + "relative_error": 0.04994923507117246, + "tag": "cand_s2" + }, + { + "archived": 1239.0146795746266, + "field": "macro_mean", + "regenerated": 1403.1986210264902, + "relative_error": 0.13251169994872905, + "tag": "cand_s2" + }, + { + "archived": 1637.4834353400001, + "field": "wq25", + "regenerated": 2403.292681494253, + "relative_error": 0.4676744995562312, + "tag": "cand_s20" + }, + { + "archived": 1238.9324906554052, + "field": "macro_mean", + "regenerated": 2015.6252473187506, + "relative_error": 0.6269048253407807, + "tag": "cand_s20" + }, + { + "archived": 1736.6384767676773, + "field": "wq25", + "regenerated": 1831.5751579183686, + "relative_error": 0.0546669225752688, + "tag": "cand_s21" + }, + { + "archived": 1346.2244227857145, + "field": "macro_mean", + "regenerated": 1632.6428711111107, + "relative_error": 0.21275683569364784, + "tag": "cand_s21" + }, + { + "archived": 1927.9062034193557, + "field": "wq25", + "regenerated": 1963.155684414895, + "relative_error": 0.018283815329304065, + "tag": "cand_s22" + }, + { + "archived": 1791.250751401274, + "field": "macro_mean", + "regenerated": 1626.0424857499997, + "relative_error": 0.09223067486337908, + "tag": "cand_s22" + }, + { + "archived": 1727.5670958315789, + "field": "wq25", + "regenerated": 1590.5140649166667, + "relative_error": 0.0793329713477441, + "tag": "cand_s23" + }, + { + "archived": 1331.175906175676, + "field": "macro_mean", + "regenerated": 1388.3628811283795, + "relative_error": 0.04295974310186818, + "tag": "cand_s23" + }, + { + "archived": 2315.489884940476, + "field": "wq25", + "regenerated": 1563.808611419999, + "relative_error": 0.3246316377407973, + "tag": "cand_s3" + }, + { + "archived": 1978.3974542125022, + "field": "macro_mean", + "regenerated": 1447.91053198, + "relative_error": 0.26813971131178066, + "tag": "cand_s3" + }, + { + "archived": 1697.4712668470586, + "field": "wq25", + "regenerated": 2060.6009194700005, + "relative_error": 0.2139238876764208, + "tag": "cand_s4" + }, + { + "archived": 1504.1807767115388, + "field": "macro_mean", + "regenerated": 1732.2689943586201, + "relative_error": 0.15163617377542282, + "tag": "cand_s4" + }, + { + "archived": 2248.4200519625006, + "field": "wq25", + "regenerated": 2882.474676712643, + "relative_error": 0.2820000756516636, + "tag": "cand_s5" + }, + { + "archived": 1786.3618813999994, + "field": "macro_mean", + "regenerated": 2015.6386160000009, + "relative_error": 0.12834842535954344, + "tag": "cand_s5" + }, + { + "archived": 2171.54877198, + "field": "wq25", + "regenerated": 2924.8595638023257, + "relative_error": 0.3469002407601757, + "tag": "cand_s6" + }, + { + "archived": 1929.5214547812502, + "field": "macro_mean", + "regenerated": 2314.76234085625, + "relative_error": 0.1996561816508407, + "tag": "cand_s6" + }, + { + "archived": 2422.3405354057973, + "field": "wq25", + "regenerated": 2084.0266576190465, + "relative_error": 0.13966404510094013, + "tag": "cand_s7" + }, + { + "archived": 1939.7175586750004, + "field": "macro_mean", + "regenerated": 1640.22694193125, + "relative_error": 0.1543990852711202, + "tag": "cand_s7" + }, + { + "archived": 1642.6493030918361, + "field": "wq25", + "regenerated": 1727.1496022842107, + "relative_error": 0.05144147264624648, + "tag": "cand_s8" + }, + { + "archived": 1432.0329670838712, + "field": "macro_mean", + "regenerated": 1593.201552193334, + "relative_error": 0.11254530364455186, + "tag": "cand_s8" + }, + { + "archived": 1707.6986122413803, + "field": "wq25", + "regenerated": 1993.478260886076, + "relative_error": 0.16734782507646687, + "tag": "cand_s9" + }, + { + "archived": 1422.9825081301371, + "field": "macro_mean", + "regenerated": 1659.4851108874986, + "relative_error": 0.16620204493457655, + "tag": "cand_s9" + } + ], + "pass": false, + "relative_tolerance": 1e-06 + }, + "gate_1_e12": { + "ci": [ + -0.6470074268239406, + 0.3091068301225919 + ], + "ci_clear_of_zero": false, + "expected_n": 24, + "flat_ci": [ + 0.48, + 0.84 + ], + "inside_flat_ci": false, + "kpi": "macro_paths_mean", + "n": 24, + "pass": false, + "population_complete": true, + "rho": -0.18869565217391304, + "verdict": "inconclusive" + }, + "gate_agreement": { + "ci": [ + 0.355857832382624, + 0.8615249780893954 + ], + "ci_clear_of_zero": true, + "n": 24, + "note": "necessary condition only: tracking the flat rung does not show either rung predicts the flow", + "pair": "clustered_hpwl_vs_regen_flat_hpwl", + "pass": true, + "rho": 0.6634782608695652, + "verdict": "pass" + }, + "population": "rtl_macro_placer -random_seed 0..23, one shared floorplan", + "rho": { + "archive_flat_macro_mean": { + "kpi": { + "achieved": { + "ci": [ + -0.5019693654266959, + 0.33508311461067375 + ], + "rho": -0.08347826086956522 + }, + "general_paths_mean": { + "ci": [ + -0.47115384615384615, + 0.36066288704753596 + ], + "rho": -0.05391304347826087 + }, + "macro_paths_mean": { + "ci": [ + 0.6054243219597552, + 0.9168126094570926 + ], + "rho": 0.8173913043478261 + }, + "stdcell_um2": { + "ci": [ + 0.12856516015796401, + 0.7075098814229249 + ], + "rho": 0.48434782608695653 + } + }, + "n": 24 + }, + "archive_flat_wq25": { + "kpi": { + "achieved": { + "ci": [ + -0.6544181977252844, + 0.1595977262789681 + ], + "rho": -0.27304347826086955 + }, + "general_paths_mean": { + "ci": [ + -0.6313485113835375, + 0.2005253940455341 + ], + "rho": -0.2417391304347826 + }, + "macro_paths_mean": { + "ci": [ + 0.47734271887373514, + 0.8429824561403507 + ], + "rho": 0.7243478260869565 + }, + "stdcell_um2": { + "ci": [ + 0.33800350262697015, + 0.8215223097112863 + ], + "rho": 0.6504347826086957 + } + }, + "n": 24 + }, + "archive_objective": { + "kpi": { + "achieved": { + "ci": [ + -0.6461336828309305, + 0.21708805579773321 + ], + "rho": -0.23391304347826086 + }, + "general_paths_mean": { + "ci": [ + -0.6334801762114537, + 0.23393091386095322 + ], + "rho": -0.21739130434782608 + }, + "macro_paths_mean": { + "ci": [ + 0.2390542907180385, + 0.7918313570487484 + ], + "rho": 0.5739130434782609 + }, + "stdcell_um2": { + "ci": [ + 0.059030837004405284, + 0.743231441048035 + ], + "rho": 0.4747826086956522 + } + }, + "n": 24 + }, + "clustered_cone_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.5431072210065646, + 0.23274336283185845 + ], + "rho": -0.19652173913043477 + }, + "general_paths_mean": { + "ci": [ + -0.5499124343257442, + 0.22251308900523561 + ], + "rho": -0.19217391304347825 + }, + "macro_paths_mean": { + "ci": [ + -0.5745614035087718, + 0.18411867364746945 + ], + "rho": -0.24347826086956523 + }, + "stdcell_um2": { + "ci": [ + -0.47267162221250547, + 0.41893076248904476 + ], + "rho": -0.029565217391304348 + } + }, + "n": 24 + }, + "clustered_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.4890254609306409, + 0.3389010989010988 + ], + "rho": -0.08434782608695653 + }, + "general_paths_mean": { + "ci": [ + -0.411610650371017, + 0.4048140043763677 + ], + "rho": -0.0026086956521739132 + }, + "macro_paths_mean": { + "ci": [ + -0.6470074268239406, + 0.3091068301225919 + ], + "rho": -0.18869565217391304 + }, + "stdcell_um2": { + "ci": [ + -0.5002192021043402, + 0.41181619256017515 + ], + "rho": -0.019130434782608695 + } + }, + "n": 24 + }, + "regen_flat_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.3491020586947, + 0.4542268944371442 + ], + "rho": 0.05304347826086957 + }, + "general_paths_mean": { + "ci": [ + -0.2772667542706965, + 0.5126637554585153 + ], + "rho": 0.14173913043478262 + }, + "macro_paths_mean": { + "ci": [ + -0.4851138353765323, + 0.40753724802804564 + ], + "rho": -0.051304347826086956 + }, + "stdcell_um2": { + "ci": [ + -0.4543867306852903, + 0.4722100656455143 + ], + "rho": 0.00608695652173913 + } + }, + "n": 24 + }, + "regen_flat_macro_mean": { + "kpi": { + "achieved": { + "ci": [ + -0.21246707638279191, + 0.6190893169877407 + ], + "rho": 0.24 + }, + "general_paths_mean": { + "ci": [ + -0.21731526016615654, + 0.6376367614879651 + ], + "rho": 0.23652173913043478 + }, + "macro_paths_mean": { + "ci": [ + -0.746268656716418, + -0.004822446295484437 + ], + "rho": -0.4252173913043478 + }, + "stdcell_um2": { + "ci": [ + -0.7219064276344557, + 0.01183691363437089 + ], + "rho": -0.39565217391304347 + } + }, + "n": 24 + }, + "regen_flat_wq25": { + "kpi": { + "achieved": { + "ci": [ + -0.2752858399296394, + 0.5731814198071868 + ], + "rho": 0.17130434782608694 + }, + "general_paths_mean": { + "ci": [ + -0.27232924693520133, + 0.5977262789680805 + ], + "rho": 0.18521739130434783 + }, + "macro_paths_mean": { + "ci": [ + -0.7471466198419666, + 0.0021920210434020165 + ], + "rho": -0.4156521739130435 + }, + "stdcell_um2": { + "ci": [ + -0.700877192982456, + -0.013134851138353762 + ], + "rho": -0.41043478260869565 + } + }, + "n": 24 + } + }, + "tags": [ + "cand_s0", + "cand_s1", + "cand_s10", + "cand_s11", + "cand_s12", + "cand_s13", + "cand_s14", + "cand_s15", + "cand_s16", + "cand_s17", + "cand_s18", + "cand_s19", + "cand_s2", + "cand_s20", + "cand_s21", + "cand_s22", + "cand_s23", + "cand_s3", + "cand_s4", + "cand_s5", + "cand_s6", + "cand_s7", + "cand_s8", + "cand_s9" + ] +} diff --git a/flow/test/macro_e12/grade_e12.py b/flow/test/macro_e12/grade_e12.py index b412334937..7054ced596 100644 --- a/flow/test/macro_e12/grade_e12.py +++ b/flow/test/macro_e12/grade_e12.py @@ -184,6 +184,76 @@ def rho_table(tags, sources, n_boot): return table +# Score-versus-score pairs. Comparing a candidate scorer against the +# established one needs no ground truth, which makes it the cheapest +# decisive experiment available: the flat rung is the thing already shown +# to predict the flow, so a clustered rung that does not track it cannot +# predict the flow either. Necessary, not sufficient -- agreement says +# nothing about whether either scorer is right. +AGREEMENT_PAIRS = ( + ("clustered_hpwl", "regen_flat_wq25"), + ("clustered_hpwl", "regen_flat_hpwl"), + ("clustered_cone_hpwl", "regen_flat_wq25"), + ("clustered_cone_hpwl", "regen_flat_hpwl"), +) + +VARIANT_FIELDS = {label: (source, field) for label, source, field in VARIANTS} + + +def agreement_table(tags, sources, n_boot): + """rho between a candidate scorer and the established one.""" + table = {} + for candidate, reference in AGREEMENT_PAIRS: + pairs = [] + for label in (candidate, reference): + source, field = VARIANT_FIELDS[label] + pairs.append((sources.get(source, {}), field)) + usable = [ + t + for t in tags + if all(t in records and field in records[t] for records, field in pairs) + ] + if len(usable) < 3: + continue + xs = [pairs[0][0][t][pairs[0][1]] for t in usable] + ys = [pairs[1][0][t][pairs[1][1]] for t in usable] + rho = spearman(xs, ys) + low, high = spearman_ci(xs, ys, n_boot=n_boot) + table["%s_vs_%s" % (candidate, reference)] = { + "n": len(usable), + "rho": rho, + "ci": [low, high], + "tracks": bool(low > 0.0), + } + return table + + +def gate_agreement(table): + """Does the clustered rung track the flat rung at all? + + The verdict rides on the plain HPWL pair, because that is the + like-for-like comparison: same scalar, same nets, only the movable + model differs. + """ + entry = table.get("clustered_hpwl_vs_regen_flat_hpwl") + if entry is None: + return {"pass": False, "verdict": "fail", "reason": "no paired scores"} + verdict = "pass" if entry["tracks"] else "inconclusive" + return { + "pair": "clustered_hpwl_vs_regen_flat_hpwl", + "rho": entry["rho"], + "ci": entry["ci"], + "n": entry["n"], + "ci_clear_of_zero": entry["tracks"], + "verdict": verdict, + "pass": verdict == "pass", + "note": ( + "necessary condition only: tracking the flat rung does not " + "show either rung predicts the flow" + ), + } + + def cost_table(tags, sources): """Mean of each cost field, per source, over the candidates that have it.""" costs = {} @@ -345,6 +415,21 @@ def format_report(verdict): ) lines.append(row) + if verdict["agreement"]: + lines.append("") + lines.append("scorer agreement (no ground truth needed):") + for pair, entry in verdict["agreement"].items(): + lines.append( + " {:<48} {:>3} {:>+6.2f} [{:>+6.2f},{:>+6.2f}]{}".format( + pair, + entry["n"], + entry["rho"], + entry["ci"][0], + entry["ci"][1], + "" if entry["tracks"] else " (interval includes zero)", + ) + ) + if verdict["cost"]: lines.append("") lines.append("mean cost per candidate:") @@ -357,6 +442,22 @@ def format_report(verdict): lines.append("") lines.append("DIVERGED (not scorable): {}".format(verdict["diverged"])) + gate_a = verdict["gate_agreement"] + lines.append("") + if "reason" in gate_a: + lines.append("Agreement gate: FAIL -- {}".format(gate_a["reason"])) + else: + lines.append( + "Agreement gate: {} -- rho(clustered vs flat HPWL) = " + "{:+.2f} [{:+.2f}, {:+.2f}], n = {}".format( + gate_a["verdict"].upper(), + gate_a["rho"], + gate_a["ci"][0], + gate_a["ci"][1], + gate_a["n"], + ) + ) + gate1 = verdict["gate_1_e12"] lines.append("") if "reason" in gate1: @@ -388,11 +489,14 @@ def format_report(verdict): def build_verdict(truth, flat, clustered, expected_n, n_boot, tolerance): tags, sources = collect(truth, flat, clustered) table = rho_table(tags, sources, n_boot) + agreement = agreement_table(tags, sources, n_boot) return { "design": truth.get("design"), "population": truth.get("population"), "tags": tags, "rho": table, + "agreement": agreement, + "gate_agreement": gate_agreement(agreement), "cost": cost_table(tags, sources), "diverged": diverged_tags(sources), "gate_0_rig_check": gate_zero( From 8792fa974769b4ae8bee437e6e1e3711712a939f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Tue, 1 Sep 2026 22:16:16 +0200 Subject: [PATCH 10/11] flow: E12 parallel driver, because bazel's lock was the real serializer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Candidate runs have been serial on the assumption that bazel-orfs's //fork was needed for parallelism and is unreachable from any commit ORFS can pin (it lands after the verilog/ subtree removal that @bazel-orfs-verilog is built from). That was the wrong diagnosis: fork was never in the way. Bazel's output-base lock is what serializes concurrent `bazelisk run` invocations, and orfs_run_executable emits a plain shell wrapper that execs make with no bazel server involved. Invoke that wrapper directly and the lock is simply not in the picture. So run_parallel.sh drives any of the four E12 stages over a candidate list, N at a time, with no fork and no bazel. Per-candidate processes were mandatory anyway -- gpl's Replace::reset() does not clear its cluster list -- and e12_redirect already gives each tag its own work directory. RUN_LOG_NAME_STEM is overridden per tag so workers do not race on a shared run.log, and scheduling uses `wait -n` so a slow candidate does not idle the other slots. This matters on any machine, not just this one: a 24-candidate truth run is hours of wall clock that parallelises almost perfectly, and handing the campaign to a bigger host without a parallel driver would just move the serialization somewhere else. Concurrency is left to the caller because the limit is memory, not cores: the flat rung peaks at 2.4GB on swerv and the timing-driven tail is higher, so the right number comes from measuring one tail rather than from the core count. Signed-off-by: Øyvind Harboe --- flow/test/macro_e12/run_parallel.sh | 93 +++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 flow/test/macro_e12/run_parallel.sh diff --git a/flow/test/macro_e12/run_parallel.sh b/flow/test/macro_e12/run_parallel.sh new file mode 100755 index 0000000000..d4097ce415 --- /dev/null +++ b/flow/test/macro_e12/run_parallel.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# Run one E12 stage over a list of candidates, N at a time. +# +# Why this exists rather than bazel-orfs's //fork: fork is unreachable +# from any bazel-orfs commit ORFS can currently pin (it lands after the +# verilog/ subtree removal that @bazel-orfs-verilog is built from). But +# fork was never what stood in the way of parallelism -- bazel's +# output-base lock was, which serializes concurrent `bazelisk run` +# invocations. orfs_run_executable emits a plain shell wrapper that execs +# make with no bazel server involved, so invoking that wrapper directly +# sidesteps the lock and needs no fork. +# +# Each candidate is a separate process by design: the scorers must be, in +# any case, because gpl's Replace::reset() does not clear its cluster +# list. Per-candidate work directories come from e12_redirect, and +# RUN_LOG_NAME_STEM is overridden per tag so the workers do not race on a +# shared run.log. +# +# Usage: +# run_parallel.sh ... +# run_parallel.sh swerv_evaluate /path/to/evidence 3 cand_s0 cand_s1 +# +# Extra KEY=VALUE overrides may be passed via E12_EXTRA_ARGS. + +set -euo pipefail + +if [ "$#" -lt 4 ]; then + echo "usage: $0 ..." >&2 + exit 2 +fi + +target=$1 +out_dir=$2 +jobs=$3 +shift 3 +tags=("$@") + +repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd) +wrapper="$repo_root/bazel-bin/flow/test/macro_e12/run_${target}_base_executable" +runfiles="$wrapper.runfiles/_main" + +if [ ! -x "$wrapper" ]; then + echo "$0: no wrapper at $wrapper" >&2 + echo " build it first: bazelisk build //flow/test/macro_e12:$target" >&2 + exit 1 +fi +if [ ! -d "$runfiles" ]; then + echo "$0: no runfiles at $runfiles" >&2 + exit 1 +fi + +mkdir -p "$out_dir/logs" + +# The wrapper creates an `external` symlink in its runfiles on first use. +# Do it once here rather than letting N workers race on it. +(cd "$runfiles" && [ -e external ] || ln -sfn "$(realpath "$runfiles/..")" "$runfiles/external") + +echo "$0: $target over ${#tags[@]} candidates, $jobs at a time" + +failed=0 +started=0 + +# Reap whichever worker finishes first, rather than blocking on a +# particular one: a slow candidate must not idle the other slots. +for tag in "${tags[@]}"; do + while [ "$(jobs -rp | wc -l)" -ge "$jobs" ]; do + if ! wait -n; then + failed=$((failed + 1)) + fi + done + + ( + cd "$runfiles" + exec "$wrapper" \ + E12_OUT_DIR="$out_dir" \ + E12_TAG="$tag" \ + RUN_LOG_NAME_STEM="run_$tag" \ + ${E12_EXTRA_ARGS:-} + ) > "$out_dir/logs/$tag.log" 2>&1 & + started=$((started + 1)) + echo " [$started/${#tags[@]}] started $tag (pid $!)" +done + +while [ "$(jobs -rp | wc -l)" -gt 0 ]; do + if ! wait -n; then + failed=$((failed + 1)) + fi +done + +echo "$0: done, $failed failure(s) of ${#tags[@]}" +echo " per-candidate logs: $out_dir/logs/.log" +exit $((failed > 0)) From 65d762511d848cbec50e776d54adfe040f5ccdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 2 Sep 2026 11:16:38 +0200 Subject: [PATCH 11/11] flow: E12 graded against a truth measured here -- the scalar is the problem, not the clustering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Truth re-measured for the full population with evaluate.tcl: 24 candidates generated, 23 evaluable, ~34 min each, about an hour of wall clock for all 23 at 4-way parallel via run_parallel.sh. cand_s2 is excluded because it is genuinely infeasible -- its macro placement leaves a channel PDN cannot repair (PDN-0179). That is the strongest truth signal a candidate can give, and notably one no wirelength score can express: a selector shipping cand_s2 would have produced a design that does not build. Graded on that truth: flat, STA aggregate (wq25) +0.61 [+0.29, +0.78] ranks flat, STA macro aggregate +0.59 [+0.20, +0.80] ranks flat, raw HPWL +0.24 [-0.24, +0.65] no evidence clustered HPWL +0.26 [-0.22, +0.66] no evidence clustered macro-cone HPWL +0.39 [-0.01, +0.72] just misses The campaign's central phenomenon reproduces: a fast non-timing-driven placement with an STA readout ranks the macro-path KPI at +0.61, interval clear of zero, against the published +0.72 [+0.48, +0.84]. The rig is sound; what failed to reproduce was the candidate population, not the idea. E3's "drop the STA" does not reproduce. The campaign reports raw HPWL at +0.67 on this KPI; here it is +0.24 with the interval spanning zero. Anything built on HPWL-only being ranking-equivalent needs to re-derive that first. And E12's own result is not what it appeared. Clustered HPWL (+0.26) is statistically indistinguishable from flat HPWL (+0.24), while tracking the flat rung's HPWL closely (+0.66 [+0.34, +0.86]) at 14.7s against 63.0s and 0.87GB against 2.43GB. So the clustering is faithful and cheap; the limitation is inherited from the scalar it reads. No improvement to the cluster model can rescue a readout that carries no signal -- which reframes E12 from "make the scorer cheaper" to "make the readout rank". The constructive thread is the macro-cone readout at +0.39, best of the HPWL family and only just short of significance. It is the one variant that moved toward the live KPI, and it did so by restricting the sum to nets within reach of a macro pin. Also settled, from both directions: the archive describes a different population. Our scores against archived truth give -0.42, and our truth against archived truth gives -0.26 [-0.65, +0.24] on macro_paths_mean and +0.07 on achieved -- uncorrelated. cand_s0's achieved matching to 0.6ps is coincidence, since the population ties on achieved anyway. The archive stays internally consistent and still reproduces its published +0.72; it simply does not describe these candidates. Signed-off-by: Øyvind Harboe --- flow/test/macro_e12/README.md | 63 ++++ .../e12_verdict_swerv_remeasured.json | 288 ++++++++++++++++++ 2 files changed, 351 insertions(+) create mode 100644 flow/test/macro_e12/e12_verdict_swerv_remeasured.json diff --git a/flow/test/macro_e12/README.md b/flow/test/macro_e12/README.md index 3a185cfe65..279fa65d37 100644 --- a/flow/test/macro_e12/README.md +++ b/flow/test/macro_e12/README.md @@ -225,6 +225,69 @@ commits and would change the OpenROAD-SYN netlist. this setup.** `evaluate.tcl` does that, and `grade_e12.py --truth-dir` consumes it. On swerv that is roughly 5 hours per candidate here. +### Graded against a truth measured here: the scalar is the problem, not the clustering + +24 candidates generated, 23 evaluable (cand_s2 is infeasible -- its macro +placement leaves a channel PDN cannot repair, `PDN-0179`, which is the +strongest truth signal a candidate can give and one no wirelength score +can express). Truth measured by `evaluate.tcl` through the full +production tail, ~34 min per candidate, ~1 h wall for all 23 at 4-way +parallel (`e12_verdict_swerv_remeasured.json`). + +| scorer | rho vs grt `macro_paths_mean` | reads | +|---|---|---| +| flat, STA aggregate (`wq25`) | **+0.61 [+0.29, +0.78]** | ranks | +| flat, STA macro aggregate | +0.59 [+0.20, +0.80] | ranks | +| flat, raw HPWL | +0.24 [-0.24, +0.65] | no evidence | +| clustered HPWL | +0.26 [-0.22, +0.66] | no evidence | +| clustered **macro-cone** HPWL | +0.39 [-0.01, +0.72] | just misses | + +Three things follow, and they change what E12 should be. + +**The campaign's central phenomenon reproduces.** A fast +non-timing-driven placement with an STA readout ranks the macro-path KPI +at +0.61, interval clear of zero, against the published +0.72 +[+0.48, +0.84]. So the rig is sound and the idea of scoring after the fog +holds -- what did not reproduce was the specific candidate population. + +**E3's "drop the STA" does not reproduce.** The campaign reports raw HPWL +ranking the same truth at +0.67. Here it is +0.24 with the interval +spanning zero: no demonstrable signal. That conclusion needs +re-examination before anything is built on it. + +**E12's clustered HPWL (+0.26) is statistically indistinguishable from +flat HPWL (+0.24).** The clustering is not what costs the ranking -- it +faithfully reproduces the flat rung's HPWL (agreement +0.66 [+0.34, ++0.86]) at 14.7 s against 63.0 s and 0.87 GB against 2.43 GB. The +limitation is inherited: E12 is built on an HPWL-only readout, and +HPWL-only does not rank on this setup. No improvement to the cluster +model can fix a scalar that carries no signal. + +The constructive thread is the **macro-cone** readout at +0.39, the best +of the HPWL family and only just short of significance. Restricting the +sum to nets within reach of a macro pin is the one variant that moved +toward the live KPI, which suggests the next E12 iteration should pursue +a readout aimed at macro-relevant structure -- or carry STA -- rather +than a cheaper way to compute the same weak number. + +### The archive and this truth describe different populations + +Measured from both directions, so this is settled: + +| comparison | rho | +|---|---| +| our scores vs archived truth | -0.42 [-0.75, +0.00] | +| **our truth vs archived truth** | **-0.26 [-0.65, +0.24]** (`macro_paths_mean`) | +| our truth vs archived truth (`achieved`) | +0.07 [-0.37, +0.48] | + +Our re-measured truth is uncorrelated with the archived truth on every +KPI. Seed N here is simply a different placement than seed N was in the +campaign. (cand_s0's `achieved` matching the archive to 0.6 ps is +coincidence: the population ties on `achieved` anyway, which is E1's own +finding.) The archive remains internally consistent and its own score +column still reproduces the published +0.72 -- it just does not describe +these candidates. + ### The clustered solve diverges at the pre-registered default on swerv Overflow floors at 0.92 for 2175 iterations while the density penalty diff --git a/flow/test/macro_e12/e12_verdict_swerv_remeasured.json b/flow/test/macro_e12/e12_verdict_swerv_remeasured.json new file mode 100644 index 0000000000..ae5cde85cf --- /dev/null +++ b/flow/test/macro_e12/e12_verdict_swerv_remeasured.json @@ -0,0 +1,288 @@ +{ + "agreement": { + "clustered_cone_hpwl_vs_regen_flat_hpwl": { + "ci": [ + -0.18245264207377865, + 0.6900149031296572 + ], + "n": 23, + "rho": 0.31225296442687744, + "tracks": false + }, + "clustered_cone_hpwl_vs_regen_flat_wq25": { + "ci": [ + -0.11576846307385232, + 0.6565152271592611 + ], + "n": 23, + "rho": 0.3181818181818182, + "tracks": false + }, + "clustered_hpwl_vs_regen_flat_hpwl": { + "ci": [ + 0.3376558603491272, + 0.8579234972677595 + ], + "n": 23, + "rho": 0.658102766798419, + "tracks": true + }, + "clustered_hpwl_vs_regen_flat_wq25": { + "ci": [ + -0.21825396825396823, + 0.6608652411735456 + ], + "n": 23, + "rho": 0.23023715415019763, + "tracks": false + } + }, + "cost": { + "clustered": { + "clustered_insts": 100373.0, + "clusters_declared": 7.0, + "cone_nets": 2940.0, + "gpl_s": 14.698217391304347, + "halo_flat_insts": 1458.0, + "signal_nets": 103315.0, + "vmhwm_kb": 870101.0434782609 + }, + "flat": { + "gpl_s": 63.016695652173915, + "vmhwm_kb": 2427651.4782608696 + } + }, + "design": "re-measured", + "diverged": [], + "gate_0_rig_check": { + "candidates_compared": 0, + "mismatches": [], + "not_applicable": "truth source carries no archived scores", + "pass": true + }, + "gate_1_e12": { + "ci": [ + -0.21990049751243781, + 0.6578816509199404 + ], + "ci_clear_of_zero": false, + "expected_n": 23, + "flat_ci": [ + 0.48, + 0.84 + ], + "inside_flat_ci": false, + "kpi": "macro_paths_mean", + "n": 23, + "pass": false, + "population_complete": true, + "rho": 0.25691699604743085, + "verdict": "inconclusive" + }, + "gate_agreement": { + "ci": [ + 0.3376558603491272, + 0.8579234972677595 + ], + "ci_clear_of_zero": true, + "n": 23, + "note": "necessary condition only: tracking the flat rung does not show either rung predicts the flow", + "pair": "clustered_hpwl_vs_regen_flat_hpwl", + "pass": true, + "rho": 0.658102766798419, + "verdict": "pass" + }, + "population": null, + "rho": { + "clustered_cone_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.3266832917705736, + 0.5754857997010463 + ], + "rho": 0.1600790513833992 + }, + "general_paths_mean": { + "ci": [ + -0.34061569016881826, + 0.5492537313432836 + ], + "rho": 0.12845849802371542 + }, + "macro_paths_mean": { + "ci": [ + -0.013986013986013984, + 0.7165829145728643 + ], + "rho": 0.3942687747035573 + }, + "stdcell_um2": { + "ci": [ + -0.34960159362549803, + 0.431547619047619 + ], + "rho": 0.03557312252964427 + } + }, + "n": 23 + }, + "clustered_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.12667660208643816, + 0.64863523573201 + ], + "rho": 0.31620553359683795 + }, + "general_paths_mean": { + "ci": [ + -0.11155378486055777, + 0.6200895077076082 + ], + "rho": 0.30237154150197626 + }, + "macro_paths_mean": { + "ci": [ + -0.21990049751243781, + 0.6578816509199404 + ], + "rho": 0.25691699604743085 + }, + "stdcell_um2": { + "ci": [ + -0.507, + 0.3766749379652606 + ], + "rho": -0.05533596837944664 + } + }, + "n": 23 + }, + "regen_flat_hpwl": { + "kpi": { + "achieved": { + "ci": [ + -0.23429710867397804, + 0.6168734491315138 + ], + "rho": 0.22332015810276679 + }, + "general_paths_mean": { + "ci": [ + -0.23752495009980043, + 0.5898456943753112 + ], + "rho": 0.19861660079051383 + }, + "macro_paths_mean": { + "ci": [ + -0.24065769805680118, + 0.6468253968253967 + ], + "rho": 0.24308300395256918 + }, + "stdcell_um2": { + "ci": [ + -0.27617148554336984, + 0.6196623634558094 + ], + "rho": 0.20553359683794467 + } + }, + "n": 23 + }, + "regen_flat_macro_mean": { + "kpi": { + "achieved": { + "ci": [ + -0.6228287841191068, + 0.2772523643603783 + ], + "rho": -0.19367588932806323 + }, + "general_paths_mean": { + "ci": [ + -0.6263079222720478, + 0.271 + ], + "rho": -0.20454545454545456 + }, + "macro_paths_mean": { + "ci": [ + 0.20358387257341964, + 0.8028870084619214 + ], + "rho": 0.5869565217391305 + }, + "stdcell_um2": { + "ci": [ + 0.018962075848303395, + 0.7522388059701492 + ], + "rho": 0.44664031620553357 + } + }, + "n": 23 + }, + "regen_flat_wq25": { + "kpi": { + "achieved": { + "ci": [ + -0.6342800199302441, + 0.23828514456630107 + ], + "rho": -0.22628458498023715 + }, + "general_paths_mean": { + "ci": [ + -0.6383507203179334, + 0.22067594433399604 + ], + "rho": -0.24209486166007904 + }, + "macro_paths_mean": { + "ci": [ + 0.28742514970059885, + 0.7779990044798408 + ], + "rho": 0.6057312252964426 + }, + "stdcell_um2": { + "ci": [ + 0.02942643391521197, + 0.7693836978131213 + ], + "rho": 0.4624505928853755 + } + }, + "n": 23 + } + }, + "tags": [ + "cand_s0", + "cand_s1", + "cand_s10", + "cand_s11", + "cand_s12", + "cand_s13", + "cand_s14", + "cand_s15", + "cand_s16", + "cand_s17", + "cand_s18", + "cand_s19", + "cand_s20", + "cand_s21", + "cand_s22", + "cand_s23", + "cand_s3", + "cand_s4", + "cand_s5", + "cand_s6", + "cand_s7", + "cand_s8", + "cand_s9" + ] +}