Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
tools/hip: build_windows.bat and package_windows.py - the ready-made Windows HIP engine zip
Niko1221b8349a8144bb
diff --git a/.gitignore b/.gitignoreindex 26885bfe4..6e65fb388 100644--- a/.gitignore+++ b/.gitignore@@ -49,3 +49,4 @@ build-vision.bat*.done/third_party/*.zip+/.rocm-win/diff --git a/tools/hip/build_windows.bat b/tools/hip/build_windows.batnew file mode 100644index 000000000..b3d0011cf--- /dev/null+++ b/tools/hip/build_windows.bat@@ -0,0 +1,86 @@+@echo off+rem Strata's HIP (AMD) engine for Windows, and the ready-made zip setup.py downloads (strata-windows-x64-hip.zip).+rem+rem tools\hip\build_windows.bat build strata.exe + strata-device.exe and package dist\strata-windows-x64-hip.zip+rem tools\hip\build_windows.bat tests also build the HIP unit tests (ctest in build-hip-win; they need an AMD GPU)+rem+rem Needs: Visual Studio 2022 (or 2019) Build Tools with the C++ workload (the linker, the CRT and the Windows SDK),+rem Python 3.10+ and git. No admin rights and no AMD GPU: ROCm comes from AMD's TheRock Python wheels (the same+rem ROCm 10.2 nightly #325 ran on an RX 9070 XT), installed into a private venv (ROCM_VENV, ~7 GB). CMake refuses to+rem mix cl.exe with Clang for HIP, so ROCm's clang compiles the host code too (targeting the MSVC ABI, with MSVC's+rem headers and linker from vcvars); cmake/hip_backend.cmake force-includes the CUDA->HIP shim.+rem+rem Settings (environment variables, all optional):+rem STRATA_HIP_ARCHS gfx1100;gfx1101;gfx1102;gfx1200;gfx1201;gfx1030 (the cards setup supports, + gfx1102)+rem STRATA_ROCM_VERSION 10.2.0a20260930 STRATA_ROCM_INDEX https://nightly.repo.amd.com/rocm/whl-next/+rem ROCM_VENV <repo>\.rocm-win BUILD_DIR <repo>\build-hip-win DIST_DIR <repo>\dist+rem STRATA_GGML_DIR a llama.cpp checkout at the pinned commit (default: CMake fetches it)+setlocal EnableDelayedExpansion+for %%I in ("%~dp0..\..") do set "SRC=%%~fI"+if not defined STRATA_HIP_ARCHS set "STRATA_HIP_ARCHS=gfx1100;gfx1101;gfx1102;gfx1200;gfx1201;gfx1030"+if not defined STRATA_ROCM_VERSION set "STRATA_ROCM_VERSION=10.2.0a20260930"+if not defined STRATA_ROCM_INDEX set "STRATA_ROCM_INDEX=https://nightly.repo.amd.com/rocm/whl-next/"+if not defined ROCM_VENV set "ROCM_VENV=%SRC%\.rocm-win"+if not defined BUILD_DIR set "BUILD_DIR=%SRC%\build-hip-win"+if not defined DIST_DIR set "DIST_DIR=%SRC%\dist"+set "TESTS=OFF"+if /i "%~1"=="tests" set "TESTS=ON"++rem ---- 1. ROCm (TheRock wheels: the compiler, the HIP runtime, hipBLAS/hipBLASLt/rocBLAS, a device package per arch)+set "PY="+py -3 -c "import sys" >nul 2>nul && set "PY=py -3"+if not defined PY python -c "import sys" >nul 2>nul && set "PY=python"+if not defined PY (echo Python 3.10+ is needed & exit /b 1)+if not exist "%ROCM_VENV%\Scripts\python.exe" %PY% -m venv "%ROCM_VENV%" || exit /b 1+set "EXTRAS=libraries,devel"+for %%A in (%STRATA_HIP_ARCHS:;= %) do set "EXTRAS=!EXTRAS!,device-%%A"+set "STAMP=%ROCM_VENV%\strata-rocm.txt"+set "WANT=%STRATA_ROCM_VERSION% %EXTRAS%"+set "HAVE="+if exist "%STAMP%" set /p HAVE=<"%STAMP%"+if not "!HAVE!"=="!WANT!" (+ echo Installing ROCm %STRATA_ROCM_VERSION% [%EXTRAS%] into %ROCM_VENV% ...+ "%ROCM_VENV%\Scripts\python.exe" -m pip install --disable-pip-version-check --index-url "%STRATA_ROCM_INDEX%" "rocm[%EXTRAS%]==%STRATA_ROCM_VERSION%" || exit /b 1+ "%ROCM_VENV%\Scripts\rocm-sdk.exe" init || exit /b 1+ >"%STAMP%" echo !WANT!+)+for /f "delims=" %%R in ('"%ROCM_VENV%\Scripts\rocm-sdk.exe" path --root') do set "ROCM=%%R"+if not exist "%ROCM%\lib\llvm\bin\clang++.exe" (echo ROCm has no compiler in "%ROCM%" & exit /b 1)+set "ROCM_F=%ROCM:\=/%"+set "BITCODE=%ROCM_F%/lib/llvm/amdgcn/bitcode"++rem ---- 2. MSVC: the linker, the C runtime and the Windows SDK (ROCm's clang uses them)+set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"+set "VS="+if exist "%VSWHERE%" for /f "delims=" %%V in ('"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VS=%%V"+if not defined VS (echo Visual Studio Build Tools with the C++ workload are needed & exit /b 1)+call "%VS%\VC\Auxiliary\Build\vcvars64.bat" >nul || exit /b 1+set "HIP_PLATFORM=amd"+set "HIP_PATH=%ROCM%"+set "ROCM_PATH=%ROCM%"+set "PATH=%ROCM%\bin;%ROCM%\lib\llvm\bin;%PATH%"++rem ---- 3. configure + build (STRATA_PORTABLE: the CPU kernels for an AVX2 baseline, as in the NVIDIA zip)+set "GGML="+if defined STRATA_GGML_DIR set "GGML=-DSTRATA_GGML_DIR=%STRATA_GGML_DIR:\=/%"+if not exist "%BUILD_DIR%\build.ninja" (+ cmake -G Ninja -S "%SRC%" -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=Release ^+ -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=%TESTS% -DSTRATA_PREFILL_MMQ=ON ^+ -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON "-DCMAKE_HIP_ARCHITECTURES=%STRATA_HIP_ARCHS%" ^+ "-DCMAKE_C_COMPILER=%ROCM_F%/lib/llvm/bin/clang.exe" "-DCMAKE_CXX_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" ^+ "-DCMAKE_HIP_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" "-DCMAKE_HIP_COMPILER_ROCM_ROOT=%ROCM_F%" ^+ "-DCMAKE_PREFIX_PATH=%ROCM_F%" "-DCMAKE_HIP_FLAGS=--rocm-path=%ROCM_F% --rocm-device-lib-path=%BITCODE%" ^+ %GGML% || exit /b 1+)+if "%TESTS%"=="ON" (+ cmake --build "%BUILD_DIR%" || exit /b 1+) else (+ cmake --build "%BUILD_DIR%" --target strata strata-device || exit /b 1+)++rem ---- 4. the zip: the two programs, the ROCm DLLs they load (+ rocBLAS/hipBLASLt kernels for these archs), licenses+"%ROCM_VENV%\Scripts\python.exe" "%SRC%\tools\hip\package_windows.py" --build "%BUILD_DIR%" --rocm "%ROCM%" ^+ --archs "%STRATA_HIP_ARCHS%" --rocm-version "%STRATA_ROCM_VERSION%" --out "%DIST_DIR%" || exit /b 1+echo.+echo Done: %DIST_DIR%\strata-windows-x64-hip.zip+endlocaldiff --git a/tools/hip/package_windows.py b/tools/hip/package_windows.pynew file mode 100644index 000000000..b7ee3d598--- /dev/null+++ b/tools/hip/package_windows.py@@ -0,0 +1,159 @@+#!/usr/bin/env python3+"""Package the Windows HIP engine as the ready-made zip setup.py downloads (strata-windows-x64-hip.zip).++ python tools/hip/package_windows.py --build build-hip-win --rocm <rocm-sdk path --root> \\+ --archs "gfx1100;gfx1201" --rocm-version 10.2.0a20260930 --out dist++tools/hip/build_windows.bat runs it after the build. The zip holds:++ strata.exe, strata-device.exe, BUILD.json (backend "hip", the archs, the ROCm and hipBLASLt versions)+ rocm/bin/*.dll the ROCm DLLs the two programs load (their import tables, followed+ through the ROCm DLLs, + amd_comgr.dll, which the HIP runtime loads+ by name) and the Microsoft C++ runtime they import+ rocm/bin/rocblas/library, rocm/bin/hipblaslt/library the GEMM kernels, for these archs only+ rocm/.kpack/ rocBLAS's own device code for these archs (rocblas.dll finds it at+ ../.kpack from its folder)+ rocm/licenses/ the shipped components' licenses, and NOTICE.txt++setup.py puts rocm/bin first on the engine's PATH (the config's lib_dirs). The AMD display driver (AMD Software:+Adrenalin Edition) is the only thing the user installs: TheRock's HIP runtime runs on top of it.+"""+from __future__ import annotations++import argparse+import json+import os+import re+import shutil+import subprocess+import sys+import zipfile+from pathlib import Path++ROOT = Path(__file__).resolve().parents[2]+ASSET = "strata-windows-x64-hip.zip"+PROGRAMS = ("strata.exe", "strata-device.exe")+DYNAMIC = ("amd_comgr.dll",) # LoadLibrary'd by amdhip64_7.dll: not in any import table+CRT = ("msvcp140.dll", "msvcp140_1.dll", "msvcp140_2.dll", "vcruntime140.dll", "vcruntime140_1.dll")+KPACKS = ("blas_lib",) # rocblas.dll's own device code; rocSOLVER's (27 MB per arch) is never launched by Strata+LICENSES = ("rocblas", "rocsolver", "hipblas", "hipblas-common", "hipblaslt", "amd_comgr", "rocm-core")+NOTICE = """Strata's Windows HIP engine ships these AMD ROCm components unmodified, from AMD's TheRock Python wheels+(ROCm {rocm}, https://nightly.repo.amd.com/rocm/whl-next/, built from https://github.com/ROCm/TheRock):++{dlls}++Licenses: rocBLAS, hipBLAS, hipBLAS-common, hipBLASLt (and its TensileLite host and origami libraries), rocm-core: MIT;+rocSOLVER: BSD 2-clause; amd_comgr: Apache 2.0 with LLVM exceptions (files in this folder). The HIP runtime+(amdhip64_7.dll, https://github.com/ROCm/rocm-systems/tree/develop/projects/clr) and rocm_kpack.dll (TheRock) are MIT+licensed; their wheels carry no license file. The Microsoft Visual C++ runtime DLLs (msvcp140*.dll,+vcruntime140*.dll) are redistributable under the Visual Studio license (Distributable Code).+"""+++def imports(objdump: Path, dll: Path) -> list[str]:+ text = subprocess.run([str(objdump), "-p", str(dll)], capture_output=True, text=True, check=True).stdout+ return [m.group(1) for m in re.finditer(r"DLL Name:\s*(\S+)", text)]+++def crt_dir() -> Path | None:+ """The MSVC redist folder with the C++ runtime DLLs (vcvars sets VCToolsRedistDir)."""+ base = os.environ.get("VCToolsRedistDir")+ if not base:+ return None+ hits = sorted(Path(base, "x64").glob("Microsoft.VC*.CRT"))+ return hits[-1] if hits else None+++def main() -> int:+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)+ ap.add_argument("--build", required=True, type=Path)+ ap.add_argument("--rocm", required=True, type=Path, help="the ROCm root (rocm-sdk path --root)")+ ap.add_argument("--archs", required=True, help="the archs the engine was compiled for, ';'-separated")+ ap.add_argument("--rocm-version", required=True)+ ap.add_argument("--out", required=True, type=Path)+ a = ap.parse_args()+ archs = [x for x in re.split(r"[;, ]+", a.archs) if x]+ rbin = a.rocm / "bin"+ objdump = a.rocm / "lib" / "llvm" / "bin" / "llvm-objdump.exe"+ stage = a.out / "strata-windows-x64-hip"+ shutil.rmtree(stage, ignore_errors=True)+ (stage / "rocm" / "bin").mkdir(parents=True)++ for p in PROGRAMS:+ shutil.copy2(a.build / p, stage / p)++ # the ROCm DLLs: the programs' imports, followed through the ROCm DLLs themselves+ rocm_dlls = {p.name.lower(): p for p in rbin.glob("*.dll")}+ need, todo, crt = [], [stage / p for p in PROGRAMS] + [rbin / d for d in DYNAMIC], set()+ while todo:+ f = todo.pop()+ for name in imports(objdump, f):+ low = name.lower()+ if low in CRT:+ crt.add(low)+ elif low in rocm_dlls and low not in need:+ need.append(low)+ todo.append(rocm_dlls[low])+ for d in DYNAMIC:+ if d not in need:+ need.append(d)+ for d in sorted(need):+ shutil.copy2(rocm_dlls[d], stage / "rocm" / "bin" / rocm_dlls[d].name)+ cdir = crt_dir()+ if cdir is None:+ sys.exit("VCToolsRedistDir is not set: run this from a Visual Studio x64 developer prompt (vcvars64.bat)")+ for d in sorted(crt):+ shutil.copy2(cdir / d, stage / "rocm" / "bin" / d)++ # the GEMM kernels and the libraries' own device code, for these archs+ lib = stage / "rocm" / "bin" / "rocblas" / "library"+ lib.mkdir(parents=True)+ for f in (rbin / "rocblas" / "library").iterdir():+ m = re.search(r"gfx[0-9a-f]+", f.name)+ if m is None or m.group() in archs:+ shutil.copy2(f, lib / f.name)+ for arch in archs:+ src = rbin / "hipblaslt" / "library" / arch+ if src.is_dir(): # hipBLASLt has no RDNA2 (gfx1030) kernels+ shutil.copytree(src, stage / "rocm" / "bin" / "hipblaslt" / "library" / arch)+ kp = stage / "rocm" / ".kpack"+ kp.mkdir()+ kpack_src = a.rocm / ".kpack"+ for arch in archs:+ for k in KPACKS:+ f = kpack_src / f"{k}_{arch}.kpack"+ if not f.exists():+ sys.exit(f"missing {f}: install the rocm-sdk-device-{arch} wheel and run rocm-sdk init")+ shutil.copy2(f, kp / f.name)++ lic = stage / "rocm" / "licenses"+ lic.mkdir()+ for comp in LICENSES:+ for f in (a.rocm / "share" / "doc" / comp).glob("LICENSE*"):+ shutil.copy2(f, lic / f"{comp}-{f.name}")+ shipped = sorted(p.name for p in (stage / "rocm" / "bin").glob("*.dll"))+ (lic / "NOTICE.txt").write_text(NOTICE.format(rocm=a.rocm_version, dlls="\n".join(" " + d for d in shipped)),+ encoding="utf-8")++ version = re.search(r"project\(strata VERSION ([\d.]+)", (ROOT / "CMakeLists.txt").read_text()).group(1)+ hl = (a.rocm / "include" / "hipblaslt" / "hipblaslt-version.h").read_text()+ hlv = [int(re.search(rf"#define\s+HIPBLASLT_VERSION_{k}\s+(\d+)", hl).group(1)) for k in ("MAJOR", "MINOR", "PATCH")]+ meta = {"source": "prebuilt", "backend": "hip", "platform": "windows-x64", "version": version, "archs": archs,+ "rocm": a.rocm_version, "hipblaslt_version": hlv[0] * 100000 + hlv[1] * 100 + hlv[2], "vision": "none",+ "lib_dirs": ["rocm/bin"]}+ (stage / "BUILD.json").write_text(json.dumps(meta, indent=1), encoding="utf-8")++ z = a.out / ASSET+ z.unlink(missing_ok=True)+ with zipfile.ZipFile(z, "w", zipfile.ZIP_DEFLATED, compresslevel=9) as f:+ for p in sorted(stage.rglob("*")):+ if p.is_file():+ f.write(p, p.relative_to(stage).as_posix())+ size = sum(p.stat().st_size for p in stage.rglob("*") if p.is_file())+ print(f"{z}: {z.stat().st_size / 2**20:.0f} MiB ({size / 2**20:.0f} MiB unpacked), engine {version}, "+ f"{', '.join(archs)}, ROCm {a.rocm_version}, DLLs: {', '.join(shipped)}")+ return 0+++if __name__ == "__main__":+ sys.exit(main())