Skip to content

Commit 77ef984

Browse files
authored
Merge pull request #2372 from igchor/bench_cpu_count
[Benchmarks] support CPU counter measurements
2 parents 53e8056 + 4a323ed commit 77ef984

File tree

8 files changed

+44
-58
lines changed

8 files changed

+44
-58
lines changed

scripts/benchmarks/benches/base.py

-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ def download(self, name, url, file, untar = False):
5757
def name(self):
5858
raise NotImplementedError()
5959

60-
def unit(self):
61-
raise NotImplementedError()
62-
6360
def lower_is_better(self):
6461
return True
6562

scripts/benchmarks/benches/compute.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setup(self):
1919
if options.sycl is None:
2020
return
2121

22-
repo_path = git_clone(self.directory, "compute-benchmarks-repo", "https://github.com/intel/compute-benchmarks.git", "c80ddec9f0b4905bcbeb0f264f710093dc70340d")
22+
repo_path = git_clone(self.directory, "compute-benchmarks-repo", "https://github.com/intel/compute-benchmarks.git", "df38bc342641d7e83fbb4fe764a23d21d734e07b")
2323
build_path = create_build_path(self.directory, 'compute-benchmarks-build')
2424

2525
configure_command = [
@@ -77,6 +77,13 @@ def benchmarks(self) -> list[Benchmark]:
7777

7878
return benches
7979

80+
def parse_unit_type(compute_unit):
81+
if "[count]" in compute_unit:
82+
return "instr"
83+
elif "[us]" in compute_unit:
84+
return "μs"
85+
return "unknown"
86+
8087
class ComputeBenchmark(Benchmark):
8188
def __init__(self, bench, name, test):
8289
self.bench = bench
@@ -90,9 +97,6 @@ def bin_args(self) -> list[str]:
9097
def extra_env_vars(self) -> dict:
9198
return {}
9299

93-
def unit(self):
94-
return "μs"
95-
96100
def setup(self):
97101
self.benchmark_bin = os.path.join(self.bench.directory, 'compute-benchmarks-build', 'bin', self.bench_name)
98102

@@ -108,22 +112,32 @@ def run(self, env_vars) -> list[Result]:
108112
env_vars.update(self.extra_env_vars())
109113

110114
result = self.run_bench(command, env_vars)
111-
(label, mean) = self.parse_output(result)
112-
return [ Result(label=self.name(), value=mean, command=command, env=env_vars, stdout=result) ]
115+
parsed_results = self.parse_output(result)
116+
ret = []
117+
for label, mean, unit in parsed_results:
118+
extra_label = " CPU count" if parse_unit_type(unit) == "CPU count" else ""
119+
ret.append(Result(label=self.name() + extra_label, value=mean, command=command, env=env_vars, stdout=result, unit=parse_unit_type(unit)))
120+
return ret
113121

114122
def parse_output(self, output):
115123
csv_file = io.StringIO(output)
116124
reader = csv.reader(csv_file)
117125
next(reader, None)
118-
data_row = next(reader, None)
119-
if data_row is None:
126+
results = []
127+
while True:
128+
data_row = next(reader, None)
129+
if data_row is None:
130+
break
131+
try:
132+
label = data_row[0]
133+
mean = float(data_row[1])
134+
unit = data_row[7]
135+
results.append((label, mean, unit))
136+
except (ValueError, IndexError) as e:
137+
raise ValueError(f"Error parsing output: {e}")
138+
if len(results) == 0:
120139
raise ValueError("Benchmark output does not contain data.")
121-
try:
122-
label = data_row[0]
123-
mean = float(data_row[1])
124-
return (label, mean)
125-
except (ValueError, IndexError) as e:
126-
raise ValueError(f"Error parsing output: {e}")
140+
return results
127141

128142
def teardown(self):
129143
return
@@ -249,6 +263,7 @@ def bin_args(self) -> list[str]:
249263
f"--memoryPlacement={self.placement}",
250264
"--useEvents=0",
251265
"--contents=Zeros",
266+
"--multiplier=1",
252267
]
253268

254269
class VectorSum(ComputeBenchmark):

scripts/benchmarks/benches/llamacpp.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ def __init__(self, bench):
138138
self.bench = bench
139139
super().__init__(bench.directory)
140140

141-
def unit(self):
142-
return "token/s"
143-
144141
def setup(self):
145142
self.benchmark_bin = os.path.join(self.bench.build_path, 'bin', 'llama-bench')
146143

@@ -171,7 +168,7 @@ def run(self, env_vars) -> list[Result]:
171168
for r in parsed:
172169
(extra_label, mean) = r
173170
label = f"{self.name()} {extra_label}"
174-
results.append(Result(label=label, value=mean, command=command, env=env_vars, stdout=result))
171+
results.append(Result(label=label, value=mean, command=command, env=env_vars, stdout=result, unit="token/s"))
175172
return results
176173

177174
def parse_output(self, output):

scripts/benchmarks/benches/result.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class Result:
1717
env: str
1818
stdout: str
1919
passed: bool = True
20-
# values should not be set by the benchmark
2120
unit: str = ""
21+
# values should not be set by the benchmark
2222
name: str = ""
2323
lower_is_better: bool = True
2424
git_hash: str = ''

scripts/benchmarks/benches/syclbench.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ def bin_args(self) -> list[str]:
9999
def extra_env_vars(self) -> dict:
100100
return {}
101101

102-
def unit(self):
103-
return "ms"
104-
105102
def setup(self):
106103
self.benchmark_bin = os.path.join(self.directory, 'sycl-bench-build', self.bench_name)
107104

@@ -134,7 +131,8 @@ def run(self, env_vars) -> list[Result]:
134131
passed=(row[1]=="PASS"),
135132
command=command,
136133
env=env_vars,
137-
stdout=row))
134+
stdout=row,
135+
unit="ms"))
138136
self.done = True
139137
return res_list
140138

scripts/benchmarks/benches/test.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ def __init__(self, name, value, diff):
4949
def name(self):
5050
return self.bname
5151

52-
def unit(self):
53-
return "ms"
54-
5552
def lower_is_better(self):
5653
return True
5754

@@ -61,7 +58,7 @@ def setup(self):
6158
def run(self, env_vars) -> list[Result]:
6259
random_value = self.value + random.uniform(-1 * (self.diff), self.diff)
6360
return [
64-
Result(label=self.name(), value=random_value, command="", env={"A": "B"}, stdout="no output")
61+
Result(label=self.name(), value=random_value, command="", env={"A": "B"}, stdout="no output", unit="ms")
6562
]
6663

6764
def teardown(self):

scripts/benchmarks/benches/velocity.py

+9-26
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ def benchmarks(self) -> list[Benchmark]:
3939
]
4040

4141
class VelocityBase(Benchmark):
42-
def __init__(self, name: str, bin_name: str, vb: VelocityBench):
42+
def __init__(self, name: str, bin_name: str, vb: VelocityBench, unit: str):
4343
super().__init__(vb.directory)
4444
self.vb = vb
4545
self.bench_name = name
4646
self.bin_name = bin_name
47+
self.unit = unit
4748
self.code_path = os.path.join(self.vb.repo_path, self.bench_name, 'SYCL')
4849

4950
def download_deps(self):
@@ -83,21 +84,18 @@ def run(self, env_vars) -> list[Result]:
8384

8485
result = self.run_bench(command, env_vars)
8586

86-
return [ Result(label=self.name(), value=self.parse_output(result), command=command, env=env_vars, stdout=result) ]
87+
return [ Result(label=self.name(), value=self.parse_output(result), command=command, env=env_vars, stdout=result, unit=self.unit) ]
8788

8889
def teardown(self):
8990
return
9091

9192
class Hashtable(VelocityBase):
9293
def __init__(self, vb: VelocityBench):
93-
super().__init__("hashtable", "hashtable_sycl", vb)
94+
super().__init__("hashtable", "hashtable_sycl", vb, "M keys/sec")
9495

9596
def name(self):
9697
return "Velocity-Bench Hashtable"
9798

98-
def unit(self):
99-
return "M keys/sec"
100-
10199
def bin_args(self) -> list[str]:
102100
return ["--no-verify"]
103101

@@ -114,15 +112,12 @@ def parse_output(self, stdout: str) -> float:
114112

115113
class Bitcracker(VelocityBase):
116114
def __init__(self, vb: VelocityBench):
117-
super().__init__("bitcracker", "bitcracker", vb)
115+
super().__init__("bitcracker", "bitcracker", vb, "s")
118116
self.data_path = os.path.join(vb.repo_path, "bitcracker", "hash_pass")
119117

120118
def name(self):
121119
return "Velocity-Bench Bitcracker"
122120

123-
def unit(self):
124-
return "s"
125-
126121
def bin_args(self) -> list[str]:
127122
return ["-f", f"{self.data_path}/img_win8_user_hash.txt",
128123
"-d", f"{self.data_path}/user_passwords_60000.txt",
@@ -137,7 +132,7 @@ def parse_output(self, stdout: str) -> float:
137132

138133
class SobelFilter(VelocityBase):
139134
def __init__(self, vb: VelocityBench):
140-
super().__init__("sobel_filter", "sobel_filter", vb)
135+
super().__init__("sobel_filter", "sobel_filter", vb, "ms")
141136

142137
def download_deps(self):
143138
self.download("sobel_filter", "https://github.com/oneapi-src/Velocity-Bench/raw/main/sobel_filter/res/sobel_filter_data.tgz?download=", "sobel_filter_data.tgz", untar=True)
@@ -146,9 +141,6 @@ def download_deps(self):
146141
def name(self):
147142
return "Velocity-Bench Sobel Filter"
148143

149-
def unit(self):
150-
return "ms"
151-
152144
def bin_args(self) -> list[str]:
153145
return ["-i", f"{self.data_path}/sobel_filter_data/silverfalls_32Kx32K.png",
154146
"-n", "5"]
@@ -166,7 +158,7 @@ def parse_output(self, stdout: str) -> float:
166158

167159
class QuickSilver(VelocityBase):
168160
def __init__(self, vb: VelocityBench):
169-
super().__init__("QuickSilver", "qs", vb)
161+
super().__init__("QuickSilver", "qs", vb, "MMS/CTT")
170162
self.data_path = os.path.join(vb.repo_path, "QuickSilver", "Examples", "AllScattering")
171163

172164
def run(self, env_vars) -> list[Result]:
@@ -179,9 +171,6 @@ def run(self, env_vars) -> list[Result]:
179171
def name(self):
180172
return "Velocity-Bench QuickSilver"
181173

182-
def unit(self):
183-
return "MMS/CTT"
184-
185174
def lower_is_better(self):
186175
return False
187176

@@ -200,17 +189,14 @@ def parse_output(self, stdout: str) -> float:
200189

201190
class Easywave(VelocityBase):
202191
def __init__(self, vb: VelocityBench):
203-
super().__init__("easywave", "easyWave_sycl", vb)
192+
super().__init__("easywave", "easyWave_sycl", vb, "ms")
204193

205194
def download_deps(self):
206195
self.download("easywave", "https://git.gfz-potsdam.de/id2/geoperil/easyWave/-/raw/master/data/examples.tar.gz", "examples.tar.gz", untar=True)
207196

208197
def name(self):
209198
return "Velocity-Bench Easywave"
210199

211-
def unit(self):
212-
return "ms"
213-
214200
def bin_args(self) -> list[str]:
215201
return ["-grid", f"{self.data_path}/examples/e2Asean.grd",
216202
"-source", f"{self.data_path}/examples/BengkuluSept2007.flt",
@@ -245,7 +231,7 @@ def parse_output(self, stdout: str) -> float:
245231

246232
class CudaSift(VelocityBase):
247233
def __init__(self, vb: VelocityBench):
248-
super().__init__("cudaSift", "cudaSift", vb)
234+
super().__init__("cudaSift", "cudaSift", vb, "ms")
249235

250236
def download_deps(self):
251237
images = os.path.join(self.vb.repo_path, self.bench_name, 'inputData')
@@ -256,9 +242,6 @@ def download_deps(self):
256242
def name(self):
257243
return "Velocity-Bench CudaSift"
258244

259-
def unit(self):
260-
return "ms"
261-
262245
def parse_output(self, stdout: str) -> float:
263246
match = re.search(r'Avg workload time = (\d+\.\d+) ms', stdout)
264247
if match:

scripts/benchmarks/main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def main(directory, additional_env_vars, save_name, compare_names, filter):
7373
if bench_results is not None:
7474
for bench_result in bench_results:
7575
if bench_result.passed:
76-
print(f"complete ({bench_result.label}: {bench_result.value:.3f} {benchmark.unit()}).")
76+
print(f"complete ({bench_result.label}: {bench_result.value:.3f} {bench_result.unit}).")
7777
else:
7878
print(f"complete ({bench_result.label}: verification FAILED)")
7979
iteration_results.append(bench_result)
@@ -91,7 +91,6 @@ def main(directory, additional_env_vars, save_name, compare_names, filter):
9191
median_index = len(label_results) // 2
9292
median_result = label_results[median_index]
9393

94-
median_result.unit = benchmark.unit()
9594
median_result.name = label
9695
median_result.lower_is_better = benchmark.lower_is_better()
9796

0 commit comments

Comments
 (0)