Skip to content

Commit a5e0c53

Browse files
[Bench] Fix torch benchmarks' passing profiler argument
- Fix missing param passing to torch benchmark bin (ref. intel#20978) - Extend test case to check if the param is passed, as expected - Move log with full command to execute from Debug to Info
1 parent 9ff23b5 commit a5e0c53

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

devops/scripts/benchmarks/benches/compute.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2024-2025 Intel Corporation
1+
# Copyright (C) 2024-2026 Intel Corporation
22
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -1027,9 +1027,11 @@ def _supported_runtimes(self) -> list[RUNTIMES]:
10271027

10281028
def _bin_args(self, run_trace: TracingType = TracingType.NONE) -> list[str]:
10291029
iters = self._get_iters(run_trace)
1030-
return [f"--iterations={iters}"] + [
1031-
f"--{k}={v}" for k, v in self._torch_params.items()
1032-
]
1030+
return (
1031+
[f"--iterations={iters}"]
1032+
+ [f"--profilerType={self._profiler_type.value}"]
1033+
+ [f"--{k}={v}" for k, v in self._torch_params.items()]
1034+
)
10331035

10341036

10351037
class TorchSingleQueue(TorchBenchmark):

devops/scripts/benchmarks/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def run_iterations(
107107
Unless options.exit_on_failure is set, then exception is raised.
108108
"""
109109

110+
log.info(f"Running '{benchmark.name()}' {iters}x iterations...")
110111
for iter in range(iters):
111-
log.info(f"running {benchmark.name()}, iteration {iter}... ")
112112
try:
113113
bench_results = benchmark.run(
114114
env_vars, run_trace=run_trace, force_trace=force_trace
@@ -145,7 +145,7 @@ def run_iterations(
145145
log.error(f"{failure_label}: verification failed: {str(e)}.")
146146
continue
147147

148-
# Iterations completed successfully
148+
log.info(f"Completed '{benchmark.name()}' {iters}x iterations")
149149
return True
150150

151151

devops/scripts/benchmarks/tests/test_integration.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2025 Intel Corporation
1+
# Copyright (C) 2025-2026 Intel Corporation
22
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -63,7 +63,7 @@ def remove_dirs(self):
6363
if d is not None:
6464
shutil.rmtree(d, ignore_errors=True)
6565

66-
def run_main(self, *args):
66+
def run_main(self, *args) -> subprocess.CompletedProcess:
6767

6868
# TODO: not yet tested: "--detect-version", "sycl,compute_runtime"
6969

@@ -101,9 +101,9 @@ def run_main(self, *args):
101101
"MAIN_PY_STDERR:",
102102
"\n" + proc.stderr.decode() if proc.stderr else " <empty>",
103103
)
104-
return proc.returncode
104+
return proc
105105

106-
def get_output(self):
106+
def get_benchmark_output_data(self):
107107
with open(os.path.join(self.OUTPUT_DIR, "data.json")) as f:
108108
out = json.load(f)
109109
return DataJson(
@@ -169,11 +169,30 @@ def _checkGroup(
169169
def _checkResultsExist(self, caseName: str, out: DataJson):
170170
self.assertIn(caseName, [r.name for r in out.runs[0].results])
171171

172-
def _checkCase(self, caseName: str, groupName: str, tags: set[str]):
173-
run_result = self.app.run_main("--filter", caseName + "$")
174-
self.assertEqual(run_result, 0, "Subprocess did not exit cleanly")
172+
def _checkExistsInProcessOutput(
173+
self, proc: subprocess.CompletedProcess, expected: str
174+
):
175+
"""
176+
Check that expected regex string exists in process output.
177+
It's useful for checking e.g. if expected params are passed to the benchmark's bin execution.
178+
"""
179+
stdout = proc.stdout.decode()
180+
self.assertRegex(stdout, expected, "Expected string not found in output")
181+
182+
def _checkCase(
183+
self,
184+
caseName: str,
185+
groupName: str,
186+
tags: set[str],
187+
expected_in_output: str = None,
188+
):
189+
return_proc = self.app.run_main("--filter", caseName + "$")
190+
self.assertEqual(return_proc.returncode, 0, "Subprocess did not exit cleanly")
191+
192+
if expected_in_output:
193+
self._checkExistsInProcessOutput(return_proc, expected_in_output)
175194

176-
out = self.app.get_output()
195+
out = self.app.get_benchmark_output_data()
177196
self._checkResultsExist(caseName, out)
178197

179198
metadata = out.metadata[caseName]
@@ -199,11 +218,13 @@ def test_torch_l0(self):
199218
"torch_benchmark_l0 KernelSubmitSingleQueue KernelBatchSize 512, KernelDataType Int32, KernelName Add, KernelParamsNum 5, KernelSubmitPattern Single, KernelWGCount 4096, KernelWGSize 512",
200219
"KernelSubmitSingleQueue Int32Large",
201220
{"pytorch", "L0"},
221+
"--test=KernelSubmitSingleQueue.*--profilerType=timer",
202222
)
203223
self._checkCase(
204224
"torch_benchmark_l0 KernelSubmitSingleQueue KernelBatchSize 512, KernelDataType Int32, KernelName Add, KernelParamsNum 5, KernelSubmitPattern Single, KernelWGCount 4096, KernelWGSize 512 CPU count",
205225
"KernelSubmitSingleQueue Int32Large, CPU count",
206226
{"pytorch", "L0"},
227+
"--test=KernelSubmitSingleQueue.*--profilerType=cpuCounter",
207228
)
208229
self._checkCase(
209230
"torch_benchmark_l0 KernelSubmitMultiQueue kernelsPerQueue 20, workgroupCount 4096, workgroupSize 512",

devops/scripts/benchmarks/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run(
7171
command_str = " ".join(command)
7272
env_str = " ".join(f"{key}={value}" for key, value in env_vars.items())
7373
full_command_str = f"{env_str} {command_str}".strip()
74-
log.debug(f"Running: {full_command_str}")
74+
log.info(f"Running: {full_command_str}")
7575

7676
for key, value in env_vars.items():
7777
# Only PATH and LD_LIBRARY_PATH should be prepended to existing values

0 commit comments

Comments
 (0)