-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathrun_bench.py
95 lines (68 loc) · 2.79 KB
/
run_bench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import time
import subprocess
import pandas as pd
BENCH_PREFIX = "cvcuda_bench_"
BENCH_OUTPUT = "out.csv"
BENCH_COMMAND = "{} {} --csv {}"
BENCH_COLNAME = "Benchmark"
BENCH_RESULTS = "bench_output.csv"
BENCH_COLUMNS = {"Benchmark", "BWUtil", "Skipped"}
BANDWIDTH_COLNAME = "BWUtil"
if __name__ == "__main__":
if len(sys.argv) == 1:
print(
"E At least one argument must be provided: benchmark folder"
f"I Usage: {sys.argv[0]} bench_folder [extra args for benchmarks]"
)
sys.exit(1)
bench_args = " ".join(sys.argv[2:]) if len(sys.argv) > 2 else ""
bench_folder = sys.argv[1]
bench_files = [fn for fn in sorted(os.listdir(bench_folder)) if BENCH_PREFIX in fn]
if len(bench_files) == 0:
print(f"E No benchmarks found in {bench_folder}")
sys.exit(1)
print(f"I Found {len(bench_files)} benchmark(s) in {bench_folder} to run")
l_df = []
for filename in bench_files:
filepath = os.path.join(bench_folder, filename)
cmd = BENCH_COMMAND.format(filepath, bench_args, BENCH_OUTPUT)
print(f'I Running "{cmd}"', end=" ")
beg = time.time()
subprocess.run(cmd.split(), stdout=subprocess.PIPE)
end = time.time()
print(f"took {end - beg:.03f} sec")
if os.path.exists(BENCH_OUTPUT) is False or os.path.getsize(BENCH_OUTPUT) == 0:
print("W Skipping as benchmark output does not exist or is empty")
continue
df = pd.read_csv(BENCH_OUTPUT)
if not BENCH_COLUMNS.issubset(df.columns):
print(f"W Skipping as benchmark output does not have: {BENCH_COLUMNS}")
continue
df = df[df["Skipped"] == "No"]
os.remove(BENCH_OUTPUT)
if len(df) > 0:
l_df.append(df)
df = pd.concat(l_df, axis=0)
df = df.reset_index(drop=True)
filepath = os.path.join(bench_folder, BENCH_RESULTS)
df.to_csv(filepath)
print(f"I Full results written to {filepath}")
df = df.groupby("Benchmark")["BWUtil"].mean()
pd.options.display.float_format = "{:.2%}".format
print(f"I Summary results:\n{df}")