-
Notifications
You must be signed in to change notification settings - Fork 5
/
sweep.bzl
149 lines (136 loc) · 5.25 KB
/
sweep.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""Sweep OpenROAD stages"""
load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_run", "set")
load(":write_binary.bzl", "write_binary")
all_stages = [
"floorplan",
"place",
"cts",
"grt",
"route",
"final",
]
def orfs_sweep(
name,
arguments,
sweep,
verilog_files,
stage_sources,
other_variants = {},
stage = "floorplan",
abstract_stage = "final",
macros = [],
visibility = ["//visibility:private"]):
"""Run a sweep of OpenROAD stages
Args:
name: Verilog module name
arguments: dictionary of the base variables for the flow
sweep: The dictionary describing the variables to sweep
other_variants: Dictionary with other variants to generate, but not as part of the sweep
stage: The stage to do the sweep on
macros: name of modules to use as macros
verilog_files: The Verilog files to build
stage_sources: dictionary with list of sources to use for the stage
abstract_stage: generate abstract from this stage
visibility: list of visibility labels
"""
sweep_json = {
"name": name,
"base": arguments,
"sweep": sweep,
"stage": stage,
"stages": all_stages[0:all_stages.index(stage) + 1],
}
write_binary(
name = name + "_sweep.json",
data = str(sweep_json),
)
all_variants = sweep | other_variants
for variant in all_variants:
orfs_flow(
name = name,
arguments = arguments | all_variants[variant].get("variables", {}),
macros = [
m
for m in macros
if m not in all_variants[variant].get("dissolve", [])
] + all_variants[variant].get("macros", []),
previous_stage = all_variants[variant].get("previous_stage", {}),
renamed_inputs = all_variants[variant].get("renamed_inputs", {}),
stage_arguments = all_variants[variant].get("stage_arguments", {}),
stage_sources = {
stage: set(stage_sources.get(stage, []) + all_variants[variant].get("stage_sources", {}).get(stage, []))
for stage in set(stage_sources.keys() + all_variants[variant].get("stage_sources", {}).keys())
},
variant = variant,
verilog_files = verilog_files,
abstract_stage = abstract_stage,
visibility = visibility,
)
native.filegroup(
name = name + "_" + variant + "_odb",
srcs = [":" + name + "_" + ("" if variant == "base" else variant + "_") + sweep_json["stage"]],
output_group = ("5_1_grt" if sweep_json["stage"] == "grt" else str(sweep_json["stages"].index(sweep_json["stage"]) + 2) + "_" + sweep_json["stage"]) +
".odb",
visibility = [":__subpackages__"],
)
orfs_run(
name = name + "_" + variant + "_report",
src = ":" + name + "_" + ("" if variant == "base" else variant + "_") + sweep_json["stage"],
outs = [
name + "_" + variant + ".txt",
],
arguments = {
"ODB_FILE": "$(location :" + name + "_" + variant + "_odb)",
"OUTPUT": "$(location :" + name + "_" + variant + ".txt)",
},
data = [":" + name + "_" + variant + "_odb"],
script = Label(":sweep-wns.tcl"),
visibility = visibility,
)
native.filegroup(
name = name + "_" + variant + "_logs",
srcs = [":" + name + "_" + ("" if variant == "base" else variant + "_") + stage for stage in sweep_json["stages"]],
output_group = "logs",
visibility = visibility,
)
# This can be built in parallel, but grt needs to be build in serial, or
# we will run out of memory
native.filegroup(
name = name + "_sweep_parallel",
srcs = [name + "_" + ("" if variant == "base" else variant + "_") + "cts" for variant in sweep],
visibility = visibility,
)
native.genrule(
name = name + "_wns_report",
srcs = [
Label(":wns_report.py"),
name + "_sweep.json",
] + [":" + name + "_" + variant + ".txt" for variant in sweep] +
[":" + name + "_" + variant + "_logs" for variant in sweep],
outs = [name + "_wns_report.md"],
cmd = (
"$(location " + str(Label(":wns_report.py")) + ") > $@" +
" $(location :" + name + "_sweep.json)"
),
visibility = visibility,
)
native.filegroup(
name = name + "_repair_logs",
srcs = [
":" + name + "_" + ("" if variant == "base" else variant + "_") + stage
for stage in sweep_json["stages"]
for variant in sweep
],
output_group = "logs",
visibility = visibility,
)
native.genrule(
name = name + "_plot_repair",
srcs = [
"plot-retiming.py",
name + "_repair_logs",
],
outs = [name + "_retiming.pdf"],
cmd = "$(location plot-retiming.py) $(location " + name + "_retiming.pdf) $(locations " + name + "_repair_logs)",
visibility = visibility,
)