Skip to content

Commit 4e0e0aa

Browse files
committed
verbose converter: simplify verbose filtering logic for testing
1 parent 4157460 commit 4e0e0aa

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

scripts/verbose_converter/src/utils.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ def check_version():
4646

4747
def dedent(multiline):
4848
lines = multiline.split("\n")
49+
if len(lines) == 1:
50+
return lines[0].strip()
4951
indent = min(len(line) - len(line.lstrip()) for line in lines[1:])
5052
return (lines[0] + "\n".join(line[indent:] for line in lines[1:])).strip()

scripts/verbose_converter/tests/benchdnn_test.py

+43-31
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import subprocess
2121
import sys
2222
from argparse import RawTextHelpFormatter
23-
from typing import List, Optional
23+
from collections import defaultdict
24+
from typing import Dict, List
2425

2526

2627
class TestingException(RuntimeError):
@@ -30,45 +31,59 @@ def __init__(self, msg):
3031
super().__init__(dedent(msg))
3132

3233

34+
class FailedCase(TestingException):
35+
def __init__(self, status: str, repro: str):
36+
super().__init__(f"Failed case: {status}: {repro}")
37+
38+
3339
def convert_dir_benchdnn2verbose(dir):
34-
return {
40+
mapping = {
3541
"FWD_D": "forward_training",
3642
"FWD_B": "forward_training",
3743
"FWD_I": "forward_inference",
3844
"BWD_D": "backward_data",
3945
"BWD_W": "backward_weights",
4046
"BWD_DW": "backward",
41-
}.get(dir)
47+
}
48+
return mapping.get(dir, "undef")
4249

4350

4451
def filter_verbose(verbose: str, driver: str, filter_event: str):
45-
found_entry = False
4652
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)
4954
for line in verbose.split("\n"):
5055
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: )
6161
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():
6364
if part.startswith(f"--{argname}="):
6465
value = part[len(argname) + 3 :]
6566
known_prop_kind = convert_dir_benchdnn2verbose(value)
6667
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])
6978
elif line.startswith("onednn_verbose,"):
7079
# Detect driver
7180
parts = line.split(",")
81+
try:
82+
float(parts[2]) # check for timestamp
83+
except ValueError:
84+
pass
85+
else:
86+
parts.pop(2)
7287
try:
7388
component = parts[2]
7489
event, *_ = parts[3].split(":", 1)
@@ -81,24 +96,22 @@ def filter_verbose(verbose: str, driver: str, filter_event: str):
8196
continue
8297
if get_driver(primitive) != driver:
8398
continue
84-
# Filter out additional forward calls.
85-
if known_prop_kind is not None and prop_kind != known_prop_kind:
86-
continue
8799
# Filter out transform routine till it's properly supported. Use
88100
# impl name for that due to it's the only difference between two
89101
# ukernel calls.
90102
if driver == "brgemm" and impl_name == "pack_B":
91103
continue
92-
# Remove primitive creation time
104+
# Remove primitive creation/run time
105+
try:
106+
float(parts[-1])
107+
except ValueError:
108+
continue
93109
without_time = ",".join(parts[:-1])
94110
# 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)
102115
return "\n".join(found_cases)
103116

104117

@@ -122,7 +135,6 @@ def generate_verbose(path_to_benchdnn, engine, driver, batch):
122135
f"--engine={engine}",
123136
f"--{driver}",
124137
f"--mode={benchdnn_mode}",
125-
"-v1",
126138
f"--batch={batch}",
127139
]
128140
try:

0 commit comments

Comments
 (0)