Skip to content

Commit aa12fb1

Browse files
eszpotanskiglatosinski
authored andcommitted
tools: Autotuner: Implement Vizier support
Signed-off-by: Eryk Szpotanski <eszpotanski@antmicro.com>
1 parent c22aebf commit aa12fb1

File tree

3 files changed

+676
-67
lines changed

3 files changed

+676
-67
lines changed

tools/AutoTuner/src/autotuner/distributed.py

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
from itertools import product
6868
from uuid import uuid4 as uuid
6969
from collections import namedtuple
70-
from multiprocessing import cpu_count
7170

7271
import numpy as np
7372
import torch
@@ -86,6 +85,7 @@
8685
from ax.service.ax_client import AxClient
8786

8887
from autotuner.utils import (
88+
add_common_args,
8989
openroad,
9090
consumer,
9191
parse_config,
@@ -269,30 +269,9 @@ def parse_arguments():
269269
tune_parser = subparsers.add_parser("tune")
270270
_ = subparsers.add_parser("sweep")
271271

272-
# DUT
273-
parser.add_argument(
274-
"--design",
275-
type=str,
276-
metavar="<gcd,jpeg,ibex,aes,...>",
277-
required=True,
278-
help="Name of the design for Autotuning.",
279-
)
280-
parser.add_argument(
281-
"--platform",
282-
type=str,
283-
metavar="<sky130hd,sky130hs,asap7,...>",
284-
required=True,
285-
help="Name of the platform for Autotuning.",
286-
)
272+
add_common_args(parser)
287273

288274
# Experiment Setup
289-
parser.add_argument(
290-
"--config",
291-
type=str,
292-
metavar="<path>",
293-
required=True,
294-
help="Configuration file that sets which knobs to use for Autotuning.",
295-
)
296275
parser.add_argument(
297276
"--experiment",
298277
type=str,
@@ -301,13 +280,6 @@ def parse_arguments():
301280
help="Experiment name. This parameter is used to prefix the"
302281
" FLOW_VARIANT and to set the Ray log destination.",
303282
)
304-
parser.add_argument(
305-
"--timeout",
306-
type=float,
307-
metavar="<float>",
308-
default=None,
309-
help="Time limit (in hours) for each trial run. Default is no limit.",
310-
)
311283
parser.add_argument(
312284
"--stop_stage",
313285
type=str,
@@ -382,50 +354,13 @@ def parse_arguments():
382354
)
383355

384356
# Workload
385-
parser.add_argument(
386-
"--jobs",
387-
type=int,
388-
metavar="<int>",
389-
default=int(np.floor(cpu_count() / 2)),
390-
help="Max number of concurrent jobs.",
391-
)
392-
parser.add_argument(
393-
"--openroad_threads",
394-
type=int,
395-
metavar="<int>",
396-
default=16,
397-
help="Max number of threads openroad can use.",
398-
)
399357
parser.add_argument(
400358
"--memory_limit",
401359
type=float,
402360
metavar="<float>",
403361
default=None,
404362
help="Maximum memory in GB that each trial job can use, process will be killed and not retried if it exceeds.",
405363
)
406-
parser.add_argument(
407-
"--server",
408-
type=str,
409-
metavar="<ip|servername>",
410-
default=None,
411-
help="The address of Ray server to connect.",
412-
)
413-
parser.add_argument(
414-
"--port",
415-
type=int,
416-
metavar="<int>",
417-
default=10001,
418-
help="The port of Ray server to connect.",
419-
)
420-
421-
parser.add_argument(
422-
"-v",
423-
"--verbose",
424-
action="count",
425-
default=0,
426-
help="Verbosity level.\n\t0: only print Ray status\n\t1: also print"
427-
" training stderr\n\t2: also print training stdout.",
428-
)
429364

430365
args = parser.parse_args()
431366
if args.mode == "tune":

tools/AutoTuner/src/autotuner/utils.py

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
##
3434
###############################################################################
3535

36+
import argparse
3637
import glob
3738
import json
3839
import os
@@ -68,6 +69,8 @@
6869
CONSTRAINTS_SDC = "constraint.sdc"
6970
# Name of the TCL script run before routing
7071
FASTROUTE_TCL = "fastroute.tcl"
72+
# URL to ORFS GitHub repository
73+
ORFS_URL = "https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts"
7174
DATE = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
7275

7376

@@ -363,6 +366,27 @@ def openroad(
363366
return metrics_file
364367

365368

369+
STAGES = list(
370+
enumerate(
371+
[
372+
"synth",
373+
"floorplan",
374+
"floorplan_io",
375+
"floorplan_tdms",
376+
"floorplan_macro",
377+
"floorplan_tap",
378+
"floorplan_pdn",
379+
"globalplace",
380+
"detailedplace",
381+
"cts",
382+
"globalroute",
383+
"detailedroute",
384+
"finish",
385+
]
386+
)
387+
)
388+
389+
366390
def read_metrics(file_name, stop_stage):
367391
"""
368392
Collects metrics to evaluate the user-defined objective function.
@@ -386,6 +410,7 @@ def read_metrics(file_name, stop_stage):
386410
num_drc = wirelength = 0
387411
else:
388412
num_drc = wirelength = "ERR"
413+
last_stage = -1
389414
for stage_name, value in data.items():
390415
if stage_name == "constraints" and len(value["clocks__details"]) > 0:
391416
clk_period = float(value["clocks__details"][0].split()[1])
@@ -407,6 +432,10 @@ def read_metrics(file_name, stop_stage):
407432
core_area = value["design__core__area"]
408433
if stage_name == stop_stage and "design__die__area" in value:
409434
die_area = value["design__die__area"]
435+
for i, stage_name in reversed(STAGES):
436+
if stage_name in data and [d for d in data[stage_name].values() if d != "ERR"]:
437+
last_stage = i
438+
break
410439
ret = {
411440
"clk_period": clk_period,
412441
"worst_slack": worst_slack,
@@ -559,6 +588,20 @@ def read_tune_pbt(name, this):
559588
return tune.choice(this["values"])
560589
return None
561590

591+
def read_vizier(this):
592+
dict_ = {}
593+
min_, max_ = this["minmax"]
594+
dict_["value"] = (min_, max_)
595+
if "scale_type" in this:
596+
dict_["scale_type"] = this["scale_type"]
597+
if min_ == max_:
598+
dict_["type"] = "fixed"
599+
elif this["type"] == "int":
600+
dict_["type"] = "int"
601+
elif this["type"] == "float":
602+
dict_["type"] = "float"
603+
return dict_
604+
562605
# Check file exists and whether it is a valid JSON file.
563606
assert os.path.isfile(file_name), f"File {file_name} not found."
564607
try:
@@ -605,6 +648,8 @@ def read_tune_pbt(name, this):
605648
config[key] = read_tune_pbt(key, value)
606649
elif mode == "tune":
607650
config[key] = read_tune(value)
651+
elif mode == "vizier":
652+
config[key] = read_vizier(value)
608653
if mode == "tune":
609654
config = apply_condition(config, data)
610655
return config, sdc_file, fr_file
@@ -675,3 +720,129 @@ def consumer(queue):
675720
print(f"[INFO TUN-0007] Scheduling run for parameter {name}.")
676721
ray.get(openroad_distributed.remote(*next_item))
677722
print(f"[INFO TUN-0008] Finished run for parameter {name}.")
723+
724+
725+
def add_common_args(parser: argparse.ArgumentParser):
726+
# DUT
727+
parser.add_argument(
728+
"--design",
729+
type=str,
730+
metavar="<gcd,jpeg,ibex,aes,...>",
731+
required=True,
732+
help="Name of the design for Autotuning.",
733+
)
734+
parser.add_argument(
735+
"--platform",
736+
type=str,
737+
metavar="<sky130hd,sky130hs,asap7,...>",
738+
required=True,
739+
help="Name of the platform for Autotuning.",
740+
)
741+
# Experiment Setup
742+
parser.add_argument(
743+
"--config",
744+
type=str,
745+
metavar="<path>",
746+
required=True,
747+
help="Configuration file that sets which knobs to use for Autotuning.",
748+
)
749+
parser.add_argument(
750+
"--timeout",
751+
type=float,
752+
metavar="<float>",
753+
default=None,
754+
help="Time limit (in hours) for each trial run. Default is no limit.",
755+
)
756+
# Workload
757+
parser.add_argument(
758+
"--openroad_threads",
759+
type=int,
760+
metavar="<int>",
761+
default=16,
762+
help="Max number of threads openroad can use.",
763+
)
764+
parser.add_argument(
765+
"-v",
766+
"--verbose",
767+
action="count",
768+
default=0,
769+
help="Verbosity level.\n\t0: only print status\n\t1: also print"
770+
" training stderr\n\t2: also print training stdout.",
771+
)
772+
773+
# Setup
774+
parser.add_argument(
775+
"--git_clean",
776+
action="store_true",
777+
help="Clean binaries and build files."
778+
" WARNING: may lose previous data."
779+
" Use carefully.",
780+
)
781+
parser.add_argument(
782+
"--git_clone",
783+
action="store_true",
784+
help="Force new git clone."
785+
" WARNING: may lose previous data."
786+
" Use carefully.",
787+
)
788+
parser.add_argument(
789+
"--git_clone_args",
790+
type=str,
791+
metavar="<str>",
792+
default="",
793+
help="Additional git clone arguments.",
794+
)
795+
parser.add_argument(
796+
"--git_latest", action="store_true", help="Use latest version of OpenROAD app."
797+
)
798+
parser.add_argument(
799+
"--git_or_branch",
800+
type=str,
801+
metavar="<str>",
802+
default="",
803+
help="OpenROAD app branch to use.",
804+
)
805+
parser.add_argument(
806+
"--git_orfs_branch",
807+
type=str,
808+
metavar="<str>",
809+
default="master",
810+
help="OpenROAD-flow-scripts branch to use.",
811+
)
812+
parser.add_argument(
813+
"--git_url",
814+
type=str,
815+
metavar="<url>",
816+
default=ORFS_URL,
817+
help="OpenROAD-flow-scripts repo URL to use.",
818+
)
819+
parser.add_argument(
820+
"--build_args",
821+
type=str,
822+
metavar="<str>",
823+
default="",
824+
help="Additional arguments given to ./build_openroad.sh.",
825+
)
826+
827+
# Workload
828+
parser.add_argument(
829+
"--jobs",
830+
type=int,
831+
metavar="<int>",
832+
default=int(np.floor(cpu_count() / 2)),
833+
help="Max number of concurrent jobs.",
834+
)
835+
parser.add_argument(
836+
"--server",
837+
type=str,
838+
metavar="<ip|servername>",
839+
default=None,
840+
help="The address of Ray server to connect.",
841+
)
842+
parser.add_argument(
843+
"--port",
844+
type=int,
845+
metavar="<int>",
846+
default=10001,
847+
help="The port of Ray server to connect.",
848+
)

0 commit comments

Comments
 (0)