Skip to content

Commit 05c5c0d

Browse files
committed
flow: AUTO_MEMORIES generated memory macros via FakeRAM2.0 (experimental)
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>
1 parent ab244fc commit 05c5c0d

26 files changed

Lines changed: 1825 additions & 37 deletions

‎MODULE.bazel‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ bazel_dep(name = "bazel-orfs", version = "0.0.1")
101101

102102
bazel_dep(name = "bazel-orfs-verilog", dev_dependency = True)
103103

104-
BAZEL_ORFS_COMMIT = "3342596c1f7017b9fda5b4a55a25a54ff2aaedf8"
104+
BAZEL_ORFS_COMMIT = "6ebadeb4be5c9ada103081c9a5e668c014126616"
105105

106106
BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"
107107

@@ -131,6 +131,17 @@ git_override(
131131
remote = "https://github.com/povik/yosys-slang.git",
132132
)
133133

134+
bazel_dep(name = "fakeram", dev_dependency = True)
135+
git_override(
136+
module_name = "fakeram",
137+
commit = "6f62c655952b683cda679d80850cb557cc3c262e",
138+
patch_strip = 1,
139+
patches = [
140+
"//patches/fakeram:0001-Add-ORFS-ASAP7-backend.patch",
141+
],
142+
remote = "https://github.com/The-OpenROAD-Project/FakeRAM2.0.git",
143+
)
144+
134145
# --- Extensions ---
135146

136147
register_toolchains(

‎docs/toc.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ entries:
1919
title: Build Using WSL
2020
- file: user/FlowVariables.md
2121
title: Flow Variables
22+
- file: user/AutoMemories.md
23+
title: Generated Memory Macros (AUTO_MEMORIES)
2224
- file: contrib/Metrics.md
2325
title: Metrics
2426
- file: user/InstructionsForAutoTuner.md

‎docs/user/AutoMemories.md‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# AUTO_MEMORIES: generated memory macros
2+
3+
**Experimental.** AUTO_MEMORIES detects memories in a design's RTL
4+
before synthesis and generates abstract `.lib`/`.lef` macro views for
5+
them, so an existing design gets macro-based synthesis and physical
6+
design results — including RTL-MP macro placement — without a memory
7+
compiler or hand-maintained fakeram files.
8+
9+
The intended audience is flows built on top of ORFS (for example
10+
bazel-orfs based in-house flows) that need early, reasonable physical
11+
results on designs whose memories exist only as behavioral RTL. Support
12+
posture: if it works for you, great; if it needs fixing, the report is
13+
itself a welcome signal that someone is using it.
14+
15+
## What it does
16+
17+
With `AUTO_MEMORIES=1`, a pre-synthesis step runs
18+
`scripts/memories/gen_memories.py` over `VERILOG_FILES` and writes:
19+
20+
| File | Content |
21+
| --- | --- |
22+
| `$(RESULTS_DIR)/memories.json` | Inventory of every detected memory: geometry, full pin list with pin functions, behavioral model, and whether it was converted (`idiomatic`) with a reason. |
23+
| `$(RESULTS_DIR)/memories/<m>.lib` | Generated Liberty view per converted memory. |
24+
| `$(RESULTS_DIR)/memories/<m>_pre_layout.lib` | Ideal-clock (zero clock-tree insertion) variant for pre-CTS consumers that select lib files themselves. The Makefile flow uses `<m>.lib` throughout. |
25+
| `$(RESULTS_DIR)/memories/<m>.lef` | Abstract LEF per converted memory. |
26+
| `$(RESULTS_DIR)/memories/blackboxes.txt` | Names of the converted modules — what synthesis blackboxes. |
27+
28+
Synthesis (canonicalization) blackboxes the converted modules so the
29+
liberty view wins over their behavioral bodies; floorplan through final
30+
read the generated `.lib`/`.lef` alongside `ADDITIONAL_LIBS`/
31+
`ADDITIONAL_LEFS`. Everything downstream keys off the files above —
32+
nothing else passes between the generator and the flow. That file-based
33+
handoff is what lets build systems (e.g. bazel-orfs) declare the
34+
generated artifacts as ordinary stage outputs and transitive
35+
dependencies of the remaining stages.
36+
37+
Memories that are *not* converted stay in the netlist and synthesize to
38+
flip-flops, like any other RTL.
39+
40+
## How memories are detected
41+
42+
Detection is a fast Python scan (`scripts/memories/detect.py`) for
43+
modules whose entire port list follows the firtool (CIRCT) memory port
44+
convention: every port named `<R|W|RW><n>_<function>`, e.g. `R0_addr`,
45+
`W0_en`, `RW0_wdata`, including the subword-split forms `RW0_wdata_3` /
46+
`W0_mask_2`. This is what Chisel/firtool emits for module-separated
47+
memories, and what the rocket-chip generation of Chisel emitted (the
48+
in-tree tinyRocket design).
49+
50+
Two consequences, documented as deliberate scope:
51+
52+
- **Module boundary only.** A memory embedded inside a larger module
53+
(a bare `reg [7:0] mem [0:255]` next to other logic) is not detected.
54+
Yosys's memory-inference pass sees those; FPGA tools extract them
55+
into block RAMs. Wiring yosys up as the detector — or growing such a
56+
pass in OpenROAD SYN, which currently has no memory inference and
57+
therefore cannot be leaned on here either — is future work; this
58+
feature punts on it with the simple scanner.
59+
- **No banking.** Each detected memory maps to exactly one macro. A
60+
memory too wide, too deep, or too ported for a single sensible macro
61+
is not decomposed across several macros — a future extension.
62+
63+
## The idiomatic gate
64+
65+
Not every detected memory should be a macro. `scripts/memories/
66+
idiomatic.py` applies simple floors (minimum depth 16, minimum capacity
67+
256 bits, at most 4 ports); memories below them are cheaper as
68+
flip-flops than as a macro paying the fixed control/decode/sense-amp
69+
floor. Rejected memories are kept in `memories.json` with
70+
`"idiomatic": false` and a reason.
71+
72+
To overrule the gate, list a `.memories` file in `ADDITIONAL_MEMORIES`:
73+
74+
```json
75+
{
76+
"version": 1,
77+
"memories": [
78+
{
79+
"name": "tag_array",
80+
"idiomatic": true,
81+
"reason": "forced: the RTL provides no behavioral fallback"
82+
}
83+
]
84+
}
85+
```
86+
87+
Entries merge by name onto the detected set: fields the override
88+
carries win, everything else (geometry, pins) is kept from detection. A
89+
`.memories` entry naming a module the scanner never found is taken
90+
whole — it must then describe its pins itself. The
91+
`designs/asap7/tinyRocket` design demonstrates the forced-conversion
92+
case: its `tag_array` wrapper is 4 entries deep (rejected by the gate)
93+
but instantiates a module the sources never define, so flops are not an
94+
option and the design forces conversion.
95+
96+
## Generated views
97+
98+
The `.lib` mirrors the structural shape OpenROAD's abstract writer
99+
produces for hardened blocks: `bus()` groups **with per-bit `pin()`
100+
records** (a bus without per-bit siblings makes yosys silently drop bit
101+
connections at parent instances), per-port clock pins with
102+
`min/max_clock_tree_path` arcs, setup/hold constraints on inputs,
103+
clock-to-out arcs on outputs, and `internal_power()` records under a
104+
`power_lut_template` so SAIF-driven power reporting is non-zero.
105+
106+
The `.lef` is an abstract following the conventions of the platform's
107+
fakeram abstracts: `CLASS BLOCK`, per-bit signal pin pads stacked along
108+
the macro edge, interleaved horizontal power/ground straps the
109+
platform's PDN macro grid connects to, and a full-footprint multi-layer
110+
`OBS`.
111+
112+
Timing and area come from simple parametric models
113+
(`scripts/memories/liberty.py`, `scripts/memories/sram_area_model.py`):
114+
log2(rows) decode depth and √bits bit-line scaling for timing; an area
115+
model anchored to published 7 nm SP-SRAM figures (Suzuki et al., ISSCC
116+
2018). These are budgetary models — good enough to make floorplanning,
117+
placement, and timing behave representatively; not sign-off numbers.
118+
119+
## Platform support
120+
121+
**asap7 only.** The emitters are split into general structure
122+
(`liberty.py`, `lef.py`, parameterized by a `PdkParams`) and platform
123+
constants (`pdk_asap7.py`: pins and power straps on M4 — where the
124+
platform's PDN macro grid connects — pin pad/pitch, strap geometry,
125+
OBS layers, nominal voltage). Generalizing to other PDKs means
126+
providing their `PdkParams` — the code seam exists, the calibration
127+
work does not. `AUTO_MEMORIES=1` on any other platform fails with a
128+
clear error.
129+
130+
## Trying it
131+
132+
```shell
133+
# Unit tests (fast, no EDA tools):
134+
bazelisk test //flow:memories_tests
135+
136+
# The demo design:
137+
make DESIGN_CONFIG=designs/asap7/tinyRocket/config.mk synth floorplan
138+
```
139+
140+
The generator can also be run standalone to inspect what it would do:
141+
142+
```shell
143+
python3 flow/scripts/memories/gen_memories.py \
144+
--platform asap7 --out-dir /tmp/mems --json /tmp/memories.json \
145+
--verilog flow/designs/src/tinyRocket/freechips.rocketchip.system.TinyConfig.v
146+
```
147+
148+
## Consuming from bazel-orfs
149+
150+
Everything downstream keys off generated files, so a build system can
151+
declare them as ordinary stage outputs and transitive dependencies. In
152+
bazel-orfs each stage runs in a sandbox where only declared outputs
153+
survive, so it additionally needs to declare `memories.json` plus the
154+
`memories/` directory (a directory artifact — the per-memory file
155+
names are only known at run time) as canonicalize outputs and stage
156+
them into every downstream stage's sandbox. The bazel-orfs change that
157+
does this is carried alongside this feature as
158+
`flow/scripts/memories/bazel-orfs-auto-memories.patch`, to be
159+
upstreamed to bazel-orfs once the feature lands here.
160+
161+
## Variables
162+
163+
- [AUTO_MEMORIES](FlowVariables.md#AUTO_MEMORIES)
164+
- [ADDITIONAL_MEMORIES](FlowVariables.md#ADDITIONAL_MEMORIES)

‎docs/user/FlowVariables.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ configuration file.
100100
| <a name="ADDITIONAL_GDS"></a>ADDITIONAL_GDS| Hardened macro GDS files listed here.| |
101101
| <a name="ADDITIONAL_LEFS"></a>ADDITIONAL_LEFS| Hardened macro LEF view files listed here. The LEF information of the macros is immutable and used throughout all stages. Stored in the .odb file.| |
102102
| <a name="ADDITIONAL_LIBS"></a>ADDITIONAL_LIBS| Hardened macro library files listed here. The library information is immutable and used throughout all stages. Not stored in the .odb file.| |
103+
| <a name="ADDITIONAL_MEMORIES"></a>ADDITIONAL_MEMORIES| Experimental. Space-separated list of user-supplied `.memories` files (the memories.json JSON schema) merged onto the set AUTO_MEMORIES detects — to force-convert a memory the idiomatic gate rejects, or to describe one the scanner cannot find. See docs/user/AutoMemories.md.| |
103104
| <a name="ADDITIONAL_SITES"></a>ADDITIONAL_SITES| Passed as -additional_sites to initialize_floorplan.| |
104105
| <a name="ASAP7_USE_VT"></a>ASAP7_USE_VT| A space separated list of VT options to use with the ASAP7 standard cell library: RVT, LVT, SLVT.| RVT|
106+
| <a name="AUTO_MEMORIES"></a>AUTO_MEMORIES| Experimental. When set to 1, memory-shaped modules in the RTL (firtool/CIRCT `R*/W*/RW*_` port convention, module boundary only) are detected pre-synthesis, inventoried in `$(RESULTS_DIR)/memories.json`, and — when idiomatic as an SRAM macro — given generated .lib/.lef views under `$(RESULTS_DIR)/memories/`. Synthesis blackboxes those modules and all later stages read the generated views, so an existing design gets macro-based results without a memory compiler. Supported for the asap7 platform only. See docs/user/AutoMemories.md.| 0|
105107
| <a name="BALANCE_ROWS"></a>BALANCE_ROWS| Balance rows during placement.| 0|
106108
| <a name="BLOCKS"></a>BLOCKS| Blocks used as hard macros in a hierarchical flow. Do note that you have to specify block-specific inputs file in the directory mentioned by Makefile.| |
107109
| <a name="BUFFER_PORTS_ARGS"></a>BUFFER_PORTS_ARGS| Specify arguments to the buffer_ports call during placement. Only used if DONT_BUFFER_PORTS=0.| |
@@ -163,7 +165,6 @@ configuration file.
163165
| <a name="GPL_RANDOM_SEED"></a>GPL_RANDOM_SEED| Specifies a random seed for global placement. Useful for perturbation studies.| |
164166
| <a name="GPL_ROUTABILITY_DRIVEN"></a>GPL_ROUTABILITY_DRIVEN| Specifies whether the placer should use routability driven placement.| 1|
165167
| <a name="GPL_TIMING_DRIVEN"></a>GPL_TIMING_DRIVEN| Specifies whether the placer should use timing driven placement.| 1|
166-
| <a name="GRT_SEED"></a>GRT_SEED| Specifies a random seed for global routing. Useful for perturbation studies.| |
167168
| <a name="GUI_TIMING"></a>GUI_TIMING| Load timing information when opening GUI. For large designs, this can be quite time consuming. Useful to disable when investigating non-timing aspects like floorplan, placement, routing, etc.| 1|
168169
| <a name="HOLD_SLACK_MARGIN"></a>HOLD_SLACK_MARGIN| Specifies a time margin for the slack when fixing hold violations. This option allows you to overfix or underfix (negative value, terminate retiming before 0 or positive slack). floorplan.tcl uses min of HOLD_SLACK_MARGIN and 0 (default hold slack margin). This avoids overrepair in floorplan for hold by default, but allows skipping hold repair using a negative HOLD_SLACK_MARGIN. Exiting timing repair early is useful in exploration where the .sdc has a fixed clock period at the design's target clock period and where HOLD/SETUP_SLACK_MARGIN is used to avoid overrepair (extremely long running times) when exploring different parameter settings. When an ideal clock is used, that is before CTS, a clock insertion delay of 0 is used in timing paths. This creates a mismatch between macros that have a .lib file from after CTS, when the clock is propagated. To mitigate this, OpenSTA will use subtract the clock insertion delay of macros when calculating timing with ideal clock. Provided that min_clock_tree_path and max_clock_tree_path are in the .lib file, which is the case for macros built with OpenROAD. This is less accurate than if OpenROAD had created a placeholder clock tree for timing estimation purposes prior to CTS. There will inevitably be inaccuracies in the timing calculation prior to CTS. Use a slack margin that is low enough, even negative, to avoid overrepair. Inaccuracies in the timing prior to CTS can also lead to underrepair, but there no obvious and simple way to avoid underrapir in these cases. Overrepair can lead to excessive runtimes in repair or too much buffering being added, which can present itself as congestion of hold cells or buffer cells. Another use of SETUP/HOLD_SLACK_MARGIN is design parameter exploration when trying to find the minimum clock period for a design. The SDC_FILE for a design can be quite complicated and instead of modifying the clock period in the SDC_FILE, which can be non-trivial, the clock period can be fixed at the target frequency and the SETUP/HOLD_SLACK_MARGIN can be swept to find a plausible current minimum clock period.| 0|
169170
| <a name="IO_CONSTRAINTS"></a>IO_CONSTRAINTS| File path to the IO constraints .tcl file. Also used for manual placement.| |
@@ -340,6 +341,7 @@ configuration file.
340341
- [ABC_DRIVER_CELL](#ABC_DRIVER_CELL)
341342
- [ABC_LOAD_IN_FF](#ABC_LOAD_IN_FF)
342343
- [ADDER_MAP_FILE](#ADDER_MAP_FILE)
344+
- [ADDITIONAL_MEMORIES](#ADDITIONAL_MEMORIES)
343345
- [CACHED_REPORTS](#CACHED_REPORTS)
344346
- [CLKGATE_MAP_FILE](#CLKGATE_MAP_FILE)
345347
- [DFF_LIB_FILE](#DFF_LIB_FILE)
@@ -535,7 +537,6 @@ configuration file.
535537
- [ENABLE_RESISTANCE_AWARE](#ENABLE_RESISTANCE_AWARE)
536538
- [GLOBAL_ROUTE_ARGS](#GLOBAL_ROUTE_ARGS)
537539
- [GLOBAL_ROUTE_USE_CUGR](#GLOBAL_ROUTE_USE_CUGR)
538-
- [GRT_SEED](#GRT_SEED)
539540
- [HOLD_SLACK_MARGIN](#HOLD_SLACK_MARGIN)
540541
- [MAX_REPAIR_ANTENNAS_ITER_GRT](#MAX_REPAIR_ANTENNAS_ITER_GRT)
541542
- [MAX_ROUTING_LAYER](#MAX_ROUTING_LAYER)
@@ -627,6 +628,7 @@ configuration file.
627628
- [ADDITIONAL_FILES](#ADDITIONAL_FILES)
628629
- [ADDITIONAL_LEFS](#ADDITIONAL_LEFS)
629630
- [ADDITIONAL_LIBS](#ADDITIONAL_LIBS)
631+
- [AUTO_MEMORIES](#AUTO_MEMORIES)
630632
- [BLOCKS](#BLOCKS)
631633
- [CAP_MARGIN](#CAP_MARGIN)
632634
- [CDL_FILES](#CDL_FILES)

‎flow/BUILD‎

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel-orfs//:openroad.bzl", "orfs_pdk")
2+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
23

34
# Expose every individual file under platforms/ as a public source-file
45
# target, so designs in other packages can refer to e.g.
@@ -23,37 +24,39 @@ exports_files(
2324
# instead of vendoring its own (drifting) copy at the bazel-orfs repo
2425
# root. See bazel-orfs `private/rules.bzl`.
2526
exports_files(
26-
[
27-
"scripts/synth.tcl",
28-
# Expose variables.yaml as an addressable source label so the
29-
# orfs-vars MCP server (//tools/orfs_mcp) can data-dep the ORFS
30-
# variable catalogue pinned to this commit.
31-
"scripts/variables.yaml",
32-
],
27+
["scripts/synth.tcl"],
3328
visibility = ["//visibility:public"],
3429
)
3530

3631
# files shared between scripts/synth.sh and scripts/flow.sh steps
3732
MAKEFILE_SHARED = [
3833
"scripts/variables.json",
3934
"scripts/*.py",
35+
"scripts/memories/*.py",
4036
"scripts/*.sh",
4137
"scripts/*.yaml",
4238
"scripts/*.mk",
4339
]
4440

41+
MAKEFILE_SHARED_EXCLUDE = [
42+
"scripts/memories/*_test.py",
43+
]
44+
4545
# makefile and scripts used by script/synth.sh steps
4646
filegroup(
4747
name = "makefile_yosys",
4848
srcs = ["Makefile"],
49-
data = glob(MAKEFILE_SHARED + [
50-
"scripts/*.script",
51-
"scripts/*.v",
52-
"scripts/util.tcl",
53-
"scripts/synth*.tcl",
54-
"scripts/synth*.v",
55-
"platforms/common/**/*.v",
56-
]) + [
49+
data = glob(
50+
MAKEFILE_SHARED + [
51+
"scripts/*.script",
52+
"scripts/*.v",
53+
"scripts/util.tcl",
54+
"scripts/synth*.tcl",
55+
"scripts/synth*.v",
56+
"platforms/common/**/*.v",
57+
],
58+
exclude = MAKEFILE_SHARED_EXCLUDE,
59+
) + [
5760
"//flow/util:makefile_yosys",
5861
],
5962
visibility = ["//visibility:public"],
@@ -63,10 +66,13 @@ filegroup(
6366
filegroup(
6467
name = "makefile",
6568
srcs = ["Makefile"],
66-
data = glob(MAKEFILE_SHARED + [
67-
"scripts/*.tcl",
68-
"platforms/common/**/*.v",
69-
]) + [
69+
data = glob(
70+
MAKEFILE_SHARED + [
71+
"scripts/*.tcl",
72+
"platforms/common/**/*.v",
73+
],
74+
exclude = MAKEFILE_SHARED_EXCLUDE,
75+
) + [
7076
"//flow/util:makefile",
7177
],
7278
visibility = ["//visibility:public"],
@@ -179,3 +185,47 @@ filegroup(
179185
"sky130hd",
180186
"sky130hs",
181187
]]
188+
189+
# AUTO_MEMORIES: pre-synthesis memory detection and .lib/.lef macro view
190+
# generation. See docs/user/AutoMemories.md. The unit tests are the
191+
# feature's test coverage — run with `bazelisk test //flow:memories_tests`.
192+
py_library(
193+
name = "memories",
194+
srcs = glob(
195+
["scripts/memories/*.py"],
196+
exclude = ["scripts/memories/*_test.py"],
197+
),
198+
imports = ["scripts/memories"],
199+
data = ["@fakeram//:all_files"],
200+
)
201+
202+
# Test fixtures (Verilog snippets) live in detect_test.py and are
203+
# imported by the other tests.
204+
py_library(
205+
name = "memories_test_fixtures",
206+
srcs = ["scripts/memories/detect_test.py"],
207+
imports = ["scripts/memories"],
208+
deps = [":memories"],
209+
)
210+
211+
MEMORIES_TESTS = [
212+
"detect_test",
213+
"gen_memories_test",
214+
"idiomatic_test",
215+
"schema_test",
216+
]
217+
218+
[py_test(
219+
name = "memories_" + test,
220+
srcs = ["scripts/memories/{}.py".format(test)],
221+
main = "scripts/memories/{}.py".format(test),
222+
deps = [
223+
":memories",
224+
":memories_test_fixtures",
225+
],
226+
) for test in MEMORIES_TESTS]
227+
228+
test_suite(
229+
name = "memories_tests",
230+
tests = ["memories_" + test for test in MEMORIES_TESTS],
231+
)

0 commit comments

Comments
 (0)