Skip to content

Commit 8ca0388

Browse files
oharboeclaude
andcommitted
util: synthesis-stage QoR check against the regular rules file
make metadata-check-synth gates a synthesis-only run on the synth__/constraints__ subset of the design's regular RULES_JSON (checkMetadata.py --only-prefix), and make metadata-synth runs synth + metadata-generate + that check. No per-variant rules files: the same rules-base.json that gates the full flow gates the fast signal, keeping the two congruent. genMetrics.py tolerates a synthesis-only tree (SDC falls back to 1_synth.sdc; grt/finish extraction is guarded; empty placeholder netlists hash as absent, matching a make run that never wrote them). synth_syn.tcl always writes the 1_synth.v gate-level netlist (write_lec_verilog, stripping physical-only masters) so the Bazel synth stage can declare it as an output in SYN mode. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent f255c15 commit 8ca0388

4 files changed

Lines changed: 68 additions & 15 deletions

File tree

‎flow/scripts/synth_syn.tcl‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,10 @@ orfs_write_db $::env(RESULTS_DIR)/1_synth.odb
7575
# out by OpenSTA that has no dependencies. Sole writer of
7676
# 1_synth.sdc.
7777
orfs_write_sdc $::env(RESULTS_DIR)/1_synth.sdc
78+
79+
# Gate-level netlist for LEC (write_lec_verilog strips physical-only
80+
# masters, matching the CTS-stage LEC convention) and any other netlist
81+
# consumer. The Bazel synthesis action declares this file as an output,
82+
# so it must be written unconditionally.
83+
source $::env(SCRIPTS_DIR)/lec_check.tcl
84+
write_lec_verilog 1_synth.v

‎flow/util/checkMetadata.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
)
3434
parser.add_argument("--metadata", "-m", required=True, help="The metadata file")
3535
parser.add_argument("--rules", "-r", required=True, nargs="+", help="The rules file")
36+
parser.add_argument(
37+
"--only-prefix",
38+
nargs="+",
39+
default=None,
40+
help="Check only rules whose field starts with one of these prefixes. "
41+
"Lets a partial run (e.g. synthesis-only) be gated by a full-flow "
42+
"rules file without tripping the missing-field error.",
43+
)
3644
args = parser.parse_args()
3745

3846
with open(args.metadata) as metadataFile:
@@ -46,6 +54,13 @@
4654
else:
4755
print(f"[WARN] File {filePath} not found")
4856

57+
if args.only_prefix:
58+
rules = {
59+
field: rule
60+
for field, rule in rules.items()
61+
if any(field.startswith(prefix) for prefix in args.only_prefix)
62+
}
63+
4964
if len(rules) == 0:
5065
print("No rules")
5166
sys.exit(1)

‎flow/util/genMetrics.py‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,12 @@ def git_head_commit(git_exe, folder):
192192

193193

194194
def file_sha1(path):
195-
"""SHA-1 of `path`, or "N/A" if absent. Read in chunks so large
195+
"""SHA-1 of `path`, or "N/A" if absent or empty. Empty counts as
196+
absent so Bazel's touched placeholder files (e.g. the canonicalize
197+
RTLIL under SYNTH_USE_SYN or SYNTH_NETLIST_FILES) hash the same as
198+
a make run that never wrote the file. Read in chunks so large
196199
netlists don't blow the heap."""
197-
if not os.path.isfile(path):
200+
if not os.path.isfile(path) or os.path.getsize(path) == 0:
198201
return "N/A"
199202
hasher = hashlib.sha1()
200203
with open(path, "rb") as f:
@@ -258,7 +261,13 @@ def extract_metrics(
258261

259262
# Clocks
260263
# =========================================================================
261-
clk_list = read_sdc(resultPath + "/2_floorplan.sdc")
264+
# Prefer the floorplan SDC; on a synthesis-only tree (e.g. the "syn"
265+
# flow variant stops after 1_synth) fall back to the canonicalized
266+
# synthesis SDC, which carries the same create_clock lines.
267+
sdc_file = resultPath + "/2_floorplan.sdc"
268+
if not os.path.isfile(sdc_file):
269+
sdc_file = resultPath + "/1_synth.sdc"
270+
clk_list = read_sdc(sdc_file)
262271
metrics_dict["constraints__clocks__count"] = len(clk_list)
263272
metrics_dict["constraints__clocks__details"] = clk_list
264273

@@ -277,22 +286,26 @@ def extract_metrics(
277286
# Global Route
278287
# =========================================================================
279288
merge_jsons(logPath, metrics_dict, "5_*.json")
280-
extractTagFromFile(
281-
"globalroute__timing__clock__slack",
282-
metrics_dict,
283-
"^\\[INFO FLW-....\\] Clock .* slack (\\S+)",
284-
logPath + "/5_1_grt.log",
285-
)
289+
# Guarded so a synthesis-only tree doesn't pollute the metadata with
290+
# "ERR" values for stages that never ran.
291+
if os.path.isfile(logPath + "/5_1_grt.log"):
292+
extractTagFromFile(
293+
"globalroute__timing__clock__slack",
294+
metrics_dict,
295+
"^\\[INFO FLW-....\\] Clock .* slack (\\S+)",
296+
logPath + "/5_1_grt.log",
297+
)
286298

287299
# Finish
288300
# =========================================================================
289301
merge_jsons(logPath, metrics_dict, "6_*.json")
290-
extractTagFromFile(
291-
"finish__timing__wns_percent_delay",
292-
metrics_dict,
293-
baseRegEx.format("finish slack div critical path delay", "(\\S+)"),
294-
rptPath + "/6_finish.rpt",
295-
)
302+
if os.path.isfile(rptPath + "/6_finish.rpt"):
303+
extractTagFromFile(
304+
"finish__timing__wns_percent_delay",
305+
metrics_dict,
306+
baseRegEx.format("finish slack div critical path delay", "(\\S+)"),
307+
rptPath + "/6_finish.rpt",
308+
)
296309

297310
extractGnuTime("finish", metrics_dict, logPath + "/6_report.log")
298311

‎flow/util/utils.mk‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
.PHONY: metadata
44
metadata: finish metadata-generate metadata-check
55

6+
# Synthesis-only metadata: generate and check QoR after just the synth
7+
# stage, without running the full flow. The synthesis-stage subset of
8+
# the design's regular rules file gates the run, so no per-variant
9+
# rules file needs to be committed.
10+
.PHONY: metadata-synth
11+
metadata-synth: export RULES_JSON = $(DESIGN_DIR)/rules-base.json
12+
metadata-synth: synth metadata-generate metadata-check-synth
13+
614
.PHONY: metadata-generate
715
metadata-generate:
816
mkdir -p $(REPORTS_DIR)
@@ -25,6 +33,16 @@ metadata-check:
2533
-r $(RULES_JSON) 2>&1 \
2634
| tee $(abspath $(REPORTS_DIR)/metadata-check.log)
2735

36+
# Check only the synthesis-stage subset of RULES_JSON, so a
37+
# synthesis-only run can be gated by the design's full-flow rules file.
38+
.PHONY: metadata-check-synth
39+
metadata-check-synth:
40+
$(PYTHON_EXE) $(UTILS_DIR)/checkMetadata.py \
41+
-m $(REPORTS_DIR)/metadata.json \
42+
-r $(RULES_JSON) \
43+
--only-prefix synth__ constraints__ 2>&1 \
44+
| tee $(abspath $(REPORTS_DIR)/metadata-check.log)
45+
2846
.PHONY: clean_metadata
2947
clean_metadata:
3048
rm -f $(REPORTS_DIR)/design-dir.txt

0 commit comments

Comments
 (0)