@@ -81,89 +81,62 @@ def bench(targets = None):
8181# pylint: disable=too-many-branches
8282def diff ():
8383 lhs , rhs = file_load_yaml (ARG ("lhs" )), file_load_yaml (ARG ("rhs" ))
84-
8584 cons .print (f"[bold]Comparing Benchmarks: Speedups from [magenta]{ os .path .relpath (ARG ('lhs' ))} [/magenta] to [magenta]{ os .path .relpath (ARG ('rhs' ))} [/magenta] are displayed below. Thus, numbers > 1 represent increases in performance.[/bold]" )
85+
8686 if lhs ["metadata" ] != rhs ["metadata" ]:
87- def _lock_to_str (lock ):
88- return ' ' .join ([f"{ k } ={ v } " for k , v in lock .items ()])
89-
90- cons .print (f"""\
91- [bold yellow]Warning[/bold yellow]: Metadata in lhs and rhs are not equal.
92- This could mean that the benchmarks are not comparable (e.g. one was run on CPUs and the other on GPUs).
93- lhs:
94- * Invocation: [magenta]{ ' ' .join (lhs ['metadata' ]['invocation' ])} [/magenta]
95- * Modes: { _lock_to_str (lhs ['metadata' ]['lock' ])}
96- rhs:
97- * Invocation: { ' ' .join (rhs ['metadata' ]['invocation' ])}
98- * Modes: [magenta]{ _lock_to_str (rhs ['metadata' ]['lock' ])} [/magenta]
99- """ )
87+ _lock_to_str = lambda lock : ' ' .join ([f"{ k } ={ v } " for k , v in lock .items ()])
88+ cons .print (f"[bold yellow]Warning[/bold yellow]: Metadata in lhs and rhs are not equal.\n "
89+ f" This could mean that the benchmarks are not comparable (e.g. one was run on CPUs and the other on GPUs).\n "
90+ f" Invocation,\t \t Modes\n "
91+ f" lhs: { ' ' .join (lhs ['metadata' ]['invocation' ])} | { _lock_to_str (lhs ['metadata' ]['lock' ])} \n "
92+ f" rhs: { ' ' .join (rhs ['metadata' ]['invocation' ])} | { _lock_to_str (rhs ['metadata' ]['lock' ])} " )
10093
10194 slugs = set (lhs ["cases" ].keys ()) & set (rhs ["cases" ].keys ())
10295 if len (slugs ) not in [len (lhs ["cases" ]), len (rhs ["cases" ])]:
10396 cons .print (f"""\
104- [bold yellow]Warning[/bold yellow]: Cases in lhs and rhs are not equal .
97+ [bold yellow]Warning[/bold yellow]: Cases in lhs and rhs differ. Using intersection: { slugs } with { len ( slugs ) } elements .
10598 * rhs cases: { ', ' .join (set (rhs ['cases' ].keys ()) - slugs )} .
106- * lhs cases: { ', ' .join (set (lhs ['cases' ].keys ()) - slugs )} .
107- Using intersection: { slugs } with { len (slugs )} elements.
108- """ )
99+ * lhs cases: { ', ' .join (set (lhs ['cases' ].keys ()) - slugs )} .""" )
109100
110101 table = rich .table .Table (show_header = True , box = rich .table .box .SIMPLE )
111102 table .add_column ("[bold]Case[/bold]" , justify = "left" )
112- table .add_column ("[bold]Pre Process[/bold]" , justify = "right" )
113- table .add_column ("[bold]Simulation[/bold]" , justify = "right" )
114- table .add_column ("[bold]Post Process[/bold]" , justify = "right" )
115103
116104 err = 0
117-
118105 for slug in slugs :
119- lhs_summary = lhs ["cases" ][slug ]["output_summary" ]
120- rhs_summary = rhs ["cases" ][slug ]["output_summary" ]
121-
122- speedups = ['N/A' , 'N/A' , 'N/A' ]
106+ lhs_summary , rhs_summary = lhs ["cases" ][slug ]["output_summary" ], rhs ["cases" ][slug ]["output_summary" ]
107+ speedups = []
123108
124- for i , target in enumerate (sorted (DEFAULT_TARGETS , key = lambda t : t .runOrder )):
109+ for target in sorted (DEFAULT_TARGETS , key = lambda t : t .runOrder ):
110+ table .add_column (f"[bold]{ target .name } [/bold]" , justify = "right" ) #add column for each target
125111 if (target .name not in lhs_summary ) or (target .name not in rhs_summary ):
126-
127- err = 1
128-
129- if target .name not in lhs_summary :
130- cons .print (f"{ target .name } not present in lhs_summary - Case: { slug } " )
131-
132- if target .name not in rhs_summary :
133- cons .print (f"{ target .name } not present in rhs_summary - Case: { slug } " )
134-
135- continue
112+ cons .print (f"{ target .name } not present in lhs_summary or rhs_summary - Case: { slug } " )
113+ err = 1 ; continue
136114
137115 if not math .isfinite (lhs_summary [target .name ]["exec" ]) or not math .isfinite (rhs_summary [target .name ]["exec" ]):
138116 err = 1
139117 cons .print (f"lhs_summary or rhs_summary reports non-real exec time for { target .name } - Case: { slug } " )
140118
141- exec_time_speedup = "N/A"
142119 try :
143- exec_time_speedup = f'{ lhs_summary [target .name ]["exec" ] / rhs_summary [target .name ]["exec" ]:.2f} '
120+ exec_time_value = lhs_summary [target .name ]["exec" ] / rhs_summary [target .name ]["exec" ]
121+ speedups = f"Exec: { exec_time_value :.2f} "
122+ if exec_time_value < 0.9 :
123+ cons .print (f"[bold yellow]Warning[/bold yellow]: Exec time speedup for { target .name } is less than 0.9 - Case: { slug } " )
124+
125+ if target == SIMULATION :
126+ if not math .isfinite (lhs_summary [target .name ]["grind" ]) or not math .isfinite (rhs_summary [target .name ]["grind" ]):
127+ err = 1
128+ cons .print (f"lhs_summary or rhs_summary reports non-real grind time for { target .name } - Case: { slug } " )
129+
130+ grind_time_value = lhs_summary [target .name ]["grind" ] / rhs_summary [target .name ]["grind" ]
131+ speedups += f" & Grind: { grind_time_value :.2f} "
132+ if grind_time_value < 0.98 :
133+ raise MFCException (f"Benchmarking failed since grind time speedup for { target .name } below acceptable threshold (<0.98) - Case: { slug } " )
144134 except Exception as _ :
145135 err = 1
146- cons .print (f"lhs_summary or rhs_summary reports non-real exec time for { target .name } - Case: { slug } " )
147-
148- speedups [i ] = f"Exec: { exec_time_speedup } "
149-
150- if target == SIMULATION :
151- grind_time_speedup = "N/A"
152- if not math .isfinite (lhs_summary [target .name ]["grind" ]) or not math .isfinite (rhs_summary [target .name ]["grind" ]):
153- err = 1
154- cons .print (f"lhs_summary or rhs_summary reports non-real grind time for { target .name } - Case: { slug } " )
155-
156- try :
157- grind_time_speedup = f'{ lhs_summary [target .name ]["grind" ] / rhs_summary [target .name ]["grind" ]:.2f} '
158- except Exception as _ :
159- err = 1
160- cons .print (f"lhs_summary or rhs_summary reports non-real grind time for { target .name } - Case: { slug } " )
161-
162- speedups [i ] += f" & Grind: { grind_time_speedup } "
163-
136+ cons .print (f"lhs_summary or rhs_summary reports non-real grind time for { target .name } - Case: { slug } " )
137+
164138 table .add_row (f"[magenta]{ slug } [/magenta]" , * speedups )
165-
139+
166140 cons .raw .print (table )
167-
168- if err != 0 :
141+ if err :
169142 raise MFCException ("Benchmarking failed" )
0 commit comments