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