Skip to content

Commit 88c0590

Browse files
oharboeclaude
andcommitted
synth: remove obsolete make memory report and clean up code
make memory printed the inferred-memory table of the last synthesis from mem.json. Nothing in ORFS documents or calls it, and its mem_hierarchical.json branch has read a file nothing writes since hierarchical synthesis moved to estimates (d07d6d9). What is in use is the SYNTH_MEMORY_MAX_BITS check, which stops a doomed synthesis early. That check needed mem.json, a JSON dump of the whole design written on every synthesis, only so that mem_dump.py could find the memories in it. synth.tcl already loops over the same memories in Tcl for SYNTH_MOCK_LARGE_MEMORIES. The check now runs in that loop, synth_memory_max_bits in flow/scripts/memories/max_bits.tcl, and mem.json, mem_dump.py and make memory go. Every synthesis now logs each inferred memory with its dimensions, a ROM marked as one; the log lines are the ones the mock already wrote. A read/write memory over the limit stops synthesis with an error that names each one, its size and the limit. A ROM is not counted. The design is still sorted where json -o mem.json sorted it: a yosys backend sorts the design by name before it writes, and the passes after it depend on that order. write_json /dev/null keeps the sort without the file; dropping it changes results and would be its own change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent e53f73a commit 88c0590

7 files changed

Lines changed: 153 additions & 264 deletions

File tree

‎flow/Makefile‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,6 @@ synth-report: synth
246246
do-synth-report:
247247
$(RUN_CMD) --log $(abspath $(LOG_DIR)/1_2_yosys_metrics.log) --tee -- $(OPENROAD_CMD) $(SCRIPTS_DIR)/synth_metrics.tcl
248248

249-
.PHONY: memory
250-
memory:
251-
if [ -f $(RESULTS_DIR)/mem_hierarchical.json ]; then \
252-
$(PYTHON_EXE) $(SCRIPTS_DIR)/mem_dump.py $(RESULTS_DIR)/mem_hierarchical.json; \
253-
fi
254-
$(PYTHON_EXE) $(SCRIPTS_DIR)/mem_dump.py $(RESULTS_DIR)/mem.json
255-
256249
# ==============================================================================
257250

258251

‎flow/scripts/mem_dump.py‎

Lines changed: 0 additions & 155 deletions
This file was deleted.

‎flow/scripts/memories/max_bits.tcl‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Log every inferred memory with its dimensions. With mock set, shrink each
2+
# memory over max_bits to one row, kept as a module when keep_mocked is set;
3+
# otherwise stop with an error naming every memory over max_bits that has a
4+
# write port. Returns the mocked memories as a list of {module width size}.
5+
proc synth_memory_max_bits { max_bits mock keep_mocked } {
6+
memory_collect
7+
set mocked {}
8+
set over {}
9+
foreach path [split [string trim [tee -q -s result.string select -list t:\$mem_v2]] "\n"] {
10+
set index [string first "/" $path]
11+
set module [string range $path 0 [expr { $index - 1 }]]
12+
set instance [string range $path [expr { $index + 1 }] end]
13+
14+
set width [rtlil::get_param -uint $module $instance WIDTH]
15+
set size [rtlil::get_param -uint $module $instance SIZE]
16+
set rom [expr { [rtlil::get_param -uint $module $instance WR_PORTS] == 0 }]
17+
set nbits [expr { $width * $size }]
18+
puts "Memory $path has dimensions $size x $width = $nbits[expr { $rom ? ", a ROM" : "" }]"
19+
if { $nbits <= $max_bits } {
20+
continue
21+
}
22+
if { $mock } {
23+
rtlil::set_param -uint $module $instance SIZE 1
24+
puts "Shrunk memory $path from $size rows to 1"
25+
lappend mocked [list $module $width $size]
26+
if { $keep_mocked } {
27+
select -module $module
28+
setattr -mod -set keep_hierarchy 1
29+
select -clear
30+
}
31+
} elseif { !$rom } {
32+
lappend over "$path $size x $width = $nbits"
33+
}
34+
}
35+
if { [llength $over] > 0 } {
36+
error "Memories over SYNTH_MEMORY_MAX_BITS=$max_bits, which would go into\
37+
flip-flops: [join $over {, }]. Put them in macros (AUTO_MEMORIES,\
38+
fakeram), mock them (SYNTH_MOCK_LARGE_MEMORIES=1) or raise the limit."
39+
}
40+
return $mocked
41+
}

‎flow/scripts/synth.tcl‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,37 +149,22 @@ if { [env_var_equals SYNTH_HDL_FRONTEND slang] } {
149149
opt_clean
150150
}
151151

152+
# Fail early if this synthesis run is doomed
153+
set mocked [synth_memory_max_bits $::env(SYNTH_MEMORY_MAX_BITS) \
154+
$::env(SYNTH_MOCK_LARGE_MEMORIES) $::env(SYNTH_KEEP_MOCKED_MEMORIES)]
152155
if { $::env(SYNTH_MOCK_LARGE_MEMORIES) } {
153-
memory_collect
154-
set select [tee -q -s result.string select -list t:\$mem_v2]
155156
set report_file [open $::env(REPORTS_DIR)/synth_mocked_memories.txt "w"]
156-
foreach path [split [string trim $select] "\n"] {
157-
set index [string first "/" $path]
158-
set module [string range $path 0 [expr { $index - 1 }]]
159-
set instance [string range $path [expr { $index + 1 }] end]
160-
161-
set width [rtlil::get_param -uint $module $instance WIDTH]
162-
set size [rtlil::get_param -uint $module $instance SIZE]
163-
set nbits [expr $width * $size]
164-
puts "Memory $path has dimensions $size x $width = $nbits"
165-
if { $nbits > $::env(SYNTH_MEMORY_MAX_BITS) } {
166-
rtlil::set_param -uint $module $instance SIZE 1
167-
puts "Shrunk memory $path from $size rows to 1"
168-
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
169-
if { $::env(SYNTH_KEEP_MOCKED_MEMORIES) } {
170-
select -module $module
171-
setattr -mod -set keep_hierarchy 1
172-
select -clear
173-
}
174-
}
157+
foreach memory $mocked {
158+
lassign $memory module width size
159+
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
175160
}
176161
close $report_file
177162
}
178163

179-
json -o $::env(RESULTS_DIR)/mem.json
180-
# Run report and check here so as to fail early if this synthesis run is doomed
181-
exec -- $::env(PYTHON_EXE) $::env(SCRIPTS_DIR)/mem_dump.py \
182-
--max-bits $::env(SYNTH_MEMORY_MAX_BITS) $::env(RESULTS_DIR)/mem.json
164+
# A yosys backend sorts the design by name before it writes, and the passes
165+
# below depend on that order; json -o mem.json did it here. The sort stays,
166+
# the file goes: dropping the sort changes results and is its own change.
167+
write_json /dev/null
183168

184169
if { [env_var_exists_and_non_empty SYNTH_RETIME_MODULES] } {
185170
select {*}$::env(SYNTH_RETIME_MODULES)

‎flow/scripts/synth_preamble.tcl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ proc read_checkpoint { file } {
4949
# canonicalization, one `<module> <area>` per line; see
5050
# docs/user/AutoMemories.md.
5151
source $::env(SCRIPTS_DIR)/memories/check_blackboxed.tcl
52+
source $::env(SCRIPTS_DIR)/memories/max_bits.tcl
5253

5354
proc auto_memories_areas { } {
5455
if { ![env_var_equals AUTO_MEMORIES 1] } {

‎flow/test/test_mem_dump.py‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)