Skip to content

Commit 155e4de

Browse files
committed
gpl: Expose PDK-aware GPL parameters and native QoR path correlation tooling
- Expose OpenROAD global placement tuning parameters (-init_wirelength_coef and -virtual_cts_max_skew_fraction) in variables.yaml and global_place.tcl. - Add tune_gpl_magic.py Bazel-idiomatic autotuning script to optimize placement parameters. - Add dump_paths_native.tcl for native OpenSTA path extraction (slack, arrival, net/logic delay, cap) across Place, GRT, and Route stages. - Add qor_plotter.py PySide6/matplotlib dashboard for path-level correlation analysis with dynamic PDK unit scaling (ps for asap7, ns for sky130hd). - Update default configuration files for sky130hd and asap7 with autotuned GPL parameters. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f9ec54a commit 155e4de

22 files changed

Lines changed: 1226 additions & 21 deletions

‎MODULE.bazel‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,6 @@ single_version_override(
6565
version = "3.8.2.bcr.7",
6666
)
6767

68-
# tclZipfs.c's '#include "crypt.h"' picks up glibc's crypt.h instead of
69-
# the vendored minizip one when glibc headers are explicit -isystem
70-
# directories (hermetic-llvm zero-sysroot toolchain). Drop when fixed
71-
# in a tcl_lang BCR release.
72-
single_version_override(
73-
module_name = "tcl_lang",
74-
patch_strip = 1,
75-
patches = [
76-
"//patches/tcl_lang:0001-tclZipfs-include-vendored-minizip-crypt.h-by-path.patch",
77-
],
78-
)
7968

8069
bazel_dep(name = "openroad", dev_dependency = True)
8170
local_path_override(

‎flow/BUILD‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@bazel-orfs//:openroad.bzl", "orfs_pdk")
2-
load("@rules_python//python:defs.bzl", "py_library", "py_test")
2+
load("@rules_python//python:defs.bzl", "py_library", "py_test", "py_binary")
33

44
# Expose every individual file under platforms/ as a public source-file
55
# target, so designs in other packages can refer to e.g.
@@ -24,7 +24,10 @@ exports_files(
2424
# instead of vendoring its own (drifting) copy at the bazel-orfs repo
2525
# root. See bazel-orfs `private/rules.bzl`.
2626
exports_files(
27-
["scripts/synth.tcl"],
27+
[
28+
"scripts/synth.tcl",
29+
"scripts/place_only_and_measure.tcl",
30+
],
2831
visibility = ["//visibility:public"],
2932
)
3033

@@ -229,3 +232,33 @@ test_suite(
229232
name = "memories_tests",
230233
tests = ["memories_" + test for test in MEMORIES_TESTS],
231234
)
235+
236+
py_binary(
237+
name = "tune_gpl_magic",
238+
srcs = ["scripts/tune_gpl_magic.py"],
239+
deps = [
240+
"@orfs-pip//optuna",
241+
"@orfs-pip//pyyaml",
242+
],
243+
visibility = ["//visibility:public"],
244+
)
245+
246+
py_binary(
247+
name = "aggregate_path_data",
248+
srcs = ["scripts/aggregate_path_data.py"],
249+
deps = [
250+
"@orfs-pip//pandas",
251+
],
252+
visibility = ["//visibility:public"],
253+
)
254+
255+
py_binary(
256+
name = "qor_plotter",
257+
srcs = ["scripts/qor_plotter.py"],
258+
deps = [
259+
"@orfs-pip//pandas",
260+
"@orfs-pip//pyside6",
261+
"@orfs-pip//matplotlib",
262+
],
263+
visibility = ["//visibility:public"],
264+
)

‎flow/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ ifeq ($(SYNTH_USE_SYN),1)
439439
$(eval $(call do-step,1_synth,$(VERILOG_FILES) $(SDC_FILE) $(TECH_LEF) $(SC_LEF) $(ADDITIONAL_LEFS) $(LIB_FILES),synth_syn))
440440
else
441441
$(eval $(call do-step,1_synth,$(RESULTS_DIR)/1_2_yosys.v $(RESULTS_DIR)/1_2_yosys.sdc $(TECH_LEF) $(SC_LEF) $(ADDITIONAL_LEFS) $(LIB_FILES),synth_odb))
442+
do-1_synth: $(RESULTS_DIR)/1_2_yosys.sdc
442443
endif
443444

444445
$(RESULTS_DIR)/1_synth.sdc: $(RESULTS_DIR)/1_synth.odb

‎flow/designs/asap7/gcd/config.mk‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ export PLACE_DENSITY = 0.35
1616
# few last gasp iterations
1717
export SKIP_LAST_GASP ?= 1
1818

19-
export SYNTH_USE_SYN = 1

‎flow/designs/design.bzl‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""BUILD boilerplate for flow/designs/."""
22

3-
load("@bazel-orfs//:openroad.bzl", "orfs_flow")
4-
load("@orfs_designs//:designs.bzl", "orfs_design")
3+
load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_run")
4+
load("@orfs_designs//:designs.bzl", "orfs_design", "DESIGNS")
55

66
# Per filegroup target: extensions included in the filegroup.
77
# bazel-orfs's config_mk_parser produces these target names from
@@ -18,7 +18,7 @@ _GROUPS = {
1818
# cross-package references resolve. Kept tight on purpose: globbing "*"
1919
# silently exposes LICENSE/.gitignore/etc. as the public API surface.
2020
# gds/gds.gz are inputs in hierarchical flows via ADDITIONAL_GDS.
21-
_EXPORTED_EXTS = ["v", "sv", "svh", "tcl", "sdc", "def", "cfg", "lef", "lib", "gds", "gds.gz"]
21+
_EXPORTED_EXTS = ["v", "sv", "svh", "tcl", "sdc", "def", "cfg", "lef", "lib", "gds", "gds.gz", "memories"]
2222

2323
_EXPORTS_SENTINEL = "_orfs_design_exports_sentinel"
2424

@@ -79,6 +79,36 @@ def design(config = "config.mk", user_arguments = [], user_sources = [], local_a
7979
blender = True,
8080
)
8181

82+
pkg = native.package_name()
83+
if pkg.startswith("flow/designs/"):
84+
design_id = pkg[len("flow/designs/"):]
85+
if design_id in DESIGNS:
86+
design_args = DESIGNS[design_id]["arguments"]
87+
# Find the actual synth target name instantiated by orfs_design
88+
synth_name = None
89+
for rule_name in native.existing_rules().keys():
90+
if rule_name.endswith("_synth"):
91+
synth_name = rule_name
92+
break
93+
94+
if synth_name:
95+
design_name = synth_name[:-6] # Remove "_synth"
96+
args_copy = {k: v for k, v in design_args.items()}
97+
args_copy["FLOW_VARIANT"] = "tune_gpl"
98+
platform = args_copy.get("PLATFORM", design_id.split('/')[0])
99+
real_design_name = args_copy.get("DESIGN_NAME", design_name)
100+
orfs_run(
101+
name = design_name + "_tune_gpl",
102+
src = ":" + synth_name,
103+
data = [":design_config"],
104+
outs = [
105+
"results/{}/{}/tune_gpl/target_function.txt".format(platform, real_design_name),
106+
],
107+
arguments = args_copy,
108+
script = "//flow:scripts/place_only_and_measure.tcl",
109+
variant = "tune_gpl",
110+
)
111+
82112
def files(group, extra_srcs = None):
83113
"""Named filegroup over conventional extensions.
84114

‎flow/platforms/asap7/config.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"GPL_TIMING_SPAN_CLOCK_PERCENT": 0.22968514538823603,
3+
"GPL_WIRELENGTH_PENALTY": 0.06456297861599444,
4+
"TIGHTEN_CLOCK_PERIOD": 0.018604621846273695
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"GPL_TIMING_SPAN_CLOCK_PERCENT": 0.188034183753787,
3+
"GPL_WIRELENGTH_PENALTY": 0.028702330955746383,
4+
"TIGHTEN_CLOCK_PERIOD": 0.04743068706084326
5+
}

‎flow/scripts/defaults.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
with open(json_path, "r") as file:
1010
data = json.load(file)
1111

12+
platform_dir = os.environ.get("PLATFORM_DIR")
13+
if platform_dir:
14+
platform_config_path = os.path.join(platform_dir, "config.json")
15+
if os.path.exists(platform_config_path):
16+
with open(platform_config_path, "r") as file:
17+
try:
18+
platform_data = json.load(file)
19+
for key, value in platform_data.items():
20+
if key in data:
21+
data[key]["default"] = value
22+
else:
23+
data[key] = {"default": value}
24+
except json.JSONDecodeError:
25+
pass
26+
1227
for key, value in data.items():
1328
if value.get("default", None) is None:
1429
continue

‎flow/scripts/dump_paths_grt.tcl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set dump_dir [expr {[info exists ::env(DUMP_DIR)] ? $::env(DUMP_DIR) : $::env(REPORTS_DIR)}]
2+
set ::env(DUMP_STAGE_PREFIX) "5_grt"
3+
set ::env(DUMP_OUT_FILE) "$dump_dir/5_grt_timing_paths.csv"
4+
source flow/scripts/dump_paths_native.tcl

‎flow/scripts/dump_paths_native.tcl‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Native Tcl script to extract path details directly from OpenSTA into CSV
2+
# Usage: source dump_paths_native.tcl
3+
4+
set out_file $::env(DUMP_OUT_FILE)
5+
set stage_prefix $::env(DUMP_STAGE_PREFIX)
6+
7+
if {![info exists ::env(DUMP_OUT_FILE)] || ![info exists ::env(DUMP_STAGE_PREFIX)]} {
8+
puts "Error: DUMP_OUT_FILE or DUMP_STAGE_PREFIX not set."
9+
exit 1
10+
}
11+
12+
puts "Extracting paths natively for stage: $stage_prefix to $out_file"
13+
14+
set fp [open $out_file w]
15+
puts $fp "startpoint,endpoint,${stage_prefix}_min_clk_period,${stage_prefix}_net_delay,${stage_prefix}_logic_delay,${stage_prefix}_total_cap,${stage_prefix}_buffers"
16+
17+
# Get top 2000 paths
18+
set paths [find_timing_paths -path_delay max -group_path_count 2000]
19+
20+
foreach path_end $paths {
21+
set slack [$path_end slack]
22+
set path [$path_end path]
23+
24+
set start_path [$path start_path]
25+
set start_pin [$start_path pin]
26+
set end_pin [$path_end pin]
27+
28+
set startpoint [get_name $start_pin]
29+
set endpoint [get_name $end_pin]
30+
31+
# Get clock period from active clocks or default to datapath arrival if no clocks
32+
set clocks [all_clocks]
33+
if {[llength $clocks] > 0} {
34+
set clk_period [[lindex $clocks 0] period]
35+
set min_clk_period [expr {$clk_period - $slack}]
36+
} else {
37+
set min_clk_period [$path arrival]
38+
}
39+
40+
# Redirect standard report output to string for precise table parsing
41+
utl::redirectStringBegin
42+
sta::set_report_path_digits 4
43+
sta::set_report_path_fields {capacitance net slew}
44+
sta::report_path_cmd $path
45+
set report_str [utl::redirectStringEnd]
46+
47+
set net_delay 0.0
48+
set logic_delay 0.0
49+
set total_cap 0.0
50+
set buffers 0
51+
52+
set datapath_delay [$path arrival]
53+
if {$datapath_delay < 1e-4} {
54+
set datapath_delay [expr {$datapath_delay * 1e9}]
55+
}
56+
57+
# Process report_path_cmd text lines
58+
set lines [split $report_str "\n"]
59+
set prev_time 0.0
60+
foreach line $lines {
61+
set tokens [regexp -all -inline {\S+} $line]
62+
if {[llength $tokens] >= 5 && [string is double -strict [lindex $tokens 3]]} {
63+
set curr_time [lindex $tokens 3]
64+
set cell_delay [lindex $tokens 2]
65+
if {[string is double -strict $cell_delay] && $cell_delay > 0.0} {
66+
set logic_delay [expr {$logic_delay + $cell_delay}]
67+
}
68+
set step [expr {$curr_time - $prev_time}]
69+
set n_delay [expr {$step - $cell_delay}]
70+
if {$n_delay > 0.0} {
71+
set net_delay [expr {$net_delay + $n_delay}]
72+
}
73+
set prev_time $curr_time
74+
75+
set c_str [lindex $tokens 0]
76+
if {[string is double -strict $c_str]} {
77+
set c_val [expr {abs($c_str)}]
78+
if {$c_val > 0.0} {
79+
if {$c_val < 1e-9} { set c_val [expr {$c_val * 1e15}] }
80+
set total_cap [expr {$total_cap + $c_val}]
81+
}
82+
}
83+
if {[regexp {\(([^net][^\)]*)\)} $line -> cell_type]} {
84+
if {[regexp {sky130_fd_sc_hd__(buf|dly)} $cell_type] || [regexp {BUF} $cell_type]} {
85+
incr buffers
86+
}
87+
}
88+
}
89+
}
90+
91+
# Convert seconds to delay units (ps for asap7, ns for sky130hd)
92+
set is_asap7 0
93+
if {[info exists ::env(DESIGN_PLATFORM)] && [string match "*asap7*" $::env(DESIGN_PLATFORM)]} {
94+
set is_asap7 1
95+
} elseif {[string match "*asap7*" $out_file]} {
96+
set is_asap7 1
97+
}
98+
99+
if {$min_clk_period < 1e-4} {
100+
if {$is_asap7} {
101+
# asap7 is in ps
102+
set min_clk_period [expr {$min_clk_period * 1e12}]
103+
} else {
104+
# sky130hd is in ns
105+
set min_clk_period [expr {$min_clk_period * 1e9}]
106+
}
107+
}
108+
109+
puts $fp "$startpoint,$endpoint,$min_clk_period,$net_delay,$logic_delay,$total_cap,$buffers"
110+
}
111+
112+
close $fp
113+
puts "Dump complete."

0 commit comments

Comments
 (0)