3333##
3434###############################################################################
3535
36+ import argparse
3637import glob
3738import json
3839import os
6869CONSTRAINTS_SDC = "constraint.sdc"
6970# Name of the TCL script run before routing
7071FASTROUTE_TCL = "fastroute.tcl"
72+ # URL to ORFS GitHub repository
73+ ORFS_URL = "https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts"
7174DATE = 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+
366390def 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 \t 0: only print status\n \t 1: also print"
770+ " training stderr\n \t 2: 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