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++
tests: hip_prefill_gemm runs the FP16-io prompt GEMMs (set_f16_io) on any HIP card, and its BF16 inputs are no longer zero
xjc10d0838c6c3a9e
diff --git a/bench/results/2026-10-04-rdna2-fp16-prompt/README.md b/bench/results/2026-10-04-rdna2-fp16-prompt/README.mdindex 29f8e9376..90f670a6c 100644--- a/bench/results/2026-10-04-rdna2-fp16-prompt/README.md+++ b/bench/results/2026-10-04-rdna2-fp16-prompt/README.md@@ -130,6 +130,12 @@ would need `STRATA_HIP_PROMPT_F16=0`.row from its end; `Gemm::bf16` converts W row slices to FP16 through the existing dequantization scratch (as`native()` does) and takes X as the FP16 image. `bf16x2_mode()` is 0 there (the BF16 low part has no FP16 meaning).- No new device memory, no host sync, no fallback branch; CUDA builds are unchanged (`#if defined(__HIPCC__)`).+- `hip_prefill_gemm` (ctest) runs its shapes a second time with `set_f16_io(true)` on any HIP card: X as the FP16 image+ for the BF16 products, a scratch of 64 rows so a 96-row weight converts in two slices, `ldy > N`, an odd N, T = 1 and+ a `beta = 1` f16() call (which keeps the FP32-out GEMM). The FP16-out results are checked against the double reference+ at FP16's rounding (6e-4 relative per element, rel L2 < 1e-3); row padding and the guards around Y must be untouched.+ The test's BF16 inputs are now made by hand: `hip_bfloat16(float)` produced 0 in this build, so the two BF16 cases had+ passed on all-zero inputs (rel L2 printed 0); with real inputs they pass at 1.9e-07 (FP32 out) and 2.2e-04 (FP16 out).## Limitsdiff --git a/tests/hip/prefill_gemm.cpp b/tests/hip/prefill_gemm.cppindex 1536c89eb..dca156e76 100644--- a/tests/hip/prefill_gemm.cpp+++ b/tests/hip/prefill_gemm.cpp@@ -1,4 +1,8 @@// BF16/F16 prefill through the actual engine GEMM path against a CPU reference.+//+// Each shape runs twice: on the engine's GEMM as every card runs it (FP32 out), and with Gemm::set_f16_io(true), the+// gfx103x prompt path's FP16-out GEMM widened in place in Y's own rows (bench/results/2026-10-04-rdna2-fp16-prompt).+// The second mode is forced here on any HIP card, so the path is covered wherever the test runs.#include <hip/hip_runtime.h>#include <hip/hip_bfloat16.h>#include <hip/hip_fp16.h>@@ -20,18 +24,27 @@ struct Buffer {~Buffer() { if (p) (void) hipFree(p); }};+// `f16_io`: the Gemm was set_f16_io(true). bf16() then takes X as the prompt path's FP16 image (W stays BF16), and+// every GEMM with beta = 0 writes its result as FP16 before widening it: those are checked at FP16's rounding+// (2^-11 relative per element, plus the FP32 accumulation) instead of the FP32-out tolerance. beta = 1 keeps the+// FP32-out GEMM on the f16() path, and bf16() refuses it there (the prompt path never accumulates a BF16 product).bool run(strata::prefill::Gemm& gemm, hipStream_t stream, bool bf16,- int t, int n, int k, int ldy, float beta) {+ int t, int n, int k, int ldy, float beta, bool f16_io = false) {std::mt19937 rng(51012 + t + n);std::uniform_real_distribution<float> dist(-0.25f, 0.25f);std::vector<uint16_t> x((size_t)t*k), w((size_t)n*k);std::vector<float> xf(x.size()), wf(w.size());- auto fill = [&](auto& bits, auto& values) {+ auto fill = [&](auto& bits, auto& values, bool as_bf16) {for (size_t i = 0; i < bits.size(); ++i) {- if (bf16) {- const hip_bfloat16 v(dist(rng));- bits[i] = v.data;- const uint32_t wide = static_cast<uint32_t>(v.data) << 16;+ if (as_bf16) {+ // the BF16 bits by hand (round to nearest even on the float's bits): hip_bfloat16(float) produced+ // data 0 in this test's build (ROCm 10.0, not traced further), so both BF16 cases passed on all-zero+ // inputs+ const float f = dist(rng);+ uint32_t u; std::memcpy(&u, &f, 4);+ u += 0x7fffu + ((u >> 16) & 1u);+ bits[i] = static_cast<uint16_t>(u >> 16);+ const uint32_t wide = static_cast<uint32_t>(bits[i]) << 16;std::memcpy(&values[i], &wide, 4);} else {const __half v = __float2half_rn(dist(rng));@@ -40,7 +53,8 @@ bool run(strata::prefill::Gemm& gemm, hipStream_t stream, bool bf16,}}};- fill(x, xf); fill(w, wf);+ fill(x, xf, bf16 && !f16_io); fill(w, wf, bf16);+ const bool f16_out = f16_io && (bf16 || beta == 0.0f);constexpr int offset = 5;std::vector<float> initial(offset + (size_t)t*ldy + 8, -777.25f);for (int r = 0; r < t; ++r) for (int c = 0; c < n; ++c)@@ -64,13 +78,15 @@ bool run(strata::prefill::Gemm& gemm, hipStream_t stream, bool bf16,for (int i=0;i<k;++i) ref+=(double)xf[(size_t)r*k+i]*wf[(size_t)c*k+i];const double d=(double)got[j]-ref;ok=ok && std::isfinite(got[j]);+ if (f16_out) ok=ok && std::abs(d) <= 6e-4*std::abs(ref) + 1e-4;diff2+=d*d; ref2+=ref*ref; maximum=std::max(maximum,std::abs(d));}+ // the padding of every row (ldy > n) and the guards before and after Y: untouched by the GEMM and the wideningfor (size_t j=0;j<got.size();++j) if (!active[j]) ok=ok && got[j]==initial[j];const double rel=std::sqrt(diff2/std::max(ref2,1e-300));- ok=ok && rel<1e-4 && maximum<5e-3;- std::printf("%s %s T=%d N=%d K=%d ldy=%d beta=%.1f rel_l2=%.3g max_abs=%.3g\n",- ok?"PASS":"FAIL",bf16?"BF16":"F16",t,n,k,ldy,beta,rel,maximum);+ ok=ok && (f16_out ? rel<1e-3 : (rel<1e-4 && maximum<5e-3));+ std::printf("%s %s%s T=%d N=%d K=%d ldy=%d beta=%.1f rel_l2=%.3g max_abs=%.3g\n",+ ok?"PASS":"FAIL",bf16?"BF16":"F16",f16_io?" (f16 io)":"",t,n,k,ldy,beta,rel,maximum);return ok;}@@ -88,6 +104,22 @@ int main() {ok=run(gemm,stream,false,32,640,2560,648,0) && ok;ok=run(gemm,stream,false,64,2560,640,2560,1) && ok;}+ {+ // The FP16-io mode. The scratch holds 64 rows at K = 2560, so bf16()'s W conversion slices N = 96 in two+ // (64 + 32 rows, the second written at Y + 64). ldy > N and the odd N check widen_rows_f16's in-place+ // walk (FP16 halves at the start of each FP32 row); T = 1 is a single block.+ strata::prefill::Gemm gemm;+ std::string error;+ if (!gemm.init(stream,64*2560,error)) { std::fprintf(stderr,"%s\n",error.c_str()); return 2; }+ gemm.set_f16_io(true);+ ok=run(gemm,stream,true,16,96,2560,96,0,true) && ok;+ ok=run(gemm,stream,true,17,48,2560,64,0,true) && ok;+ ok=run(gemm,stream,false,32,640,2560,648,0,true) && ok;+ ok=run(gemm,stream,false,64,2560,640,2560,0,true) && ok;+ ok=run(gemm,stream,false,33,257,640,264,0,true) && ok;+ ok=run(gemm,stream,false,1,96,2560,96,0,true) && ok;+ ok=run(gemm,stream,false,17,48,2560,64,1,true) && ok;+ }CHECK(hipStreamDestroy(stream));return ok?0:1;}