Skip to content

Commit 2ba1223

Browse files
authored
Merge pull request #4824 from oharboe/auto-memories-dir
flow: AUTO_MEMORIES_DIR, where AUTO_MEMORIES' views are written and read
2 parents 8f8a87d + 4cbf6bf commit 2ba1223

11 files changed

Lines changed: 69 additions & 34 deletions

File tree

‎docs/user/AutoMemories.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ flow. That file-based handoff is what lets build systems (e.g.
3838
bazel-orfs) declare the generated artifacts as ordinary stage outputs
3939
and transitive dependencies of the remaining stages.
4040

41+
Synthesis writes the views and lists to its own
42+
`$(RESULTS_DIR)/memories`. Every step reads them from
43+
`AUTO_MEMORIES_DIR`, synthesis included, which defaults to that
44+
directory; with make, leave it there. `AUTO_MEMORIES_DIR` is for a build
45+
system that runs a stage of one variant on another variant's synthesis
46+
(e.g. bazel-orfs): it sets it for each step it runs, synthesis included,
47+
to the memories of the variant that synthesised them.
48+
4149
Memories that are *not* converted stay in the netlist and synthesize to
4250
flip-flops, like any other RTL.
4351

‎docs/user/FlowVariables.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ configuration file.
104104
| <a name="ADDITIONAL_SITES"></a>ADDITIONAL_SITES| Passed as -additional_sites to initialize_floorplan.| |
105105
| <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|
106106
| <a name="AUTO_MEMORIES"></a>AUTO_MEMORIES| Experimental. When set to 1, memories that yosys infers in the RTL (`$mem_v2` cells, 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|
107+
| <a name="AUTO_MEMORIES_DIR"></a>AUTO_MEMORIES_DIR| Directory every step reads AUTO_MEMORIES' generated views and lists from, synthesis included. Synthesis writes them to its own $(RESULTS_DIR)/memories, the default; with make, leave it there. For a build system that runs a stage of one variant on another variant's synthesis (e.g. bazel-orfs), which sets it for each step it runs, synthesis included, to the memories of the variant that synthesised them. Like AUTO_MEMORIES, not tied to stages: every step that reads the views needs it, the abstract among them.| |
107108
| <a name="AUTO_MEMORIES_MACRO_PLACE"></a>AUTO_MEMORIES_MACRO_PLACE| Experimental. Space-separated list of module names of AUTO_MEMORIES_REGFILES register files to place as macros, blackboxed in synthesis and placed by the macro placer (and, in `mode netlist`, dissolved after macro placement). A register file not listed is inlined: its generated netlist of standard cells replaces the module's body in synthesis, and its cells are placed, sized and buffered with the rest of the design -- the better shape for a small design, where a macro's outline and channels cost more core than the array saves. A name no spec builds stops the build. Requires AUTO_MEMORIES=1.| |
108109
| <a name="AUTO_MEMORIES_REGFILES"></a>AUTO_MEMORIES_REGFILES| Experimental. Space-separated list of register-file spec files, one per RTL module to build as a register file of placed standard cells rather than synthesise to flops. Each spec names its module, words, bits, read and write ports by the RTL's own port names, and the cells. memories/regfile_ram.py checks the spec against the module's ports and has OpenROAD's generate_ram build it as `<module>_ram`, under `$(RESULTS_DIR)/memories/`, with a wrapper in the module's place. A module named in AUTO_MEMORIES_MACRO_PLACE is blackboxed like an AUTO_MEMORIES macro and placed as one; any other is inlined as its generated netlist. A placed spec in `mode netlist` then dissolves into its cells after macro placement: its core FIRM where the macro was placed, in the macro's orientation, its periphery left to placement. Every register file appears in memories.json with kind `regfile`. Requires AUTO_MEMORIES=1.| |
109110
| <a name="BALANCE_ROWS"></a>BALANCE_ROWS| Balance rows during placement.| 0|
@@ -152,7 +153,7 @@ configuration file.
152153
| <a name="FILL_CELLS"></a>FILL_CELLS| Fill cells are used to fill empty sites. If not set or empty, fill cell insertion is skipped.| |
153154
| <a name="FILL_CONFIG"></a>FILL_CONFIG| JSON rule file for metal fill during chip finishing.| |
154155
| <a name="FLOORPLAN_DEF"></a>FLOORPLAN_DEF| Use the DEF file to initialize floorplan. Mutually exclusive with FOOTPRINT or DIE_AREA/CORE_AREA or CORE_UTILIZATION.| |
155-
| <a name="FLOW_INPUT_VARIANT"></a>FLOW_INPUT_VARIANT| Flow variant a stage reads the previous stage's result from, the .odb and the .sdc beside it. Defaults to FLOW_VARIANT. A variant forked off another sets it to that variant for the first stage it runs, then leaves it at the default: the shared stages run once, and the fork writes only its own results. A stage's later steps read the stage's own results. A stage stops when its input is in both variants. Not with AUTO_MEMORIES=1, whose memories are read from the variant that synthesised them.| |
156+
| <a name="FLOW_INPUT_VARIANT"></a>FLOW_INPUT_VARIANT| Flow variant a stage reads the previous stage's result from, the .odb and the .sdc beside it. Defaults to FLOW_VARIANT. A variant forked off another sets it to that variant for the first stage it runs, then leaves it at the default: the shared stages run once, and the fork writes only its own results. A stage's later steps read the stage's own results. A stage stops when its input is in both variants. With AUTO_MEMORIES=1, AUTO_MEMORIES_DIR names the memories of the variant that synthesised them, for every stage the fork runs.| |
156157
| <a name="FLOW_VARIANT"></a>FLOW_VARIANT| Flow variant to use, used in the flow variant directory name.| base|
157158
| <a name="FOOTPRINT"></a>FOOTPRINT| Custom footprint definition file for ICeWall-based floorplan initialization. Mutually exclusive with FLOORPLAN_DEF or DIE_AREA/CORE_AREA or CORE_UTILIZATION.| |
158159
| <a name="FOOTPRINT_TCL"></a>FOOTPRINT_TCL| Specifies a Tcl script with custom footprint-related commands for floorplan setup.| |
@@ -687,6 +688,7 @@ configuration file.
687688
- [ADDITIONAL_LEFS](#ADDITIONAL_LEFS)
688689
- [ADDITIONAL_LIBS](#ADDITIONAL_LIBS)
689690
- [AUTO_MEMORIES](#AUTO_MEMORIES)
691+
- [AUTO_MEMORIES_DIR](#AUTO_MEMORIES_DIR)
690692
- [CAP_MARGIN](#CAP_MARGIN)
691693
- [CDL_FILES](#CDL_FILES)
692694
- [CORNER](#CORNER)

‎flow/Makefile‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ do-klayout:
205205
--output $(OBJECTS_DIR)/klayout.lyt \
206206
--lef-files $(OBJECTS_DIR)/klayout_tech.lef $(SC_LEF) $(ADDITIONAL_LEFS) \
207207
--map-files $(wildcard $(FLOW_HOME)/platforms/$(PLATFORM)/*map) \
208-
$(if $(filter 1,$(AUTO_MEMORIES)),--blackboxes $(RESULTS_DIR)/memories/blackboxes.txt)
208+
$(if $(filter 1,$(AUTO_MEMORIES)),--blackboxes $(AUTO_MEMORIES_DIR)/blackboxes.txt)
209209

210210
$(OBJECTS_DIR)/klayout_wrap.lyt: $(KLAYOUT_TECH_FILE) $(OBJECTS_DIR)/klayout_tech.lef
211211
$(UNSET_AND_MAKE) do-klayout_wrap
@@ -284,9 +284,13 @@ $(RESULTS_DIR)/memories.json: $(RESULTS_DIR)/memories_inferred.json $(ADDITIONAL
284284

285285
yosys-dependencies: $(RESULTS_DIR)/memories.json
286286
$(RESULTS_DIR)/1_1_yosys_canonicalize.rtlil: $(RESULTS_DIR)/memories.json
287+
$(RESULTS_DIR)/memories/blackboxes.txt: $(RESULTS_DIR)/memories.json ;
287288
# The generated LEFs are part of the KLayout technology the GDS merge
288-
# reads the final DEF with.
289-
$(OBJECTS_DIR)/klayout.lyt: $(RESULTS_DIR)/memories.json
289+
# reads the final DEF with. Synthesis writes its own memories;
290+
# AUTO_MEMORIES_DIR is where the stages after it read them, as
291+
# INPUT_RESULTS_DIR is where a stage reads its input, and another
292+
# variant's blackboxes.txt has no rule here.
293+
$(OBJECTS_DIR)/klayout.lyt: $(AUTO_MEMORIES_DIR)/blackboxes.txt
290294
endif
291295

292296
# OpenROAD stages read binary liberty (.blib) files from a cache shared by

‎flow/scripts/load.tcl‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ proc load_design { design_file } {
1111
# variant FLOW_INPUT_VARIANT names.
1212
proc load_stage_input { design_file } {
1313
if { $::env(INPUT_RESULTS_DIR) ne $::env(RESULTS_DIR) } {
14-
if { $::env(AUTO_MEMORIES) } {
15-
error "AUTO_MEMORIES=1 reads the memories synthesised in this variant,\
16-
$::env(FLOW_VARIANT), and FLOW_INPUT_VARIANT=$::env(FLOW_INPUT_VARIANT)\
17-
reads the design from another"
14+
if {
15+
$::env(AUTO_MEMORIES)
16+
&& [file normalize $::env(AUTO_MEMORIES_DIR)]
17+
eq [file normalize $::env(RESULTS_DIR)/memories]
18+
} {
19+
error "AUTO_MEMORIES=1 reads the memories from AUTO_MEMORIES_DIR, this\
20+
variant's, $::env(FLOW_VARIANT), and FLOW_INPUT_VARIANT=$::env(FLOW_INPUT_VARIANT)\
21+
reads the design from another. Set AUTO_MEMORIES_DIR to the memories of\
22+
the variant that synthesised them, for every stage the variant runs."
1823
}
1924
if { [file exists $::env(RESULTS_DIR)/$design_file] } {
2025
error "$design_file is in both FLOW_VARIANT=$::env(FLOW_VARIANT) and\

‎flow/scripts/regfile_dissolve.tcl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ if { [llength $regfile_modules] > 0 } {
9999
utl::info FLW 9 "register file $module: no instance in the design (removed as dead logic)"
100100
continue
101101
}
102-
set cells [regfile_netlist "$::env(RESULTS_DIR)/memories/$module.v"]
103-
set place [regfile_place_file "$::env(RESULTS_DIR)/memories/$module.place"]
102+
set cells [regfile_netlist "$::env(AUTO_MEMORIES_DIR)/$module.v"]
103+
set place [regfile_place_file "$::env(AUTO_MEMORIES_DIR)/$module.place"]
104104
foreach macro $macros {
105105
set path [$macro getName]
106106
set parent [$macro getModule]

‎flow/scripts/synth_preamble.tcl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ proc read_auto_memories_inline { } {
6060
foreach {- name} [regexp -all -inline -- {parameter \\(\S+)} $dump] {
6161
setparam -unset $name t:$m
6262
}
63-
read_verilog -overwrite "$::env(RESULTS_DIR)/memories/$m.v"
63+
read_verilog -overwrite "$::env(AUTO_MEMORIES_DIR)/$m.v"
6464
}
6565
}
6666

‎flow/scripts/util.tcl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,15 @@ proc env_var_exists_and_non_empty { env_var } {
115115
# AUTO_MEMORIES: do-auto-memories writes into $RESULTS_DIR/memories the
116116
# lists below, and every later step reads the files they name, never
117117
# what a directory happens to hold. gen_memories.py writes each list
118-
# whole, after every view exists.
118+
# whole, after every view exists. Every step reads them from
119+
# AUTO_MEMORIES_DIR, synthesis included.
119120

120121
# The words of one of those lists; none without AUTO_MEMORIES.
121122
proc auto_memories_words { list } {
122123
if { ![env_var_equals AUTO_MEMORIES 1] } {
123124
return {}
124125
}
125-
set fh [open "$::env(RESULTS_DIR)/memories/$list" r]
126+
set fh [open "$::env(AUTO_MEMORIES_DIR)/$list" r]
126127
set content [read $fh]
127128
close $fh
128129
return [regexp -all -inline {\S+} $content]
@@ -154,7 +155,7 @@ proc auto_memories_names { list } {
154155
# The view of every macro in blackboxes.txt, by extension (.lib, .lef).
155156
proc auto_memories_views { ext } {
156157
return [lmap m [auto_memories_blackboxes] {
157-
file join $::env(RESULTS_DIR) memories $m$ext
158+
file join $::env(AUTO_MEMORIES_DIR) $m$ext
158159
}]
159160
}
160161

‎flow/scripts/variables.mk‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export RESULTS_DIR = $(WORK_HOME)/results/$(PLATFORM)/$(DESIGN_NICKNAME)/$(FLOW_
5757
# Where a stage reads the previous stage's result.
5858
export FLOW_INPUT_VARIANT ?= $(FLOW_VARIANT)
5959
export INPUT_RESULTS_DIR = $(WORK_HOME)/results/$(PLATFORM)/$(DESIGN_NICKNAME)/$(FLOW_INPUT_VARIANT)
60+
# Where every step reads AUTO_MEMORIES' generated views; synthesis writes
61+
# them to its own $(RESULTS_DIR)/memories. Set by a build system that
62+
# runs a stage of one variant on another variant's synthesis.
63+
export AUTO_MEMORIES_DIR ?= $(RESULTS_DIR)/memories
6064

6165
#-------------------------------------------------------------------------------
6266
ifeq (,$(strip $(NUM_CORES)))

‎flow/scripts/variables.yaml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,16 @@ SYNTH_USE_SYN:
185185
stages:
186186
- synth
187187
default: 0
188+
AUTO_MEMORIES_DIR:
189+
description: >
190+
Directory every step reads AUTO_MEMORIES' generated views and lists
191+
from, synthesis included. Synthesis writes them to its own
192+
$(RESULTS_DIR)/memories, the default; with make, leave it there. For
193+
a build system that runs a stage of one variant on another variant's
194+
synthesis (e.g. bazel-orfs), which sets it for each step it runs,
195+
synthesis included, to the memories of the variant that synthesised
196+
them. Like AUTO_MEMORIES, not tied to stages: every step that reads
197+
the views needs it, the abstract among them.
188198
AUTO_MEMORIES:
189199
description: >
190200
Experimental. When set to 1, memories that yosys infers in the RTL
@@ -1682,8 +1692,8 @@ FLOW_INPUT_VARIANT:
16821692
runs, then leaves it at the default: the shared stages run once, and
16831693
the fork writes only its own results. A stage's later steps read the
16841694
stage's own results. A stage stops when its input is in both
1685-
variants. Not with AUTO_MEMORIES=1, whose memories are read from the
1686-
variant that synthesised them.
1695+
variants. With AUTO_MEMORIES=1, AUTO_MEMORIES_DIR names the memories
1696+
of the variant that synthesised them, for every stage the fork runs.
16871697
stages:
16881698
- floorplan
16891699
- place

‎flow/test/test_def2stream.py‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,43 +356,44 @@ def test_auto_memories_cell_may_be_empty(self):
356356
class TestAutoMemoriesCells(unittest.TestCase):
357357
def test_off_reads_nothing(self):
358358
self.assertEqual(
359-
def2stream.auto_memories_cells({"RESULTS_DIR": "/nonexistent"}),
359+
def2stream.auto_memories_cells({"AUTO_MEMORIES_DIR": "/nonexistent"}),
360360
frozenset(),
361361
)
362362

363363
def test_names_from_blackboxes_txt(self):
364-
with tempfile.TemporaryDirectory() as results:
365-
os.mkdir(os.path.join(results, "memories"))
366-
with open(os.path.join(results, "memories", "blackboxes.txt"), "w") as f:
364+
with tempfile.TemporaryDirectory() as memories:
365+
with open(os.path.join(memories, "blackboxes.txt"), "w") as f:
367366
# a name per line, optionally followed by more columns
368367
f.write("tage_entry_sram\nmbtb_entry_sram 491.400000\n\n")
369368
self.assertEqual(
370369
def2stream.auto_memories_cells(
371-
{"AUTO_MEMORIES": "1", "RESULTS_DIR": results}
370+
{"AUTO_MEMORIES": "1", "AUTO_MEMORIES_DIR": memories}
372371
),
373372
frozenset(["tage_entry_sram", "mbtb_entry_sram"]),
374373
)
375374

376375
def test_missing_list_is_an_error(self):
377376
# the flow always writes it; a missing list is a broken flow, not
378377
# a design without generated macros
379-
with tempfile.TemporaryDirectory() as results:
378+
with tempfile.TemporaryDirectory() as memories:
380379
with self.assertRaisesRegex(RuntimeError, "blackboxes.txt is missing"):
381380
def2stream.auto_memories_cells(
382-
{"AUTO_MEMORIES": "1", "RESULTS_DIR": results}
381+
{"AUTO_MEMORIES": "1", "AUTO_MEMORIES_DIR": memories}
383382
)
384383

385-
def test_missing_results_dir_is_an_error(self):
386-
with self.assertRaisesRegex(RuntimeError, "RESULTS_DIR is not set"):
387-
def2stream.auto_memories_cells({"AUTO_MEMORIES": "1"})
384+
def test_missing_auto_memories_dir_is_an_error(self):
385+
# RESULTS_DIR is no stand-in: the memories may be another variant's
386+
with self.assertRaisesRegex(RuntimeError, "AUTO_MEMORIES_DIR is not set"):
387+
def2stream.auto_memories_cells(
388+
{"AUTO_MEMORIES": "1", "RESULTS_DIR": "/nonexistent"}
389+
)
388390

389391
def test_empty_list_allows_nothing(self):
390-
with tempfile.TemporaryDirectory() as results:
391-
os.mkdir(os.path.join(results, "memories"))
392-
open(os.path.join(results, "memories", "blackboxes.txt"), "w").close()
392+
with tempfile.TemporaryDirectory() as memories:
393+
open(os.path.join(memories, "blackboxes.txt"), "w").close()
393394
self.assertEqual(
394395
def2stream.auto_memories_cells(
395-
{"AUTO_MEMORIES": "1", "RESULTS_DIR": results}
396+
{"AUTO_MEMORIES": "1", "AUTO_MEMORIES_DIR": memories}
396397
),
397398
frozenset(),
398399
)

0 commit comments

Comments
 (0)