|
| 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) |
0 commit comments