Skip to content

flow: AUTO_MEMORIES generated memory macros via FakeRAM2.0 (experimental) - #4389

Merged
maliberty merged 6 commits into
The-OpenROAD-Project:masterfrom
oharboe:auto-memories
Aug 5, 2026
Merged

maliberty merged 6 commits into
The-OpenROAD-Project:masterfrom
oharboe:auto-memories

Conversation

@oharboe

@oharboe oharboe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR introduces pre-synthesis AUTO_MEMORIES support into ORFS by integrating FakeRAM2.0 as a Bazel dependency (git_override) carrying an isolated orfs_asap7 backend patch (//patches/fakeram:0001-Add-ORFS-ASAP7-backend.patch).

This PR supersedes #4367 by rearticulating memory macro generation around the dedicated FakeRAM2.0 repository instead of adding custom ASAP7 generator scripts directly into the ORFS tree.

Highlights & Architecture

  • FakeRAM 2.0 Integration: Added fakeram module override in MODULE.bazel pointing to base commit 6f62c655952b683cda679d80850cb557cc3c262e (The-OpenROAD-Project/FakeRAM2.0) and applying patches/fakeram/0001-Add-ORFS-ASAP7-backend.patch.
  • Refactored Driver: flow/scripts/memories/gen_memories.py now scans RTL, applies the idiomatic gate, dumps memories.json, and invokes FakeRAM2.0 via subprocess (--orfs_asap7_backend) to generate .lib, .lef, and blackboxes.txt.
  • Clean Separation: Internal LEF/Liberty generation logic is kept inside FakeRAM2.0, minimizing churn and keeping ORFS code minimal.
  • Testing: Updated unit tests run cleanly under Bazel (bazelisk test //flow:memories_tests).

Supersedes #4367

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces AUTO_MEMORIES, an experimental feature for the asap7 platform that automatically detects memory-shaped modules in Verilog RTL pre-synthesis and generates abstract .lib and .lef macro views using FakeRAM2.0. The changes include comprehensive documentation, Bazel build rules, a demo design configuration, Python scripts for scanning and evaluating memories, and integration with the Yosys synthesis flow. Feedback on the implementation highlights several robustness and cross-platform improvements: handling parameter lists in the Verilog port parser, wrapping the FakeRAM subprocess call in a try-except block to prevent raw tracebacks, catching OSError when reading user-supplied memory files, and stripping carriage returns when reading the blackbox list in Tcl to ensure Windows compatibility.

Comment thread flow/scripts/memories/detect.py Resolved
Comment thread flow/scripts/memories/gen_memories.py Resolved
Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/synth_preamble.tcl Resolved
@oharboe

oharboe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

@jeffng-or @maliberty The idea is to carry the FakeRAM2.0 patch here until churn is done so that ORFS+bazel can test test this new flow.

Once we know what is needed and we think it is ready, a FakeRAM2.0 PR can be articulated and this can be cleaned up.

We also regularly merge PRs with patches upstream and then clean out the patches as they land upstream, it all depends on what is practical in each case.

@oharboe
oharboe force-pushed the auto-memories branch 5 times, most recently from 5dd06ae to 0a439a6 Compare August 3, 2026 21:50
@oharboe

oharboe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

@oharboe

oharboe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

/gemini review

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the experimental AUTO_MEMORIES feature, which detects memory-shaped modules in RTL pre-synthesis and generates abstract .lib and .lef macro views for them using FakeRAM. It integrates this flow into the Makefile, Bazel build rules, and TCL scripts, while updating several design configurations and rules-base files. The review feedback highlights several robustness improvements: addressing a bug in schema.py where merging overrides could silently reset a memory's idiomatic status to False, making the Verilog parser in detect.py more resilient to whitespace, and replacing a fragile Tcl list conversion in synth_preamble.tcl with a safer regexp approach.

Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/memories/detect.py Resolved
Comment thread flow/scripts/memories/detect.py Resolved
Comment thread flow/scripts/synth_preamble.tcl Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces AUTO_MEMORIES, an experimental feature for the asap7 platform that automatically detects memory-shaped modules in RTL pre-synthesis, generates abstract .lib and .lef macro views for them using FakeRAM2.0, and blackboxes them during synthesis. The changes span documentation, Python detection and schema scripts, unit tests, Makefile/Bazel build rules, and Tcl integration. The review feedback is highly constructive, pointing out critical issues such as a merge override bug in schema.py that could silently reset idiomatic memories, a missing default fallback for FAKERAM_RUN_PY in gen_memories.py, and the need to support multi-corner analysis in read_liberty.tcl. Additionally, defensive type checks were recommended for JSON parsing to prevent cryptic runtime errors.

Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/memories/gen_memories.py Resolved
Comment thread flow/scripts/read_liberty.tcl Resolved
Comment thread flow/scripts/memories/schema.py Resolved
Comment thread flow/scripts/memories/schema.py Resolved
@oharboe
oharboe force-pushed the auto-memories branch 2 times, most recently from 2248398 to 4f1e11c Compare August 3, 2026 22:00
@oharboe
oharboe requested review from jeffng-or and maliberty August 3, 2026 22:01
Comment thread docs/user/FlowVariables.md Resolved
Comment thread flow/designs/asap7/tinyRocket/BUILD Resolved
Comment thread docs/user/AutoMemories.md Resolved
@oharboe

oharboe commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Replaced the ad-hoc Python regex scanner with Yosys's native memory inference pass (proc; memory -nomap; write_json). Memory detection now runs via a pre-synthesis Yosys pass (extract_memories.tcl) and extracts $mem_v2 primitives, resolved dimensions, write-enable bitmasks, and verifies clock net equivalence across ports.

@oharboe

oharboe commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed DCO signoff and cleaned up Python import linting nits.

@oharboe

oharboe commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Restored GRT_SEED in flow/scripts/variables.yaml, variables.json, and docs/user/FlowVariables.md.

@oharboe

oharboe commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Removed the raw Verilog regex scanner from detect.py. Memory detection now uses Yosys netlist JSON (`` cells) exclusively.

@oharboe
oharboe requested a review from maliberty August 4, 2026 05:13
@oharboe
oharboe requested a review from maliberty August 4, 2026 19:13
@oharboe

oharboe commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

I have updated the PR to address the remaining review comments:

  1. PDK Technology Decoupling: Moved all ASAP7-specific process and timing parameters out of the FakeRAM patch and into flow/platforms/asap7/fakeram.json.
  2. PDN / Minimum Height Parameter: Parameterized min_macro_height_um: 3.5 inside fakeram.json for PDN power stripe alignment and row grid snapping on ASAP7.
  3. PDK Injection: gen_memories.py now injects --tech_config into FakeRAM2.0 at runtime, keeping FakeRAM PDK-agnostic.
  4. CI / Submodules: AUTO_MEMORIES=1 works with standard Makefile flows (make DESIGN_CONFIG=designs/asap7/tinyRocket/config.mk). I'll leave adding FakeRAM2.0 submodules and hooking up the example project to Jenkins CI to the ORFS maintainers once patch churn settles.

All Bazel tests (bazelisk test //flow:memories_tests) are passing.

@oharboe
oharboe force-pushed the auto-memories branch 2 times, most recently from 753ec8e to 224d88b Compare August 4, 2026 19:16
@maliberty

Copy link
Copy Markdown
Member

fakeram has been moved over to ORFS so this PR needs updating

@oharboe

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

fakeram has been moved over to ORFS so this PR needs updating

Fixed

Comment thread tools/FakeRAM2.0/utils/class_process.py Outdated
self.snap_height_nm = (
int(json_data["snap_height_nm"]) if "snap_height_nm" in json_data else 1
)
self.min_macro_height_um = float(json_data.get("min_macro_height_um", 0.0))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this used for?

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.

IIRC I added it to account for cases where the number of pins required can't fit in the computed height. So, this is an option to "grow" the height so that the pins can fit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It enforces a minimum macro height, ensuring that generated memories meet specific PDK layout rules/minimum row heights (like the 3.5um limit in ASAP7), preventing invalid power grid routing. I have added a comment in the code to clarify this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this patch still relevant?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, we've deferred the bazel-orfs integration to avoid churn here. I'll upstream it to bazel-orfs once this is merged. I have removed the patch and the other bazel-related changes from this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

need to push?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correction: Yes, this patch is still relevant. We will complete the churn for bazel-orfs integration in this PR, and then upstream it to bazel-orfs once this is merged. I've restored the patch and related changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no changes to the PR since this statement

@oharboe

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@maliberty Any more FakeRAM asks today?

@maliberty

Copy link
Copy Markdown
Member

Missing DCO
│ b6cbfba │ Address review comments │
│ b554670 │ Restore bazel-orfs integration │
│ 921efca │ Fix Bazel query errors and remove redundant bazel-orfs patch

@oharboe

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Waiting for drive-by-fixes to be merged with master, then I'll merge this with master again to simplify.

oharboe added 5 commits August 5, 2026 20:47
…tal)

Detect memory-shaped modules (firtool R*/W*/RW*_ port convention) in the RTL before synthesis, inventory them in results/memories.json, and generate .lib/.lef macro views via FakeRAM2.0 for the ones idiomatic as SRAM macros.

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

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

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

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Missing DCO │ b6cbfba │ Address review comments │ │ b554670 │ Restore bazel-orfs integration │ │ 921efca │ Fix Bazel query errors and remove redundant bazel-orfs patch

fixed.

@maliberty
maliberty enabled auto-merge August 5, 2026 18:51
@oharboe

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

You set automerge, but there's a nit that needs to be fixed: trim verific.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
auto-merge was automatically disabled August 5, 2026 19:05

Head branch was pushed to by a user without write access

@oharboe

oharboe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@maliberty Fixed verific word that triggered a failure, please re-apply automerge.

@maliberty
maliberty enabled auto-merge August 5, 2026 20:24
@openroad-ci

openroad-ci commented Aug 5, 2026 •

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch. Advisory — results are log-only and do not affect build status. The authoritative QoR gate remains the local rules-file check.

Commit bbd7ed1 · Jenkins build #28 · Baseline: build

61 design(s) checked — 0 with regression(s), 7 without a comparable baseline.
Design Variant Verdict local vs inline passed / failed / missing
asap7/aes base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/aes-block base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/aes-mbff base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/aes_lvt base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/cva6 base ✅ pass ✅ MATCH 12 / 0 / 0
asap7/ethmac base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/ethmac_lvt base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/gcd base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/gcd-ccs base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/jpeg_lvt base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/mock-alu base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/mock-cpu base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/riscv32i base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/riscv32i-mock-sram base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/swerv_wrapper base ✅ pass ✅ MATCH 23 / 0 / 0
asap7/uart base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/aes base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/aes-hybrid base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/riscv32i base ✅ pass ✅ MATCH 23 / 0 / 0
gf180/uart-blocks base ✅ pass ✅ MATCH 23 / 0 / 0
gt2n/aes base ➖ inconclusive ➖ N/A 0 / 0 / 457
gt2n/gcd base ➖ inconclusive ➖ N/A 0 / 0 / 451
gt2n/jpeg base ➖ inconclusive ➖ N/A 0 / 0 / 456
ihp-sg13g2/aes base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/gcd base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/i2c-gpio-expander base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/riscv32i base ✅ pass ✅ MATCH 23 / 0 / 0
ihp-sg13g2/spi base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/aes base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/ariane133 base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/ariane136 base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/black_parrot — ➖ inconclusive ➖ N/A no reports directory — flow produced no output
nangate45/bp_be_top — ➖ inconclusive ➖ N/A no reports directory — flow produced no output
nangate45/bp_fe_top — ➖ inconclusive ➖ N/A no reports directory — flow produced no output
nangate45/bp_multi_top — ➖ inconclusive ➖ N/A no reports directory — flow produced no output
nangate45/dynamic_node base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/gcd base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/mempool_group base ✅ pass ✅ MATCH 12 / 0 / 0
nangate45/swerv base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/swerv_wrapper base ✅ pass ✅ MATCH 23 / 0 / 0
nangate45/tinyRocket base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/aes base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/chameleon base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/gcd base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/microwatt base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hd/riscv32i base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hs/aes base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hs/gcd base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hs/ibex base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hs/jpeg base ✅ pass ✅ MATCH 23 / 0 / 0
sky130hs/riscv32i base ✅ pass ✅ MATCH 23 / 0 / 0

@maliberty
maliberty merged commit e4daf84 into The-OpenROAD-Project:master Aug 5, 2026
7 of 8 checks passed
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.

4 participants