okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-mmq-default-off: build the engine without llama.cpp's MMQ kernels by default (-DSTRATA_MMQ=ON keeps the old path; linux-aarch64 unchanged)5649b9e52

main
8.3 KiB123 linesraw
1@echo off
2rem Strata's HIP (AMD) engine for Windows, and the ready-made zip setup.py downloads (strata-windows-x64-hip.zip).
3rem
4rem   tools\hip\build_windows.bat              build strata.exe + strata-device.exe and package dist\strata-windows-x64-hip.zip
5rem   tools\hip\build_windows.bat tests        also build the HIP unit tests (ctest in build-hip-win; they need an AMD GPU)
6rem
7rem Needs: Visual Studio 2022 (or 2019) Build Tools with the C++ workload (the linker, the CRT and the Windows SDK),
8rem Python 3.10+ and git.  No admin rights and no AMD GPU: ROCm comes from AMD's TheRock Python wheels (the same
9rem ROCm 10.2 nightly #325 ran on an RX 9070 XT), installed into a private venv (ROCM_VENV, ~7 GB).  CMake refuses to
10rem mix cl.exe with Clang for HIP, so ROCm's clang compiles the host code too (targeting the MSVC ABI, with MSVC's
11rem headers and linker from vcvars); cmake/hip_backend.cmake force-includes the CUDA->HIP shim.
12rem
13rem Settings (environment variables, all optional):
14rem   STRATA_HIP_ARCHS     gfx1100;gfx1101;gfx1102;gfx1200;gfx1201;gfx1030;gfx1031;gfx1151 (the cards setup supports, + gfx1102; gfx1151 = Strix Halo;
15rem                        gfx1031 = RX 6700 XT / 6800M, #915 #1078; drop it from the list to build the zip without it)
16rem                        The release packages are built one per card family: rx9070 = gfx1200;gfx1201, rdna3 = gfx1100;gfx1101;gfx1102;gfx1151,
17rem                        rdna2 (0.2.2, RX 6000: built, not tested on a real card) = gfx1030;gfx1031; each then goes through package_engine.py --variant <name>
18rem   STRATA_ROCM_VERSION  10.2.0a20260930        STRATA_ROCM_INDEX  https://nightly.repo.amd.com/rocm/whl-next/
19rem   ROCM_VENV            <repo>\.rocm-win       BUILD_DIR          <repo>\build-hip-win     DIST_DIR  <repo>\dist
20rem   STRATA_GGML_DIR      optional override (kept for two releases): a llama.cpp checkout to take ggml from; default: the vendored third_party/strata-ggml
21rem   STRATA_ROCM_KEEP      1 = use the ROCM_VENV as it is (no pip install, even when its archs differ from STRATA_HIP_ARCHS)
22rem   STRATA_VISION_HIP_ARCHS  the GPU reader's archs (default: STRATA_HIP_ARCHS; about 70 MB of the zip per arch)
23rem   STRATA_NO_VISION     1 = skip the two picture readers (strata-vision.exe for the CPU, strata-vision-hip.exe for the GPU)
24rem   STRATA_CMAKE_EXTRA   extra cmake configure arguments (for example -DSTRATA_WINDOW_MAX_T=8)
25setlocal EnableDelayedExpansion
26for %%I in ("%~dp0..\..") do set "SRC=%%~fI"
27if not defined STRATA_HIP_ARCHS set "STRATA_HIP_ARCHS=gfx1100;gfx1101;gfx1102;gfx1200;gfx1201;gfx1030;gfx1031;gfx1151"
28if not defined STRATA_ROCM_VERSION set "STRATA_ROCM_VERSION=10.2.0a20260930"
29if not defined STRATA_ROCM_INDEX set "STRATA_ROCM_INDEX=https://nightly.repo.amd.com/rocm/whl-next/"
30if not defined ROCM_VENV set "ROCM_VENV=%SRC%\.rocm-win"
31if not defined BUILD_DIR set "BUILD_DIR=%SRC%\build-hip-win"
32if not defined DIST_DIR set "DIST_DIR=%SRC%\dist"
33set "TESTS=OFF"
34if /i "%~1"=="tests" set "TESTS=ON"
35
36rem ---- 1. ROCm (TheRock wheels: the compiler, the HIP runtime, hipBLAS/hipBLASLt/rocBLAS, a device package per arch)
37set "PY="
38py -3 -c "import sys" >nul 2>nul && set "PY=py -3"
39if not defined PY python -c "import sys" >nul 2>nul && set "PY=python"
40if not defined PY (echo Python 3.10+ is needed & exit /b 1)
41if not exist "%ROCM_VENV%\Scripts\python.exe" %PY% -m venv "%ROCM_VENV%" || exit /b 1
42set "EXTRAS=libraries,devel"
43for %%A in (%STRATA_HIP_ARCHS:;= %) do set "EXTRAS=!EXTRAS!,device-%%A"
44set "STAMP=%ROCM_VENV%\strata-rocm.txt"
45set "WANT=%STRATA_ROCM_VERSION% %EXTRAS%"
46set "HAVE="
47if exist "%STAMP%" set /p HAVE=<"%STAMP%"
48if not "!HAVE!"=="!WANT!" if not "%STRATA_ROCM_KEEP%"=="1" (
49  echo Installing ROCm %STRATA_ROCM_VERSION% [%EXTRAS%] into %ROCM_VENV% ...
50  "%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
51  "%ROCM_VENV%\Scripts\rocm-sdk.exe" init || exit /b 1
52  >"%STAMP%" echo !WANT!
53)
54for /f "delims=" %%R in ('"%ROCM_VENV%\Scripts\rocm-sdk.exe" path --root') do set "ROCM=%%R"
55if not exist "%ROCM%\lib\llvm\bin\clang++.exe" (echo ROCm has no compiler in "%ROCM%" & exit /b 1)
56set "ROCM_F=%ROCM:\=/%"
57set "BITCODE=%ROCM_F%/lib/llvm/amdgcn/bitcode"
58
59rem ---- 2. MSVC: the linker, the C runtime and the Windows SDK (ROCm's clang uses them)
60set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
61set "VS="
62if exist "%VSWHERE%" for /f "delims=" %%V in ('"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VS=%%V"
63if not defined VS (echo Visual Studio Build Tools with the C++ workload are needed & exit /b 1)
64call "%VS%\VC\Auxiliary\Build\vcvars64.bat" >nul || exit /b 1
65set "HIP_PLATFORM=amd"
66set "HIP_PATH=%ROCM%"
67set "ROCM_PATH=%ROCM%"
68set "PATH=%ROCM%\bin;%ROCM%\lib\llvm\bin;%PATH%"
69
70rem ---- 3. configure + build (STRATA_PORTABLE: the CPU kernels for an AVX2 baseline, as in the NVIDIA zip)
71set "GGML="
72if defined STRATA_GGML_DIR set "GGML=-DSTRATA_GGML_DIR=%STRATA_GGML_DIR:\=/%"
73if not exist "%BUILD_DIR%\build.ninja" (
74  cmake -G Ninja -S "%SRC%" -B "%BUILD_DIR%" -DCMAKE_BUILD_TYPE=Release ^
75    -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=%TESTS% -DSTRATA_PREFILL_MMQ=ON ^
76    -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON "-DCMAKE_HIP_ARCHITECTURES=%STRATA_HIP_ARCHS%" ^
77    "-DCMAKE_C_COMPILER=%ROCM_F%/lib/llvm/bin/clang.exe" "-DCMAKE_CXX_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" ^
78    "-DCMAKE_HIP_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" "-DCMAKE_HIP_COMPILER_ROCM_ROOT=%ROCM_F%" ^
79    "-DCMAKE_PREFIX_PATH=%ROCM_F%" "-DCMAKE_HIP_FLAGS=--rocm-path=%ROCM_F% --rocm-device-lib-path=%BITCODE%" ^
80    -DSTRATA_MMQ=OFF %GGML% %STRATA_CMAKE_EXTRA% || exit /b 1
81)
82if "%TESTS%"=="ON" (
83  cmake --build "%BUILD_DIR%" || exit /b 1
84) else (
85  cmake --build "%BUILD_DIR%" --target strata strata-device || exit /b 1
86)
87
88rem ---- 3b. the picture readers (tools/vision, the same llama.cpp as the engine): strata-vision.exe on the CPU (MSVC, portable: the
89rem      fallback that starts on any PC) and strata-vision-hip.exe on the GPU (ROCm's clang, ggml-hip, the archs above)
90set "VISION_ARGS="
91if not defined STRATA_VISION_HIP_ARCHS set "STRATA_VISION_HIP_ARCHS=%STRATA_HIP_ARCHS%"
92if not "%STRATA_NO_VISION%"=="1" (
93  rem llama.cpp's sources are the vendored third_party\strata-llama (tools/vision's default); STRATA_GGML_DIR names a checkout to build from instead
94  set "VLLAMA="
95  if defined STRATA_GGML_DIR (
96    set "LLAMA=%STRATA_GGML_DIR%"
97    set "LLAMA=!LLAMA:\=/!"
98    if not exist "!LLAMA!/tools/mtmd" (echo llama.cpp with tools/mtmd not found in !LLAMA! - check STRATA_GGML_DIR & exit /b 1)
99    set VLLAMA="-DLLAMA_DIR=!LLAMA!"
100  )
101  if not exist "%SRC%\build-vision-cpu-win\build.ninja" (
102    cmake -G Ninja -S "%SRC%\tools\vision" -B "%SRC%\build-vision-cpu-win" -DCMAKE_BUILD_TYPE=Release !VLLAMA! ^
103      -DSTRATA_VISION_CUDA=OFF -DSTRATA_PORTABLE=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl || exit /b 1
104  )
105  cmake --build "%SRC%\build-vision-cpu-win" --target strata-vision || exit /b 1
106  if not exist "%SRC%\build-vision-hip-win\build.ninja" (
107    cmake -G Ninja -S "%SRC%\tools\vision" -B "%SRC%\build-vision-hip-win" -DCMAKE_BUILD_TYPE=Release !VLLAMA! ^
108      -DSTRATA_VISION_HIP=ON "-DSTRATA_VISION_HIP_ARCHS=%STRATA_VISION_HIP_ARCHS%" -DSTRATA_PORTABLE=ON ^
109      "-DCMAKE_CXX_FLAGS=--rocm-path=%ROCM_F% --rocm-device-lib-path=%BITCODE%" ^
110      "-DCMAKE_C_COMPILER=%ROCM_F%/lib/llvm/bin/clang.exe" "-DCMAKE_CXX_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" ^
111      "-DCMAKE_HIP_COMPILER=%ROCM_F%/lib/llvm/bin/clang++.exe" "-DCMAKE_HIP_COMPILER_ROCM_ROOT=%ROCM_F%" ^
112      "-DCMAKE_PREFIX_PATH=%ROCM_F%" "-DCMAKE_HIP_FLAGS=--rocm-path=%ROCM_F% --rocm-device-lib-path=%BITCODE%" || exit /b 1
113  )
114  cmake --build "%SRC%\build-vision-hip-win" --target strata-vision || exit /b 1
115  set "VISION_ARGS=--vision-cpu %SRC%\build-vision-cpu-win\bin\strata-vision.exe --vision-hip %SRC%\build-vision-hip-win\bin\strata-vision-hip.exe"
116)
117
118rem ---- 4. the zip: the programs, the ROCm DLLs they load (+ rocBLAS/hipBLASLt kernels for these archs), licenses
119"%ROCM_VENV%\Scripts\python.exe" "%SRC%\tools\hip\package_windows.py" --build "%BUILD_DIR%" --rocm "%ROCM%" ^
120  --archs "%STRATA_HIP_ARCHS%" --rocm-version "%STRATA_ROCM_VERSION%" --out "%DIST_DIR%" !VISION_ARGS! || exit /b 1
121echo.
122echo Done: %DIST_DIR%\strata-windows-x64-hip.zip
123endlocal