Skip to content

Commit 1c74e61

Browse files
committed
flow: SYNTH_KEEP_LARGE_MEMORIES is now orthogonal to other options
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 4a06a65 commit 1c74e61

3 files changed

Lines changed: 28 additions & 31 deletions

File tree

‎docs/user/FlowVariables.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ configuration file.
247247
| <a name="SYNTH_HDL_FRONTEND"></a>SYNTH_HDL_FRONTEND| Select an alternative language frontend to ingest the design. Available option is "slang". If the variable is empty, design is read with the Yosys read_verilog command.| |
248248
| <a name="SYNTH_HIERARCHICAL"></a>SYNTH_HIERARCHICAL| Enable to Synthesis hierarchically, otherwise considered flat synthesis.| 0|
249249
| <a name="SYNTH_HIER_SEPARATOR"></a>SYNTH_HIER_SEPARATOR| Separator used for the synthesis flatten stage.| .|
250-
| <a name="SYNTH_KEEP_MOCKED_MEMORIES"></a>SYNTH_KEEP_MOCKED_MEMORIES| When `SYNTH_MOCK_LARGE_MEMORIES=1`, setting this to 1, will keep mocked memories (not flattening them). This preserves some of the access logic complexity and avoids optimizations outside of the mocked memory.| 1|
250+
| <a name="SYNTH_KEEP_LARGE_MEMORIES"></a>SYNTH_KEEP_LARGE_MEMORIES| Keep memories larger than `SYNTH_MEMORY_MAX_BITS`.| 1|
251251
| <a name="SYNTH_KEEP_MODULES"></a>SYNTH_KEEP_MODULES| Mark modules to keep from getting removed in flattening.| |
252252
| <a name="SYNTH_MEMORY_MAX_BITS"></a>SYNTH_MEMORY_MAX_BITS| Maximum number of bits for memory synthesis. Ideally, real RAM or realistic fakeram should be used for RAMs much larger than 1024 bits. To temporarily ignore the RAM concerns and investigate other aspects of the design, consider setting `SYNTH_MOCK_LARGE_MEMORIES=1`, or adjusting `SYNTH_MEMORY_MAX_BITS`.| 4096|
253253
| <a name="SYNTH_MINIMUM_KEEP_SIZE"></a>SYNTH_MINIMUM_KEEP_SIZE| For hierarchical synthesis, we keep modules of larger area than given by this variable and flatten smaller modules. The area unit used is the size of a basic nand2 gate from the platform's standard cell library. The default value is platform specific.| 0|
@@ -291,7 +291,7 @@ configuration file.
291291
- [SYNTH_GUT](#SYNTH_GUT)
292292
- [SYNTH_HDL_FRONTEND](#SYNTH_HDL_FRONTEND)
293293
- [SYNTH_HIERARCHICAL](#SYNTH_HIERARCHICAL)
294-
- [SYNTH_KEEP_MOCKED_MEMORIES](#SYNTH_KEEP_MOCKED_MEMORIES)
294+
- [SYNTH_KEEP_LARGE_MEMORIES](#SYNTH_KEEP_LARGE_MEMORIES)
295295
- [SYNTH_KEEP_MODULES](#SYNTH_KEEP_MODULES)
296296
- [SYNTH_MEMORY_MAX_BITS](#SYNTH_MEMORY_MAX_BITS)
297297
- [SYNTH_MINIMUM_KEEP_SIZE](#SYNTH_MINIMUM_KEEP_SIZE)

‎flow/scripts/synth.tcl‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,34 @@ if { !$::env(SYNTH_HIERARCHICAL) } {
8888
synth -flatten -run coarse:fine {*}$synth_full_args
8989
}
9090

91-
92-
if { $::env(SYNTH_MOCK_LARGE_MEMORIES) } {
93-
memory_collect
94-
set select [tee -q -s result.string select -list t:\$mem_v2]
95-
set report_file [open $::env(REPORTS_DIR)/synth_mocked_memories.txt "w"]
96-
foreach path [split [string trim $select] "\n"] {
97-
set index [string first "/" $path]
98-
set module [string range $path 0 [expr { $index - 1 }]]
99-
set instance [string range $path [expr { $index + 1 }] end]
100-
101-
set width [rtlil::get_param -uint $module $instance WIDTH]
102-
set size [rtlil::get_param -uint $module $instance SIZE]
103-
set nbits [expr $width * $size]
104-
puts "Memory $path has dimensions $size x $width = $nbits"
105-
if { $nbits > $::env(SYNTH_MEMORY_MAX_BITS) } {
91+
# Enumerate memories in log, single code path and useful to
92+
# see memories in log, and mock/keep as needed.
93+
memory_collect
94+
set select [tee -q -s result.string select -list t:\$mem_v2]
95+
set report_file [open $::env(REPORTS_DIR)/synth_mocked_memories.txt "w"]
96+
foreach path [split [string trim $select] "\n"] {
97+
set index [string first "/" $path]
98+
set module [string range $path 0 [expr { $index - 1 }]]
99+
set instance [string range $path [expr { $index + 1 }] end]
100+
101+
set width [rtlil::get_param -uint $module $instance WIDTH]
102+
set size [rtlil::get_param -uint $module $instance SIZE]
103+
set nbits [expr $width * $size]
104+
puts "Memory $path has dimensions $size x $width = $nbits"
105+
if { $nbits > $::env(SYNTH_MEMORY_MAX_BITS) } {
106+
if { $::env(SYNTH_MOCK_LARGE_MEMORIES) } {
106107
rtlil::set_param -uint $module $instance SIZE 1
107-
puts "Shrunk memory $path from $size rows to 1"
108-
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
109-
if { $::env(SYNTH_KEEP_MOCKED_MEMORIES) } {
110-
select -module $module
111-
setattr -mod -set keep_hierarchy 1
112-
select -clear
113-
}
108+
}
109+
puts "Shrunk memory $path from $size rows to 1"
110+
puts -nonewline $report_file "$module:\n width: $width\n size: $size\n"
111+
if { $::env(SYNTH_KEEP_LARGE_MEMORIES) } {
112+
select -module $module
113+
setattr -mod -set keep_hierarchy 1
114+
select -clear
114115
}
115116
}
116-
close $report_file
117117
}
118+
close $report_file
118119

119120
json -o $::env(RESULTS_DIR)/mem.json
120121
# Run report and check here so as to fail early if this synthesis run is doomed

‎flow/scripts/variables.yaml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,9 @@ SYNTH_MOCK_LARGE_MEMORIES:
228228
default: 0
229229
stages:
230230
- synth
231-
SYNTH_KEEP_MOCKED_MEMORIES:
231+
SYNTH_KEEP_LARGE_MEMORIES:
232232
description: >
233-
When `SYNTH_MOCK_LARGE_MEMORIES=1`, setting this to 1,
234-
will keep mocked memories (not flattening them).
235-
236-
This preserves some of the access logic complexity and
237-
avoids optimizations outside of the mocked memory.
233+
Keep memories larger than `SYNTH_MEMORY_MAX_BITS`.
238234
default: 1
239235
stages:
240236
- synth

0 commit comments

Comments
 (0)