1+ import argparse
12import glob
23import json
34import os
3233CONSTRAINTS_SDC = "constraint.sdc"
3334# Name of the TCL script run before routing
3435FASTROUTE_TCL = "fastroute.tcl"
36+ # URL to ORFS GitHub repository
37+ ORFS_URL = "https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts"
3538DATE = datetime .now ().strftime ("%Y-%m-%d-%H-%M-%S" )
3639
3740
@@ -295,6 +298,27 @@ def openroad(
295298 return metrics_file
296299
297300
301+ STAGES = list (
302+ enumerate (
303+ [
304+ "synth" ,
305+ "floorplan" ,
306+ "floorplan_io" ,
307+ "floorplan_tdms" ,
308+ "floorplan_macro" ,
309+ "floorplan_tap" ,
310+ "floorplan_pdn" ,
311+ "globalplace" ,
312+ "detailedplace" ,
313+ "cts" ,
314+ "globalroute" ,
315+ "detailedroute" ,
316+ "finish" ,
317+ ]
318+ )
319+ )
320+
321+
298322def read_metrics (file_name ):
299323 """
300324 Collects metrics to evaluate the user-defined objective function.
@@ -311,6 +335,7 @@ def read_metrics(file_name):
311335 design_area = "ERR"
312336 die_area = "ERR"
313337 core_area = "ERR"
338+ last_stage = - 1
314339 for stage_name , value in data .items ():
315340 if stage_name == "constraints" and len (value ["clocks__details" ]) > 0 :
316341 clk_period = float (value ["clocks__details" ][0 ].split ()[1 ])
@@ -332,6 +357,10 @@ def read_metrics(file_name):
332357 core_area = value ["design__core__area" ]
333358 if stage_name == "finish" and "design__die__area" in value :
334359 die_area = value ["design__die__area" ]
360+ for i , stage_name in reversed (STAGES ):
361+ if stage_name in data and [d for d in data [stage_name ].values () if d != "ERR" ]:
362+ last_stage = i
363+ break
335364 ret = {
336365 "clk_period" : clk_period ,
337366 "worst_slack" : worst_slack ,
@@ -466,6 +495,20 @@ def read_tune_pbt(name, this):
466495 if this ["type" ] == "float" :
467496 return tune .uniform (min_ , max_ )
468497
498+ def read_vizier (this ):
499+ dict_ = {}
500+ min_ , max_ = this ["minmax" ]
501+ dict_ ["value" ] = (min_ , max_ )
502+ if "scale_type" in this :
503+ dict_ ["scale_type" ] = this ["scale_type" ]
504+ if min_ == max_ :
505+ dict_ ["type" ] = "fixed"
506+ elif this ["type" ] == "int" :
507+ dict_ ["type" ] = "int"
508+ elif this ["type" ] == "float" :
509+ dict_ ["type" ] = "float"
510+ return dict_
511+
469512 # Check file exists and whether it is a valid JSON file.
470513 assert os .path .isfile (file_name ), f"File { file_name } not found."
471514 try :
@@ -512,6 +555,8 @@ def read_tune_pbt(name, this):
512555 config [key ] = read_tune_pbt (key , value )
513556 elif mode == "tune" :
514557 config [key ] = read_tune (value )
558+ elif mode == "vizier" :
559+ config [key ] = read_vizier (value )
515560 if mode == "tune" :
516561 config = apply_condition (config , data )
517562 return config , sdc_file , fr_file
@@ -650,3 +695,129 @@ def consumer(queue):
650695 print (f"[INFO TUN-0007] Scheduling run for parameter { name } ." )
651696 ray .get (openroad_distributed .remote (* next_item ))
652697 print (f"[INFO TUN-0008] Finished run for parameter { name } ." )
698+
699+
700+ def add_common_args (parser : argparse .ArgumentParser ):
701+ # DUT
702+ parser .add_argument (
703+ "--design" ,
704+ type = str ,
705+ metavar = "<gcd,jpeg,ibex,aes,...>" ,
706+ required = True ,
707+ help = "Name of the design for Autotuning." ,
708+ )
709+ parser .add_argument (
710+ "--platform" ,
711+ type = str ,
712+ metavar = "<sky130hd,sky130hs,asap7,...>" ,
713+ required = True ,
714+ help = "Name of the platform for Autotuning." ,
715+ )
716+ # Experiment Setup
717+ parser .add_argument (
718+ "--config" ,
719+ type = str ,
720+ metavar = "<path>" ,
721+ required = True ,
722+ help = "Configuration file that sets which knobs to use for Autotuning." ,
723+ )
724+ parser .add_argument (
725+ "--timeout" ,
726+ type = float ,
727+ metavar = "<float>" ,
728+ default = None ,
729+ help = "Time limit (in hours) for each trial run. Default is no limit." ,
730+ )
731+ # Workload
732+ parser .add_argument (
733+ "--openroad_threads" ,
734+ type = int ,
735+ metavar = "<int>" ,
736+ default = 16 ,
737+ help = "Max number of threads openroad can use." ,
738+ )
739+ parser .add_argument (
740+ "-v" ,
741+ "--verbose" ,
742+ action = "count" ,
743+ default = 0 ,
744+ help = "Verbosity level.\n \t 0: only print status\n \t 1: also print"
745+ " training stderr\n \t 2: also print training stdout." ,
746+ )
747+
748+ # Setup
749+ parser .add_argument (
750+ "--git_clean" ,
751+ action = "store_true" ,
752+ help = "Clean binaries and build files."
753+ " WARNING: may lose previous data."
754+ " Use carefully." ,
755+ )
756+ parser .add_argument (
757+ "--git_clone" ,
758+ action = "store_true" ,
759+ help = "Force new git clone."
760+ " WARNING: may lose previous data."
761+ " Use carefully." ,
762+ )
763+ parser .add_argument (
764+ "--git_clone_args" ,
765+ type = str ,
766+ metavar = "<str>" ,
767+ default = "" ,
768+ help = "Additional git clone arguments." ,
769+ )
770+ parser .add_argument (
771+ "--git_latest" , action = "store_true" , help = "Use latest version of OpenROAD app."
772+ )
773+ parser .add_argument (
774+ "--git_or_branch" ,
775+ type = str ,
776+ metavar = "<str>" ,
777+ default = "" ,
778+ help = "OpenROAD app branch to use." ,
779+ )
780+ parser .add_argument (
781+ "--git_orfs_branch" ,
782+ type = str ,
783+ metavar = "<str>" ,
784+ default = "master" ,
785+ help = "OpenROAD-flow-scripts branch to use." ,
786+ )
787+ parser .add_argument (
788+ "--git_url" ,
789+ type = str ,
790+ metavar = "<url>" ,
791+ default = ORFS_URL ,
792+ help = "OpenROAD-flow-scripts repo URL to use." ,
793+ )
794+ parser .add_argument (
795+ "--build_args" ,
796+ type = str ,
797+ metavar = "<str>" ,
798+ default = "" ,
799+ help = "Additional arguments given to ./build_openroad.sh." ,
800+ )
801+
802+ # Workload
803+ parser .add_argument (
804+ "--jobs" ,
805+ type = int ,
806+ metavar = "<int>" ,
807+ default = int (np .floor (cpu_count () / 2 )),
808+ help = "Max number of concurrent jobs." ,
809+ )
810+ parser .add_argument (
811+ "--server" ,
812+ type = str ,
813+ metavar = "<ip|servername>" ,
814+ default = None ,
815+ help = "The address of Ray server to connect." ,
816+ )
817+ parser .add_argument (
818+ "--port" ,
819+ type = int ,
820+ metavar = "<int>" ,
821+ default = 10001 ,
822+ help = "The port of Ray server to connect." ,
823+ )
0 commit comments