Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions devops/actions/run-tests/benchmark/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ runs:
sycl-ls
echo "-----"

taskset -c "$CORES" ./devops/scripts/benchmarks/main.py \
"$(realpath ./llvm_test_workdir)" \
WORKDIR="$(realpath ./llvm_test_workdir)"
if [ -n "$WORKDIR" ] && [ -d "$WORKDIR" ] && [[ "$WORKDIR" == *llvm_test_workdir* ]]; then rm -rf "$WORKDIR" ; fi

taskset -c "$CORES" ./devops/scripts/benchmarks/main.py "$WORKDIR" \
--sycl "$(realpath ./toolchain)" \
--ur "$(realpath ./ur/install)" \
--adapter "$FORCELOAD_ADAPTER" \
Expand Down
8 changes: 4 additions & 4 deletions devops/scripts/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ using the built compiler located in `~/llvm/build/` and
installed Unified Runtime in directory `~/ur_install`,
and then **run** the benchmarks for `adapter_name` adapter.

The scripts will try to reuse the files stored in `~/benchmarks_workdir/`.
If any dependant projects binaries are already built, they will not be rebuilt
again if their tags match tags specified by benchmarks source code.

>NOTE: By default `level_zero` adapter is used.

>NOTE: Pay attention to the `--ur` parameter. It points directly to the directory where UR is installed.
Expand All @@ -48,10 +52,6 @@ $ cmake --build ~/ur_build -j $(nproc)
$ cmake --install ~/ur_build
```

### Rebuild
The scripts will try to reuse the files stored in `~/benchmarks_workdir/`, but the benchmarks will be rebuilt every time.
To avoid that, use `--no-rebuild` option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, a comment that scripts try to reuse binaries or rebuild projects automatically would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied


## Results

By default, the benchmark results are not stored.
Expand Down
7 changes: 5 additions & 2 deletions devops/scripts/benchmarks/benches/benchdnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ def setup(self) -> None:
self.git_tag(),
Path(options.workdir),
"onednn",
force_rebuild=True,
use_installdir=False,
)

if not self.project.needs_rebuild():
log.info(f"Rebuilding {self.project.name()} skipped")
return

extra_cmake_args = [
f"-DCMAKE_PREFIX_PATH={options.sycl}",
"-DCMAKE_CXX_COMPILER=clang++",
Expand All @@ -80,7 +84,6 @@ def setup(self) -> None:
]
self.project.configure(
extra_cmake_args,
install_prefix=False,
add_sycl=True,
)
self.project.build(
Expand Down
8 changes: 6 additions & 2 deletions devops/scripts/benchmarks/benches/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ def setup(self) -> None:
self.git_hash(),
Path(options.workdir),
"compute-benchmarks",
force_rebuild=True,
use_installdir=False,
)

if not self.project.needs_rebuild():
log.info(f"Rebuilding {self.project.name()} skipped")
return

extra_args = [
f"-DBUILD_SYCL=ON",
f"-DSYCL_COMPILER_ROOT={options.sycl}",
Expand All @@ -96,7 +100,7 @@ def setup(self) -> None:
f"-Dunified-runtime_DIR={options.ur}/lib/cmake/unified-runtime",
]

self.project.configure(extra_args, install_prefix=False, add_sycl=True)
self.project.configure(extra_args, add_sycl=True)
self.project.build(add_sycl=True)

def additional_metadata(self) -> dict[str, BenchmarkMetadata]:
Expand Down
10 changes: 7 additions & 3 deletions devops/scripts/benchmarks/benches/gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setup(self) -> None:
self.git_tag(),
Path(options.workdir),
"gromacs",
force_rebuild=True,
use_installdir=False,
)

# TODO: Detect the GPU architecture and set the appropriate flags
Expand All @@ -83,8 +83,12 @@ def setup(self) -> None:
if options.unitrace:
extra_args.append("-DGMX_USE_ITT=ON")

self.project.configure(extra_args, install_prefix=False, add_sycl=True)
self.project.build(add_sycl=True, ld_library=self.oneapi.ld_libraries())
if self.project.needs_rebuild():
self.project.configure(extra_args, add_sycl=True)
self.project.build(add_sycl=True, ld_library=self.oneapi.ld_libraries())
else:
log.info(f"Rebuilding {self.project.name()} skipped")

download(
options.workdir,
self.grappa_url(),
Expand Down
5 changes: 4 additions & 1 deletion devops/scripts/benchmarks/benches/llamacpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def setup(self) -> None:
self.git_hash(),
Path(options.workdir),
"llamacpp",
force_rebuild=True,
)

models_dir = Path(options.workdir, "llamacpp-models")
Expand All @@ -54,6 +53,10 @@ def setup(self) -> None:

self.oneapi = get_oneapi()

if not self.project.needs_rebuild():
log.info(f"Rebuilding {self.project.name()} skipped")
return

extra_args = [
f"-DGGML_SYCL=ON",
f"-DCMAKE_C_COMPILER=clang",
Expand Down
8 changes: 6 additions & 2 deletions devops/scripts/benchmarks/benches/syclbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ def setup(self) -> None:
self.git_hash(),
Path(options.workdir),
"sycl-bench",
force_rebuild=True,
use_installdir=False,
)

if not self.project.needs_rebuild():
log.info(f"Rebuilding {self.project.name()} skipped")
return

extra_args = [
f"-DCMAKE_CXX_COMPILER={options.sycl}/bin/clang++",
f"-DCMAKE_C_COMPILER={options.sycl}/bin/clang",
Expand All @@ -53,7 +57,7 @@ def setup(self) -> None:
f"-DCMAKE_CXX_FLAGS=-fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch={options.hip_arch}"
]

self.project.configure(extra_args, install_prefix=False, add_sycl=True)
self.project.configure(extra_args, add_sycl=True)
self.project.build(add_sycl=True)

def benchmarks(self) -> list[Benchmark]:
Expand Down
9 changes: 5 additions & 4 deletions devops/scripts/benchmarks/benches/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ def ld_libraries(self) -> list[str]:

def setup(self):
self.download_deps()
self.configure()
self.build()
if self.needs_rebuild():
self.configure()
self.build()
else:
log.info(f"Skipping {self.bench_name} rebuild")

def configure(self) -> None:
if options.rebuild and self.build_dir.exists():
shutil.rmtree(self.build_dir)
self.build_dir.mkdir(parents=True, exist_ok=True)

cmd = [
Expand Down
59 changes: 16 additions & 43 deletions devops/scripts/benchmarks/git_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def __init__(
ref: str,
directory: Path,
name: str,
force_rebuild: bool = False,
use_installdir: bool = True,
no_suffix_src: bool = False,
shallow_clone: bool = True,
) -> None:
self._url = url
self._ref = ref
self._directory = directory
self._name = name
self._force_rebuild = force_rebuild
self._use_installdir = use_installdir
self._no_suffix_src = no_suffix_src
self._shallow_clone = shallow_clone
self._rebuild_needed = self._setup_repo()
Expand All @@ -44,56 +44,29 @@ def build_dir(self) -> Path:
def install_dir(self) -> Path:
return self._directory / f"{self._name}-install"

def needs_rebuild(self, check_build=False, check_install=False) -> bool:
"""Checks if the project needs to be rebuilt.
def needs_rebuild(self) -> bool:
if self._rebuild_needed:
log.debug(
f"Rebuild needed because new sources were detected for project {self._name}."
)
return True

Args:
check_build (bool): If True, checks if the build directory exists and has some files.
check_install (bool): If True, checks if the install directory exists and has some files.
dir_to_check = self.install_dir if self._use_installdir else self.build_dir

Returns:
bool: True if the project needs to be rebuilt, False otherwise.
"""
log.debug(f"Checking if project {self._name} needs rebuild.")
if self._force_rebuild:
if not (
dir_to_check.exists()
and any(path.is_file() for path in dir_to_check.glob("**/*"))
):
log.debug(
f"Force rebuild is enabled for project {self._name}, rebuild needed."
f"{dir_to_check} does not exist or does not contain any file, rebuild needed."
)
if Path(self.build_dir).exists():
shutil.rmtree(self.build_dir)
return True
elif self._rebuild_needed:
return True
if check_build:
if self.build_dir.exists() and any(
path.is_file() for path in self.build_dir.glob("**/*")
):
log.debug(
f"Build directory {self.build_dir} exists and is not empty, no rebuild needed."
)
else:
log.debug(
f"Build directory {self.build_dir} does not exist or does not contain any file, rebuild needed."
)
return True
if check_install:
if self.install_dir.exists() and any(
path.is_file() for path in self.install_dir.glob("**/*")
):
log.debug(
f"Install directory {self.install_dir} exists and is not empty, no rebuild needed."
)
else:
log.debug(
f"Install directory {self.install_dir} does not exist or does not contain any file, rebuild needed."
)
return True
log.debug(f"{dir_to_check} exists and is not empty, no rebuild needed.")
return False

def configure(
self,
extra_args: list | None = None,
install_prefix: bool = True,
add_sycl: bool = False,
) -> None:
"""Configures the project."""
Expand All @@ -103,7 +76,7 @@ def configure(
f"-B {self.build_dir}",
f"-DCMAKE_BUILD_TYPE=Release",
]
if install_prefix:
if self._use_installdir:
cmd.append(f"-DCMAKE_INSTALL_PREFIX={self.install_dir}")
if extra_args:
cmd.extend(extra_args)
Expand Down
6 changes: 0 additions & 6 deletions devops/scripts/benchmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,6 @@ def validate_and_parse_env_args(env_args):
help="Unified Runtime adapter to use.",
default="level_zero",
)
parser.add_argument(
"--no-rebuild",
help="Do not rebuild the benchmarks from scratch.",
action="store_true",
)
parser.add_argument(
"--redownload",
help="Always download benchmark data dependencies, even if they already exist.",
Expand Down Expand Up @@ -694,7 +689,6 @@ def validate_and_parse_env_args(env_args):
additional_env_vars = validate_and_parse_env_args(args.env)

options.workdir = args.benchmark_directory
options.rebuild = not args.no_rebuild
options.redownload = args.redownload
options.sycl = args.sycl
options.iterations = args.iterations
Expand Down
1 change: 0 additions & 1 deletion devops/scripts/benchmarks/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Options:
ur: str = None
ur_adapter: str = None
umf: str = None
rebuild: bool = True
redownload: bool = False
benchmark_cwd: str = "INVALID"
timeout: float = 600
Expand Down
15 changes: 8 additions & 7 deletions devops/scripts/benchmarks/utils/compute_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def build_gmmlib(self, repo, commit) -> tuple[Path, bool]:
log.info("Building GMMLib...")
project = GitProject(repo, commit, Path(options.workdir), "gmmlib")
rebuilt = False
if project.needs_rebuild(check_install=True):
project.configure(install_prefix=True)
if project.needs_rebuild():
project.configure()
project.build()
project.install()
rebuilt = True
Expand All @@ -74,8 +74,8 @@ def build_level_zero(self, repo, commit) -> tuple[Path, bool]:
)

rebuilt = False
if project.needs_rebuild(check_install=True):
project.configure(install_prefix=True)
if project.needs_rebuild():
project.configure()
project.build()
project.install()
rebuilt = True
Expand All @@ -88,7 +88,7 @@ def build_igc(self, repo, commit) -> tuple[Path, bool]:
log.info("Building IGC...")
igc_project = GitProject(repo, commit, Path(options.workdir), "igc")
rebuilt = False
if igc_project.needs_rebuild(check_install=True):
if igc_project.needs_rebuild():
# Clone igc dependencies by creating a GitProject instance for each dependency.
# Repos with commit hashes as refs can't be cloned shallowly.
GitProject(
Expand Down Expand Up @@ -142,7 +142,7 @@ def build_igc(self, repo, commit) -> tuple[Path, bool]:
"-DCMAKE_C_FLAGS=-Wno-error",
"-DCMAKE_CXX_FLAGS=-Wno-error",
]
igc_project.configure(extra_args=configure_args, install_prefix=True)
igc_project.configure(extra_args=configure_args)
# set timeout to 2h. IGC takes A LONG time to build if building from scratch.
igc_project.build(timeout=60 * 60 * 2)
# cmake --install doesn't work...
Expand Down Expand Up @@ -172,6 +172,7 @@ def build_compute_runtime(self):
options.compute_runtime_tag,
Path(options.workdir),
"compute-runtime",
use_installdir=False,
)

manifest_path = project.src_dir / "manifests" / "manifest.yml"
Expand All @@ -190,7 +191,7 @@ def build_compute_runtime(self):
self.igc, self.igc_rebuilt = self.build_igc(igc_repo, igc_commit)

if (
project.needs_rebuild(check_build=True)
project.needs_rebuild()
or self.level_zero_rebuilt
or self.gmmlib_rebuilt
or (options.build_igc and self.igc_rebuilt)
Expand Down
Loading