From df93504935b8a605ad10b6f49f96ec9c10b222fd Mon Sep 17 00:00:00 2001 From: Samuel Reeder Date: Mon, 23 Nov 2026 19:09:46 +0000 Subject: [PATCH 1/2] feat(setup): match rocm-libraries commit to Quartz nightly's TheRock commit In --torch-mode rocm, setup_env.py installs ROCm PyTorch and SDK wheels from a Quartz-selected TheRock nightly, then builds hipDNN and its providers (including miopen-provider) from rocm-libraries against that wheel's MIOpen. When the rocm-libraries submodule lags the nightly wheel across a MIOpen/miopen-provider ABI change (for example the MIOpen_private symbol rename in ROCm/rocm-libraries#16128), libmiopen_plugin.so fails to load at runtime. Resolve the rocm-libraries submodule gitlink from ROCm/TheRock at the Quartz-selected nightly's therock_commit via a tree-filtered git fetch (~10 KB, no GitHub REST API rate limit) and use it by default when rocm-libraries/ is absent: - Explicit --rocm-libraries-ref always takes precedence. - Otherwise, in rocm mode (or existing mode on a ROCm venv) with a Quartz-known therock_commit, resolve and cache rocm_libraries_commit in dnn-bench-rocm-build.json so reused venvs make no network call. - Non-ROCm modes and builds without a Quartz therock_commit keep the repository's pinned rocm-libraries submodule commit. - build-dnn-benchmark-performance-image.sh resolves the matched rocm-libraries commit on the host (with an optional --rocm-libraries-ref override) instead of overriding Quartz with the local submodule pin. - CI job summaries now print the matched rocm-libraries commit. --- .github/workflows/check-deserialize.yml | 2 +- .github/workflows/setup.yml | 2 +- ...Dockerfile.dnn-benchmark-performance-linux | 8 +- .../build-dnn-benchmark-performance-image.sh | 46 ++-- docs/setup.md | 38 ++-- setup_env.py | 166 ++++++++++++-- tests/unit/test_setup_env.py | 215 +++++++++++++++++- 7 files changed, 423 insertions(+), 54 deletions(-) diff --git a/.github/workflows/check-deserialize.yml b/.github/workflows/check-deserialize.yml index f0cdde8..8c0ea26 100644 --- a/.github/workflows/check-deserialize.yml +++ b/.github/workflows/check-deserialize.yml @@ -90,7 +90,7 @@ jobs: - name: Log the ROCm build run: | - python -c 'import json, sys; r = json.load(open(sys.argv[1])); print("ROCm", r["rocm_version"], "built", r["build_date"], "from TheRock", r["therock_commit"], "(" + r["source"] + "), untested:", r["untested"])' \ + python -c 'import json, sys; r = json.load(open(sys.argv[1])); print("ROCm", r["rocm_version"], "built", r["build_date"], "from TheRock", r["therock_commit"], "rocm-libraries", r.get("rocm_libraries_commit"), "(" + r["source"] + "), untested:", r["untested"])' \ .ci-workspace/.venv/dnn-bench-rocm-build.json | tee -a "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/setup.yml b/.github/workflows/setup.yml index 567ba28..f0296ca 100644 --- a/.github/workflows/setup.yml +++ b/.github/workflows/setup.yml @@ -122,7 +122,7 @@ jobs: - name: Log the ROCm build run: | - python -c 'import json, sys; r = json.load(open(sys.argv[1])); print("ROCm", r["rocm_version"], "built", r["build_date"], "from TheRock", r["therock_commit"], "(" + r["source"] + "), untested:", r["untested"])' \ + python -c 'import json, sys; r = json.load(open(sys.argv[1])); print("ROCm", r["rocm_version"], "built", r["build_date"], "from TheRock", r["therock_commit"], "rocm-libraries", r.get("rocm_libraries_commit"), "(" + r["source"] + "), untested:", r["untested"])' \ .ci-gpu-workspace/.venv/dnn-bench-rocm-build.json | tee -a "$GITHUB_STEP_SUMMARY" diff --git a/dockerfiles/Dockerfile.dnn-benchmark-performance-linux b/dockerfiles/Dockerfile.dnn-benchmark-performance-linux index 66f345e..0ef533c 100644 --- a/dockerfiles/Dockerfile.dnn-benchmark-performance-linux +++ b/dockerfiles/Dockerfile.dnn-benchmark-performance-linux @@ -10,9 +10,11 @@ ARG DEVICE_TARGET=gfx942 ARG FETCHCONTENT_GIT_SSL_NO_VERIFY=false ARG ROCM_TORCH_INDEX_URL=https://nightly.repo.amd.com/rocm/whl-next/ # The build context has no .git (see .dockerignore), so setup_env.py cannot -# resolve the rocm-libraries submodule pin itself. The build script passes it -# (`git rev-parse HEAD:rocm-libraries`); empty => setup warns and builds the -# moving .gitmodules branch. +# resolve the rocm-libraries submodule pin itself. The build script passes the +# rocm-libraries commit matched to ROCM_VERSION's TheRock commit (falling back +# to `git rev-parse HEAD:rocm-libraries` when Quartz has no TheRock commit). +# Empty => setup resolves rocm-libraries from Quartz's therock_commit when +# known, else warns and builds the moving .gitmodules branch. ARG ROCM_LIBRARIES_REF="" ENV DEBIAN_FRONTEND=noninteractive \ diff --git a/dockerfiles/build-dnn-benchmark-performance-image.sh b/dockerfiles/build-dnn-benchmark-performance-image.sh index d4b5380..a64bc79 100755 --- a/dockerfiles/build-dnn-benchmark-performance-image.sh +++ b/dockerfiles/build-dnn-benchmark-performance-image.sh @@ -5,6 +5,7 @@ container_command="docker" device_target="gfx942" tag="" rocm_version="" +rocm_libraries_ref="" build_args=() usage() { @@ -21,6 +22,10 @@ Options: 10.3.0a20261117. Default: the newest nightly that Quartz reports as built for the device target, selected on this host. + --rocm-libraries-ref SHA Full 40-character rocm-libraries commit to build. + Default: the rocm-libraries commit pinned by the + selected ROCm nightly's TheRock commit (falling back + to the local submodule pin if Quartz has none). -h, --help Show this help. Examples: @@ -53,6 +58,11 @@ while [[ $# -gt 0 ]]; do rocm_version="$2" shift 2 ;; + --rocm-libraries-ref) + [[ $# -ge 2 ]] || { echo "--rocm-libraries-ref requires a value" >&2; exit 2; } + rocm_libraries_ref="$2" + shift 2 + ;; -h|--help) usage exit 0 @@ -82,32 +92,40 @@ fi script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" repo_root="$(cd -- "${script_dir}/.." && pwd)" -# The image build context excludes .git, so resolve the pinned rocm-libraries -# commit here; setup_env.py otherwise falls back to a moving branch. -rocm_libraries_ref="$(git -C "${repo_root}" rev-parse HEAD:rocm-libraries 2>/dev/null || true)" -if [[ -z "${rocm_libraries_ref}" ]]; then - echo "WARNING: could not resolve the rocm-libraries submodule commit; the image will build its moving branch." >&2 -fi - -# Select the ROCm nightly here, with the same rule as setup_env.py. The image -# then installs and labels that ROCm build even when a newer nightly appears. -resolved="$(python3 - "${repo_root}/setup_env.py" "${device_target}" "${rocm_version}" <<'PY' +# Select the ROCm nightly here, with the same rule as setup_env.py, and resolve +# the matching rocm-libraries commit from its TheRock commit unless the caller +# passed --rocm-libraries-ref. The image then installs and labels that matched +# build even when a newer nightly appears. +resolved="$(python3 - "${repo_root}/setup_env.py" "${device_target}" "${rocm_version}" "${rocm_libraries_ref}" <<'PY' import importlib.util import sys spec = importlib.util.spec_from_file_location("setup_env", sys.argv[1]) setup_env = importlib.util.module_from_spec(spec) spec.loader.exec_module(setup_env) -device_target, rocm_version = sys.argv[2:] +device_target, rocm_version, rocm_libraries_ref = sys.argv[2:] if rocm_version: build = setup_env.describe_rocm_version(rocm_version, "", "linux", device_target) else: build = setup_env.select_quartz_nightly("linux", device_target) -print(build.rocm_version, build.index_url) +if not rocm_libraries_ref and build.therock_commit: + rocm_libraries_ref = setup_env.resolve_therock_rocm_libraries_commit( + build.therock_commit + ) +print(build.rocm_version, build.index_url, rocm_libraries_ref) PY )" -read -r rocm_version rocm_index_url <<<"${resolved}" -echo "ROCm ${rocm_version} from ${rocm_index_url}" +read -r rocm_version rocm_index_url rocm_libraries_ref <<<"${resolved}" + +# Fall back to the local submodule pin when Quartz had no TheRock commit (for +# example a custom --rocm-version unknown to Quartz). +if [[ -z "${rocm_libraries_ref}" ]]; then + rocm_libraries_ref="$(git -C "${repo_root}" rev-parse HEAD:rocm-libraries 2>/dev/null || true)" +fi +if [[ -z "${rocm_libraries_ref}" ]]; then + echo "WARNING: could not resolve a rocm-libraries commit; the image will build its moving branch." >&2 +fi +echo "ROCm ${rocm_version} from ${rocm_index_url} (rocm-libraries ${rocm_libraries_ref:-moving})" DOCKER_BUILDKIT="${DOCKER_BUILDKIT:-1}" "${container_command}" build \ -f "${script_dir}/Dockerfile.dnn-benchmark-performance-linux" \ diff --git a/docs/setup.md b/docs/setup.md index 14a9df8..e518898 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -273,11 +273,12 @@ Quartz. After the install, setup writes `/.venv/dnn-bench-rocm-build.json`: the ROCm wheel version, the TheRock build date and commit from Quartz, the -untested suites (`untested`, for example `["rocm"]`), the `status.json` URL, -the index URL, and what selected the build (`quartz`, `--rocm-version` or -`--torch-index-url`). The build date, commit and untested suites are `null` -when Quartz has no `status.json` for the version. Result files copy them to -`environment.rocm_build_version`, `environment.rocm_build_date`, +matched `rocm-libraries` commit (added when `rocm-libraries` is resolved from +Quartz), the untested suites (`untested`, for example `["rocm"]`), the +`status.json` URL, the index URL, and what selected the build (`quartz`, +`--rocm-version` or `--torch-index-url`). The build date, commit and untested +suites are `null` when Quartz has no `status.json` for the version. Result +files copy them to `environment.rocm_build_version`, `environment.rocm_build_date`, `environment.therock_commit` and `environment.rocm_build_untested` (see [results-schema.md](results-schema.md#environment)). @@ -292,18 +293,29 @@ and its untested suites in its log and in the job summary. `rocm-libraries/` is a git submodule. It holds the hipDNN and provider sources. -- When `rocm-libraries/` is absent, setup does a sparse, blobless clone of - the pinned submodule commit (`git rev-parse HEAD:rocm-libraries`). The clone - contains only `cmake`, `shared/ctest`, `projects/hipdnn` and - `dnn-providers`, not the full monorepo. `shared/ctest` carries the CMake +- When `rocm-libraries/` is absent, setup does a sparse, blobless clone. It + selects the commit in this order: + 1. `--rocm-libraries-ref SHA`, when passed. + 2. In `--torch-mode rocm` (or `--torch-mode existing` with a ROCm venv that + has `dnn-bench-rocm-build.json`), when Quartz supplies a `therock_commit` + for the installed ROCm nightly, the `rocm-libraries` submodule commit + pinned by that `therock_commit` in `ROCm/TheRock`. This keeps + `miopen-provider` and hipDNN in lockstep with the MIOpen libraries in the + ROCm wheel. + 3. Otherwise (`--torch-mode cpu`, `--torch-mode none`, a custom + `--torch-index-url` without Quartz, or a `--rocm-version` unknown to + Quartz), the pinned submodule commit (`git rev-parse HEAD:rocm-libraries`). + The clone contains only `.dvc`, `cmake`, `shared/ctest`, `projects/hipdnn` + and `dnn-providers`, not the full monorepo. `shared/ctest` carries the CMake file that declares hipDNN's test categories; the rest of `shared/` (Tensile and friends) stays out. -- Where no git metadata exists (Docker builds, source tarballs), give - `--rocm-libraries-ref SHA`. Without it, setup uses the moving - `.gitmodules` branch and shows a warning. +- Where no git metadata and no Quartz `therock_commit` exist (for example a + source tarball with `--torch-mode cpu`), give `--rocm-libraries-ref SHA`. + Without it, setup uses the moving `.gitmodules` branch and shows a warning. - Setup uses an existing checkout as it is. A checkout from `git submodule update --init` also works. Setup shows a warning when the - checkout is not at the pinned commit. When that checkout is sparse and was + checkout is not at the expected commit (the Quartz-matched commit in `rocm` + mode, or the pinned commit otherwise). When that checkout is sparse and was made by an older setup, the root directories added since are added to its sparse set; a full checkout is left alone. diff --git a/setup_env.py b/setup_env.py index c2abffa..ea40daa 100755 --- a/setup_env.py +++ b/setup_env.py @@ -34,6 +34,7 @@ import stat import subprocess import sys +import tempfile import time import urllib.error import urllib.request @@ -112,6 +113,10 @@ def aiter_build_requires(aiter_dir: Path) -> list[str]: # The ROCm wheel version of a nightly, for example 10.3.0a20261117. The group # is the build date. _NIGHTLY_VERSION = re.compile(r"\d+\.\d+\.\d+a(\d{8})") +# TheRock repository whose rocm-libraries submodule gitlink supplies the +# rocm-libraries commit that a Quartz-selected ROCm nightly was built from. +THEROCK_REPO_URL = "https://github.com/ROCm/TheRock.git" +THEROCK_ROCM_LIBRARIES_PATH = "rocm-libraries" # Windows has no rocm_agent_enumerator/rocminfo to detect the local arch with, # so fall back to a default target known to have published wheels. @@ -491,6 +496,65 @@ def describe_rocm_version( ) +def resolve_therock_rocm_libraries_commit( + therock_commit: str, repo_url: str = THEROCK_REPO_URL +) -> str: + """The rocm-libraries submodule commit pinned by ``therock_commit`` in TheRock. + + Uses a bare, tree-filtered git fetch of the single commit (~10 KB, no + GitHub REST API rate limit) and reads the ``rocm-libraries`` gitlink via + ``git ls-tree``. Exits with an actionable error when the commit cannot be + fetched or carries no ``rocm-libraries`` submodule entry. + """ + commit = therock_commit.strip().lower() + if not re.fullmatch(r"[0-9a-f]{40}", commit): + fail( + f"expected a 40-character TheRock commit SHA, got {therock_commit!r}.", + "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + ) + with tempfile.TemporaryDirectory(prefix="therock-ref-") as tmp: + git = ["-C", tmp] + try: + run_git(["init", "--bare", "--quiet", tmp]) + run_git( + [ + *git, + "fetch", + "--quiet", + "--depth", + "1", + "--filter=tree:0", + repo_url, + commit, + ] + ) + entry = git_output( + [*git, "ls-tree", "FETCH_HEAD", "--", THEROCK_ROCM_LIBRARIES_PATH] + ) + except subprocess.CalledProcessError as exc: + detail = (exc.stderr or exc.stdout or "").strip() + fail( + f"cannot resolve {THEROCK_ROCM_LIBRARIES_PATH} commit for " + f"TheRock {commit} from {repo_url}.", + *(line for line in (detail,) if line), + "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + ) + parts = entry.split() + if ( + len(parts) != 4 + or parts[0] != "160000" + or parts[1] != "commit" + or not re.fullmatch(r"[0-9a-f]{40}", parts[2]) + or parts[3] != THEROCK_ROCM_LIBRARIES_PATH + ): + fail( + f"TheRock commit {commit} has no '{THEROCK_ROCM_LIBRARIES_PATH}' " + f"submodule entry in {repo_url} (got {entry!r}).", + "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + ) + return parts[2] + + def default_workspace() -> Path: """Env override, else /workspace when present and writable (Linux only), else /.workspace.""" @@ -912,10 +976,13 @@ def build_parser() -> argparse.ArgumentParser: help=( "Full 40-character rocm-libraries commit to fetch when " "rocm-libraries/ is absent. " - "Default: the submodule commit pinned in this repository (`git " - "rev-parse HEAD:rocm-libraries`). Needed where no git metadata " - "exists (Docker builds, source tarballs); without it setup falls " - "back to the moving .gitmodules branch and warns." + "Default: in rocm mode with a Quartz-known ROCm nightly, the " + "rocm-libraries commit pinned by that nightly's TheRock commit " + "(so miopen-provider matches the wheel's MIOpen); otherwise the " + "submodule commit pinned in this repository (`git rev-parse " + "HEAD:rocm-libraries`). Without git metadata or Quartz metadata " + "(for example a custom --torch-index-url in a Docker build), " + "setup falls back to the moving .gitmodules branch and warns." ), ) parser.add_argument( @@ -1021,25 +1088,70 @@ def require_python_version() -> None: # -- rocm-libraries checkout -------------------------------------------- + def _resolve_rocm_libraries_ref(self) -> Tuple[str, str, Optional[str]]: + """Return ``(ref, source, therock_commit)`` for the rocm-libraries checkout. + + Precedence: + 1. Explicit ``--rocm-libraries-ref``. + 2. When ROCm PyTorch was installed from a Quartz-known TheRock nightly + (recorded in ``ROCM_BUILD_RECORD``), the ``rocm-libraries`` commit + pinned by that ``therock_commit`` so ``miopen-provider`` and hipDNN + stay in lockstep with the wheel's MIOpen. + 3. The pinned ``rocm-libraries`` git submodule commit of this repo. + """ + if self.rocm_libraries_ref: + return self.rocm_libraries_ref, "--rocm-libraries-ref", None + if self.installed_torch_mode == "rocm": + record = self._read_venv_record(ROCM_BUILD_RECORD) + if record: + therock_commit = record.get("therock_commit") + if not isinstance(therock_commit, str) or not therock_commit: + therock_commit = None + recorded_ref = record.get("rocm_libraries_commit") + if isinstance(recorded_ref, str) and re.fullmatch( + r"[0-9a-f]{40}", recorded_ref + ): + return recorded_ref, "quartz", therock_commit + if therock_commit: + print( + "Resolving rocm-libraries commit for TheRock " + f"{therock_commit[:12]}..." + ) + ref = resolve_therock_rocm_libraries_commit(therock_commit) + record["rocm_libraries_commit"] = ref + try: + (self.venv_dir / ROCM_BUILD_RECORD).write_text( + json.dumps(record) + "\n" + ) + except OSError: + pass + return ref, "quartz", therock_commit + return ( + self._pinned_submodule_commit( + "rocm-libraries", + "The hipDNN/provider build is not reproducible. Pass " + "--rocm-libraries-ref (`git rev-parse " + "HEAD:rocm-libraries` in a checkout of this repository).", + ), + "submodule", + None, + ) + def ensure_rocm_libraries_checkout(self) -> None: """Fetch rocm-libraries if absent. It is a git submodule (see .gitmodules), so `git submodule update --init` also works. This is the fast path used only when the directory - isn't already a checkout: a sparse, blobless clone of the pinned - submodule commit (or --rocm-libraries-ref), limited to the hipDNN/ - provider sources and root CMake tooling this script builds. - To build against a different ref, check it out directly, e.g. - `git -C rocm-libraries fetch --depth 1 origin && + isn't already a checkout: a sparse, blobless clone of the resolved + commit (--rocm-libraries-ref, else the Quartz-selected TheRock build's + rocm-libraries commit in rocm mode, else the pinned submodule commit), + limited to the hipDNN/provider sources and root CMake tooling this + script builds. To build against a different ref, check it out directly, + e.g. `git -C rocm-libraries fetch --depth 1 origin && git -C rocm-libraries checkout FETCH_HEAD`. """ gitmodules = str(SCRIPT_DIR / ".gitmodules") - ref = self.rocm_libraries_ref or self._pinned_submodule_commit( - "rocm-libraries", - "The hipDNN/provider build is not reproducible. Pass " - "--rocm-libraries-ref (`git rev-parse " - "HEAD:rocm-libraries` in a checkout of this repository).", - ) + ref, source, therock_commit = self._resolve_rocm_libraries_ref() # Only a full commit id can be compared with HEAD; a branch moves. pinned = re.fullmatch(r"[0-9a-f]{40}", ref) is not None @@ -1058,11 +1170,25 @@ def ensure_rocm_libraries_checkout(self) -> None: # sparse clone would otherwise go unnoticed. head = git_output(["-C", str(ROCM_LIBRARIES_DIR), "rev-parse", "HEAD"]) if pinned and head != ref: - warn( - f"rocm-libraries is at {head[:12]}, not the pinned {ref[:12]}. " - "Check out that commit in rocm-libraries/ (e.g. `git submodule " - "update rocm-libraries`) or delete the directory to fetch it." - ) + if source == "quartz": + therock_note = ( + f" (matched to TheRock {therock_commit[:12]})" + if therock_commit + else " (matched to the Quartz ROCm nightly)" + ) + warn( + f"rocm-libraries is at {head[:12]}, not {ref[:12]}" + f"{therock_note}. Check out that commit in " + "rocm-libraries/ or delete the directory to fetch it " + "(or pass --rocm-libraries-ref to override)." + ) + else: + warn( + f"rocm-libraries is at {head[:12]}, not the pinned " + f"{ref[:12]}. Check out that commit in rocm-libraries/ " + "(e.g. `git submodule update rocm-libraries`) or delete " + "the directory to fetch it." + ) if not (ROCM_LIBRARIES_DIR / "CMakePresets.json").is_file(): warn( "rocm-libraries/CMakePresets.json is missing (a non-cone " diff --git a/tests/unit/test_setup_env.py b/tests/unit/test_setup_env.py index 3f6b73d..a4a42cc 100644 --- a/tests/unit/test_setup_env.py +++ b/tests/unit/test_setup_env.py @@ -39,10 +39,18 @@ def setup_env(): @pytest.fixture(autouse=True) def _no_quartz_network(setup_env, monkeypatch): - def refuse(url): + def refuse_url(url): raise AssertionError(f"unit test fetched {url}") - monkeypatch.setattr(setup_env, "fetch_quartz_text", refuse) + def refuse_therock(therock_commit, repo_url=setup_env.THEROCK_REPO_URL): + raise AssertionError( + f"unit test resolved TheRock {therock_commit} from {repo_url}" + ) + + monkeypatch.setattr(setup_env, "fetch_quartz_text", refuse_url) + monkeypatch.setattr( + setup_env, "resolve_therock_rocm_libraries_commit", refuse_therock + ) def _quartz_document(build_date: str) -> dict: @@ -1510,6 +1518,209 @@ def test_missing_toolchain_is_installed_at_the_recorded_rocm_version( ] +# --- Quartz -> TheRock -> rocm-libraries lockstep --------------------------- + + +def _make_fake_therock_repo( + tmp_path: Path, rocm_libraries_commit: str | None +) -> tuple[Path, str]: + """Create a local bare TheRock repo whose tip optionally pins rocm-libraries.""" + src = tmp_path / "therock-src" + src.mkdir() + _git("init", "-q", "-b", "main", cwd=src) + if rocm_libraries_commit is not None: + _git( + "update-index", + "--add", + "--cacheinfo", + f"160000,{rocm_libraries_commit},rocm-libraries", + cwd=src, + ) + else: + (src / "README.md").write_text("no submodule\n") + _git("add", "README.md", cwd=src) + _git("commit", "-q", "-m", "therock pin", cwd=src) + commit = _head(src) + bare = tmp_path / "therock.git" + _git("clone", "-q", "--bare", str(src), str(bare)) + _git("config", "uploadpack.allowfilter", "true", cwd=bare) + return bare, commit + + +def test_resolve_therock_rocm_libraries_commit_reads_submodule_gitlink( + setup_env, tmp_path, monkeypatch +) -> None: + if shutil.which("git") is None: + pytest.skip("git unavailable") + # Un-stub to exercise the real git implementation against a local bare repo. + monkeypatch.undo() + expected_sha = "1234567890abcdef" * 2 + "12345678" + bare, therock_commit = _make_fake_therock_repo(tmp_path, expected_sha) + + resolved = setup_env.resolve_therock_rocm_libraries_commit( + therock_commit, repo_url=bare.as_uri() + ) + + assert resolved == expected_sha + + +def test_resolve_therock_rocm_libraries_commit_fails_when_submodule_missing( + setup_env, tmp_path, monkeypatch, capsys +) -> None: + if shutil.which("git") is None: + pytest.skip("git unavailable") + monkeypatch.undo() + bare, therock_commit = _make_fake_therock_repo(tmp_path, None) + + with pytest.raises(SystemExit) as exc: + setup_env.resolve_therock_rocm_libraries_commit( + therock_commit, repo_url=bare.as_uri() + ) + + assert exc.value.code == 1 + err = capsys.readouterr().err + assert "no 'rocm-libraries' submodule entry" in err + assert "--rocm-libraries-ref" in err + + +def test_resolve_therock_rocm_libraries_commit_rejects_bad_sha( + setup_env, monkeypatch, capsys +) -> None: + monkeypatch.undo() + with pytest.raises(SystemExit) as exc: + setup_env.resolve_therock_rocm_libraries_commit("not-a-sha") + + assert exc.value.code == 1 + assert "40-character TheRock commit SHA" in capsys.readouterr().err + + +def _two_commit_rocm_libraries(tmp_path: Path) -> tuple[str, str]: + """Advance the local rocm_libraries origin by one commit; return (first, second).""" + src = tmp_path / "src" + first = _head(src) + (src / "projects/hipdnn/matched.txt").write_text("matched\n") + _git("add", ".", cwd=src) + _git("commit", "-q", "-m", "matched commit", cwd=src) + _git("fetch", "-q", str(src), "main:main", cwd=tmp_path / "origin.git") + return first, _head(src) + + +def test_rocm_mode_checks_out_quartz_matched_rocm_libraries_and_caches_it( + setup_env, tmp_path, monkeypatch, rocm_libraries +) -> None: + submodule_sha, quartz_sha = _two_commit_rocm_libraries(tmp_path) + therock_sha = "a" * 40 + calls = [] + monkeypatch.setattr( + setup_env, + "resolve_therock_rocm_libraries_commit", + lambda sha, repo_url=setup_env.THEROCK_REPO_URL: ( + calls.append(sha), + quartz_sha, + )[1], + ) + + setup = _setup(setup_env, tmp_path) + setup.venv_dir.mkdir(parents=True) + setup.installed_torch_mode = "rocm" + record_path = setup.venv_dir / setup_env.ROCM_BUILD_RECORD + record_path.write_text( + json.dumps( + {"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": therock_sha} + ) + ) + monkeypatch.setattr(setup, "_pinned_submodule_commit", lambda *_a: submodule_sha) + + setup.ensure_rocm_libraries_checkout() + + assert calls == [therock_sha] + assert _head(rocm_libraries) == quartz_sha + saved = json.loads(record_path.read_text()) + assert saved["rocm_libraries_commit"] == quartz_sha + + # A second run against the same venv reuses the cached rocm_libraries_commit + # without querying TheRock again. + setup.ensure_rocm_libraries_checkout() + assert calls == [therock_sha] + + +def test_rocm_mode_warns_when_existing_checkout_differs_from_quartz_match( + setup_env, tmp_path, monkeypatch, capsys, rocm_libraries +) -> None: + older_sha, quartz_sha = _two_commit_rocm_libraries(tmp_path) + therock_sha = "b" * 40 + # Pre-populate rocm-libraries/ at the older commit. + _setup( + setup_env, tmp_path, "--rocm-libraries-ref", older_sha + ).ensure_rocm_libraries_checkout() + assert _head(rocm_libraries) == older_sha + + monkeypatch.setattr( + setup_env, + "resolve_therock_rocm_libraries_commit", + lambda sha, repo_url=setup_env.THEROCK_REPO_URL: quartz_sha, + ) + setup = _setup(setup_env, tmp_path) + setup.venv_dir.mkdir(parents=True) + setup.installed_torch_mode = "rocm" + (setup.venv_dir / setup_env.ROCM_BUILD_RECORD).write_text( + json.dumps( + {"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": therock_sha} + ) + ) + + setup.ensure_rocm_libraries_checkout() + + assert _head(rocm_libraries) == older_sha + err = capsys.readouterr().err + assert f"not {quartz_sha[:12]} (matched to TheRock {therock_sha[:12]})" in err + + +def test_explicit_rocm_libraries_ref_overrides_quartz_therock_commit( + setup_env, tmp_path, rocm_libraries +) -> None: + explicit_sha, _ = _two_commit_rocm_libraries(tmp_path) + # The autouse guard fails if resolve_therock_rocm_libraries_commit is called. + setup = _setup(setup_env, tmp_path, "--rocm-libraries-ref", explicit_sha) + setup.venv_dir.mkdir(parents=True) + setup.installed_torch_mode = "rocm" + record_path = setup.venv_dir / setup_env.ROCM_BUILD_RECORD + record_path.write_text( + json.dumps({"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": "c" * 40}) + ) + + setup.ensure_rocm_libraries_checkout() + + assert _head(rocm_libraries) == explicit_sha + assert "rocm_libraries_commit" not in json.loads(record_path.read_text()) + + +@pytest.mark.parametrize( + "torch_mode, record", + [ + ("cpu", {"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": "d" * 40}), + ("rocm", {"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": None}), + ("rocm", None), + ], + ids=["cpu-mode", "rocm-without-therock-commit", "rocm-without-record"], +) +def test_rocm_libraries_falls_back_to_submodule_pin_without_quartz_therock_commit( + setup_env, tmp_path, monkeypatch, rocm_libraries, torch_mode, record +) -> None: + submodule_sha, _ = _two_commit_rocm_libraries(tmp_path) + # The autouse guard fails if resolve_therock_rocm_libraries_commit is called. + setup = _setup(setup_env, tmp_path, "--torch-mode", torch_mode) + setup.venv_dir.mkdir(parents=True) + setup.installed_torch_mode = torch_mode + if record is not None: + (setup.venv_dir / setup_env.ROCM_BUILD_RECORD).write_text(json.dumps(record)) + monkeypatch.setattr(setup, "_pinned_submodule_commit", lambda *_a: submodule_sha) + + setup.ensure_rocm_libraries_checkout() + + assert _head(rocm_libraries) == submodule_sha + + def _host_gpu_archs(setup_env, monkeypatch, archs): """rocm_agent_enumerator reports ``archs`` (plus the CPU agent).""" real_run, real_which = setup_env.subprocess.run, setup_env.shutil.which From 47df5966528893838a0c80dc7cf0467a81b77791 Mon Sep 17 00:00:00 2001 From: Samuel Reeder Date: Mon, 23 Nov 2026 19:20:04 +0000 Subject: [PATCH 2/2] fix(setup): make existing-checkout TheRock lookup advisory, preserve Docker apt cache, validate ref - Make Quartz therock_commit -> rocm-libraries resolution advisory when rocm-libraries/.git already exists: warn and keep the existing checkout instead of aborting setup when offline or git is unavailable. - Capture git stderr cleanly and handle missing git (FileNotFoundError) without a traceback. - Move ARG ROCM_LIBRARIES_REF below COPY . . in Dockerfile.dnn-benchmark-performance-linux so new nightlies reuse the apt layer. - Validate --rocm-libraries-ref up front in build-dnn-benchmark-performance-image.sh before Quartz or docker build. - Update docs/setup.md options table and Docker section, and add unit tests for offline existing-checkout reuse and missing git. --- ...Dockerfile.dnn-benchmark-performance-linux | 16 ++-- .../build-dnn-benchmark-performance-image.sh | 7 ++ docs/setup.md | 26 +++--- setup_env.py | 87 ++++++++++++++----- tests/unit/test_setup_env.py | 59 ++++++++++++- 5 files changed, 150 insertions(+), 45 deletions(-) diff --git a/dockerfiles/Dockerfile.dnn-benchmark-performance-linux b/dockerfiles/Dockerfile.dnn-benchmark-performance-linux index 0ef533c..fba7c0d 100644 --- a/dockerfiles/Dockerfile.dnn-benchmark-performance-linux +++ b/dockerfiles/Dockerfile.dnn-benchmark-performance-linux @@ -9,13 +9,6 @@ FROM ${BASE_IMAGE} AS builder ARG DEVICE_TARGET=gfx942 ARG FETCHCONTENT_GIT_SSL_NO_VERIFY=false ARG ROCM_TORCH_INDEX_URL=https://nightly.repo.amd.com/rocm/whl-next/ -# The build context has no .git (see .dockerignore), so setup_env.py cannot -# resolve the rocm-libraries submodule pin itself. The build script passes the -# rocm-libraries commit matched to ROCM_VERSION's TheRock commit (falling back -# to `git rev-parse HEAD:rocm-libraries` when Quartz has no TheRock commit). -# Empty => setup resolves rocm-libraries from Quartz's therock_commit when -# known, else warns and builds the moving .gitmodules branch. -ARG ROCM_LIBRARIES_REF="" ENV DEBIAN_FRONTEND=noninteractive \ HIP_PLATFORM=amd \ @@ -50,6 +43,15 @@ COPY . . # build keeps the apt layer. ARG ROCM_VERSION="" +# The build context has no .git (see .dockerignore), so setup_env.py cannot +# resolve the rocm-libraries submodule pin itself. The build script passes the +# rocm-libraries commit matched to ROCM_VERSION's TheRock commit (falling back +# to `git rev-parse HEAD:rocm-libraries` when Quartz has no TheRock commit). +# Empty => setup resolves rocm-libraries from Quartz's therock_commit when +# known, else warns and builds the moving .gitmodules branch. Declared here, +# not at the stage top, so a new nightly keeps the apt layer. +ARG ROCM_LIBRARIES_REF="" + RUN --mount=type=cache,target=/root/.cache/pip <<'EOF' set -eu diff --git a/dockerfiles/build-dnn-benchmark-performance-image.sh b/dockerfiles/build-dnn-benchmark-performance-image.sh index a64bc79..5028c51 100755 --- a/dockerfiles/build-dnn-benchmark-performance-image.sh +++ b/dockerfiles/build-dnn-benchmark-performance-image.sh @@ -97,6 +97,7 @@ repo_root="$(cd -- "${script_dir}/.." && pwd)" # passed --rocm-libraries-ref. The image then installs and labels that matched # build even when a newer nightly appears. resolved="$(python3 - "${repo_root}/setup_env.py" "${device_target}" "${rocm_version}" "${rocm_libraries_ref}" <<'PY' +import argparse import importlib.util import sys @@ -104,6 +105,12 @@ spec = importlib.util.spec_from_file_location("setup_env", sys.argv[1]) setup_env = importlib.util.module_from_spec(spec) spec.loader.exec_module(setup_env) device_target, rocm_version, rocm_libraries_ref = sys.argv[2:] +if rocm_libraries_ref: + try: + rocm_libraries_ref = setup_env._commit_sha(rocm_libraries_ref) + except argparse.ArgumentTypeError as exc: + print(f"ERROR: --rocm-libraries-ref: {exc}", file=sys.stderr) + sys.exit(2) if rocm_version: build = setup_env.describe_rocm_version(rocm_version, "", "linux", device_target) else: diff --git a/docs/setup.md b/docs/setup.md index e518898..a7f914b 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -75,7 +75,7 @@ The setup prints the prefix as `Using hipDNN/ROCm prefix: ...`. | `--reuse-artifacts` | Reuse an installed hipDNN prefix and `hipdnn_frontend` package without building them. `rocm`, `cpu` and `none` need a pre-existing venv with matching PyTorch (`none`: no torch) and reject `--clean` before workspace changes. `existing` keeps the installed torch. CUDA-only setup needs no hipDNN bindings. | | `--no-aiter` | Skip the `AITER` stage. Only `--runtime aiter` needs it. | | `--clean` | Delete and create again the venv, and delete the hipDNN, provider and binding build directories. Not allowed with `--torch-mode existing`. | -| `--rocm-libraries-ref SHA` | Full 40-character `rocm-libraries` commit to fetch when `rocm-libraries/` is absent. Abbreviated SHAs and branch names are rejected. | +| `--rocm-libraries-ref SHA` | Full 40-character `rocm-libraries` commit to fetch when `rocm-libraries/` is absent. Default: the commit pinned by the Quartz nightly's `therock_commit` in `rocm` mode, else the repo's submodule pin. Abbreviated SHAs and branch names are rejected. | | `--cmake-arg NAME=VALUE` | Extra CMake define for the hipDNN and provider configure. Repeatable. See [Extra CMake defines](#extra-cmake-defines). | | `-y`, `--yes` | Answer yes to every prompt. Required when stdin is not a terminal and a prompt would show. | @@ -476,19 +476,23 @@ from the local checkout: | `--device-target TARGET` | `gfx942` | ROCm PyTorch architecture: `gfx90a`, `gfx942`, `gfx950`, `gfx1151` or `gfx1152`. | | `--tag TAG` | `dnn-benchmark-performance:` | Image tag. | | `--rocm-version VERSION` | newest usable Quartz nightly | ROCm wheel version to install. | +| `--rocm-libraries-ref SHA` | matched to the nightly's `therock_commit` | Full 40-character `rocm-libraries` commit to build. | | `-- ARGS...` | none | More arguments for the container build command. | -The script passes the pinned `rocm-libraries` commit to the build, because -the build context has no `.git`. The script also selects the ROCm nightly for -`--device-target` on the host, as in +The script selects the ROCm nightly for `--device-target` on the host, as in [ROCm nightly selection](#rocm-nightly-selection), unless `--rocm-version` -names one. The host thus needs `python3`. When no nightly qualifies for the -device target, for example while Quartz reports failed `gfx90a` tests, the -script stops; then pass `--rocm-version`. The script passes the version as -the `ROCM_VERSION` build argument and the wheels URL as -`ROCM_TORCH_INDEX_URL`. A new nightly thus rebuilds the setup layer. The -image carries the ROCm version in the label -`com.amd.dnn-benchmark.rocm-version`: +names one. Unless `--rocm-libraries-ref` is given, it then resolves the +matching `rocm-libraries` commit from `ROCm/TheRock` at that nightly's +`therock_commit` (falling back to the local submodule pin when Quartz has no +`therock_commit`, because the build context has no `.git`). The host thus +needs `python3`, `git` and HTTPS access to `github.com`. When no nightly +qualifies for the device target, for example while Quartz reports failed +`gfx90a` tests, the script stops; then pass `--rocm-version`. The script +passes the selected build as the `ROCM_VERSION`, `ROCM_LIBRARIES_REF` and +`ROCM_TORCH_INDEX_URL` build arguments. Both `ROCM_VERSION` and +`ROCM_LIBRARIES_REF` are declared after the `apt-get` stage, so a new nightly +reuses the apt layer and rebuilds only the setup layer. The image carries the +ROCm version in the label `com.amd.dnn-benchmark.rocm-version`: ```bash docker inspect --format \ diff --git a/setup_env.py b/setup_env.py index ea40daa..4342f40 100755 --- a/setup_env.py +++ b/setup_env.py @@ -496,27 +496,24 @@ def describe_rocm_version( ) -def resolve_therock_rocm_libraries_commit( +def _fetch_therock_rocm_libraries_commit( therock_commit: str, repo_url: str = THEROCK_REPO_URL ) -> str: - """The rocm-libraries submodule commit pinned by ``therock_commit`` in TheRock. + """Resolve the rocm-libraries gitlink at ``therock_commit`` in TheRock. - Uses a bare, tree-filtered git fetch of the single commit (~10 KB, no - GitHub REST API rate limit) and reads the ``rocm-libraries`` gitlink via - ``git ls-tree``. Exits with an actionable error when the commit cannot be - fetched or carries no ``rocm-libraries`` submodule entry. + Raises ``RuntimeError`` on invalid input, missing git, fetch failure, or a + missing submodule entry so callers can choose fatal vs advisory handling. """ commit = therock_commit.strip().lower() if not re.fullmatch(r"[0-9a-f]{40}", commit): - fail( - f"expected a 40-character TheRock commit SHA, got {therock_commit!r}.", - "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + raise RuntimeError( + f"expected a 40-character TheRock commit SHA, got {therock_commit!r}." ) with tempfile.TemporaryDirectory(prefix="therock-ref-") as tmp: git = ["-C", tmp] try: - run_git(["init", "--bare", "--quiet", tmp]) - run_git( + git_output(["init", "--bare", "--quiet", tmp]) + git_output( [ *git, "fetch", @@ -531,14 +528,20 @@ def resolve_therock_rocm_libraries_commit( entry = git_output( [*git, "ls-tree", "FETCH_HEAD", "--", THEROCK_ROCM_LIBRARIES_PATH] ) + except FileNotFoundError as exc: + raise RuntimeError( + f"git not found on PATH; cannot resolve {THEROCK_ROCM_LIBRARIES_PATH} " + f"commit for TheRock {commit}." + ) from exc except subprocess.CalledProcessError as exc: detail = (exc.stderr or exc.stdout or "").strip() - fail( + msg = ( f"cannot resolve {THEROCK_ROCM_LIBRARIES_PATH} commit for " - f"TheRock {commit} from {repo_url}.", - *(line for line in (detail,) if line), - "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + f"TheRock {commit} from {repo_url}." ) + if detail: + msg = f"{msg}\n{detail}" + raise RuntimeError(msg) from exc parts = entry.split() if ( len(parts) != 4 @@ -547,14 +550,40 @@ def resolve_therock_rocm_libraries_commit( or not re.fullmatch(r"[0-9a-f]{40}", parts[2]) or parts[3] != THEROCK_ROCM_LIBRARIES_PATH ): - fail( + raise RuntimeError( f"TheRock commit {commit} has no '{THEROCK_ROCM_LIBRARIES_PATH}' " - f"submodule entry in {repo_url} (got {entry!r}).", - "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + f"submodule entry in {repo_url} (got {entry!r})." ) return parts[2] +def resolve_therock_rocm_libraries_commit( + therock_commit: str, + repo_url: str = THEROCK_REPO_URL, + *, + required: bool = True, +) -> Optional[str]: + """The rocm-libraries submodule commit pinned by ``therock_commit`` in TheRock. + + Uses a bare, tree-filtered git fetch of the single commit (~10 KB, no + GitHub REST API rate limit) and reads the ``rocm-libraries`` gitlink via + ``git ls-tree``. When ``required`` is True, exits with an actionable error + on failure; when False (advisory check for an existing checkout), warns and + returns None. + """ + try: + return _fetch_therock_rocm_libraries_commit(therock_commit, repo_url) + except RuntimeError as exc: + lines = str(exc).splitlines() + if required: + fail( + *lines, + "Pass --rocm-libraries-ref to select rocm-libraries explicitly.", + ) + warn(*lines, "Keeping the existing rocm-libraries/ checkout.") + return None + + def default_workspace() -> Path: """Env override, else /workspace when present and writable (Linux only), else /.workspace.""" @@ -1088,7 +1117,9 @@ def require_python_version() -> None: # -- rocm-libraries checkout -------------------------------------------- - def _resolve_rocm_libraries_ref(self) -> Tuple[str, str, Optional[str]]: + def _resolve_rocm_libraries_ref( + self, *, required: bool = True + ) -> Tuple[str, str, Optional[str]]: """Return ``(ref, source, therock_commit)`` for the rocm-libraries checkout. Precedence: @@ -1096,7 +1127,9 @@ def _resolve_rocm_libraries_ref(self) -> Tuple[str, str, Optional[str]]: 2. When ROCm PyTorch was installed from a Quartz-known TheRock nightly (recorded in ``ROCM_BUILD_RECORD``), the ``rocm-libraries`` commit pinned by that ``therock_commit`` so ``miopen-provider`` and hipDNN - stay in lockstep with the wheel's MIOpen. + stay in lockstep with the wheel's MIOpen. When ``required`` is False + (reusing an existing checkout), a failed lookup warns and returns an + empty ref instead of aborting setup. 3. The pinned ``rocm-libraries`` git submodule commit of this repo. """ if self.rocm_libraries_ref: @@ -1117,7 +1150,11 @@ def _resolve_rocm_libraries_ref(self) -> Tuple[str, str, Optional[str]]: "Resolving rocm-libraries commit for TheRock " f"{therock_commit[:12]}..." ) - ref = resolve_therock_rocm_libraries_commit(therock_commit) + ref = resolve_therock_rocm_libraries_commit( + therock_commit, required=required + ) + if ref is None: + return "", "quartz", therock_commit record["rocm_libraries_commit"] = ref try: (self.venv_dir / ROCM_BUILD_RECORD).write_text( @@ -1151,12 +1188,14 @@ def ensure_rocm_libraries_checkout(self) -> None: git -C rocm-libraries checkout FETCH_HEAD`. """ gitmodules = str(SCRIPT_DIR / ".gitmodules") - ref, source, therock_commit = self._resolve_rocm_libraries_ref() + has_checkout = (ROCM_LIBRARIES_DIR / ".git").exists() + ref, source, therock_commit = self._resolve_rocm_libraries_ref( + required=not has_checkout + ) # Only a full commit id can be compared with HEAD; a branch moves. pinned = re.fullmatch(r"[0-9a-f]{40}", ref) is not None - if (ROCM_LIBRARIES_DIR / ".git").exists(): - # A sparse clone made by an older setup lacks root dirs added since. + if has_checkout: missing = [ path for path in ROCM_LIBRARIES_ROOT_DIRS diff --git a/tests/unit/test_setup_env.py b/tests/unit/test_setup_env.py index a4a42cc..f22d819 100644 --- a/tests/unit/test_setup_env.py +++ b/tests/unit/test_setup_env.py @@ -42,7 +42,9 @@ def _no_quartz_network(setup_env, monkeypatch): def refuse_url(url): raise AssertionError(f"unit test fetched {url}") - def refuse_therock(therock_commit, repo_url=setup_env.THEROCK_REPO_URL): + def refuse_therock( + therock_commit, repo_url=setup_env.THEROCK_REPO_URL, *, required=True + ): raise AssertionError( f"unit test resolved TheRock {therock_commit} from {repo_url}" ) @@ -1614,7 +1616,7 @@ def test_rocm_mode_checks_out_quartz_matched_rocm_libraries_and_caches_it( monkeypatch.setattr( setup_env, "resolve_therock_rocm_libraries_commit", - lambda sha, repo_url=setup_env.THEROCK_REPO_URL: ( + lambda sha, repo_url=setup_env.THEROCK_REPO_URL, *, required=True: ( calls.append(sha), quartz_sha, )[1], @@ -1658,7 +1660,7 @@ def test_rocm_mode_warns_when_existing_checkout_differs_from_quartz_match( monkeypatch.setattr( setup_env, "resolve_therock_rocm_libraries_commit", - lambda sha, repo_url=setup_env.THEROCK_REPO_URL: quartz_sha, + lambda sha, repo_url=setup_env.THEROCK_REPO_URL, *, required=True: quartz_sha, ) setup = _setup(setup_env, tmp_path) setup.venv_dir.mkdir(parents=True) @@ -1676,6 +1678,57 @@ def test_rocm_mode_warns_when_existing_checkout_differs_from_quartz_match( assert f"not {quartz_sha[:12]} (matched to TheRock {therock_sha[:12]})" in err +def test_rocm_mode_reuses_existing_checkout_when_therock_lookup_fails( + setup_env, tmp_path, monkeypatch, capsys, rocm_libraries +) -> None: + older_sha, _ = _two_commit_rocm_libraries(tmp_path) + _setup( + setup_env, tmp_path, "--rocm-libraries-ref", older_sha + ).ensure_rocm_libraries_checkout() + assert _head(rocm_libraries) == older_sha + + # Exercise the real resolver against an unreachable repo URL: because + # rocm-libraries/ already exists, the lookup is advisory and must warn + # instead of aborting setup. + monkeypatch.undo() + monkeypatch.setattr(setup_env, "ROCM_LIBRARIES_DIR", rocm_libraries) + monkeypatch.setattr( + setup_env, "THEROCK_REPO_URL", (tmp_path / "no-such-therock.git").as_uri() + ) + setup = _setup(setup_env, tmp_path) + setup.venv_dir.mkdir(parents=True) + setup.installed_torch_mode = "rocm" + (setup.venv_dir / setup_env.ROCM_BUILD_RECORD).write_text( + json.dumps({"rocm_version": _RECORDED_ROCM_VERSION, "therock_commit": "e" * 40}) + ) + + setup.ensure_rocm_libraries_checkout() + + assert _head(rocm_libraries) == older_sha + err = capsys.readouterr().err + assert "WARNING:" in err + assert "Keeping the existing rocm-libraries/ checkout." in err + + +def test_resolve_therock_rocm_libraries_commit_handles_missing_git( + setup_env, monkeypatch, capsys +) -> None: + monkeypatch.undo() + + def no_git(*_args, **_kwargs): + raise FileNotFoundError("git") + + monkeypatch.setattr(setup_env, "git_output", no_git) + + with pytest.raises(SystemExit) as exc: + setup_env.resolve_therock_rocm_libraries_commit("f" * 40) + + assert exc.value.code == 1 + err = capsys.readouterr().err + assert "git not found on PATH" in err + assert "--rocm-libraries-ref" in err + + def test_explicit_rocm_libraries_ref_overrides_quartz_therock_commit( setup_env, tmp_path, rocm_libraries ) -> None: