Files
lemonade/test/cpp/test_gfx_arch_gating.cpp
364d071133 Update to ROCm 7.14 (#2768)
* Update to ROCm 7.14

* Update therock download URL to tarball-multi-arch

Co-Authored-By: Claude <[email protected]>

* Update to stable diffusion 7.14 build

* Use upstream llama.cpp rocm 7.14 artifacts

* Install ROCm runtime via pip wheels, falling back to TheRock tarball

Prefer AMD's recommended pip-wheel install (rocm[libraries,device-gfxNNNN])
into a lemonade-managed venv, falling back to the TheRock tarball when
Python/venv/pip is unavailable, the arch has no device wheel, or any step
fails. The wheel builds differ from the tarball, which may resolve the
gfx1151 Windows batched-GEMM (hipErrorInvalidDeviceFunction) failure.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Force copy of HIP library to adjust for search order

* fix(sdcpp): put all TheRock runtime dirs on Windows PATH so sd-server resolves rocBLAS

(cherry picked from commit c6c9f0211c)

* fix(upscale): put all TheRock runtime dirs on Windows PATH so sd-cli resolves rocBLAS for ESRGAN

(cherry picked from commit 7099f036fc)

* Update sdcpp version

* Align llama.cpp version for rocm-stable

* fix(rocm-7.14): address code review feedback from PR #2768

- Route all loader-path sites through join_runtime_dirs(get_therock_lib_paths(...))
  so all wheel runtime dirs (HIP + BLAS) land on PATH/LD_LIBRARY_PATH
- Move LLVM dir discovery into get_therock_lib_paths; remove broken LLVM
  derivation from join_runtime_dirs
- Record install method in method.txt so rocm_install_method mismatch
  (e.g. user switches from wheel to tarball) triggers reinstall
- Track user cancellation during pip so it stops install rather than
  falling back to a ~2 GB tarball
- Add amdhip64_7.dll force-copy to llama-server and sd-cli upscale on
  Windows (system32 DLL shadowed was already mitigated in sd-server)
- Use cleanup_stale_version_dirs helper for wheel cleanup loop
- Remove dead duplicate rocm-stable branch in llamacpp_server.cpp
- Fix validate_llamacpp.yml report label (ggml-org -> lemonade-sdk)

* fix(rocm-7.14): address remaining code review issues

- Change force-copy error logging from WARNING to ERROR for roc-stable
- Download manager: parse pip wheel sizes for real progress bar, emit
  initial 0% event with human label before venv probe, emit progress
  event on 'Installing collected packages' phase
- Verify rocm_install_method in is_therock_installed_for_current_arch
  itself instead of duplicating the check in install_backend
- Clean up unused g_therock_install_method thread-local

* fix(rocm-7.14): fix MSVC build errors in TheRock code paths

MSVC rejects two constructs GCC/Clang accept:

- backend_utils.cpp captured g_therock_wheels_cancelled, a thread_local
  in an anonymous namespace, in the pip log_line lambda. Variables with
  static/thread storage duration cannot appear in a capture list; they
  are accessible directly. Dropping the capture also clears the cascading
  run_process_with_output overload-resolution errors caused by the
  ill-formed closure type.
- server.cpp declared therock_dirs inside the 'if (!rocm_arch.empty())'
  block but used it afterward for the amdhip64_7.dll copy. Hoist the
  declaration to the enclosing rocm-stable block and guard the .front()
  access against an empty vector.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(rocm-7.14): address second-round review (crash, tarball knob, workflow, mediums)

- Fix guaranteed divide-by-zero (SIGFPE) on the streamed wheel install: the
  pip size parser cut the token before the size parens and never matched pip's
  uppercase units, leaving bytes_total at 0. Rewrite as testable
  parse_pip_download_line() and guard the remaining division.
- Honour rocm_install_method=tarball in get_therock_lib_paths() and remove the
  non-selected tree on install so the ISV/OEM knob actually switches runtimes
  (also stops a per-load reinstall loop from a stale method.txt).
- validate_llamacpp.yml: validate/pin rocm-stable against ggml-org (where it is
  served) instead of the lemonade-sdk fork, stopping the weekly silent revert.
- Windows tarball LLVM dir lib->bin; drop dead join_runtime_dirs include_llvm
  param; decode UTF-8 cache paths (+ -X utf8 probe); pip --no-cache-dir; skip
  WindowsApps python stub; readable completed-row label.
- backend_versions.json: gfx908/gfx90a resolve verbatim (their gfx90X-dcgpu
  tarball 403s; verbatim returns 200, verified against repo.amd.com).
- Add unit tests for parse_pip_download_line() and is_concrete_gfx_arch().
- Docs: prefer rocm_bin=builtin over latest on the stable channel; drop the
  inaccurate "multiple ROCm versions concurrently" note.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Fix symlink match

* Fix library search dir from previous changes

* Revert back to lemonade-sdk/llama.cpp for rocm 7.14 builds

* fix(rocm-7.14): consolidate repeated comment explanations

Pre-commit hook flagged 4 concepts being explained at multiple sites:
- ROCm runtime install methods (5 sites) → consolidated to backend_utils.cpp
- Install method tracking (4 sites) → consolidated to backend_utils.cpp
- Prepending TheRock runtime dirs (3 sites) → kept compressed version in llamacpp_server.cpp
- Copying amdhip64_7.dll (3 sites) → kept compressed version in llamacpp_server.cpp

Co-Authored-By: Claude <[email protected]>

* fix(rocm-7.14): correct wheel install progress, cancel, and venv liveness

- Cancelled wheel download no longer reports "TheRock successfully
  installed": install_rocm_runtime throws on cancel so the caller rolls
  back instead of force-reporting completion.
- Per-wheel pip progress events are no longer flagged complete, so the
  download manager stops reporting the whole install done after the
  first of many wheels.
- Wheel venv liveness now checks the wheel's runtime_paths.txt directly
  instead of get_therock_lib_path(), which fell back to the tarball
  layout and reported the venv alive when only a tarball existed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Update ROCm version llamacpp

* fix(rocm-7.14): harden ROCm wheel install idempotency, paths, and markers

Address review findings in the ROCm wheel install path:
- Require runtime liveness (not just version markers) before the wheel
  install short-circuits, so a deleted venv or moved cache reinstalls
  instead of leaving a dead loader path that can't self-heal.
- Decode the UTF-8 runtime dir through path_from_utf8 before iterating so
  the HIP-runtime check works on non-ASCII Windows profile paths.
- Write version.txt last (after method.txt) in both the wheel and tarball
  paths so an interrupted install can't be mistaken for a completed one or
  silently defeat an explicit rocm_install_method preference.
- Use the cached backend_versions_config() in get_therock_lib_paths() and
  cleanup_old_therock_versions() instead of re-reading backend_versions.json
  from disk on every model load.
- Reorder the added <string> include to satisfy the alphabetical rule.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Harkirat Gill <[email protected]>
2026-08-18 16:36:16 +00:00

58 lines
1.7 KiB
C++

// Unit tests for lemon::backends::BackendUtils::is_concrete_gfx_arch().
//
// This predicate gates the ROCm wheel install: a concrete gfx target maps to a
// rocm-sdk-device wheel, while a family placeholder (gfx110X) has none and must
// fall back to the tarball. Getting it wrong either skips the wheel path for a
// supported GPU or attempts a wheel install that can't resolve a device package.
#include <iostream>
#include <string>
#include <lemon/backends/backend_utils.h>
using lemon::backends::BackendUtils;
namespace {
int g_failures = 0;
void expect(const std::string& arch, bool want) {
const bool got = BackendUtils::is_concrete_gfx_arch(arch);
if (got == want) {
std::cout << "[ok] " << arch << " -> " << (got ? "concrete" : "family/invalid") << std::endl;
} else {
std::cerr << "[FAIL] " << arch << " -> " << got << " (wanted " << want << ")" << std::endl;
++g_failures;
}
}
} // namespace
int main() {
// Concrete targets: all hex after the gfx prefix.
expect("gfx1151", true);
expect("gfx90a", true); // trailing hex letter
expect("gfx908", true);
expect("gfx942", true);
expect("gfx1100", true);
// Family placeholders: the non-hex 'X' rules them out.
expect("gfx110X", false);
expect("gfx103X", false);
expect("gfx120X", false);
// Malformed / non-gfx.
expect("gfx", false);
expect("gf", false);
expect("", false);
expect("radeon", false);
expect("gfxzzzz", false); // non-hex letters
if (g_failures > 0) {
std::cerr << "Total failures: " << g_failures << std::endl;
return 1;
}
std::cout << "All gfx arch gating unit tests passed!" << std::endl;
return 0;
}