Skip to content

Commit 9c32d65

Browse files
committed
tools: Autotuner: Add --to-stage argument
Signed-off-by: Eryk Szpotanski <[email protected]>
1 parent bc59e18 commit 9c32d65

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

tools/AutoTuner/src/autotuner/distributed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ def step(self):
110110
parameters=self.parameters,
111111
flow_variant=self._variant,
112112
install_path=INSTALL_PATH,
113+
stage=args.to_stage,
113114
)
114115
self.step_ += 1
115116
(score, effective_clk_period, num_drc) = self.evaluate(
116-
read_metrics(metrics_file)
117+
read_metrics(metrics_file, args.to_stage)
117118
)
118119
# Feed the score back to Tune.
119120
# return must match 'metric' used in tune.run()
@@ -455,7 +456,7 @@ def sweep():
455456
TrainClass = set_training_class(args.eval)
456457
# PPAImprov requires a reference file to compute training scores.
457458
if args.eval == "ppa-improv":
458-
reference = read_metrics(args.reference)
459+
reference = read_metrics(args.reference, args.to_stage)
459460

460461
tune_args = dict(
461462
name=args.experiment,

tools/AutoTuner/src/autotuner/utils.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
set_input_delay [expr $clk_period * $clk_io_pct] -clock $clk_name $non_clock_inputs
3030
set_output_delay [expr $clk_period * $clk_io_pct] -clock $clk_name [all_outputs]
3131
"""
32+
# Maps ORFS stage to a name of produced metrics
33+
STAGE_TO_METRICS = {
34+
"route": "detailedroute",
35+
"place": "detailedplace",
36+
"final": "finish",
37+
}
3238
# Name of the SDC file with constraints
3339
CONSTRAINTS_SDC = "constraint.sdc"
3440
# Name of the TCL script run before routing
@@ -246,6 +252,7 @@ def openroad(
246252
flow_variant,
247253
path="",
248254
install_path=None,
255+
stage="",
249256
):
250257
"""
251258
Run OpenROAD-flow-scripts with a given set of parameters.
@@ -269,7 +276,7 @@ def openroad(
269276

270277
make_command = export_command
271278
make_command += f"make -C {base_dir}/flow DESIGN_CONFIG=designs/"
272-
make_command += f"{args.platform}/{args.design}/config.mk"
279+
make_command += f"{args.platform}/{args.design}/config.mk {stage}"
273280
make_command += f" PLATFORM={args.platform}"
274281
make_command += f" FLOW_VARIANT={flow_variant} {parameters}"
275282
make_command += " EQUIVALENCE_CHECK=0"
@@ -320,10 +327,11 @@ def openroad(
320327
)
321328

322329

323-
def read_metrics(file_name):
330+
def read_metrics(file_name, stage=""):
324331
"""
325332
Collects metrics to evaluate the user-defined objective function.
326333
"""
334+
metric_name = STAGE_TO_METRICS.get(stage if stage else "final", stage)
327335
with open(file_name) as file:
328336
data = json.load(file)
329337
clk_period = 9999999
@@ -346,17 +354,17 @@ def read_metrics(file_name):
346354
num_drc = value["route__drc_errors"]
347355
if stage_name == "detailedroute" and "route__wirelength" in value:
348356
wirelength = value["route__wirelength"]
349-
if stage_name == "finish" and "timing__setup__ws" in value:
357+
if stage_name == metric_name and "timing__setup__ws" in value:
350358
worst_slack = value["timing__setup__ws"]
351-
if stage_name == "finish" and "power__total" in value:
359+
if stage_name == metric_name and "power__total" in value:
352360
total_power = value["power__total"]
353-
if stage_name == "finish" and "design__instance__utilization" in value:
361+
if stage_name == metric_name and "design__instance__utilization" in value:
354362
final_util = value["design__instance__utilization"]
355-
if stage_name == "finish" and "design__instance__area" in value:
363+
if stage_name == metric_name and "design__instance__area" in value:
356364
design_area = value["design__instance__area"]
357-
if stage_name == "finish" and "design__core__area" in value:
365+
if stage_name == metric_name and "design__core__area" in value:
358366
core_area = value["design__core__area"]
359-
if stage_name == "finish" and "design__die__area" in value:
367+
if stage_name == metric_name and "design__die__area" in value:
360368
die_area = value["design__die__area"]
361369
for i, stage_name in reversed(STAGES):
362370
if stage_name in data and [d for d in data[stage_name].values() if d != "ERR"]:
@@ -371,9 +379,15 @@ def read_metrics(file_name):
371379
"design_area": design_area,
372380
"core_area": core_area,
373381
"die_area": die_area,
374-
"wirelength": wirelength,
375-
"num_drc": num_drc,
376-
}
382+
"last_successful_stage": last_stage,
383+
} | (
384+
{
385+
"wirelength": wirelength,
386+
"num_drc": num_drc,
387+
}
388+
if metric_name in ("detailedroute", "finish")
389+
else {}
390+
)
377391
return ret
378392

379393

@@ -682,6 +696,7 @@ def openroad_distributed(
682696
flow_variant=f"{uuid()}-{variant}",
683697
path=path,
684698
install_path=install_path,
699+
stage=args.to_stage,
685700
)
686701
duration = time() - t
687702
return metric_file, duration
@@ -722,6 +737,13 @@ def add_common_args(parser: argparse.ArgumentParser):
722737
required=True,
723738
help="Configuration file that sets which knobs to use for Autotuning.",
724739
)
740+
parser.add_argument(
741+
"--to-stage",
742+
type=str,
743+
choices=("floorplan", "place", "cts", "route", "finish"),
744+
default="",
745+
help="Run ORFS only to the given stage (inclusive)",
746+
)
725747
parser.add_argument(
726748
"--timeout",
727749
type=float,

tools/AutoTuner/src/autotuner/vizier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def evaluate(args: argparse.Namespace, metric_file: str) -> Dict[str, float]:
6464
Dictionary with metrics
6565
"""
6666
try:
67-
metrics = read_metrics(metric_file)
67+
metrics = read_metrics(metric_file, stage=args.to_stage)
6868
# Calculate difference of clock period and worst slack
6969
if metrics["clk_period"] != 9999999 and metrics["worst_slack"] != "ERR":
7070
metrics["clk_period-worst_slack"] = (

0 commit comments

Comments
 (0)