Skip to content

Commit ea71270

Browse files
authored
Merge pull request #3077 from Pinata-Consulting/rules-json
Add RULES_JSON and makefile rules more consistent with the do-something pattern
2 parents 0cf17a2 + 3ce8a5b commit ea71270

File tree

4 files changed

+92
-47
lines changed

4 files changed

+92
-47
lines changed

docs/user/FlowVariables.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ configuration file.
163163
| <a name="RTLMP_RPT_DIR"></a>RTLMP_RPT_DIR| Path to the directory where reports are saved.| | |
164164
| <a name="RTLMP_SIGNATURE_NET_THRESHOLD"></a>RTLMP_SIGNATURE_NET_THRESHOLD| Minimum number of connections between two clusters to be identified as connected.| 50| |
165165
| <a name="RTLMP_WIRELENGTH_WT"></a>RTLMP_WIRELENGTH_WT| Weight for half-perimiter wirelength.| 100.0| |
166+
| <a name="RULES_JSON"></a>RULES_JSON| json files with the metrics baseline regression rules. In the ORFS Makefile, this defaults to $DESIGN_DIR/rules-base.json, but ORFS does not mandate the users source directory layout and this can be placed elsewhere when the user sets up an ORFS config.mk or from bazel-orfs.| | |
166167
| <a name="RUN_LOG_NAME_STEM"></a>RUN_LOG_NAME_STEM| Stem of the log file name, the log file will be named `$(LOG_DIR)/$(RUN_LOG_NAME_STEM).log`.| run| |
167168
| <a name="RUN_SCRIPT"></a>RUN_SCRIPT| Path to script to run from `make run`, python or tcl script detected by .py or .tcl extension.| | |
168169
| <a name="SC_LEF"></a>SC_LEF| Path to technology standard cell LEF file.| | |
@@ -370,6 +371,10 @@ configuration file.
370371

371372
- [ABSTRACT_SOURCE](#ABSTRACT_SOURCE)
372373

374+
## test variables
375+
376+
- [RULES_JSON](#RULES_JSON)
377+
373378
## All stages variables
374379

375380

flow/scripts/variables.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,3 +923,12 @@ FLOW_VARIANT:
923923
description: >
924924
Flow variant to use, used in the flow variant directory name.
925925
default: base
926+
RULES_JSON:
927+
description: >
928+
json files with the metrics baseline regression rules.
929+
In the ORFS Makefile, this defaults to $DESIGN_DIR/rules-base.json,
930+
but ORFS does not mandate the users source directory layout and
931+
this can be placed elsewhere when the user sets up an ORFS
932+
config.mk or from bazel-orfs.
933+
stages:
934+
- test

flow/util/genRuleFile.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,34 @@
77
import argparse
88
import json
99
import operator
10+
import os
1011
import sys
1112

1213

1314
def gen_rule_file(
14-
design_dir,
15+
rules_file,
16+
new_rules_file,
1517
update,
1618
tighten,
1719
failing,
1820
variant,
19-
metrics=None,
21+
metrics_file=None,
2022
metrics_to_consider=[],
2123
):
24+
print(f"{os.path.normpath(rules_file)} updates:")
2225

23-
golden_metrics = f"metadata-{variant}-ok.json"
24-
if isinstance(metrics, str) and isfile(metrics):
25-
with open(metrics, "r") as f:
26-
metrics = json.load(f)
27-
elif isfile(golden_metrics):
28-
with open(golden_metrics, "r") as f:
29-
metrics = json.load(f)
26+
with open(metrics_file, "r") as f:
27+
metrics = json.load(f)
3028
if not isinstance(metrics, dict):
31-
print(f"[ERROR] Invalid format for reference metrics {design_dir}")
29+
print(f"[ERROR] Invalid format for reference metrics {metrics_file}")
3230
sys.exit(1)
3331

34-
original_directory = getcwd()
35-
chdir(design_dir)
36-
rules_file = f"rules-{variant}.json"
3732
rules = dict()
38-
3933
if isfile(rules_file):
4034
with open(rules_file, "r") as f:
4135
OLD_RULES = json.load(f)
4236
else:
43-
print(f"[WARNING] Rules file not found {design_dir}")
37+
print(f"[WARNING] No old rules file found {rules_file}")
4438
OLD_RULES = None
4539

4640
# dict format
@@ -189,10 +183,7 @@ def gen_rule_file(
189183
change_str = ""
190184
for field, option in rules_dict.items():
191185
if field not in metrics.keys():
192-
print(
193-
f"[ERROR] Metric {field} not found in "
194-
f"metrics file: {metrics_file} or golden metrics."
195-
)
186+
print(f"[ERROR] Metric {field} not found")
196187
sys.exit(1)
197188

198189
if isinstance(metrics[field], str):
@@ -305,16 +296,13 @@ def gen_rule_file(
305296
rules[field] = dict(value=rule_value, compare=option["compare"])
306297

307298
if len(change_str) > 0:
308-
print(design_dir)
309299
print(format_str.format("Metric", "Old", "New", "Type"), end="")
310300
print(format_str.format("------", "---", "---", "----"), end="")
311301
print(change_str)
312302

313-
with open(rules_file, "w") as f:
303+
with open(new_rules_file, "w") as f:
314304
json.dump(rules, f, indent=4)
315305

316-
chdir(original_directory)
317-
318306

319307
def comma_separated_list(value):
320308
if value is None or value == "all":
@@ -326,7 +314,6 @@ def comma_separated_list(value):
326314
parser = argparse.ArgumentParser(
327315
description="Generates or updates rules file for CI."
328316
)
329-
parser.add_argument("dir", help="Path to the design directory.")
330317
parser.add_argument(
331318
"-v", "--variant", default="base", help='Flow variant [default="base"].'
332319
)
@@ -358,6 +345,18 @@ def comma_separated_list(value):
358345
default=None,
359346
help="Reference metadata file.",
360347
)
348+
parser.add_argument(
349+
"--rules",
350+
type=str,
351+
default=None,
352+
help="Rules input file.",
353+
)
354+
parser.add_argument(
355+
"--new-rules",
356+
type=str,
357+
default=None,
358+
help="Rules output file.",
359+
)
361360
parser.add_argument(
362361
"-m",
363362
"--metrics",
@@ -376,7 +375,8 @@ def comma_separated_list(value):
376375
sys.exit(1)
377376

378377
gen_rule_file(
379-
args.dir,
378+
args.rules,
379+
args.new_rules,
380380
args.update,
381381
args.tighten,
382382
args.failing,

flow/util/utils.mk

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,80 @@
11
# Utilities
22
#===============================================================================
33
.PHONY: metadata
4-
metadata: finish
4+
metadata: finish metadata-generate metadata-check
5+
6+
.PHONY: metadata-generate
7+
metadata-generate:
8+
@mkdir -p $(REPORTS_DIR)
59
@echo $(DESIGN_DIR) > $(REPORTS_DIR)/design-dir.txt
610
@$(UTILS_DIR)/genMetrics.py -d $(DESIGN_NICKNAME) \
7-
-p $(PLATFORM) \
8-
-v $(FLOW_VARIANT) \
9-
-o $(REPORTS_DIR)/metadata-$(FLOW_VARIANT).json 2>&1 \
10-
| tee $(REPORTS_DIR)/gen-metrics-$(FLOW_VARIANT)-check.log
11+
-p $(PLATFORM) \
12+
-v $(FLOW_VARIANT) \
13+
-o $(REPORTS_DIR)/metadata.json 2>&1 \
14+
| tee $(abspath $(REPORTS_DIR)/metadata-generate.log)
15+
16+
export RULES_JSON ?= $(DESIGN_DIR)/rules-$(FLOW_VARIANT).json
17+
18+
.PHONY: metadata-check
19+
metadata-check:
1120
@$(UTILS_DIR)/checkMetadata.py \
12-
-m $(REPORTS_DIR)/metadata-$(FLOW_VARIANT).json \
13-
-r $(DESIGN_DIR)/rules-$(FLOW_VARIANT).json 2>&1 \
14-
| tee $(REPORTS_DIR)/metadata-$(FLOW_VARIANT)-check.log
21+
-m $(REPORTS_DIR)/metadata.json \
22+
-r $(RULES_JSON) 2>&1 \
23+
| tee $(abspath $(REPORTS_DIR)/metadata-check.log)
1524

1625
.PHONY: clean_metadata
1726
clean_metadata:
18-
rm -f $(REPORTS_DIR)/metadata-$(FLOW_VARIANT)-check.log
19-
rm -f $(REPORTS_DIR)/metadata-$(FLOW_VARIANT).json
27+
rm -f $(REPORTS_DIR)/design-dir.txt
28+
rm -f $(REPORTS_DIR)/metadata*.*
2029

2130
.PHONY: update_ok
2231
update_ok: update_rules
2332

2433
.PHONY: update_metadata
2534
update_metadata:
26-
cp -f $(REPORTS_DIR)/metadata-$(FLOW_VARIANT).json \
35+
cp -f $(REPORTS_DIR)/metadata.json \
2736
$(DESIGN_DIR)/metadata-$(FLOW_VARIANT)-ok.json
2837

38+
.PHONY: do-update_rules
39+
do-update_rules:
40+
@mkdir -p $(REPORTS_DIR)
41+
$(UTILS_DIR)/genRuleFile.py \
42+
--rules $(RULES_JSON) \
43+
--new-rules $(REPORTS_DIR)/rules.json \
44+
--reference $(REPORTS_DIR)/metadata.json \
45+
--variant $(FLOW_VARIANT) \
46+
--failing \
47+
--tighten
48+
49+
.PHONY: do-copy_update_rules
50+
do-copy_update_rules:
51+
cp -f $(REPORTS_DIR)/rules.json \
52+
$(RULES_JSON)
53+
2954
.PHONY: update_rules
30-
update_rules:
31-
$(UTILS_DIR)/genRuleFile.py $(DESIGN_DIR) \
32-
--reference $(REPORTS_DIR)/metadata-$(FLOW_VARIANT).json \
33-
--variant $(FLOW_VARIANT) \
34-
--failing \
35-
--tighten
55+
update_rules: do-update_rules do-copy_update_rules
56+
57+
.PHONY: do-update_rules_force
58+
do-update_rules_force:
59+
@mkdir -p $(REPORTS_DIR)
60+
$(UTILS_DIR)/genRuleFile.py \
61+
--rules $(RULES_JSON) \
62+
--new-rules $(REPORTS_DIR)/rules.json \
63+
--reference $(REPORTS_DIR)/metadata.json \
64+
--variant $(FLOW_VARIANT) \
65+
--update
3666

3767
.PHONY: update_rules_force
38-
update_rules_force:
39-
$(UTILS_DIR)/genRuleFile.py $(DESIGN_DIR) --variant $(FLOW_VARIANT) --update
68+
update_rules_force: do-update_rules_force
69+
cp -f $(REPORTS_DIR)/rules.json \
70+
$(RULES_JSON)
4071

4172
.PHONY: update_metadata_autotuner
4273
update_metadata_autotuner:
4374
@$(UTILS_DIR)/genMetrics.py -d $(DESIGN_NICKNAME) \
44-
-p $(PLATFORM) \
45-
-v $(FLOW_VARIANT) \
46-
-o $(DESIGN_DIR)/metadata-$(FLOW_VARIANT)-at.json -x
75+
-p $(PLATFORM) \
76+
-v $(FLOW_VARIANT) \
77+
-o $(DESIGN_DIR)/metadata-$(FLOW_VARIANT)-at.json -x
4778

4879
#-------------------------------------------------------------------------------
4980

0 commit comments

Comments
 (0)