Skip to content

Commit

Permalink
synthesis: minimal synthesis to drive MAX_UNGROUP_SIZE policy
Browse files Browse the repository at this point in the history
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
  • Loading branch information
oharboe committed Jan 16, 2024
1 parent c7c605e commit 6642a8a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 68 deletions.
3 changes: 2 additions & 1 deletion flow/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,9 @@ do-synth-report:
SYNTH_SCRIPT ?= $(SCRIPTS_DIR)/synth.tcl

$(SYNTH_STOP_MODULE_SCRIPT):
mkdir -p $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR)
mkdir -p $(OBJECTS_DIR) $(RESULTS_DIR) $(LOG_DIR) $(REPORTS_DIR)
($(TIME_CMD) $(YOSYS_CMD) $(YOSYS_FLAGS) -c $(HIER_REPORT_SCRIPT)) 2>&1 | tee $(LOG_DIR)/1_1_yosys_hier_report.log
python $(SCRIPTS_DIR)/synth_keep.py $(OBJECTS_DIR)/synth.json $(SYNTH_STOP_MODULE_SCRIPT) $(or $(MAX_UNGROUP_SIZE),0)

ifeq ($(SYNTH_HIERARCHICAL), 1)
do-yosys: $(SYNTH_STOP_MODULE_SCRIPT)
Expand Down
1 change: 1 addition & 0 deletions flow/scripts/synth.tcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source $::env(SCRIPTS_DIR)/synth_preamble.tcl

if { [info exist ::env(SYNTH_HIERARCHICAL)] && $::env(SYNTH_HIERARCHICAL) == 1 && [file isfile $::env(SYNTH_STOP_MODULE_SCRIPT)] } {
hierarchy -check -top $::env(DESIGN_NAME)
puts "Sourcing $::env(SYNTH_STOP_MODULE_SCRIPT)"
source $::env(SYNTH_STOP_MODULE_SCRIPT)
}
Expand Down
82 changes: 15 additions & 67 deletions flow/scripts/synth_hier_report.tcl
Original file line number Diff line number Diff line change
@@ -1,71 +1,19 @@
source $::env(SCRIPTS_DIR)/synth_preamble.tcl

# Hierarchical synthesis
synth -top $::env(DESIGN_NAME)
if { [info exist ::env(ADDER_MAP_FILE)] && [file isfile $::env(ADDER_MAP_FILE)] } {
techmap -map $::env(ADDER_MAP_FILE)
}
techmap
if {[info exist ::env(DFF_LIB_FILE)]} {
dfflibmap -liberty $::env(DFF_LIB_FILE)
} else {
dfflibmap -liberty $::env(DONT_USE_SC_LIB)
}
puts "abc [join $abc_args " "]"
abc {*}$abc_args

tee -o $::env(REPORTS_DIR)/synth_hier_stat.txt stat {*}$stat_libs

if { [info exist ::env(REPORTS_DIR)] && [file isfile $::env(REPORTS_DIR)/synth_hier_stat.txt] } {
set ungroup_threshold 0
if { [info exist ::env(MAX_UNGROUP_SIZE)] && $::env(MAX_UNGROUP_SIZE) > 0 } {
set ungroup_threshold $::env(MAX_UNGROUP_SIZE)
puts "Ungroup modules of size $ungroup_threshold"
}
hierarchy -check -top $::env(DESIGN_NAME)
set fptr [open $::env(REPORTS_DIR)/synth_hier_stat.txt r]
set contents [read -nonewline $fptr]
close $fptr
set split_cont [split $contents "\n"]
set hierarchy_section 0
set module_list {}
foreach line $split_cont {
if {[regexp {=== design hierarchy ===} $line]} {
set hierarchy_section 1
continue
}
if {[regexp { Number of wires.*} $line ]} {
set hierarchy_section 0
continue
}
if { $hierarchy_section == 1 } {
if {[regexp { +(\S+) +.*} $line -> module_name]} {
lappend module_list $module_name
puts "Found module $module_name"
}
}
}
set out_script_ptr [open $::env(OBJECTS_DIR)/mark_hier_stop_modules.tcl w]
puts $out_script_ptr "hierarchy -check -top $::env(DESIGN_NAME)"
foreach module $module_list {
tee -o $::env(REPORTS_DIR)/synth_hier_stat_temp_module.txt stat -top "$module" {*}$stat_libs
set fptr1 [open $::env(REPORTS_DIR)/synth_hier_stat_temp_module.txt r]
set contents1 [read -nonewline $fptr1]
close $fptr1
set split_cont1 [split $contents1 "\n"]
foreach line $split_cont1 {
if {[regexp { +Chip area for top module '(\S+)': (.*)} $line -> module_name area]} {
puts "Area of module $module_name is $area"
if {[expr $area > $ungroup_threshold]} {
puts "Preserving hierarchical module: $module_name"
puts $out_script_ptr "select -module {$module_name}"
puts $out_script_ptr "setattr -mod -set keep_hierarchy 1"
puts $out_script_ptr "select -clear"
}
}
}
file delete -force $::env(REPORTS_DIR)/synth_hier_stat_temp_module.txt
}
close $out_script_ptr
set ungroup_threshold 0
if { [info exist ::env(MAX_UNGROUP_SIZE)] && $::env(MAX_UNGROUP_SIZE) > 0 } {
set ungroup_threshold $::env(MAX_UNGROUP_SIZE)
puts "Ungroup modules of size $ungroup_threshold"
}

# Minimal hierarchical synthesis to use number of cells to drive policy
# of whether to flatten a module or not.
synth -run :coarse -top $::env(DESIGN_NAME)
# These commands are cherry-picked from the "synth -run coarse:" list
# of commands in the Yosys manual.
#
# 'proc' pass is called 'procs' to avoid conflict with tcl 'proc' command
procs
memory -nomap
memory_map
json -o $::env(OBJECTS_DIR)/synth.json
20 changes: 20 additions & 0 deletions flow/scripts/synth_keep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
import sys


def main(args):
threshold = int(args[2])
with open(args[0], "r") as f:
synth = json.load(f)

print("Preserving hierarchical modules...")
with open(args[1], "w") as f:
for name, module in synth["modules"].items():
if len(module["cells"]) > threshold:
f.write("select -module {\\" + name + "}\n")
f.write("setattr -mod -set keep_hierarchy 1\n")
f.write("select -clear\n")


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 6642a8a

Please sign in to comment.