@@ -17,7 +17,7 @@ class BenchCase:
1717 args : typing .List [str ]
1818
1919
20- def bench (targets = None ):
20+ def bench (targets = None ):
2121 if targets is None :
2222 targets = ARG ("targets" )
2323
@@ -31,7 +31,7 @@ def bench(targets = None):
3131 cons .indent ()
3232 cons .print ()
3333
34- CASES = [ BenchCase (** case ) for case in file_load_yaml (MFC_BENCH_FILEPATH ) ]
34+ CASES = [BenchCase (** case ) for case in file_load_yaml (MFC_BENCH_FILEPATH )]
3535
3636 for case in CASES :
3737 case .args = case .args + ARG ("--" )
@@ -40,14 +40,17 @@ def bench(targets = None):
4040 results = {
4141 "metadata" : {
4242 "invocation" : sys .argv [1 :],
43- "lock" : dataclasses .asdict (CFG ())
43+ "lock" : dataclasses .asdict (CFG ())
4444 },
4545 "cases" : {},
4646 }
4747
48+ single_precision_runtime = None
49+ double_precision_runtime = None
50+
4851 for i , case in enumerate (CASES ):
4952 summary_filepath = os .path .join (bench_dirpath , f"{ case .slug } .yaml" )
50- log_filepath = os .path .join (bench_dirpath , f"{ case .slug } .out" )
53+ log_filepath = os .path .join (bench_dirpath , f"{ case .slug } .out" )
5154
5255 cons .print (f"{ str (i + 1 ).zfill (len (CASES ) // 10 + 1 )} /{ len (CASES )} : { case .slug } @ [bold]{ os .path .relpath (case .path )} [/bold]" )
5356 cons .indent ()
@@ -65,13 +68,28 @@ def bench(targets = None):
6568 stdout = log_file ,
6669 stderr = subprocess .STDOUT )
6770
71+ output_summary = file_load_yaml (summary_filepath )
6872 results ["cases" ][case .slug ] = {
69- "description" : dataclasses .asdict (case ),
70- "output_summary" : file_load_yaml ( summary_filepath ) ,
73+ "description" : dataclasses .asdict (case ),
74+ "output_summary" : output_summary ,
7175 }
7276
73- file_dump_yaml (ARG ("output" ), results )
77+ if "single" in case .slug :
78+ single_precision_runtime = output_summary .get ("exec" )
79+ elif "double" in case .slug :
80+ double_precision_runtime = output_summary .get ("exec" )
81+
82+ # Check for speedup requirement
83+ if single_precision_runtime and double_precision_runtime :
84+ speedup = double_precision_runtime / single_precision_runtime
85+ cons .print (f"Single precision runtime: { single_precision_runtime } " )
86+ cons .print (f"Double precision runtime: { double_precision_runtime } " )
87+ cons .print (f"Speedup: { speedup :.2f} " )
7488
89+ if speedup < 1.2 :
90+ raise MFCException ("Error: Single precision runtime is not at least 1.2 times faster than double precision." )
91+
92+ file_dump_yaml (ARG ("output" ), results )
7593 cons .print (f"Wrote results to [bold magenta]{ os .path .relpath (ARG ('output' ))} [/bold magenta]." )
7694
7795 cons .unindent ()
0 commit comments