Skip to content

Commit c19a45c

Browse files
eszpotanskiglatosinski
authored andcommitted
tools: Autotuner: Add --stop-stage argument
Signed-off-by: Eryk Szpotanski <eszpotanski@antmicro.com>
1 parent aa12fb1 commit c19a45c

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

tools/AutoTuner/src/autotuner/distributed.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def step(self):
152152
parameters=self.parameters,
153153
flow_variant=self._variant,
154154
install_path=INSTALL_PATH,
155+
stage=args.stop_stage,
155156
)
156157
self.step_ += 1
157158
(score, effective_clk_period, num_drc, die_area) = self.evaluate(
@@ -280,14 +281,6 @@ def parse_arguments():
280281
help="Experiment name. This parameter is used to prefix the"
281282
" FLOW_VARIANT and to set the Ray log destination.",
282283
)
283-
parser.add_argument(
284-
"--stop_stage",
285-
type=str,
286-
metavar="<str>",
287-
choices=["floorplan", "place", "cts", "globalroute", "route", "finish"],
288-
default="finish",
289-
help="Name of the stage to stop after. Default is finish.",
290-
)
291284
tune_parser.add_argument(
292285
"--resume",
293286
action="store_true",

tools/AutoTuner/src/autotuner/utils.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
set_input_delay [expr $clk_period * $clk_io_pct] -clock $clk_name $non_clock_inputs
6666
set_output_delay [expr $clk_period * $clk_io_pct] -clock $clk_name [all_outputs]
6767
"""
68+
# Maps ORFS stage to a name of produced metrics
69+
STAGE_TO_METRICS = {
70+
"route": "detailedroute",
71+
"place": "detailedplace",
72+
"final": "finish",
73+
}
6874
# Name of the SDC file with constraints
6975
CONSTRAINTS_SDC = "constraint.sdc"
7076
# Name of the TCL script run before routing
@@ -296,6 +302,7 @@ def openroad(
296302
parameters,
297303
flow_variant,
298304
install_path=None,
305+
stage="",
299306
):
300307
"""
301308
Run OpenROAD-flow-scripts with a given set of parameters.
@@ -331,7 +338,7 @@ def openroad(
331338
limit = int(args.memory_limit * 1_000_000)
332339
make_command += f"ulimit -v {limit}; "
333340
make_command += f"make -C {base_dir}/flow DESIGN_CONFIG=designs/"
334-
make_command += f"{args.platform}/{args.design}/config.mk"
341+
make_command += f"{args.platform}/{args.design}/config.mk {stage}"
335342
make_command += f" PLATFORM={args.platform}"
336343
make_command += f" FLOW_VARIANT={flow_variant} {parameters}"
337344
make_command += " EQUIVALENCE_CHECK=0"
@@ -387,7 +394,7 @@ def openroad(
387394
)
388395

389396

390-
def read_metrics(file_name, stop_stage):
397+
def read_metrics(file_name, stop_stage=""):
391398
"""
392399
Collects metrics to evaluate the user-defined objective function.
393400
@@ -396,6 +403,7 @@ def read_metrics(file_name, stop_stage):
396403
before "finish", then no need to extract the metrics from the route stage,
397404
so set them to 0
398405
"""
406+
validated_stage = STAGE_TO_METRICS.get(stop_stage if stop_stage else "final", stop_stage)
399407
with open(file_name) as file:
400408
data = json.load(file)
401409
clk_period = 9999999
@@ -420,17 +428,17 @@ def read_metrics(file_name, stop_stage):
420428
num_drc = value["route__drc_errors"]
421429
if stage_name == "detailedroute" and "route__wirelength" in value:
422430
wirelength = value["route__wirelength"]
423-
if stage_name == stop_stage and "timing__setup__ws" in value:
431+
if stage_name == validated_stage and "timing__setup__ws" in value:
424432
worst_slack = value["timing__setup__ws"]
425-
if stage_name == stop_stage and "power__total" in value:
433+
if stage_name == validated_stage and "power__total" in value:
426434
total_power = value["power__total"]
427-
if stage_name == stop_stage and "design__instance__utilization" in value:
435+
if stage_name == validated_stage and "design__instance__utilization" in value:
428436
final_util = value["design__instance__utilization"]
429-
if stage_name == stop_stage and "design__instance__area" in value:
437+
if stage_name == validated_stage and "design__instance__area" in value:
430438
design_area = value["design__instance__area"]
431-
if stage_name == stop_stage and "design__core__area" in value:
439+
if stage_name == validated_stage and "design__core__area" in value:
432440
core_area = value["design__core__area"]
433-
if stage_name == stop_stage and "design__die__area" in value:
441+
if stage_name == validated_stage and "design__die__area" in value:
434442
die_area = value["design__die__area"]
435443
for i, stage_name in reversed(STAGES):
436444
if stage_name in data and [d for d in data[stage_name].values() if d != "ERR"]:
@@ -445,9 +453,15 @@ def read_metrics(file_name, stop_stage):
445453
"design_area": design_area,
446454
"core_area": core_area,
447455
"die_area": die_area,
448-
"wirelength": wirelength,
449-
"num_drc": num_drc,
450-
}
456+
"last_successful_stage": last_stage,
457+
} | (
458+
{
459+
"wirelength": wirelength,
460+
"num_drc": num_drc,
461+
}
462+
if validated_stage in ("detailedroute", "finish")
463+
else {}
464+
)
451465
return ret
452466

453467

@@ -706,6 +720,7 @@ def openroad_distributed(
706720
parameters=config,
707721
flow_variant=f"{uuid.uuid4()}-{variant}" if variant else f"{uuid.uuid4()}",
708722
install_path=install_path,
723+
stage=args.stop_stage,
709724
)
710725
duration = time.time() - t
711726
return metric_file, duration
@@ -746,6 +761,14 @@ def add_common_args(parser: argparse.ArgumentParser):
746761
required=True,
747762
help="Configuration file that sets which knobs to use for Autotuning.",
748763
)
764+
parser.add_argument(
765+
"--stop_stage",
766+
type=str,
767+
metavar="<str>",
768+
choices=["floorplan", "place", "cts", "globalroute", "route", "finish"],
769+
default="finish",
770+
help="Name of the stage to stop after. Default is finish.",
771+
)
749772
parser.add_argument(
750773
"--timeout",
751774
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, stop_stage=args.stop_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)