Skip to content

Commit d909283

Browse files
oharboeclaude
andcommitted
util: OpenROAD-SYN status plots (QoR deltas, runtime A/B, clock period)
plotSynQoR.py renders the syn-vs-yosys synthesis QoR comparison from per-design best-effort qor.json pairs: percent-delta panels (std-cell area, instance count, runtime) plus an absolute SYN worst-slack panel, with failed designs drawn as hatched FAIL columns instead of omitted. --runtime-output adds an absolute runtime A/B grouped-bar chart (log scale) from the same inputs. plotClockPeriod.py renders effective clock period (target - gated worst slack) across synth/cts/globalroute/finish, one series per design, from the checked-in rules-*.json files alone — the OpenROAD-SYN synthesis point overlays the regular flow's trajectory, no flow runs needed. genMetrics.py gains a scalar constraints__clocks__period metric (rule files cannot carry the details list) and genRuleFile.py propagates it as a direct == rule, so regenerated rules files feed the clock-period plot. Both scripts are matplotlib py_binaries fed from the @orfs-pip hub, so bazelisk build needs no host python packages; output is deterministic (Agg, fixed geometry, no timestamps) for meaningful PNG diffs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 3fbe63e commit d909283

5 files changed

Lines changed: 675 additions & 1 deletion

File tree

‎flow/util/BUILD‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@rules_python//python:defs.bzl", "py_library", "py_test")
1+
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
22
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
33

44
exports_files(["open_plots.sh"])
@@ -39,6 +39,26 @@ py_library(
3939
imports = ["."],
4040
)
4141

42+
# Renders the OpenROAD-SYN vs yosys synthesis QoR comparison graph from
43+
# per-design qor.json pairs (see //flow/designs/asap7:syn_qor_png).
44+
# matplotlib comes from the @orfs-pip hub, so `bazelisk build` needs no
45+
# host python packages.
46+
py_binary(
47+
name = "plotSynQoR",
48+
srcs = ["plotSynQoR.py"],
49+
visibility = ["//visibility:public"],
50+
deps = ["@orfs-pip//matplotlib"],
51+
)
52+
53+
# Renders effective clock period across flow stages from the checked-in
54+
# rules-*.json QoR gates (see //flow/designs/asap7:clock_period_png).
55+
py_binary(
56+
name = "plotClockPeriod",
57+
srcs = ["plotClockPeriod.py"],
58+
visibility = ["//visibility:public"],
59+
deps = ["@orfs-pip//matplotlib"],
60+
)
61+
4262
py_test(
4363
name = "genMetrics_test",
4464
srcs = ["genMetrics_test.py"],

‎flow/util/genMetrics.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ def extract_metrics(
270270
clk_list = read_sdc(sdc_file)
271271
metrics_dict["constraints__clocks__count"] = len(clk_list)
272272
metrics_dict["constraints__clocks__details"] = clk_list
273+
# Scalar clock period (min across clocks) so rule files can carry it:
274+
# checkMetadata.py cannot compare the details list, and QoR plots need
275+
# the period to turn per-stage worst slack into an effective period.
276+
periods = []
277+
for clk in clk_list:
278+
try:
279+
periods.append(float(clk.split()[-1]))
280+
except (ValueError, IndexError):
281+
pass
282+
if periods:
283+
metrics_dict["constraints__clocks__period"] = min(periods)
273284

274285
# Floorplan
275286
# =========================================================================

‎flow/util/genRuleFile.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ def gen_rule_file(
119119
"round_value": True,
120120
"compare": "==",
121121
},
122+
"constraints__clocks__period": {
123+
"mode": "direct",
124+
"round_value": False,
125+
"compare": "==",
126+
},
122127
# place
123128
"placeopt__design__instance__area": {
124129
"mode": "padding",

‎flow/util/plotClockPeriod.py‎

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#!/usr/bin/env python3
2+
"""Plot effective clock period across flow stages from rules-*.json.
3+
4+
For every design, rules-base.json carries the QoR-gated setup worst
5+
slack of the design's regular flow at the synth/cts/globalroute/finish
6+
stages, and rules-syn.json carries the OpenROAD-SYN synthesis-only
7+
gate. Effective period = clock period - worst slack, i.e. the period
8+
the design would need to meet timing. One line per design (regular
9+
flow), with the OpenROAD-SYN post-synthesis point overlaid as a diamond
10+
so the two synthesis engines can be compared without running any flow.
11+
12+
The values are QoR gates (padded by genRuleFile.py), not measurements —
13+
both engines are padded identically, so the comparison is fair, but the
14+
absolute numbers include rule margin.
15+
16+
Usage:
17+
plotClockPeriod.py --output png \\
18+
--design gcd --rules-base .../rules-base.json --rules-syn .../rules-syn.json \\
19+
[--design ... --rules-base ... --rules-syn ...]
20+
21+
Deterministic output (Agg backend, fixed geometry, no timestamps).
22+
"""
23+
24+
import argparse
25+
import json
26+
import sys
27+
28+
import matplotlib
29+
30+
matplotlib.use("Agg")
31+
32+
import matplotlib.pyplot as plt # noqa: E402
33+
from matplotlib.ticker import ScalarFormatter # noqa: E402
34+
35+
STAGES = ["synth", "cts", "globalroute", "finish"]
36+
37+
TEXT_PRIMARY = "#0b0b0b"
38+
TEXT_SECONDARY = "#52514e"
39+
SURFACE = "#fcfcfb"
40+
SYN_MARKER_EDGE = "#0b0b0b"
41+
42+
43+
def parse_args():
44+
parser = argparse.ArgumentParser(description=__doc__)
45+
parser.add_argument("--output", required=True, help="Output PNG path")
46+
parser.add_argument(
47+
"--title",
48+
default="Effective clock period across stages (rules-*.json gates, asap7)",
49+
help="Figure title",
50+
)
51+
parser.add_argument("--design", action="append", default=[], help="Design name")
52+
parser.add_argument(
53+
"--rules-base", action="append", default=[], help="rules-base.json path"
54+
)
55+
parser.add_argument(
56+
"--rules-syn", action="append", default=[], help="rules-syn.json path"
57+
)
58+
args = parser.parse_args()
59+
if not (len(args.design) == len(args.rules_base) == len(args.rules_syn)):
60+
parser.error(
61+
"--design/--rules-base/--rules-syn must be given the same number of times"
62+
)
63+
if not args.design:
64+
parser.error("at least one design is required")
65+
return args
66+
67+
68+
def load_rules(path):
69+
try:
70+
with open(path) as f:
71+
return json.load(f)
72+
except (OSError, json.JSONDecodeError) as e:
73+
print(f"[WARN] cannot read {path}: {e}", file=sys.stderr)
74+
return {}
75+
76+
77+
def rule_number(rules, field):
78+
rule = rules.get(field)
79+
if not rule:
80+
return None
81+
value = rule.get("value")
82+
if isinstance(value, (int, float)) and not isinstance(value, bool):
83+
return float(value)
84+
return None
85+
86+
87+
def main():
88+
args = parse_args()
89+
90+
fig, ax = plt.subplots(figsize=(9.0, 7.0), dpi=120)
91+
fig.patch.set_facecolor(SURFACE)
92+
ax.set_facecolor(SURFACE)
93+
94+
cmap = plt.get_cmap("tab20")
95+
x = range(len(STAGES))
96+
skipped = []
97+
plotted = 0
98+
99+
for idx, (design, base_path, syn_path) in enumerate(
100+
zip(args.design, args.rules_base, args.rules_syn)
101+
):
102+
base = load_rules(base_path)
103+
syn = load_rules(syn_path)
104+
period = rule_number(syn, "constraints__clocks__period") or rule_number(
105+
base, "constraints__clocks__period"
106+
)
107+
if period is None:
108+
skipped.append(design)
109+
continue
110+
111+
color = cmap(idx % 20)
112+
ys = [
113+
(
114+
period - ws
115+
if (ws := rule_number(base, f"{stage}__timing__setup__ws")) is not None
116+
else None
117+
)
118+
for stage in STAGES
119+
]
120+
xs = [i for i, y in zip(x, ys) if y is not None]
121+
vals = [y for y in ys if y is not None]
122+
if vals:
123+
ax.plot(
124+
xs,
125+
vals,
126+
marker="o",
127+
markersize=4,
128+
linewidth=1.6,
129+
color=color,
130+
zorder=2,
131+
)
132+
# Direct label at the line end; text in ink, mark carries color.
133+
ax.annotate(
134+
design,
135+
(xs[-1], vals[-1]),
136+
textcoords="offset points",
137+
xytext=(6, 0),
138+
fontsize=7,
139+
color=TEXT_PRIMARY,
140+
va="center",
141+
zorder=3,
142+
)
143+
plotted += 1
144+
145+
syn_ws = rule_number(syn, "synth__timing__setup__ws")
146+
if syn_ws is not None:
147+
ax.plot(
148+
[0],
149+
[period - syn_ws],
150+
marker="D",
151+
markersize=7,
152+
linestyle="none",
153+
markerfacecolor=color,
154+
markeredgecolor=SYN_MARKER_EDGE,
155+
markeredgewidth=0.8,
156+
zorder=4,
157+
)
158+
159+
ax.set_xticks(list(x))
160+
ax.set_xticklabels(STAGES, fontsize=9)
161+
ax.set_yscale("log")
162+
for set_formatter in [ax.yaxis.set_major_formatter, ax.yaxis.set_minor_formatter]:
163+
formatter = ScalarFormatter()
164+
formatter.set_scientific(False)
165+
set_formatter(formatter)
166+
ax.set_ylabel("effective clock period: target - worst slack (ps, log)", fontsize=9)
167+
ax.grid(axis="y", which="both", color="#e5e4e0", linewidth=0.6, zorder=0)
168+
ax.tick_params(colors=TEXT_SECONDARY, labelsize=8)
169+
for spine in ax.spines.values():
170+
spine.set_visible(False)
171+
ax.margins(x=0.12)
172+
173+
title = args.title
174+
if skipped:
175+
title += "\n(no period rule yet: {})".format(", ".join(skipped))
176+
ax.set_title(title, fontsize=11, color=TEXT_PRIMARY, loc="left")
177+
178+
handles = [
179+
plt.Line2D([], [], marker="o", linewidth=1.6, color=TEXT_SECONDARY),
180+
plt.Line2D(
181+
[],
182+
[],
183+
marker="D",
184+
linestyle="none",
185+
markersize=7,
186+
markerfacecolor=SURFACE,
187+
markeredgecolor=SYN_MARKER_EDGE,
188+
),
189+
]
190+
ax.legend(
191+
handles,
192+
["regular flow (rules-base.json)", "OpenROAD-SYN synth (rules-syn.json)"],
193+
loc="upper right",
194+
fontsize=8,
195+
frameon=False,
196+
)
197+
198+
fig.tight_layout()
199+
fig.savefig(args.output, facecolor=fig.get_facecolor())
200+
print(f"Wrote {args.output} ({plotted} designs, {len(skipped)} skipped)")
201+
202+
203+
if __name__ == "__main__":
204+
main()

0 commit comments

Comments
 (0)