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++
prefill: the gfx11 WMMA gates match the compiled arch list (no silent zeros on gfx1103 / gfx1152), cached per device
Niko12211bb3279d7492
diff --git a/include/strata/kernels/gfx_arch.hpp b/include/strata/kernels/gfx_arch.hppnew file mode 100644index 000000000..64bc78dd3--- /dev/null+++ b/include/strata/kernels/gfx_arch.hpp@@ -0,0 +1,30 @@+// include/strata/kernels/gfx_arch.hpp - which AMD architecture names the gfx11 matrix-core code was built for.+//+// The WMMA kernels select their intrinsic with `#if defined(__gfx1100__) || ... || defined(__gfx1151__)`: a gfx11 part+// outside that list (gfx1103, gfx1152, ...) gets an empty or trapping body. The runtime gates therefore match the SAME+// list, not the "gfx11" prefix, so such a part falls back to hipBLASLt / the portable kernels instead of launching code+// that is not there. Pure string matching (no HIP headers), usable from host code of any build.+#pragma once++#include <cstddef>+#include <cstring>++namespace strata::kernels {++/// `gcn` is hipDeviceProp_t::gcnArchName ("gfx1151", or "gfx1151:sramecc-:xnack-"): true when it is exactly `name`.+inline bool gfx_arch_is(const char* gcn, const char* name) {+ if (gcn == nullptr) return false;+ const std::size_t n = std::strlen(name);+ return std::strncmp(gcn, name, n) == 0 && (gcn[n] == '\0' || gcn[n] == ':');+}++/// The gfx11 targets the matrix-core kernels (prompt GEMM / attention / scorer / fused experts) are compiled for.+inline bool gfx_arch_is_gfx11_wmma(const char* gcn) {+ return gfx_arch_is(gcn, "gfx1100") || gfx_arch_is(gcn, "gfx1101") || gfx_arch_is(gcn, "gfx1102") ||+ gfx_arch_is(gcn, "gfx1150") || gfx_arch_is(gcn, "gfx1151");+}++/// Strix Halo (Ryzen AI Max, RDNA3.5): the part the gfx1151 defaults (docs/STRIX_HALO.md) are measured on.+inline bool gfx_arch_is_gfx1151(const char* gcn) { return gfx_arch_is(gcn, "gfx1151"); }++} // namespace strata::kernelsdiff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cuindex cfc5a001e..b34656b8e 100644--- a/src/kernels/cuda/qsa_prompt_attn.cu+++ b/src/kernels/cuda/qsa_prompt_attn.cu@@ -3,6 +3,7 @@#include <cstdlib>#include <cstring>#include "strata/kernels/qsa_prompt_attn.hpp"+#include "strata/kernels/gfx_arch.hpp"#include "strata/kernels/kv_q8.hpp"#include "strata/kernels/kv_q4.hpp"@@ -1407,7 +1408,7 @@ bool hip_wmma_usable() {if (arch[dev] == 0) {hipDeviceProp_t prop{};if (hipGetDeviceProperties(&prop, dev) != hipSuccess) { (void) hipGetLastError(); return false; }- arch[dev] = std::strncmp(prop.gcnArchName, "gfx12", 5) == 0 || std::strncmp(prop.gcnArchName, "gfx11", 5) == 0+ arch[dev] = std::strncmp(prop.gcnArchName, "gfx12", 5) == 0 || strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName)? 1 : 2;static bool told = false;if (!told) {diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cuindex 305969e6a..638f27e49 100644--- a/src/kernels/cuda/qsa_select.cu+++ b/src/kernels/cuda/qsa_select.cu@@ -3,6 +3,7 @@#include <cstdlib>#include <cstring>#include "strata/kernels/qsa_select.hpp"+#include "strata/kernels/gfx_arch.hpp"#include <cuda_runtime.h>@@ -448,7 +449,7 @@ bool sel_gfx12_device() {cudaDeviceProp prop;ok[dev] = (cudaGetDeviceProperties(&prop, dev) == cudaSuccess &&(std::strncmp(prop.gcnArchName, "gfx1200", 7) == 0 || std::strncmp(prop.gcnArchName, "gfx1201", 7) == 0 ||- std::strncmp(prop.gcnArchName, "gfx110", 6) == 0 || std::strncmp(prop.gcnArchName, "gfx115", 6) == 0))+ strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName)))? 1 : 2;cudaGetLastError();}diff --git a/src/prefill/kernels.cu b/src/prefill/kernels.cuindex 38586df66..00490a80b 100644--- a/src/prefill/kernels.cu+++ b/src/prefill/kernels.cu@@ -1,6 +1,7 @@// src/prefill/kernels.cu - see include/strata/prefill/kernels.hpp.#include "strata/prefill/kernels.hpp"#include "strata/kernels/mrope.hpp"+#include "strata/kernels/gfx_arch.hpp"#include "strata/kernels/router_top10.hpp"#include <cuda_fp16.h>@@ -1484,7 +1485,7 @@ bool gr_upmix(const uint16_t* lo16, const uint16_t* w_up, const float* R, constint dev = 0;cudaDeviceProp p;if (cudaGetDevice(&dev) != cudaSuccess || cudaGetDeviceProperties(&p, dev) != cudaSuccess) return false;- return std::strncmp(p.gcnArchName, "gfx11", 5) == 0;+ return strata::kernels::gfx_arch_is_gfx11_wmma(p.gcnArchName);}();if (!gfx11 || T <= 0) return false;gr_upmix_kernel<<<dim3(N / UM_D, (unsigned) ((T + UM_T - 1) / UM_T)), 256, 0, (cudaStream_t) stream>>>(diff --git a/src/prefill/wmma_gemm.cu b/src/prefill/wmma_gemm.cuindex 9547596ac..02452d967 100644--- a/src/prefill/wmma_gemm.cu+++ b/src/prefill/wmma_gemm.cu@@ -23,6 +23,9 @@#include <hip/hip_bfloat16.h>#include <cstdlib>+#include "strata/kernels/gfx_arch.hpp"++#include <atomic>#include <cstring>// STRATA_WMMA_GFX11 is defined by the BUILD (CMakeLists.txt, from CMAKE_HIP_ARCHITECTURES), not inferred@@ -35,6 +38,24 @@using v8fp32 = float __attribute__((ext_vector_type(8)));+// Does the CURRENT device run the gfx11 WMMA kernels of this file? Exactly the targets whose intrinsics are selected+// below (gfx1100 / 1101 / 1102 / 1150 / 1151): a gfx11 part outside the list (gfx1103, gfx1152) has no device code+// here, so it takes the hipBLASLt / hipBLAS paths instead of running a kernel that is not there. Cached per device+// (hipGetDeviceProperties is not cheap, and a mixed-GPU box has more than one answer).+static bool strata_wmma_gfx11_device() {+ static std::atomic<int> cache[64]; // 0 unknown, 1 yes, 2 no+ int dev = 0;+ if (hipGetDevice(&dev) != hipSuccess || dev < 0 || dev >= 64) return false;+ int c = cache[dev].load(std::memory_order_acquire);+ if (c == 0) {+ hipDeviceProp_t prop{};+ const bool ok = hipGetDeviceProperties(&prop, dev) == hipSuccess && strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName);+ c = ok ? 1 : 2;+ cache[dev].store(c, std::memory_order_release);+ }+ return c == 1;+}+template <typename ElemT>struct WmmaTraits;@@ -45,7 +66,8 @@ struct WmmaTraits<_Float16> {#if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1150__) || defined(__gfx1151__)return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c);#else- (void) a; (void) b; return c; // not a gfx11 device pass: never launched (runtime gate)+ (void) a; (void) b; (void) c;+ __builtin_trap(); // a device pass without the gfx11 intrinsic: the runtime gate never launches it, and a stray launch must not return zeros#endif}};@@ -57,7 +79,8 @@ struct WmmaTraits<__bf16> {#if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1150__) || defined(__gfx1151__)return __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32(a, b, c);#else- (void) a; (void) b; return c; // not a gfx11 device pass: never launched (runtime gate)+ (void) a; (void) b; (void) c;+ __builtin_trap(); // see above#endif}};@@ -246,12 +269,7 @@ static inline bool strata_wmma_gemm_dispatch(const uint16_t* X, const uint16_t*if (T <= 0 || N <= 0 || K <= 0) return false;// Runtime gate (review): run only on gfx11 devices, whatever this build compiled for. The build-time// STRATA_WMMA_GFX11 macro controls whether the intrinsics compile; this check controls whether they run.- {- int dev = 0;- hipDeviceProp_t prop{};- if (hipGetDevice(&dev) != hipSuccess || hipGetDeviceProperties(&prop, dev) != hipSuccess) return false;- if (std::strncmp(prop.gcnArchName, "gfx11", 5) != 0) return false;- }+ if (!strata_wmma_gfx11_device()) return false;if (K % 16 != 0) return false;if (beta != 0.0f && beta != 1.0f) return false;if (ldy <= 0) ldy = N;@@ -636,13 +654,7 @@ bool strata_pf_hcdown_bf16(const uint16_t* X, int64_t ldx, const uint16_t* Wd, cint64_t ni, float* lo, float* inj, int64_t T, int64_t K, void* stream) {if (!X || !Wd || !Wi || !lo || !inj || T < 64 || nd < 1 || ni < 0 || K % 64 != 0 || ldx < K || ldx % 8 != 0) return false;if (T > (1LL << 30) || K > (1LL << 30) || ldx > (1LL << 30)) return false;- static const bool gfx11 = [] {- int dev = 0;- hipDeviceProp_t prop{};- if (hipGetDevice(&dev) != hipSuccess || hipGetDeviceProperties(&prop, dev) != hipSuccess) return false;- return std::strncmp(prop.gcnArchName, "gfx11", 5) == 0;- }();- if (!gfx11) return false;+ if (!strata_wmma_gfx11_device()) return false;const int64_t mt = (T + pfg::BM - 1) / pfg::BM;const unsigned grid = (unsigned) (mt * ((nd + ni + 127) / 128));pfg::kernel_hcdown<<<grid, 256, 0, static_cast<hipStream_t>(stream)>>>(X, (int) ldx, Wd, Wi, (int) nd, (int) ni,@@ -655,13 +667,7 @@ bool strata_pf_hcdown_exact_bf16(const uint16_t* X, int64_t ldx, const uint16_t*if (!X || !W || !Y || T < 1 || N != pfg::HX_N || K != pfg::HX_K || ldx < K || ldx % 8 != 0 || ldx > (1LL << 30) ||T > (1LL << 30))return false;- static const bool gfx11 = [] {- int dev = 0;- hipDeviceProp_t prop{};- if (hipGetDevice(&dev) != hipSuccess || hipGetDeviceProperties(&prop, dev) != hipSuccess) return false;- return std::strncmp(prop.gcnArchName, "gfx11", 5) == 0;- }();- if (!gfx11) return false;+ if (!strata_wmma_gfx11_device()) return false;const unsigned grid = (unsigned) (2 * ((T + pfg::HX_BM - 1) / pfg::HX_BM));pfg::kernel_hcd_exact<<<grid, pfg::HX_NT, 0, static_cast<hipStream_t>(stream)>>>(X, (int) ldx, W, Y, (int) T);return hipGetLastError() == hipSuccess;@@ -679,13 +685,7 @@ bool strata_pf_gemm_f16_ld(const uint16_t* X, int64_t ldx, const uint16_t* W, inif (ldy <= 0) ldy = N;if (ldx < K || ldw < K || ldx % 8 != 0 || ldw % 8 != 0 || ldx > (1LL << 30) || ldw > (1LL << 30)) return false;if (ldy < N || T > (1LL << 30) || N > (1LL << 30) || K > (1LL << 30)) return false;- static const bool gfx11 = [] {- int dev = 0;- hipDeviceProp_t prop{};- if (hipGetDevice(&dev) != hipSuccess || hipGetDeviceProperties(&prop, dev) != hipSuccess) return false;- return std::strncmp(prop.gcnArchName, "gfx11", 5) == 0;- }();- if (!gfx11) return false;+ if (!strata_wmma_gfx11_device()) return false;hipStream_t s = static_cast<hipStream_t>(stream);const int acc = beta == 1.0f ? 1 : 0;const int64_t mt = (T + pfg::BM - 1) / pfg::BM;