Skip to content

Commit a5839b8

Browse files
oharboeclaude
andcommitted
flow: record yosys netlist hashes in rules-base.json (warning-level)
flow/README.md "Triaging a failing _test" → "Yosys-environment false positive" already calls out that bazel-built yosys and make-built yosys can produce different 1_2_yosys.v for the same RTL, drifting QoR past rules-base.json thresholds even though OpenROAD itself is bit-deterministic. Today the only way to spot the drift is to re-run `@bazel-orfs//:make-yosys-netlist`; if a designer has a freshly-failing _test in front of them, they have no way to see "the yosys netlist changed" vs "a real regression". Persist a fingerprint in rules-base.json instead so the next _test just prints it: - genMetrics.py: emit `synth__canonical_netlist__hash` (SHA-1 of 1_1_yosys_canonicalize.rtlil, the canonical RTLIL pre-ABC) and `synth__netlist__hash` (SHA-1 of 1_2_yosys.v, post-ABC). Having both lets the user see whether divergence is in the front-end flow or downstream of ABC. - genRuleFile.py: new `literal` mode passes the metric value through verbatim (no padding / rounding / float coercion). The two hash fields use it with `level: warning` + `compare: ==`, so `_update` writes them into rules-base.json and `_test` treats a hash mismatch as a diagnostic, not a failure. - checkMetadata.py: a warning-level mismatch previously printed "[WARN] field pass test: a == b" — confusing when a != b yet "pass" implied a match. Say "differs" instead so the hash mismatch reads naturally without changing the no-error contract (still doesn't increment ERRORS). rules-base.json files are unchanged in this commit; the next `_update` per design adds the two hash fields automatically, and existing _test runs are unaffected until that happens. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f626145 commit a5839b8

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

‎flow/util/checkMetadata.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,15 @@ def try_number(string):
106106
PRE = "[INFO]"
107107
CHECK = "pass"
108108
elif rule.get("level") == "warning":
109+
# Warning-level rules never fail the build, but the prior
110+
# message ("[WARN] field pass test: a == b") was misleading
111+
# when a != b -- the build_value clearly differed from the
112+
# rule_value yet "pass" implied a match. Say "differs"
113+
# instead so the diagnostic reads naturally for fields like
114+
# the netlist hash where the user wants visibility without
115+
# an error.
109116
PRE = "[WARN]"
110-
CHECK = "pass"
117+
CHECK = "differs"
111118
WARNS += 1
112119
else:
113120
PRE = "[ERROR]"

‎flow/util/genMetrics.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# information in specific files using regular expressions
66
# -----------------------------------------------------------------------------
77

8+
import hashlib
89
import os
910
import shutil
1011
from datetime import datetime, timedelta
@@ -190,6 +191,18 @@ def git_head_commit(git_exe, folder):
190191
)
191192

192193

194+
def file_sha1(path):
195+
"""SHA-1 of `path`, or "N/A" if absent. Read in chunks so large
196+
netlists don't blow the heap."""
197+
if not os.path.isfile(path):
198+
return "N/A"
199+
hasher = hashlib.sha1()
200+
with open(path, "rb") as f:
201+
for chunk in iter(lambda: f.read(16 * 1024 * 1024), b""):
202+
hasher.update(chunk)
203+
return hasher.hexdigest()
204+
205+
193206
def merge_jsons(root_path, output, files):
194207
paths = sorted(glob(os.path.join(root_path, files)))
195208
for path in paths:
@@ -249,6 +262,16 @@ def extract_metrics(
249262
rptPath + "/synth_stat.txt",
250263
)
251264

265+
# Netlist hashes: fingerprints of the canonical RTLIL (pre-ABC) and
266+
# the final post-synthesis Verilog so the rules-base.json check
267+
# (level=warning) flags when bazel-built vs make-built yosys
268+
# disagree for the same RTL. See flow/README.md "Triaging a failing
269+
# _test" → "Yosys-environment false positive" for context.
270+
metrics_dict["synth__canonical_netlist__hash"] = file_sha1(
271+
resultPath + "/1_1_yosys_canonicalize.rtlil"
272+
)
273+
metrics_dict["synth__netlist__hash"] = file_sha1(resultPath + "/1_2_yosys.v")
274+
252275
# Clocks
253276
# =========================================================================
254277
clk_list = read_sdc(resultPath + "/2_floorplan.sdc")

‎flow/util/genRuleFile.py‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ def gen_rule_file(
4646

4747
# dict format
4848
# 'metric_name': {
49-
# 'mode': <str>, one of ['direct', 'sum_fixed', 'period', 'padding',
50-
# 'period_padding', 'abs_padding', 'metric']
49+
# 'mode': <str>, one of ['direct', 'literal', 'sum_fixed', 'period',
50+
# 'padding', 'period_padding', 'abs_padding',
51+
# 'metric']. 'literal' propagates the metric
52+
# value verbatim (e.g. a hash string) and
53+
# skips all numeric padding/rounding.
5154
# 'padding': <float>, percentage of padding to use
5255
# 'fixed': <float>, sum this number instead of using % padding
5356
# 'round_value': <bool>, use the rounded value for the rule
@@ -71,6 +74,21 @@ def gen_rule_file(
7174
"level": "warning",
7275
},
7376
# synth
77+
# Yosys netlist hash fingerprints. `mode: literal` propagates
78+
# the string value verbatim; `level: warning` means a mismatch
79+
# surfaces as a [WARN] diagnostic in checkMetadata.py without
80+
# failing the build, matching how rules-base.json already
81+
# treats warning counts.
82+
"synth__canonical_netlist__hash": {
83+
"mode": "literal",
84+
"compare": "==",
85+
"level": "warning",
86+
},
87+
"synth__netlist__hash": {
88+
"mode": "literal",
89+
"compare": "==",
90+
"level": "warning",
91+
},
7492
"synth__design__instance__area__stdcell": {
7593
"mode": "padding",
7694
"padding": 15,
@@ -279,7 +297,7 @@ def gen_rule_file(
279297
if ":" in field:
280298
field = field.replace(":", "__")
281299
processed_fields.add(field)
282-
if isinstance(metrics[field], str):
300+
if isinstance(metrics[field], str) and option["mode"] != "literal":
283301
print(f"[WARNING] Skipping string field {field} = {metrics[field]}")
284302
continue
285303

@@ -291,6 +309,9 @@ def gen_rule_file(
291309
if option["mode"] == "direct":
292310
rule_value = metrics[field]
293311

312+
elif option["mode"] == "literal":
313+
rule_value = metrics[field]
314+
294315
elif option["mode"] == "sum_fixed":
295316
rule_value = metrics[field] + option["padding"]
296317

@@ -342,10 +363,11 @@ def gen_rule_file(
342363
print(f"[ERROR] Metric {field} has invalid mode {option['mode']}.")
343364
sys.exit(1)
344365

345-
if option["round_value"] and not isinf(rule_value):
346-
rule_value = int(round(rule_value))
347-
else:
348-
rule_value = float(f"{rule_value:.3g}")
366+
if option["mode"] != "literal":
367+
if option["round_value"] and not isinf(rule_value):
368+
rule_value = int(round(rule_value))
369+
else:
370+
rule_value = float(f"{rule_value:.3g}")
349371

350372
preserve_old_rule = (
351373
True

0 commit comments

Comments
 (0)