Skip to content

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++

HIP: RDNA4 gfx1201 beside gfx1100; the startup check compares the card with the compiled archs; setup picks ROCm and the hipBLASLt table per arch

Niko1221862c5a4767f1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 10cdc871b..8877f667d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,7 +33,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
endif()
option(STRATA_ENABLE_CUDA "Build the CUDA targets (Phase 2+)" OFF)
-option(STRATA_ENABLE_HIP "Build the HIP targets for gfx1100 wave32 hardware" OFF)
+option(STRATA_ENABLE_HIP "Build the HIP targets for wave32 AMD GPUs (gfx1100, gfx1201)" OFF)
option(STRATA_PREFILL_MMQ "Build the optional GGML MMQ prefill path for HIP" OFF)
if(STRATA_PREFILL_MMQ AND NOT STRATA_ENABLE_HIP)
message(FATAL_ERROR "STRATA_PREFILL_MMQ requires STRATA_ENABLE_HIP=ON")
diff --git a/cmake/hip_backend.cmake b/cmake/hip_backend.cmake
index 12941a386..c22d94631 100644
--- a/cmake/hip_backend.cmake
+++ b/cmake/hip_backend.cmake
@@ -1,12 +1,34 @@
-# Opt-in HIP configuration. Strata's CUDA-shaped kernels currently target RDNA3 gfx1100 wave32.
-# CMake/compiler discovery stays machine-independent; pass CMAKE_HIP_COMPILER when it is not on PATH.
+# Opt-in HIP configuration. Strata's CUDA-shaped kernels target wave32 RDNA3 / RDNA4 (64 KiB LDS per workgroup,
+# the signed dot4 instruction). CMake/compiler discovery stays machine-independent; pass CMAKE_HIP_COMPILER when it
+# is not on PATH.
if(NOT DEFINED CMAKE_HIP_ARCHITECTURES OR CMAKE_HIP_ARCHITECTURES STREQUAL "")
- set(CMAKE_HIP_ARCHITECTURES gfx1100 CACHE STRING "Strata HIP target architecture")
+ set(CMAKE_HIP_ARCHITECTURES gfx1100 CACHE STRING "Strata HIP target architecture(s), e.g. gfx1100 or gfx1100;gfx1201")
endif()
-if(NOT CMAKE_HIP_ARCHITECTURES MATCHES "^(gfx1100|gfx1201)$")
- message(FATAL_ERROR
- "Strata HIP currently supports only gfx1100 wave32; CMAKE_HIP_ARCHITECTURES is '${CMAKE_HIP_ARCHITECTURES}'")
+# Validated on real cards: gfx1100 (RX 7900 XT / XTX) and gfx1201 (RX 9070 / 9070 XT, Radeon AI PRO R9700).
+# The other RDNA3 / RDNA4 wave32 chips have the same LDS limit and dot4 instruction and build the same code, but
+# the maintainers have not run them (community reports: gfx1102 #192, gfx1200 #176).
+set(_strata_hip_validated gfx1100 gfx1201)
+set(_strata_hip_unvalidated gfx1101 gfx1102 gfx1200)
+set(STRATA_HIP_ARCH_LIST "")
+foreach(_arch IN LISTS CMAKE_HIP_ARCHITECTURES)
+ string(REGEX REPLACE ":.*$" "" _base "${_arch}") # gfx1100:xnack- -> gfx1100
+ if(_base IN_LIST _strata_hip_validated)
+ elseif(_base IN_LIST _strata_hip_unvalidated)
+ message(WARNING "Strata HIP: ${_base} builds, but it is not validated on a real card yet; please report results")
+ else()
+ message(FATAL_ERROR
+ "Strata HIP supports wave32 gfx1100 and gfx1201 (unvalidated: ${_strata_hip_unvalidated}); "
+ "CMAKE_HIP_ARCHITECTURES is '${CMAKE_HIP_ARCHITECTURES}'")
+ endif()
+ list(APPEND STRATA_HIP_ARCH_LIST "${_base}")
+endforeach()
+list(REMOVE_DUPLICATES STRATA_HIP_ARCH_LIST)
+if(NOT STRATA_HIP_ARCH_LIST)
+ message(FATAL_ERROR "Strata HIP: CMAKE_HIP_ARCHITECTURES is empty")
endif()
+# The compiled architectures reach the runtime device check (src/core/device.cu) as "gfx1100,gfx1201": a binary
+# carried to a card it has no code for stops at startup with a clear message instead of "invalid device function".
+string(REPLACE ";" "," STRATA_HIP_ARCHS "${STRATA_HIP_ARCH_LIST}")
enable_language(HIP)
find_package(hip CONFIG REQUIRED)
@@ -33,7 +55,7 @@ set(STRATA_HIP_COMPAT_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/strata/hi
add_library(strata_hip_runtime INTERFACE)
target_include_directories(strata_hip_runtime BEFORE INTERFACE
"${STRATA_HIP_COMPAT_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include")
-target_compile_definitions(strata_hip_runtime INTERFACE STRATA_USE_HIP=1)
+target_compile_definitions(strata_hip_runtime INTERFACE STRATA_USE_HIP=1 "STRATA_HIP_ARCHS=\"${STRATA_HIP_ARCHS}\"")
target_link_libraries(strata_hip_runtime INTERFACE hip::host)
foreach(_language IN ITEMS CXX HIP)
target_compile_options(strata_hip_runtime INTERFACE
@@ -55,4 +77,4 @@ foreach(_source IN ITEMS tests/hip/intrinsics.cpp tests/hip/native_qsa_score.cpp
endif()
endforeach()
-message(STATUS "Strata: HIP enabled, arch ${CMAKE_HIP_ARCHITECTURES}")
+message(STATUS "Strata: HIP enabled, arch ${STRATA_HIP_ARCHS}")
diff --git a/include/strata/core/device.hpp b/include/strata/core/device.hpp
index 7a27e4f8b..8fb93ad6b 100644
--- a/include/strata/core/device.hpp
+++ b/include/strata/core/device.hpp
@@ -26,8 +26,18 @@ struct DeviceInfo {
uint64_t free_bytes = 0;
int driver_version = 0, runtime_version = 0;
int multi_processor_count = 0;
+ std::string arch; // HIP: gcnArchName without its feature suffix ("gfx1201"); empty on CUDA
};
+// HIP builds: whether GPU `ordinal` can run this binary - its architecture must be one the binary was COMPILED
+// for (STRATA_HIP_ARCHS, set by cmake/hip_backend.cmake) and it must run wave32. "" when it can (or when there
+// is no such device: the caller's own device errors apply), else the reason in a sentence. A binary carried to
+// another card would otherwise fail later with "invalid device function". CUDA builds: always "".
+std::string gpu_arch_problem(int ordinal);
+
+// The GPU architectures this binary was compiled for ("gfx1100,gfx1201"); "" on CUDA builds.
+const char* compiled_gpu_archs();
+
// Throws when there is no CUDA device. The engine targets sm_120 specifically and must say so rather than
// run slowly on something else: `CMakeLists.txt` already refuses to COMPILE for another architecture, and
// this is the matching check at run time (a binary can be carried to a different machine).
diff --git a/include/strata/hip_compat/intrinsics.hpp b/include/strata/hip_compat/intrinsics.hpp
index ffffb2fd7..b1d7378c2 100644
--- a/include/strata/hip_compat/intrinsics.hpp
+++ b/include/strata/hip_compat/intrinsics.hpp
@@ -1,6 +1,6 @@
#pragma once
-// CUDA device intrinsics used by Strata kernels that HIP does not provide on gfx1100.
+// CUDA device intrinsics used by Strata kernels that HIP does not provide on RDNA3 / RDNA4 (wave32).
// This header is included only from the HIP cuda_runtime compatibility shim.
#if defined(__HIPCC__)
@@ -15,10 +15,11 @@ __device__ __forceinline__ int signed_byte(uint32_t word, int lane) {
// CUDA's signed __dp4a: four signed byte products accumulated modulo 2^32.
__device__ __forceinline__ int dp4a(int a, int b, int c) {
-#if (defined(__gfx1100__) || defined(__gfx1201__)) && __has_builtin(__builtin_amdgcn_sudot4)
- // RDNA3 exposes the signed/unsigned dot4 form. Mark both packed operands
- // signed to preserve CUDA __dp4a semantics; keep the portable path for
- // other HIP compilers/targets.
+#if (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1200__) || \
+ defined(__gfx1201__)) && __has_builtin(__builtin_amdgcn_sudot4)
+ // RDNA3 and RDNA4 expose the signed/unsigned dot4 form (v_dot4_i32_iu8). Mark
+ // both packed operands signed to preserve CUDA __dp4a semantics; keep the
+ // portable path for other HIP compilers/targets.
return __builtin_amdgcn_sudot4(true, a, true, b, c, false);
#else
const uint32_t ua = static_cast<uint32_t>(a);
diff --git a/setup.py b/setup.py
index b195d0605..62e92361c 100644
--- a/setup.py
+++ b/setup.py
@@ -701,13 +701,22 @@ def cuda_lib_dirs():
# ------------------------------------------------------------------------------------------------ AMD (experimental)
-# The RX 7900 XT / XTX (gfx1100) on Linux, through the HIP backend (docs/AMD_HIP.md). There is no ready-made AMD
-# engine: ROCm comes from AMD's TheRock Python wheels into .venv (no sudo; a system ROCm in /opt/rocm is used when it
-# has hipcc and hipBLAS) and the engine is compiled here. One GPU, no images yet.
-ROCM_INDEX = os.environ.get("STRATA_ROCM_INDEX", "https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/")
+# The RX 7900 XT / XTX (gfx1100) and the RX 9070 series / Radeon AI PRO R9700 (gfx1201) on Linux, through the HIP
+# backend (docs/AMD_HIP.md). There is no ready-made AMD engine: ROCm comes from AMD's TheRock Python wheels into .venv
+# (no sudo; a system ROCm 7 in /opt/rocm is used when it has hipcc and hipBLAS) and the engine is compiled here for
+# the card. One GPU, no images yet.
+ROCM_INDEXES = {"gfx1100": "https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/", # TheRock's wheels per GPU family
+ "gfx1201": "https://rocm.nightlies.amd.com/v2/gfx120X-all/"}
ROCM_VERSION = os.environ.get("STRATA_ROCM_VERSION", "7.10.0a20251120") # what Strata's HIP build was tested with
+ROCM_SYSTEM_MIN = (7, 0) # an older system ROCm is passed over for the wheels (gfx1201 needs ROCm 6.4 or newer)
AMD_ARCHS = ("gfx1100", "gfx1201")
-AMD_NAMES = {"gfx1100": "AMD Radeon RX 7900 series (gfx1100)", "gfx1201": "AMD Radeon RX 9070 / AI PRO R9700 (gfx1201)"} # when sysfs has no product name
+AMD_NAMES = {"gfx1100": "AMD Radeon RX 7900 series (gfx1100)", # when sysfs has no product name
+ "gfx1201": "AMD Radeon RX 9070 series / AI PRO R9700 (gfx1201)"}
+AMD_CARDS = "the RX 7900 XT / XTX (gfx1100) and the RX 9070 / 9070 XT / Radeon AI PRO R9700 (gfx1201)"
+
+
+def rocm_index(arch):
+ return os.environ.get("STRATA_ROCM_INDEX") or ROCM_INDEXES[arch]
def amd_gpus():
@@ -747,35 +756,88 @@ def amd_gpus():
def amd_problem(g):
if g["arch"] not in AMD_ARCHS:
- return (f"not supported - Strata's AMD backend runs on the RX 7900 XT / XTX ({', '.join(AMD_ARCHS)}) only, "
- f"this is {g['arch']}")
+ return f"not supported - Strata's AMD backend runs on {AMD_CARDS} only, this is {g['arch']}"
return None
-def rocm_root():
- """ROCm for compiling and running the HIP engine: (root, library folders). A system ROCm with hipcc and hipBLAS,
- else AMD's TheRock wheels (ROCM_VERSION, from ROCM_INDEX) installed into .venv."""
+def rocm_version(root):
+ """(major, minor) of a ROCm install, from rocm-core's header; None when it has none."""
+ try:
+ text = (Path(root) / "include" / "rocm-core" / "rocm_version.h").read_text()
+ return tuple(int(re.search(rf"#define\s+ROCM_VERSION_{k}\s+(\d+)", text).group(1)) for k in ("MAJOR", "MINOR"))
+ except (OSError, AttributeError, ValueError):
+ return None
+
+
+def rocm_root(arch):
+ """ROCm for compiling and running the HIP engine for `arch`: (root, library folders). A system ROCm 7 with hipcc
+ and hipBLAS, else AMD's TheRock wheels (ROCM_VERSION, from the card family's index) installed into .venv."""
sysroot = Path(os.environ.get("ROCM_PATH") or "/opt/rocm")
if (sysroot / "bin" / "hipcc").exists() and list((sysroot / "lib").glob("libhipblas.so*")):
- return sysroot, [str(sysroot / "lib")]
+ ver = rocm_version(sysroot)
+ if ver is None or ver >= ROCM_SYSTEM_MIN:
+ return sysroot, [str(sysroot / "lib")]
+ warn(f"the ROCm in {sysroot} is {ver[0]}.{ver[1]}; Strata needs {ROCM_SYSTEM_MIN[0]}.{ROCM_SYSTEM_MIN[1]} or "
+ "newer: using AMD's wheels in .venv instead")
+ index = rocm_index(arch)
stamp = Path(sys.prefix) / ".strata-rocm.json"
- if not stamp.exists() or json.loads(stamp.read_text()).get("version") != ROCM_VERSION:
+ have = json.loads(stamp.read_text()) if stamp.exists() else {}
+ if have.get("version") != ROCM_VERSION or have.get("index") != index:
say(f" Installing ROCm {ROCM_VERSION} for AMD GPUs into .venv (AMD's TheRock wheels, ~10 GB, no sudo) ...")
- run([sys.executable, "-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--index-url",
- ROCM_INDEX, f"rocm[libraries,devel]=={ROCM_VERSION}"])
- stamp.write_text(json.dumps({"version": ROCM_VERSION, "index": ROCM_INDEX}))
+ pip = [sys.executable, "-m", "pip", "install", "--quiet", "--disable-pip-version-check", "--index-url", index]
+ if have.get("version") == ROCM_VERSION: # the same version for another GPU family: its own libraries
+ run(pip + ["--force-reinstall", "--no-deps", f"rocm=={ROCM_VERSION}"])
+ run(pip + [f"rocm[libraries,devel]=={ROCM_VERSION}"])
+ stamp.write_text(json.dumps({"version": ROCM_VERSION, "index": index}))
sdk = Path(sys.executable).parent / "rocm-sdk"
root = Path(out([str(sdk), "path", "--root"]).strip())
if not (root / "llvm" / "bin" / "clang++").exists():
fail(f"ROCm was installed but its compiler is missing ({root})",
f"remove {stamp} and run this again; or install ROCm 7 system-wide")
+ # the card family's libraries only (gfx120X-all -> _rocm_sdk_libraries_gfx120X_all): another family's
+ # libhipblaslt.so first on the path would have no kernels for this card
+ family = "_rocm_sdk_libraries_" + index.rstrip("/").rsplit("/", 1)[-1].replace("-", "_")
dirs = [str(root / "lib")]
for sp in {Path(p) for p in sys.path if p.endswith("site-packages")}:
- dirs += [str(d / "lib") for d in sorted(sp.glob("_rocm_sdk_libraries_*")) if (d / "lib").is_dir()]
+ libs = sorted(sp.glob("_rocm_sdk_libraries_*"))
+ libs = [d for d in libs if d.name.lower() == family.lower()] or libs
+ dirs += [str(d / "lib") for d in libs if (d / "lib").is_dir()]
ok(f"ROCm: {root}")
return root, list(dict.fromkeys(dirs))
+def hipblaslt_version(lib_dirs):
+ """The installed hipBLASLt's version as the engine reads it (hipblasLtGetVersion: 1.4.1 -> 100401), from the
+ header of the ROCm whose libraries the engine loads; None when not found."""
+ for d in lib_dirs:
+ try:
+ text = (Path(d).parent / "include" / "hipblaslt" / "hipblaslt-version.h").read_text()
+ v = [int(re.search(rf"#define\s+HIPBLASLT_VERSION_{k}\s+(\d+)", text).group(1))
+ for k in ("MAJOR", "MINOR", "PATCH")]
+ except (OSError, AttributeError, ValueError):
+ continue
+ return v[0] * 100000 + v[1] * 100 + v[2]
+ return None
+
+
+def hipblaslt_table(arch, lib_dirs):
+ """tools/hip/<arch>-hipblaslt-<version>.txt for this card AND the installed hipBLASLt, else None: its solution
+ ids are valid only for that pair (the engine refuses any other table and uses plain hipBLAS)."""
+ ver = hipblaslt_version(lib_dirs)
+ table = ROOT / "tools" / "hip" / f"{arch}-hipblaslt-{ver}.txt"
+ if ver is not None and table.exists():
+ head = table.read_text().split("\n", 2)[:2]
+ if f"STRATA_HIPBLASLT_TUNING_V1 {arch} {ver}" in (h.strip() for h in head):
+ ok(f"hipBLASLt tuning table: {table.name} (faster prompts)")
+ return table
+ have = sorted(p.name for p in (ROOT / "tools" / "hip").glob(f"{arch}-hipblaslt-*.txt"))
+ warn(f"no hipBLASLt tuning table for {arch} with hipBLASLt {ver or '(version unknown)'}"
+ + (f" (have: {', '.join(have)})" if have else "")
+ + ": the prompt's dense matrix products use plain hipBLAS (tools/hip/tune_hipblaslt makes a table, "
+ "docs/AMD_HIP_PERFORMANCE.md)")
+ return None
+
+
def build_engine_hip(gpu, llama) -> Path:
"""Compile the HIP engine for this AMD GPU into engine/ (again only when its source changed: a `git pull`)."""
eng = ROOT / "engine"
@@ -783,13 +845,13 @@ def build_engine_hip(gpu, llama) -> Path:
stamp = eng / "BUILD.json"
meta = json.loads(stamp.read_text()) if stamp.exists() else {}
src = source_hash(ENGINE_SOURCES)
- if meta.get("backend") == "hip" and (eng / EXE).exists() and meta.get("src") == src:
+ if meta.get("backend") == "hip" and (eng / EXE).exists() and meta.get("src") == src and gpu["arch"] in meta.get("archs", []):
ok("engine already built for this PC")
return eng
if not (shutil.which("c++") or shutil.which("g++")) or not shutil.which("git"):
fail("a C++ compiler and git are needed to compile the AMD engine",
"Ubuntu/Debian: sudo apt install build-essential git Fedora: sudo dnf install gcc-c++ git")
- root, dirs = rocm_root()
+ root, dirs = rocm_root(gpu["arch"])
libs = [str(Path(d).parent) for d in dirs[1:]]
bitcode = next((p for p in (root / "lib" / "llvm" / "amdgcn" / "bitcode", root / "amdgcn" / "bitcode") if p.is_dir()),
root / "amdgcn" / "bitcode")
@@ -798,7 +860,7 @@ def build_engine_hip(gpu, llama) -> Path:
os.environ["LD_LIBRARY_PATH"] = os.pathsep.join(dirs + [os.environ.get("LD_LIBRARY_PATH", "")]).rstrip(os.pathsep)
os.environ["PATH"] = os.pathsep.join([str(root / "bin"), str(root / "llvm" / "bin"), os.environ.get("PATH", "")])
say(" The engine's source changed: compiling it again (only what changed, a few minutes) ..."
- if meta.get("backend") == "hip" and (eng / EXE).exists()
+ if meta.get("backend") == "hip" and (eng / EXE).exists() and gpu["arch"] in meta.get("archs", [])
else " Compiling the Strata engine for your AMD GPU (10-20 minutes, once) ...")
cmake_build(ROOT, ROOT / "build-hip", "strata",
["-DSTRATA_ENABLE_HIP=ON", "-DSTRATA_ENABLE_CUDA=OFF", "-DSTRATA_BUILD_TESTS=OFF",
@@ -912,7 +974,8 @@ def update_installed_engine(url_base) -> None:
if meta.get("backend") == "hip": # AMD: compiled here, again when its source changed
if meta.get("src") != source_hash(ENGINE_SOURCES):
try:
- g = next((x for x in amd_gpus() if amd_problem(x) is None), None)
+ usable = [x for x in amd_gpus() if amd_problem(x) is None]
+ g = next((x for x in usable if x["arch"] in meta.get("archs", [])), usable[0] if usable else None)
if g is None:
raise RuntimeError("no supported AMD GPU found")
build_engine_hip(g, get_llama_cpp())
@@ -1725,7 +1788,7 @@ def main() -> int:
say(f" GPU {g['index']}: {g['name']}, {g['vram_gb']:.0f} GB VRAM - " + (amd_problem(g) or "can be used"))
usable = [g for g in amd if amd_problem(g) is None]
if not usable:
- fail("no AMD GPU Strata can use", "the AMD backend runs on the RX 7900 XT / XTX (gfx1100) on Linux")
+ fail("no AMD GPU Strata can use", f"the AMD backend runs on {AMD_CARDS} on Linux")
if a.gpus:
fail("several GPUs sharing one model: NVIDIA only for now", "use one AMD card (--gpu N)")
if a.gpu is not None:
@@ -2057,10 +2120,11 @@ def main() -> int:
if hip:
cfg["backend"] = "hip"
# the dense prompt GEMMs through hipBLASLt with kernels measured on this GPU generation (tools/hip; +40-60%
- # prompt speed on the 7900 XTX); the engine refuses a table made for another hipBLASLt version and falls back
- tables = sorted((ROOT / "tools" / "hip").glob(f"{gpu['arch']}-hipblaslt-*.txt"))
- if tables:
- cfg["env"] = {"STRATA_HIPBLASLT_TUNING": str(tables[-1])}
+ # prompt speed on the 7900 XTX): only a table for this card's arch AND the installed hipBLASLt version (the
+ # engine refuses any other one and falls back to plain hipBLAS)
+ table = hipblaslt_table(gpu["arch"], lib_dirs)
+ if table:
+ cfg["env"] = {"STRATA_HIPBLASLT_TUNING": str(table)}
if gpu["count"] > 1 or a.gpu is not None:
cfg["gpu"] = gpu["index"] # the engine is told this card (issue #51)
cfg["gpus_asked"] = True # chosen at setup: not asked again at start
diff --git a/src/core/device.cu b/src/core/device.cu
index 1e1a7d0be..c1dfbb1c6 100644
--- a/src/core/device.cu
+++ b/src/core/device.cu
@@ -24,14 +24,80 @@ __global__ void poison_kernel(float* p, uint64_t n_floats) {
if (i < n_floats) p[i] = __int_as_float(0x7fc00000);
}
+#if defined(STRATA_USE_HIP)
+#if !defined(STRATA_HIP_ARCHS)
+#error "STRATA_HIP_ARCHS (the compiled HIP architectures) is set by cmake/hip_backend.cmake"
+#endif
+// "gfx1201:sramecc-:xnack-" -> "gfx1201"
+std::string base_arch(const char* gcn_arch_name) {
+ std::string arch(gcn_arch_name);
+ const size_t colon = arch.find(':');
+ if (colon != std::string::npos) arch.resize(colon);
+ return arch;
+}
+
+bool compiled_for(const std::string& arch) {
+ const std::string list = STRATA_HIP_ARCHS;
+ size_t a = 0;
+ while (a <= list.size()) {
+ size_t b = list.find(',', a);
+ if (b == std::string::npos) b = list.size();
+ if (!arch.empty() && list.compare(a, b - a, arch) == 0 && b - a == arch.size()) return true;
+ a = b + 1;
+ }
+ return false;
+}
+
+std::string arch_problem(const cudaDeviceProp& p, int ordinal) {
+ const std::string arch = base_arch(p.gcnArchName);
+ const std::string card = "GPU " + std::to_string(ordinal) + " (" + p.name + ", " + arch + ")";
+ if (!compiled_for(arch)) {
+ return card + " is not an architecture this Strata engine was compiled for (" + STRATA_HIP_ARCHS +
+ "); compile it for this card (./setup.sh --backend hip, or -DCMAKE_HIP_ARCHITECTURES=" + arch +
+ ", docs/AMD_HIP.md) or choose another GPU with HIP_VISIBLE_DEVICES";
+ }
+ if (p.warpSize != 32) {
+ return card + " runs wave" + std::to_string(p.warpSize) + "; Strata's HIP kernels need wave32";
+ }
+ return "";
+}
+#endif
+
} // namespace
+const char* compiled_gpu_archs() {
+#if defined(STRATA_USE_HIP)
+ return STRATA_HIP_ARCHS;
+#else
+ return "";
+#endif
+}
+
+std::string gpu_arch_problem(int ordinal) {
+#if defined(STRATA_USE_HIP)
+ int count = 0;
+ if (cudaGetDeviceCount(&count) != cudaSuccess || ordinal < 0 || ordinal >= count) {
+ cudaGetLastError();
+ return "";
+ }
+ cudaDeviceProp p{};
+ if (cudaGetDeviceProperties(&p, ordinal) != cudaSuccess) {
+ cudaGetLastError();
+ return "";
+ }
+ return arch_problem(p, ordinal);
+#else
+ (void) ordinal;
+ return "";
+#endif
+}
+
DeviceInfo device_info(int ordinal) {
int count = 0;
check(cudaGetDeviceCount(&count), "cudaGetDeviceCount");
if (count == 0) {
#if defined(STRATA_USE_HIP)
- throw CudaError("no HIP device is present; this backend targets gfx1100 wave32", -1);
+ throw CudaError(std::string("no HIP device is present; this engine was compiled for ") + STRATA_HIP_ARCHS, -1);
#else
throw CudaError("no CUDA device is present; Strata needs an NVIDIA GPU (RTX 20 series or newer)", -1);
#endif
@@ -64,11 +130,10 @@ DeviceInfo device_info(int ordinal) {
// fp32-FMA fallback below sm_80, the tensor-core prompt kernels refuse and fall back). Compiling for a
// supported arch is enforced by CMake; RUNNING on an older card is caught here, because a binary can be carried
// to a machine with an older card and would otherwise silently take whatever path the driver chose. The HIP
- // backend is validated on gfx1100 (wave32) only.
+ // backend checks the card against the architectures the binary was compiled for (and wave32).
#if defined(STRATA_USE_HIP)
- if ((std::strncmp(p.gcnArchName, "gfx1100", 7) != 0 && std::strncmp(p.gcnArchName, "gfx1201", 7) != 0) || p.warpSize != 32) {
- throw CudaError("HIP backend requires validated gfx1100 wave32 hardware", -1);
- }
+ d.arch = base_arch(p.gcnArchName);
+ if (const std::string why = arch_problem(p, ordinal); !why.empty()) throw CudaError(why, -1);
#else
if (d.cc_major * 10 + d.cc_minor < 75) {
throw CudaError("device " + d.name + " reports compute capability " + std::to_string(d.cc_major) +
diff --git a/src/core/device_main.cpp b/src/core/device_main.cpp
index e97cefca7..524e7b182 100644
--- a/src/core/device_main.cpp
+++ b/src/core/device_main.cpp
@@ -34,7 +34,8 @@ int main(int argc, char** argv) {
const strata::core::DeviceInfo d = strata::core::device_info(0);
std::printf("device %d: %s\n", d.ordinal, d.name.c_str());
#if defined(STRATA_USE_HIP)
- std::printf(" HIP target gfx1100 wave32\n");
+ std::printf(" HIP arch %s wave32 (compiled for %s)\n", d.arch.c_str(),
+ strata::core::compiled_gpu_archs());
#else
std::printf(" compute capability %d.%d (sm_%d%d)\n", d.cc_major, d.cc_minor, d.cc_major, d.cc_minor);
#endif
diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu
index f56e152bc..98b112f21 100644
--- a/src/kernels/cuda/fused_gr.cu
+++ b/src/kernels/cuda/fused_gr.cu
@@ -180,7 +180,7 @@ __global__ void __launch_bounds__(THREADS) gr_norm_multi_kernel(GrMulti m) {
}
#if defined(__HIPCC__)
-constexpr int TILE = 1280; // eight-token tile fits gfx1100's 64 KiB LDS limit
+constexpr int TILE = 1280; // eight-token tile fits RDNA3/RDNA4's 64 KiB LDS limit
#else
constexpr int TILE = 2560; // xn floats per token staged at a time: 320 chunks of 8, 10 per lane
#endif
diff --git a/src/kernels/cuda/verify_kernels.cu b/src/kernels/cuda/verify_kernels.cu
index b8a3a619f..d4717ba09 100644
--- a/src/kernels/cuda/verify_kernels.cu
+++ b/src/kernels/cuda/verify_kernels.cu
@@ -545,7 +545,7 @@ void copy_indexed(float* dst, const float* src, int64_t stride, const int32_t* i
namespace { __global__ void gpu_stamp_kernel(unsigned long long* buf, int i) {
unsigned long long t;
#if defined(__HIPCC__)
- t = wall_clock64() * 10ull; // gfx11: a constant 100 MHz counter, in ns
+ t = wall_clock64() * 10ull; // gfx11 / gfx12: a constant 100 MHz counter, in ns
#else
asm volatile("mov.u64 %0, %%globaltimer;" : "=l"(t));
#endif
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index 607008706..3c79d51eb 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -14,6 +14,7 @@
// AND IT IS PHASE 2, so hit rate is `h = 0` and the number it prints is slow on purpose
// (`phase-2-correct-engine.md:5-9`). What it is FOR is the honest tok/s figure and the logit dump.
+#include "strata/core/device.hpp"
#include "strata/core/expert_cache.hpp"
#include "strata/core/expert_source.hpp"
#include "strata/core/remote_experts.hpp"
@@ -1179,6 +1180,22 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: layer split across %zu GPUs: CUDA0, then CUDA%s (split %s)\n",
split_devs.size() + 1, devs.c_str(), o.layer_split.c_str());
}
+#if defined(STRATA_USE_HIP)
+ {
+ // every GPU this run uses must be an architecture the binary has code for (a gfx1100 build on a gfx1201
+ // card would otherwise fail later with "invalid device function")
+ std::vector<int> used{0};
+ if (multi_gpu) used.insert(used.end(), split_devs.begin(), split_devs.end());
+ for (int r = 0; r < 3; ++r)
+ if (o.expert_cache_remote[(size_t) r] > 0) used.push_back(remote_dev[r]);
+ for (const int d : used) {
+ if (const std::string why = strata::core::gpu_arch_problem(d); !why.empty()) {
+ std::fprintf(stderr, "strata generate: %s\n", why.c_str());
+ return 1;
+ }
+ }
+ }
+#endif
if (o.prefill_auto && (o.no_prefill_borrow || o.expert_profile.empty())) {
o.prefill_auto = false; // nothing to lend from: the buffers are reserved for the session, so keep them small
o.prefill_chunk = 2048;