dsv41 on Windows HIP (gfx1151): build script for ROCm 10.2 + MSVC, Linux HIP build script, portable per-byte add for the IQ1_M decode (no __vadd4 on HIP), strata_core link for the DXGI-budgeted cudaMemGetInfo

This commit is contained in:
Niko1221 committed 2026-10-23 15:38:17 +02:00
1 parent e7b3f15240
commit 084e654bcb
4 files changed
+83 -2

No files matched your search

+4
View File
@@ -783,6 +783,10 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
target_link_libraries(strata-dsv41 PRIVATE strata_dsv41_kernels ${_strata_gpu_runtime_target} ${_strata_gpu_blas_target})
find_package(Threads REQUIRED)
target_link_libraries(strata-dsv41 PRIVATE Threads::Threads)
if(WIN32 AND STRATA_ENABLE_HIP) # cudaMemGetInfo is the DXGI-budgeted hip_compat::mem_get_info (src/core/device.cu): on a Strix Halo the
# carve-out is not all the GPU may use, and the engine sizes its expert tiers by what the budget says is free
target_link_libraries(strata-dsv41 PRIVATE strata_core)
endif()
if(STRATA_NATIVE_EXPERTS) # Strata's CPU trellis kernels (tq_cpu.hpp) for the trellis experts on the CPU lane
target_link_libraries(strata-dsv41 PRIVATE strata_kernels_cpu)
target_compile_definitions(strata-dsv41 PRIVATE STRATA_DSV41_TQ_CPU=1)
+6 -2
View File
@@ -96,6 +96,10 @@ __device__ __forceinline__ int sgn4(uint32_t g, uint32_t b) {
const uint32_t lo = (((b & 15u) * 0x10204080u) & 0x80808080u) >> 7;
return (int) ((g ^ (lo * 255u)) + lo);
}
// per-byte wrapping add (CUDA's __vadd4, which HIP has not): no carry crosses a byte
__device__ __forceinline__ uint32_t add4(uint32_t a, uint32_t b) {
return ((a & 0x7f7f7f7fu) + (b & 0x7f7f7f7fu)) ^ ((a ^ b) & 0x80808080u);
}
__device__ __forceinline__ int2 tab16(uint32_t q4, const uint32_t* t) { // vecdotq's get_int_from_table_16
uint32_t tmp[2];
const uint32_t sel = 0x32103210u | ((q4 & 0x88888888u) >> 1);
@@ -212,8 +216,8 @@ __device__ __forceinline__ void decode(const uint8_t* __restrict__ row, int kb,
const uint32_t h = (uint32_t) qh[l >> 1] >> (4 * (l & 1));
const uint32_t e = tab[(uint32_t) qs[l] | ((h & 7u) << 8)];
const uint32_t dl = (h & 8u) ? 0xf7f7f7f7u : 0xf9f9f9f9u; // -8 -+ 1 in each byte
s.q[2 * l] = (int) __vadd4((e & 0x0f0f0f0fu) << 3, dl);
s.q[2 * l + 1] = (int) __vadd4(((e >> 4) & 0x0f0f0f0fu) << 3, dl);
s.q[2 * l] = (int) add4((e & 0x0f0f0f0fu) << 3, dl);
s.q[2 * l + 1] = (int) add4(((e >> 4) & 0x0f0f0f0fu) << 3, dl);
}
s.s0 = 2 * (int) (sc & 7u) + 1;
s.s1 = 2 * (int) ((sc >> 3) & 7u) + 1;
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# strata-dsv41 + the kernel parity tests for AMD (HIP) on Linux. Default arch gfx1151 (Strix Halo, RDNA3.5); gfx1201 (R9700) works the same.
# Built and ready, NOT run on a Linux Strix box (there is none); the Windows build of the same sources is the tested one.
#
# ROCM_ROOT=/opt/rocm (or the TheRock wheel root, e.g. .../_rocm_sdk_devel) tools/dsv41/build_hip_linux.sh [targets...]
# env: STRATA_HIP_ARCHS (default gfx1151), BUILD_DIR (default build-dsv41-hip), JOBS (default nproc), STRATA_GGML_DIR (llama.cpp checkout)
# Needs: cmake, ninja, a ROCm with clang++ (ROCm >= 6.4 knows gfx1151; the wheel's device package is _rocm_sdk_libraries_gfx115X_all
# or gfx1151), and glibc matching the box. The engine has no RPATH: run with the ROCm lib dir on LD_LIBRARY_PATH.
set -e
SRC="$(cd "$(dirname "$0")/../.." && pwd)"
ARCH="${STRATA_HIP_ARCHS:-gfx1151}"
R="${ROCM_ROOT:-/opt/rocm}"
B="${BUILD_DIR:-$SRC/build-dsv41-hip}"
J="${JOBS:-$(nproc)}"
CLANG="$R/llvm/bin/clang++"; [ -x "$CLANG" ] || CLANG="$R/lib/llvm/bin/clang++"
GGML=""; [ -n "$STRATA_GGML_DIR" ] && GGML="-DSTRATA_GGML_DIR=$STRATA_GGML_DIR"
BC="$R/amdgcn/bitcode"; [ -d "$BC" ] || BC="$R/lib/llvm/amdgcn/bitcode"; [ -d "$BC" ] || BC="$R/llvm/amdgcn/bitcode"
export PATH="$R/bin:$PATH"
if [ ! -f "$B/build.ninja" ]; then
cmake -S "$SRC" -B "$B" -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES="$ARCH" -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON \
-DSTRATA_NATIVE_EXPERTS=ON $GGML \
-DCMAKE_HIP_COMPILER="$CLANG" -DCMAKE_HIP_COMPILER_ROCM_ROOT="$R" \
"-DCMAKE_HIP_FLAGS=--rocm-path=$R --rocm-device-lib-path=$BC" \
"-DCMAKE_PREFIX_PATH=$R"
fi
cmake --build "$B" -j "$J" --target ${@:-strata-dsv41 ds4_iq_test} -- -k 0
echo "built in $B"
+45
View File
@@ -0,0 +1,45 @@
@echo off
rem strata-dsv41 + the kernel parity tests for AMD (HIP) on Windows, ROCm 10.2 (TheRock wheels), default gfx1151 (Strix Halo).
rem
rem tools\dsv41\win\build_hip_win.bat [targets...] (default: strata-dsv41 ds4_iq_test)
rem
rem Same toolchain as tools\hip\build_windows.bat: the ROCm venv, MSVC's headers and linker from vcvars, ROCm's clang for host and
rem device code. Settings (all optional):
rem STRATA_HIP_ARCHS gfx1151 (also gfx1100;gfx1201 ...) ROCM_VENV <repo>\.rocm-win
rem BUILD_DIR <repo>\build-dsv41-hip STRATA_GGML_DIR a llama.cpp checkout at the pinned commit
rem JOBS parallel compile jobs (default 6)
setlocal EnableDelayedExpansion
for %%I in ("%~dp0..\..\..") do set "SRC=%%~fI"
if not defined STRATA_HIP_ARCHS set "STRATA_HIP_ARCHS=gfx1151"
if not defined ROCM_VENV set "ROCM_VENV=%SRC%\.rocm-win"
if not defined BUILD_DIR set "BUILD_DIR=%SRC%\build-dsv41-hip"
if not defined JOBS set "JOBS=6"
set "TARGETS=%*"
if "%TARGETS%"=="" set "TARGETS=strata-dsv41 ds4_iq_test"
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"
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
set "VS="
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%"
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=OFF -DSTRATA_BUILD_DSV41=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
)
cmake --build "%BUILD_DIR%" -j %JOBS% --target %TARGETS% -- -k 0
echo BUILD-EXIT %errorlevel%
endlocal