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++
RDNA2 SGEMM prompt GEMMs (#1123) are opt-in: STRATA_RDNA2_SGEMM=1 (gfx103x) / =all (any AMD card)
Niko12210c808eed00fa
diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.mdindex fcbd4f01e..b817e4957 100644--- a/docs/AMD_HIP.md+++ b/docs/AMD_HIP.md@@ -453,10 +453,10 @@ run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx10`platform_memory_test` cannot `mlock` at the shell's default `ulimit -l`).- **Prompt GEMMs as SGEMMs (engine 0.1.39 + `Gemm::rdna2_sgemm`):** the rocBLAS in setup's ROCm (10.2.0a20260930)has tuned gfx1030 kernels for FP16 -> FP16, int8 and FP32 -> FP32 only. The prompt path's dense GEMMs take FP16 or- BF16 inputs and write FP32 (rocBLAS's HS / BS types), which run its fallback kernels at about 5 TFLOPS. On gfx103x- the engine widens both inputs to FP32 (exact) and runs SGEMM, which accumulates in FP32 like the native call- (`src/prefill/gemm.cu`; N < 64 keeps the native call; `STRATA_RDNA2_SGEMM=0` / `=1` turns it off / on for any AMD- card). Measured on an RX 6800 16 GB over OCuLink (PCIe 4.0 x4, 7.1 GB/s), Ryzen 7 8845HS, 28.8 GB RAM, Windows 11,+ BF16 inputs and write FP32 (rocBLAS's HS / BS types), which run its fallback kernels at about 5 TFLOPS. With+ `STRATA_RDNA2_SGEMM=1` (opt-in; `=all` forces it on any AMD card) the engine widens both inputs to FP32 (exact) and runs SGEMM,+ which accumulates in FP32 like the native call (`src/prefill/gemm.cu`; N < 64 keeps the native call). The author ran it+ as the gfx103x default; here it is a switch because it is not bit-identical to the native call (below). Measured on an RX 6800 16 GB over OCuLink (PCIe 4.0 x4, 7.1 GB/s), Ryzen 7 8845HS, 28.8 GB RAM, Windows 11,Coder IQ1_M with setup's arguments (64K context, MTP), fresh 12K-token prompts, 4 per arm, A/B in one binary:| | native GEMMs | SGEMM route |@@ -471,7 +471,7 @@ run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx10[-1, 1], the SGEMM route is as close as or closer than the native call on all 10 FP16 / BF16 shapes checked; thetwo differ by at most 4.3e-6 of the largest output. A 9-task code-repair benchmark (the model patches seeded bugsin a browser game until 38 browser checks pass) solved 9/9 on the first try with both, model time 458 -> 374 s.- The SGEMM route is the default on gfx103x when `STRATA_HIP_PROMPT_F16` is unset; with `STRATA_HIP_PROMPT_F16=1`+ With the switch on and `STRATA_HIP_PROMPT_F16` unset the SGEMM route runs; with `STRATA_HIP_PROMPT_F16=1`the FP16 route above runs first and the SGEMM route takes the products it leaves (`beta != 0`). Same RX 6800, onesession, fresh 12K-token prompts: native 310, SGEMM 439, FP16 (#835) 494 tok/s; `STRATA_F16_RANGE=1` on the CoderIQ1_M peaked at 105.3 (activations) and 424.8 (FP16 outputs) with nothing beyond 65504, and the repair benchmarkdiff --git a/src/prefill/gemm.cu b/src/prefill/gemm.cuindex 183950f64..315c3017a 100644--- a/src/prefill/gemm.cu+++ b/src/prefill/gemm.cu@@ -678,8 +678,9 @@ bool Gemm::bf16_hcd_exact(const uint16_t* X, int64_t ldx, const uint16_t* W, flo// same up to summation order. The weight is widened once per call, the activations in slices of up to 128 MiB of// FP32 (an 8,192-token chunk at K = 2560 is one slice). Small N (< 64: routers, gates) keeps the native call:// there the widening costs more than the GEMM gains. If the FP32 buffers cannot be allocated, the native call runs.-// Default: on for gfx103x, off for every other AMD architecture. STRATA_RDNA2_SGEMM=0 / =1 turns it off / on for-// any AMD card (the A/B arms).+// OPT-IN here: STRATA_RDNA2_SGEMM=1 turns it on for gfx103x devices (other cards keep the native call, also in a+// mixed layer split); =all turns it on for every AMD card (A/B arms, tests); unset or 0 is the native path. The+// author ran it as the gfx103x default (RX 6800 343 -> 534 tok/s); it is not bit-identical to the native call.namespace {__global__ void rdna2_bf16_to_f32_kernel(const uint16_t* __restrict__ in, float* __restrict__ out, int64_t n) {const int64_t i = (int64_t) blockIdx.x * blockDim.x + threadIdx.x;@@ -697,12 +698,14 @@ void rdna2_widen(const uint16_t* in, float* out, int64_t n, bool bf16, cudaStrea}// whether this GEMM runs as an SGEMM (see above)bool rdna2_sgemm_on(int64_t N) {- static const int forced = [] {+ static const int mode = [] { // 0 off (unset), 1 gfx103x devices, 2 every AMD deviceconst char* v = std::getenv("STRATA_RDNA2_SGEMM");- return v != nullptr && v[0] != '\0' ? std::atoi(v) : -1;+ if (v == nullptr || v[0] == '\0') return 0;+ if (std::strcmp(v, "all") == 0) return 2;+ return std::atoi(v) > 0 ? 1 : 0;}();- if (forced == 0 || N < 64) return false;- if (forced > 0) return true;+ if (mode == 0 || N < 64) return false;+ if (mode == 2) return true;static std::atomic<int> arch[64] = {}; // per device: 0 not known, 1 gfx103x, 2 another architectureint dev = 0;if (hipGetDevice(&dev) != hipSuccess || dev < 0 || dev >= 64) { (void) hipGetLastError(); return false; }@@ -735,6 +738,8 @@ bool Gemm::rdna2_sgemm(const uint16_t* X, const uint16_t* W, float* Y, int64_t Tfloat beta, bool bf16) {if (K <= 0 || !rdna2_sgemm_on(N)) return false;const int64_t rows = std::max<int64_t>(1, std::min<int64_t>(T, kRdna2SliceF32 / K));+ // growing frees a buffer an earlier GEMM on this stream may still read (as the sm_60 FP32 route does)+ if (tc_w_elems_ < 2 * N * K || tc_x_elems_ < 2 * rows * K) (void) hipStreamSynchronize((hipStream_t) stream_);if (!rdna2_grow(tc_w_, tc_w_elems_, N * K) || !rdna2_grow(tc_x_, tc_x_elems_, rows * K)) return false;float* const wf = reinterpret_cast<float*>(tc_w_);float* const xf = reinterpret_cast<float*>(tc_x_);