6969# Name of the TCL script run before routing
7070FASTROUTE_TCL = "fastroute.tcl"
7171DATE = datetime .now ().strftime ("%Y-%m-%d-%H-%M-%S" )
72+ # The worst of optimized metric
73+ ERROR_METRIC = 9e99
74+
75+
76+ def calculate_score (metrics , step = 1 ):
77+ """Calculate optimization score from metrics."""
78+ error = "ERR" in metrics .values ()
79+ not_found = "N/A" in metrics .values ()
80+
81+ if error or not_found :
82+ return (ERROR_METRIC , "-" , "-" , "-" )
83+
84+ effective_clk_period = metrics ["clk_period" ] - metrics ["worst_slack" ]
85+ num_drc = metrics ["num_drc" ]
86+ gamma = effective_clk_period / 10
87+ score = effective_clk_period * (100 / step ) + gamma * num_drc
88+
89+ return (score , effective_clk_period , num_drc , metrics ["die_area" ])
7290
7391
7492def write_sdc (variables , path , sdc_original , constraints_sdc ):
@@ -287,6 +305,21 @@ def run_command(
287305 raise RuntimeError
288306
289307
308+ def calculate_trial_path (args , base_dir , flow_variant ):
309+ """
310+ Calculate the log path and flow variant
311+ """
312+ flow_variant_with_experiment = f"{ args .experiment } /{ flow_variant } "
313+ log_path = os .path .abspath (
314+ os .path .join (
315+ base_dir ,
316+ f"flow/logs/{ args .platform } /{ args .design } " ,
317+ flow_variant_with_experiment ,
318+ )
319+ )
320+ return log_path , flow_variant_with_experiment
321+
322+
290323def openroad (
291324 args ,
292325 base_dir ,
@@ -297,10 +330,8 @@ def openroad(
297330 """
298331 Run OpenROAD-flow-scripts with a given set of parameters.
299332 """
300- # Make sure path ends in a slash, i.e., is a folder
301- flow_variant = f"{ args .experiment } /{ flow_variant } "
302- log_path = os .path .abspath (
303- os .path .join (base_dir , f"flow/logs/{ args .platform } /{ args .design } " , flow_variant )
333+ log_path , flow_variant = calculate_trial_path (
334+ args = args , base_dir = base_dir , flow_variant = flow_variant
304335 )
305336 report_path = os .path .abspath (
306337 os .path .join (
@@ -643,6 +674,20 @@ def openroad_distributed(
643674 variant = None ,
644675):
645676 """Simple wrapper to run openroad distributed with Ray."""
677+ if variant is None :
678+ variant_parts = []
679+ for key , value in config .items ():
680+ if key not in ["_SDC_FILE_PATH" , "_FR_FILE_PATH" ]:
681+ variant_parts .append (f"{ key } _{ value } " )
682+ variant = "_" .join (variant_parts ) if variant_parts else ""
683+ flow_variant = f"{ uuid .uuid4 ()} -{ variant } " if variant else f"{ uuid .uuid4 ()} "
684+
685+ trial_path , _ = calculate_trial_path (
686+ args = args , base_dir = repo_dir , flow_variant = flow_variant
687+ )
688+
689+ os .makedirs (trial_path , exist_ok = True )
690+
646691 config = parse_config (
647692 config = config ,
648693 base_dir = repo_dir ,
@@ -651,15 +696,15 @@ def openroad_distributed(
651696 constraints_sdc = CONSTRAINTS_SDC ,
652697 fr_original = fr_original ,
653698 fastroute_tcl = FASTROUTE_TCL ,
699+ path = trial_path ,
654700 )
655- if variant is None :
656- variant = config .replace (" " , "_" ).replace ("=" , "_" )
701+
657702 t = time .time ()
658703 metric_file = openroad (
659704 args = args ,
660705 base_dir = repo_dir ,
661706 parameters = config ,
662- flow_variant = f" { uuid . uuid4 () } - { variant } " if variant else f" { uuid . uuid4 () } " ,
707+ flow_variant = flow_variant ,
663708 install_path = install_path ,
664709 )
665710 duration = time .time () - t
@@ -669,9 +714,29 @@ def openroad_distributed(
669714@ray .remote
670715def consumer (queue ):
671716 """consumer"""
672- while not queue .empty ():
673- next_item = queue .get ()
674- name = next_item [1 ]
675- print (f"[INFO TUN-0007] Scheduling run for parameter { name } ." )
676- ray .get (openroad_distributed .remote (* next_item ))
677- print (f"[INFO TUN-0008] Finished run for parameter { name } ." )
717+ item = queue .get ()
718+ tb_logger = item [6 ]
719+
720+ while item :
721+ args , repo_dir , config , sdc , fr , install , tb_logger = item
722+ print (f"[INFO TUN-0007] Scheduling run for parameter { config } ." )
723+ metric_file , _ = ray .get (
724+ openroad_distributed .remote (args , repo_dir , config , sdc , fr , install )
725+ )
726+ print (f"[INFO TUN-0008] Finished run for parameter { config } ." )
727+
728+ metrics = read_metrics (metric_file , args .stop_stage )
729+ score , effective_clk_period , num_drc , die_area = calculate_score (metrics )
730+
731+ ray .get (
732+ tb_logger .log_sweep_metrics .remote (
733+ params = config ,
734+ metrics = metrics ,
735+ score = score ,
736+ effective_clk_period = effective_clk_period ,
737+ num_drc = num_drc ,
738+ die_area = die_area ,
739+ )
740+ )
741+
742+ item = queue .get () if not queue .empty () else None
0 commit comments