Skip to content

Commit 27c67bf

Browse files
authored
Merge pull request #3262 from jeffng-or/at-add-stop-stage-support
added support for AutoTuner to stop after a specified stage
2 parents 804e222 + c0c9825 commit 27c67bf

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

flow/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ clean_cts:
541541
route: $(RESULTS_DIR)/5_route.odb \
542542
$(RESULTS_DIR)/5_route.sdc
543543

544-
.PHONY: grt
544+
.PHONY: grt globalroute
545+
globalroute: grt
545546
grt: $(RESULTS_DIR)/5_1_grt.odb
546547

547548
# ==============================================================================

tools/AutoTuner/src/autotuner/distributed.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,16 @@ def step(self):
154154
install_path=INSTALL_PATH,
155155
)
156156
self.step_ += 1
157-
(score, effective_clk_period, num_drc) = self.evaluate(
158-
read_metrics(metrics_file)
157+
(score, effective_clk_period, num_drc, die_area) = self.evaluate(
158+
read_metrics(metrics_file, args.stop_stage)
159159
)
160160
# Feed the score back to Tune.
161161
# return must match 'metric' used in tune.run()
162162
return {
163163
METRIC: score,
164164
"effective_clk_period": effective_clk_period,
165165
"num_drc": num_drc,
166+
"die_area": die_area,
166167
}
167168

168169
def evaluate(self, metrics):
@@ -174,13 +175,13 @@ def evaluate(self, metrics):
174175
error = "ERR" in metrics.values()
175176
not_found = "N/A" in metrics.values()
176177
if error or not_found:
177-
return (ERROR_METRIC, "-", "-")
178+
return (ERROR_METRIC, "-", "-", "-")
178179
effective_clk_period = metrics["clk_period"] - metrics["worst_slack"]
179180
num_drc = metrics["num_drc"]
180181
gamma = effective_clk_period / 10
181182
score = effective_clk_period
182183
score = score * (100 / self.step_) + gamma * num_drc
183-
return (score, effective_clk_period, num_drc)
184+
return (score, effective_clk_period, num_drc, metrics["die_area"])
184185

185186
def _is_valid_config(self, config):
186187
"""
@@ -247,13 +248,13 @@ def evaluate(self, metrics):
247248
error = "ERR" in metrics.values() or "ERR" in reference.values()
248249
not_found = "N/A" in metrics.values() or "N/A" in reference.values()
249250
if error or not_found:
250-
return (ERROR_METRIC, "-", "-")
251+
return (ERROR_METRIC, "-", "-", "-")
251252
ppa = self.get_ppa(metrics)
252253
gamma = ppa / 10
253254
score = ppa * (self.step_ / 100) ** (-1) + (gamma * metrics["num_drc"])
254255
effective_clk_period = metrics["clk_period"] - metrics["worst_slack"]
255256
num_drc = metrics["num_drc"]
256-
return (score, effective_clk_period, num_drc)
257+
return (score, effective_clk_period, num_drc, metrics["die_area"])
257258

258259

259260
def parse_arguments():
@@ -307,6 +308,14 @@ def parse_arguments():
307308
default=None,
308309
help="Time limit (in hours) for each trial run. Default is no limit.",
309310
)
311+
parser.add_argument(
312+
"--stop_stage",
313+
type=str,
314+
metavar="<str>",
315+
choices=["floorplan", "place", "cts", "globalroute", "route", "finish"],
316+
default="finish",
317+
help="Name of the stage to stop after. Default is finish.",
318+
)
310319
tune_parser.add_argument(
311320
"--resume",
312321
action="store_true",
@@ -598,7 +607,7 @@ def main():
598607
TrainClass = set_training_class(args.eval)
599608
# PPAImprov requires a reference file to compute training scores.
600609
if args.eval == "ppa-improv":
601-
reference = read_metrics(args.reference)
610+
reference = read_metrics(args.reference, args.stop_stage)
602611

603612
tune_args = dict(
604613
name=args.experiment,

tools/AutoTuner/src/autotuner/utils.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def openroad(
330330
make_command += f" FLOW_VARIANT={flow_variant} {parameters}"
331331
make_command += " EQUIVALENCE_CHECK=0"
332332
make_command += f" NUM_CORES={args.openroad_threads} SHELL=bash"
333+
if args.stop_stage != "finish":
334+
make_command += f" {args.stop_stage}"
333335
run_command(
334336
args,
335337
make_command,
@@ -358,22 +360,29 @@ def openroad(
358360
return metrics_file
359361

360362

361-
def read_metrics(file_name):
363+
def read_metrics(file_name, stop_stage):
362364
"""
363365
Collects metrics to evaluate the user-defined objective function.
366+
367+
stop_stage indicates the last stage executed, so get most of the metrics
368+
from that stage. The default stop stage is "finish". But if the run stops
369+
before "finish", then no need to extract the metrics from the route stage,
370+
so set them to 0
364371
"""
365372
with open(file_name) as file:
366373
data = json.load(file)
367374
clk_period = 9999999
368375
worst_slack = "ERR"
369-
wirelength = "ERR"
370-
num_drc = "ERR"
371376
total_power = "ERR"
372377
core_util = "ERR"
373378
final_util = "ERR"
374379
design_area = "ERR"
375380
die_area = "ERR"
376381
core_area = "ERR"
382+
if stop_stage != "finish":
383+
num_drc = wirelength = 0
384+
else:
385+
num_drc = wirelength = "ERR"
377386
for stage_name, value in data.items():
378387
if stage_name == "constraints" and len(value["clocks__details"]) > 0:
379388
clk_period = float(value["clocks__details"][0].split()[1])
@@ -383,17 +392,17 @@ def read_metrics(file_name):
383392
num_drc = value["route__drc_errors"]
384393
if stage_name == "detailedroute" and "route__wirelength" in value:
385394
wirelength = value["route__wirelength"]
386-
if stage_name == "finish" and "timing__setup__ws" in value:
395+
if stage_name == stop_stage and "timing__setup__ws" in value:
387396
worst_slack = value["timing__setup__ws"]
388-
if stage_name == "finish" and "power__total" in value:
397+
if stage_name == stop_stage and "power__total" in value:
389398
total_power = value["power__total"]
390-
if stage_name == "finish" and "design__instance__utilization" in value:
399+
if stage_name == stop_stage and "design__instance__utilization" in value:
391400
final_util = value["design__instance__utilization"]
392-
if stage_name == "finish" and "design__instance__area" in value:
401+
if stage_name == stop_stage and "design__instance__area" in value:
393402
design_area = value["design__instance__area"]
394-
if stage_name == "finish" and "design__core__area" in value:
403+
if stage_name == stop_stage and "design__core__area" in value:
395404
core_area = value["design__core__area"]
396-
if stage_name == "finish" and "design__die__area" in value:
405+
if stage_name == stop_stage and "design__die__area" in value:
397406
die_area = value["design__die__area"]
398407
ret = {
399408
"clk_period": clk_period,

0 commit comments

Comments
 (0)