Skip to content

Commit d1abb0c

Browse files
authored
[Benchmarks] Use GitProject for git operations (#20207)
Use GitProject for git operations instead of utility methods. Plus, remove `directory` path in suites' ctors as this path can be obtained from the `options` module.
1 parent 75e9e73 commit d1abb0c

File tree

15 files changed

+216
-269
lines changed

15 files changed

+216
-269
lines changed

devops/scripts/benchmarks/CONTRIB.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,17 @@ The benchmark suite generates an interactive HTML dashboard that visualizes `Res
191191

192192
## Utilities
193193

194+
* **`git_project.GitProject`:** Manages git repository cloning, building, and installation for benchmark suites:
195+
* Automatically clones repositories to a specified directory and checks out specific commits/refs.
196+
* Provides standardized directory structure with `src_dir`, `build_dir`, and `install_dir` properties.
197+
* Handles incremental updates - only re-clones if the target commit has changed.
198+
* Supports force rebuilds and custom directory naming via constructor options.
199+
* Provides `configure()`, `build()`, and `install()` methods for CMake-based projects.
200+
* Use this for benchmark suites that need to build from external git repositories (e.g., `ComputeBench`, `VelocityBench`).
194201
* **`utils.utils`:** Provides common helper functions:
195202
* `run()`: Executes shell commands with environment setup (SYCL paths, LD_LIBRARY_PATH).
196-
* `git_clone()`: Clones/updates Git repositories.
197203
* `download()`: Downloads files via HTTP, checks checksums, optionally extracts tar/gz archives.
198204
* `prepare_workdir()`: Sets up the main working directory.
199-
* `create_build_path()`: Creates a clean build directory.
200205
* **`utils.oneapi`:** Provides the `OneAPI` singleton class (`get_oneapi()`). Downloads and installs specified oneAPI components (oneDNN, oneMKL) into the working directory if needed, providing access to their paths (libs, includes, CMake configs). Use this if your benchmark depends on these components instead of requiring a system-wide install.
201206
* **`options.py`:** Defines and holds global configuration options, populated by `argparse` in `main.py`. Use options instead of defining your own global variables.
202207
* **`presets.py`:** Defines named sets of suites (`enabled_suites()`) used by the `--preset` argument.

devops/scripts/benchmarks/benches/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class TracingType(Enum):
4949

5050

5151
class Benchmark(ABC):
52-
def __init__(self, directory, suite):
53-
self.directory = directory
52+
def __init__(self, suite):
5453
self.suite = suite
5554

5655
@abstractmethod
@@ -84,8 +83,8 @@ def tracing_enabled(self, run_trace, force_trace, tr_type: TracingType):
8483
"""Returns whether tracing is enabled for the given type."""
8584
return (self.traceable(tr_type) or force_trace) and run_trace == tr_type
8685

87-
@abstractmethod
8886
def setup(self):
87+
"""Extra setup steps to be performed before running the benchmark."""
8988
pass
9089

9190
@abstractmethod
@@ -205,9 +204,9 @@ def run_bench(
205204

206205
def create_data_path(self, name, skip_data_dir=False):
207206
if skip_data_dir:
208-
data_path = os.path.join(self.directory, name)
207+
data_path = os.path.join(options.workdir, name)
209208
else:
210-
data_path = os.path.join(self.directory, "data", name)
209+
data_path = os.path.join(options.workdir, "data", name)
211210
if options.redownload and Path(data_path).exists():
212211
shutil.rmtree(data_path)
213212

devops/scripts/benchmarks/benches/benchdnn.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88

99
from .base import Suite, Benchmark, TracingType
1010
from options import options
11-
from utils.utils import git_clone, run, create_build_path
1211
from utils.result import Result
1312
from utils.oneapi import get_oneapi
1413
from utils.logger import log
1514
from .benchdnn_list import get_bench_dnn_list
15+
from git_project import GitProject
1616

1717

1818
class OneDnnBench(Suite):
19-
def __init__(self, directory):
20-
self.directory = Path(directory).resolve()
21-
build_path = create_build_path(self.directory, "onednn-build")
22-
self.build_dir = Path(build_path)
23-
self.src_dir = self.directory / "onednn-repo"
19+
def __init__(self):
20+
self.project = None
2421

2522
def git_url(self):
2623
return "https://github.com/uxlfoundation/oneDNN.git"
@@ -62,36 +59,35 @@ def setup(self) -> None:
6259
if options.sycl is None:
6360
return
6461

65-
self.src_dir = git_clone(
66-
self.directory,
67-
"onednn-repo",
68-
self.git_url(),
69-
self.git_tag(),
70-
)
71-
7262
self.oneapi = get_oneapi()
73-
cmake_args = [
74-
"cmake",
75-
f"-S {self.src_dir}",
76-
f"-B {self.build_dir}",
63+
if self.project is None:
64+
self.project = GitProject(
65+
self.git_url(),
66+
self.git_tag(),
67+
Path(options.workdir),
68+
"onednn",
69+
force_rebuild=True,
70+
)
71+
72+
extra_cmake_args = [
7773
f"-DCMAKE_PREFIX_PATH={options.sycl}",
7874
"-DCMAKE_CXX_COMPILER=clang++",
7975
"-DCMAKE_C_COMPILER=clang",
80-
"-DCMAKE_BUILD_TYPE=Release",
8176
"-DDNNL_BUILD_TESTS=ON",
8277
"-DDNNL_BUILD_EXAMPLES=OFF",
8378
"-DDNNL_CPU_RUNTIME=NONE", # Disable SYCL CPU support
8479
"-DDNNL_GPU_RUNTIME=SYCL", # Enable SYCL GPU support
8580
]
86-
run(
87-
cmake_args,
81+
self.project.configure(
82+
extra_cmake_args,
83+
install_prefix=False,
8884
add_sycl=True,
8985
)
90-
91-
run(
92-
f"cmake --build {self.build_dir} --target benchdnn -j {options.build_jobs}",
86+
self.project.build(
87+
target="benchdnn",
9388
add_sycl=True,
94-
ld_library=[str(self.build_dir) + "/src"] + self.oneapi.ld_libraries(),
89+
ld_library=[str(self.project.build_dir / "src")]
90+
+ self.oneapi.ld_libraries(),
9591
timeout=60 * 20,
9692
)
9793

@@ -113,7 +109,10 @@ def __init__(self, suite, bench_driver, bench_name, bench_args, syclgraph=True):
113109
self.bench_args += " --execution-mode=direct"
114110
self.bench_name += "-eager"
115111
self.bench_args += f" {bench_args}"
116-
self.bench_bin = suite.build_dir / "tests" / "benchdnn" / "benchdnn"
112+
113+
@property
114+
def benchmark_bin(self) -> Path:
115+
return self.suite.project.build_dir / "tests" / "benchdnn" / "benchdnn"
117116

118117
def enabled(self):
119118
if options.sycl is None:
@@ -129,8 +128,8 @@ def explicit_group(self) -> str:
129128
return self.exp_group
130129

131130
def setup(self):
132-
if not self.bench_bin.exists():
133-
raise FileNotFoundError(f"Benchmark binary not found: {self.bench_bin}")
131+
if not self.benchmark_bin.exists():
132+
raise FileNotFoundError(f"Benchmark binary not found: {self.benchmark_bin}")
134133

135134
def run(
136135
self,
@@ -145,12 +144,12 @@ def run(
145144
extra_trace_opt = None
146145

147146
command = [
148-
str(self.bench_bin),
147+
str(self.benchmark_bin),
149148
*self.bench_args.split(),
150149
]
151150

152151
ld_library = self.suite.oneapi.ld_libraries() + [
153-
str(self.suite.build_dir / "src")
152+
str(self.suite.project.build_dir / "src")
154153
]
155154

156155
env_vars = dict(env_vars) if env_vars else {}

devops/scripts/benchmarks/benches/compute.py

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
from itertools import product
7-
import os
87
import csv
98
import io
109
import copy
1110
import math
1211
from enum import Enum
12+
from pathlib import Path
1313

14-
from utils.utils import run, git_clone, create_build_path
1514
from .base import Benchmark, Suite, TracingType
1615
from utils.result import BenchmarkMetadata, Result
1716
from .base import Benchmark, Suite
1817
from options import options
18+
from git_project import GitProject
1919

2020

2121
class RUNTIMES(Enum):
@@ -49,9 +49,9 @@ def runtime_to_tag_name(runtime: RUNTIMES) -> str:
4949

5050

5151
class ComputeBench(Suite):
52-
def __init__(self, directory):
53-
self.directory = directory
52+
def __init__(self):
5453
self.submit_graph_num_kernels = [4, 10, 32]
54+
self.project = None
5555

5656
def name(self) -> str:
5757
return "Compute Benchmarks"
@@ -67,47 +67,36 @@ def setup(self) -> None:
6767
if options.sycl is None:
6868
return
6969

70-
repo_path = git_clone(
71-
self.directory,
72-
"compute-benchmarks-repo",
73-
self.git_url(),
74-
self.git_hash(),
75-
)
76-
build_path = create_build_path(self.directory, "compute-benchmarks-build")
70+
if self.project is None:
71+
self.project = GitProject(
72+
self.git_url(),
73+
self.git_hash(),
74+
Path(options.workdir),
75+
"compute-benchmarks",
76+
force_rebuild=True,
77+
)
7778

78-
configure_command = [
79-
"cmake",
80-
f"-B {build_path}",
81-
f"-S {repo_path}",
82-
f"-DCMAKE_BUILD_TYPE=Release",
79+
extra_args = [
8380
f"-DBUILD_SYCL=ON",
8481
f"-DSYCL_COMPILER_ROOT={options.sycl}",
8582
f"-DALLOW_WARNINGS=ON",
8683
f"-DCMAKE_CXX_COMPILER=clang++",
8784
f"-DCMAKE_C_COMPILER=clang",
8885
]
89-
9086
if options.ur_adapter == "cuda":
91-
configure_command += [
87+
extra_args += [
9288
"-DBUILD_SYCL_WITH_CUDA=ON",
9389
"-DBUILD_L0=OFF",
9490
"-DBUILD_OCL=OFF",
9591
]
96-
9792
if options.ur is not None:
98-
configure_command += [
93+
extra_args += [
9994
f"-DBUILD_UR=ON",
10095
f"-Dunified-runtime_DIR={options.ur}/lib/cmake/unified-runtime",
10196
]
10297

103-
run(configure_command, add_sycl=True)
104-
105-
run(
106-
f"cmake --build {build_path} -j {options.build_jobs}",
107-
add_sycl=True,
108-
)
109-
110-
self.built = True
98+
self.project.configure(extra_args, install_prefix=False, add_sycl=True)
99+
self.project.build(add_sycl=True)
111100

112101
def additional_metadata(self) -> dict[str, BenchmarkMetadata]:
113102
metadata = {
@@ -371,7 +360,7 @@ def __init__(
371360
runtime: RUNTIMES = None,
372361
profiler_type: PROFILERS = PROFILERS.TIMER,
373362
):
374-
super().__init__(bench.directory, bench)
363+
super().__init__(bench)
375364
self.bench = bench
376365
self.bench_name = name
377366
self.test = test
@@ -385,6 +374,11 @@ def __init__(
385374
self._validate_attr("iterations_regular")
386375
self._validate_attr("iterations_trace")
387376

377+
@property
378+
def benchmark_bin(self) -> Path:
379+
"""Returns the path to the benchmark binary"""
380+
return self.bench.project.build_dir / "bin" / self.bench_name
381+
388382
def get_iters(self, run_trace: TracingType):
389383
"""Returns the number of iterations to run for the given tracing type."""
390384
return (
@@ -438,11 +432,6 @@ def bin_args(self, run_trace: TracingType = TracingType.NONE) -> list[str]:
438432
def extra_env_vars(self) -> dict:
439433
return {}
440434

441-
def setup(self):
442-
self.benchmark_bin = os.path.join(
443-
self.bench.directory, "compute-benchmarks-build", "bin", self.bench_name
444-
)
445-
446435
def explicit_group(self):
447436
return ""
448437

@@ -456,7 +445,7 @@ def run(
456445
force_trace: bool = False,
457446
) -> list[Result]:
458447
command = [
459-
f"{self.benchmark_bin}",
448+
str(self.benchmark_bin),
460449
f"--test={self.test}",
461450
"--csv",
462451
"--noHeaders",

0 commit comments

Comments
 (0)