20
20
import subprocess
21
21
import sys
22
22
from argparse import RawTextHelpFormatter
23
- from typing import List , Optional
23
+ from collections import defaultdict
24
+ from typing import Dict , List
24
25
25
26
26
27
class TestingException (RuntimeError ):
@@ -30,45 +31,59 @@ def __init__(self, msg):
30
31
super ().__init__ (dedent (msg ))
31
32
32
33
34
+ class FailedCase (TestingException ):
35
+ def __init__ (self , status : str , repro : str ):
36
+ super ().__init__ (f"Failed case: { status } : { repro } " )
37
+
38
+
33
39
def convert_dir_benchdnn2verbose (dir ):
34
- return {
40
+ mapping = {
35
41
"FWD_D" : "forward_training" ,
36
42
"FWD_B" : "forward_training" ,
37
43
"FWD_I" : "forward_inference" ,
38
44
"BWD_D" : "backward_data" ,
39
45
"BWD_W" : "backward_weights" ,
40
46
"BWD_DW" : "backward" ,
41
- }.get (dir )
47
+ }
48
+ return mapping .get (dir , "undef" )
42
49
43
50
44
51
def filter_verbose (verbose : str , driver : str , filter_event : str ):
45
- found_entry = False
46
52
found_cases : List [str ] = []
47
- last_reorder : Optional [str ] = None
48
- known_prop_kind : Optional [str ] = None
53
+ tentative_cases : Dict [str , List [str ]] = defaultdict (list )
49
54
for line in verbose .split ("\n " ):
50
55
if "__REPRO" in line :
51
- found_entry = False
52
- # Adding reorders is deferred to here because we need to exclude all
53
- # but the final one.
54
- if driver == "reorder" and last_reorder is not None :
55
- found_cases .append (last_reorder )
56
- last_reorder = None
57
- elif found_entry :
58
- pass
59
- elif "create: " in line :
60
- # Detect prop kind in benchdnn log
56
+ # n: STATUS (Status message) __REPRO: repro
57
+ _ , status_info , repro = map (str .strip , line .split (":" , 2 ))
58
+ status_and_message = status_info .rsplit (None , 1 )[0 ]
59
+ status = status_and_message .split ("(" , 1 )[0 ].strip ()
60
+ # workaround for nvim-treesitter indent bug: )
61
61
argname = "prop" if driver == "rnn" else "dir"
62
- for part in line .split ():
62
+ known_prop_kind : str = "undef"
63
+ for part in repro .split ():
63
64
if part .startswith (f"--{ argname } =" ):
64
65
value = part [len (argname ) + 3 :]
65
66
known_prop_kind = convert_dir_benchdnn2verbose (value )
66
67
break
67
- else :
68
- known_prop_kind = None
68
+
69
+ cases = tentative_cases [known_prop_kind ]
70
+ tentative_cases .clear ()
71
+ if status == "SKIPPED" :
72
+ continue
73
+ elif "FAILED" in status :
74
+ raise FailedCase (status , repro )
75
+ elif not cases :
76
+ continue
77
+ found_cases .append (cases [- 1 ])
69
78
elif line .startswith ("onednn_verbose," ):
70
79
# Detect driver
71
80
parts = line .split ("," )
81
+ try :
82
+ float (parts [2 ]) # check for timestamp
83
+ except ValueError :
84
+ pass
85
+ else :
86
+ parts .pop (2 )
72
87
try :
73
88
component = parts [2 ]
74
89
event , * _ = parts [3 ].split (":" , 1 )
@@ -81,24 +96,22 @@ def filter_verbose(verbose: str, driver: str, filter_event: str):
81
96
continue
82
97
if get_driver (primitive ) != driver :
83
98
continue
84
- # Filter out additional forward calls.
85
- if known_prop_kind is not None and prop_kind != known_prop_kind :
86
- continue
87
99
# Filter out transform routine till it's properly supported. Use
88
100
# impl name for that due to it's the only difference between two
89
101
# ukernel calls.
90
102
if driver == "brgemm" and impl_name == "pack_B" :
91
103
continue
92
- # Remove primitive creation time
104
+ # Remove primitive creation/run time
105
+ try :
106
+ float (parts [- 1 ])
107
+ except ValueError :
108
+ continue
93
109
without_time = "," .join (parts [:- 1 ])
94
110
# Filter out fill reorders. Only the last one is real.
95
- if driver == "reorder" :
96
- last_reorder = without_time
97
- continue
98
- found_entry = True # Skip to next __REPRO line
99
- found_cases .append (without_time )
100
- if driver == "reorder" and last_reorder is not None :
101
- found_cases .append (last_reorder )
111
+ tentative_cases [prop_kind ].append (without_time )
112
+ if prop_kind != "undef" :
113
+ # In case the reproducer uses the default prop kind
114
+ tentative_cases ["undef" ].append (without_time )
102
115
return "\n " .join (found_cases )
103
116
104
117
@@ -122,7 +135,6 @@ def generate_verbose(path_to_benchdnn, engine, driver, batch):
122
135
f"--engine={ engine } " ,
123
136
f"--{ driver } " ,
124
137
f"--mode={ benchdnn_mode } " ,
125
- "-v1" ,
126
138
f"--batch={ batch } " ,
127
139
]
128
140
try :
0 commit comments