Skip to content

Commit ff512f5

Browse files
authored
[CI][Benchmarks] Refactor Compute Runtime builds (#19303)
- don't rebuild any of the Compute Runtime components if none of them has changed - rebuild Compute Runtime and all of its components if any of them has changed - refactor components directories' names to be more consistent ~Requires: #19158~ ~Please, review only the last commit~
1 parent 254482c commit ff512f5

File tree

11 files changed

+310
-157
lines changed

11 files changed

+310
-157
lines changed

devops/scripts/benchmarks/benches/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ def benchmarks(self) -> list[Benchmark]:
199199
def name(self) -> str:
200200
pass
201201

202-
def setup(self):
202+
@abstractmethod
203+
def setup(self) -> None:
203204
return
204205

205206
def additional_metadata(self) -> dict[str, BenchmarkMetadata]:

devops/scripts/benchmarks/benches/benchdnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def benchmarks(self) -> list:
5858
)
5959
return benchmarks
6060

61-
def setup(self):
61+
def setup(self) -> None:
6262
if options.sycl is None:
6363
return
6464

devops/scripts/benchmarks/benches/compute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def git_url(self) -> str:
5252
def git_hash(self) -> str:
5353
return "83b9ae3ebb3563552409f3a317cdc1cf3d3ca6bd"
5454

55-
def setup(self):
55+
def setup(self) -> None:
5656
if options.sycl is None:
5757
return
5858

devops/scripts/benchmarks/benches/gromacs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def benchmarks(self) -> list[Benchmark]:
5050
# GromacsBenchmark(self, "0192", "rf", "eager"),
5151
]
5252

53-
def setup(self):
53+
def setup(self) -> None:
5454
self.gromacs_src = git_clone(
5555
self.directory,
5656
"gromacs-repo",

devops/scripts/benchmarks/benches/llamacpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def git_url(self) -> str:
2828
def git_hash(self) -> str:
2929
return "916c83bfe7f8b08ada609c3b8e583cf5301e594b"
3030

31-
def setup(self):
31+
def setup(self) -> None:
3232
if options.sycl is None:
3333
return
3434

devops/scripts/benchmarks/benches/syclbench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def git_url(self) -> str:
2626
def git_hash(self) -> str:
2727
return "31fc70be6266193c4ba60eb1fe3ce26edee4ca5b"
2828

29-
def setup(self):
29+
def setup(self) -> None:
3030
if options.sycl is None:
3131
return
3232

devops/scripts/benchmarks/benches/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestSuite(Suite):
1616
def __init__(self):
1717
return
1818

19-
def setup(self):
19+
def setup(self) -> None:
2020
return
2121

2222
def name(self) -> str:

devops/scripts/benchmarks/benches/umf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def __init__(self, directory):
2626
def name(self) -> str:
2727
return "UMF"
2828

29-
def setup(self):
29+
def setup(self) -> None:
3030
if not isUMFAvailable():
31-
return []
31+
return
3232
self.built = True
3333

3434
def benchmarks(self) -> list[Benchmark]:

devops/scripts/benchmarks/benches/velocity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def git_url(self) -> str:
2929
def git_hash(self) -> str:
3030
return "b22215c16f789100449c34bf4eaa3fb178983d69"
3131

32-
def setup(self):
32+
def setup(self) -> None:
3333
if options.sycl is None:
3434
return
3535

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
from pathlib import Path
7+
import shutil
8+
9+
from utils.logger import log
10+
from utils.utils import run
11+
from options import options
12+
13+
14+
class GitProject:
15+
def __init__(
16+
self,
17+
url: str,
18+
ref: str,
19+
directory: Path,
20+
name: str,
21+
force_rebuild: bool = False,
22+
) -> None:
23+
self._url = url
24+
self._ref = ref
25+
self._directory = directory
26+
self._name = name
27+
self._force_rebuild = force_rebuild
28+
self._rebuild_needed = self._git_clone()
29+
30+
@property
31+
def src_dir(self) -> Path:
32+
return self._directory / f"{self._name}-src"
33+
34+
@property
35+
def build_dir(self) -> Path:
36+
return self._directory / f"{self._name}-build"
37+
38+
@property
39+
def install_dir(self) -> Path:
40+
return self._directory / f"{self._name}-install"
41+
42+
def needs_rebuild(self, check_build=False, check_install=False) -> bool:
43+
"""Checks if the project needs to be rebuilt.
44+
45+
Args:
46+
check_build (bool): If True, checks if the build directory exists and has some files.
47+
check_install (bool): If True, checks if the install directory exists and has some files.
48+
49+
Returns:
50+
bool: True if the project needs to be rebuilt, False otherwise.
51+
"""
52+
log.debug(f"Checking if project {self._name} needs rebuild.")
53+
if self._force_rebuild:
54+
log.debug(
55+
f"Force rebuild is enabled for project {self._name}, rebuild needed."
56+
)
57+
if Path(self.build_dir).exists():
58+
shutil.rmtree(self.build_dir)
59+
return True
60+
elif self._rebuild_needed:
61+
return True
62+
if check_build:
63+
if self.build_dir.exists() and any(
64+
path.is_file() for path in self.build_dir.glob("**/*")
65+
):
66+
log.debug(
67+
f"Build directory {self.build_dir} exists and is not empty, no rebuild needed."
68+
)
69+
else:
70+
log.debug(
71+
f"Build directory {self.build_dir} does not exist or does not contain any file, rebuild needed."
72+
)
73+
return True
74+
if check_install:
75+
if self.install_dir.exists() and any(
76+
path.is_file() for path in self.install_dir.glob("**/*")
77+
):
78+
log.debug(
79+
f"Install directory {self.install_dir} exists and is not empty, no rebuild needed."
80+
)
81+
else:
82+
log.debug(
83+
f"Install directory {self.install_dir} does not exist or does not contain any file, rebuild needed."
84+
)
85+
return True
86+
return False
87+
88+
def configure(
89+
self,
90+
extra_args: list | None = None,
91+
install_prefix=True,
92+
add_sycl: bool = False,
93+
) -> None:
94+
"""Configures the project."""
95+
cmd = [
96+
"cmake",
97+
f"-S {self.src_dir}",
98+
f"-B {self.build_dir}",
99+
f"-DCMAKE_BUILD_TYPE=Release",
100+
]
101+
if install_prefix:
102+
cmd.append(f"-DCMAKE_INSTALL_PREFIX={self.install_dir}")
103+
if extra_args:
104+
cmd.extend(extra_args)
105+
106+
run(cmd, add_sycl=add_sycl)
107+
108+
def build(
109+
self,
110+
target: str = "",
111+
add_sycl: bool = False,
112+
ld_library: list = [],
113+
timeout: int | None = None,
114+
) -> None:
115+
"""Builds the project."""
116+
target_arg = f"--target {target}" if target else ""
117+
run(
118+
f"cmake --build {self.build_dir} {target_arg} -j {options.build_jobs}",
119+
add_sycl=add_sycl,
120+
ld_library=ld_library,
121+
timeout=timeout,
122+
)
123+
124+
def install(self) -> None:
125+
"""Installs the project."""
126+
run(f"cmake --install {self.build_dir}")
127+
128+
def _git_clone(self) -> bool:
129+
"""Clone a git repository into a specified directory at a specific commit.
130+
Returns:
131+
bool: True if the repository was cloned or updated, False if it was already up-to-date.
132+
"""
133+
log.debug(f"Cloning {self._url} into {self.src_dir} at commit {self._ref}")
134+
if self.src_dir.exists() and Path(self.src_dir, ".git").exists():
135+
log.debug(
136+
f"Repository {self._url} already exists at {self.src_dir}, checking for updates."
137+
)
138+
run("git fetch", cwd=self.src_dir)
139+
target_commit = (
140+
run(f"git rev-parse {self._ref}", cwd=self.src_dir)
141+
.stdout.decode()
142+
.strip()
143+
)
144+
current_commit = (
145+
run("git rev-parse HEAD", cwd=self.src_dir).stdout.decode().strip()
146+
)
147+
if current_commit != target_commit:
148+
log.debug(
149+
f"Current commit {current_commit} does not match target {target_commit}, checking out {self._ref}."
150+
)
151+
run("git reset --hard", cwd=self.src_dir)
152+
run(f"git checkout {self._ref}", cwd=self.src_dir)
153+
else:
154+
log.debug(
155+
f"Current commit {current_commit} matches target {target_commit}, no update needed."
156+
)
157+
return False
158+
elif not self.src_dir.exists():
159+
run(f"git clone --recursive {self._url} {self.src_dir}")
160+
run(f"git checkout {self._ref}", cwd=self.src_dir)
161+
else:
162+
raise Exception(
163+
f"The directory {self.src_dir} exists but is not a git repository."
164+
)
165+
log.debug(f"Cloned {self._url} into {self.src_dir} at commit {self._ref}")
166+
return True

0 commit comments

Comments
 (0)