Skip to content

Commit 67a9db2

Browse files
committed
flow: AUTO_MEMORIES generated memory macros (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 for the ones idiomatic as SRAM macros. Synthesis blackboxes the converted modules so the liberty view wins over their behavioral bodies; floorplan through final read the generated views. ADDITIONAL_MEMORIES merges user-supplied .memories files onto the detected set, e.g. to force-convert a memory the idiomatic gate rejects. Together with RTL-MP macro placement this gives macro-based physical design results on an existing design without a memory compiler or hand-maintained fakeram files. asap7 only; the emitters are split into general structure and asap7 parameters as a first pass at separating PDK concerns. Banking and yosys/OpenROAD-SYN-based memory detection are documented as future work. The new designs/asap7/tinyRocket design demonstrates the flow end to end with no platform memory-mapping file and no checked-in fakerams; its tag_array forces conversion via a .memories override because the generic RTL has no behavioral fallback for it. Tested with `bazelisk test //flow:memories_tests` (detector, schema, idiomatic gate, and .lib/.lef emitter unit tests) and `make DESIGN_CONFIG=designs/asap7/tinyRocket/config.mk floorplan`. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f255c15 commit 67a9db2

30 files changed

Lines changed: 2461 additions & 13 deletions

‎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: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
## Variables
149+
150+
- [AUTO_MEMORIES](FlowVariables.md#AUTO_MEMORIES)
151+
- [ADDITIONAL_MEMORIES](FlowVariables.md#ADDITIONAL_MEMORIES)

‎docs/user/FlowVariables.md‎

Lines changed: 4 additions & 0 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.| |
@@ -339,6 +341,7 @@ configuration file.
339341
- [ABC_DRIVER_CELL](#ABC_DRIVER_CELL)
340342
- [ABC_LOAD_IN_FF](#ABC_LOAD_IN_FF)
341343
- [ADDER_MAP_FILE](#ADDER_MAP_FILE)
344+
- [ADDITIONAL_MEMORIES](#ADDITIONAL_MEMORIES)
342345
- [CACHED_REPORTS](#CACHED_REPORTS)
343346
- [CLKGATE_MAP_FILE](#CLKGATE_MAP_FILE)
344347
- [DFF_LIB_FILE](#DFF_LIB_FILE)
@@ -625,6 +628,7 @@ configuration file.
625628
- [ADDITIONAL_FILES](#ADDITIONAL_FILES)
626629
- [ADDITIONAL_LEFS](#ADDITIONAL_LEFS)
627630
- [ADDITIONAL_LIBS](#ADDITIONAL_LIBS)
631+
- [AUTO_MEMORIES](#AUTO_MEMORIES)
628632
- [BLOCKS](#BLOCKS)
629633
- [CAP_MARGIN](#CAP_MARGIN)
630634
- [CDL_FILES](#CDL_FILES)

‎flow/BUILD‎

Lines changed: 70 additions & 12 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.
@@ -31,23 +32,31 @@ exports_files(
3132
MAKEFILE_SHARED = [
3233
"scripts/variables.json",
3334
"scripts/*.py",
35+
"scripts/memories/*.py",
3436
"scripts/*.sh",
3537
"scripts/*.yaml",
3638
"scripts/*.mk",
3739
]
3840

41+
MAKEFILE_SHARED_EXCLUDE = [
42+
"scripts/memories/*_test.py",
43+
]
44+
3945
# makefile and scripts used by script/synth.sh steps
4046
filegroup(
4147
name = "makefile_yosys",
4248
srcs = ["Makefile"],
43-
data = glob(MAKEFILE_SHARED + [
44-
"scripts/*.script",
45-
"scripts/*.v",
46-
"scripts/util.tcl",
47-
"scripts/synth*.tcl",
48-
"scripts/synth*.v",
49-
"platforms/common/**/*.v",
50-
]) + [
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+
) + [
5160
"//flow/util:makefile_yosys",
5261
],
5362
visibility = ["//visibility:public"],
@@ -57,10 +66,13 @@ filegroup(
5766
filegroup(
5867
name = "makefile",
5968
srcs = ["Makefile"],
60-
data = glob(MAKEFILE_SHARED + [
61-
"scripts/*.tcl",
62-
"platforms/common/**/*.v",
63-
]) + [
69+
data = glob(
70+
MAKEFILE_SHARED + [
71+
"scripts/*.tcl",
72+
"platforms/common/**/*.v",
73+
],
74+
exclude = MAKEFILE_SHARED_EXCLUDE,
75+
) + [
6476
"//flow/util:makefile",
6577
],
6678
visibility = ["//visibility:public"],
@@ -173,3 +185,49 @@ filegroup(
173185
"sky130hd",
174186
"sky130hs",
175187
]]
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+
)
200+
201+
# Test fixtures (Verilog snippets) live in detect_test.py and are
202+
# imported by the other tests.
203+
py_library(
204+
name = "memories_test_fixtures",
205+
srcs = ["scripts/memories/detect_test.py"],
206+
imports = ["scripts/memories"],
207+
deps = [":memories"],
208+
)
209+
210+
MEMORIES_TESTS = [
211+
"detect_test",
212+
"gen_memories_test",
213+
"idiomatic_test",
214+
"lef_test",
215+
"liberty_test",
216+
"schema_test",
217+
"sram_area_model_test",
218+
]
219+
220+
[py_test(
221+
name = "memories_" + test,
222+
srcs = ["scripts/memories/{}.py".format(test)],
223+
main = "scripts/memories/{}.py".format(test),
224+
deps = [
225+
":memories",
226+
":memories_test_fixtures",
227+
],
228+
) for test in MEMORIES_TESTS]
229+
230+
test_suite(
231+
name = "memories_tests",
232+
tests = ["memories_" + test for test in MEMORIES_TESTS],
233+
)

‎flow/Makefile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ $(SDC_FILE_CLOCK_PERIOD): $(SDC_FILE)
261261
.PHONY: yosys-dependencies
262262
yosys-dependencies: $(YOSYS_DEPENDENCIES)
263263

264+
# AUTO_MEMORIES: detect memories in the RTL pre-synthesis and generate
265+
# .lib/.lef macro views for them. Experimental; see
266+
# docs/user/AutoMemories.md.
267+
ifeq ($(AUTO_MEMORIES),1)
268+
.PHONY: do-auto-memories
269+
do-auto-memories:
270+
mkdir -p $(RESULTS_DIR)
271+
$(PYTHON_EXE) $(SCRIPTS_DIR)/memories/gen_memories.py \
272+
--platform $(PLATFORM) \
273+
--out-dir $(RESULTS_DIR)/memories \
274+
--json $(RESULTS_DIR)/memories.json \
275+
$(foreach file,$(VERILOG_FILES),--verilog $(file)) \
276+
$(foreach file,$(ADDITIONAL_MEMORIES),--memories $(file))
277+
278+
$(RESULTS_DIR)/memories.json: $(VERILOG_FILES) $(ADDITIONAL_MEMORIES) \
279+
$(wildcard $(SCRIPTS_DIR)/memories/*.py)
280+
$(UNSET_AND_MAKE) do-auto-memories
281+
282+
yosys-dependencies: $(RESULTS_DIR)/memories.json
283+
$(RESULTS_DIR)/1_1_yosys_canonicalize.rtlil: $(RESULTS_DIR)/memories.json
284+
endif
285+
264286
.PHONY: do-yosys
265287
do-yosys: yosys-dependencies
266288
$(SCRIPTS_DIR)/synth.sh $(SYNTH_SCRIPT) $(LOG_DIR)/1_2_yosys.log
@@ -278,6 +300,7 @@ $(RESULTS_DIR)/1_2_yosys.v $(RESULTS_DIR)/1_2_yosys.sdc: $(RESULTS_DIR)/1_1_yosy
278300
.PHONY: clean_synth
279301
clean_synth:
280302
rm -f $(RESULTS_DIR)/1_* $(RESULTS_DIR)/mem*.json
303+
rm -rf $(RESULTS_DIR)/memories
281304
rm -f $(REPORTS_DIR)/synth_*
282305
rm -f $(LOG_DIR)/1_*
283306
rm -f $(SYNTH_STATS)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load("//flow/designs:design.bzl", "design")
2+
3+
design(config = "config.mk")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export DESIGN_NICKNAME = tinyRocket
2+
export DESIGN_NAME = RocketTile
3+
export PLATFORM = asap7
4+
5+
# The generic tinyRocket sources only: unlike the nangate45 tinyRocket
6+
# there is no hand-written platform memory-mapping file and no
7+
# checked-in fakeram .lib/.lef — AUTO_MEMORIES detects the memory
8+
# wrapper modules and generates macro views for them instead.
9+
export VERILOG_FILES = $(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/AsyncResetReg.v \
10+
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider2.v \
11+
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/ClockDivider3.v \
12+
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/plusarg_reader.v \
13+
$(DESIGN_HOME)/src/$(DESIGN_NICKNAME)/freechips.rocketchip.system.TinyConfig.v
14+
15+
export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/constraint.sdc
16+
17+
export AUTO_MEMORIES = 1
18+
# tag_array (4x25) falls below the idiomatic-macro floors, but this RTL
19+
# provides no behavioral fallback (the wrapper instantiates a
20+
# tag_array_ext module the sources never define), so its conversion is
21+
# forced via a .memories override.
22+
export ADDITIONAL_MEMORIES = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NICKNAME)/tag_array.memories
23+
24+
export CORE_UTILIZATION = 40
25+
export CORE_MARGIN = 2
26+
27+
export PLACE_DENSITY_LB_ADDON = 0.10
28+
export MACRO_PLACE_HALO = 2 2
29+
30+
export TNS_END_PERCENT = 100
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
current_design RocketTile
2+
3+
create_clock -name core_clock -period 1600 [get_ports {clock}]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"version": 1,
3+
"memories": [
4+
{
5+
"name": "tag_array",
6+
"idiomatic": true,
7+
"reason": "forced: the RTL provides no behavioral fallback for this wrapper"
8+
}
9+
]
10+
}

‎flow/designs/design.bzl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _GROUPS = {
1717
# cross-package references resolve. Kept tight on purpose: globbing "*"
1818
# silently exposes LICENSE/.gitignore/etc. as the public API surface.
1919
# gds/gds.gz are inputs in hierarchical flows via ADDITIONAL_GDS.
20-
_EXPORTED_EXTS = ["v", "sv", "svh", "tcl", "sdc", "def", "cfg", "lef", "lib", "gds", "gds.gz"]
20+
_EXPORTED_EXTS = ["v", "sv", "svh", "tcl", "sdc", "def", "cfg", "lef", "lib", "gds", "gds.gz", "memories"]
2121

2222
_EXPORTS_SENTINEL = "_orfs_design_exports_sentinel"
2323

0 commit comments

Comments
 (0)