Skip to content

Commit ff02cdf

Browse files
authored
Add summary processing tool (#3032)
1 parent ad5735c commit ff02cdf

1 file changed

Lines changed: 149 additions & 0 deletions

File tree

tools/psummary

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import json
5+
import sys
6+
7+
# ROOT = Path(__file__).parent.parent
8+
DATA = {}
9+
10+
11+
def load_data(data_path):
12+
global DATA
13+
try:
14+
with open(data_path, "r") as f:
15+
DATA = json.load(f)
16+
return True
17+
except Exception as ex:
18+
print(f"Failed to load data: {ex}")
19+
return False
20+
21+
22+
def format_record(fields, fmt):
23+
if fmt == "csv":
24+
return ",".join(fields)
25+
26+
if fmt == "markdown":
27+
line = " | ".join(fields)
28+
return f"| {line} |"
29+
30+
if fmt == "html":
31+
line = "</rd><td>".join(fields)
32+
return "<tr><td>" + line + "</td></tr>"
33+
34+
return ""
35+
36+
37+
def parse_lines(fmt):
38+
"""Write result to CSV.
39+
40+
The layout is as follows:
41+
<id>,<astatus>,<pass/fail/skip>,<pstatus>,<fp16>,<fp32>,<bf16>,<cf64>,<i16>,<i32>,<i64>,<note>
42+
"""
43+
data = DATA.get("result", {})
44+
lines = []
45+
for op, item in data.items():
46+
fields = []
47+
# print(f"{op} ....")
48+
accu = item["accuracy"]["status"]
49+
accud = "/".join(
50+
[
51+
str(item["accuracy"]["passed"]),
52+
str(item["accuracy"]["failed"]),
53+
str(item["accuracy"]["skipped"]),
54+
]
55+
)
56+
fields.extend([op, accu, accud])
57+
58+
perf_data = item["performance"]["data"]
59+
perf_status = item["performance"]["status"]
60+
if perf_status == "NotFound":
61+
fields.append("NotFound")
62+
fields.extend([""] * 8)
63+
64+
elif perf_status in ["Failed", "Skipped"]:
65+
reason = item["performance"]["reason"]
66+
reason = reason.split("\n")[0]
67+
fields.append(perf_status)
68+
fields.extend([""] * 7)
69+
fields.append(f'"{reason}"')
70+
71+
else:
72+
fields.append(perf_status)
73+
for dtype in ["fp16", "fb32", "bf16", "cf64", "int16", "int32", "int64"]:
74+
dobj = perf_data.get(dtype, {})
75+
speedup = dobj.get("speedup", None)
76+
if speedup:
77+
fields.append(f"{speedup:6.3f}")
78+
else:
79+
fields.append("")
80+
81+
lines.append(format_record(fields, fmt))
82+
83+
return sorted(lines)
84+
85+
86+
def main():
87+
parser = argparse.ArgumentParser()
88+
parser.add_argument("data", help="the data file to process")
89+
parser.add_argument(
90+
"-f",
91+
"--format",
92+
choices=["csv", "markdown", "html"],
93+
default="csv",
94+
help="the output format",
95+
)
96+
parser.add_argument(
97+
"-o", "--output", default="<stdout>", help="path to the output file."
98+
)
99+
100+
args = parser.parse_args()
101+
if args.data is None:
102+
parser.print_help()
103+
return 0
104+
105+
if not load_data(args.data):
106+
return 1
107+
108+
lines = parse_lines(args.format)
109+
header_fields = [
110+
"ID",
111+
"AccRes",
112+
"AccStat",
113+
"PerfRes",
114+
"FP16",
115+
"FP32",
116+
"BF16",
117+
"CF64",
118+
"I16",
119+
"I32",
120+
"I64",
121+
"Note",
122+
]
123+
if args.format == "csv":
124+
lines.insert(0, ",".join(header_fields))
125+
elif args.format == "markdown":
126+
header = "|" + "----|" * 12
127+
lines.insert(0, header)
128+
header = "| " + " | ".join(header_fields) + " |"
129+
lines.insert(0, header)
130+
elif args.format == "html":
131+
header = ["<table>", "<thead>", "<tr>"]
132+
for field in header_fields:
133+
header.append(f"<th>{field}</th>")
134+
header.extend(["</tr>", "</thead>", "<tbody>"])
135+
lines = header + lines
136+
lines.append("</tbody></table")
137+
138+
if args.output == "<stdout>":
139+
for ln in lines:
140+
print(ln)
141+
else:
142+
with open(args.output, "w") as f:
143+
f.writelines(lines)
144+
145+
return 0
146+
147+
148+
if __name__ == "__main__":
149+
sys.exit(main())

0 commit comments

Comments
 (0)