Skip to content

bazel: kepler-formal LEC per stage for all designs [experimental] - #4337

Closed
oharboe wants to merge 11 commits into
The-OpenROAD-Project:masterfrom
oharboe:kepler-lec
Closed

oharboe wants to merge 11 commits into
The-OpenROAD-Project:masterfrom
oharboe:kepler-lec

Conversation

@oharboe

@oharboe oharboe commented Jul 6, 2026 •

Copy link
Copy Markdown
Collaborator

Draft / experimental — not ready for review.

Wires kepler-formal LEC into the ORFS bazel flow as per-design, per-stage equivalence checks.

Rides on:

  • OpenROAD#10812 (hermetic-llvm toolchain) — tools/OpenROAD submodule points at the PR head, so CI submodule clones may trip until it merges.
  • kepler-formal's hermetic-llvm bazel build and pre-synthesis (RTL) .v support (RTL-vs-gate SEC via sv2v).
  • The _syn variant work from flow: add OpenROAD built-in synth as _syn variant of every flat design #4253 (carried here; closed unmerged).

What this does

  • bazelisk run @bazel-orfs//:bump (3a5ddd7 → 970ff81, patch 0001 dropped — landed upstream) + OpenROAD submodule → PR 10812 head; ORFS root switches toolchains_llvm → hermetic-llvm to match, mirroring the root-only single_version_overrides (abc/bison/boost.icl/gawk/tcl_lang, plus m4/sed fix releases for the same gnulib class) and the rules_pycross workaround.
  • kepler-formal pinned idiomatically in MODULE.bazel (git_override, no submodule use); bazel-orfs's lec module consumed as bazel-orfs-lec with an expansion patch carried in patches/bazel-orfs/ (to be upstreamed): build-time lec_check + instant lec_status_test + lec() macro + generic stage-netlist extraction, and orfs_canon_verilog (canonicalize RTLIL → pre-synthesis Verilog).
  • LEC runs as build actions (bazelisk build //flow:lec_check --jobs=N) so verdicts+logs cache; <design>_lec_<stage>_test targets only assert the recorded verdict — instant, no test timeouts (33 tests over the verified designs run in ~0s each).
  • Per-stage chain per design: canonicalized RTL ↔ synth netlist (SEC, sv2v, pdr engine), then adjacent-pair gate LEC synth↔floorplan↔place↔cts↔route↔final on OpenROAD-written netlists (physical-only cells removed).
  • Gold is the post-canonicalization .v (yosys canonicalize checkpoint → proc; pmuxtree; memory_collect; memory_map; write_verilog), so kepler never parses raw (System)Verilog edge cases — a failure implicates synthesis, not canonicalization.
  • Flat designs additionally check the OpenROAD built-in synth (_syn variant) netlist against the same gold.
  • Hierarchical (OPENROAD_HIERARCHICAL=1) designs (ibex, mock-alu, …) exercise -hier read/write throughout.

Usage

bazelisk build //flow:lec_check --jobs=N   # runs kepler-formal, memory-hungry; cap jobs
bazelisk test  //flow:lec_test             # instant verdict checks (409 tests enumerate)

Results (asap7)

design RTL↔synth (SEC) RTL↔builtin-synth (SEC) fp place cts route final
gcd PASS (100% outputs) PASS (100%) PASS PASS PASS PASS PASS
uart PASS (100%) PASS (100%) PASS PASS PASS PASS PASS
aes PASS (0.78% outputs¹) PASS (0.78%¹) PASS PASS PASS PASS PASS
mock-alu (-hier) PASS (100%) synth fails² PASS PASS PASS PASS PASS
ibex (-hier) PASS (5.66% outputs¹) synth fails³ PASS PASS PASS PASS PASS
riscv32i (SYNTH_HIERARCHICAL) —⁴ —⁴ — — — — —

All 33 built checks report PASS; the per-stage gate-level chain is clean on every design tried, including the -hier ones.

Notable findings — summary

  1. Hollow PASSes are the top kepler-formal item: aes proves "equivalence" at 0.78% checked-output coverage (multi-driver extraction skips 128/129 outputs), ibex at 5.66%. The verdict artifact now records coverage so these are visible at a glance.
  2. legacy SEC engine is not usable in practice: inconclusive on uart after 28 min at k=32; pdr proves the same check at k=1 in seconds. pdr is the default here.
  3. Three kepler parser/lowering gaps were avoidable in gold preparation rather than kepler patches: $pmux-as-function (pmuxtree), initial-block ROM/reg init (memory_map), and multi-root top inference (use the OpenROAD-written 1_synth.odb netlist as gate side).
  4. Pre-existing failures, not LEC bugs: built-in synth fails on mock-alu (SDC *io_out_REG*) and ibex (elaboration); riscv32i's base partitioned yosys synth is broken at the new bazel-orfs pin.

No kepler-formal source patches ended up necessary for the basic asap7 designs — every blocker was either avoidable in gold preparation or is a genuine finding for upstream.

Findings — detail

kepler-formal (gaps to feed back upstream):

  1. format: verilog netlist parser rejects behavioral RTL (reg [0:0] x; → parse error). The pre-synthesis path must use sv2v (slang frontend for gold). Wired accordingly.
  2. Verilog function calls in continuous assigns unsupported (naja lowering): yosys write_verilog renders $pmux as a function. Dodged with pmuxtree in orfs_canon_verilog.
  3. initial blocks unsupported (only always* lowered): yosys emits ROM/memory init as initial (aes sbox/rcon, ibex decoder). Dodged with memory_map — ROMs become logic, memories FF arrays, same fate synthesis gives them.
  4. Top inference fails with multiple root modules ("No top design was found"): SYNTH_WRAPPED_OPERATORS keeps unused adder-architecture variants in 1_2_yosys.v (ibex, mock-alu). No explicit-top option exists for verilog mode (only SV flists have --sv_design*_top). Dodged by using the OpenROAD-written netlist from 1_synth.odb as gate side (linking drops unused modules) — arguably better anyway: it also covers the ODB import and matches all later stages.
  5. Default (legacy) SEC engine is weak: inconclusive on uart at k=32 after 28 min; pdr proves the same check at k=1 in seconds. pdr is now the default for the pre-synthesis checks here.
  6. Multi-driver extraction skips most outputs on aes/ibex gold: aes proves "equivalence" at 0.78% checked-output coverage (128/129 outputs skipped: "design0 multi-driver connectivity: its iso has multiple drivers"); ibex 5.66% (skips trace to prefetch-buffer state cones). A PASS at 1% coverage is much weaker than a proof — lec_check now records the coverage line in the .status artifact next to the verdict. Root-causing the multi-driver extraction on the canonicalized gold is the top kepler-formal item this PR surfaces.
  7. X/Z lowering: unknown literal bits in continuous assigns are lowered as 0 with a warning — X-propagation differences are invisible to SEC.

OpenROAD built-in synth (_syn variant; pre-existing, not LEC bugs):
8. mock-alu: design SDC *io_out_REG* wildcard doesn't resolve after built-in synthesis (Error: Could not find *io_out_REG*) — register naming differs from yosys.
9. ibex: sv_elaborate fails ([ERROR SYN-0001] Elaboration failed, synth_syn.tcl:58).

Infrastructure fallout fixed along the way:

  • The new bazel-orfs validates sources= against variables.yaml and the LEC aggregates force-load every design package: declared IO_{NORTH,SOUTH,EAST,WEST}_PINS and ADDITIONAL_{FAST,SLOW,TYP}_LIBS in variables.yaml (real ORFS/platform variables that were missing); routed DESIGN_TYPE, BC/TC/WC_ADDITIONAL_LIB_FILES, VERILOG_FILES_BLACKBOX through user_arguments/user_sources/local_arguments in the affected design BUILDs; _emit_syn_variant now splits user/local config.mk vars like orfs_design does.
  • BCR sed failed to compile under hermetic-llvm (gnulib libc-header shadowing, BCR #7642); sed@4.9.bcr.5 carries the fix.
  • bazel-orfs load_json_file repository rule does not re-fetch when variables.yaml changes (repository_ctx.path without a read); needed bazelisk fetch --force. Upstream bazel-orfs bug.

¹ PASS with most outputs skipped by extraction limitations — see finding 6.
² ³ Built-in synth (_syn) fails before LEC runs — findings 8/9.
⁴ riscv32i's base yosys flow fails at the new bazel-orfs pin before any LEC: partitioned synthesis dies with per-module checkpoint missing: partition_magcompare2c_canonical.rtlil (parallel_synth.mk:31 do-yosys-partition) — bazel-orfs parallel-synth issue, independent of this PR's wiring.

🤖 Generated with Claude Code

oharboe and others added 3 commits May 22, 2026 10:02
Adds OpenROAD's integrated synthesizer (sv_elaborate + synthesize,
OpenROAD #10473) as a universal "_syn" variant of every flat
design driven by design() in flow/designs/design.bzl. Relocates
and generalises the throwaway smoke target from OpenROAD #10479,
which explicitly said the proper home for this was bazel-orfs /
ORFS, not OpenROAD's test tree.

Purely additive: no existing Makefile recipe, bazel rule, design,
or target's behaviour is altered. Pieces:

- flow/scripts/synth_syn.tcl (new) -- povik's driver. Reads
  LEF/Liberty/SDC via the ORFS env vars and writes 1_synth.odb +
  1_synth.sdc directly, bypassing the Yosys 1_2_yosys.v ->
  synth_odb.tcl chain.
- flow/Makefile gains one new phony target do-syn-synth that
  invokes openroad on synth_syn.tcl. No existing recipe touched.
- patches/bazel-orfs/0002-...patch adds a parallel
  orfs_openroad_synth_rule + orfs_openroad_synth macro in
  bazel-orfs. OrfsInfo shape matches orfs_synth_rule, so
  orfs_flow(previous_stage = {"floorplan": ":<name>_syn_synth"})
  chains downstream stages unchanged. Vendored here until the
  integrated syn tool stabilises and this lands upstream.
- flow/designs/design.bzl -- design() now also emits the _syn
  chain for every flat design via a DESIGNS lookup + helper.
  Hierarchical designs (blocks non-empty) are skipped -- the
  built-in synthesizer doesn't handle BLOCKS yet. All _syn
  targets are tagged manual so bazel build //... is unaffected.

End state for every flat design:

  bazelisk build //flow/designs/asap7/gcd:gcd_syn_synth   # OpenROAD synth
  bazelisk build //flow/designs/asap7/gcd:gcd_synth       # Yosys (unchanged)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Reformat with tclfmt 0.7.0 — normalize line endings, replace tab
indentation with two spaces, and add spaces inside the `if { ... }`
brace expression. Pure formatting; no behavior change. Fixes the
Tclint CI job on PR The-OpenROAD-Project#4253.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Build vIdirsArgs with `[list]` + `lappend` and let `{*}` expand it
directly into elaborate_args. The previous code joined the list into
a space-separated string and re-expanded it, which would corrupt any
include directory path containing whitespace.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request integrates OpenROAD's built-in synthesizer into the Bazel-ORFS flow by adding a new Makefile target, Starlark rules, and the synth_syn.tcl script. Feedback on the changes includes addressing potential Tcl errors from unchecked environment variables (DONT_USE_CELLS and SYNTH_SLANG_ARGS), fixing a case-sensitivity bug in Verilog file extension checks, replacing a hardcoded design check for cva6 with a generic port check, and correcting a Starlark style violation when comparing to None.

read_lef $lef
}
}
set_dont_use $::env(DONT_USE_CELLS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If DONT_USE_CELLS is not defined in the environment, referencing $::env(DONT_USE_CELLS) directly will throw a Tcl error and halt the synthesis process. It is safer to wrap this call in a check to ensure the environment variable exists and is non-empty.

if { [env_var_exists_and_non_empty DONT_USE_CELLS] } {
  set_dont_use $::env(DONT_USE_CELLS)
}

}
}

lappend elaborate_args {*}$::env(SYNTH_SLANG_ARGS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If SYNTH_SLANG_ARGS is not defined in the environment, referencing $::env(SYNTH_SLANG_ARGS) directly will throw a Tcl error. Using [env_var_or_empty SYNTH_SLANG_ARGS] is much safer and aligns with how other optional environment variables are handled in this script.

lappend elaborate_args {*}[env_var_or_empty SYNTH_SLANG_ARGS]

# If the sources are solely .v files, enable Verilog compatibility
set has_non_v_files false
foreach fn $::env(VERILOG_FILES) {
if { [file extension [string trim $fn]] != ".v" } {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If a Verilog file has an uppercase extension (e.g., .V), [file extension] will return .V. The comparison ".V" != ".v" will evaluate to true, incorrectly marking it as a non-v file and disabling the --std=1364-2005 flag. Converting the extension to lowercase using string tolower makes this check case-insensitive and more robust.

  if { [string tolower [file extension [string trim $fn]]] != ".v" } {

Comment on lines +61 to +63
if { $::env(DESIGN_NAME) == "cva6" } {
syn::remove_ports rvfi_probes_o
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Hardcoding design-specific checks (like cva6) in a generic synthesis script reduces maintainability and modularity. Instead of checking the design name, check if the port rvfi_probes_o exists in the design before attempting to remove it.

if { [get_ports -quiet rvfi_probes_o] != "" } {
  syn::remove_ports rvfi_probes_o
}

Comment thread flow/designs/design.bzl
does not pick them up while the OpenROAD synth tool (PR #10473)
matures.
"""
if entry == None or entry.get("blocks"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to PEP 8, comparisons to singletons like None should always be done with is or is not, never the equality operators.

    if entry is None or entry.get("blocks"):
References
  1. PEP 8: Comparisons to singletons like None should always be done with is or is not, never the equality operators. (link)

oharboe and others added 8 commits July 6, 2026 23:23
…dules

- tools/OpenROAD -> OpenROAD#10812 head (hermetic-llvm toolchain swap);
  ORFS root mirrors it: toolchains_llvm 20.1.8 -> BCR module llvm 0.8.11.
- Mirror tools/OpenROAD's root-only single_version_overrides (abc,
  bison, boost.icl, gawk, tcl_lang) plus m4/sed fix releases for the
  same gnulib libc-header class; override patches must live in the main
  repo, so they are copied to patches/openroad-deps/.
- Mirror the rules_pycross 3.13 environments workaround (root-honored
  only).
- bazelisk run @bazel-orfs//:bump: 3a5ddd7 -> 970ff81; drop patch 0001
  (landed upstream as bazel-orfs bfd3a1d).
- Pin kepler-formal (hermetic-llvm bazel build, keplertech main) via
  git_override and consume bazel-orfs's lec module as bazel-orfs-lec.
- Carry two new bazel-orfs patches: orfs_canon_verilog (pre-synthesis
  Verilog from the canonicalize RTLIL checkpoint) and the lec module
  expansion (build-time lec_check + instant lec_status_test + stage
  netlist extraction script).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
The bazel-orfs bump validates orfs_flow sources= against
variables.yaml and my LEC aggregates force-load every design package,
surfacing latent gaps:

- Declare IO_{NORTH,SOUTH,EAST,WEST}_PINS (ihp-sg13g2 pad.tcl) and
  ADDITIONAL_{FAST,SLOW,TYP}_LIBS (flow/Makefile corner libs) in
  variables.yaml; regenerate variables.json.
- gf180/aes{,-hybrid}: DESIGN_TYPE (private-PDK DRC hook) via
  user_arguments; BC/TC/WC_ADDITIONAL_LIB_FILES make helpers via
  local_arguments.
- microwatt, chameleon: VERILOG_FILES_BLACKBOX is source-typed, route
  through user_sources instead of local_arguments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Every design gets manual-tagged equivalence checks that run at build
time (cached lec_check actions) with instant verdict tests:

- <n>_lec_synth: canonicalized RTL (yosys canonicalize checkpoint ->
  <n>_canon_v) vs the yosys netlist, SEC via kepler-formal's
  pre-synthesis .v support. kepler-formal never parses raw
  (System)Verilog, so a failure implicates synthesis, not
  canonicalization.
- <n>_lec_<stage>: adjacent-pair gate-level LEC synth<->floorplan<->
  place<->cts<->route<->final on netlists written from each stage odb
  (physical-only cells removed; -hier for OPENROAD_HIERARCHICAL).
- <n>_syn_lec_synth (flat designs): OpenROAD built-in synth netlist vs
  the same canonicalized RTL.
- //flow:lec_check + //flow:lec_test aggregates; single-corner
  <pdk>_lec_libs liberty sets; README documents build-then-test and
  --jobs throttling.
- _emit_syn_variant: split user/local config.mk vars out of DESIGNS
  entries so variables.yaml validation only sees ORFS variables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
First real kepler-formal runs on gcd/asap7 surfaced two issues with
the canonicalized-RTL gold:

- format: verilog uses naja's structural netlist parser, which rejects
  behavioral constructs (reg declarations, always blocks). Add a
  format attr to lec_check and use sv2v for the pre-synthesis checks:
  gold goes through the SystemVerilog (slang) frontend, gate through
  the netlist parser.
- yosys write_verilog renders $pmux as a Verilog function, which
  naja's lowering rejects in continuous assigns. pmuxtree in
  orfs_canon_verilog lowers $pmux to plain mux trees first.

With these, gcd pre-synthesis SEC passes: 'No difference was found.
SEC proved equivalence at k = 3', 100% checked-output coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
The legacy engine was inconclusive on uart after 28 minutes at k=32;
pdr proves the same check at k=1 in seconds.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
yosys write_verilog emits memory/ROM init as 'initial' blocks, which
kepler-formal's naja lowering rejects (aes sbox/rcon ROMs, ibex
decoder table). memory_map lowers ROMs to logic and memories to FF
arrays — the same fate synthesis gives them — so the pre-synthesis
gold stays within the supported subset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
SYNTH_WRAPPED_OPERATORS keeps unused adder-architecture modules in the
yosys netlist, leaving kepler-formal's top inference with multiple
roots ('No top design was found' on ibex, mock-alu). The
OpenROAD-written netlist from 1_synth.odb has only the linked design,
also covers the ODB import, and matches every later stage's gate side.

With this, mock-alu pre-synthesis SEC passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
aes proved 'equivalence' with 0.78% output coverage (128/129 outputs
skipped as design0 multi-driver connectivity) — a PASS that skips most
outputs is much weaker than a full proof, so lec_check now records the
coverage line in the .status artifact and lec_status_test accepts the
annotated verdict.

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

oharboe commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@nanocoh @maliberty I asked Claude to take kepler-formal for a spin on ORFS.

@nanocoh To take this forward, someone has to slug through the results on the kepler-formal side, probably fix a few things in kepler-formal.

Also, there's pre-requisite work that needs to land like LLVM hermetic toolchain.

Closing for now, out of sight out of mind.

@oharboe oharboe closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant