Skip to content

Commit 9982a0c

Browse files
committed
[Benchmarks] support CPU counter measurements
for api_overhead_benchmark_ur
1 parent 5b57041 commit 9982a0c

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

scripts/benchmarks/benches/compute.py

Lines changed: 60 additions & 25 deletions
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", "XXX")
2323
build_path = create_build_path(self.directory, 'compute-benchmarks-build')
2424

2525
configure_command = [
@@ -71,17 +71,20 @@ def benchmarks(self) -> list[Benchmark]:
7171

7272
if options.ur is not None:
7373
benches += [
74-
SubmitKernelUR(self, 0),
75-
SubmitKernelUR(self, 1),
74+
SubmitKernelURWithTime(self, 0),
75+
SubmitKernelURWithTime(self, 1),
76+
SubmitKernelURWithCPUCounter(self, 0),
77+
SubmitKernelURWithCPUCounter(self, 1),
7678
]
7779

7880
return benches
7981

8082
class ComputeBenchmark(Benchmark):
81-
def __init__(self, bench, name, test):
83+
def __init__(self, bench, name, test, unit="time [us]"):
8284
self.bench = bench
8385
self.bench_name = name
8486
self.test = test
87+
self.unitType = unit
8588
super().__init__(bench.directory)
8689

8790
def bin_args(self) -> list[str]:
@@ -91,7 +94,7 @@ def extra_env_vars(self) -> dict:
9194
return {}
9295

9396
def unit(self):
94-
return "μs"
97+
return {"time [us]": "μs", "hw instructions [count]": "CPU instructions count"}[self.unitType]
9598

9699
def setup(self):
97100
self.benchmark_bin = os.path.join(self.bench.directory, 'compute-benchmarks-build', 'bin', self.bench_name)
@@ -108,30 +111,41 @@ def run(self, env_vars) -> list[Result]:
108111
env_vars.update(self.extra_env_vars())
109112

110113
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) ]
114+
parsed_results = self.parse_output(result)
115+
ret = []
116+
for label, mean, unit in parsed_results:
117+
if self.unitType in unit:
118+
extra_label = " CPU count" if self.unitType == "hw instructions [count]" else ""
119+
ret.append(Result(label=label + extra_label, value=mean, command=command, env=env_vars, stdout=result))
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
130144

131145
class SubmitKernelSYCL(ComputeBenchmark):
132146
def __init__(self, bench, ioq):
133147
self.ioq = ioq
134-
super().__init__(bench, "api_overhead_benchmark_sycl", "SubmitKernel")
148+
super().__init__(bench, "api_overhead_benchmark_sycl", "SubmitKernel", "time [us]")
135149

136150
def name(self):
137151
order = "in order" if self.ioq else "out of order"
@@ -148,14 +162,35 @@ def bin_args(self) -> list[str]:
148162
"--KernelExecTime=1"
149163
]
150164

151-
class SubmitKernelUR(ComputeBenchmark):
165+
class SubmitKernelURWithTime(ComputeBenchmark):
152166
def __init__(self, bench, ioq):
153167
self.ioq = ioq
154-
super().__init__(bench, "api_overhead_benchmark_ur", "SubmitKernel")
168+
super().__init__(bench, "api_overhead_benchmark_ur", "SubmitKernel", "time [us]")
155169

156170
def name(self):
157171
order = "in order" if self.ioq else "out of order"
158-
return f"api_overhead_benchmark_ur SubmitKernel {order}"
172+
return f"api_overhead_benchmark_ur SubmitKernel {order} time"
173+
174+
def bin_args(self) -> list[str]:
175+
return [
176+
f"--Ioq={self.ioq}",
177+
"--DiscardEvents=0",
178+
"--MeasureCompletion=0",
179+
"--iterations=100000",
180+
"--Profiling=0",
181+
"--NumKernels=10",
182+
"--KernelExecTime=1"
183+
]
184+
185+
186+
class SubmitKernelURWithCPUCounter(ComputeBenchmark):
187+
def __init__(self, bench, ioq):
188+
self.ioq = ioq
189+
super().__init__(bench, "api_overhead_benchmark_ur", "SubmitKernel", "hw instructions [count]")
190+
191+
def name(self):
192+
order = "in order" if self.ioq else "out of order"
193+
return f"api_overhead_benchmark_ur SubmitKernel {order} CPU count"
159194

160195
def bin_args(self) -> list[str]:
161196
return [
@@ -175,7 +210,7 @@ def __init__(self, bench, ioq, isCopyOnly, source, destination, size):
175210
self.source = source
176211
self.destination = destination
177212
self.size = size
178-
super().__init__(bench, "api_overhead_benchmark_sycl", "ExecImmediateCopyQueue")
213+
super().__init__(bench, "api_overhead_benchmark_sycl", "ExecImmediateCopyQueue", "time [us]")
179214

180215
def name(self):
181216
order = "in order" if self.ioq else "out of order"
@@ -198,7 +233,7 @@ def __init__(self, bench, isCopyOnly, source, destination, size):
198233
self.source = source
199234
self.destination = destination
200235
self.size = size
201-
super().__init__(bench, "memory_benchmark_sycl", "QueueInOrderMemcpy")
236+
super().__init__(bench, "memory_benchmark_sycl", "QueueInOrderMemcpy", "time [us]")
202237

203238
def name(self):
204239
return f"memory_benchmark_sycl QueueInOrderMemcpy from {self.source} to {self.destination}, size {self.size}"
@@ -218,7 +253,7 @@ def __init__(self, bench, source, destination, size):
218253
self.source = source
219254
self.destination = destination
220255
self.size = size
221-
super().__init__(bench, "memory_benchmark_sycl", "QueueMemcpy")
256+
super().__init__(bench, "memory_benchmark_sycl", "QueueMemcpy", "time [us]")
222257

223258
def name(self):
224259
return f"memory_benchmark_sycl QueueMemcpy from {self.source} to {self.destination}, size {self.size}"
@@ -236,7 +271,7 @@ def __init__(self, bench, type, size, placement):
236271
self.type = type
237272
self.size = size
238273
self.placement = placement
239-
super().__init__(bench, "memory_benchmark_sycl", "StreamMemory")
274+
super().__init__(bench, "memory_benchmark_sycl", "StreamMemory", "time [us]")
240275

241276
def name(self):
242277
return f"memory_benchmark_sycl StreamMemory, placement {self.placement}, type {self.type}, size {self.size}"
@@ -253,7 +288,7 @@ def bin_args(self) -> list[str]:
253288

254289
class VectorSum(ComputeBenchmark):
255290
def __init__(self, bench):
256-
super().__init__(bench, "miscellaneous_benchmark_sycl", "VectorSum")
291+
super().__init__(bench, "miscellaneous_benchmark_sycl", "VectorSum", "time [us]")
257292

258293
def name(self):
259294
return f"miscellaneous_benchmark_sycl VectorSum"
@@ -274,7 +309,7 @@ def __init__(self, bench, numOpsPerThread, numThreads, allocSize, iterations, sr
274309
self.iterations = iterations
275310
self.srcUSM = srcUSM
276311
self.dstUSM = dstUSM
277-
super().__init__(bench, "multithread_benchmark_ur", "MemcpyExecute")
312+
super().__init__(bench, "multithread_benchmark_ur", "MemcpyExecute", "time [us]")
278313

279314
def name(self):
280315
return f"multithread_benchmark_ur MemcpyExecute opsPerThread:{self.numOpsPerThread}, numThreads:{self.numThreads}, allocSize:{self.allocSize} srcUSM:{self.srcUSM} dstUSM:{self.dstUSM}"

0 commit comments

Comments
 (0)