Skip to content

Commit 7daba05

Browse files
committed
flow: drill down — non-determinism enters in read_design_sources
The earlier three-way hash (`canonical`, `preabc`, `netlist`) showed all three differing between bazel-yosys and make-yosys even at matching versions (Yosys 0.65, ABC 1.01), but couldn't pinpoint which yosys pass introduces the drift. This commit adds three more hash points to bisect: post_read_sources : after `read_design_sources` (verilog/slang frontend only) post_hierarchy : after `hierarchy -check -top` (elaboration order) canonical_netlist : after `opt_clean -purge` (existing) post_synth_main : after `synth -run fine: -noabc` (main synth pipeline) preabc_netlist : immediately before `abc` (existing) netlist : post-ABC `1_2_yosys.v` (existing) Mechanism: `synth_preamble.tcl` defines a `write_state_hash` tcl proc that `setattr -unset src */mod` (so paths in src attributes don't make the hash bazel-vs-make path-dependent), `write_rtlil` to a temp, sha1sum, deletes the temp, and `puts` a `<metric>: <sha>` line to the yosys log. `genMetrics.py` greps the lines via `extractTagFromFile`. No new bazel artifacts ship; the existing `1_1_yosys_canonicalize.log` / `1_2_yosys.log` carry the SHAs. The `setattr -unset src` strip is now unconditional (the `SYNTH_REPEATABLE_BUILD`-gated block in `synth_canonicalize.tcl` becomes redundant since `write_state_hash` strips on first call; left in place as harmless idempotent backup). Src attributes are debug metadata that no downstream pass relies on for decisions. Verification on asap7/uart with same-version yosys/ABC on both sides: [INFO] synth__yosys__version pass test: 0.65 == 0.65 [INFO] synth__abc__version pass test: 1.01 == 1.01 [WARN] synth__post_read_sources__hash differs test: 39c975e8... == fc8ed9cc... [WARN] synth__post_hierarchy__hash differs test: 39c975e8... == fc8ed9cc... [WARN] synth__canonical_netlist__hash differs test: c1269aa7... == 579a132d... [WARN] synth__post_synth_main__hash differs test: 0cb19660... == 022a854d... [WARN] synth__preabc_netlist__hash differs test: 49c7bd07... == 6a40bd28... [WARN] synth__netlist__hash differs test: 5ed342e4... == c3163e94... Two findings fall out: 1. Non-determinism is born at `post_read_sources`. `hierarchy -check` is a no-op for uart (slang has already elaborated the top); `post_hierarchy` matches `post_read_sources` exactly on both sides. Every subsequent pass (opt_clean, synth pipeline, techmap+dfflibmap, ABC) faithfully propagates the entering divergence but does not introduce new divergence between bazel and make. 2. The slang frontend call is therefore the proximate site of the drift. Mechanism is consistent with yosys' pointer-keyed `IdString`/`dict` iteration: different memory layouts in the bazel-built and make-built yosys binaries assign different counter values to anonymous wires (visible as systematic `+3` offsets in `$<N>y` wire names in the canonical RTLIL diff). Next investigation: which yosys API call in `read_slang`'s implementation allocates IdStrings/dicts/pools in pointer order? That's the patch site. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent cb32ece commit 7daba05

6 files changed

Lines changed: 110 additions & 37 deletions

File tree

‎flow/designs/asap7/uart/rules-base.json‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,33 @@
99
"compare": "==",
1010
"level": "warning"
1111
},
12+
"synth__post_read_sources__hash": {
13+
"value": "fc8ed9cca61614e52bc7621061eb3fea9fc09786",
14+
"compare": "==",
15+
"level": "warning"
16+
},
17+
"synth__post_hierarchy__hash": {
18+
"value": "fc8ed9cca61614e52bc7621061eb3fea9fc09786",
19+
"compare": "==",
20+
"level": "warning"
21+
},
1222
"synth__canonical_netlist__hash": {
13-
"value": "51e1c96c1cbd84acbe6094554dfc328512dada66",
23+
"value": "579a132d7bd12d7a17c960889a88a625ba1bd761",
24+
"compare": "==",
25+
"level": "warning"
26+
},
27+
"synth__post_synth_main__hash": {
28+
"value": "022a854dceb7dfe23c650b960efd4a8bbf580602",
1429
"compare": "==",
1530
"level": "warning"
1631
},
1732
"synth__preabc_netlist__hash": {
18-
"value": "f1b261b2a091a9be65c846a11f71588d55210cee",
33+
"value": "6a40bd282d816cd8c48a4cbb4a8ceabc365ca6fb",
1934
"compare": "==",
2035
"level": "warning"
2136
},
2237
"synth__netlist__hash": {
23-
"value": "11a8cf6937376ae7e00f0afeee5304fa944a145e",
38+
"value": "c3163e9457e39e5d07c4030ce974232fc9e36f66",
2439
"compare": "==",
2540
"level": "warning"
2641
},

‎flow/scripts/synth.tcl‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ if {
194194
} else {
195195
synth -top $::env(DESIGN_NAME) -run fine: -noabc {*}$synth_full_args
196196
}
197+
write_state_hash synth__post_synth_main__hash
197198

198199
# Get rid of indigestibles
199200
chformal -remove
@@ -250,20 +251,9 @@ setundef -zero
250251

251252
# Fingerprint the design state immediately before ABC runs so the
252253
# `synth__preabc_netlist__hash` rules-base.json check can isolate
253-
# mid-level-yosys drift from ABC drift. Combined with
254-
# `synth__canonical_netlist__hash` (front-end + opt_clean snapshot)
255-
# and `synth__netlist__hash` (post-ABC `1_2_yosys.v`), this gives a
256-
# three-way bisection: front-end vs mid-level synth vs ABC.
257-
#
258-
# The RTLIL itself is written to a temp path, hashed, and deleted —
259-
# we only ship the SHA in the yosys log so we don't burden bazel's
260-
# action outputs with another large netlist artifact. See
261-
# flow/util/genMetrics.py for the matching log-extraction.
262-
set preabc_tmp $::env(RESULTS_DIR)/1_2_yosys_preabc.rtlil
263-
write_rtlil $preabc_tmp
264-
set preabc_sha [lindex [split [exec sha1sum $preabc_tmp]] 0]
265-
file delete $preabc_tmp
266-
puts "synth__preabc_netlist__hash: $preabc_sha"
254+
# mid-level-yosys drift from ABC drift. See `write_state_hash` in
255+
# synth_preamble.tcl for the dump+sha+delete mechanism.
256+
write_state_hash synth__preabc_netlist__hash
267257

268258
if {
269259
![env_var_exists_and_non_empty SYNTH_WRAPPED_OPERATORS] &&

‎flow/scripts/synth_canonicalize.tcl‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
source $::env(SCRIPTS_DIR)/synth_preamble.tcl
22
read_design_sources
3+
write_state_hash synth__post_read_sources__hash
34

45
hierarchy -check -top $::env(DESIGN_NAME)
6+
write_state_hash synth__post_hierarchy__hash
57

68
source_env_var_if_exists SYNTH_CANONICALIZE_TCL
79

810
# Get rid of unused modules
911
opt_clean -purge
12+
# `write_state_hash` above already stripped src attrs, so the
13+
# SYNTH_REPEATABLE_BUILD-gated stripping below is now redundant for
14+
# this script. Kept harmless (idempotent) for callers that source
15+
# SYNTH_CANONICALIZE_TCL hooks that may re-introduce src attrs.
1016
if { $::env(SYNTH_REPEATABLE_BUILD) } {
1117
# avoid source line and path info affecting the hash
1218
setattr -unset src *

‎flow/scripts/synth_preamble.tcl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@ yosys -import
33
source $::env(SCRIPTS_DIR)/util.tcl
44
erase_non_stage_variables synth
55

6+
# Bisect bazel-vs-make yosys drift into front-end / hierarchy /
7+
# mid-level synth / pre-ABC / post-ABC buckets. write_state_hash
8+
# dumps the current design state to a temp RTLIL, SHA-1's it,
9+
# deletes the temp, and emits a `<metric>: <sha>` line for
10+
# `genMetrics.py` to extract from the surrounding yosys log. No
11+
# new bazel artifacts are shipped — only the hash strings in the
12+
# existing 1_1_yosys_canonicalize.log / 1_2_yosys.log files.
13+
#
14+
# `setattr -unset src` strips file:line attribute lines from the
15+
# RTLIL before hashing so the hash is path-independent (bazel
16+
# sandbox paths differ from the make build's relative paths;
17+
# without stripping, hashes always differ trivially). The strip
18+
# is permanent for the rest of the yosys run, matching the
19+
# SYNTH_REPEATABLE_BUILD=1 path's behavior — src attributes are
20+
# debug metadata that no downstream pass relies on for decisions.
21+
proc write_state_hash { metric } {
22+
setattr -unset src *
23+
setattr -mod -unset src *
24+
set tmp $::env(RESULTS_DIR)/.${metric}.tmp.rtlil
25+
write_rtlil $tmp
26+
set sha [lindex [split [exec sha1sum $tmp]] 0]
27+
file delete $tmp
28+
puts "${metric}: $sha"
29+
}
30+
631
# Emit the ABC version into the yosys log so `genMetrics.py` can pick
732
# it up as `synth__abc__version` (a literal warning-level entry in
833
# `rules-base.json`). Combined with the yosys version banner already

‎flow/util/genMetrics.py‎

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,52 @@ def extract_metrics(
262262
rptPath + "/synth_stat.txt",
263263
)
264264

265-
# Netlist hashes: front-end / mid-level / post-ABC fingerprints
266-
# so the rules-base.json check (level=warning) flags where bazel-
267-
# built vs make-built yosys diverge. See flow/README.md "Triaging
268-
# a failing _test" → "Yosys-environment false positive".
265+
# Yosys-state fingerprints — front-end through post-ABC — so the
266+
# rules-base.json `level=warning` checks flag where bazel-built
267+
# vs make-built yosys diverge. See flow/README.md "Triaging a
268+
# failing _test" → "Yosys-environment false positive".
269269
#
270-
# canonical = after `read_design_sources` + `hierarchy -check` +
271-
# `opt_clean -purge` (front-end snapshot)
272-
# preabc = immediately before the main `abc` call (after
273-
# techmap, dfflibmap, setundef etc.)
274-
# netlist = `1_2_yosys.v`, post-ABC
270+
# post_read_sources = after `read_design_sources`
271+
# (verilog/slang frontend only)
272+
# post_hierarchy = after `hierarchy -check -top`
273+
# (elaboration order)
274+
# canonical_netlist = after `opt_clean -purge`
275+
# (= `1_1_yosys_canonicalize.rtlil`)
276+
# post_synth_main = after `synth -run fine: -noabc`
277+
# (main synth pipeline)
278+
# preabc_netlist = immediately before the main `abc` call
279+
# (techmap, dfflibmap, setundef etc.)
280+
# netlist = `1_2_yosys.v`, post-ABC
281+
#
282+
# All except `canonical_netlist` and `netlist` are emitted by
283+
# synth.tcl / synth_canonicalize.tcl via the `write_state_hash`
284+
# helper as `<metric>: <sha>` lines in the surrounding yosys log
285+
# (1_1_yosys_canonicalize.log or 1_2_yosys.log). `canonical`
286+
# and post-ABC come straight from `file_sha1` of the
287+
# already-emitted RTLIL / Verilog.
288+
for metric in ("synth__post_read_sources__hash",
289+
"synth__post_hierarchy__hash"):
290+
extractTagFromFile(
291+
metric,
292+
metrics_dict,
293+
rf"^{metric}:\s+([0-9a-f]{{40}})\s*$",
294+
logPath + "/1_1_yosys_canonicalize.log",
295+
t=str,
296+
required=False,
297+
)
275298
metrics_dict["synth__canonical_netlist__hash"] = file_sha1(
276299
resultPath + "/1_1_yosys_canonicalize.rtlil"
277300
)
278-
# `synth__preabc_netlist__hash` is emitted by synth.tcl as a
279-
# `synth__preabc_netlist__hash: <sha>` line in 1_2_yosys.log so we
280-
# don't have to ship the full pre-ABC RTLIL as a bazel artifact.
281-
extractTagFromFile(
282-
"synth__preabc_netlist__hash",
283-
metrics_dict,
284-
r"^synth__preabc_netlist__hash:\s+([0-9a-f]{40})\s*$",
285-
logPath + "/1_2_yosys.log",
286-
t=str,
287-
required=False,
288-
)
301+
for metric in ("synth__post_synth_main__hash",
302+
"synth__preabc_netlist__hash"):
303+
extractTagFromFile(
304+
metric,
305+
metrics_dict,
306+
rf"^{metric}:\s+([0-9a-f]{{40}})\s*$",
307+
logPath + "/1_2_yosys.log",
308+
t=str,
309+
required=False,
310+
)
289311
metrics_dict["synth__netlist__hash"] = file_sha1(resultPath + "/1_2_yosys.v")
290312

291313
# Yosys + ABC version fingerprints — surface bazel-vs-make

‎flow/util/genRuleFile.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,26 @@ def gen_rule_file(
8989
"compare": "==",
9090
"level": "warning",
9191
},
92+
"synth__post_read_sources__hash": {
93+
"mode": "literal",
94+
"compare": "==",
95+
"level": "warning",
96+
},
97+
"synth__post_hierarchy__hash": {
98+
"mode": "literal",
99+
"compare": "==",
100+
"level": "warning",
101+
},
92102
"synth__canonical_netlist__hash": {
93103
"mode": "literal",
94104
"compare": "==",
95105
"level": "warning",
96106
},
107+
"synth__post_synth_main__hash": {
108+
"mode": "literal",
109+
"compare": "==",
110+
"level": "warning",
111+
},
97112
"synth__preabc_netlist__hash": {
98113
"mode": "literal",
99114
"compare": "==",

0 commit comments

Comments
 (0)