|
| 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