From acc94b21714e03511ab507fe046a419689c93be3 Mon Sep 17 00:00:00 2001 From: libratechw Date: Sat, 10 Oct 2026 17:52:00 +0900 Subject: [PATCH 01/28] prompt attention (gfx11 / gfx12 WMMA): issue a chunk's reads before its compute prompt_attn_wmma_kernel interleaved a chunk's global reads with its compute: the V slice was staged first, then each 16-cell tile loaded its K scale and fragments between the q.k WMMAs, so a wave waited on each read in turn (a thread trace on gfx1151: 56% of the kernel's time in s_waitcnt vmcnt, 0.4% in WMMA). The chunk's reads now go out together (fetch), then the same compute runs on them (chunk). The values and the order of the arithmetic are unchanged. gfx1151, ROCm 7.14.1 SDK (clang 23), hip_prompt_attn_wmma with STRATA_PA_FAST=1, three interleaved runs against the unchanged kernel, ms per chunk: 32K context / 2,048 queries 12.50 -> 11.29 (-9.7%), 1,500 / 1,500 3.39 -> 3.20, 2,100 / 256 1.30 -> 1.23. The output hashes (NEWHASH) match with STRATA_PA_FAST=1 and =0. gfx12 compiles the same change; it was not run there. --- src/kernels/cuda/qsa_prompt_attn.cu | 85 +++++++++++++++++++---------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/src/kernels/cuda/qsa_prompt_attn.cu b/src/kernels/cuda/qsa_prompt_attn.cu index bd99609d..aef60089 100644 --- a/src/kernels/cuda/qsa_prompt_attn.cu +++ b/src/kernels/cuda/qsa_prompt_attn.cu @@ -1254,57 +1254,77 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float* for (int j = 0; j < 4; ++j) acc[j] = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; const int n_chunks = (n + WCH - 1) / WCH; - for (int ci = 0; ci < n_chunks; ++ci) { + // chunk ci's cell for this lane (lane = cell index): its pool row, or -1 (past the selection, or a block the KV + // streaming left non-resident: masked as in the decode kernel) + auto row_of = [&](int ci) -> long long { const int c0 = ci * WCH; - // this lane's cell of the chunk (lane = cell index): its pool row, or -1 (past the selection, or a block the - // KV streaming left non-resident: masked as in the decode kernel) - long long myrow = -1; + long long r = -1; if (c0 + lane < n) { const int cell = __ldg(ids + c0 + lane); const long long page = (long long) __ldg(p.page_table + cell / page_size); - if (page >= 0) myrow = (page * n_kv_heads + kvh) * page_size + (cell % page_size); + if (page >= 0) r = (page * n_kv_heads + kvh) * page_size + (cell % page_size); } - // stage this wave's V slice of the chunk (64 bytes of each row) and the V scale; the K fragments come straight - // from global memory (8 consecutive codes per lane) - { - uint4 v0 = make_uint4(0, 0, 0, 0), v1 = v0, v2 = v0, v3 = v0; - float vsc = 0.0f; - if (myrow >= 0) { - const uint4* src = reinterpret_cast(p.v_q + myrow * HD + dim0); - v0 = __ldg(src); v1 = __ldg(src + 1); v2 = __ldg(src + 2); v3 = __ldg(src + 3); - vsc = __half2float(__ushort_as_half(__ldg(p.v_scale + myrow * (HD / KV_Q8_GROUP) + warp))); - } - uint4* dst = reinterpret_cast(&S.v[warp][lane][0]); - dst[0] = v0; dst[1] = v1; dst[2] = v2; dst[3] = v3; - S.vs[warp][lane] = vsc; - if (warp == 0) S.valid[lane] = myrow >= 0; + return r; + }; + // a chunk's global reads: this wave's V slice (64 bytes of each row) and V scale, and the K fragments (8 or 16 + // consecutive codes per lane) and K scales of its two 16-cell tiles + struct Chunk { + long long row; + uint4 v[4]; + float vsc, ksc[2]; + uint32_t kx[2][4][PA_KL / 4]; + }; + auto fetch = [&](long long row, Chunk& d) { + d.row = row; + d.v[0] = d.v[1] = d.v[2] = d.v[3] = make_uint4(0, 0, 0, 0); + d.vsc = 0.0f; + if (row >= 0) { + const uint4* src = reinterpret_cast(p.v_q + row * HD + dim0); + d.v[0] = __ldg(src); d.v[1] = __ldg(src + 1); d.v[2] = __ldg(src + 2); d.v[3] = __ldg(src + 3); + d.vsc = __half2float(__ushort_as_half(__ldg(p.v_scale + row * (HD / KV_Q8_GROUP) + warp))); } - // q.k over this wave's 64 dims for two 16-cell tiles, times the cell's K scale for this group #pragma unroll for (int nt = 0; nt < 2; ++nt) { - const long long rr = __shfl(myrow, nt * 16 + col); - wf8 s = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; - float ksc = 0.0f; - if (rr >= 0) ksc = __half2float(__ushort_as_half(__ldg(p.k_scale + rr * (HD / KV_Q8_GROUP) + warp))); + const long long rr = __shfl(row, nt * 16 + col); + d.ksc[nt] = 0.0f; + if (rr >= 0) d.ksc[nt] = __half2float(__ushort_as_half(__ldg(p.k_scale + rr * (HD / KV_Q8_GROUP) + warp))); #pragma unroll for (int kk = 0; kk < 4; ++kk) { - uint32_t kx[PA_KL / 4] = {}; +#pragma unroll + for (int i = 0; i < PA_KL / 4; ++i) d.kx[nt][kk][i] = 0; if (rr >= 0) { const uint32_t* src = reinterpret_cast(p.k_q + rr * HD + dim0 + kk * 16 + PA_KOFF(half)); #if STRATA_PA_GFX11 const uint4 v = __ldg(reinterpret_cast(src)); - kx[0] = v.x; kx[1] = v.y; kx[2] = v.z; kx[3] = v.w; + d.kx[nt][kk][0] = v.x; d.kx[nt][kk][1] = v.y; d.kx[nt][kk][2] = v.z; d.kx[nt][kk][3] = v.w; #else const uint2 v = __ldg(reinterpret_cast(src)); - kx[0] = v.x; kx[1] = v.y; + d.kx[nt][kk][0] = v.x; d.kx[nt][kk][1] = v.y; #endif } - const wh8 b = i8_to_h(kx); + } + } + }; + auto chunk = [&](const Chunk& cd) { + // stage this wave's V slice and scale + { + uint4* dst = reinterpret_cast(&S.v[warp][lane][0]); + dst[0] = cd.v[0]; dst[1] = cd.v[1]; dst[2] = cd.v[2]; dst[3] = cd.v[3]; + S.vs[warp][lane] = cd.vsc; + if (warp == 0) S.valid[lane] = cd.row >= 0; + } + // q.k over this wave's 64 dims for two 16-cell tiles, times the cell's K scale for this group +#pragma unroll + for (int nt = 0; nt < 2; ++nt) { + wf8 s = wf8{0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; +#pragma unroll + for (int kk = 0; kk < 4; ++kk) { + const wh8 b = i8_to_h(cd.kx[nt][kk]); s = wmma_f16(qh[kk], b, s); if constexpr (SPLIT) s = wmma_f16(ql[kk], b, s); } #pragma unroll - for (int i = 0; i < 8; ++i) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * ksc; + for (int i = 0; i < 8; ++i) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * cd.ksc[nt]; } __syncthreads(); // online softmax over the four groups' sum (fixed order): row t/8, 4 cells per thread @@ -1380,6 +1400,13 @@ __global__ void __launch_bounds__(THREADS) prompt_attn_wmma_kernel(const float* } // no barrier here: `v`/`vs` are this wave's own, and `p`/`alpha`/`valid` are rewritten only after the next // chunk's first barrier (which every wave reaches after its p.v) + }; + // all of a chunk's reads are issued before its compute (they were interleaved with the q.k WMMAs and the V + // staging): 32K context, 2,048 queries, gfx1151, STRATA_PA_FAST=1: 12.49 -> 11.27 ms; the same bits + for (int ci = 0; ci < n_chunks; ++ci) { + Chunk d; + fetch(row_of(ci), d); + chunk(d); } float inv[8]; #pragma unroll From edf61f18e9d3b66fd1970a91aa2f882f7dbbb91f Mon Sep 17 00:00:00 2001 From: libratechw Date: Sat, 10 Oct 2026 01:51:38 +0900 Subject: [PATCH 02/28] prefill: the VGPR-capped gfx11 fused expert kernels are on again for gfx1151 on clang 23, except IQ2_XS and Q8_0 (#1180) Since 0.1.40.2 the waves_per_eu(8) variant of native_w11_kernel is uncapped on clang 22 and newer, because clang 22 computes wrong results with it on gfx1100. On gfx1151 with clang 23 (ROCm 7.14.1) the capped kernels give the same bits and take less time, as alexdns1 measured in #1180. The cap now applies there again, per format (hip_prefill_fused_iq, one layer, 2048 / 3584 / 8192 tokens, the same output bits hash in every case): - gate/up IQ2_XXS / IQ3_XXS / IQ3_S / IQ4_XS and down Q2_0 / IQ4_NL: capped, 8-15% less time per layer. IQ2_S gate/up is capped too, but its LDS leaves room for 3 blocks per WGP and the compiler keeps its 238 VGPRs; IQ2_S / Q2_0 takes 2-4% less time from the Q2_0 down. - IQ2_XS gate/up: not capped. Under the cap it spills 104 VGPRs and takes 61-66% more time. - Q8_0 down: not capped. It spills 18 VGPRs and took -1.9% to +1.9% time (with Q4_K gate/up). The test is the clang major version: other clang 23 builds are not measured, and clang 24 and newer keep the clang 22 rule. The template argument is the same in the host and every device pass; only the device pass for gfx1151 decides the attribute (nw_capped). Other architectures, other compilers and -DSTRATA_W_LB=N behave as before: the gfx1100 disassembly is identical to before (kernel names aside). The file builds for gfx1012 / 1030 / 1100 / 1150 / 1151 / 1200 / 1201 and with STRATA_HIP_GFX906 (gfx906); no CUDA build here, and the changed lines are inside `#if defined(__HIPCC__)`. SYCL has its own copy of this file, not touched. The path is opt-in (STRATA_PF_FUSED=1), so default output is unchanged. End to end on a Ryzen AI Max+ 395 (128 GB, gfx1151), UD-IQ4_XS, the section-5 switches of docs/STRIX_HALO.md with --prefill 16384, 3 interleaved rounds of fresh servers: a 128K prompt read 1,126.1 -> 1,153.4 tok/s (+2.4%; +1.8%, +2.4%, +2.6% per round). At 4K (868.0 -> 894.9, +3.1%) and 32K (1,182.9 -> 1,207.0, +2.0%) the medians moved too, but within the spread of 3 runs. Decode unchanged; the same text for all 9 prompts. --- src/prefill/moe_fused_iq.cu | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index ce2ca76f..3baf5d39 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -678,15 +678,33 @@ native_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_ #else #define NW_DROW(i, hi) (2 * (i) + (hi)) #endif -// The VGPR cap of the occupancy variant (amdgpu_waves_per_eu). 8 was measured against ROCm 7's clang; clang 22 (ROCm 7.10) -// computes wrong results with it (#1180: gfx1100, every run), so there the cap is off. -DSTRATA_W_LB=N sets it. +// The VGPR cap of the occupancy variant (amdgpu_waves_per_eu). 8 was measured against a clang before 22; clang 22 +// (ROCm 7.10) computes wrong results with it (#1180: gfx1100, every run), so from clang 22 the cap is off - except for +// gfx1151 on clang 23, where the capped kernels give the same bits and take less time (measured with ROCm 7.14.1's +// clang 23, hip_prefill_fused_iq, one layer, 2048-8192 tokens: gate/up IQ2_XXS / IQ3_XXS / IQ3_S / IQ4_XS with down +// Q2_0 / IQ4_NL 8-15%; IQ2_S / Q2_0 2-4%, from its Q2_0 down: IQ2_S's LDS leaves room for 3 blocks per WGP, so the +// compiler keeps its 238 VGPRs). Two formats stay uncapped there: IQ2_XS gate/up spills 104 VGPRs under the cap and +// takes 61-66% more time, and Q8_0 down (18 spilled) took -1.9% to +1.9% time. The test is the clang major version: +// other clang 23 builds are not measured, and clang 24 and newer keep the clang 22 rule. NW_LB is the variant's +// template argument, the same in the host and every device pass (the launch names that instance); whether its cap +// applies is decided per architecture and format in the device pass (nw_capped). -DSTRATA_W_LB=N sets the cap on +// every architecture and format. #if defined(STRATA_W_LB) constexpr int NW_LB = STRATA_W_LB; -#elif defined(__clang_major__) && __clang_major__ >= 22 -constexpr int NW_LB = 1; #else constexpr int NW_LB = 8; #endif +constexpr bool nw_capped(int wt) { +#if defined(STRATA_W_LB) || !defined(__clang_major__) || __clang_major__ < 22 + (void) wt; + return true; +#elif defined(__gfx1151__) && __clang_major__ == 23 + return wt != T_IQ2_XS && wt != T_Q8_0; +#else + (void) wt; + return false; +#endif +} typedef int nw_i4 __attribute__((ext_vector_type(4))); typedef int nw_i2 __attribute__((ext_vector_type(2))); typedef int nw_i8 __attribute__((ext_vector_type(8))); @@ -714,10 +732,11 @@ __device__ __forceinline__ nw_i8 nw_wmma(nw_ab a, nw_ab b, nw_i8 c) { #endif } -// W (X1): ALIAS = the H tile lives on the weight buffers (one extra barrier); LB > 0 = amdgpu_waves_per_eu(LB) (VGPR cap). +// W (X1): ALIAS = the H tile lives on the weight buffers (one extra barrier); LB > 0 = amdgpu_waves_per_eu(LB) (VGPR cap) +// where nw_capped(WT) says the cap applies. // Disable both with -DSTRATA_W_NO_OCC (the launch sites then use and grid factor wgp_blocks). template -__global__ void __launch_bounds__(NW_THREADS) __attribute__((amdgpu_waves_per_eu(LB > 0 ? LB : 1))) +__global__ void __launch_bounds__(NW_THREADS) __attribute__((amdgpu_waves_per_eu(LB > 0 && nw_capped(WT) ? LB : 1))) native_w11_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_t* __restrict__ act, const int32_t* __restrict__ src, uint8_t* __restrict__ out, float* __restrict__ dm) { #if STRATA_NAT_WMMA @@ -1161,6 +1180,8 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n // W (X1): LDS alias of the H tile + waves_per_eu(8) (192 VGPRs) + 4 blocks per WGP, only for the types whose // kernels do not spill under the cap (measured: gate/up IQ2_*, IQ3_*, IQ4_XS 0-5 regs; down IQ4_NL 11, Q8_0 / Q2_0 0; // Q4_K / Q5_K gate/up and Q5_1 down spill 100+ and keep the old launch). + // Those counts are from a clang before 22; from clang 22 nw_capped decides which of these kernels get the cap + // (above NW_LB), and the launch is the same. #ifdef STRATA_W_NO_OCC const bool occ_gu = false, occ_d = false; #else From d573332130a53911f5f29a0aa1fea8c42b1caa53 Mon Sep 17 00:00:00 2001 From: libratechw Date: Mon, 12 Oct 2026 12:03:20 +0900 Subject: [PATCH 03/28] prefill: refill a prompt's lent expert slots from the GGUF mapping's pieces (STRATA_REFILL_PARTS=1, gfx1151's table) After a prompt the borrowed expert-cache slots are refilled from the experts' files. With the GGUF read in place an expert is three tensors, and the refill first assembled each 4 MB blob in a staging buffer (a copy on the calling thread) and then copied that to the slot. The pieces are contiguous in the mapping, so they can go straight to their offsets in the slot: blob_parts() hands them out, ExpertCache::fill_slot_queued_parts copies them on the same queue. The bytes in the slot are the same. Off by default; gfx1151's table turns it on. --- docs/STRIX_HALO.md | 1 + include/strata/core/expert_cache.hpp | 6 ++++++ include/strata/core/expert_source.hpp | 6 ++++++ include/strata/core/remote_experts.hpp | 3 +++ src/core/arch_defaults.cpp | 1 + src/core/expert_cache.cpp | 26 ++++++++++++++++++++++++++ src/core/expert_source.cpp | 19 +++++++++++++++++++ src/program/generate.cpp | 10 ++++++++++ 8 files changed, 72 insertions(+) diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index a28df535..f01875eb 100644 --- a/docs/STRIX_HALO.md +++ b/docs/STRIX_HALO.md @@ -92,6 +92,7 @@ they change speed, not answers. Nothing here applies to CUDA or to another AMD a | `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY` | the prompt's gated-delta-net recurrence: four lanes per column, two columns per lane, the convolution and the norms fused | | `STRATA_HCD_EXACT` | the hyper-connection down projection (N 320, K 10240) in a WMMA kernel that reproduces hipBLASLt solution 1176 / 1177's summation order (`hip_prefill_hcd_exact_parity` checks it bit for bit); it runs only where the table makes hipBLASLt pick one of those two, and says once if it cannot | | `STRATA_CVEC_FUSE`, `STRATA_PF_PAD` | a steered layer's write, control vector and next norm in one pass; padded GEMM row strides | +| `STRATA_REFILL_PARTS` | after a prompt, the expert-cache slots it borrowed are refilled straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt | | `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) | | `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE` | the grouped decode experts (IQ3_S / IQ4_NL), single-butterfly warp sums, fewer launches around the shared expert and the KV append | | `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH` | the GDN step over four blocks per head, activation images written by their producers, the PLE key / value projections of a verify window at once | diff --git a/include/strata/core/expert_cache.hpp b/include/strata/core/expert_cache.hpp index 17e277de..d41a4ff9 100644 --- a/include/strata/core/expert_cache.hpp +++ b/include/strata/core/expert_cache.hpp @@ -78,6 +78,9 @@ bool write_expert_profile(const std::string& path, int64_t n_layers, int64_t n_e /// and the engine's host side (STRATA_UMA_HEADROOM_GIB). Elsewhere it is cudaMemGetInfo's. size_t device_free_bytes(); +/// One piece of an expert blob that lives contiguously in a source's own memory: `n` bytes at `p`, to land `at` bytes into the blob. +struct BlobPart { const uint8_t* p; uint64_t n; uint64_t at; }; + class ExpertCache { public: ExpertCache() = default; @@ -191,6 +194,9 @@ public: /// perf-review D-4: `fill_slot_blocking`'s copy on the same (legacy) stream, but queued: many slots are refilled /// with one `sync_queued` at the end instead of a wait per slot. Same ordering against earlier work, same bytes. bool fill_slot_queued(int32_t slot, const uint8_t* host_blob, std::string& err, int64_t bytes = 0); + /// `fill_slot_queued` for a blob that is not in one piece: each `parts[i].n` bytes at `parts[i].p` go to byte `parts[i].at` + /// of the slot (the pieces tile the blob). Same queue, same `sync_queued`. + bool fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err); bool sync_queued(std::string& err); /// Reads `slot` back to the host and compares it to `host_blob`, byte for byte. **THE ONLY THING THAT SAYS diff --git a/include/strata/core/expert_source.hpp b/include/strata/core/expert_source.hpp index cf517690..7ca3be96 100644 --- a/include/strata/core/expert_source.hpp +++ b/include/strata/core/expert_source.hpp @@ -170,6 +170,11 @@ public: /// A blob pointer that stays valid (not recycled) for as long as the source is open: for a copy that runs /// asynchronously long after the call (the adaptive tier's swap-ins). Defaults to `blob`. virtual const uint8_t* blob_stable(int64_t layer, int64_t expert) { return blob(layer, expert); } + /// The pieces (up to 3) a blob consists of when the source can hand them out where they already are - the GGUF + /// mapped in place keeps an expert's gate, up and down in three tensors - so the caller can copy each straight to + /// its destination instead of `blob_stable` assembling a staging copy first. 0: not available for this + /// (layer, expert) - take `blob_stable`. The pointers stay valid as long as the source is open. + virtual int blob_parts(int64_t layer, int64_t expert, BlobPart* out) { (void) layer; (void) expert; (void) out; return 0; } /// The caller has queued an asynchronous copy out of `blob` (a pointer this source handed out) on `stream` (a /// cudaStream_t): the source must not overwrite or recycle that memory until the copy has finished. A source whose /// pointers are never recycled ignores it. (#1237: a page-locked stage buffer is read by the DMA after the copy call @@ -692,6 +697,7 @@ public: const uint8_t* blob(int64_t layer, int64_t expert) override; /// With io prefetch in the experts.bin tier, the mapping itself (blob() may hand out a recycled staging buffer). const uint8_t* blob_stable(int64_t layer, int64_t expert) override; + int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override; void note_async_read(const uint8_t* blob, void* stream) override; /// Windows, opt-in with STRATA_FILE_RELEASE=1: trim the file mapping's full pages after their expert reaches /// VRAM. Never touches the resident complement or staging buffers. Disabled by default. diff --git a/include/strata/core/remote_experts.hpp b/include/strata/core/remote_experts.hpp index d499c031..115d1dc8 100644 --- a/include/strata/core/remote_experts.hpp +++ b/include/strata/core/remote_experts.hpp @@ -128,6 +128,9 @@ public: const uint8_t* blob_stable(int64_t layer, int64_t expert) override { return fallback_.blob_stable(layer, expert); } + int blob_parts(int64_t layer, int64_t expert, BlobPart* out) override { + return from_helper(layer, expert) ? 0 : fallback_.blob_parts(layer, expert, out); + } int64_t reads() const override { return fallback_.reads(); } bool pinned(int64_t layer, int64_t expert) const override { return from_helper(layer, expert) ? false : fallback_.pinned(layer, expert); diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp index e8ca7c9b..59d3f6a1 100644 --- a/src/core/arch_defaults.cpp +++ b/src/core/arch_defaults.cpp @@ -42,6 +42,7 @@ std::vector> arch_default_env(const char* gc {"STRATA_CVEC_FUSE", "1"}, // a steered layer's write, control vector and next norm in one pass (S23) {"STRATA_HCD_EXACT", "1"}, // the HC down GEMM in hipBLASLt solution 1176's k order: 64K +1.8% (stream S) {"STRATA_PF_PAD", "1"}, // padded GEMM row strides (acts with STRATA_PF_GEMM; inert without it) (S23) + {"STRATA_REFILL_PARTS", "1"}, // the prompt's lent slots refilled from the GGUF mapping's pieces, not an assembled copy: same bytes, refill 217 -> 105 ms at 4K, 589 -> 322 ms at 32K // decode {"STRATA_Q8_PACKED", "1"}, // the packed Q8_0 decode layout: +2.3% (S26) {"STRATA_Q6_PACKED", "1"}, // the packed Q6_K heads (S26) diff --git a/src/core/expert_cache.cpp b/src/core/expert_cache.cpp index 1920fdb7..ecd337a6 100644 --- a/src/core/expert_cache.cpp +++ b/src/core/expert_cache.cpp @@ -7,6 +7,8 @@ #define STRATA_EC_NO_VMM 1 #endif +#include +#include #include #if !defined(STRATA_EC_NO_VMM) #include // #533: the virtual memory management types (the functions come through the runtime's entry points) @@ -737,6 +739,30 @@ bool ExpertCache::fill_slot_queued(int32_t slot, const uint8_t* host_blob, std:: return true; } +bool ExpertCache::fill_slot_queued_parts(int32_t slot, const BlobPart* parts, int n, std::string& err) { + uint8_t* dst = device_slot(slot); + if (dst == nullptr || parts == nullptr || n <= 0) { + err = "ExpertCache::fill_slot_queued_parts: slot outside the arena or no pieces"; + return false; + } + uint64_t total = 0; + for (int i = 0; i < n; ++i) total += parts[i].n; + if (total > (uint64_t) blob_) { + err = "ExpertCache::fill_slot_queued_parts: the pieces are larger than a slot"; + return false; + } + for (int i = 0; i < n; ++i) { + const cudaError_t e = cudaMemcpyAsync(dst + parts[i].at, parts[i].p, (size_t) parts[i].n, cudaMemcpyHostToDevice, + (cudaStream_t) 0); + if (e != cudaSuccess) { + err = std::string("ExpertCache::fill_slot_queued_parts: ") + cudaGetErrorString(e); + return false; + } + } + ++fills_; + return true; +} + bool ExpertCache::sync_queued(std::string& err) { const cudaError_t e = cudaStreamSynchronize((cudaStream_t) 0); if (e != cudaSuccess) { diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cpp index 4878c111..0965d83a 100644 --- a/src/core/expert_source.cpp +++ b/src/core/expert_source.cpp @@ -3459,6 +3459,25 @@ const uint8_t* FileExpertSource::blob_stable(int64_t layer, int64_t expert) { return blob(layer, expert); } +int FileExpertSource::blob_parts(int64_t layer, int64_t expert, BlobPart* out) { + // the GGUF mapped in place only (three tensors per expert); the RAM copy, an exchange override, the unbuffered + // reads, a closed mapping and the I/O prefetch (STRATA_IO_PREFETCH: it preads the ranges the page cache lacks, which a copy out + // of the mapping would fault in one page at a time) keep going through blob(), which knows them + if (role_ptr_.empty() || !direct_.empty() || io_pf_ || unmapped_ || base_ == nullptr || layer < 0 || expert < 0 || + layer >= n_layers_ || expert >= n_expert_) + return 0; + const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert; + if (complement_ready_ && (resident_blob(index) != nullptr || (!override_.empty() && override_[index] != nullptr))) return 0; + Span sp[3]; + const int ns = spans(layer, expert, sp); + for (int i = 0; i < ns; ++i) out[i] = {sp[i].p, sp[i].n, sp[i].at}; + if (ns > 0) { + file_read_bytes_.fetch_add(layer_blob_bytes_[(size_t) layer], std::memory_order_relaxed); + ++reads_; + } + return ns; +} + const uint8_t* FileExpertSource::blob(int64_t layer, int64_t expert) { if (base_ == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || expert >= n_expert_) return nullptr; const size_t index = (size_t) layer * (size_t) n_expert_ + (size_t) expert; diff --git a/src/program/generate.cpp b/src/program/generate.cpp index ba00f94d..ef8965f2 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -11413,10 +11413,20 @@ int main(int argc, char** argv) { // through its own cache and its own device - a slot refilled into the wrong cache would leave that // stage's cache holding an expert it does not own, which is silent and produces plausible tokens. // (split in two halves so a layer split can queue every stage's copies before it waits for any: #340) + // STRATA_REFILL_PARTS=1 (gfx1151's table): a lent slot of a GGUF read in place is refilled from the pieces in the mapping. + // The default assembles the blob in a staging buffer first (a 4 MB copy on this thread), then copies that. + static const bool refill_parts = [] { const char* v = std::getenv("STRATA_REFILL_PARTS"); return v != nullptr && std::atoi(v) != 0; }(); auto refill_issue = [&](PfPart& p, std::string& e) -> bool { tr("refill start", (long long) p.lent.size()); const strata::core::OnDevice on(p.dev); for (const auto& [i, slot] : p.lent) { // D-4: queued, one wait (STRATA_REFILL_BLOCKING=1: each) + strata::core::BlobPart parts[3]; + const int np = refill_parts && !refill_blocking() ? srcp->blob_parts(i / g.n_expert, i % g.n_expert, parts) : 0; + if (np > 0) { // the GGUF read in place: the tensors' pieces go from the mapping to the slot, no assembled copy + if (!p.cache->fill_slot_queued_parts(slot, parts, np, e)) return false; + host_res[(size_t) i] = slot; + continue; + } const uint8_t* b = srcp->blob_stable(i / g.n_expert, i % g.n_expert); const int64_t nb = (int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert); if (b == nullptr || !(refill_blocking() ? p.cache->fill_slot_blocking(slot, b, e, nb) From df218bd8aea7fc3b725c6a9ae1b0ca9ba7b3f6c4 Mon Sep 17 00:00:00 2001 From: libratechw Date: Sun, 11 Oct 2026 14:25:29 +0900 Subject: [PATCH 04/28] prefill: K-quant gate/up on the gfx11 F16 matrix cores (opt-in STRATA_PF_F16_KQ=1) UD-Q4_K_XL's routed gate/up was 6/10 of the prompt-time gap to gufo on gfx1151 (128K: 23.1 s against 13.9 s). moe_f16_kq.cu adapts gufo's paired RoutedF16GEMMKernel (97b8645f, MIT) to Strata's tables, int8 activations and H: the Q4_K / Q5_K codes stay packed in LDS and each wave turns its own rows into F16 after the read, so the F16 WMMA accumulates all of K in F32 with no per-block epilogue; the activations are staged once in LDS as F16 for every wave; the epilogue writes H as int8 per 32 features for the existing down kernels. One block per work item; two tiles of an expert per item from 64 routed rows per expert on average. hip_prefill_fused_iq (gfx1151, ROCm 7.14.1 clang 23, one layer, 16384 tokens x top 10 over 512 experts): - gate/up kernel 14.63 -> 8.46 ms per 128-expert launch; Q4_K / Q5_1 layer 85.3 -> 62.7 ms, Q5_K / Q5_1 89.9 -> 66.2. - against the FP32 reference the error is the int8 path's (rel RMS 1.305e-2 / 1.302e-2: the int8 activations dominate); the int8 model check allows 5e-3 under this switch (2.5e-3 measured with Q8_0 down). - the output bits are the same with 64- and 128-row items. Off by default; it needs STRATA_PF_FUSED=1 and STRATA_PF_FUSED_KQ=1, whose output already differs from MMQ's. --- CMakeLists.txt | 3 +- src/prefill/moe_f16_kq.cu | 391 +++++++++++++++++++++++++++ src/prefill/moe_f16_kq.hpp | 25 ++ src/prefill/moe_fused_iq.cu | 8 +- tests/cuda/prefill_fused_iq_test.cpp | 6 +- 5 files changed, 430 insertions(+), 3 deletions(-) create mode 100644 src/prefill/moe_f16_kq.cu create mode 100644 src/prefill/moe_f16_kq.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e28abd9b..d695af19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1549,6 +1549,7 @@ if(STRATA_NATIVE_EXPERTS) src/prefill/moe_mmq.cu src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu + src/prefill/moe_f16_kq.cu src/prefill/ggml_cuda_host.cu "${_strata_mmq}/quantize.cu") if(STRATA_MMQ_KQUANTS) @@ -1561,7 +1562,7 @@ if(STRATA_NATIVE_EXPERTS) endforeach() set_source_files_properties(${_strata_mmq_sources} PROPERTIES LANGUAGE HIP) # moe_fused.cu is Strata's own CUDA-shaped source: it takes the HIP compat headers, ggml's MMQ sources do not - set_source_files_properties(src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu + set_source_files_properties(src/prefill/moe_fused.cu src/prefill/moe_fused_iq.cu src/prefill/moe_f16_kq.cu PROPERTIES INCLUDE_DIRECTORIES "${STRATA_HIP_COMPAT_INCLUDE_DIR}") add_library(strata_mmq STATIC ${_strata_mmq_sources}) target_include_directories(strata_mmq diff --git a/src/prefill/moe_f16_kq.cu b/src/prefill/moe_f16_kq.cu new file mode 100644 index 00000000..953b3782 --- /dev/null +++ b/src/prefill/moe_f16_kq.cu @@ -0,0 +1,391 @@ +// src/prefill/moe_f16_kq.cu - see moe_f16_kq.hpp. gfx11 only (opt-in STRATA_PF_F16_KQ=1). +// +// The paired gate/up kernel of gufo's routed experts, on Strata's tables, int8 activations and H: +// - one work item is 64 features of one expert (its 64 gate and 64 up rows, BM = 128) against one 64-row tile of +// fused::group, K = 2560 in 40 stages of 64 values; +// - the weight codes stay packed in LDS (one 32-byte Q4_K nibble group per row and stage) and each wave turns its +// own 16 rows into F16 right after the LDS read: w = q * (d sc) - dmin m as one packed FMA, so the F16 matrix +// core accumulates the whole K in F32 with no per-block epilogue; +// - the activations are native_w11_kernel's int8 blocks, staged in LDS as F16 (a * d_x, one product each), shared +// by every wave; +// - the epilogue applies SwiGLU and writes H as int8 per 32 features (with the codes' sum), the form the existing +// down kernels read. +// The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), like STRATA_PF_FUSED_KQ's +// does from the MMQ path. +// +// Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp +// (RoutedF16GEMMKernel and its helpers). +// MIT License +// Copyright (c) 2026 gufo contributors +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#include "moe_f16_kq.hpp" + +#include + +#include "ggml.h" + +#include +#include +#include +#include + +namespace strata::prefill::fused::f16kq { +namespace { + +constexpr int T_Q4_K = GGML_TYPE_Q4_K, T_Q5_K = GGML_TYPE_Q5_K; +constexpr int AB = 80; // activation / H bytes per 64 values: 64 codes, {d0, d1}, {sum0, sum1} +constexpr int K_GU = 2560; // n_embd +constexpr int NS = K_GU / 64; // stages +constexpr int ACT_LD = NS * AB; // bytes per activation row +constexpr int FEAT = 64; // features (gate rows = up rows) per work item +constexpr int NFB = 640 / FEAT; // work items per tile +constexpr int BM = 2 * FEAT; // code rows in LDS: gate 0..63, up 64..127 +constexpr int THREADS = 256; + +#if defined(__HIPCC__) && (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || \ + defined(__gfx1150__) || defined(__gfx1151__)) +#define STRATA_F16KQ_DEVICE 1 +#else +#define STRATA_F16KQ_DEVICE 0 +#endif + +using v16h = __attribute__((__vector_size__(16 * sizeof(_Float16)))) _Float16; +using v8f = __attribute__((__vector_size__(8 * sizeof(float)))) float; + +__device__ __forceinline__ v8f wmma_f16(v16h a, v16h b, v8f c) { +#if STRATA_F16KQ_DEVICE + return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); +#else + __builtin_trap(); + return c; +#endif +} + +// Byte i of the 16-byte K-quant block header (d, dmin, scales[12]). +__device__ __forceinline__ uint32_t header_byte(const uint4& h, uint32_t i) { + const uint32_t word = i < 4 ? h.x : i < 8 ? h.y : i < 12 ? h.z : h.w; + return (word >> (8U * (i & 3U))) & 0xFFU; +} +// Bit s of each of the four bytes of w, packed into bits 0-3. +__device__ __forceinline__ uint32_t gather_bit(uint32_t w, int s) { return (((w >> s) & 0x01010101U) * 0x01020408U) >> 24U; } +// Bits 0-3 of `bits` to bit 4 of each byte. +__device__ __forceinline__ uint32_t spread_high_bits(uint32_t bits) { return (__umul24(bits, 0x00204081U) & 0x01010101U) << 4U; } + +constexpr uint32_t HALF_MAGIC = 0x64646464U; // the high bytes of 1024.0 as F16 +// Four code bytes (< 32) to four halves: 1024 + q exactly, minus 1024, then q * scale + bias. +__device__ __forceinline__ void codes_to_halves(uint32_t codes, __half2 magic, __half2 scale2, __half2 bias2, __half2& lo, + __half2& hi) { +#if STRATA_F16KQ_DEVICE + const uint32_t p0 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x01050004U); + const uint32_t p1 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x03070206U); + lo = __hfma2(__hadd2(__builtin_bit_cast(__half2, p0), magic), scale2, bias2); + hi = __hfma2(__hadd2(__builtin_bit_cast(__half2, p1), magic), scale2, bias2); +#else + (void) codes; (void) magic; (void) scale2; (void) bias2; lo = hi = __half2{}; +#endif +} + +// BN: tokens per work item, fused::group's 64-row tile or two consecutive tiles of one expert (128) +template +__global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, + const int2* __restrict__ tiles, const int32_t* __restrict__ off, + const uint8_t* __restrict__ act, const int32_t* __restrict__ src, + uint8_t* __restrict__ out) { +#if STRATA_F16KQ_DEVICE + static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); + constexpr bool Q5K = WT == T_Q5_K; + constexpr int TOK_TILES = BN / 16; + constexpr int BLOCK_CHUNKS = Q5K ? 11 : 9; // 16-byte chunks per 256-value block + constexpr int CODE_CHUNK = Q5K ? 3 : 1; // the first chunk of qs + // LDS (bytes): codes BM rows x 2 chunks (swizzled); Q5_K's high bits and the (scale, bias) half2 per row and K + // block; the activations [kb][quarter][token][16 B], one slot of padding per quarter plane. The epilogue reuses + // the front for eight 16 x 18 float planes. + constexpr int CODE_BYTES = BM * 2 * 16; + constexpr int HIGH_BYTES = Q5K ? 2 * BM * 4 : 0; + constexpr int SCALE_BYTES = 2 * BM * 4; + constexpr int ACT_STRIDE = BN + 1; + constexpr int ACT_BYTES = 2 * 4 * ACT_STRIDE * 16; + constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ACT_BYTES; + constexpr int EPI_STRIDE = 18, EPI_PLANE = 16 * EPI_STRIDE; + static_assert(8 * EPI_PLANE * 4 <= STAGE_BYTES, "the epilogue planes fit the stage"); + __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; + __shared__ int srow[BN]; + auto* s_codes = reinterpret_cast(lds); + auto* s_high = reinterpret_cast(lds + CODE_BYTES); + auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); + auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); + + const int tid = threadIdx.x, wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + const int f_c = tid & 1; // this thread's chunk (and K block) of its weight row + const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; + const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); + + // One work item per block, the grid the batch's bound (gufo's launch: the hardware balances the blocks; the + // NFB items of a tile are consecutive, so they meet its activations in L2) + const int t0 = ts[b.e0], w = blockIdx.x; + if (w >= (ts[b.e1] - t0) * NFB) return; + { + const int2 tl = tiles[t0 + w / NFB]; + const int fb = w % NFB, e = tl.x, row0 = tl.y; + if (BN > kTileRows && ((t0 + w / NFB - ts[e]) & 1)) return; // the second tile of a pair: its first takes it + const int nrows = min(BN, off[e + 1] - row0); + const int live_tok_tiles = (nrows + 15) / 16; + const uint8_t* blob = b.blob[e - b.e0]; + if (tid < BN) srow[tid] = tid < nrows ? src[row0 + tid] : -1; + __syncthreads(); + + // Weight fetch: row tid / 2 of the code plane (gate rows, then up rows), chunk f_c. + const uint8_t* f_ptr = blob + ((tid >> 1) >= FEAT ? geo.up_off : 0) + + (size_t) (fb * FEAT + ((tid >> 1) & (FEAT - 1))) * geo.gu_row; + uint4 f_header = make_uint4(0u, 0u, 0u, 0u), f_codes, f_qh[2] = {}; + uint4 code_cache[4]; // the block's four nibble groups, this thread's chunk of each + uint32_t f_high = 0; + int f_sb32 = 0; + // Activation fetch: BN tokens x 8 chunks of 8 values per stage; chunk sub = kb * 4 + quarter. + constexpr int ACT_FETCH = BN * 8 / THREADS; + const uint8_t* a_src[ACT_FETCH]; + int a_slot[ACT_FETCH], a_sub[ACT_FETCH]; + uint2 a_codes[ACT_FETCH]; + float a_d[ACT_FETCH]; +#pragma unroll + for (int i = 0; i < ACT_FETCH; ++i) { + const int chunk = tid + i * THREADS, t = chunk >> 3, sub = chunk & 7; + const int tok = srow[t]; + a_src[i] = tok >= 0 ? act + (size_t) tok * ACT_LD : nullptr; + a_slot[i] = sub * ACT_STRIDE + t; + a_sub[i] = sub; + } + + const auto fetch_stage = [&](int s) { + const int kb0 = 2 * s; + const uint4* blk = reinterpret_cast(f_ptr) + (kb0 / 8) * BLOCK_CHUNKS; + if (kb0 % 8 == 0) { // a new 256-value block every four stages + f_header = blk[0]; +#pragma unroll + for (int group = 0; group < 4; ++group) code_cache[group] = blk[CODE_CHUNK + group * 2 + f_c]; + if constexpr (Q5K) { + f_qh[0] = blk[1]; + f_qh[1] = blk[2]; + } + } + const int sb32 = (kb0 % 8) + f_c; + { + const int group = sb32 / 2; // uniform across the wave + const uint32_t low = 0u - (group & 1u), high = 0u - ((group >> 1u) & 1u); + const auto select = [](uint32_t a, uint32_t bb, uint32_t mask) { + uint32_t value; + asm("v_cndmask_b32_e64 %0, %1, %2, %3" : "=v"(value) : "v"(a), "v"(bb), "s"(mask)); + return value; + }; + const uint4 &c0 = code_cache[0], &c1 = code_cache[1], &c2 = code_cache[2], &c3 = code_cache[3]; + f_codes = make_uint4(select(select(c0.x, c1.x, low), select(c2.x, c3.x, low), high), + select(select(c0.y, c1.y, low), select(c2.y, c3.y, low), high), + select(select(c0.z, c1.z, low), select(c2.z, c3.z, low), high), + select(select(c0.w, c1.w, low), select(c2.w, c3.w, low), high)); + } + f_sb32 = sb32; + if constexpr (Q5K) { + const uint32_t qh[8] = {f_qh[0].x, f_qh[0].y, f_qh[0].z, f_qh[0].w, f_qh[1].x, f_qh[1].y, f_qh[1].z, f_qh[1].w}; + uint32_t hb = 0; +#pragma unroll + for (int i = 0; i < 8; ++i) hb |= gather_bit(qh[i], sb32) << (4 * i); + f_high = hb; + } +#pragma unroll + for (int i = 0; i < ACT_FETCH; ++i) { + if (a_src[i] != nullptr) { + const uint8_t* p = a_src[i] + (size_t) s * AB; + a_codes[i] = *reinterpret_cast(p + 8 * a_sub[i]); + a_d[i] = *reinterpret_cast(p + 64 + 4 * (a_sub[i] >> 2)); + } else { + a_codes[i] = make_uint2(0u, 0u); + a_d[i] = 0.0f; + } + } + }; + + const auto commit_stage = [&]() { + const int row = tid >> 1; + s_codes[swizzle(row, f_c)] = f_codes; + if constexpr (Q5K) s_high[f_c * BM + row] = f_high; + const int sb32 = f_sb32; + uint32_t sc, mn; + if (sb32 < 4) { + sc = header_byte(f_header, 4 + sb32) & 0x3FU; + mn = header_byte(f_header, 8 + sb32) & 0x3FU; + } else { + sc = (header_byte(f_header, 8 + sb32) & 0x0FU) | ((header_byte(f_header, sb32) >> 6U) << 4U); + mn = (header_byte(f_header, 8 + sb32) >> 4U) | ((header_byte(f_header, 4 + sb32) >> 6U) << 4U); + } + const __half2 dm = __builtin_bit_cast(__half2, f_header.x); + const float scale = __low2float(dm) * (float) sc, offset = __high2float(dm) * (float) mn; + s_scale[f_c * BM + row] = __builtin_bit_cast(uint32_t, __floats2half2_rn(scale, -offset)); +#pragma unroll + for (int i = 0; i < ACT_FETCH; ++i) { + const uint32_t ws[2] = {a_codes[i].x, a_codes[i].y}; + __half2 h[4]; +#pragma unroll + for (int j = 0; j < 4; ++j) { + const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); + const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); + h[j] = __floats2half2_rn(lo * a_d[i], hi * a_d[i]); + } + s_act[a_slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), + __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); + } + }; + + v8f acc[TOK_TILES]; +#pragma unroll + for (int j = 0; j < TOK_TILES; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; // waves 0-3: gate rows, 4-7: the matching up rows + const uint4 raw0 = s_codes[swizzle(row, 0)], raw1 = s_codes[swizzle(row, 1)]; +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * BM + row]); + const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); + // elements 0-15 of K block 2s + kb are the low (kb = 0) or high (kb = 1) nibbles of chunk 0, 16-31 of chunk 1 + const unsigned shift = 4U * (unsigned) kb; + const uint32_t words[8] = {raw0.x, raw0.y, raw0.z, raw0.w, raw1.x, raw1.y, raw1.z, raw1.w}; + const uint32_t hb = Q5K ? s_high[kb * BM + row] : 0U; + __half2 h[16]; +#pragma unroll + for (int i = 0; i < 8; ++i) { + uint32_t nib = (words[i] >> shift) & 0x0F0F0F0FU; + if constexpr (Q5K) nib |= spread_high_bits((hb >> (4 * i)) & 0xFU); + codes_to_halves(nib, magic, scale2, bias2, h[2 * i], h[2 * i + 1]); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &h[0], 32); + __builtin_memcpy(&a_hi, &h[8], 32); +#pragma unroll + for (int j = 0; j < TOK_TILES; ++j) { + asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) + if (j >= live_tok_tiles) continue; + const uint4* frag = s_act + (kb * 4) * ACT_STRIDE + j * 16 + sub_lane; + uint4 bq[4]; +#pragma unroll + for (int q = 0; q < 4; ++q) bq[q] = frag[q * ACT_STRIDE]; + v16h b_lo, b_hi; + __builtin_memcpy(&b_lo, &bq[0], 32); + __builtin_memcpy(&b_hi, &bq[2], 32); + acc[j] = wmma_f16(a_lo, b_lo, acc[j]); + acc[j] = wmma_f16(a_hi, b_hi, acc[j]); + } + } + }; + + fetch_stage(0); + for (int s = 0; s < NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + + // Epilogue per token tile: each wave's 16 x 16 accumulators as plane [token][row] (gate planes 0-3, up 4-7), + // then a thread per (token, half of the 64 features): SwiGLU, int8 per 32 with the codes' sum. + float* base = reinterpret_cast(lds); + float* scratch = base + wave * EPI_PLANE; +#pragma unroll + for (int j = 0; j < TOK_TILES; ++j) { + if (j >= live_tok_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) scratch[sub_lane * EPI_STRIDE + 2 * l + half_id] = acc[j][l]; + __syncthreads(); + if (tid < 32) { + const int t = tid >> 1, hh = tid & 1, r = j * 16 + t; + if (r < nrows) { + float hv[32]; + float am = 0.0f; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int ft = 32 * hh + f; + const int idx = (ft >> 4) * EPI_PLANE + t * EPI_STRIDE + (ft & 15); + const float gt = base[idx], up = base[idx + 4 * EPI_PLANE]; + hv[f] = gt / (1.0f + __expf(-gt)) * up; + am = fmaxf(am, fabsf(hv[f])); + } + const float inv = am > 0.0f ? 127.0f / am : 0.0f; + uint8_t* o = out + (size_t) (row0 + r) * (10 * AB) + (size_t) fb * AB; + uint32_t wd[8] = {}; + int csum = 0; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int c = __float2int_rn(hv[f] * inv); + csum += c; + wd[f >> 2] |= (uint32_t) (uint8_t) (int8_t) c << (8 * (f & 3)); + } + uint4* o4 = reinterpret_cast(o + 32 * hh); + o4[0] = make_uint4(wd[0], wd[1], wd[2], wd[3]); + o4[1] = make_uint4(wd[4], wd[5], wd[6], wd[7]); + *reinterpret_cast(o + 64 + 4 * hh) = am / 127.0f; + *reinterpret_cast(o + 72 + 4 * hh) = (float) csum; + } + } + __syncthreads(); + } + } +#else + (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) act; (void) src; (void) out; + __builtin_trap(); +#endif +} + +// Two tiles a work item when an expert has a tile's rows or more on average. gfx1151, Q4_K, top 10 over 512 experts, +// one 128-expert launch, ms (64 / 128): 1024 tokens 1.22 / 1.28, 2048 1.51 / 1.64, 4096 2.73 / 2.48, 8192 4.76 / 4.59, +// 16384 9.19 / 8.46. STRATA_PF_F16_KQ_BN=64|128 forces one. +int pick_bn(int64_t n, int n_expert) { + static const int forced = [] { + const char* v = std::getenv("STRATA_PF_F16_KQ_BN"); + const int t = v ? std::atoi(v) : 0; + return t == 64 || t == 128 ? t : 0; + }(); + if (forced) return forced; + return (double) n / std::max(n_expert, 1) >= kTileRows ? 2 * kTileRows : kTileRows; +} + +template +void launch(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t work_bound, + const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { + const unsigned grid = (unsigned) std::max(1, work_bound * NFB); + if (g.gu_type == T_Q5_K) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); +} + +} // namespace + +bool requested() { + static const bool on = [] { + const char* v = std::getenv("STRATA_PF_F16_KQ"); + return v != nullptr && v[0] == '1'; + }(); + return on; +} + +bool covers(int gu_type) { return gu_type == T_Q4_K || gu_type == T_Q5_K; } + +void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, + int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { + if (pick_bn(n, n_expert) == 2 * kTileRows) launch<2 * kTileRows>(b, g, ts, tiles, off, work_bound, act, src, out, s); + else launch(b, g, ts, tiles, off, work_bound, act, src, out, s); +} + +} // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_f16_kq.hpp b/src/prefill/moe_f16_kq.hpp new file mode 100644 index 00000000..30bcc577 --- /dev/null +++ b/src/prefill/moe_f16_kq.hpp @@ -0,0 +1,25 @@ +// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts' gate/up on the F16 matrix cores (moe_f16_kq.cu). +// Internal to moe_fused_iq.cu, which owns the native experts' tables, launch and down projection. +#pragma once + +#include + +#include + +#include "strata/prefill/moe_fused.hpp" +#include "strata/prefill/moe_fused_iq.hpp" + +namespace strata::prefill::fused::f16kq { + +/// STRATA_PF_F16_KQ=1 (on top of STRATA_PF_FUSED=1 and STRATA_PF_FUSED_KQ=1): Q4_K / Q5_K gate/up take this path. +bool requested(); +/// The gate/up type has a kernel here (and this build has gfx11 device code). +bool covers(int gu_type); + +/// Gate/up, SwiGLU and H for experts [b.e0, b.e1): the same tiles, activations and H as native_w11_kernel. +/// `ts`, `tiles`, `off` are fused::group's tables (at most `work_bound` tiles); `n` the layer's routed rows over +/// `n_expert` experts; `act` the int8 activations (quantize_act_native); `out` H. +void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, + int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s); + +} // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index 3baf5d39..505517f0 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -22,6 +22,10 @@ #include "strata/prefill/moe_fused_iq.hpp" #include "strata/kernels/gfx_arch.hpp" +#if defined(__HIPCC__) +#include "moe_f16_kq.hpp" +#endif + #include #include @@ -1200,7 +1204,9 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const uint8_t* xa8 = (const uint8_t*) xa; uint8_t* ha8 = (uint8_t*) ha; #define STRATA_NW_GU(T) do { if (occ_gu) native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); else native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); } while (0) - switch (g.gu_type) { + // STRATA_PF_F16_KQ=1: the K-quant gate/up on the F16 matrix cores (moe_f16_kq.cu); down stays below + if (f16kq::requested() && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); + else switch (g.gu_type) { case T_IQ2_XXS: STRATA_NW_GU(T_IQ2_XXS); break; case T_IQ2_XS: STRATA_NW_GU(T_IQ2_XS); break; case T_IQ2_S: STRATA_NW_GU(T_IQ2_S); break; diff --git a/tests/cuda/prefill_fused_iq_test.cpp b/tests/cuda/prefill_fused_iq_test.cpp index ebab9b54..6af2ae97 100644 --- a/tests/cuda/prefill_fused_iq_test.cpp +++ b/tests/cuda/prefill_fused_iq_test.cpp @@ -397,7 +397,11 @@ void reference_part(const Pair& p, cudaStream_t s) { const Err e2 = compare(y_f, frow, ref2, pair, (size_t) rows); std::printf(" fused vs the int8-rounded model (same activation / H rounding, double sums): rel RMS %.3e worst %.3e\n", e2.rms, e2.worst); - if (e2.rms > 2e-3 || e2.worst > 3e-2) + // STRATA_PF_F16_KQ=1: the K-quant gate/up runs on F16 weights (moe_f16_kq.cu), so H's int8 rounding meets values + // a few F16 ulps from the int8 model's; the FP32 reference checks below stay as they are + const char* f16e = std::getenv("STRATA_PF_F16_KQ"); + const bool f16 = f16e != nullptr && f16e[0] == '1' && (p.gu == GGML_TYPE_Q4_K || p.gu == GGML_TYPE_Q5_K); + if (e2.rms > (f16 ? 5e-3 : 2e-3) || e2.worst > 3e-2) throw std::runtime_error(std::string(p.name) + ": the fused path differs from its own arithmetic's model"); if (mq) std::printf(" MMQ vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", em.rms, em.worst); std::printf(" fused vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", ef.rms, ef.worst); From b2492918f5118aaa6d5cede33903ca2b3c972f08 Mon Sep 17 00:00:00 2001 From: libratechw Date: Sun, 11 Oct 2026 15:18:42 +0900 Subject: [PATCH 05/28] prefill: Q5_1 down on the gfx11 F16 matrix cores too (STRATA_PF_F16_KQ=1) down_kernel takes gate/up's structure for UD-Q4_K_XL's Q5_1 down (47 of its layers): the codes and high-bit words packed in LDS, w = q d + m per wave in F16, H staged once as F16 from its int8 blocks, FP32 outputs at the routed rows. The activation staging and the WMMA loop are shared with gate/up (ActStage, mma_tiles). Q8_0 down stays on native_w11_kernel. hip_prefill_fused_iq (gfx1151, one layer, 16384 tokens x top 10 over 512 experts): down 7.10 -> 4.83 ms per 128-expert launch; Q4_K / Q5_1 layer 62.7 -> 53.5 ms (85.3 on the int8 kernels); FP32 reference rel RMS 1.304e-2. --- src/prefill/moe_f16_kq.cu | 261 ++++++++++++++++++++++++++++-------- src/prefill/moe_f16_kq.hpp | 13 +- src/prefill/moe_fused_iq.cu | 5 +- 3 files changed, 216 insertions(+), 63 deletions(-) diff --git a/src/prefill/moe_f16_kq.cu b/src/prefill/moe_f16_kq.cu index 953b3782..2634d9c6 100644 --- a/src/prefill/moe_f16_kq.cu +++ b/src/prefill/moe_f16_kq.cu @@ -10,8 +10,9 @@ // by every wave; // - the epilogue applies SwiGLU and writes H as int8 per 32 features (with the codes' sum), the form the existing // down kernels read. -// The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), like STRATA_PF_FUSED_KQ's -// does from the MMQ path. +// Q5_1 down takes the same structure (down_kernel): H staged as F16, the codes and high bits packed in LDS, FP32 +// outputs at the routed rows. The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), +// like STRATA_PF_FUSED_KQ's does from the MMQ path. // // Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp // (RoutedF16GEMMKernel and its helpers). @@ -99,6 +100,76 @@ __device__ __forceinline__ void codes_to_halves(uint32_t codes, __half2 magic, _ #endif } +// The int8 activation (or H) rows of a work item, staged as F16 per stage: BN rows x 8 chunks of 8 values, chunk +// sub = kb * 4 + quarter, into LDS [sub][row] (stride BN + 1) - the B fragments' layout of the F16 WMMA. A row past +// the item's end is zero. +template struct ActStage { + static constexpr int FETCH = BN * 8 / THREADS, STRIDE = BN + 1, BYTES = 2 * 4 * STRIDE * 16; + const uint8_t* src[FETCH]; + int slot[FETCH], sub[FETCH]; + uint2 codes[FETCH]; + float d[FETCH]; + // rows[t]: the row of item row t in `base` (rows of `ld` bytes), or -1 + __device__ __forceinline__ void init(const uint8_t* base, size_t ld, const int* rows, int tid) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const int chunk = tid + i * THREADS, t = chunk >> 3, c = chunk & 7; + src[i] = rows[t] >= 0 ? base + (size_t) rows[t] * ld : nullptr; + slot[i] = c * STRIDE + t; + sub[i] = c; + } + } + __device__ __forceinline__ void fetch(int s) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + if (src[i] != nullptr) { + const uint8_t* p = src[i] + (size_t) s * AB; + codes[i] = *reinterpret_cast(p + 8 * sub[i]); + d[i] = *reinterpret_cast(p + 64 + 4 * (sub[i] >> 2)); + } else { + codes[i] = make_uint2(0u, 0u); + d[i] = 0.0f; + } + } + } + __device__ __forceinline__ void commit(uint4* s_act) const { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const uint32_t ws[2] = {codes[i].x, codes[i].y}; + __half2 h[4]; +#pragma unroll + for (int j = 0; j < 4; ++j) { + const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); + const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); + h[j] = __floats2half2_rn(lo * d[i], hi * d[i]); + } + s_act[slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), + __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); + } + } +}; + +// Two F16 WMMAs (K 32) of a wave's 16 weight rows against each live 16-row tile of the staged activations. +template +__device__ __forceinline__ void mma_tiles(v8f (&acc)[BN / 16], v16h a_lo, v16h a_hi, const uint4* s_act, int kb, int sub_lane, + int live_tiles) { + constexpr int STRIDE = ActStage::STRIDE; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) + if (j >= live_tiles) continue; + const uint4* frag = s_act + (kb * 4) * STRIDE + j * 16 + sub_lane; + uint4 bq[4]; +#pragma unroll + for (int q = 0; q < 4; ++q) bq[q] = frag[q * STRIDE]; + v16h b_lo, b_hi; + __builtin_memcpy(&b_lo, &bq[0], 32); + __builtin_memcpy(&b_hi, &bq[2], 32); + acc[j] = wmma_f16(a_lo, b_lo, acc[j]); + acc[j] = wmma_f16(a_hi, b_hi, acc[j]); + } +} + // BN: tokens per work item, fused::group's 64-row tile or two consecutive tiles of one expert (128) template __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, @@ -117,9 +188,7 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N constexpr int CODE_BYTES = BM * 2 * 16; constexpr int HIGH_BYTES = Q5K ? 2 * BM * 4 : 0; constexpr int SCALE_BYTES = 2 * BM * 4; - constexpr int ACT_STRIDE = BN + 1; - constexpr int ACT_BYTES = 2 * 4 * ACT_STRIDE * 16; - constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ACT_BYTES; + constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; constexpr int EPI_STRIDE = 18, EPI_PLANE = 16 * EPI_STRIDE; static_assert(8 * EPI_PLANE * 4 <= STAGE_BYTES, "the epilogue planes fit the stage"); __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; @@ -155,20 +224,8 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N uint4 code_cache[4]; // the block's four nibble groups, this thread's chunk of each uint32_t f_high = 0; int f_sb32 = 0; - // Activation fetch: BN tokens x 8 chunks of 8 values per stage; chunk sub = kb * 4 + quarter. - constexpr int ACT_FETCH = BN * 8 / THREADS; - const uint8_t* a_src[ACT_FETCH]; - int a_slot[ACT_FETCH], a_sub[ACT_FETCH]; - uint2 a_codes[ACT_FETCH]; - float a_d[ACT_FETCH]; -#pragma unroll - for (int i = 0; i < ACT_FETCH; ++i) { - const int chunk = tid + i * THREADS, t = chunk >> 3, sub = chunk & 7; - const int tok = srow[t]; - a_src[i] = tok >= 0 ? act + (size_t) tok * ACT_LD : nullptr; - a_slot[i] = sub * ACT_STRIDE + t; - a_sub[i] = sub; - } + ActStage as; + as.init(act, ACT_LD, srow, tid); // the tokens' activation rows const auto fetch_stage = [&](int s) { const int kb0 = 2 * s; @@ -205,17 +262,7 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N for (int i = 0; i < 8; ++i) hb |= gather_bit(qh[i], sb32) << (4 * i); f_high = hb; } -#pragma unroll - for (int i = 0; i < ACT_FETCH; ++i) { - if (a_src[i] != nullptr) { - const uint8_t* p = a_src[i] + (size_t) s * AB; - a_codes[i] = *reinterpret_cast(p + 8 * a_sub[i]); - a_d[i] = *reinterpret_cast(p + 64 + 4 * (a_sub[i] >> 2)); - } else { - a_codes[i] = make_uint2(0u, 0u); - a_d[i] = 0.0f; - } - } + as.fetch(s); }; const auto commit_stage = [&]() { @@ -234,19 +281,7 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N const __half2 dm = __builtin_bit_cast(__half2, f_header.x); const float scale = __low2float(dm) * (float) sc, offset = __high2float(dm) * (float) mn; s_scale[f_c * BM + row] = __builtin_bit_cast(uint32_t, __floats2half2_rn(scale, -offset)); -#pragma unroll - for (int i = 0; i < ACT_FETCH; ++i) { - const uint32_t ws[2] = {a_codes[i].x, a_codes[i].y}; - __half2 h[4]; -#pragma unroll - for (int j = 0; j < 4; ++j) { - const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); - const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); - h[j] = __floats2half2_rn(lo * a_d[i], hi * a_d[i]); - } - s_act[a_slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), - __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); - } + as.commit(s_act); }; v8f acc[TOK_TILES]; @@ -274,20 +309,7 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N v16h a_lo, a_hi; __builtin_memcpy(&a_lo, &h[0], 32); __builtin_memcpy(&a_hi, &h[8], 32); -#pragma unroll - for (int j = 0; j < TOK_TILES; ++j) { - asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) - if (j >= live_tok_tiles) continue; - const uint4* frag = s_act + (kb * 4) * ACT_STRIDE + j * 16 + sub_lane; - uint4 bq[4]; -#pragma unroll - for (int q = 0; q < 4; ++q) bq[q] = frag[q * ACT_STRIDE]; - v16h b_lo, b_hi; - __builtin_memcpy(&b_lo, &bq[0], 32); - __builtin_memcpy(&b_hi, &bq[2], 32); - acc[j] = wmma_f16(a_lo, b_lo, acc[j]); - acc[j] = wmma_f16(a_hi, b_hi, acc[j]); - } + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tok_tiles); } }; @@ -349,9 +371,123 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N #endif } +// Q5_1 down: 128 of the 2560 output rows (DNFB items per tile) against a tile's (or pair's) H rows, K = 640 in 10 +// stages; the products are the routed rows' FP32 outputs in `dm` (native_w11_kernel's). gufo's +// RoutedF16GEMMKernel: a K block's 16 code bytes and its high-bit word in LDS, w = q d + m per wave. +constexpr int D_ROWS = 128, DNFB = 2560 / D_ROWS, D_NS = 640 / 64, H_LD = D_NS * AB; +template +__global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, + const int2* __restrict__ tiles, const int32_t* __restrict__ off, + const uint8_t* __restrict__ h, float* __restrict__ dm) { +#if STRATA_F16KQ_DEVICE + static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); + constexpr int CODE_BYTES = D_ROWS * 2 * 16, HIGH_BYTES = 2 * D_ROWS * 4, SCALE_BYTES = 2 * D_ROWS * 4; + constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; + static_assert(8 * 256 * 4 <= STAGE_BYTES, "the epilogue's 16 x 16 tile per wave fits the stage"); + __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; + __shared__ int srow[BN]; + auto* s_codes = reinterpret_cast(lds); + auto* s_high = reinterpret_cast(lds + CODE_BYTES); + auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); + auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); + + const int tid = threadIdx.x, wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + const int f_c = tid & 1; // this thread's K block of its weight row + const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; + const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); + + const int t0 = ts[b.e0], w = blockIdx.x; + if (w >= (ts[b.e1] - t0) * DNFB) return; + const int2 tl = tiles[t0 + w / DNFB]; + const int fb = w % DNFB, e = tl.x, row0 = tl.y; + if (BN > kTileRows && ((t0 + w / DNFB - ts[e]) & 1)) return; // the second tile of a pair: its first takes it + const int nrows = min(BN, off[e + 1] - row0); + const int live_tiles = (nrows + 15) / 16; + if (tid < BN) srow[tid] = tid < nrows ? row0 + tid : -1; // H is indexed by the routed row + __syncthreads(); + + const uint2* f_ptr = reinterpret_cast(b.blob[e - b.e0] + geo.down_off + + (size_t) (fb * D_ROWS + (tid >> 1)) * geo.d_row); + uint4 f_codes; + uint32_t f_high = 0, f_dm = 0; + ActStage as; + as.init(h, H_LD, srow, tid); + const auto fetch_stage = [&](int s) { + const uint2* words = f_ptr + (2 * s + f_c) * 3; // block_q5_1: {d, m}, qh, qs[16] + const uint2 w0 = words[0], w1 = words[1], w2 = words[2]; + f_codes = make_uint4(w1.x, w1.y, w2.x, w2.y); + f_high = w0.y; + f_dm = w0.x; + as.fetch(s); + }; + const auto commit_stage = [&]() { + const int row = tid >> 1; + s_codes[swizzle(row, f_c)] = f_codes; + s_high[f_c * D_ROWS + row] = f_high; + s_scale[f_c * D_ROWS + row] = f_dm; // the half2 (d, m): w = q d + m + as.commit(s_act); + }; + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; + const uint4 raw[2] = {s_codes[swizzle(row, 0)], s_codes[swizzle(row, 1)]}; +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * D_ROWS + row]); + const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); + // elements 0-15 are the low nibbles of the 16 code bytes, 16-31 the high, plus bit j of the high-bit word + const uint32_t words[4] = {raw[kb].x, raw[kb].y, raw[kb].z, raw[kb].w}; + const uint32_t hb = s_high[kb * D_ROWS + row]; + __half2 hh[16]; +#pragma unroll + for (int i = 0; i < 4; ++i) { + const uint32_t lo = (words[i] & 0x0F0F0F0FU) | spread_high_bits((hb >> (4 * i)) & 0xFU); + const uint32_t hi = ((words[i] >> 4U) & 0x0F0F0F0FU) | spread_high_bits((hb >> (16 + 4 * i)) & 0xFU); + codes_to_halves(lo, magic, scale2, bias2, hh[2 * i], hh[2 * i + 1]); + codes_to_halves(hi, magic, scale2, bias2, hh[8 + 2 * i], hh[8 + 2 * i + 1]); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &hh[0], 32); + __builtin_memcpy(&a_hi, &hh[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + fetch_stage(0); + for (int s = 0; s < D_NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < D_NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + // Each wave's 16 x 16 tile through LDS ([token][row]), then 16 consecutive FP32 rows per routed row. + float* tile = reinterpret_cast(lds) + wave * 256; + const int r0 = fb * D_ROWS + wave * 16; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + if (j >= live_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) tile[sub_lane * 16 + 2 * l + half_id] = acc[j][l]; + __builtin_amdgcn_wave_barrier(); +#pragma unroll + for (int q = 0; q < 8; ++q) { + const int flat = q * 32 + lane, t = j * 16 + (flat >> 4); + if (t < nrows) dm[(size_t) (row0 + t) * 2560 + r0 + (flat & 15)] = tile[flat]; + } + __builtin_amdgcn_wave_barrier(); + } +#else + (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) h; (void) dm; + __builtin_trap(); +#endif +} + // Two tiles a work item when an expert has a tile's rows or more on average. gfx1151, Q4_K, top 10 over 512 experts, // one 128-expert launch, ms (64 / 128): 1024 tokens 1.22 / 1.28, 2048 1.51 / 1.64, 4096 2.73 / 2.48, 8192 4.76 / 4.59, -// 16384 9.19 / 8.46. STRATA_PF_F16_KQ_BN=64|128 forces one. +// 16384 9.19 / 8.46; Q5_1 down 2048 1.02 / 1.04, 4096 1.61 / 1.48, 16384 5.29 / 4.83. STRATA_PF_F16_KQ_BN=64|128 forces +// one. int pick_bn(int64_t n, int n_expert) { static const int forced = [] { const char* v = std::getenv("STRATA_PF_F16_KQ_BN"); @@ -382,6 +518,15 @@ bool requested() { bool covers(int gu_type) { return gu_type == T_Q4_K || gu_type == T_Q5_K; } +bool covers_down(int d_type) { return d_type == GGML_TYPE_Q5_1; } + +void down(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, + int64_t work_bound, const uint8_t* h, float* dm, cudaStream_t s) { + const unsigned grid = (unsigned) std::max(1, work_bound * DNFB); + if (pick_bn(n, n_expert) == 2 * kTileRows) down_kernel<2 * kTileRows><<>>(b, g, ts, tiles, off, h, dm); + else down_kernel<<>>(b, g, ts, tiles, off, h, dm); +} + void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { if (pick_bn(n, n_expert) == 2 * kTileRows) launch<2 * kTileRows>(b, g, ts, tiles, off, work_bound, act, src, out, s); diff --git a/src/prefill/moe_f16_kq.hpp b/src/prefill/moe_f16_kq.hpp index 30bcc577..28260d8e 100644 --- a/src/prefill/moe_f16_kq.hpp +++ b/src/prefill/moe_f16_kq.hpp @@ -1,5 +1,5 @@ -// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts' gate/up on the F16 matrix cores (moe_f16_kq.cu). -// Internal to moe_fused_iq.cu, which owns the native experts' tables, launch and down projection. +// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts on the F16 matrix cores (moe_f16_kq.cu). +// Internal to moe_fused_iq.cu, which owns the native experts' tables and launches. #pragma once #include @@ -11,7 +11,8 @@ namespace strata::prefill::fused::f16kq { -/// STRATA_PF_F16_KQ=1 (on top of STRATA_PF_FUSED=1 and STRATA_PF_FUSED_KQ=1): Q4_K / Q5_K gate/up take this path. +/// STRATA_PF_F16_KQ=1 (on top of STRATA_PF_FUSED=1 and STRATA_PF_FUSED_KQ=1): Q4_K / Q5_K gate/up and Q5_1 down +/// take these kernels. bool requested(); /// The gate/up type has a kernel here (and this build has gfx11 device code). bool covers(int gu_type); @@ -22,4 +23,10 @@ bool covers(int gu_type); void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s); +/// The down type has a kernel here (Q5_1). +bool covers_down(int d_type); +/// Down for the same experts and tiles: H (int8, `h`) to the routed rows' FP32 outputs in `dm`. +void down(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, + int64_t work_bound, const uint8_t* h, float* dm, cudaStream_t s); + } // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index 505517f0..b1b8aea7 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -1204,7 +1204,7 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const uint8_t* xa8 = (const uint8_t*) xa; uint8_t* ha8 = (uint8_t*) ha; #define STRATA_NW_GU(T) do { if (occ_gu) native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); else native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); } while (0) - // STRATA_PF_F16_KQ=1: the K-quant gate/up on the F16 matrix cores (moe_f16_kq.cu); down stays below + // STRATA_PF_F16_KQ=1: the K-quant gate/up and Q5_1 down on the F16 matrix cores (moe_f16_kq.cu) if (f16kq::requested() && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); else switch (g.gu_type) { case T_IQ2_XXS: STRATA_NW_GU(T_IQ2_XXS); break; @@ -1218,7 +1218,8 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n } #undef STRATA_NW_GU #define STRATA_NW_D(T) do { if (occ_d) native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); else native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); } while (0) - if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); + if (f16kq::requested() && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); + else if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); else if (g.d_type == T_Q5_1) STRATA_NW_D(T_Q5_1); else if (g.d_type == T_Q8_0) STRATA_NW_D(T_Q8_0); else STRATA_NW_D(T_IQ4_NL); From 929010be61302e6e435cad8d618ac3b45730f10a Mon Sep 17 00:00:00 2001 From: libratechw Date: Sun, 11 Oct 2026 16:02:34 +0900 Subject: [PATCH 06/28] prefill: gfx12 keeps the int8 kernels under STRATA_PF_F16_KQ=1 moe_f16_kq.cu's bodies are gfx11's WMMA layout (and trap on other targets); v0.1.42's gfx12 native kernels share experts_native's launch, so the F16 path is taken only off gfx12. --- src/prefill/moe_fused_iq.cu | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index b1b8aea7..46f8a9a9 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -1204,8 +1204,9 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const uint8_t* xa8 = (const uint8_t*) xa; uint8_t* ha8 = (uint8_t*) ha; #define STRATA_NW_GU(T) do { if (occ_gu) native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); else native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); } while (0) - // STRATA_PF_F16_KQ=1: the K-quant gate/up and Q5_1 down on the F16 matrix cores (moe_f16_kq.cu) - if (f16kq::requested() && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); + // STRATA_PF_F16_KQ=1: the K-quant gate/up and Q5_1 down on gfx11's F16 matrix cores (moe_f16_kq.cu; gfx12's + // WMMA layout differs, so it keeps the int8 kernels) + if (!d.w12 && f16kq::requested() && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); else switch (g.gu_type) { case T_IQ2_XXS: STRATA_NW_GU(T_IQ2_XXS); break; case T_IQ2_XS: STRATA_NW_GU(T_IQ2_XS); break; @@ -1218,7 +1219,7 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n } #undef STRATA_NW_GU #define STRATA_NW_D(T) do { if (occ_d) native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); else native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); } while (0) - if (f16kq::requested() && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); + if (!d.w12 && f16kq::requested() && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); else if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); else if (g.d_type == T_Q5_1) STRATA_NW_D(T_Q5_1); else if (g.d_type == T_Q8_0) STRATA_NW_D(T_Q8_0); From bd5cc1f27bf528215e275879f5ba8249177464fd Mon Sep 17 00:00:00 2001 From: libratechw Date: Sun, 11 Oct 2026 17:06:13 +0900 Subject: [PATCH 07/28] prefill: the other native formats on gfx11's F16 matrix cores (STRATA_PF_F16=1) native_f16_kernel takes the IQ gate/up formats (IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_XS) and the Q2_0, IQ4_NL and Q8_0 down: load_unit / convert decode each sub-block once into an int8 weight tile in LDS with its scales as half2, each wave turns its own rows into F16 (gufo's Q8_0 decode: sign flip, byte permute into 1024's mantissa, one packed multiply), and the F16 WMMA accumulates all of K. The work item, the activations staged as F16, the WMMA loop and both epilogues move to moe_f16_common.cuh, shared with the K-quant kernels (moe_f16_kq.cu, now on it; its output bits are unchanged). The switch becomes STRATA_PF_F16=1 (was STRATA_PF_F16_KQ) and covers both; the K-quants still need STRATA_PF_FUSED_KQ=1. gfx12 keeps the int8 kernels. hip_prefill_fused_iq (gfx1151, ROCm 7.14.1 clang 23, top 10 over 512 experts, one 128-expert launch, ms): - IQ3_S / IQ4_NL at 16384 tokens: gate/up 11.65 -> 9.87, down 6.11 -> 4.71; layer at 8192 37.3 -> 32.2. - every pair is faster at 4096 and 16384 (IQ2_S gate/up 14.38 -> 9.85, Q8_0 down 6.80 -> 4.79), and at 128-2048 tokens equal or faster. - FP32 reference rel RMS as the int8 kernels' (IQ3_S / IQ4_NL 1.456e-2 against 1.454e-2); against the int8 model and MMQ the F16 path sits at 2.4-2.7e-3, so both checks allow 5e-3 under STRATA_PF_F16=1 (f16_on). - With the weights decoded to F16 in LDS (18 KB a block) gate/up was 9.83 and down 5.71. Neither a VGPR cap nor dropping the sign table (4 blocks per WGP) nor decoding after the products moved gate/up; without the decode it is 8.98, without the weight loads 9.30. Off by default (the output differs from the int8 kernels'). --- src/prefill/moe_f16_common.cuh | 250 +++++++++++++ src/prefill/moe_f16_kq.cu | 512 ++++++++------------------- src/prefill/moe_f16_kq.hpp | 6 +- src/prefill/moe_fused_iq.cu | 166 ++++++++- tests/cuda/prefill_fused_iq_test.cpp | 17 +- 5 files changed, 580 insertions(+), 371 deletions(-) create mode 100644 src/prefill/moe_f16_common.cuh diff --git a/src/prefill/moe_f16_common.cuh b/src/prefill/moe_f16_common.cuh new file mode 100644 index 00000000..cde99444 --- /dev/null +++ b/src/prefill/moe_f16_common.cuh @@ -0,0 +1,250 @@ +// src/prefill/moe_f16_common.cuh - the parts the gfx11 F16 prompt-expert kernels share (STRATA_PF_F16=1): the +// switch, the work item's width, the int8 activations staged as F16, the WMMA over the token tiles and the two +// epilogues. moe_f16_kq.cu (the K-quant kernels) and moe_fused_iq.cu (the other native formats) include it. +// +// A work item is 128 weight rows (gate/up: the 64 gate and 64 up rows of 64 features; down: 128 output rows) against +// one 64-row tile of fused::group or two consecutive tiles of one expert; each of the eight waves owns 16 of the +// weight rows. The F16 WMMA accumulates all of K in F32. The fragment loop and the epilogues' layouts follow gufo's +// RoutedF16GEMMKernel. +// +// Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp (RoutedF16GEMMKernel). +// MIT License +// Copyright (c) 2026 gufo contributors +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +#pragma once + +#include +#include + +#include +#include + +#include "strata/prefill/moe_fused.hpp" + +#if defined(__HIPCC__) && (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || \ + defined(__gfx1150__) || defined(__gfx1151__)) +#define STRATA_F16_DEVICE 1 +#else +#define STRATA_F16_DEVICE 0 +#endif + +namespace strata::prefill::fused::f16 { + +constexpr int AB = 80; // activation / H bytes per 64 values: 64 codes, {d0, d1}, {sum0, sum1} +constexpr int THREADS = 256; +constexpr int ROWS = 128; // weight rows per work item +constexpr int GU_NFB = 640 / 64, D_NFB = 2560 / ROWS; // work items per tile: 64 features, 128 output rows +constexpr int GU_ACT_LD = 2560 / 64 * AB, H_LD = 640 / 64 * AB; // bytes per activation / H row + +/// STRATA_PF_F16=1 (on top of STRATA_PF_FUSED=1): the covered formats take the F16 kernels on gfx11. +inline bool requested() { + static const bool on = [] { + const char* v = std::getenv("STRATA_PF_F16"); + return v != nullptr && v[0] == '1'; + }(); + return on; +} + +/// Two tiles a work item when an expert has a tile's rows or more on average. gfx1151, Q4_K, top 10 over 512 +/// experts, one 128-expert launch, ms (64 / 128): 1024 tokens 1.22 / 1.28, 2048 1.51 / 1.64, 4096 2.73 / 2.48, 8192 +/// 4.76 / 4.59, 16384 9.19 / 8.46; Q5_1 down 2048 1.02 / 1.04, 4096 1.61 / 1.48, 16384 5.29 / 4.83. +/// STRATA_PF_F16_BN=64|128 forces one. +inline int pick_bn(int64_t n, int n_expert) { + static const int forced = [] { + const char* v = std::getenv("STRATA_PF_F16_BN"); + const int t = v ? std::atoi(v) : 0; + return t == kTileRows || t == 2 * kTileRows ? t : 0; + }(); + if (forced) return forced; + return (double) n / (n_expert > 0 ? n_expert : 1) >= kTileRows ? 2 * kTileRows : kTileRows; +} + +using v16h = __attribute__((__vector_size__(16 * sizeof(_Float16)))) _Float16; +using v8f = __attribute__((__vector_size__(8 * sizeof(float)))) float; + +__device__ __forceinline__ v8f wmma_f16(v16h a, v16h b, v8f c) { +#if STRATA_F16_DEVICE + return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); +#else + __builtin_trap(); + return c; +#endif +} + +/// The work item of block `w`: its tile (fused::group's tables), whether it is the second tile of a pair (the first +/// takes it), and its rows. Returns false when the block has no work. +template +__device__ __forceinline__ bool work_item(const Batch& b, const int32_t* ts, const int2* tiles, const int32_t* off, int w, + int& fb, int& e, int& row0, int& nrows) { + static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); + const int t0 = ts[b.e0]; + if (w >= (ts[b.e1] - t0) * NFB) return false; + const int2 tl = tiles[t0 + w / NFB]; + fb = w % NFB; + e = tl.x; + row0 = tl.y; + if (BN > kTileRows && ((t0 + w / NFB - ts[e]) & 1)) return false; + nrows = min(BN, off[e + 1] - row0); + return true; +} + +/// The int8 activation (or H) rows of a work item, staged as F16 per stage: BN rows x 8 chunks of 8 values, chunk +/// sub = kb * 4 + quarter, into LDS [sub][row] (stride BN + 1) - the B fragments' layout of the F16 WMMA. A row past +/// the item's end is zero. +template struct ActStage { + static constexpr int FETCH = BN * 8 / THREADS, STRIDE = BN + 1, BYTES = 2 * 4 * STRIDE * 16; + const uint8_t* src[FETCH]; + int slot[FETCH], sub[FETCH]; + uint2 codes[FETCH]; + float d[FETCH]; + // rows[t]: the row of item row t in `base` (rows of `ld` bytes), or -1 + __device__ __forceinline__ void init(const uint8_t* base, size_t ld, const int* rows, int tid) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const int chunk = tid + i * THREADS, t = chunk >> 3, c = chunk & 7; + src[i] = rows[t] >= 0 ? base + (size_t) rows[t] * ld : nullptr; + slot[i] = c * STRIDE + t; + sub[i] = c; + } + } + __device__ __forceinline__ void fetch(int s) { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + if (src[i] != nullptr) { + const uint8_t* p = src[i] + (size_t) s * AB; + codes[i] = *reinterpret_cast(p + 8 * sub[i]); + d[i] = *reinterpret_cast(p + 64 + 4 * (sub[i] >> 2)); + } else { + codes[i] = make_uint2(0u, 0u); + d[i] = 0.0f; + } + } + } + __device__ __forceinline__ void commit(uint4* s_act) const { +#pragma unroll + for (int i = 0; i < FETCH; ++i) { + const uint32_t ws[2] = {codes[i].x, codes[i].y}; + __half2 h[4]; +#pragma unroll + for (int j = 0; j < 4; ++j) { + const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); + const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); + h[j] = __floats2half2_rn(lo * d[i], hi * d[i]); + } + s_act[slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), + __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); + } + } +}; + +/// Two F16 WMMAs (K 32) of a wave's 16 weight rows against each live 16-row tile of the staged activations. +template +__device__ __forceinline__ void mma_tiles(v8f (&acc)[BN / 16], v16h a_lo, v16h a_hi, const uint4* s_act, int kb, int sub_lane, + int live_tiles) { + constexpr int STRIDE = ActStage::STRIDE; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) + if (j >= live_tiles) continue; + const uint4* frag = s_act + (kb * 4) * STRIDE + j * 16 + sub_lane; + uint4 bq[4]; +#pragma unroll + for (int q = 0; q < 4; ++q) bq[q] = frag[q * STRIDE]; + v16h b_lo, b_hi; + __builtin_memcpy(&b_lo, &bq[0], 32); + __builtin_memcpy(&b_hi, &bq[2], 32); + acc[j] = wmma_f16(a_lo, b_lo, acc[j]); + acc[j] = wmma_f16(a_hi, b_hi, acc[j]); + } +} + +constexpr int GU_EPI_STRIDE = 18, GU_EPI_PLANE = 16 * GU_EPI_STRIDE; +constexpr int GU_EPI_BYTES = 8 * GU_EPI_PLANE * 4, D_EPI_BYTES = 8 * 256 * 4; + +/// Gate/up epilogue (every wave; `lds` at least GU_EPI_BYTES, free): per token tile, each wave's 16 x 16 +/// accumulators as plane [token][row] (waves 0-3 the gate rows, 4-7 the up rows), then a thread per (token, half of +/// the 64 features): SwiGLU, H as int8 per 32 features with its scale and the codes' sum (native_w11_kernel's H). +template +__device__ __forceinline__ void gu_epilogue(const v8f (&acc)[BN / 16], uint8_t* lds, int tid, int live_tiles, int nrows, int row0, + int fb, uint8_t* __restrict__ out) { + const int wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + float* base = reinterpret_cast(lds); + float* scratch = base + wave * GU_EPI_PLANE; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + if (j >= live_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) scratch[sub_lane * GU_EPI_STRIDE + 2 * l + half_id] = acc[j][l]; + __syncthreads(); + if (tid < 32) { + const int t = tid >> 1, hh = tid & 1, r = j * 16 + t; + if (r < nrows) { + float hv[32]; + float am = 0.0f; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int ft = 32 * hh + f; + const int idx = (ft >> 4) * GU_EPI_PLANE + t * GU_EPI_STRIDE + (ft & 15); + const float gt = base[idx], up = base[idx + 4 * GU_EPI_PLANE]; + hv[f] = gt / (1.0f + __expf(-gt)) * up; + am = fmaxf(am, fabsf(hv[f])); + } + const float inv = am > 0.0f ? 127.0f / am : 0.0f; + uint8_t* o = out + (size_t) (row0 + r) * H_LD + (size_t) fb * AB; + uint32_t wd[8] = {}; + int csum = 0; +#pragma unroll + for (int f = 0; f < 32; ++f) { + const int c = __float2int_rn(hv[f] * inv); + csum += c; + wd[f >> 2] |= (uint32_t) (uint8_t) (int8_t) c << (8 * (f & 3)); + } + uint4* o4 = reinterpret_cast(o + 32 * hh); + o4[0] = make_uint4(wd[0], wd[1], wd[2], wd[3]); + o4[1] = make_uint4(wd[4], wd[5], wd[6], wd[7]); + *reinterpret_cast(o + 64 + 4 * hh) = am / 127.0f; + *reinterpret_cast(o + 72 + 4 * hh) = (float) csum; + } + } + __syncthreads(); + } +} + +/// Down epilogue (`lds` at least D_EPI_BYTES, free): each wave's 16 x 16 tile through LDS ([token][row]), then 16 +/// consecutive FP32 rows per routed row into dm [routed row][2560]. +template +__device__ __forceinline__ void down_epilogue(const v8f (&acc)[BN / 16], uint8_t* lds, int tid, int live_tiles, int nrows, int row0, + int fb, float* __restrict__ dm) { + const int wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + float* tile = reinterpret_cast(lds) + wave * 256; + const int r0 = fb * ROWS + wave * 16; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) { + if (j >= live_tiles) break; // uniform +#pragma unroll + for (int l = 0; l < 8; ++l) tile[sub_lane * 16 + 2 * l + half_id] = acc[j][l]; + __builtin_amdgcn_wave_barrier(); +#pragma unroll + for (int q = 0; q < 8; ++q) { + const int flat = q * 32 + lane, t = j * 16 + (flat >> 4); + if (t < nrows) dm[(size_t) (row0 + t) * 2560 + r0 + (flat & 15)] = tile[flat]; + } + __builtin_amdgcn_wave_barrier(); + } +} + +} // namespace strata::prefill::fused::f16 diff --git a/src/prefill/moe_f16_kq.cu b/src/prefill/moe_f16_kq.cu index 2634d9c6..824b8cce 100644 --- a/src/prefill/moe_f16_kq.cu +++ b/src/prefill/moe_f16_kq.cu @@ -1,18 +1,12 @@ -// src/prefill/moe_f16_kq.cu - see moe_f16_kq.hpp. gfx11 only (opt-in STRATA_PF_F16_KQ=1). +// src/prefill/moe_f16_kq.cu - see moe_f16_kq.hpp. gfx11 only (opt-in STRATA_PF_F16=1 with STRATA_PF_FUSED_KQ=1). // -// The paired gate/up kernel of gufo's routed experts, on Strata's tables, int8 activations and H: -// - one work item is 64 features of one expert (its 64 gate and 64 up rows, BM = 128) against one 64-row tile of -// fused::group, K = 2560 in 40 stages of 64 values; -// - the weight codes stay packed in LDS (one 32-byte Q4_K nibble group per row and stage) and each wave turns its -// own 16 rows into F16 right after the LDS read: w = q * (d sc) - dmin m as one packed FMA, so the F16 matrix -// core accumulates the whole K in F32 with no per-block epilogue; -// - the activations are native_w11_kernel's int8 blocks, staged in LDS as F16 (a * d_x, one product each), shared -// by every wave; -// - the epilogue applies SwiGLU and writes H as int8 per 32 features (with the codes' sum), the form the existing -// down kernels read. -// Q5_1 down takes the same structure (down_kernel): H staged as F16, the codes and high bits packed in LDS, FP32 -// outputs at the routed rows. The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), -// like STRATA_PF_FUSED_KQ's does from the MMQ path. +// gufo's routed-expert kernels for the K-quants, on Strata's tables, int8 activations and H (the work item, the +// activation staging and the epilogues are moe_f16_common.cuh's): +// - gate/up (Q4_K, Q5_K): the weight codes stay packed in LDS (one 32-byte nibble group per row and stage) and +// each wave turns its own 16 rows into F16 right after the LDS read: w = q * (d sc) - dmin m as one packed FMA; +// - down (Q5_1): a K block's 16 code bytes and its high-bit word in LDS, w = q d + m per wave. +// The output differs from native_w11_kernel's (F16 weights instead of int8 sub-blocks), like STRATA_PF_FUSED_KQ's +// does from the MMQ path. // // Adapted from gufo 97b8645f: src/models/qwen38_flash_next/kernels/rocm/kernels.hip.cpp // (RoutedF16GEMMKernel and its helpers). @@ -35,46 +29,20 @@ // SOFTWARE. #include "moe_f16_kq.hpp" -#include +#include "moe_f16_common.cuh" #include "ggml.h" #include -#include -#include -#include namespace strata::prefill::fused::f16kq { namespace { +using namespace f16; + constexpr int T_Q4_K = GGML_TYPE_Q4_K, T_Q5_K = GGML_TYPE_Q5_K; -constexpr int AB = 80; // activation / H bytes per 64 values: 64 codes, {d0, d1}, {sum0, sum1} -constexpr int K_GU = 2560; // n_embd -constexpr int NS = K_GU / 64; // stages -constexpr int ACT_LD = NS * AB; // bytes per activation row -constexpr int FEAT = 64; // features (gate rows = up rows) per work item -constexpr int NFB = 640 / FEAT; // work items per tile -constexpr int BM = 2 * FEAT; // code rows in LDS: gate 0..63, up 64..127 -constexpr int THREADS = 256; - -#if defined(__HIPCC__) && (defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || \ - defined(__gfx1150__) || defined(__gfx1151__)) -#define STRATA_F16KQ_DEVICE 1 -#else -#define STRATA_F16KQ_DEVICE 0 -#endif - -using v16h = __attribute__((__vector_size__(16 * sizeof(_Float16)))) _Float16; -using v8f = __attribute__((__vector_size__(8 * sizeof(float)))) float; - -__device__ __forceinline__ v8f wmma_f16(v16h a, v16h b, v8f c) { -#if STRATA_F16KQ_DEVICE - return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); -#else - __builtin_trap(); - return c; -#endif -} +constexpr int GU_NS = 2560 / 64, D_NS = 640 / 64; // stages of 64 values +constexpr int FEAT = 64; // features (gate rows = up rows) per gate/up item // Byte i of the 16-byte K-quant block header (d, dmin, scales[12]). __device__ __forceinline__ uint32_t header_byte(const uint4& h, uint32_t i) { @@ -90,7 +58,7 @@ constexpr uint32_t HALF_MAGIC = 0x64646464U; // the high bytes of 1024.0 as F1 // Four code bytes (< 32) to four halves: 1024 + q exactly, minus 1024, then q * scale + bias. __device__ __forceinline__ void codes_to_halves(uint32_t codes, __half2 magic, __half2 scale2, __half2 bias2, __half2& lo, __half2& hi) { -#if STRATA_F16KQ_DEVICE +#if STRATA_F16_DEVICE const uint32_t p0 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x01050004U); const uint32_t p1 = __builtin_amdgcn_perm(codes, HALF_MAGIC, 0x03070206U); lo = __hfma2(__hadd2(__builtin_bit_cast(__half2, p0), magic), scale2, bias2); @@ -100,97 +68,23 @@ __device__ __forceinline__ void codes_to_halves(uint32_t codes, __half2 magic, _ #endif } -// The int8 activation (or H) rows of a work item, staged as F16 per stage: BN rows x 8 chunks of 8 values, chunk -// sub = kb * 4 + quarter, into LDS [sub][row] (stride BN + 1) - the B fragments' layout of the F16 WMMA. A row past -// the item's end is zero. -template struct ActStage { - static constexpr int FETCH = BN * 8 / THREADS, STRIDE = BN + 1, BYTES = 2 * 4 * STRIDE * 16; - const uint8_t* src[FETCH]; - int slot[FETCH], sub[FETCH]; - uint2 codes[FETCH]; - float d[FETCH]; - // rows[t]: the row of item row t in `base` (rows of `ld` bytes), or -1 - __device__ __forceinline__ void init(const uint8_t* base, size_t ld, const int* rows, int tid) { -#pragma unroll - for (int i = 0; i < FETCH; ++i) { - const int chunk = tid + i * THREADS, t = chunk >> 3, c = chunk & 7; - src[i] = rows[t] >= 0 ? base + (size_t) rows[t] * ld : nullptr; - slot[i] = c * STRIDE + t; - sub[i] = c; - } - } - __device__ __forceinline__ void fetch(int s) { -#pragma unroll - for (int i = 0; i < FETCH; ++i) { - if (src[i] != nullptr) { - const uint8_t* p = src[i] + (size_t) s * AB; - codes[i] = *reinterpret_cast(p + 8 * sub[i]); - d[i] = *reinterpret_cast(p + 64 + 4 * (sub[i] >> 2)); - } else { - codes[i] = make_uint2(0u, 0u); - d[i] = 0.0f; - } - } - } - __device__ __forceinline__ void commit(uint4* s_act) const { -#pragma unroll - for (int i = 0; i < FETCH; ++i) { - const uint32_t ws[2] = {codes[i].x, codes[i].y}; - __half2 h[4]; -#pragma unroll - for (int j = 0; j < 4; ++j) { - const uint32_t wd = ws[j >> 1] >> (16 * (j & 1)); - const float lo = (float) (int8_t) (wd & 0xFFu), hi = (float) (int8_t) ((wd >> 8) & 0xFFu); - h[j] = __floats2half2_rn(lo * d[i], hi * d[i]); - } - s_act[slot[i]] = make_uint4(__builtin_bit_cast(uint32_t, h[0]), __builtin_bit_cast(uint32_t, h[1]), - __builtin_bit_cast(uint32_t, h[2]), __builtin_bit_cast(uint32_t, h[3])); - } - } -}; - -// Two F16 WMMAs (K 32) of a wave's 16 weight rows against each live 16-row tile of the staged activations. -template -__device__ __forceinline__ void mma_tiles(v8f (&acc)[BN / 16], v16h a_lo, v16h a_hi, const uint4* s_act, int kb, int sub_lane, - int live_tiles) { - constexpr int STRIDE = ActStage::STRIDE; -#pragma unroll - for (int j = 0; j < BN / 16; ++j) { - asm volatile("" ::: "memory"); // one token tile's fragments live at a time (gufo: hoisting spills) - if (j >= live_tiles) continue; - const uint4* frag = s_act + (kb * 4) * STRIDE + j * 16 + sub_lane; - uint4 bq[4]; -#pragma unroll - for (int q = 0; q < 4; ++q) bq[q] = frag[q * STRIDE]; - v16h b_lo, b_hi; - __builtin_memcpy(&b_lo, &bq[0], 32); - __builtin_memcpy(&b_hi, &bq[2], 32); - acc[j] = wmma_f16(a_lo, b_lo, acc[j]); - acc[j] = wmma_f16(a_hi, b_hi, acc[j]); - } -} - -// BN: tokens per work item, fused::group's 64-row tile or two consecutive tiles of one expert (128) +// Gate/up (Q4_K / Q5_K): code rows 0..63 are the item's gate rows, 64..127 its up rows; a thread pair per row. template __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, const int2* __restrict__ tiles, const int32_t* __restrict__ off, const uint8_t* __restrict__ act, const int32_t* __restrict__ src, uint8_t* __restrict__ out) { -#if STRATA_F16KQ_DEVICE - static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); +#if STRATA_F16_DEVICE constexpr bool Q5K = WT == T_Q5_K; - constexpr int TOK_TILES = BN / 16; constexpr int BLOCK_CHUNKS = Q5K ? 11 : 9; // 16-byte chunks per 256-value block constexpr int CODE_CHUNK = Q5K ? 3 : 1; // the first chunk of qs - // LDS (bytes): codes BM rows x 2 chunks (swizzled); Q5_K's high bits and the (scale, bias) half2 per row and K - // block; the activations [kb][quarter][token][16 B], one slot of padding per quarter plane. The epilogue reuses - // the front for eight 16 x 18 float planes. - constexpr int CODE_BYTES = BM * 2 * 16; - constexpr int HIGH_BYTES = Q5K ? 2 * BM * 4 : 0; - constexpr int SCALE_BYTES = 2 * BM * 4; + // LDS (bytes): codes ROWS x 2 chunks (swizzled); Q5_K's high bits and the (scale, bias) half2 per row and K + // block; the activations. The epilogue reuses the front. + constexpr int CODE_BYTES = ROWS * 2 * 16; + constexpr int HIGH_BYTES = Q5K ? 2 * ROWS * 4 : 0; + constexpr int SCALE_BYTES = 2 * ROWS * 4; constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; - constexpr int EPI_STRIDE = 18, EPI_PLANE = 16 * EPI_STRIDE; - static_assert(8 * EPI_PLANE * 4 <= STAGE_BYTES, "the epilogue planes fit the stage"); + static_assert(GU_EPI_BYTES <= STAGE_BYTES, "the epilogue fits the stage"); __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; __shared__ int srow[BN]; auto* s_codes = reinterpret_cast(lds); @@ -198,192 +92,137 @@ __global__ void __launch_bounds__(THREADS) gate_up_kernel(const Batch b, const N auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); - const int tid = threadIdx.x, wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; const int f_c = tid & 1; // this thread's chunk (and K block) of its weight row const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); - // One work item per block, the grid the batch's bound (gufo's launch: the hardware balances the blocks; the - // NFB items of a tile are consecutive, so they meet its activations in L2) - const int t0 = ts[b.e0], w = blockIdx.x; - if (w >= (ts[b.e1] - t0) * NFB) return; - { - const int2 tl = tiles[t0 + w / NFB]; - const int fb = w % NFB, e = tl.x, row0 = tl.y; - if (BN > kTileRows && ((t0 + w / NFB - ts[e]) & 1)) return; // the second tile of a pair: its first takes it - const int nrows = min(BN, off[e + 1] - row0); - const int live_tok_tiles = (nrows + 15) / 16; - const uint8_t* blob = b.blob[e - b.e0]; - if (tid < BN) srow[tid] = tid < nrows ? src[row0 + tid] : -1; - __syncthreads(); + int fb, e, row0, nrows; + if (!work_item(b, ts, tiles, off, blockIdx.x, fb, e, row0, nrows)) return; + const int live_tiles = (nrows + 15) / 16; + const uint8_t* blob = b.blob[e - b.e0]; + if (tid < BN) srow[tid] = tid < nrows ? src[row0 + tid] : -1; + __syncthreads(); - // Weight fetch: row tid / 2 of the code plane (gate rows, then up rows), chunk f_c. - const uint8_t* f_ptr = blob + ((tid >> 1) >= FEAT ? geo.up_off : 0) + - (size_t) (fb * FEAT + ((tid >> 1) & (FEAT - 1))) * geo.gu_row; - uint4 f_header = make_uint4(0u, 0u, 0u, 0u), f_codes, f_qh[2] = {}; - uint4 code_cache[4]; // the block's four nibble groups, this thread's chunk of each - uint32_t f_high = 0; - int f_sb32 = 0; - ActStage as; - as.init(act, ACT_LD, srow, tid); // the tokens' activation rows + const uint8_t* f_ptr = blob + ((tid >> 1) >= FEAT ? geo.up_off : 0) + (size_t) (fb * FEAT + ((tid >> 1) & (FEAT - 1))) * geo.gu_row; + uint4 f_header = make_uint4(0u, 0u, 0u, 0u), f_codes, f_qh[2] = {}; + uint4 code_cache[4]; // the block's four nibble groups, this thread's chunk of each + uint32_t f_high = 0; + int f_sb32 = 0; + ActStage as; + as.init(act, GU_ACT_LD, srow, tid); // the tokens' activation rows - const auto fetch_stage = [&](int s) { - const int kb0 = 2 * s; - const uint4* blk = reinterpret_cast(f_ptr) + (kb0 / 8) * BLOCK_CHUNKS; - if (kb0 % 8 == 0) { // a new 256-value block every four stages - f_header = blk[0]; + const auto fetch_stage = [&](int s) { + const int kb0 = 2 * s; + const uint4* blk = reinterpret_cast(f_ptr) + (kb0 / 8) * BLOCK_CHUNKS; + if (kb0 % 8 == 0) { // a new 256-value block every four stages + f_header = blk[0]; #pragma unroll - for (int group = 0; group < 4; ++group) code_cache[group] = blk[CODE_CHUNK + group * 2 + f_c]; - if constexpr (Q5K) { - f_qh[0] = blk[1]; - f_qh[1] = blk[2]; - } - } - const int sb32 = (kb0 % 8) + f_c; - { - const int group = sb32 / 2; // uniform across the wave - const uint32_t low = 0u - (group & 1u), high = 0u - ((group >> 1u) & 1u); - const auto select = [](uint32_t a, uint32_t bb, uint32_t mask) { - uint32_t value; - asm("v_cndmask_b32_e64 %0, %1, %2, %3" : "=v"(value) : "v"(a), "v"(bb), "s"(mask)); - return value; - }; - const uint4 &c0 = code_cache[0], &c1 = code_cache[1], &c2 = code_cache[2], &c3 = code_cache[3]; - f_codes = make_uint4(select(select(c0.x, c1.x, low), select(c2.x, c3.x, low), high), - select(select(c0.y, c1.y, low), select(c2.y, c3.y, low), high), - select(select(c0.z, c1.z, low), select(c2.z, c3.z, low), high), - select(select(c0.w, c1.w, low), select(c2.w, c3.w, low), high)); - } - f_sb32 = sb32; + for (int group = 0; group < 4; ++group) code_cache[group] = blk[CODE_CHUNK + group * 2 + f_c]; if constexpr (Q5K) { - const uint32_t qh[8] = {f_qh[0].x, f_qh[0].y, f_qh[0].z, f_qh[0].w, f_qh[1].x, f_qh[1].y, f_qh[1].z, f_qh[1].w}; - uint32_t hb = 0; -#pragma unroll - for (int i = 0; i < 8; ++i) hb |= gather_bit(qh[i], sb32) << (4 * i); - f_high = hb; + f_qh[0] = blk[1]; + f_qh[1] = blk[2]; } - as.fetch(s); - }; - - const auto commit_stage = [&]() { - const int row = tid >> 1; - s_codes[swizzle(row, f_c)] = f_codes; - if constexpr (Q5K) s_high[f_c * BM + row] = f_high; - const int sb32 = f_sb32; - uint32_t sc, mn; - if (sb32 < 4) { - sc = header_byte(f_header, 4 + sb32) & 0x3FU; - mn = header_byte(f_header, 8 + sb32) & 0x3FU; - } else { - sc = (header_byte(f_header, 8 + sb32) & 0x0FU) | ((header_byte(f_header, sb32) >> 6U) << 4U); - mn = (header_byte(f_header, 8 + sb32) >> 4U) | ((header_byte(f_header, 4 + sb32) >> 6U) << 4U); - } - const __half2 dm = __builtin_bit_cast(__half2, f_header.x); - const float scale = __low2float(dm) * (float) sc, offset = __high2float(dm) * (float) mn; - s_scale[f_c * BM + row] = __builtin_bit_cast(uint32_t, __floats2half2_rn(scale, -offset)); - as.commit(s_act); - }; - - v8f acc[TOK_TILES]; -#pragma unroll - for (int j = 0; j < TOK_TILES; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; - - const auto compute_stage = [&]() { - const int row = wave * 16 + sub_lane; // waves 0-3: gate rows, 4-7: the matching up rows - const uint4 raw0 = s_codes[swizzle(row, 0)], raw1 = s_codes[swizzle(row, 1)]; -#pragma unroll - for (int kb = 0; kb < 2; ++kb) { - const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * BM + row]); - const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); - // elements 0-15 of K block 2s + kb are the low (kb = 0) or high (kb = 1) nibbles of chunk 0, 16-31 of chunk 1 - const unsigned shift = 4U * (unsigned) kb; - const uint32_t words[8] = {raw0.x, raw0.y, raw0.z, raw0.w, raw1.x, raw1.y, raw1.z, raw1.w}; - const uint32_t hb = Q5K ? s_high[kb * BM + row] : 0U; - __half2 h[16]; -#pragma unroll - for (int i = 0; i < 8; ++i) { - uint32_t nib = (words[i] >> shift) & 0x0F0F0F0FU; - if constexpr (Q5K) nib |= spread_high_bits((hb >> (4 * i)) & 0xFU); - codes_to_halves(nib, magic, scale2, bias2, h[2 * i], h[2 * i + 1]); - } - v16h a_lo, a_hi; - __builtin_memcpy(&a_lo, &h[0], 32); - __builtin_memcpy(&a_hi, &h[8], 32); - mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tok_tiles); - } - }; - - fetch_stage(0); - for (int s = 0; s < NS; ++s) { - commit_stage(); - __syncthreads(); - if (s + 1 < NS) fetch_stage(s + 1); - compute_stage(); - __syncthreads(); } - - // Epilogue per token tile: each wave's 16 x 16 accumulators as plane [token][row] (gate planes 0-3, up 4-7), - // then a thread per (token, half of the 64 features): SwiGLU, int8 per 32 with the codes' sum. - float* base = reinterpret_cast(lds); - float* scratch = base + wave * EPI_PLANE; -#pragma unroll - for (int j = 0; j < TOK_TILES; ++j) { - if (j >= live_tok_tiles) break; // uniform -#pragma unroll - for (int l = 0; l < 8; ++l) scratch[sub_lane * EPI_STRIDE + 2 * l + half_id] = acc[j][l]; - __syncthreads(); - if (tid < 32) { - const int t = tid >> 1, hh = tid & 1, r = j * 16 + t; - if (r < nrows) { - float hv[32]; - float am = 0.0f; -#pragma unroll - for (int f = 0; f < 32; ++f) { - const int ft = 32 * hh + f; - const int idx = (ft >> 4) * EPI_PLANE + t * EPI_STRIDE + (ft & 15); - const float gt = base[idx], up = base[idx + 4 * EPI_PLANE]; - hv[f] = gt / (1.0f + __expf(-gt)) * up; - am = fmaxf(am, fabsf(hv[f])); - } - const float inv = am > 0.0f ? 127.0f / am : 0.0f; - uint8_t* o = out + (size_t) (row0 + r) * (10 * AB) + (size_t) fb * AB; - uint32_t wd[8] = {}; - int csum = 0; -#pragma unroll - for (int f = 0; f < 32; ++f) { - const int c = __float2int_rn(hv[f] * inv); - csum += c; - wd[f >> 2] |= (uint32_t) (uint8_t) (int8_t) c << (8 * (f & 3)); - } - uint4* o4 = reinterpret_cast(o + 32 * hh); - o4[0] = make_uint4(wd[0], wd[1], wd[2], wd[3]); - o4[1] = make_uint4(wd[4], wd[5], wd[6], wd[7]); - *reinterpret_cast(o + 64 + 4 * hh) = am / 127.0f; - *reinterpret_cast(o + 72 + 4 * hh) = (float) csum; - } - } - __syncthreads(); + const int sb32 = (kb0 % 8) + f_c; + { + const int group = sb32 / 2; // uniform across the wave + const uint32_t low = 0u - (group & 1u), high = 0u - ((group >> 1u) & 1u); + const auto select = [](uint32_t a, uint32_t bb, uint32_t mask) { + uint32_t value; + asm("v_cndmask_b32_e64 %0, %1, %2, %3" : "=v"(value) : "v"(a), "v"(bb), "s"(mask)); + return value; + }; + const uint4 &c0 = code_cache[0], &c1 = code_cache[1], &c2 = code_cache[2], &c3 = code_cache[3]; + f_codes = make_uint4(select(select(c0.x, c1.x, low), select(c2.x, c3.x, low), high), + select(select(c0.y, c1.y, low), select(c2.y, c3.y, low), high), + select(select(c0.z, c1.z, low), select(c2.z, c3.z, low), high), + select(select(c0.w, c1.w, low), select(c2.w, c3.w, low), high)); } + f_sb32 = sb32; + if constexpr (Q5K) { + const uint32_t qh[8] = {f_qh[0].x, f_qh[0].y, f_qh[0].z, f_qh[0].w, f_qh[1].x, f_qh[1].y, f_qh[1].z, f_qh[1].w}; + uint32_t hb = 0; +#pragma unroll + for (int i = 0; i < 8; ++i) hb |= gather_bit(qh[i], sb32) << (4 * i); + f_high = hb; + } + as.fetch(s); + }; + + const auto commit_stage = [&]() { + const int row = tid >> 1; + s_codes[swizzle(row, f_c)] = f_codes; + if constexpr (Q5K) s_high[f_c * ROWS + row] = f_high; + const int sb32 = f_sb32; + uint32_t sc, mn; + if (sb32 < 4) { + sc = header_byte(f_header, 4 + sb32) & 0x3FU; + mn = header_byte(f_header, 8 + sb32) & 0x3FU; + } else { + sc = (header_byte(f_header, 8 + sb32) & 0x0FU) | ((header_byte(f_header, sb32) >> 6U) << 4U); + mn = (header_byte(f_header, 8 + sb32) >> 4U) | ((header_byte(f_header, 4 + sb32) >> 6U) << 4U); + } + const __half2 dm = __builtin_bit_cast(__half2, f_header.x); + const float scale = __low2float(dm) * (float) sc, offset = __high2float(dm) * (float) mn; + s_scale[f_c * ROWS + row] = __builtin_bit_cast(uint32_t, __floats2half2_rn(scale, -offset)); + as.commit(s_act); + }; + + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; // waves 0-3: gate rows, 4-7: the matching up rows + const uint4 raw0 = s_codes[swizzle(row, 0)], raw1 = s_codes[swizzle(row, 1)]; +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * ROWS + row]); + const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); + // elements 0-15 of K block 2s + kb are the low (kb = 0) or high (kb = 1) nibbles of chunk 0, 16-31 of chunk 1 + const unsigned shift = 4U * (unsigned) kb; + const uint32_t words[8] = {raw0.x, raw0.y, raw0.z, raw0.w, raw1.x, raw1.y, raw1.z, raw1.w}; + const uint32_t hb = Q5K ? s_high[kb * ROWS + row] : 0U; + __half2 h[16]; +#pragma unroll + for (int i = 0; i < 8; ++i) { + uint32_t nib = (words[i] >> shift) & 0x0F0F0F0FU; + if constexpr (Q5K) nib |= spread_high_bits((hb >> (4 * i)) & 0xFU); + codes_to_halves(nib, magic, scale2, bias2, h[2 * i], h[2 * i + 1]); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &h[0], 32); + __builtin_memcpy(&a_hi, &h[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + + fetch_stage(0); + for (int s = 0; s < GU_NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < GU_NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); } + gu_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, out); #else (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) act; (void) src; (void) out; __builtin_trap(); #endif } -// Q5_1 down: 128 of the 2560 output rows (DNFB items per tile) against a tile's (or pair's) H rows, K = 640 in 10 -// stages; the products are the routed rows' FP32 outputs in `dm` (native_w11_kernel's). gufo's -// RoutedF16GEMMKernel: a K block's 16 code bytes and its high-bit word in LDS, w = q d + m per wave. -constexpr int D_ROWS = 128, DNFB = 2560 / D_ROWS, D_NS = 640 / 64, H_LD = D_NS * AB; +// Q5_1 down: 128 of the 2560 output rows against a tile's (or pair's) H rows, K = 640 in 10 stages; the routed rows' +// FP32 outputs in `dm` (native_w11_kernel's). template __global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const NativeGeom geo, const int32_t* __restrict__ ts, const int2* __restrict__ tiles, const int32_t* __restrict__ off, const uint8_t* __restrict__ h, float* __restrict__ dm) { -#if STRATA_F16KQ_DEVICE - static_assert(BN == kTileRows || BN == 2 * kTileRows, "one tile or a pair"); - constexpr int CODE_BYTES = D_ROWS * 2 * 16, HIGH_BYTES = 2 * D_ROWS * 4, SCALE_BYTES = 2 * D_ROWS * 4; +#if STRATA_F16_DEVICE + constexpr int CODE_BYTES = ROWS * 2 * 16, HIGH_BYTES = 2 * ROWS * 4, SCALE_BYTES = 2 * ROWS * 4; constexpr int STAGE_BYTES = CODE_BYTES + HIGH_BYTES + SCALE_BYTES + ActStage::BYTES; - static_assert(8 * 256 * 4 <= STAGE_BYTES, "the epilogue's 16 x 16 tile per wave fits the stage"); + static_assert(D_EPI_BYTES <= STAGE_BYTES, "the epilogue fits the stage"); __shared__ __attribute__((aligned(16))) uint8_t lds[STAGE_BYTES]; __shared__ int srow[BN]; auto* s_codes = reinterpret_cast(lds); @@ -391,23 +230,18 @@ __global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const Nati auto* s_scale = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES); auto* s_act = reinterpret_cast(lds + CODE_BYTES + HIGH_BYTES + SCALE_BYTES); - const int tid = threadIdx.x, wave = tid >> 5, lane = tid & 31, sub_lane = lane & 15, half_id = lane >> 4; + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; const int f_c = tid & 1; // this thread's K block of its weight row const auto swizzle = [](int row, int c) { return row * 2 + (c ^ ((row >> 2) & 1)); }; const __half2 magic = __floats2half2_rn(-1024.0f, -1024.0f); - const int t0 = ts[b.e0], w = blockIdx.x; - if (w >= (ts[b.e1] - t0) * DNFB) return; - const int2 tl = tiles[t0 + w / DNFB]; - const int fb = w % DNFB, e = tl.x, row0 = tl.y; - if (BN > kTileRows && ((t0 + w / DNFB - ts[e]) & 1)) return; // the second tile of a pair: its first takes it - const int nrows = min(BN, off[e + 1] - row0); + int fb, e, row0, nrows; + if (!work_item(b, ts, tiles, off, blockIdx.x, fb, e, row0, nrows)) return; const int live_tiles = (nrows + 15) / 16; if (tid < BN) srow[tid] = tid < nrows ? row0 + tid : -1; // H is indexed by the routed row __syncthreads(); - const uint2* f_ptr = reinterpret_cast(b.blob[e - b.e0] + geo.down_off + - (size_t) (fb * D_ROWS + (tid >> 1)) * geo.d_row); + const uint2* f_ptr = reinterpret_cast(b.blob[e - b.e0] + geo.down_off + (size_t) (fb * ROWS + (tid >> 1)) * geo.d_row); uint4 f_codes; uint32_t f_high = 0, f_dm = 0; ActStage as; @@ -423,8 +257,8 @@ __global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const Nati const auto commit_stage = [&]() { const int row = tid >> 1; s_codes[swizzle(row, f_c)] = f_codes; - s_high[f_c * D_ROWS + row] = f_high; - s_scale[f_c * D_ROWS + row] = f_dm; // the half2 (d, m): w = q d + m + s_high[f_c * ROWS + row] = f_high; + s_scale[f_c * ROWS + row] = f_dm; // the half2 (d, m): w = q d + m as.commit(s_act); }; v8f acc[BN / 16]; @@ -435,11 +269,11 @@ __global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const Nati const uint4 raw[2] = {s_codes[swizzle(row, 0)], s_codes[swizzle(row, 1)]}; #pragma unroll for (int kb = 0; kb < 2; ++kb) { - const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * D_ROWS + row]); + const __half2 sb = __builtin_bit_cast(__half2, s_scale[kb * ROWS + row]); const __half2 scale2 = __low2half2(sb), bias2 = __high2half2(sb); // elements 0-15 are the low nibbles of the 16 code bytes, 16-31 the high, plus bit j of the high-bit word const uint32_t words[4] = {raw[kb].x, raw[kb].y, raw[kb].z, raw[kb].w}; - const uint32_t hb = s_high[kb * D_ROWS + row]; + const uint32_t hb = s_high[kb * ROWS + row]; __half2 hh[16]; #pragma unroll for (int i = 0; i < 4; ++i) { @@ -462,75 +296,39 @@ __global__ void __launch_bounds__(THREADS) down_kernel(const Batch b, const Nati compute_stage(); __syncthreads(); } - // Each wave's 16 x 16 tile through LDS ([token][row]), then 16 consecutive FP32 rows per routed row. - float* tile = reinterpret_cast(lds) + wave * 256; - const int r0 = fb * D_ROWS + wave * 16; -#pragma unroll - for (int j = 0; j < BN / 16; ++j) { - if (j >= live_tiles) break; // uniform -#pragma unroll - for (int l = 0; l < 8; ++l) tile[sub_lane * 16 + 2 * l + half_id] = acc[j][l]; - __builtin_amdgcn_wave_barrier(); -#pragma unroll - for (int q = 0; q < 8; ++q) { - const int flat = q * 32 + lane, t = j * 16 + (flat >> 4); - if (t < nrows) dm[(size_t) (row0 + t) * 2560 + r0 + (flat & 15)] = tile[flat]; - } - __builtin_amdgcn_wave_barrier(); - } + down_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, dm); #else (void) b; (void) geo; (void) ts; (void) tiles; (void) off; (void) h; (void) dm; __builtin_trap(); #endif } -// Two tiles a work item when an expert has a tile's rows or more on average. gfx1151, Q4_K, top 10 over 512 experts, -// one 128-expert launch, ms (64 / 128): 1024 tokens 1.22 / 1.28, 2048 1.51 / 1.64, 4096 2.73 / 2.48, 8192 4.76 / 4.59, -// 16384 9.19 / 8.46; Q5_1 down 2048 1.02 / 1.04, 4096 1.61 / 1.48, 16384 5.29 / 4.83. STRATA_PF_F16_KQ_BN=64|128 forces -// one. -int pick_bn(int64_t n, int n_expert) { - static const int forced = [] { - const char* v = std::getenv("STRATA_PF_F16_KQ_BN"); - const int t = v ? std::atoi(v) : 0; - return t == 64 || t == 128 ? t : 0; - }(); - if (forced) return forced; - return (double) n / std::max(n_expert, 1) >= kTileRows ? 2 * kTileRows : kTileRows; -} - -template -void launch(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t work_bound, - const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { - const unsigned grid = (unsigned) std::max(1, work_bound * NFB); - if (g.gu_type == T_Q5_K) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); - else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); -} - } // namespace -bool requested() { - static const bool on = [] { - const char* v = std::getenv("STRATA_PF_F16_KQ"); - return v != nullptr && v[0] == '1'; - }(); - return on; -} - bool covers(int gu_type) { return gu_type == T_Q4_K || gu_type == T_Q5_K; } bool covers_down(int d_type) { return d_type == GGML_TYPE_Q5_1; } +void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, + int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { + // one block per work item, the grid the batch's bound (gufo's launch: the hardware balances the blocks; the items + // of a tile are consecutive, so they meet its activations in L2) + const unsigned grid = (unsigned) std::max(1, work_bound * GU_NFB); + const bool q5k = g.gu_type == T_Q5_K; + if (pick_bn(n, n_expert) == 2 * kTileRows) { + if (q5k) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + } else { + if (q5k) gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + else gate_up_kernel<<>>(b, g, ts, tiles, off, act, src, out); + } +} + void down(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, int n_expert, int64_t work_bound, const uint8_t* h, float* dm, cudaStream_t s) { - const unsigned grid = (unsigned) std::max(1, work_bound * DNFB); + const unsigned grid = (unsigned) std::max(1, work_bound * D_NFB); if (pick_bn(n, n_expert) == 2 * kTileRows) down_kernel<2 * kTileRows><<>>(b, g, ts, tiles, off, h, dm); else down_kernel<<>>(b, g, ts, tiles, off, h, dm); } -void gate_up(const Batch& b, const NativeGeom& g, const int32_t* ts, const int2* tiles, const int32_t* off, int64_t n, - int n_expert, int64_t work_bound, const uint8_t* act, const int32_t* src, uint8_t* out, cudaStream_t s) { - if (pick_bn(n, n_expert) == 2 * kTileRows) launch<2 * kTileRows>(b, g, ts, tiles, off, work_bound, act, src, out, s); - else launch(b, g, ts, tiles, off, work_bound, act, src, out, s); -} - } // namespace strata::prefill::fused::f16kq diff --git a/src/prefill/moe_f16_kq.hpp b/src/prefill/moe_f16_kq.hpp index 28260d8e..c7f80eb1 100644 --- a/src/prefill/moe_f16_kq.hpp +++ b/src/prefill/moe_f16_kq.hpp @@ -1,4 +1,5 @@ -// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts on the F16 matrix cores (moe_f16_kq.cu). +// src/prefill/moe_f16_kq.hpp - gfx11: the K-quant prompt experts on the F16 matrix cores (moe_f16_kq.cu; the switch, +// STRATA_PF_F16=1 with STRATA_PF_FUSED_KQ=1, is moe_f16_common.cuh's). // Internal to moe_fused_iq.cu, which owns the native experts' tables and launches. #pragma once @@ -11,9 +12,6 @@ namespace strata::prefill::fused::f16kq { -/// STRATA_PF_F16_KQ=1 (on top of STRATA_PF_FUSED=1 and STRATA_PF_FUSED_KQ=1): Q4_K / Q5_K gate/up and Q5_1 down -/// take these kernels. -bool requested(); /// The gate/up type has a kernel here (and this build has gfx11 device code). bool covers(int gu_type); diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index 46f8a9a9..f37de7de 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -23,6 +23,7 @@ #include "strata/kernels/gfx_arch.hpp" #if defined(__HIPCC__) +#include "moe_f16_common.cuh" #include "moe_f16_kq.hpp" #endif @@ -978,6 +979,133 @@ native_w11_kernel(const Batch b, const NativeGeom geo, const Tables tb, const ui __builtin_trap(); #endif } + +// STRATA_PF_F16=1 (gfx11): the other native formats on the F16 matrix cores - moe_f16_common.cuh's work item, +// staged activations and epilogues. load_unit / convert decode each sub-block once into the weight tile in LDS (int8 +// codes, the scales as half2), and each wave turns its own 16 rows into F16 before its products. Gate/up rows 0..63 +// are the item's gate rows, 64..127 its up rows; down rows are output rows. The output differs from +// native_w11_kernel's (F16 products instead of int8 dots with float scales). +// gfx1151, IQ3_S / IQ4_NL, 16384 tokens x top 10 over 512 experts, one 128-expert launch (ms, native_w11_kernel -> +// this): gate/up 11.65 -> 9.87, down 6.11 -> 4.71; weights decoded to F16 in LDS (18 KB a block) were 9.83 and 5.71. +template +__global__ void __launch_bounds__(f16::THREADS) +native_f16_kernel(const Batch b, const NativeGeom geo, const Tables tb, const uint8_t* __restrict__ act, + const int32_t* __restrict__ src, uint8_t* __restrict__ out, float* __restrict__ dm) { +#if STRATA_F16_DEVICE + // (moe_fused_iq.cu has its own THREADS and AB: the f16 names are qualified where they collide) + using namespace f16; + constexpr int NS = (GU ? GU_ROWS_K : D_ROWS_K) / 64; // 64-value stages along K + constexpr int NFB = GU ? GU_NFB : D_NFB; + constexpr int RW = raw_words(WT); + constexpr int BS = block_bytes(WT); + constexpr bool K16 = per16(WT); + constexpr int GB = grid_bytes(WT) > 0 ? grid_bytes(WT) : 16; + constexpr int SGN = (WT == T_IQ2_XXS || WT == T_IQ2_XS || WT == T_IQ2_S || WT == T_IQ3_XXS || WT == T_IQ3_S) + ? sign_entries(WT) : 1; + constexpr int WLD8 = 80; // bytes per weight row: 64 int8 codes + 16 (rows 80 bytes apart spread a fragment read) + constexpr int W_BYTES = ROWS * WLD8 + 2 * ROWS * 4; // the codes, then the (s0, s1) half2 per row and sub-block + constexpr int STAGE_BYTES = W_BYTES + ActStage::BYTES; + static_assert(GU_EPI_BYTES <= STAGE_BYTES && D_EPI_BYTES <= STAGE_BYTES, "the epilogues fit the stage"); + __shared__ __align__(16) uint8_t lds[STAGE_BYTES]; + __shared__ __align__(16) uint8_t sgrid[GB]; + __shared__ __align__(16) uint4 ssign[SGN]; + __shared__ int srow[BN]; + uint8_t* s_w = lds; + auto* s_sc = reinterpret_cast(lds + ROWS * WLD8); + auto* s_act = reinterpret_cast(lds + W_BYTES); + const int tid = threadIdx.x, wave = tid >> 5, sub_lane = tid & 15; + + int fb, e, row0, nrows; + if (!work_item(b, tb.ts, tb.tiles, tb.off, blockIdx.x, fb, e, row0, nrows)) return; + if constexpr (grid_bytes(WT) > 0) { + const uint32_t* gs = (const uint32_t*) grid_src(); + for (int i = tid; i < grid_bytes(WT) / 4; i += f16::THREADS) ((uint32_t*) sgrid)[i] = gs[i]; + } + if constexpr (SGN > 1) { + for (int i = tid; i < SGN; i += f16::THREADS) ssign[i] = sign_entry(i, SGN == 128); + } + uint32_t kv[4] = {0, 0, 0, 0}; + if constexpr (WT == T_IQ4_XS || WT == T_IQ4_NL) { +#pragma unroll + for (int k = 0; k < 16; ++k) kv[k >> 2] |= (uint32_t) (uint8_t) kvalues_iq4nl[k] << (8 * (k & 3)); + } + const int live_tiles = (nrows + 15) / 16; + const uint8_t* blob = b.blob[e - b.e0]; + if (tid < BN) srow[tid] = tid < nrows ? (GU ? src[row0 + tid] : row0 + tid) : -1; // tokens; H by routed row + __syncthreads(); + + const int ur = tid >> 1, uj = tid & 1; // this thread's decode unit: weight-tile row ur, sub-block uj of a stage + const uint8_t* wrow = GU ? blob + (ur >= 64 ? geo.up_off : 0) + (size_t) (fb * 64 + (ur & 63)) * geo.gu_row + : blob + geo.down_off + (size_t) (fb * ROWS + ur) * geo.d_row; + const auto unit = [&](int s) -> const uint8_t* { + if (GU) return wrow + (s >> 2) * BS; + return (WT == T_IQ4_NL || WT == T_Q8_0) ? wrow + (2 * s + uj) * BS : wrow + s * BS; + }; + const auto sub = [&](int s) { return GU ? 2 * (s & 3) + uj : uj; }; + uint32_t raw[RW]; + ActStage as; + as.init(act, GU ? GU_ACT_LD : H_LD, srow, tid); + const auto fetch_stage = [&](int s) { + load_unit(unit(s), sub(s), raw); + as.fetch(s); + }; + // the sub-block as int8 codes and its scales into the weight tile + const auto commit_stage = [&]() { + uint32_t q[8]; + float s0, s1; + convert(raw, sgrid, kv, q, s0, s1, ssign); + uint4* d = reinterpret_cast(s_w + ur * WLD8 + 32 * uj); + d[0] = make_uint4(q[0], q[1], q[2], q[3]); + d[1] = make_uint4(q[4], q[5], q[6], q[7]); + s_sc[uj * ROWS + ur] = __builtin_bit_cast(uint32_t, __floats2half2_rn(s0, K16 ? s1 : s0)); + as.commit(s_act); + }; + v8f acc[BN / 16]; +#pragma unroll + for (int j = 0; j < BN / 16; ++j) acc[j] = v8f{0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; + // int8 codes to F16 per wave (gufo's Q8_0 decode): the sign bit flipped carries q + 128, a byte permute makes it + // the mantissa of 1024 (exact), minus 1152 is q, then one packed multiply by the sub-block's scale + const __half2 magic = __floats2half2_rn(-1152.0f, -1152.0f), zero2 = __floats2half2_rn(0.0f, 0.0f); + const auto compute_stage = [&]() { + const int row = wave * 16 + sub_lane; + const uint4* wp = reinterpret_cast(s_w + row * WLD8); +#pragma unroll + for (int kb = 0; kb < 2; ++kb) { + const uint4 c0 = wp[2 * kb], c1 = wp[2 * kb + 1]; + const __half2 sc = __builtin_bit_cast(__half2, s_sc[kb * ROWS + row]); + const __half2 sc0 = __low2half2(sc), sc1 = __high2half2(sc); + const uint32_t words[8] = {c0.x, c0.y, c0.z, c0.w, c1.x, c1.y, c1.z, c1.w}; + uint32_t hw[16]; +#pragma unroll + for (int i = 0; i < 8; ++i) { // values 4i .. 4i + 3 (s0: values 0-15, s1: 16-31) + const uint32_t c = words[i] ^ 0x80808080u; + const uint32_t p0 = __builtin_amdgcn_perm(c, 0x64646464u, 0x01050004u); + const uint32_t p1 = __builtin_amdgcn_perm(c, 0x64646464u, 0x03070206u); + const __half2 s2 = i < 4 ? sc0 : sc1; + hw[2 * i] = __builtin_bit_cast(uint32_t, __hfma2(__hadd2(__builtin_bit_cast(__half2, p0), magic), s2, zero2)); + hw[2 * i + 1] = __builtin_bit_cast(uint32_t, __hfma2(__hadd2(__builtin_bit_cast(__half2, p1), magic), s2, zero2)); + } + v16h a_lo, a_hi; + __builtin_memcpy(&a_lo, &hw[0], 32); + __builtin_memcpy(&a_hi, &hw[8], 32); + mma_tiles(acc, a_lo, a_hi, s_act, kb, sub_lane, live_tiles); + } + }; + fetch_stage(0); + for (int s = 0; s < NS; ++s) { + commit_stage(); + __syncthreads(); + if (s + 1 < NS) fetch_stage(s + 1); + compute_stage(); + __syncthreads(); + } + if constexpr (GU) gu_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, out); + else down_epilogue(acc, lds, tid, live_tiles, nrows, row0, fb, dm); +#else + (void) b; (void) geo; (void) tb; (void) act; (void) src; (void) out; (void) dm; + __builtin_trap(); +#endif +} #endif // __HIPCC__ unsigned blocks(int64_t n, int per) { return (unsigned) ((n + per - 1) / per); } @@ -1096,6 +1224,11 @@ bool kq_on() { }(); return on; } +// STRATA_PF_F16=1 (gfx11): the formats native_f16_kernel takes (the K-quants are moe_f16_kq.cu's) +bool f16_gu(int t) { + return t == T_IQ2_XXS || t == T_IQ2_XS || t == T_IQ2_S || t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS; +} +bool f16_d(int t) { return t == T_Q2_0 || t == T_IQ4_NL || t == T_Q8_0; } bool gu_covered(int t) { return t == T_IQ2_XXS || t == T_IQ2_XS || t == T_IQ2_S || t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS #if defined(__HIPCC__) @@ -1204,9 +1337,28 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const uint8_t* xa8 = (const uint8_t*) xa; uint8_t* ha8 = (uint8_t*) ha; #define STRATA_NW_GU(T) do { if (occ_gu) native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); else native_w11_kernel<<>>(b, g, tb, xa8, src, ha8, nullptr); } while (0) - // STRATA_PF_F16_KQ=1: the K-quant gate/up and Q5_1 down on gfx11's F16 matrix cores (moe_f16_kq.cu; gfx12's - // WMMA layout differs, so it keeps the int8 kernels) - if (!d.w12 && f16kq::requested() && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); + // STRATA_PF_F16=1: gfx11's F16 matrix cores - the K-quants' kernels (moe_f16_kq.cu) and native_f16_kernel for + // f16_gu / f16_d (gfx12's WMMA layout differs, so it keeps the int8 kernels) + const bool f16 = !d.w12 && f16::requested(); + const bool f16_wide = f16::pick_bn(n, n_expert) == 2 * kTileRows; +#define STRATA_F16_LAUNCH(T, GU, NFB, ACT, OUT, DM) do { \ + const unsigned grid_f = (unsigned) std::max(1, tiles * (NFB)); \ + if (f16_wide) native_f16_kernel<<>>(b, g, tb, ACT, src, OUT, DM); \ + else native_f16_kernel<<>>(b, g, tb, ACT, src, OUT, DM); \ +} while (0) + if (f16 && f16kq::covers(g.gu_type)) f16kq::gate_up(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, xa8, src, ha8, s); + else if (f16 && f16_gu(g.gu_type)) { +#define STRATA_F16_GU(T) STRATA_F16_LAUNCH(T, true, f16::GU_NFB, xa8, ha8, nullptr) + switch (g.gu_type) { + case T_IQ2_XXS: STRATA_F16_GU(T_IQ2_XXS); break; + case T_IQ2_XS: STRATA_F16_GU(T_IQ2_XS); break; + case T_IQ2_S: STRATA_F16_GU(T_IQ2_S); break; + case T_IQ3_XXS: STRATA_F16_GU(T_IQ3_XXS); break; + case T_IQ3_S: STRATA_F16_GU(T_IQ3_S); break; + default: STRATA_F16_GU(T_IQ4_XS); break; + } +#undef STRATA_F16_GU + } else switch (g.gu_type) { case T_IQ2_XXS: STRATA_NW_GU(T_IQ2_XXS); break; case T_IQ2_XS: STRATA_NW_GU(T_IQ2_XS); break; @@ -1219,12 +1371,18 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n } #undef STRATA_NW_GU #define STRATA_NW_D(T) do { if (occ_d) native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); else native_w11_kernel<<>>(b, g, tb, ha8, src, nullptr, dm); } while (0) - if (!d.w12 && f16kq::requested() && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); + if (f16 && f16kq::covers_down(g.d_type)) f16kq::down(b, g, tb.ts, tb.tiles, tb.off, n, n_expert, tiles, ha8, dm, s); + else if (f16 && f16_d(g.d_type)) { + if (g.d_type == T_Q2_0) STRATA_F16_LAUNCH(T_Q2_0, false, f16::D_NFB, ha8, nullptr, dm); + else if (g.d_type == T_Q8_0) STRATA_F16_LAUNCH(T_Q8_0, false, f16::D_NFB, ha8, nullptr, dm); + else STRATA_F16_LAUNCH(T_IQ4_NL, false, f16::D_NFB, ha8, nullptr, dm); + } else if (g.d_type == T_Q2_0) STRATA_NW_D(T_Q2_0); else if (g.d_type == T_Q5_1) STRATA_NW_D(T_Q5_1); else if (g.d_type == T_Q8_0) STRATA_NW_D(T_Q8_0); else STRATA_NW_D(T_IQ4_NL); #undef STRATA_NW_D +#undef STRATA_F16_LAUNCH ck(cudaGetLastError(), "experts_native"); return; } diff --git a/tests/cuda/prefill_fused_iq_test.cpp b/tests/cuda/prefill_fused_iq_test.cpp index 6af2ae97..af6099c1 100644 --- a/tests/cuda/prefill_fused_iq_test.cpp +++ b/tests/cuda/prefill_fused_iq_test.cpp @@ -78,6 +78,12 @@ struct Geo { }; // random blocks with a sane fp16 scale `d` at each block's start (every format here begins with it): scales chosen so +// STRATA_PF_F16=1: the covered formats run on F16 weights (moe_f16_kq.cu, native_f16_kernel), not the int8 kernels +bool f16_on() { + const char* v = std::getenv("STRATA_PF_F16"); + return v != nullptr && v[0] == '1'; +} + // that the weights' typical size is that of a 2-3 bit expert (a few hundredths) void fill_matrix(uint8_t* m, ggml_type t, int64_t rows, int64_t cols, std::mt19937& rng) { const size_t bs = ggml_type_size(t), nb = (size_t) rows * (size_t) (cols / ggml_blck_size(t)); @@ -397,11 +403,9 @@ void reference_part(const Pair& p, cudaStream_t s) { const Err e2 = compare(y_f, frow, ref2, pair, (size_t) rows); std::printf(" fused vs the int8-rounded model (same activation / H rounding, double sums): rel RMS %.3e worst %.3e\n", e2.rms, e2.worst); - // STRATA_PF_F16_KQ=1: the K-quant gate/up runs on F16 weights (moe_f16_kq.cu), so H's int8 rounding meets values - // a few F16 ulps from the int8 model's; the FP32 reference checks below stay as they are - const char* f16e = std::getenv("STRATA_PF_F16_KQ"); - const bool f16 = f16e != nullptr && f16e[0] == '1' && (p.gu == GGML_TYPE_Q4_K || p.gu == GGML_TYPE_Q5_K); - if (e2.rms > (f16 ? 5e-3 : 2e-3) || e2.worst > 3e-2) + // STRATA_PF_F16=1: H's int8 rounding meets values a few F16 ulps from the int8 model's (f16_on); the FP32 reference + // checks below stay as they are + if (e2.rms > (f16_on() ? 5e-3 : 2e-3) || e2.worst > 3e-2) throw std::runtime_error(std::string(p.name) + ": the fused path differs from its own arithmetic's model"); if (mq) std::printf(" MMQ vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", em.rms, em.worst); std::printf(" fused vs FP32 reference: rel RMS %.3e worst row max rel %.3e\n", ef.rms, ef.worst); @@ -631,7 +635,8 @@ void timing_part(const Pair& p, int T, cudaStream_t s) { cudaEventDestroy(b); delete mbp; // the two int8 paths at the real shape, every tile of the layer: R9700 rel RMS 1.3-1.9e-4, worst row 2.9e-3-8.3e-3 - if (mq && !no_mmq && (efm.rms > 1e-3 || efm.worst > 2e-2)) + // (STRATA_PF_F16=1: F16 products against MMQ's int8, gfx1151 rel RMS 2.5-2.7e-3, worst row 6.4e-3-8.8e-3) + if (mq && !no_mmq && (efm.rms > (f16_on() ? 5e-3 : 1e-3) || efm.worst > 2e-2)) throw std::runtime_error(std::string(p.name) + ": the paths disagree at the real shape"); } } // namespace From 0c2608ae97eeff6a0dfc38e4b3275aadfd5f1264 Mon Sep 17 00:00:00 2001 From: libratechw Date: Sun, 11 Oct 2026 18:41:58 +0900 Subject: [PATCH 08/28] prefill: STRATA_PF_F16=1 takes Q8_0 down without STRATA_PF_FUSED_KQ on gfx11 Q8_0 has no minimum term and the F16 kernel's output already differs from the int8 kernels', so the KQ opt-in is not needed for it. UD-IQ4_XS has five Q8_0-down layers (4 IQ3_S / Q8_0, 1 IQ4_XS / Q8_0): they left the fused path for MMQ, and since fused_ring() asks every layer, the pack kept MMQ's buffers. d_covered_on() is the one test, for native_supported() and experts_native(); gfx12 keeps d_covered(). UD-IQ4_XS, gfx1151, 3 interleaved rounds, prompt tok/s (v0.1.42 / 65d809c6 with STRATA_PF_F16=1 / this): 4K 926.6 / 992.2 / 1054.8, 32K 1257.4 / 1364.6 / 1397.1, 128K 1202.0 / 1309.4 / 1333.6. --- src/prefill/moe_fused_iq.cu | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index f37de7de..637f0ec3 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -1243,6 +1243,16 @@ bool d_covered(int t) { #endif ; } +// d_covered on this device: STRATA_PF_F16=1 also takes Q8_0 down on gfx11 without STRATA_PF_FUSED_KQ - the F16 kernel +// has no minimum term, and its output already differs from the int8 kernels' (UD-IQ4_XS: the five Q8_0-down layers +// would otherwise leave the fused path for MMQ). +bool d_covered_on(int t, const DevInfo& d) { +#if defined(__HIPCC__) + if (t == T_Q8_0 && !d.w12 && f16::requested()) return true; +#endif + (void) d; + return d_covered(t); +} template void launch(int ww, unsigned grid, const Batch& b, const NativeGeom& g, const Tables& tb, const void* act, @@ -1284,14 +1294,15 @@ bool native_supported(int gu_type, int d_type) { const char* v = std::getenv("STRATA_PF_FUSED"); return v == nullptr || v[0] == '\0' ? -1 : (v[0] == '1' ? 1 : 0); }(); - if (off || env == 0 || !gu_covered(gu_type) || !d_covered(d_type)) return false; + if (off || env == 0 || !gu_covered(gu_type)) return false; #if !defined(__HIPCC__) if (env < 0) return false; // the default is gfx12 (HIP) only #endif if (env < 0 && gu_type != T_IQ3_S && gu_type != T_IQ3_XXS) return false; // default: only these two const DevInfo& d = dev_info(); - if (env < 0) return d.ok && d.w12; - return d.ok && (requested() || d.w12); + if (!d.ok || !d_covered_on(d_type, d)) return false; + if (env < 0) return d.w12; + return requested() || d.w12; } void quantize_act_native(const float* x, int64_t rows, int64_t cols, void* xa, void* stream) { @@ -1305,7 +1316,7 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n const int32_t* src, void* ha, float* dm, void* stream) { if (b.e1 <= b.e0 || n <= 0) return; const DevInfo& d = dev_info(); - if (!d.ok || !gu_covered(g.gu_type) || !d_covered(g.d_type)) { + if (!d.ok || !gu_covered(g.gu_type) || !d_covered_on(g.d_type, d)) { std::fprintf(stderr, "prefill fused experts (native): types %d / %d are not covered here\n", g.gu_type, g.d_type); std::exit(1); } From ed160b461aee82a3f6fb3b0477e3e6ce63b767db Mon Sep 17 00:00:00 2001 From: libratechw Date: Mon, 12 Oct 2026 01:18:40 +0900 Subject: [PATCH 09/28] tests: hip_prefill_fused_iq also runs with STRATA_PF_F16=1 STRATA_PF_F16_KQ=1 --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d695af19..f17db220 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1590,6 +1590,9 @@ if(STRATA_NATIVE_EXPERTS) target_link_libraries(hip_prefill_fused_iq PRIVATE strata_mmq ggml-base strata_hip_runtime) add_test(NAME hip_prefill_fused_iq COMMAND hip_prefill_fused_iq) set_tests_properties(hip_prefill_fused_iq PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600) + # the same binary on F16 weights (gfx11: the covered formats take moe_f16_kq.cu / native_f16_kernel; elsewhere it is the default run again) + add_test(NAME hip_prefill_fused_iq_f16 COMMAND hip_prefill_fused_iq) + set_tests_properties(hip_prefill_fused_iq_f16 PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 600 ENVIRONMENT "STRATA_PF_F16=1;STRATA_PF_F16_KQ=1") list(APPEND _strata_hip_tests hip_prefill_fused_iq) # Numerical diagnostic: synthetic layouts by default, optional first-expert IQ3_XXS/IQ4_NL check with a pack. From feeb8dc808f8c53182decc0a2a91dcc6ef63fc96 Mon Sep 17 00:00:00 2001 From: libratechw Date: Mon, 12 Oct 2026 01:55:07 +0900 Subject: [PATCH 10/28] docs: STRATA_PF_F16=1 on gfx1151 (what it covers, the layer times, first-token KL) --- docs/STRIX_HALO.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index f01875eb..20790766 100644 --- a/docs/STRIX_HALO.md +++ b/docs/STRIX_HALO.md @@ -125,6 +125,14 @@ replay 3.4 -> 2.1 s per turn). Its output is the fused path's, which reads of 1, under `STRATA_PF_SWITCH_MIN_T`, which gates only the hyper-connection and padding switches. A UD-Q4_K_XL or other K-quant pack takes the fused experts only with `STRATA_PF_FUSED_KQ=1` as well. +`STRATA_PF_F16=1` (gfx11 only; add it to the list above) runs the covered prompt experts on the F16 matrix cores instead of +the int8 ones: K-quant gate/up and Q5_1 down (with `STRATA_PF_FUSED_KQ=1`), IQ2 / IQ3 / IQ4_XS gate/up, Q2_0 / IQ4_NL / Q8_0 +down. One layer, 16,384 tokens: Q4_K / Q5_1 85.3 -> 53.5 ms, IQ3_S / IQ4_NL gate/up 11.65 -> 9.87 and down 6.11 -> 4.71 ms. +It rounds differently from the int8 kernels. First-token KL against a run with no switches, 12 natural-text prompts of +1.5K-24K tokens (Strata's own docs and sources), top-1 the same in 12 of 12: UD-Q4_K_XL mean 0.0068 (median 0.0021) against +0.0031 (0.0024) for `STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1` without it; UD-IQ4_XS 0.0085 (0.0036) against 0.0068 (0.0032). One +1.5K prompt carries most of the Q4_K_XL mean (0.049). + Two engine flags help on long contexts and are not Strix-specific: `--mtp-window 8192` (the draft layer attends to the last 8,192 cells: 64K output +3.5%, 32K -0.4%) and `--spec`, `--lookup-chain`, `--mtp-q4` (see [DETAILS.md](DETAILS.md)). From 1b1bd4b4a84bfbcc4b851e9a9026412a99a11e63 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:07:48 +0200 Subject: [PATCH 11/28] prefill: STRATA_GDN_CHUNKED=1 on gfx11, the prompt's DeltaNet recurrence in 16-token chunks on the matrix cores (opt-in) The switch exists for CUDA (#1372) and is compiled out on HIP. On gfx11 it now runs the WY form of the gated delta rule in chunks of 16 tokens, every product one 16x16x16 WMMA (FP16 operands, FP32 accumulation, the state in the accumulators), with the output norm and the z gate fused: a prep kernel for T and P of every chunk, then a scan with a block per value head. It rounds differently from the FP32 recurrence, so it is opt-in; the default path is unchanged. A gfx1100, gfx1101, gfx1102, gfx1150 or gfx1151 part, 64 tokens and more, an output row stride divisible by 8 and no STRATA_GDN_REC_HEADS take it; anything else runs the existing kernels. tests/hip/gdn_chunked.cpp: bounds on the FP16 output and the carried state against the existing recurrence over 0-16,385 tokens (chunk and stride edges, a split request), a double-precision CPU check, and bit-identical output with the switch off or unset. tests/hip/gdn_rec_head.cpp unsets the switch, as its variants 0 and 1 are the references there. hip_gdn_chunked --bench and --bench-default time this path and gfx1151's default kernels, one per process (the switch is read once). gfx1151 (Ryzen AI Max+ 395, UD-IQ4_XS): a layer's recurrence + norm takes 1.60x less time than the default kernels at 16K and 32K tokens; a whole prompt 1.4-2.1% less at 4K-128K after a warm-up prompt (11 pairs each: 1.8-2.1% with the docs/STRIX_HALO.md section-5 switches, 1.4-1.5% without them, 10 or 11 of 11 faster); first-token KL against the default 0.006-0.007 on average, the same top token in 12 of 12 prompts. Run on gfx1151 only; kernels.cu compiles for gfx1030, 1100, 1151, 1152 and 1201 (docs/AMD_HIP.md). Co-authored-by: libratechw --- CMakeLists.txt | 6 + docs/AMD_HIP.md | 58 +++++ docs/DETAILS.md | 7 +- include/strata/prefill/kernels.hpp | 3 +- src/prefill/kernels.cu | 345 ++++++++++++++++++++++++++++- tests/hip/gdn_chunked.cpp | 235 ++++++++++++++++++++ tests/hip/gdn_rec_head.cpp | 8 + 7 files changed, 659 insertions(+), 3 deletions(-) create mode 100644 tests/hip/gdn_chunked.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f17db220..b7d4fd1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -701,6 +701,12 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) target_link_libraries(hip_gdn_rec_head PRIVATE strata_prefill strata_hip_runtime) add_test(NAME hip_gdn_rec_head COMMAND hip_gdn_rec_head) list(APPEND _strata_hip_tests hip_gdn_rec_head) + add_executable(hip_gdn_chunked tests/hip/gdn_chunked.cpp) + target_link_libraries(hip_gdn_chunked PRIVATE strata_prefill strata_hip_runtime) + add_test(NAME hip_gdn_chunked COMMAND hip_gdn_chunked) + add_test(NAME hip_gdn_chunked_off COMMAND hip_gdn_chunked --off) + add_test(NAME hip_gdn_chunked_default COMMAND hip_gdn_chunked --default) + list(APPEND _strata_hip_tests hip_gdn_chunked hip_gdn_chunked_off hip_gdn_chunked_default) # #313: the RDNA3 / RDNA3.5 WMMA dense GEMMs (opt-in STRATA_WMMA_GEMM=1) against a reference add_executable(hip_prefill_wmma_gemm_parity tests/hip/prefill_wmma_gemm_parity.cpp) target_include_directories(hip_prefill_wmma_gemm_parity PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/prefill") diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index a8fe8834..132b2efe 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -153,6 +153,64 @@ pinned by this repository. For an offline build, point `STRATA_GGML_DIR` at a checkout of that exact revision; using an arbitrary newer checkout changes the dependency being tested. +## Opt-in chunked prompt GDN on gfx11 + +`STRATA_GDN_CHUNKED=1` runs the prompt's gated DeltaNet recurrence in 16-token chunks on the gfx11 matrix cores, +with FP16 operands and FP32 accumulation, and fuses the output norm. It is off by default: rounding differs from +the token-by-token FP32 recurrence. The CUDA switch of the same name uses a separate FP32 implementation. + +The HIP path accepts gfx1100, gfx1101, gfx1102, gfx1150 and gfx1151, and prompt chunks of at least 64 tokens. +Other cards, shorter chunks, an output row stride not divisible by eight, and `STRATA_GDN_REC_HEADS` use the +existing recurrence. Runtime measurements and numerical checks were run on gfx1151 only; building for another +target does not validate its speed or answers. The synthetic test compares the FP16 output and carried FP32 state +against the existing recurrence, and short cases against a double-precision CPU calculation. It covers partial +chunks, padded rows, weak decay and a split request; the off/default tests require identical output and state bits. +It does not establish model answer equivalence. + +`STRATA_GDN_CHUNKED=2`, which on CUDA skips the SM-count test, is the same as 1 here. + +Measured on a Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1), UD-IQ4_XS. One layer's recurrence and norm take 1.60x less time than +gfx1151's default kernels at 16K and 32K tokens (`hip_gdn_chunked --bench` against `--bench-default`, three runs each: 20.92 -> +13.11 ms at 16K, 42.14 -> 26.30 ms at 32K). A whole prompt: the same binary with only this switch changed, a fresh engine per +side, 11 pairs in alternating order after a discarded one, the engine's `prompt_ms`, every prompt read in full (no reused +tokens). Each engine reads a discarded 4K prompt first, because the first prompt after a start varies more (on those first +prompts the same pairs gave 95% intervals of [1.004, 1.032] and [0.981, 1.015]); the prompts follow each other once +`/proc/vmstat`'s page-migration and direct-reclaim counters have stood still for 3 s, and a pair in which either prompt still +met page migration or direct reclaim was dropped and measured again (3 of the 69 pairs, all 32K with the switch on; kept in, 32K +gives 1.020 and 1.015). "Section 5" is the nine variables of `STRIX_HALO.md` section 5 (with `STRATA_PF_SWITCH_MIN_T=2048`); +"defaults" is the engine without them (section 4's gfx1151 defaults stay). Times are medians; the ratio is the geometric mean of +the 11 off / on ratios with a 95% bootstrap interval; "faster" counts the pairs in which the switch was faster: + +| tokens | arm | off -> on | off / on | faster | +|---:|---|---:|---:|---:| +| 4,096 | section 5 | 3.703 -> 3.641 s | 1.018 [1.016, 1.020] | 11 of 11 | +| 4,096 | defaults | 5.914 -> 5.829 s | 1.014 [1.010, 1.017] | 10 of 11 | +| 32,768 | section 5 | 26.157 -> 25.589 s | 1.021 [1.020, 1.023] | 11 of 11 | +| 32,768 | defaults | 44.082 -> 43.479 s | 1.015 [1.012, 1.017] | 11 of 11 | +| 128,000 | section 5 | 107.149 -> 104.866 s | 1.021 [1.020, 1.023] | 11 of 11 | +| 128,000 | defaults | 193.439 -> 191.055 s | 1.014 [1.012, 1.016] | 11 of 11 | + +So about 2% on top of section 5 and about 1.5% on the defaults. At 36 gated-DeltaNet layers the layer figures predict about +0.56 s for a 32K prompt; 0.57 s (section 5) and 0.60 s (defaults) were measured. + +First-token KL against the same run without the switch, 12 prompts of 1.5K-24K tokens: UD-IQ4_XS 0.0067 mean (0.044 max) on the +defaults and 0.0039 (0.027) on top of section 5; UD-Q4_K_XL 0.0063 (0.043) and 0.0040 (0.014); the same top token in all of +them (across the 12 prompts the first token takes only two distinct values). Section 5's switches alone are 0.0068 (IQ4_XS) and +0.0031 (Q4_K_XL) against the defaults, a different change that is listed for scale and not as a limit for this one. Only the +first generated token was compared: a long generation and perplexity were not measured. + +Build and run these checks in the HIP build directory: + +```sh +cmake --build build-hip --target hip_gdn_chunked hip_gdn_rec_head +ctest --test-dir build-hip -R 'hip_gdn_(chunked|rec_head)' --output-on-failure +for i in 1 2 3; do ./build-hip/hip_gdn_chunked --bench-default; ./build-hip/hip_gdn_chunked --bench; done +``` + +Each benchmark run reports the GPU-event median of seven runs after two warmups, the same nonzero initial state every run: +`--bench` this path, `--bench-default` gfx1151's default kernels (`STRATA_GDN_PP=2`, `STRATA_GDN_NOY=1`). The switch is read +once per process, so the two are separate runs. It times one layer's recurrence and norm, not a whole prompt. + ## Model and serving configuration Prepare a supported model pack and its MTP runtime using the existing tools. diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 5bd5fbbb..50e78725 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1727,12 +1727,17 @@ None of these changes the default answers; each was measured against the default engine runs (a fresh engine per side, warmed, 200-token greedy answers on three fixed prompts, medians; "pairs faster" counts the pairs in which the switched arm won). They are here so you can try them on your own card. -- **`STRATA_GDN_CHUNKED=1`: the DeltaNet recurrence of the prompt in chunks of 32 tokens** (sergiywith, #1372; WY form, FP32, +- **`STRATA_GDN_CHUNKED=1`: the DeltaNet recurrence of the prompt, opt-in**. On CUDA it runs in chunks of 32 tokens + (sergiywith, #1372; WY form, FP32, other bits than the default: first-token KL against the default was 0.002-0.009 nats on average, the same top token in every prompt tried). The kernel needs 128 SMs in one wave, so by itself it runs only on a card with 128 or more (RTX 5090: 1.8x on the recurrence). On smaller cards `STRATA_GDN_CHUNKED=2` forces it for a measurement, and it is slower there: 0.73x on an RTX 3060 (28 SMs) and 0.87x on an RTX 5070 (48 SMs) at 2K-32K tokens (`gdn_rec_parity --bench`), and the prompt time did not improve: RTX 5070 2K 1.01x, 8K 1.00x of the default's time; RTX 3060 2K, 8K, 16K 1.01x, no pair faster. + On HIP, gfx1100-gfx1102, gfx1150 and gfx1151 use 16-token WMMA chunks with FP16 operands and a fused output norm; other cards and short + chunks keep the existing path. It changes rounding too (first-token KL against the default 0.006-0.007 on average, the same top + token in 12 of 12 prompts); on a Radeon 8060S (gfx1151) the layer's recurrence is 1.6x faster and a 4K-128K prompt after a warm-up prompt 1.4-2.1%; see + [the HIP conditions and numerical checks](AMD_HIP.md#opt-in-chunked-prompt-gdn-on-gfx11). - **`STRATA_FS_SLOTS=N`: the Foresight swap space** (q8atnight, #1348): N VRAM slots per layer, refilled on a copy stream with the experts that just missed and with the ones the next layer's router predicts (`STRATA_FS_AHEAD=0` for the misses only), so that an expert the cache lacks can be computed on the GPU instead of by the CPU. The model's own router diff --git a/include/strata/prefill/kernels.hpp b/include/strata/prefill/kernels.hpp index f12f34b9..9cc17d22 100644 --- a/include/strata/prefill/kernels.hpp +++ b/include/strata/prefill/kernels.hpp @@ -63,7 +63,8 @@ void gdn_recurrence(float* state, const float* h, const float* gate, const float int64_t ld16 = 0); // ld16: y16's row stride (0 = 6144; S23 STRATA_PF_PAD pads it) /// The kernels behind gdn_recurrence, for the parity test: 0 = the column-split kernels + the norm kernel (or the /// one-block-per-head kernel under STRATA_GDN_REC_HEADS), 1 = four lanes per column (no barrier per token) + the grid-stride norm, 2 = the -/// one-block-per-head kernel (its fused norm rounds differently). 0 and 1 give the same bits. +/// one-block-per-head kernel (its fused norm rounds differently). 0 and 1 give the same bits. On HIP, 0 and 1 run the opt-in +/// chunked WMMA recurrence instead (gfx11, STRATA_GDN_CHUNKED=1, 64 tokens and more: other bits, see docs/AMD_HIP.md). /// SYCL only: 6 = the Xe sub-group recurrence (16-lane sub-groups, one barrier per token) + the norm kernel, the same /// bits as 0 on an Arc A770; gdn_recurrence takes it by default on Alchemist (STRATA_GDN_XE=0 off, =1 any Intel GPU). void gdn_recurrence_variant(int variant, float* state, const float* h, const float* gate, const float* beta, diff --git a/src/prefill/kernels.cu b/src/prefill/kernels.cu index f58a189c..322cd126 100644 --- a/src/prefill/kernels.cu +++ b/src/prefill/kernels.cu @@ -1469,6 +1469,340 @@ __global__ void __launch_bounds__(S) gdn_out_norm_loop_kernel(const float* __res } } } +// STRATA_GDN_CHUNKED=1 on the gfx11 matrix cores: the recurrence in chunks of 16 tokens (the WY form of the CUDA +// chunked path above), FP16 operands and FP32 accumulation, the output norm fused. Per value head, gamma_t the +// gate's sum from the chunk's start to t (inclusive; the code's sg) and S0 the state before the chunk: +// A[t][i] = beta_t exp(gamma_t - gamma_i) k_t.k_i (i < t), T = (I + A)^-1, P[t][i] = exp(gamma_t - gamma_i) q_t.k_i (i <= t), +// Y = beta (V - exp(gamma) K S0), D = T Y, o = exp(gamma) Q S0 + P D, +// S = exp(gamma_last) S0 + K^T (exp(gamma_last - gamma) D). +// gdn_wmma_prep_kernel computes T and P of every chunk at once (they do not depend on the state); gdn_wmma_scan_kernel +// walks the chunks, a block per value head and a wave per 16 value columns, the state in the waves' WMMA accumulators +// (FP32), each product a 16 x 16 x 16 WMMA: k, q, T, P, D and the state as an operand are rounded to FP16 (relative +// 2^-11), so the output differs from the FP32 kernels by more than their rounding (tests/hip/gdn_chunked.cpp holds it +// to the bounds of its Error::ok). The norm and the z gate run in the scan. +#if defined(__gfx1100__) || defined(__gfx1101__) || defined(__gfx1102__) || defined(__gfx1150__) || defined(__gfx1151__) +#define STRATA_GDN_WMMA 1 // device pass with the gfx11 WMMA intrinsic (the list of gfx_arch_is_gfx11_wmma) +#endif +constexpr int GW_CK = 16; // tokens per chunk (a WMMA tile) +constexpr int GW_NW = S / 16; // the scan's waves per block: one per 16 value columns +constexpr int GW_VPK = HV / HK; // value heads per key head: the prep's waves per block +constexpr int GW_KP = S + 8; // the scan's padded FP16 k / q rows +constexpr int GW_AHEAD = 3; // the scan warms the cache this many chunks ahead +constexpr int64_t kGdnWmmaMin = 64; // STRATA_GDN_CHUNKED=1 takes prompt chunks of this many tokens and more +typedef _Float16 gw_h16 __attribute__((ext_vector_type(16))); +typedef _Float16 gw_h8 __attribute__((ext_vector_type(8))); +typedef _Float16 gw_h2 __attribute__((ext_vector_type(2))); +typedef float gw_f8 __attribute__((ext_vector_type(8))); +typedef float gw_f4 __attribute__((ext_vector_type(4))); // (HIP's float4 copies through memcpy, which kept a staged + // copy in scratch: a store that waits for the load) +__device__ __forceinline__ gw_f8 gw_mma(gw_h16 a, gw_h16 b, gw_f8 c) { +#if defined(STRATA_GDN_WMMA) + return __builtin_amdgcn_wmma_f32_16x16x16_f16_w32(a, b, c); +#else + (void) a; (void) b; (void) c; + __builtin_trap(); // not a gfx11 device pass: the runtime gate never launches it +#endif +} +// An accumulator tile (lane l: rows 2v + (l >> 4) for v = 0..7, column l & 15) as a B operand (lane l: column l & 15, +// rows 0..15, both halves of the wave alike): pairs of rows rounded to FP16 and packed, the other half's pairs fetched +// across (permlanex16), then interleaved by a byte permute whose selector depends on the lane's half (gw_sel). +struct GwSel { unsigned even, odd; }; +__device__ __forceinline__ GwSel gw_sel(int hi) { return hi ? GwSel{0x01000504u, 0x03020706u} : GwSel{0x05040100u, 0x07060302u}; } +__device__ __forceinline__ gw_h16 gw_acc_to_b(gw_f8 x, GwSel ps) { + unsigned wd[8]; +#pragma unroll + for (int m = 0; m < 4; ++m) { + const gw_h2 p = {(_Float16) x[2 * m], (_Float16) x[2 * m + 1]}; + const unsigned own = __builtin_bit_cast(unsigned, p); +#if defined(STRATA_GDN_WMMA) + const unsigned other = __builtin_amdgcn_permlanex16(own, own, 0x76543210u, 0xfedcba98u, false, false); +#else + const unsigned other = own; +#endif + wd[2 * m] = __builtin_amdgcn_perm(other, own, ps.even); + wd[2 * m + 1] = __builtin_amdgcn_perm(other, own, ps.odd); + } + return __builtin_bit_cast(gw_h16, wd); +} +__device__ __forceinline__ gw_h16 gw_ld(const _Float16* p) { // 32 bytes of LDS, 16-byte aligned + const uint4 a = *reinterpret_cast(p), b = *reinterpret_cast(p + 8); + const uint4 ab[2] = {a, b}; + return __builtin_bit_cast(gw_h16, ab); +} +// The wave's own LDS writes complete (read back across its lanes). A gfx11 instruction: gfx12 device passes never run these kernels. +__device__ __forceinline__ void gw_lds_wait() { +#if defined(STRATA_GDN_WMMA) + __asm__ volatile("s_waitcnt lgkmcnt(0)" ::: "memory"); +#endif +} +// A barrier over LDS only. __syncthreads() is a workgroup fence over all memory, which on gfx11 also waits for every +// global load in flight: the scan's loads of the next chunk would have to land before each barrier. +__device__ __forceinline__ void gw_lds_barrier() { +#if defined(STRATA_GDN_WMMA) + __asm__ volatile("s_waitcnt lgkmcnt(0)\n\ts_barrier" ::: "memory"); +#else + __syncthreads(); // the gfx11-only instruction must not reach a gfx12 device pass +#endif +} + +// A block per (key head, chunk) - the grid's x the key head, so the blocks in flight read the same token rows (blocks +// that walked the key heads' slices of far-apart rows took 14 ms against 2.2 ms for 16K tokens on gfx1151) - and a wave per value head of the key head. +// T then P, FP16 row-major (1 KB), at tp[(chunk * HV + value head) * 512]. +__global__ void __launch_bounds__(32 * GW_VPK) gdn_wmma_prep_kernel(const float* __restrict__ h, const float* __restrict__ gate, + const float* __restrict__ beta, _Float16* __restrict__ tp, + int64_t T) { + __shared__ float sa[GW_VPK][GW_CK * GW_CK], sg[GW_VPK][GW_CK], sb[GW_VPK][GW_CK]; + const int qh = blockIdx.x, ch = blockIdx.y, w = threadIdx.x >> 5, l = threadIdx.x & 31, c = l & 15, hi = l >> 4; + const int vh = qh + w * HK; + const int64_t t0 = (int64_t) ch * GW_CK; + gw_f8 kk = {}, qk = {}; // k_t.k_i and q_t.k_i (lane: column i = c, rows t = 2v + hi) + { + const bool ok = t0 + c < T; // past the end: zero rows + const float* ht = h + (ok ? t0 + c : 0) * C; +#pragma unroll + for (int j = 0; j < S / 16; ++j) { + gw_h16 ka, qa; +#pragma unroll + for (int i = 0; i < 4; ++i) { + const gw_f4 k4 = *reinterpret_cast(ht + HK * S + qh * S + 16 * j + 4 * i); + const gw_f4 q4 = *reinterpret_cast(ht + qh * S + 16 * j + 4 * i); +#pragma unroll + for (int e = 0; e < 4; ++e) { + ka[4 * i + e] = (_Float16) (ok ? k4[e] : 0.0f); + qa[4 * i + e] = (_Float16) (ok ? q4[e] : 0.0f); + } + } + kk = gw_mma(ka, ka, kk); // B = K^T: lane i holds column i of K^T, row i of K - the A operand itself + qk = gw_mma(qa, ka, qk); + } + } + if (l < GW_CK) { // past the end: gate 0, beta 0 + const bool ok = t0 + l < T; + float g = ok ? gate[(t0 + l) * HV + vh] : 0.0f; +#pragma unroll + for (int o = 1; o < GW_CK; o <<= 1) { + const float u = __shfl_up(g, o, GW_CK); + if (l >= o) g += u; + } + sg[w][l] = g; + sb[w][l] = ok ? beta[(t0 + l) * HV + vh] : 0.0f; + } + gw_lds_wait(); // the wave's own LDS writes, read across its lanes + _Float16* out = tp + ((int64_t) ch * HV + vh) * (2 * GW_CK * GW_CK); +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + sa[w][t * GW_CK + c] = c < t ? sb[w][t] * __expf(sg[w][t] - sg[w][c]) * kk[v] : 0.0f; + out[GW_CK * GW_CK + t * GW_CK + c] = (_Float16) (c <= t ? __expf(sg[w][t] - sg[w][c]) * qk[v] : 0.0f); + } + gw_lds_wait(); + if (l < GW_CK) { // lane c: column c of T = (I + A)^-1 by forward substitution + float tc[GW_CK]; +#pragma unroll + for (int t = 0; t < GW_CK; ++t) { + float v = t == c ? 1.0f : 0.0f; +#pragma unroll + for (int k = 0; k < t; ++k) v = fmaf(-sa[w][t * GW_CK + k], tc[k], v); + tc[t] = v; + out[t * GW_CK + c] = (_Float16) v; + } + } +} + +// A thread's slice of a chunk in the scan (token threadIdx / 16, columns (threadIdx % 16) * 8 .. + 7): k, q and v, +// loaded a chunk ahead, and one word of the chunk's T and P; lanes 0..15 of wave 0 also gate and beta of token l. +// Rows past the end read the last row (finite: their gate and beta become 0 at staging, which keeps them out of the +// state, of the real rows' products and of the output) - no select on the loaded values, which would wait for them. +struct GwChunk { + gw_f4 k0, k1, q0, q1, v0, v1; + float g, b; + unsigned tp; +}; +__device__ __forceinline__ void gw_load(GwChunk& in, const float* __restrict__ h, const float* __restrict__ gate, + const float* __restrict__ beta, const unsigned* __restrict__ tp, int64_t t0, + int64_t T, int vh, int qh) { + const int t = threadIdx.x >> 4, r = (threadIdx.x & 15) * 8; + const float* ht = h + std::min(t0 + t, T - 1) * C; + in.tp = tp[((t0 / GW_CK) * HV + vh) * (GW_CK * GW_CK) + threadIdx.x]; + in.k0 = *reinterpret_cast(ht + HK * S + qh * S + r); + in.k1 = *reinterpret_cast(ht + HK * S + qh * S + r + 4); + in.q0 = *reinterpret_cast(ht + qh * S + r); + in.q1 = *reinterpret_cast(ht + qh * S + r + 4); + in.v0 = *reinterpret_cast(ht + 2 * HK * S + vh * S + r); + in.v1 = *reinterpret_cast(ht + 2 * HK * S + vh * S + r + 4); + if (threadIdx.x < GW_CK) { + const int64_t tl = std::min(t0 + threadIdx.x, T - 1); + in.g = gate[tl * HV + vh]; + in.b = beta[tl * HV + vh]; + } +} +// Brings a later chunk's lines (this block's k, q, v and z rows: 256 lines of 128 bytes, one a thread) into the cache +// with a load whose result is not used, so the real loads of that chunk hit the cache. An ordinary load: the compiler +// tracks it, and the result is consumed (by an empty asm) one chunk later, after the store of the previous chunk's output +// rows, where the wait for the loads issued before that point also covers it. +__device__ __forceinline__ unsigned gw_touch(const float* __restrict__ h, const float* __restrict__ z, int64_t t0, + int64_t T, int vh, int qh) { + const int t = threadIdx.x >> 4, part = threadIdx.x & 15, kind = part >> 2; + if (t0 + t >= T) return 0u; + const float* p = kind == 0 ? h + (t0 + t) * C + HK * S + qh * S + : kind == 1 ? h + (t0 + t) * C + qh * S + : kind == 2 ? h + (t0 + t) * C + 2 * HK * S + vh * S + : z + (t0 + t) * HV * S + vh * S; + return __float_as_uint(p[32 * (part & 3)]); +} +// Per chunk: stage it (k / q FP16, k also transposed, v, the gate's running sum, beta, T and P); barrier (1); store +// the previous chunk's output rows (the z gate on its normed output, 16 bytes a thread); X = K S0, QS = Q S0; Y, D, +// o and the wave's sums of o^2; the state update; barrier (2); the norm. LDS is single-buffered: an array written in +// the staging of chunk c + 1 or after its barrier (2) was last read before that wave reached barrier (1) of c + 1. +__global__ void __launch_bounds__(GW_NW * 32) gdn_wmma_scan_kernel(float* __restrict__ state, const float* __restrict__ h, + const float* __restrict__ gate, const float* __restrict__ beta, + const float* __restrict__ z, const float* __restrict__ gamma, + const unsigned* __restrict__ tp, float eps, + uint16_t* __restrict__ y16, int64_t T, int64_t ld16) { + __shared__ __attribute__((aligned(16))) _Float16 sk[GW_CK * GW_KP], sq[GW_CK * GW_KP], skt[S * GW_CK], + stp[2 * GW_CK * GW_CK]; + __shared__ __attribute__((aligned(16))) float sv[GW_CK * S], so[GW_CK * S], sn[GW_CK * GW_NW]; + __shared__ float sg[GW_CK], sb[GW_CK], sgam[S]; + const _Float16 *st_ = stp, *sp_ = stp + GW_CK * GW_CK; // T, P + const int vh = blockIdx.x, qh = vh % HK, w = threadIdx.x >> 5, l = threadIdx.x & 31, c = l & 15, hi = l >> 4; + const int col = 16 * w + c; // this lane's column in the products + const int st = threadIdx.x >> 4, sr = (threadIdx.x & 15) * 8; // this thread's staging slice + const size_t rs = (size_t) HV * S; + const GwSel ps = gw_sel(hi); + gw_f8 s[S / 16]; // the state: rows 16j + 2v + hi, column col +#pragma unroll + for (int j = 0; j < S / 16; ++j) +#pragma unroll + for (int v = 0; v < 8; ++v) s[j][v] = state[(size_t) (16 * j + 2 * v + hi) * rs + (size_t) vh * S + col]; + if (threadIdx.x < S) sgam[threadIdx.x] = gamma[threadIdx.x]; + const float out_scale = rsqrtf((float) S); + GwChunk cur; + gw_load(cur, h, gate, beta, tp, 0, T, vh, qh); + unsigned touched = 0; + gw_f4 z0 = {}, z1 = {}; // the z slice of the chunk whose output rows are stored next + auto store_rows = [&](int64_t c0) { // the output rows of the chunk at c0 (its norm in so): z gate, FP16 + if (c0 + st >= T) return; + const float* o = &so[st * S + sr]; + gw_h8 r; +#pragma unroll + for (int i = 0; i < 8; ++i) r[i] = (_Float16) (o[i] * sigm(i < 4 ? z0[i] : z1[i - 4])); + *reinterpret_cast(y16 + (c0 + st) * ld16 + vh * S + sr) = __builtin_bit_cast(uint4, r); + }; + for (int64_t t0 = 0; t0 < T; t0 += GW_CK) { + { // stage this chunk + gw_h8 kh, qq; +#pragma unroll + for (int i = 0; i < 8; ++i) { + kh[i] = (_Float16) (i < 4 ? cur.k0[i] : cur.k1[i - 4]); + qq[i] = (_Float16) (i < 4 ? cur.q0[i] : cur.q1[i - 4]); + skt[(sr + i) * GW_CK + st] = kh[i]; + } + *reinterpret_cast(&sk[st * GW_KP + sr]) = __builtin_bit_cast(uint4, kh); + *reinterpret_cast(&sq[st * GW_KP + sr]) = __builtin_bit_cast(uint4, qq); + *reinterpret_cast(&sv[st * S + sr]) = cur.v0; + *reinterpret_cast(&sv[st * S + sr + 4]) = cur.v1; + reinterpret_cast(stp)[threadIdx.x] = cur.tp; + if (threadIdx.x < GW_CK) { // past the end: gate 0, beta 0 + const bool ok = t0 + l < T; + float g = ok ? cur.g : 0.0f; +#pragma unroll + for (int o = 1; o < GW_CK; o <<= 1) { + const float u = __shfl_up(g, o, GW_CK); + if (l >= o) g += u; + } + sg[l] = g; + sb[l] = ok ? cur.b : 0.0f; + } + } + if (t0 + GW_CK < T) gw_load(cur, h, gate, beta, tp, t0 + GW_CK, T, vh, qh); // lands during this chunk + const unsigned touch_now = gw_touch(h, z, t0 + GW_AHEAD * GW_CK, T, vh, qh); + gw_lds_barrier(); // (1) this chunk staged; the previous chunk's norm in so + if (t0 > 0) store_rows(t0 - GW_CK); + __asm__ volatile("" ::"v"(touched)); // the previous touch, consumed here + touched = touch_now; + { // this chunk's z slice, for its output rows after barrier (1) of the next chunk + const int64_t tz = std::min(t0 + st, T - 1); + z0 = *reinterpret_cast(z + tz * HV * S + vh * S + sr); + z1 = *reinterpret_cast(z + tz * HV * S + vh * S + sr + 4); + } + gw_f8 x = {}, qs = {}; // K S0 and Q S0, this wave's columns +#pragma unroll + for (int j = 0; j < S / 16; ++j) { + const gw_h16 b = gw_acc_to_b(s[j], ps); + x = gw_mma(gw_ld(sk + c * GW_KP + 16 * j), b, x); + qs = gw_mma(gw_ld(sq + c * GW_KP + 16 * j), b, qs); + } + gw_f8 y; +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + y[v] = sb[t] * (sv[t * S + col] - __expf(sg[t]) * x[v]); + } + const gw_f8 d = gw_mma(gw_ld(st_ + c * GW_CK), gw_acc_to_b(y, ps), gw_f8{}); + gw_f8 o; +#pragma unroll + for (int v = 0; v < 8; ++v) o[v] = __expf(sg[2 * v + hi]) * qs[v]; + o = gw_mma(gw_ld(sp_ + c * GW_CK), gw_acc_to_b(d, ps), o); +#pragma unroll + for (int v = 0; v < 8; ++v) { // the wave's 16 columns of o^2 per token, then the 8 waves' through LDS + o[v] *= out_scale; + float p = o[v] * o[v]; +#pragma unroll + for (int m = 1; m < 16; m <<= 1) p += __shfl_xor(p, m); + if (c == 0) sn[(2 * v + hi) * GW_NW + w] = p; + } + const float gl = sg[GW_CK - 1]; + gw_f8 dd; +#pragma unroll + for (int v = 0; v < 8; ++v) dd[v] = __expf(gl - sg[2 * v + hi]) * d[v]; + const gw_h16 db = gw_acc_to_b(dd, ps); + const float eg = __expf(gl); +#pragma unroll + for (int j = 0; j < S / 16; ++j) s[j] = gw_mma(gw_ld(skt + (16 * j + c) * GW_CK), db, s[j] * eg); + gw_lds_barrier(); // (2) the sums of o^2 + const float g_col = sgam[col]; +#pragma unroll + for (int v = 0; v < 8; ++v) { + const int t = 2 * v + hi; + const gw_f4 n0 = *reinterpret_cast(&sn[t * GW_NW]), n1 = *reinterpret_cast(&sn[t * GW_NW + 4]); + const float ss = n0[0] + n0[1] + n0[2] + n0[3] + n1[0] + n1[1] + n1[2] + n1[3]; + so[t * S + col] = o[v] * rsqrtf(ss * (1.0f / S) + eps) * g_col; + } + } + __asm__ volatile("" ::"v"(touched)); + gw_lds_barrier(); + store_rows((T - 1) / GW_CK * GW_CK); + __asm__ volatile("" : "+s"(state)); // the state's addresses recomputed here, not kept (spilled) since the start +#pragma unroll + for (int j = 0; j < S / 16; ++j) +#pragma unroll + for (int v = 0; v < 8; ++v) state[(size_t) (16 * j + 2 * v + hi) * rs + (size_t) vh * S + col] = s[j][v]; +} +// The opt-in chunked recurrence on gfx11 (STRATA_GDN_CHUNKED=1): false (nothing launched) on another part. y, the +// FP32 scratch of the other kernels (T x 6144 floats), holds T and P (1 KB per chunk and value head: T x 3 KB). +bool gdn_rec_wmma(float* state, const float* h, const float* gate, const float* beta, const float* z, const float* gamma, + float eps, float* y, uint16_t* y16, int64_t T, cudaStream_t s, int64_t ld16) { + if (T < kGdnWmmaMin || ld16 % 8 != 0) return false; // the rows are stored 16 bytes at a time + // A layer-split worker can change devices: a process-wide answer for the first card can launch a trapping + // gfx11 kernel on a later gfx12 card. Cache only the current thread's last device, as properties are not cheap. + static thread_local int last_device = -1; + static thread_local bool gfx11 = false; + int dev = 0; + if (cudaGetDevice(&dev) != cudaSuccess) return false; + if (dev != last_device) { + cudaDeviceProp p{}; + if (cudaGetDeviceProperties(&p, dev) != cudaSuccess) return false; + gfx11 = strata::kernels::gfx_arch_is_gfx11_wmma(p.gcnArchName); + last_device = dev; + } + if (!gfx11) return false; + const int64_t nch = (T + GW_CK - 1) / GW_CK; + _Float16* tp = reinterpret_cast<_Float16*>(y); + gdn_wmma_prep_kernel<<>>(h, gate, beta, tp, T); + gdn_wmma_scan_kernel<<>>(state, h, gate, beta, z, gamma, reinterpret_cast(tp), + eps, y16, T, ld16); + return true; +} #endif // __HIPCC__ __global__ void __launch_bounds__(S) gdn_out_norm_kernel(const float* __restrict__ z, const float* __restrict__ gamma, float eps, float* __restrict__ y, uint16_t* __restrict__ y16, @@ -1939,7 +2273,17 @@ void gdn_recurrence_variant(int variant, float* state, const float* h, const flo const float* z, const float* gamma, float eps, float* y, uint16_t* y16, int64_t T, void* stream, int64_t ld16) { if (ld16 <= 0) ld16 = (int64_t) HV * S; + static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr; // the one-block-per-head kernel (A/B) #if defined(__HIPCC__) + if (variant == 0 || variant == 1) { + // STRATA_GDN_CHUNKED=1 (opt-in): the chunked recurrence on the gfx11 matrix cores, FP16 operands (other bits; + // a shorter chunk or another part takes the kernels below) + static const bool chunked = [] { const char* v = std::getenv("STRATA_GDN_CHUNKED"); return v != nullptr && std::atoi(v) != 0; }(); + if (chunked && !serial && gdn_rec_wmma(state, h, gate, beta, z, gamma, eps, y, y16, T, (cudaStream_t) stream, ld16)) { + check("gdn_recurrence (chunked, WMMA)"); + return; + } + } if (variant == 3) { // diagnostics: the quad recurrence + the old norm kernel if (T > 0) { gdn_rec_quad_kernel<<>>(state, h, gate, beta, y, T); @@ -1982,7 +2326,6 @@ void gdn_recurrence_variant(int variant, float* state, const float* h, const flo #else (void) variant; // the quad recurrence kernels are AMD-only #endif - static const bool serial = std::getenv("STRATA_GDN_REC_HEADS") != nullptr; // the one-block-per-head kernel (A/B) if (serial || T <= 0 || variant == 2) { gdn_rec_kernel<<>>(state, h, gate, beta, z, gamma, eps, y, y16, T, ld16); } else { diff --git a/tests/hip/gdn_chunked.cpp b/tests/hip/gdn_chunked.cpp new file mode 100644 index 00000000..a0f29cf2 --- /dev/null +++ b/tests/hip/gdn_chunked.cpp @@ -0,0 +1,235 @@ +// Exercise the public opt-in dispatch, including tails, padded rows and a nonzero carried state. The FP32 +// recurrence is the all-head reference; short cases also use an independent double-precision CPU recurrence. +#include "strata/prefill/kernels.hpp" +#include "strata/kernels/gfx_arch.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +constexpr int S = 128, HK = 16, HV = 48, C = 10240, ROW = HV * S; +constexpr uint16_t SENTINEL = 0x7bff; +void ck(cudaError_t e, const char* where) { + if (e != cudaSuccess) { std::fprintf(stderr, "%s: %s\n", where, cudaGetErrorString(e)); std::exit(2); } +} +void setting(const char* key, const char* value) { +#ifdef _WIN32 + if (_putenv_s(key, value)) std::exit(2); +#else + if (setenv(key, value, 1)) std::exit(2); +#endif +} +template X* upload(const std::vector& v) { + X* p = nullptr; + ck(cudaMalloc(&p, v.size() * sizeof(X)), "malloc"); + ck(cudaMemcpy(p, v.data(), v.size() * sizeof(X), cudaMemcpyHostToDevice), "upload"); + return p; +} +template std::vector download(const X* p, size_t n) { + std::vector v(n); + ck(cudaMemcpy(v.data(), p, n * sizeof(X), cudaMemcpyDeviceToHost), "download"); + return v; +} +float half(uint16_t bits) { __half_raw x; x.x = bits; return __half2float(__half(x)); } +struct Error { + double square = 0, reference = 0, max_error = 0, max_reference = 0; + bool finite = true; + void add(double a, double b) { + finite &= std::isfinite(a) && std::isfinite(b); + square += (a - b) * (a - b); reference += a * a; + max_error = std::max(max_error, std::fabs(a - b)); max_reference = std::max(max_reference, std::fabs(a)); + } + double rms() const { return std::sqrt(square / std::max(reference, 1e-30)); } + bool ok() const { return finite && rms() <= 0.003 && max_error <= 0.02 * max_reference + 1e-5; } +}; +struct Input { + int64_t n; + std::vector h, gate, beta, z, gamma, state; + Input(int64_t t, float decay, float scale, bool no_update) : n(t), h(std::max(t, 1) * C), + gate(std::max(t, 1) * HV), beta(gate.size()), z(std::max(t, 1) * ROW), + gamma(S), state(S * ROW) { + std::mt19937 rng(11); + std::normal_distribution normal(0, 1); + std::uniform_real_distribution uniform(0, 1); + for (auto& x : h) x = normal(rng); + for (int64_t i = 0; i < t; ++i) { + float* row = h.data() + i * C; + for (int head = 0; head < 2 * HK; ++head) { + double norm = 0; + for (int d = 0; d < S; ++d) norm += double(row[head * S + d]) * row[head * S + d]; + for (int d = 0; d < S; ++d) row[head * S + d] /= std::sqrt(norm + 1e-6); + } + for (int d = 2 * HK * S; d < C; ++d) row[d] *= scale; + } + for (auto& x : gate) x = -decay * uniform(rng); + for (auto& x : beta) x = no_update ? 0 : uniform(rng); + for (auto& x : z) x = normal(rng); + for (auto& x : gamma) x = 0.5f + uniform(rng); + for (auto& x : state) x = 0.1f * scale * normal(rng); + } +}; +struct Output { std::vector y; std::vector state; }; +Output run(const Input& in, int ld, bool reference, int64_t split = 0) { + auto h = upload(in.h), g = upload(in.gate), b = upload(in.beta), z = upload(in.z), gm = upload(in.gamma); + auto state = upload(in.state); + auto y = upload(std::vector(std::max(in.n, 1) * ld + 8, SENTINEL)); + // The chunked path owns y as temporary storage; only y16 and state are observable outputs. + auto scratch = upload(std::vector(std::max(in.n, 1) * ROW)); + auto call = [&](int64_t start, int64_t n) { + if (reference) + strata::prefill::gdn_recurrence_variant(5, state, h + start * C, g + start * HV, b + start * HV, + z + start * ROW, gm, 1e-6f, scratch, y + start * ld, n, nullptr, ld); + else + strata::prefill::gdn_recurrence(state, h + start * C, g + start * HV, b + start * HV, + z + start * ROW, gm, 1e-6f, scratch, y + start * ld, n, nullptr, ld); + ck(cudaDeviceSynchronize(), "recurrence"); + }; + if (split) { call(0, split); call(split, in.n - split); } + else call(0, in.n); + Output out{download(y, std::max(in.n, 1) * ld + 8), download(state, in.state.size())}; + ck(cudaFree(h), "free"); ck(cudaFree(g), "free"); ck(cudaFree(b), "free"); ck(cudaFree(z), "free"); + ck(cudaFree(gm), "free"); ck(cudaFree(state), "free"); ck(cudaFree(y), "free"); ck(cudaFree(scratch), "free"); + return out; +} +bool compare(const Input& in, int ld, const Output& ref, const Output& got, bool exact, const char* label) { + Error y, state; + bool guards = true, bits = true; + for (int64_t t = 0; t < in.n; ++t) { + for (int d = 0; d < ROW; ++d) { + y.add(half(ref.y[t * ld + d]), half(got.y[t * ld + d])); + bits &= ref.y[t * ld + d] == got.y[t * ld + d]; + } + for (int d = ROW; d < ld; ++d) guards &= got.y[t * ld + d] == SENTINEL; + } + for (size_t i = in.n * ld; i < got.y.size(); ++i) guards &= got.y[i] == SENTINEL; + for (size_t i = 0; i < got.state.size(); ++i) { + state.add(ref.state[i], got.state[i]); + bits &= std::memcmp(&ref.state[i], &got.state[i], sizeof(float)) == 0; + } + const bool ok = guards && (exact ? bits : y.ok() && state.ok()); + std::printf("%s %s T=%lld ld=%d exact=%d y_rms=%.3e y_max=%.3e state_rms=%.3e guards=%d\n", + ok ? "PASS" : "FAIL", label, (long long) in.n, ld, exact, y.rms(), y.max_error, state.rms(), guards); + return ok; +} +bool cpu_check(const Input& in, int ld, const Output& got) { + Error y, state; + for (int vh : {0, 23, 47}) { + const int qh = vh % HK; + std::vector s(S * S), output(S), delta(S); + for (int r = 0; r < S; ++r) + for (int c = 0; c < S; ++c) s[r * S + c] = in.state[r * ROW + vh * S + c]; + for (int64_t t = 0; t < in.n; ++t) { + const float* row = in.h.data() + t * C; + const float* q = row + qh * S; + const float* k = row + HK * S + qh * S; + const float* v = row + 2 * HK * S + vh * S; + const double decay = std::exp(in.gate[t * HV + vh]), beta = in.beta[t * HV + vh]; + for (auto& x : s) x *= decay; + for (int c = 0; c < S; ++c) { + double prediction = 0; + for (int r = 0; r < S; ++r) prediction += k[r] * s[r * S + c]; + delta[c] = beta * (v[c] - prediction); + } + double norm = 0; + for (int c = 0; c < S; ++c) { + double o = 0; + for (int r = 0; r < S; ++r) { s[r * S + c] += k[r] * delta[c]; o += q[r] * s[r * S + c]; } + output[c] = o / std::sqrt(double(S)); norm += output[c] * output[c]; + } + for (int c = 0; c < S; ++c) { + const double value = output[c] / std::sqrt(norm / S + 1e-6) * in.gamma[c] + / (1 + std::exp(-in.z[t * ROW + vh * S + c])); + y.add(value, half(got.y[t * ld + vh * S + c])); + } + } + for (int r = 0; r < S; ++r) + for (int c = 0; c < S; ++c) state.add(s[r * S + c], got.state[r * ROW + vh * S + c]); + } + const bool ok = y.ok() && state.ok(); + std::printf("%s CPU T=%lld y_rms=%.3e state_rms=%.3e\n", ok ? "PASS" : "FAIL", (long long) in.n, y.rms(), state.rms()); + return ok; +} +// One path's time for one layer's recurrence + norm (GPU-event median of 7 runs after 2 warmups, the same start state each +// run). STRATA_GDN_CHUNKED is read once per process, so --bench (this path) and --bench-default (gfx1151's default: the +// existing kernels with STRATA_GDN_PP=2 and STRATA_GDN_NOY=1) are separate runs of this binary. +void bench(const char* path) { + for (int64_t t : {64, 256, 2048, 16384, 32768}) { + const Input in(t, 2, 1, false); + auto h = upload(in.h), g = upload(in.gate), b = upload(in.beta), z = upload(in.z), gm = upload(in.gamma); + auto state = upload(in.state); + auto y = upload(std::vector(t * (ROW + 8))); + auto scratch = upload(std::vector(t * ROW)); + cudaEvent_t start, end; + ck(cudaEventCreate(&start), "event"); ck(cudaEventCreate(&end), "event"); + std::vector times; + for (int round = -2; round < 7; ++round) { + ck(cudaMemcpy(state, in.state.data(), in.state.size() * sizeof(float), cudaMemcpyHostToDevice), "reset"); + ck(cudaEventRecord(start), "event"); + strata::prefill::gdn_recurrence(state, h, g, b, z, gm, 1e-6f, scratch, y, t, nullptr, ROW + 8); + ck(cudaEventRecord(end), "event"); ck(cudaEventSynchronize(end), "time"); + float ms = 0; + ck(cudaEventElapsedTime(&ms, start, end), "time"); + if (round >= 0) times.push_back(ms); + } + std::sort(times.begin(), times.end()); + std::printf("BENCH path=%s T=%lld ms=%.6f repeats=7\n", path, (long long) t, times[3]); + ck(cudaEventDestroy(start), "event"); ck(cudaEventDestroy(end), "event"); + ck(cudaFree(h), "free"); ck(cudaFree(g), "free"); ck(cudaFree(b), "free"); ck(cudaFree(z), "free"); + ck(cudaFree(gm), "free"); ck(cudaFree(state), "free"); ck(cudaFree(y), "free"); ck(cudaFree(scratch), "free"); + } +} +} +int main(int argc, char** argv) { + const bool bench_default = argc > 1 && std::strcmp(argv[1], "--bench-default") == 0; + const bool off = argc > 1 && (std::strcmp(argv[1], "--off") == 0 || std::strcmp(argv[1], "--default") == 0 || bench_default); + setting("STRATA_GDN_CHUNKED", off ? "0" : "1"); + setting("STRATA_GDN_HEAD", "1"); setting("STRATA_GDN_PP", "2"); + if (argc > 1 && std::strncmp(argv[1], "--bench", 7) == 0) setting("STRATA_GDN_NOY", "1"); // gfx1151's default +#ifdef _WIN32 + _putenv_s("STRATA_GDN_REC_HEADS", ""); + if (argc > 1 && std::strcmp(argv[1], "--default") == 0) _putenv_s("STRATA_GDN_CHUNKED", ""); +#else + unsetenv("STRATA_GDN_REC_HEADS"); + if (argc > 1 && std::strcmp(argv[1], "--default") == 0) unsetenv("STRATA_GDN_CHUNKED"); +#endif + int device = 0; + cudaDeviceProp props{}; + ck(cudaGetDevice(&device), "device"); ck(cudaGetDeviceProperties(&props, device), "properties"); + const bool wmma = strata::kernels::gfx_arch_is_gfx11_wmma(props.gcnArchName); + std::printf("device=%s chunked=%d wmma=%d\n", props.gcnArchName, !off, wmma); + if (argc > 1 && std::strcmp(argv[1], "--bench") == 0) { bench("chunked"); return 0; } + if (bench_default) { bench("default"); return 0; } + int failures = 0; + for (int64_t t : {0, 1, 15, 16, 17, 63, 64, 65, 79, 80, 81, 257, 2051, 16385}) { + if (off && t > 2051) continue; + const Input in(t, 2, 1, false); + for (int padding : {0, 8, 1}) { + if (t > 257 && padding != 8) continue; + const int ld = ROW + padding; + const auto ref = run(in, ld, true), got = run(in, ld, false); + const bool exact = off || !wmma || t < 64 || ld % 8; + failures += !compare(in, ld, ref, got, exact, "dispatch"); + if (t == 65 && padding == 8) failures += !cpu_check(in, ld, got); + if (t == 257 && padding == 8) failures += !compare(in, ld, got, run(in, ld, false, 129), false, "continuation"); + } + } + if (!off) { + for (const float decay : {0.f, 0.01f}) { + const Input in(2051, decay, 16, false); + failures += !compare(in, ROW + 8, run(in, ROW + 8, true), run(in, ROW + 8, false), !wmma, "weak-decay"); + } + const Input in(65, 0.01f, 1, true); + const auto got = run(in, ROW, false); + failures += !compare(in, ROW, run(in, ROW, true), got, !wmma, "beta-zero"); + failures += !cpu_check(in, ROW, got); + } + std::printf("FAILURES: %d\n", failures); + return failures ? 1 : 0; +} diff --git a/tests/hip/gdn_rec_head.cpp b/tests/hip/gdn_rec_head.cpp index 06af26bb..6249440e 100644 --- a/tests/hip/gdn_rec_head.cpp +++ b/tests/hip/gdn_rec_head.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,13 @@ template std::vector host(const T* d, size_t n) { } // namespace int main() { + // variants 0 and 1 are the references here; STRATA_GDN_CHUNKED=1 would turn them into the opt-in chunked recurrence + // (tests/hip/gdn_chunked.cpp), whose bits differ +#ifdef _WIN32 + _putenv_s("STRATA_GDN_CHUNKED", ""); +#else + unsetenv("STRATA_GDN_CHUNKED"); +#endif std::mt19937 rng(11); std::normal_distribution nd(0.f, 1.f); std::uniform_real_distribution ud(0.f, 1.f); From 0fb72e8b0e0d5f94d3b226035badec6c16059964 Mon Sep 17 00:00:00 2001 From: AlexisCarbonell <51439370+AlexisCarbonell@users.noreply.github.com> Date: Tue, 13 Oct 2026 18:27:40 +0200 Subject: [PATCH 12/28] hip: a gfx1103 hipBLASLt tuning table (Radeon 780M) The Radeon 780M (gfx1103, RDNA3, 12 CUs) builds and runs (issue #1423), but had no hipBLASLt table, so the prompt's dense GEMMs ran on plain hipBLAS. This adds tools/hip/gfx1103-hipblaslt-100401.txt, calibrated on one 780M with ROCm 10.1's hipBLASLt 1.4.1 (version number 100401) over the gfx1150 table's 144 GEMM cases at T = 64..16384 with the engine's 32 MiB workspace. Two tune_hipblaslt passes back to back; each row keeps the solution with the lowest median of all six repetitions, and a row is left out when no candidate beats plain hipBLAS. 143 rows, 1.05-23.30x per GEMM, geometric mean 4.95x; the one shape left out is bf16 N=1 K=2560 T=64 (best 0.039 ms against 0.024 ms on plain hipBLAS, sub-100 us timings), where the engine falls back to hipBLASEx. Measured on the 780M (Ryzen 7 8745HS, 60 GB, GTT 50 GiB, Q2_0 + MTP, 32K context): a 4K prompt read 90 tok/s on plain hipBLAS against 187 with the table (medians of an interleaved A/B; with the gfx1103 exact switches and the WMMA opt-ins, 277 at 4K and 272 at 32K). hip_prefill_hipblaslt_gemm passes with it (launches=4 fallbacks=0) and hip_prefill_hcd_exact_parity skips, because the table picks no 1176 / 1177 for the HC down GEMM - the gfx1150 table gets the same skip, which is why STRATA_HCD_EXACT is not in the gfx1103 switch set. Setup installs for gfx1103 only with STRATA_EXPERIMENTAL_GFX1103=1 and then picks the table up when the installed hipBLASLt reports 1.4.1. Docs, the community report (runs.csv, tune-summary.csv, the server config, the engine's start-up lines) and the setup tables list carry the numbers. Refs #1423. --- .../2026-10-12-community-gfx1103/README.md | 165 ++++++++++++++++++ .../context-ladder-instant.jsonl | 4 + .../context-ladder.jsonl | 7 + .../engine-log-excerpt.txt | 35 ++++ .../phase4c-knobs-results.txt | 15 ++ .../phase4c-spec-results.txt | 12 ++ .../phase4c-window-results.txt | 6 + .../phase5a-results.txt | 12 ++ .../phase5b-results.txt | 7 + .../2026-10-12-community-gfx1103/runs.csv | 61 +++++++ .../s1-base.jsonl | 4 + .../s2-table.jsonl | 10 ++ .../s3-table-exact.jsonl | 4 + .../s3a-table-prompt5.jsonl | 4 + .../s3b-table-decode11.jsonl | 4 + .../s4-table-wmma.jsonl | 6 + .../s5-table-wmma-fused.jsonl | 4 + .../s6-table-all.jsonl | 6 + .../strata-base.jsonl | 6 + .../strata-gfx1103.json | 34 ++++ .../strata-table.jsonl | 6 + .../2026-10-12-community-gfx1103/strata.jsonl | 6 + .../tune-summary.csv | 144 +++++++++++++++ bench/results/COMMUNITY.md | 1 + docs/AMD_HIP.md | 14 ++ docs/COMMUNITY_BENCHMARKS.md | 2 + tools/hip/gfx1103-hipblaslt-100401.txt | 145 +++++++++++++++ 27 files changed, 724 insertions(+) create mode 100644 bench/results/2026-10-12-community-gfx1103/README.md create mode 100644 bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/phase5a-results.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/phase5b-results.txt create mode 100644 bench/results/2026-10-12-community-gfx1103/runs.csv create mode 100644 bench/results/2026-10-12-community-gfx1103/s1-base.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s2-table.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/strata-base.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json create mode 100644 bench/results/2026-10-12-community-gfx1103/strata-table.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/strata.jsonl create mode 100644 bench/results/2026-10-12-community-gfx1103/tune-summary.csv create mode 100644 tools/hip/gfx1103-hipblaslt-100401.txt diff --git a/bench/results/2026-10-12-community-gfx1103/README.md b/bench/results/2026-10-12-community-gfx1103/README.md new file mode 100644 index 00000000..81758a53 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/README.md @@ -0,0 +1,165 @@ +# Radeon 780M (gfx1103) on ROCm 10.1: dot4 + WMMA + a hipBLASLt table (2026-10-12) + +The gfx1103 port of the code in this tree: the native dot4 path, the gfx11 WMMA kernels, a calibrated hipBLASLt +table and the gfx1103 exact speed switches (written into the config's `env` by setup, like gfx1150's). Measured on +one 780M with every cited configuration run interleaved against the base. Everything here is one machine; see +"Not tested". + +## Rig + +- Ryzen 7 8745HS (8 cores / 16 threads, Zen 4, AVX-512), Radeon 780M (gfx1103, RDNA3, 12 CUs), 60 GB DDR5, GTT + 50 GiB (`mem_info_gtt_total` 50 GiB), Ubuntu kernel 7.0.0-38, amdgpu CWSR disabled (`cwsr_enable=0`). +- ROCm 10.1 (`rocm/dev-ubuntu-24.04:10.1.0-full`, HIP 7.16.26385, hipBLASLt 1.4.1 = `100401`, clang 24), engine built + by hand into `build-780m`: + `cmake -B build-780m -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF + -DSTRATA_PREFILL_MMQ=ON -DCMAKE_HIP_ARCHITECTURES=gfx1103`. +- Model: Qwen3.8-Flash-Next GSQ-RCO Q2_0 (ISTA-DASLab, revision `ed59f920`), a native pack with the experts read + from the GGUF in place (`--mmap-experts`), the PLE table on the SSD (`--ple-io direct`), Int8 KV, 32K context. + MTP draft layer built by `tools/mtp_fetch.py` + `mtp_pack.py` + `mtp_rt.py`. + +## Correctness gates + +- `ctest` (ROCm 10.1, gfx1103): 57 passed, 2 skipped (`hip_prefill_hcd_exact_parity`, + `hip_prefill_hipblaslt_gemm` — they run and pass with the table present, see below), 2 environmental failures + (`ple_parity` needs the `bench/micro` fixtures, `platform_memory_test` needs an 8 GiB+ memlock limit; this + host's hard limit is 8 MiB). +- The WMMA tests now **run and pass** on gfx1103 instead of skipping: `hip_intrinsics` (dot4 vs the byte loop), + `hip_prefill_wmma_gemm_parity`, `hip_prompt_attn_wmma`, `qsa_*`, `hip_prefill_fused_moe`, `hip_prefill_fused_iq`, + `hip_gemm_f16_io_parity`, `hip_prefill_mmq_parity`. +- The table: `hip_prefill_hipblaslt_gemm` passes with `launches=4 fallbacks=0`; the server's own log line says + `prefill gemm: hipBLASLt tuning enabled (143 rows, gfx1103, version 100401)`. +- **Token ids**: the ported engine with default flags prints the same greedy ids as the pre-port build at 4K and + 32K (the dot4 kernels are exact integer arithmetic). The 17 gfx1103 exact switches, with the table, also print + the same greedy ids as without them. The table itself changes the dense GEMMs' summation order (one 32-token + suffix differs, as on every other card), so identity is claimed for the exact paths, not the table. + +## Speed (bench_vs_llama.py, 256 tokens out, interleaved; medians of the shown samples) + +The 780M at 4K and 32K, one round, temperature 0 and 0.7: + +| arm | cell | prompt tok/s | decode tok/s | TTFT s | +| --- | --- | ---: | ---: | ---: | +| base (no table, no opt-ins) | 4K | 90 | 13.1 | 44.9 | +| base (no table, no opt-ins) | 32K | 90 | 13.1 | 351 | +| table + all opt-ins | 4K | 277 | 13.9 | 14.6 | +| table + WMMA set | 32K | 272 | 14.3 | 118 | + +Switch screening at 4K (medians of 4 requests; each arm is the arm above plus the named set; the screening ran with +the first calibration pass, and the merged table re-measured 187 tok/s at 4K, see "The table"): + +| arm | prompt tok/s | decode tok/s | +| --- | ---: | ---: | +| base (no table) | 91 | 13.1 | +| + hipBLASLt table | 186 | 13.9 | +| + the 17 exact switches | 211 | 13.4 | +| + WMMA set (`HIP_WMMA`, `PF_GEMM`, `PA_FAST`, `SELECT_WMMA`) | 248 | 13.4 | +| + `PF_FUSED` | 246 | 12.8 | +| + all of the above + `HC_UPMIX` | 277 | 13.7 | + +Decode (greedy, 640 tokens, 3 interleaved pairs, short prompt): the 11 decode exact switches 16.63 -> 17.17 tok/s +median (+3.2%, every pair). + +## Engine flags (Phase 4c) + +Draft-layer flags, `strata` in generate mode, 4K prompt, 256 greedy tokens, restarts per arm, 3 interleaved reps +(2 for `--mtp-window`, which used the 32K prompt): + +| arm | decode tok/s (reps) | +| --- | --- | +| `--spec 2` (default) | 15.93 / 15.65 / 15.65 | +| `--spec 3` | 15.38 / 15.89 / 15.69 | +| `--spec 4` (the gfx1150-style config) | 13.98 / 14.18 / 14.21 | +| `--spec 6` | 11.16 / 11.16 / 10.85 | +| `--spec 2 --spec-min-p 0.5` | 14.71 / 14.94 / 14.98 | +| `--spec 2 --mtp-q4 all` | 15.73 / 15.39 / 15.63 | +| `--spec 2 --mtp-q4 proj` | 15.71 / 15.88 / 15.74 | +| `--spec 2 --lookup-chain 4` | 16.01 / 16.37 / 15.72 | + +`--spec 2` is the best window on this chip (15.65 median against 14.18 at `--spec 4` and 11.16 at `--spec 6`); +`--spec-min-p 0.5` is 4.5% slower here than the engine default; `--mtp-q4` is neutral; `--lookup-chain 4` is +2.3% +(3 of 3 pairs) and byte-identical greedy answers. `--mtp-window 4096` against the default at 32K: 14.07/13.82 +against 13.72/13.63 (+2%, 2 pairs - weak). Raw: [phase4c-spec-results.txt](phase4c-spec-results.txt), +[phase4c-knobs-results.txt](phase4c-knobs-results.txt), [phase4c-window-results.txt](phase4c-window-results.txt). + +## Context ladder (the shipping configuration: 131K context, table + exact + WMMA opt-ins) + +Fresh prompts (a nonce first, so nothing is reused), 128 greedy tokens each, one sample per cell; the prompts come +from this checkout's own documentation (676K tokens of it). Prefill is the server's `prompt_per_second` for the +whole read, decode its `predicted_per_second`: + +| prompt tokens | prefill tok/s | decode tok/s | draft acceptance | +|---:|---:|---:|---:| +| 4,089 | 276.7 | 16.4 | 57/73 | +| 8,090 | 314.3 | 15.9 | 55/75 | +| 16,090 | 314.6 | 16.2 | 57/74 | +| 32,091 | 308.7 | 15.5 | 56/77 | +| 64,091 | 258.2 | 12.1 | 57/83 | +| 96,095 | 215.5 | 9.9 | 55/81 | +| 128,097 | 198.5 | 9.8 | 55/86 | + +So ~200 tok/s is the **average over the full 128K read**; the early-to-mid context reads faster (~310 tok/s to +32K). To see the rate at depth, a second request appended 256 tokens to the same prompt and let the server reuse +its cached prefix (the checkpoints are 16K apart, so the fresh part is 13-16K tokens ending at that depth): + +| depth | fresh tail tokens | tail prefill tok/s (cached prefix) | +|---:|---:|---:| +| 32K | 15,964 | 297.2 | +| 64K | 15,196 | 207.6 | +| 96K | 14,433 | 211.9 | +| 128K | 13,665 | 206.2 | + +The tail at 128K depth reads at ~206 tok/s, and a second full 128K run measured 221.4 (198.5 and 221.4 are two +samples), so ~200 tok/s holds both as the full-read average and as the local rate near the end. Decode falls with +depth because the attention reads the whole KV: 16 tok/s to 32K, ~12 at 64K, ~10 at 96-128K; draft acceptance is +steady (~70%), so it is context cost, not the drafter. Memory is flat across the ladder: GTT 38.1 of 50 GiB (11.9 +free), RAM 51 of 60 GB with the parked 128K conversation. The 4K cell here (276.7) matches the 277 in the Speed +table; the 32K cell is higher than the earlier 272 because the shipping configuration adds `--spec 2` and +`--lookup-chain 4`. Raw: [context-ladder.jsonl](context-ladder.jsonl), +[context-ladder-instant.jsonl](context-ladder-instant.jsonl). + +## Stability (Phase 5) + +- `STRATA_NO_ARENA_THP=1` (setup writes it for gfx1103): 6 engine starts with it and 6 without, alternating, all + clean (this config reads the experts through `--mmap-experts` and has no resident arena, so the flag is inert + here). Raw: [phase5a-results.txt](phase5a-results.txt). +- Memory pressure with the reset-prone combination from 7.10 - a partial expert cache (16,384 of 24,576 slots, + so file-tier reads), `STRATA_IO_PREFETCH=1`, 32K prompts, the adaptive tier on, then `--adapt-every 100000`: + 4 sessions, all clean, peak GTT 26.7 GiB. The 7.10 resets do not reproduce on ROCm 10.1 with `cwsr_enable=0` + (the fix reported in #1423). Raw: [phase5b-results.txt](phase5b-results.txt). +- Zero `amdgpu` resets or KFD evictions in the kernel log (`journalctl -k`) over the whole session. +- Soak: a 2 h 07 m `--serve` run through `tools/serve_load.py` (2 clients, 462 rounds, 924 requests, 64 tokens each, + fresh nonces): zero errors, zero resets, decode steady at 8.0-8.7 tok/s aggregate (two clients over a server that + serializes requests; 15-16 s per 128-token round). +- Memory: 65K context + Int8 KV + all 24,576 experts in GTT = 37.2 GiB of 50 GiB (12.8 GiB free); at 131K it is + 38.1 GiB (11.9 GiB free), the whole ladder above. + +## The table + +`tools/hip/gfx1103-hipblaslt-100401.txt`, calibrated with `tools/hip/tune_hipblaslt` over the gfx1150 table's 144 +GEMM cases at T = 64..16384 (the same case list the 890M run used), 32 MiB workspace. Two passes back to back; each +row keeps the solution with the lowest median of all six repetitions, and a row is left out when no candidate beats +plain hipBLAS: **143 rows**, 1.05-23.30x per GEMM, geometric mean 4.95x; the one shape left out is +`bf16 N=1 K=2560 T=64` (best 0.039 ms against 0.024 ms on plain hipBLAS - sub-100 us timings), where the engine +falls back to hipBLASEx by design. Per-row medians and candidate counts: +[tune-summary.csv](tune-summary.csv). `HCD_EXACT` is deliberately **not** in the gfx1103 switches: the table picks +no 1176 / 1177 for the HC down GEMM (`hip_prefill_hcd_exact_parity` skips on that, as it does on gfx1150). Startup +lines: [engine-log-excerpt.txt](engine-log-excerpt.txt). + +## The exact switches and the opt-ins + +- The 17 exact switches are written by setup into the config's `env` for `STRATA_EXPERIMENTAL_GFX1103=1` installs, + the same way the table is (the engine keeps gfx1103 out of its arch defaults: `arch_default_env("gfx1103")` stays + empty). `SETUP_ENV` carries them, so a re-run refreshes them and turning the opt-in off removes them. +- Opt-in, bit-changing: `STRATA_HIP_WMMA`, `STRATA_PF_GEMM`, `STRATA_PF_FUSED`, `STRATA_PA_FAST`, + `STRATA_SELECT_WMMA`, `STRATA_HC_UPMIX`. The measured wins are above; no KL was measured here. + +## Not tested + +- The TheRock-wheel route for gfx1103: the index (`gfx110X-all`) has no 10.x wheels, setup's pin is unchanged, and + a full `setup.sh` install was not run here - the numbers come from the hand build. +- CUDA and SYCL were not built here (no toolchains on this box). The changed files compile for HIP gfx1103 and for + gfx1100;gfx1103;gfx1201; the gfx1103 macros are undefined for CUDA/SYCL, as for the other gfx11 targets. +- The opt-in set beyond one round; KL of any bit-changing switch; other models, other quantizations; contexts past + 131K. +- `--adapt-every 100000` vs the default adaptive tier was run under a partial cache (Phase 5, both clean); the + default tier with the full cache was not A/B'd for resets, because none occurred. diff --git a/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl b/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl new file mode 100644 index 00000000..332ec22a --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/context-ladder-instant.jsonl @@ -0,0 +1,4 @@ +{"depth": 32000, "full": {"prompt_n": 32091, "cache_n": 0, "prompt_ms": 105853.1, "prompt_tps": 303.2, "pred_n": 32, "pred_tps": 16.6, "draft_n": 18, "draft_acc": 16, "wall_s": 107.8}, "incr": {"prompt_n": 15964, "cache_n": 16384, "prompt_ms": 53719.1, "prompt_tps": 297.2, "pred_n": 32, "pred_tps": 16.9, "draft_n": 16, "draft_acc": 15, "wall_s": 55.6}} +{"depth": 64000, "full": {"prompt_n": 64091, "cache_n": 0, "prompt_ms": 276118.9, "prompt_tps": 232.1, "pred_n": 32, "pred_tps": 11.6, "draft_n": 21, "draft_acc": 16, "wall_s": 278.9}, "incr": {"prompt_n": 15196, "cache_n": 49152, "prompt_ms": 73201.0, "prompt_tps": 207.6, "pred_n": 32, "pred_tps": 10.7, "draft_n": 20, "draft_acc": 13, "wall_s": 76.3}} +{"depth": 96000, "full": {"prompt_n": 96096, "cache_n": 0, "prompt_ms": 426208.3, "prompt_tps": 225.5, "pred_n": 32, "pred_tps": 14.8, "draft_n": 20, "draft_acc": 13, "wall_s": 428.4}, "incr": {"prompt_n": 14433, "cache_n": 81920, "prompt_ms": 68127.8, "prompt_tps": 211.9, "pred_n": 32, "pred_tps": 11.7, "draft_n": 20, "draft_acc": 13, "wall_s": 71.0}} +{"depth": 128000, "full": {"prompt_n": 128096, "cache_n": 0, "prompt_ms": 578558.8, "prompt_tps": 221.4, "pred_n": 32, "pred_tps": 13.0, "draft_n": 18, "draft_acc": 15, "wall_s": 581.1}, "incr": {"prompt_n": 13665, "cache_n": 114688, "prompt_ms": 66258.3, "prompt_tps": 206.2, "pred_n": 32, "pred_tps": 13.3, "draft_n": 17, "draft_acc": 16, "wall_s": 68.8}} diff --git a/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl b/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl new file mode 100644 index 00000000..0a44542c --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/context-ladder.jsonl @@ -0,0 +1,7 @@ +{"target": 4000, "prompt_n": 4089, "prompt_ms": 14776.4, "prompt_tps": 276.7, "pred_n": 128, "pred_tps": 16.4, "draft_n": 73, "draft_acc": 57, "wall_s": 22.6, "finish": "length"} +{"target": 8000, "prompt_n": 8090, "prompt_ms": 25738.6, "prompt_tps": 314.3, "pred_n": 128, "pred_tps": 15.9, "draft_n": 75, "draft_acc": 55, "wall_s": 33.8, "finish": "length"} +{"target": 16000, "prompt_n": 16090, "prompt_ms": 51137.1, "prompt_tps": 314.6, "pred_n": 128, "pred_tps": 16.2, "draft_n": 74, "draft_acc": 57, "wall_s": 59.0, "finish": "length"} +{"target": 32000, "prompt_n": 32091, "prompt_ms": 103969.5, "prompt_tps": 308.7, "pred_n": 128, "pred_tps": 15.5, "draft_n": 77, "draft_acc": 56, "wall_s": 112.3, "finish": "length"} +{"target": 64000, "prompt_n": 64091, "prompt_ms": 248265.4, "prompt_tps": 258.2, "pred_n": 128, "pred_tps": 12.1, "draft_n": 83, "draft_acc": 57, "wall_s": 258.9, "finish": "length"} +{"target": 96000, "prompt_n": 96095, "prompt_ms": 445909.7, "prompt_tps": 215.5, "pred_n": 128, "pred_tps": 9.9, "draft_n": 81, "draft_acc": 55, "wall_s": 459.0, "finish": "length"} +{"target": 128000, "prompt_n": 128097, "prompt_ms": 645432.8, "prompt_tps": 198.5, "pred_n": 128, "pred_tps": 9.8, "draft_n": 86, "draft_acc": 55, "wall_s": 658.5, "finish": "length"} diff --git a/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt b/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt new file mode 100644 index 00000000..122c28a6 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/engine-log-excerpt.txt @@ -0,0 +1,35 @@ +strata generate: PCIe probe: 29.4 GB/s host->device (best of 25.6 25.6 26.0 29.4) -> pcie_frac 0.55 (default 0.55) +strata generate: native pack: /data/packs/qwen-q2_0 experts (largest blob 1.38 MB), token embedding Q3_K in mapped host memory (260 MiB, 0.2 s) +strata generate: 1416 MiB of weights loaded from /data/packs/qwen-q2_0 in 0.6 s (303 canonical tensors skipped: served natively) +strata generate: 301 native projection matrices, 1376.20 MiB of weights, in 0.7 s +strata generate: PLE direct read probe: 67528 rows/s (fine) +strata generate: the SSD is kept awake while rows are read: one page of the table after 100 ms without a read, until 60 s after the last request (STRATA_SSD_KEEPALIVE=0 turns it off) +strata generate: profile /src/data/expert-profile.bin: 24576 ranked pairs, built for 24576 slots +strata generate: PLE on, table 320001536 rows of /models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf +strata mtp: draft layer loaded, 799 MiB of VRAM (experts 675, dense 111), files read in 0.47 s (1654 MiB/s) +strata generate: experimental native Q5_K head, 437043200 bytes, in 0.2 s +strata generate: GPU 0: AMD Radeon 780M Graphics (gfx1103) +strata generate: experts via mmap (--mmap-experts; the GGUF shards in place, no experts.bin) +strata generate: GPU host-callback thread started before host-core pinning +strata generate: CPU pool tasks/phase: 24 (automatic), participating threads: 8 +strata generate: 7 pool workers on logical processors 1,2,3,4,5,6,7, the host thread on 0 (draining too) (--host-core first) +strata generate: expert cache 24576 slots, 31.64 GiB of VRAM; policy is +strata generate: the GPU computes the experts in the cache; it rounds differently from the CPU, +strata generate: the profile fill asks for 256 pairs ahead (STRATA_FILL_AHEAD) +strata generate: pre-filled 24576 of 24576 slots from the profile in 21.9 s (1550 MB/s); slot 0 verified +strata generate: routing-aware prefetch on (the next layer's router, file tier) +strata generate: R4 hit path ON - resident experts are computed on the GPU +strata generate: 7 expert-pool workers + the host thread +strata generate: session is up (engine 0.1.43.1) +strata generate: sampling greedy +strata generate: token graph hit path: 24576 resident experts, decided on the device +strata generate: prompt chunk auto: 256 tokens +strata generate: prompt path borrows 191 cache slots (0.25 GiB) +prefill gemm: hipBLASLt tuning enabled (143 rows, gfx1103, version 100401) +strata generate: 191 lent slots refilled in 23.4 ms +strata generate: prefill 1 tokens in 1 chunks, 729.8 ms (1.4 tok/s); experts streamed 0 (0 by DMA, host 0.0 ms), resident 480, on the CPU 0 (share 0.00); PLE 0.9 ms +strata verify: window up to 6 tokens, 54.8 MiB of device buffers (100% VRAM resident: zero-doorbell graph) +strata verify: capturing the 1-token window (14137 MiB of VRAM free) +strata verify: captured the 1-token window (upload no error, sync no error) +strata verify: capturing the 2-token window (14134 MiB of VRAM free) +strata verify: captured the 2-token window (upload no error, sync no error) diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt new file mode 100644 index 00000000..42106f17 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-knobs-results.txt @@ -0,0 +1,15 @@ +spec2-r1 15.93 tok/s +minp0.5-r1 14.71 tok/s +q4all-r1 15.73 tok/s +q4proj-r1 15.71 tok/s +chain4-r1 16.01 tok/s +spec2-r2 15.65 tok/s +minp0.5-r2 14.94 tok/s +q4all-r2 15.39 tok/s +q4proj-r2 15.88 tok/s +chain4-r2 16.37 tok/s +spec2-r3 15.65 tok/s +minp0.5-r3 14.98 tok/s +q4all-r3 15.63 tok/s +q4proj-r3 15.74 tok/s +chain4-r3 15.72 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt new file mode 100644 index 00000000..26ffa400 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-spec-results.txt @@ -0,0 +1,12 @@ +spec2-r1 15.70 tok/s +spec3-r1 15.38 tok/s +spec4-r1 13.98 tok/s +spec6-r1 11.16 tok/s +spec2-r2 15.96 tok/s +spec3-r2 15.89 tok/s +spec4-r2 14.18 tok/s +spec6-r2 11.16 tok/s +spec2-r3 15.78 tok/s +spec3-r3 15.69 tok/s +spec4-r3 14.21 tok/s +spec6-r3 10.85 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt b/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt new file mode 100644 index 00000000..72a59fc9 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase4c-window-results.txt @@ -0,0 +1,6 @@ +window-default-r1 13.72 tok/s +window8192-r1 13.78 tok/s +window4096-r1 14.07 tok/s +window-default-r2 13.63 tok/s +window8192-r2 12.95 tok/s +window4096-r2 13.82 tok/s diff --git a/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt b/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt new file mode 100644 index 00000000..f7b28814 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase5a-results.txt @@ -0,0 +1,12 @@ +thp-off-1 RC=0 +thp-on-1 RC=0 +thp-off-2 RC=0 +thp-on-2 RC=0 +thp-off-3 RC=0 +thp-on-3 RC=0 +thp-off-4 RC=0 +thp-on-4 RC=0 +thp-off-5 RC=0 +thp-on-5 RC=0 +thp-off-6 RC=0 +thp-on-6 RC=0 diff --git a/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt b/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt new file mode 100644 index 00000000..f3f352ca --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/phase5b-results.txt @@ -0,0 +1,7 @@ +== adaptive tier (default), IO prefetch on +adapt-a1 RC=0 GTT-peak=26,7 GiB +adapt-a2 RC=0 GTT-peak=26,7 GiB +== --adapt-every 100000, IO prefetch on +static-b1 RC=0 GTT-peak=26,7 GiB +static-b2 RC=0 GTT-peak=26,7 GiB +== resets: 0 diff --git a/bench/results/2026-10-12-community-gfx1103/runs.csv b/bench/results/2026-10-12-community-gfx1103/runs.csv new file mode 100644 index 00000000..d2756460 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/runs.csv @@ -0,0 +1,61 @@ +config,round,cell,temp,rep,prompt_tokens,prompt_ms,prompt_tok_s,generated,decode_tok_s,drafts_accepted,drafts +s1-base,0,4k,0.0,0,4052,44151.7,91.8,112,13.9,57,93 +s1-base,0,4k,0.0,1,4052,44017.5,92.1,94,13.7,45,69 +s1-base,0,4k,0.7,0,4052,45970.2,88.1,123,12.4,56,105 +s1-base,0,4k,0.7,1,4052,45067.9,89.9,96,12.3,35,64 +s2-table,0,4k,0.0,0,4052,21652.6,187.1,92,14.6,49,68 +s2-table,0,4k,0.0,1,4052,22051.3,183.8,88,14.3,44,60 +s2-table,0,4k,0.7,0,4052,21810.3,185.8,109,13.3,46,72 +s2-table,0,4k,0.7,1,4052,21868.0,185.3,121,13.8,61,93 +s2-table,0,32k,0.0,0,32058,180319.2,177.8,124,13.1,63,95 +s2-table,0,32k,0.7,0,32058,201403.1,159.2,124,11.7,63,114 +s2-table,0,4k,0.0,0,4052,22012.5,184.1,98,13.7,46,69 +s2-table,0,4k,0.0,1,4052,22095.3,183.4,112,14.6,58,79 +s2-table,0,4k,0.7,0,4052,22448.0,180.5,132,15.1,73,97 +s2-table,0,4k,0.7,1,4052,21947.0,184.6,121,15.3,70,95 +s3-table-exact,0,4k,0.0,0,4054,19361.2,209.4,108,13.5,51,89 +s3-table-exact,0,4k,0.0,1,4054,19106.1,212.2,104,13.2,45,80 +s3-table-exact,0,4k,0.7,0,4054,19202.9,211.1,116,13.0,53,98 +s3-table-exact,0,4k,0.7,1,4054,19185.6,211.3,107,13.9,54,90 +s3a-table-prompt5,0,4k,0.0,0,4056,21214.5,191.2,106,15.0,62,82 +s3a-table-prompt5,0,4k,0.0,1,4056,21304.9,190.4,84,13.0,40,72 +s3a-table-prompt5,0,4k,0.7,0,4056,21475.2,188.9,97,12.9,45,73 +s3a-table-prompt5,0,4k,0.7,1,4056,21127.9,192.0,93,12.2,34,68 +s3b-table-decode11,0,4k,0.0,0,4057,20671.5,196.3,94,15.4,48,63 +s3b-table-decode11,0,4k,0.0,1,4057,20289.8,200.0,93,15.2,49,64 +s3b-table-decode11,0,4k,0.7,0,4057,20932.3,193.8,106,12.8,45,85 +s3b-table-decode11,0,4k,0.7,1,4057,22806.7,177.9,113,11.1,53,80 +s4-table-wmma,0,4k,0.0,0,4054,16272.5,249.1,110,13.6,53,84 +s4-table-wmma,0,4k,0.0,1,4054,16446.1,246.5,113,13.3,55,94 +s4-table-wmma,0,4k,0.7,0,4054,16299.7,248.7,119,13.4,55,89 +s4-table-wmma,0,4k,0.7,1,4054,16397.2,247.2,107,13.5,53,84 +s4-table-wmma,0,32k,0.0,0,32060,117646.1,272.5,123,14.3,63,90 +s4-table-wmma,0,32k,0.7,0,32060,127975.8,250.5,134,11.5,63,113 +s5-table-wmma-fused,0,4k,0.0,0,4056,16434.3,246.8,102,14.3,52,74 +s5-table-wmma-fused,0,4k,0.0,1,4056,16579.7,244.6,101,13.3,45,74 +s5-table-wmma-fused,0,4k,0.7,0,4056,16383.0,247.6,129,11.3,55,129 +s5-table-wmma-fused,0,4k,0.7,1,4056,16552.3,245.0,123,12.6,61,117 +s6-table-all,0,4k,0.0,0,4053,14601.2,277.6,91,14.6,45,66 +s6-table-all,0,4k,0.0,1,4053,14716.2,275.4,93,15.0,47,64 +s6-table-all,0,4k,0.7,0,4053,14539.8,278.8,118,13.2,53,99 +s6-table-all,0,4k,0.7,1,4053,14641.3,276.8,109,14.2,53,82 +s6-table-all,0,32k,0.0,0,32059,110471.4,290.2,137,11.9,67,102 +s6-table-all,0,32k,0.7,0,32059,132319.7,242.3,115,12.0,59,100 +strata-base,0,4k,0.0,0,4052,43555.7,93.0,115,12.9,52,95 +strata-base,0,4k,0.0,1,4052,44875.6,90.3,103,12.9,42,74 +strata-base,0,4k,0.7,0,4052,43629.8,92.9,122,13.7,62,96 +strata-base,0,4k,0.7,1,4052,43422.6,93.3,135,14.7,71,97 +strata-base,0,32k,0.0,0,32058,351862.3,91.1,141,13.7,72,108 +strata-base,0,32k,0.7,0,32058,349500.1,91.7,122,13.3,63,97 +strata-table,0,4k,0.0,0,4052,43992.3,92.1,103,13.5,50,76 +strata-table,0,4k,0.0,1,4052,43282.1,93.6,99,13.0,45,78 +strata-table,0,4k,0.7,0,4052,44033.8,92.0,81,12.9,39,70 +strata-table,0,4k,0.7,1,4052,43881.7,92.3,125,14.6,68,99 +strata-table,0,32k,0.0,0,32058,351109.8,91.3,120,13.7,58,86 +strata-table,0,32k,0.7,0,32058,351360.7,91.2,123,12.8,55,96 +strata,0,4k,0.0,0,4051,45084.7,89.9,103,12.2,43,86 +strata,0,4k,0.0,1,4051,45181.7,89.7,104,13.7,49,79 +strata,0,4k,0.7,0,4051,44951.7,90.1,140,15.1,82,110 +strata,0,4k,0.7,1,4051,45055.6,89.9,101,13.3,48,78 +strata,0,32k,0.0,0,32057,356669.0,89.9,109,13.1,54,93 +strata,0,32k,0.7,0,32057,357066.0,89.8,104,13.1,52,85 diff --git a/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl b/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl new file mode 100644 index 00000000..3fa09a6e --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s1-base.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 52.23, "prompt_n": 4052, "prompt_ms": 44151.7, "prompt_tps": 91.8, "pred_n": 112, "pred_tps": 13.9, "draft_n": 93, "draft_acc": 57, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on models like Q2_0 and IQ2_XS. The system offers advanced memory management features, such as KV streaming and hybrid K8V4 ca", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.98, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s1-base.json --port 8190"} +{"wall_s": 50.9, "prompt_n": 4052, "prompt_ms": 44017.5, "prompt_tps": 92.1, "pred_n": 94, "pred_tps": 13.7, "draft_n": 69, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details various memory management strategies, such as KV streaming and hybrid 4-bit caches, whic", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.25, "load_s": 28.0, "cmd": null} +{"wall_s": 55.93, "prompt_n": 4052, "prompt_ms": 45970.2, "prompt_tps": 88.1, "pred_n": 123, "pred_tps": 12.4, "draft_n": 105, "draft_acc": 56, "text": "Strata is a local AI engine that delivers high-speed inference by utilizing fused int8 tensor-core kernels and speculative decoding to optimize both prompt processing and output generation across various model quantizations. The documentation details specific performance benchmarks on hardware like ", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.46, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s1-base.json --port 8190"} +{"wall_s": 52.9, "prompt_n": 4052, "prompt_ms": 45067.9, "prompt_tps": 89.9, "pred_n": 96, "pred_tps": 12.3, "draft_n": 64, "draft_acc": 35, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware by utilizing specialized kernels for prompt processing and speculative decoding to optimize output speeds. The documentation details extensive technical features, including KV cache streaming, hybrid quan", "config": "s1-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.79, "load_s": 28.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl b/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl new file mode 100644 index 00000000..18f9cdf5 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s2-table.jsonl @@ -0,0 +1,10 @@ +{"wall_s": 27.96, "prompt_n": 4052, "prompt_ms": 21652.6, "prompt_tps": 187.1, "pred_n": 92, "pred_tps": 14.6, "draft_n": 68, "draft_acc": 49, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific benchmark results for prompt processing and output generation across different mo", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.9, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 28.23, "prompt_n": 4052, "prompt_ms": 22051.3, "prompt_tps": 183.8, "pred_n": 88, "pred_tps": 14.3, "draft_n": 60, "draft_acc": 44, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific benchmark results for prompt processing and output generation across different mo", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.19, "load_s": 30.0, "cmd": null} +{"wall_s": 30.02, "prompt_n": 4052, "prompt_ms": 21810.3, "prompt_tps": 185.8, "pred_n": 109, "pred_tps": 13.3, "draft_n": 72, "draft_acc": 46, "text": "Strata is a local AI engine that delivers high-speed inference by utilizing fused int8 tensor-core kernels and speculative decoding to significantly boost prompt processing and output speeds across various GPU hardware. The system supports advanced memory management features like KV streaming and hy", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.48, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 30.65, "prompt_n": 4052, "prompt_ms": 21868.0, "prompt_tps": 185.3, "pred_n": 121, "pred_tps": 13.8, "draft_n": 93, "draft_acc": 61, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance improvements in version 0.1.36 driven by fused kernels and speculative decoding. The documentation details technical optimizations such as KV ca", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.74, "load_s": 30.0, "cmd": null} +{"wall_s": 189.86, "prompt_n": 32058, "prompt_ms": 180319.2, "prompt_tps": 177.8, "pred_n": 124, "pred_tps": 13.1, "draft_n": 95, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "s2-table", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.02, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 212.05, "prompt_n": 32058, "prompt_ms": 201403.1, "prompt_tps": 159.2, "pred_n": 124, "pred_tps": 11.7, "draft_n": 114, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer GPUs, featuring advanced memory management techniques like KV streaming, hybrid KV caches, and low-RAM modes to enable efficient execution on machines with limited hardware resources. The system provides a comprehensive ", "config": "s2-table", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.84, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.2, "prompt_n": 4052, "prompt_ms": 22012.5, "prompt_tps": 184.1, "pred_n": 98, "pred_tps": 13.7, "draft_n": 69, "draft_acc": 46, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring advanced techniques like fused int8 kernels, KV streaming, and speculative decoding to significantly improve prompt processing and output rates. The documentation provides detailed benchmark data for various models and G", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.86, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.78, "prompt_n": 4052, "prompt_ms": 22095.3, "prompt_tps": 183.4, "pred_n": 112, "pred_tps": 14.6, "draft_n": 79, "draft_acc": 58, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on models like Q2_0 and IQ2_XS. The documentation details various memory management techniques, such as KV streaming and hybri", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.17, "load_s": 30.0, "cmd": null} +{"wall_s": 31.18, "prompt_n": 4052, "prompt_ms": 22448.0, "prompt_tps": 180.5, "pred_n": 132, "pred_tps": 15.1, "draft_n": 97, "draft_acc": 73, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance metrics detailed for both prompt processing and output generation across different context lengths. The engine employs advanced optimization tec", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.43, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s2-table.json --port 8190"} +{"wall_s": 29.88, "prompt_n": 4052, "prompt_ms": 21947.0, "prompt_tps": 184.6, "pred_n": 121, "pred_tps": 15.3, "draft_n": 95, "draft_acc": 70, "text": "Strata is a local AI engine that delivers high-speed inference for various quantized models on GPUs like the RTX 5070 and AMD RX 7900 XTX, with performance metrics detailed for both prompt processing and output generation. The engine employs advanced optimizations such as KV streaming, hybrid KV cac", "config": "s2-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.71, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl b/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl new file mode 100644 index 00000000..a75be13b --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3-table-exact.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 27.39, "prompt_n": 4054, "prompt_ms": 19361.2, "prompt_tps": 209.4, "pred_n": 108, "pred_tps": 13.5, "draft_n": 89, "draft_acc": 51, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 tensor-core kernels and thread-block clusters that significantly improve prompt processing and output speeds for models like Q2_0. The documentation details various memory management techni", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.96, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3-table-exact.json --port 8190"} +{"wall_s": 26.98, "prompt_n": 4054, "prompt_ms": 19106.1, "prompt_tps": 212.2, "pred_n": 104, "pred_tps": 13.2, "draft_n": 80, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 tensor-core kernels and thread-block clusters that significantly improve prompt processing and output speeds. The documentation details various memory management techniques, such as KV stre", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.23, "load_s": 30.0, "cmd": null} +{"wall_s": 28.14, "prompt_n": 4054, "prompt_ms": 19202.9, "prompt_tps": 211.1, "pred_n": 116, "pred_tps": 13.0, "draft_n": 98, "draft_acc": 53, "text": "Strata is a high-performance AI engine optimized for long-context processing, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding on modern GPUs like the RTX 5070. The system offers flexible memory management options, including KV streaming, 4-bit", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.52, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3-table-exact.json --port 8190"} +{"wall_s": 26.89, "prompt_n": 4054, "prompt_ms": 19185.6, "prompt_tps": 211.3, "pred_n": 107, "pred_tps": 13.9, "draft_n": 90, "draft_acc": 54, "text": "Strata is a high-performance AI engine optimized for GPUs like the RTX 5070 and AMD RX 7900 XTX, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding. The documentation details various configuration options for memory management, such as KV streami", "config": "s3-table-exact", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.8, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl b/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl new file mode 100644 index 00000000..a29fc736 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3a-table-prompt5.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 28.31, "prompt_n": 4056, "prompt_ms": 21214.5, "prompt_tps": 191.2, "pred_n": 106, "pred_tps": 15.0, "draft_n": 82, "draft_acc": 62, "text": "Strata is a high-performance AI engine optimized for various GPUs, featuring significant speed improvements in version 0.1.36 through fused int8 tensor-core kernels and thread-block clusters for both prompt processing and output generation. The engine offers advanced memory management options, such ", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.84, "load_s": 32.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3a-table-prompt5.json --port 8190"} +{"wall_s": 27.77, "prompt_n": 4056, "prompt_ms": 21304.9, "prompt_tps": 190.4, "pred_n": 84, "pred_tps": 13.0, "draft_n": 72, "draft_acc": 40, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and hardware configurations, hig", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.15, "load_s": 32.0, "cmd": null} +{"wall_s": 29.03, "prompt_n": 4056, "prompt_ms": 21475.2, "prompt_tps": 188.9, "pred_n": 97, "pred_tps": 12.9, "draft_n": 73, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on consumer hardware, achieving high prompt processing and output throughput through techniques like speculative decoding, KV cache streaming, and fused tensor-core kernels. The documentation provides detailed performance benchmarks across various GPU ", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.41, "load_s": 32.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3a-table-prompt5.json --port 8190"} +{"wall_s": 28.76, "prompt_n": 4056, "prompt_ms": 21127.9, "prompt_tps": 192.0, "pred_n": 93, "pred_tps": 12.2, "draft_n": 68, "draft_acc": 34, "text": "Strata is a high-performance local AI engine that achieves significant speed improvements through optimized fused kernels, speculative decoding, and advanced KV cache management techniques like streaming and hybrid quantization. The documentation provides detailed benchmark data for various models o", "config": "s3a-table-prompt5", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.68, "load_s": 32.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl b/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl new file mode 100644 index 00000000..ed427d3b --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s3b-table-decode11.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 26.8, "prompt_n": 4057, "prompt_ms": 20671.5, "prompt_tps": 196.3, "pred_n": 94, "pred_tps": 15.4, "draft_n": 63, "draft_acc": 48, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and context lengths, highlightin", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.17, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3b-table-decode11.json --port 8190"} +{"wall_s": 26.41, "prompt_n": 4057, "prompt_ms": 20289.8, "prompt_tps": 200.0, "pred_n": 93, "pred_tps": 15.2, "draft_n": 64, "draft_acc": 49, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for prompt processing and output generation across differe", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.25, "load_s": 30.0, "cmd": null} +{"wall_s": 29.21, "prompt_n": 4057, "prompt_ms": 20932.3, "prompt_tps": 193.8, "pred_n": 106, "pred_tps": 12.8, "draft_n": 85, "draft_acc": 45, "text": "Strata is a local AI engine that achieves high performance on consumer hardware by using speculative decoding, fused tensor-core kernels, and memory-efficient KV cache options like streaming and hybrid formats to maximize speed and context capacity. The documentation provides detailed benchmark data", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.55, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s3b-table-decode11.json --port 8190"} +{"wall_s": 32.99, "prompt_n": 4057, "prompt_ms": 22806.7, "prompt_tps": 177.9, "pred_n": 113, "pred_tps": 11.1, "draft_n": 80, "draft_acc": 53, "text": "Strata is a high-performance AI inference engine that achieves significant speed improvements through advanced techniques like fused int8 tensor-core kernels, speculative decoding, and dynamic KV cache streaming. The documentation provides detailed benchmark data for various models on different hard", "config": "s3b-table-decode11", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.84, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl b/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl new file mode 100644 index 00000000..2dbf45a8 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s4-table-wmma.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 24.35, "prompt_n": 4054, "prompt_ms": 16272.5, "prompt_tps": 249.1, "pred_n": 110, "pred_tps": 13.6, "draft_n": 84, "draft_acc": 53, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on RTX 30 and newer GPUs. The documentation details various memory optimization techniques, such as KV streaming and hybrid K8", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.9, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 24.93, "prompt_n": 4054, "prompt_ms": 16446.1, "prompt_tps": 246.5, "pred_n": 113, "pred_tps": 13.3, "draft_n": 94, "draft_acc": 55, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding on RTX 30 and newer GPUs. The documentation details various memory management techniques, such as KV streaming and hybrid K8V4", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.18, "load_s": 30.0, "cmd": null} +{"wall_s": 25.19, "prompt_n": 4054, "prompt_ms": 16299.7, "prompt_tps": 248.7, "pred_n": 119, "pred_tps": 13.4, "draft_n": 89, "draft_acc": 55, "text": "Strata is a high-performance local AI engine that leverages advanced optimization techniques, such as fused int8 tensor-core kernels and KV streaming, to significantly improve prompt and output speeds across various model sizes and hardware configurations. The documentation details specific performa", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.47, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 24.31, "prompt_n": 4054, "prompt_ms": 16397.2, "prompt_tps": 247.2, "pred_n": 107, "pred_tps": 13.5, "draft_n": 84, "draft_acc": 53, "text": "Strata is a high-performance local AI engine that leverages advanced optimization techniques, such as fused int8 tensor-core kernels and KV streaming, to achieve significant speedups in prompt processing and output generation across various GPU architectures. The documentation provides detailed benc", "config": "s4-table-wmma", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.76, "load_s": 30.0, "cmd": null} +{"wall_s": 126.27, "prompt_n": 32060, "prompt_ms": 117646.1, "prompt_tps": 272.5, "pred_n": 123, "pred_tps": 14.3, "draft_n": 90, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "s4-table-wmma", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.0, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} +{"wall_s": 139.7, "prompt_n": 32060, "prompt_ms": 127975.8, "prompt_tps": 250.5, "pred_n": 134, "pred_tps": 11.5, "draft_n": 113, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that delivers high-speed inference on NVIDIA and AMD GPUs by leveraging advanced techniques like speculative decoding, KV cache streaming, and adaptive expert tiering to balance CPU and VRAM resources. The system provides a comprehe", "config": "s4-table-wmma", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.81, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s4-table-wmma.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl b/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl new file mode 100644 index 00000000..ab66364c --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s5-table-wmma-fused.jsonl @@ -0,0 +1,4 @@ +{"wall_s": 23.56, "prompt_n": 4056, "prompt_ms": 16434.3, "prompt_tps": 246.8, "pred_n": 102, "pred_tps": 14.3, "draft_n": 74, "draft_acc": 52, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different models and context lengths, highlighting fea", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.14, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s5-table-wmma-fused.json --port 8190"} +{"wall_s": 24.2, "prompt_n": 4056, "prompt_ms": 16579.7, "prompt_tps": 244.6, "pred_n": 101, "pred_tps": 13.3, "draft_n": 74, "draft_acc": 45, "text": "Strata is a high-performance AI engine that achieves significant speed improvements through fused int8 tensor-core kernels and speculative decoding, with benchmark data showing substantial gains in prompt processing and output generation across various model sizes. The system offers advanced memory ", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.21, "load_s": 30.0, "cmd": null} +{"wall_s": 27.83, "prompt_n": 4056, "prompt_ms": 16383.0, "prompt_tps": 247.6, "pred_n": 129, "pred_tps": 11.3, "draft_n": 129, "draft_acc": 55, "text": "Strata is an AI engine optimized for RTX 5070 and AMD GPUs that achieves significant speed improvements through fused int8 tensor-core kernels, thread-block clusters, and speculative decoding. The documentation details various performance benchmarks for prompt processing and output tokens per second", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.5, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s5-table-wmma-fused.json --port 8190"} +{"wall_s": 26.29, "prompt_n": 4056, "prompt_ms": 16552.3, "prompt_tps": 245.0, "pred_n": 123, "pred_tps": 12.6, "draft_n": 117, "draft_acc": 61, "text": "Strata is an AI engine optimized for RTX 30 and newer GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding for prompt processing and output generation. The documentation details various configuration options, such as KV cache streaming, hybri", "config": "s5-table-wmma-fused", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.77, "load_s": 30.0, "cmd": null} diff --git a/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl b/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl new file mode 100644 index 00000000..3e66c01f --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/s6-table-all.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 20.86, "prompt_n": 4053, "prompt_ms": 14601.2, "prompt_tps": 277.6, "pred_n": 91, "pred_tps": 14.6, "draft_n": 66, "draft_acc": 45, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for different model sizes and hardware configurations, hig", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.12, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 20.94, "prompt_n": 4053, "prompt_ms": 14716.2, "prompt_tps": 275.4, "pred_n": 93, "pred_tps": 15.0, "draft_n": 64, "draft_acc": 47, "text": "Strata is a high-performance AI engine optimized for various GPUs, achieving significant speed improvements through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details specific performance benchmarks for prompt processing and output generation across differe", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.39, "load_s": 30.0, "cmd": null} +{"wall_s": 23.46, "prompt_n": 4053, "prompt_ms": 14539.8, "prompt_tps": 278.8, "pred_n": 118, "pred_tps": 13.2, "draft_n": 99, "draft_acc": 53, "text": "Strata is a local AI engine that achieves high performance through speculative decoding, KV cache streaming, and fused tensor-core kernels, with benchmark results demonstrating significant speed improvements across various model sizes and GPU configurations. The engine offers advanced memory managem", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.67, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 22.33, "prompt_n": 4053, "prompt_ms": 14641.3, "prompt_tps": 276.8, "pred_n": 109, "pred_tps": 14.2, "draft_n": 82, "draft_acc": 53, "text": "Strata is a high-performance AI engine optimized for various hardware configurations, featuring significant speed improvements in version 0.1.36 through fused int8 tensor-core kernels and specialized decode path optimizations. The documentation details extensive technical benchmarks for prompt proce", "config": "s6-table-all", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.95, "load_s": 30.0, "cmd": null} +{"wall_s": 122.05, "prompt_n": 32059, "prompt_ms": 110471.4, "prompt_tps": 290.2, "pred_n": 137, "pred_tps": 11.9, "draft_n": 102, "draft_acc": 67, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API compatible ", "config": "s6-table-all", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.11, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} +{"wall_s": 141.96, "prompt_n": 32059, "prompt_ms": 132319.7, "prompt_tps": 242.3, "pred_n": 115, "pred_tps": 12.0, "draft_n": 100, "draft_acc": 59, "text": "Strata is a local LLM engine optimized for Qwen3.8-Flash-Next models that utilizes advanced techniques like speculative decoding, KV cache streaming, and low-RAM expert mapping to achieve high prompt processing and output speeds on consumer GPUs. The document details extensive technical configuratio", "config": "s6-table-all", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.83, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-s6-table-all.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl b/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl new file mode 100644 index 00000000..bd483f86 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-base.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 52.49, "prompt_n": 4052, "prompt_ms": 43555.7, "prompt_tps": 93.0, "pred_n": 115, "pred_tps": 12.9, "draft_n": 95, "draft_acc": 52, "text": "Strata is a local AI engine optimized for speed on specific hardware configurations, featuring advanced techniques like KV streaming, speculative decoding, and fused tensor-core kernels to significantly improve prompt processing and output generation rates. The documentation provides detailed benchm", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.6, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 52.86, "prompt_n": 4052, "prompt_ms": 44875.6, "prompt_tps": 90.3, "pred_n": 103, "pred_tps": 12.9, "draft_n": 74, "draft_acc": 42, "text": "Strata is a local AI engine optimized for speed and memory efficiency, featuring recent updates like fused int8 tensor-core kernels and KV streaming that significantly improve prompt processing and output rates on various GPUs. The documentation details specific performance benchmarks for different ", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.87, "load_s": 28.0, "cmd": null} +{"wall_s": 52.52, "prompt_n": 4052, "prompt_ms": 43629.8, "prompt_tps": 92.9, "pred_n": 122, "pred_tps": 13.7, "draft_n": 96, "draft_acc": 62, "text": "Strata is a local AI engine that delivers high-speed performance through optimized kernels and speculative decoding, achieving over 1,000 tokens per second in prompt processing and approximately 90 tokens per second in output on an RTX 5070. The document details various memory-saving features, such ", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.15, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 52.64, "prompt_n": 4052, "prompt_ms": 43422.6, "prompt_tps": 93.3, "pred_n": 135, "pred_tps": 14.7, "draft_n": 97, "draft_acc": 71, "text": "Strata is a local AI engine that delivers high-speed performance through optimized kernels and speculative decoding, achieving over 1,000 tokens per second in prompt processing and nearly 100 tokens per second in output on modern hardware like the RTX 5070. The engine features advanced memory manage", "config": "strata-base", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.46, "load_s": 28.0, "cmd": null} +{"wall_s": 362.21, "prompt_n": 32058, "prompt_ms": 351862.3, "prompt_tps": 91.1, "pred_n": 141, "pred_tps": 13.7, "draft_n": 108, "draft_acc": 72, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "strata-base", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.86, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} +{"wall_s": 358.73, "prompt_n": 32058, "prompt_ms": 349500.1, "prompt_tps": 91.7, "pred_n": 122, "pred_tps": 13.3, "draft_n": 97, "draft_acc": 63, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer hardware, offering detailed performance metrics for various GPU configurations and features like KV streaming, low-RAM modes, and speculative decoding to balance speed and quality. It supports multiple API interfaces (Op", "config": "strata-base", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.64, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-base.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json b/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json new file mode 100644 index 00000000..041888b6 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-gfx1103.json @@ -0,0 +1,34 @@ +{ + "exe": "~/llm/Strata/build-780m/strata", + "args": [ + "--pack", "/data/packs/qwen-q2_0", + "--native", "/models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf", + "--ple-gguf", "/models/flash-next/Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf", + "--expert-profile", "~/llm/Strata/data/expert-profile.bin", + "--expert-cache", "24576", + "--mmap-experts", + "--prefill", "auto", + "--spec", "2", + "--lookup-chain", "4", + "--mtp", "/data/mtp/rt", + "--max-context", "32768", + "--kv", "int8", + "--conversation-cache-mib", "12288", + "--conversation-cache-slots", "8", + "--vram-reserve-mib", "700" + ], + "cwd": "~/llm/Strata", + "tokenizer": "/data/packs/qwen-q2_0/tokenizer", + "model_name": "qwen3.8-flash-next", + "aliases": ["flash-next-q2"], + "port": 8080, + "backend": "hip", + "env": { + "STRATA_HIPBLASLT_TUNING": "~/llm/Strata/tools/hip/gfx1103-hipblaslt-100401.txt", + "STRATA_GDN_HEAD": "1", "STRATA_GDN_PP": "2", "STRATA_GDN_CONVL2": "1", "STRATA_GDN_NOY": "1", + "STRATA_CVEC_FUSE": "1", "STRATA_PF_PAD": "1", + "STRATA_Q8_PACKED": "1", "STRATA_Q6_PACKED": "1", "STRATA_MMVF_ROWS": "1", "STRATA_ATTN_LANECELL": "1", + "STRATA_EXPERT_V2": "1", "STRATA_TSUM": "1", "STRATA_LFUSE": "1", "STRATA_GDN_SPLIT": "1", + "STRATA_QFUSE": "1", "STRATA_PLE_BATCH": "1", "STRATA_SH_STREAM": "1" + } +} diff --git a/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl b/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl new file mode 100644 index 00000000..8eb02b7a --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata-table.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 51.65, "prompt_n": 4052, "prompt_ms": 43992.3, "prompt_tps": 92.1, "pred_n": 103, "pred_tps": 13.5, "draft_n": 76, "draft_acc": 50, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving high prompt and output token rates through techniques like fused int8 kernels, speculative decoding, and KV cache streaming. The documentation details performance benchmarks across various models and GPUs, highlighting s", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 38.87, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 50.89, "prompt_n": 4052, "prompt_ms": 43282.1, "prompt_tps": 93.6, "pred_n": 99, "pred_tps": 13.0, "draft_n": 78, "draft_acc": 45, "text": "Strata is a local AI engine optimized for speed on specific hardware, achieving significant performance gains through fused int8 tensor-core kernels and speculative decoding techniques. The documentation details various memory management strategies, such as KV streaming and hybrid K8V4 caches, which", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.15, "load_s": 28.0, "cmd": null} +{"wall_s": 50.33, "prompt_n": 4052, "prompt_ms": 44033.8, "prompt_tps": 92.0, "pred_n": 81, "pred_tps": 12.9, "draft_n": 70, "draft_acc": 39, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware, achieving significant speed improvements through optimized kernels and speculative decoding techniques. It offers flexible memory management features, such as KV streaming and hybrid 4-bit caches, to ena", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.44, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 52.46, "prompt_n": 4052, "prompt_ms": 43881.7, "prompt_tps": 92.3, "pred_n": 125, "pred_tps": 14.6, "draft_n": 99, "draft_acc": 68, "text": "Strata is a local AI engine that delivers high-speed inference performance on consumer hardware, achieving over 1,000 tokens per second for prompt processing and 50-90 tokens per second for output on models like Q2_0 and IQ3_XXS. The system utilizes advanced optimization techniques, including specul", "config": "strata-table", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 39.71, "load_s": 28.0, "cmd": null} +{"wall_s": 359.89, "prompt_n": 32058, "prompt_ms": 351109.8, "prompt_tps": 91.3, "pred_n": 120, "pred_tps": 13.7, "draft_n": 86, "draft_acc": 58, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, adaptive expert caching, and low-RAM modes to efficiently manage large model weights across GPU and system memory. It provides a comprehensive API co", "config": "strata-table", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.26, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} +{"wall_s": 361.01, "prompt_n": 32058, "prompt_ms": 351360.7, "prompt_tps": 91.2, "pred_n": 123, "pred_tps": 12.8, "draft_n": 96, "draft_acc": 55, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models on consumer hardware, featuring advanced memory management techniques like KV streaming, hybrid KV caches, and low-RAM modes to enable 64-bit context windows on systems with 32-64 GB RAM. It supports a flexible API compatible with O", "config": "strata-table", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 41.07, "load_s": 28.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata-table.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/strata.jsonl b/bench/results/2026-10-12-community-gfx1103/strata.jsonl new file mode 100644 index 00000000..79dac1dd --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/strata.jsonl @@ -0,0 +1,6 @@ +{"wall_s": 53.56, "prompt_n": 4051, "prompt_ms": 45084.7, "prompt_tps": 89.9, "pred_n": 103, "pred_tps": 12.2, "draft_n": 86, "draft_acc": 43, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring recent updates like fused int8 kernels and thread-block clusters that significantly improve prompt processing and output speeds for models like Q2_0. The documentation details various memory management techniques, such a", "config": "strata", "round": 0, "cell": "4k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 38.86, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 52.81, "prompt_n": 4051, "prompt_ms": 45181.7, "prompt_tps": 89.7, "pred_n": 104, "pred_tps": 13.7, "draft_n": 79, "draft_acc": 49, "text": "Strata is a local AI engine optimized for speed on specific hardware, featuring advanced techniques like fused int8 kernels, KV streaming, and speculative decoding to significantly improve prompt processing and output generation rates. The documentation provides detailed benchmark data for various m", "config": "strata", "round": 0, "cell": "4k", "temp": 0.0, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.14, "load_s": 30.0, "cmd": null} +{"wall_s": 54.22, "prompt_n": 4051, "prompt_ms": 44951.7, "prompt_tps": 90.1, "pred_n": 140, "pred_tps": 15.1, "draft_n": 110, "draft_acc": 82, "text": "The Strata engine achieves significant performance improvements in version 0.1.36 through fused int8 tensor-core kernels and thread-block clusters, resulting in 16\u201322% faster prompt processing and higher output speeds for models like Q2_0. To handle large context windows efficiently, the system supp", "config": "strata", "round": 0, "cell": "4k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.41, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 52.64, "prompt_n": 4051, "prompt_ms": 45055.6, "prompt_tps": 89.9, "pred_n": 101, "pred_tps": 13.3, "draft_n": 78, "draft_acc": 48, "text": "The Strata engine delivers high performance on RTX 5070 hardware, achieving significant speed improvements in prompt processing and output generation through optimized fused kernels and speculative decoding. The technical documentation details various configuration options, such as KV cache streamin", "config": "strata", "round": 0, "cell": "4k", "temp": 0.7, "rep": 1, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.23, "sys_used_delta_gib": 39.72, "load_s": 30.0, "cmd": null} +{"wall_s": 365.07, "prompt_n": 32057, "prompt_ms": 356669.0, "prompt_tps": 89.9, "pred_n": 109, "pred_tps": 13.1, "draft_n": 93, "draft_acc": 54, "text": "Strata is a local AI engine optimized for Qwen3.8-Flash-Next models that achieves high performance on consumer hardware by using speculative decoding, KV cache streaming, and adaptive expert caching to manage memory efficiently. It provides a comprehensive API compatible with OpenAI, Anthropic, and ", "config": "strata", "round": 0, "cell": "32k", "temp": 0.0, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.11, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} +{"wall_s": 365.03, "prompt_n": 32057, "prompt_ms": 357066.0, "prompt_tps": 89.8, "pred_n": 104, "pred_tps": 13.1, "draft_n": 85, "draft_acc": 52, "text": "Strata is a local AI engine for Qwen3.8-Flash-Next models that utilizes MTP speculative decoding and an adaptive expert caching system to optimize speed on consumer hardware. It offers a comprehensive API compatible with OpenAI, Anthropic, and MCP standards, featuring extensive configuration options", "config": "strata", "round": 0, "cell": "32k", "temp": 0.7, "rep": 0, "vram_peak_mib": 0, "vram_base_mib": -1, "rss_peak_gib": 0.24, "sys_used_delta_gib": 40.92, "load_s": 30.0, "cmd": "/usr/bin/python3 /home/alexis/llm/Strata/serve/server.py --engine strata --config /tmp/opencode/bench-780m/strata-cfg-strata.json --port 8190"} diff --git a/bench/results/2026-10-12-community-gfx1103/tune-summary.csv b/bench/results/2026-10-12-community-gfx1103/tune-summary.csv new file mode 100644 index 00000000..12c6a314 --- /dev/null +++ b/bench/results/2026-10-12-community-gfx1103/tune-summary.csv @@ -0,0 +1,144 @@ +dtype,T,N,K,ldy,hipblas_ms,hipblaslt_ms,speedup,solution_id,candidates +f16,16384,12288,2560,12288,651.4479,197.0342,3.31,6137,7 +f16,16384,10240,2560,10240,542.8069,166.0204,3.27,6137,7 +f16,16384,6144,2560,6144,345.9530,96.6217,3.58,6137,7 +f16,16384,2560,6144,2560,390.0417,107.3124,3.63,6137,7 +f16,16384,2560,640,2560,33.6158,13.3609,2.52,6137,7 +f16,16384,640,2560,640,33.8896,10.0479,3.37,6137,7 +f16,16384,512,2560,512,29.6666,7.9387,3.74,6137,7 +bf16,16384,10240,2560,10240,631.0419,160.4246,3.93,5532,9 +bf16,16384,10240,320,10240,75.3301,19.1821,3.93,5532,9 +bf16,16384,320,10240,320,89.4026,21.8081,4.10,5532,9 +bf16,16384,2560,2560,2560,157.4283,39.5652,3.98,5532,9 +bf16,16384,512,2560,512,32.5609,7.6947,4.23,5532,9 +bf16,16384,128,2560,128,13.7590,2.2721,6.06,5532,9 +bf16,16384,48,2560,96,18.4464,1.3195,13.98,5532,9 +bf16,16384,4,10240,4,52.5905,4.1701,12.61,5529,9 +bf16,16384,1,2560,1,3.0841,1.1410,2.70,5529,9 +f16,8192,12288,2560,12288,323.5122,94.2652,3.43,6137,7 +f16,8192,10240,2560,10240,273.5645,77.9223,3.51,6137,7 +f16,8192,6144,2560,6144,167.4047,44.9688,3.72,6137,7 +f16,8192,2560,6144,2560,196.8117,50.2592,3.92,6137,7 +f16,8192,2560,640,2560,21.1493,8.6701,2.44,6137,7 +f16,8192,640,2560,640,20.6502,4.4961,4.59,6137,7 +f16,8192,512,2560,512,18.8066,3.2986,5.70,6137,7 +bf16,8192,10240,2560,10240,328.2333,77.4579,4.24,5532,9 +bf16,8192,10240,320,10240,36.8328,13.6604,2.70,5532,9 +bf16,8192,320,10240,320,42.6251,10.7526,3.96,5532,9 +bf16,8192,2560,2560,2560,76.3570,21.3682,3.57,5532,9 +bf16,8192,512,2560,512,18.9671,3.2273,5.88,5532,9 +bf16,8192,128,2560,128,8.8628,1.1204,7.91,5532,9 +bf16,8192,48,2560,96,13.5616,0.6895,19.67,5532,9 +bf16,8192,4,10240,4,27.3588,2.1101,12.97,5531,9 +bf16,8192,1,2560,1,1.5131,0.6191,2.44,5531,9 +f16,4096,12288,2560,12288,169.7946,44.4350,3.82,6137,7 +f16,4096,10240,2560,10240,147.1302,36.6967,4.01,6137,7 +f16,4096,6144,2560,6144,92.1636,23.4922,3.92,6137,7 +f16,4096,2560,6144,2560,97.8004,23.0363,4.25,6137,7 +f16,4096,2560,640,2560,13.9061,2.9316,4.74,6137,7 +f16,4096,640,2560,640,14.5406,2.2543,6.45,6137,7 +f16,4096,512,2560,512,13.3511,1.6140,8.27,6137,7 +bf16,4096,10240,2560,10240,153.4310,37.0421,4.14,5532,9 +bf16,4096,10240,320,10240,21.1589,9.1450,2.31,5532,9 +bf16,4096,320,10240,320,23.4575,4.9431,4.75,5532,9 +bf16,4096,2560,2560,2560,37.1116,9.1205,4.07,5532,9 +bf16,4096,512,2560,512,9.7326,1.5817,6.15,5532,9 +bf16,4096,128,2560,128,2.5324,0.5845,4.33,5532,9 +bf16,4096,48,2560,96,4.8128,0.3308,14.55,5532,9 +bf16,4096,4,10240,4,18.7145,1.0724,17.45,5529,9 +bf16,4096,1,2560,1,0.4450,0.2940,1.51,5531,9 +f16,2048,12288,2560,12288,82.5431,22.2695,3.71,6137,7 +f16,2048,10240,2560,10240,68.3010,19.7460,3.46,6137,7 +f16,2048,6144,2560,6144,40.8165,11.5715,3.53,6137,7 +f16,2048,2560,6144,2560,48.3422,10.4967,4.61,6137,7 +f16,2048,2560,640,2560,5.9756,1.0463,5.71,6137,7 +f16,2048,640,2560,640,10.7108,1.0926,9.80,6137,7 +f16,2048,512,2560,512,9.7222,0.8346,11.65,6137,7 +bf16,2048,10240,2560,10240,81.5673,19.6505,4.15,5532,9 +bf16,2048,10240,320,10240,14.3898,4.8025,3.00,5532,9 +bf16,2048,320,10240,320,16.2767,2.3612,6.89,5532,9 +bf16,2048,2560,2560,2560,19.4104,3.8451,5.05,5532,9 +bf16,2048,512,2560,512,4.1245,0.8258,4.99,5532,9 +bf16,2048,128,2560,128,1.0089,0.2817,3.58,5532,9 +bf16,2048,48,2560,96,1.9788,0.1633,12.12,5532,9 +bf16,2048,4,10240,4,13.6673,0.5865,23.30,5531,9 +bf16,2048,1,2560,1,0.2029,0.1502,1.35,5531,9 +f16,1024,12288,2560,12288,42.6525,11.6712,3.65,6137,7 +f16,1024,10240,2560,10240,32.8025,9.3415,3.51,6137,7 +f16,1024,6144,2560,6144,22.8920,5.3547,4.28,6137,7 +f16,1024,2560,6144,2560,24.7134,4.6159,5.35,6137,7 +f16,1024,2560,640,2560,2.9783,0.5994,4.97,6137,7 +f16,1024,640,2560,640,6.1688,0.6388,9.66,6137,7 +f16,1024,512,2560,512,4.4970,0.4833,9.30,6137,7 +bf16,1024,10240,2560,10240,36.5673,9.0905,4.02,5532,9 +bf16,1024,10240,320,10240,7.0192,2.4893,2.82,5532,9 +bf16,1024,320,10240,320,10.8369,1.2971,8.36,5532,9 +bf16,1024,2560,2560,2560,9.6968,2.0858,4.65,5532,9 +bf16,1024,512,2560,512,1.9058,0.4493,4.24,5532,9 +bf16,1024,128,2560,128,0.5103,0.1348,3.78,5532,9 +bf16,1024,48,2560,96,0.9148,0.1033,8.85,5531,9 +bf16,1024,4,10240,4,5.3652,0.3247,16.52,5529,9 +bf16,1024,1,2560,1,0.1859,0.0915,2.03,5530,9 +f16,512,12288,2560,12288,23.0393,4.8510,4.75,6137,7 +f16,512,10240,2560,10240,20.9931,4.0471,5.19,6137,7 +f16,512,6144,2560,6144,16.4222,2.3456,7.00,6137,7 +f16,512,2560,6144,2560,16.6570,2.2563,7.38,6137,7 +f16,512,2560,640,2560,1.1452,0.3358,3.41,6137,7 +f16,512,640,2560,640,2.7805,0.3833,7.25,6137,7 +f16,512,512,2560,512,2.3714,0.4154,5.71,6137,7 +bf16,512,10240,2560,10240,21.5507,4.0228,5.36,5532,9 +bf16,512,10240,320,10240,2.4796,0.8281,2.99,5532,9 +bf16,512,320,10240,320,7.0230,0.5453,12.88,5532,9 +bf16,512,2560,2560,2560,5.4400,1.0147,5.36,5532,9 +bf16,512,512,2560,512,1.0290,0.2863,3.59,5532,9 +bf16,512,128,2560,128,0.3998,0.0895,4.46,5531,9 +bf16,512,48,2560,96,0.4848,0.0623,7.78,5531,9 +bf16,512,4,10240,4,2.1638,0.1797,12.04,5529,9 +bf16,512,1,2560,1,0.1092,0.0493,2.22,5530,9 +f16,256,12288,2560,12288,16.0630,2.7367,5.87,6137,7 +f16,256,10240,2560,10240,15.1772,2.3952,6.34,6137,7 +f16,256,6144,2560,6144,11.4429,1.3735,8.33,6137,7 +f16,256,2560,6144,2560,12.2967,1.5591,7.89,6137,7 +f16,256,2560,640,2560,0.5889,0.2377,2.48,6136,7 +f16,256,640,2560,640,1.0700,0.2277,4.70,6137,7 +f16,256,512,2560,512,1.1540,0.2318,4.98,6137,7 +bf16,256,10240,2560,10240,15.0066,2.3144,6.48,5532,9 +bf16,256,10240,320,10240,1.1594,0.3223,3.60,5532,9 +bf16,256,320,10240,320,3.7195,0.3856,9.64,5532,9 +bf16,256,2560,2560,2560,3.5364,0.6533,5.41,5532,9 +bf16,256,512,2560,512,0.5690,0.1603,3.55,5532,9 +bf16,256,128,2560,128,0.2697,0.0586,4.60,5531,9 +bf16,256,48,2560,96,0.3158,0.0436,7.24,5530,9 +bf16,256,4,10240,4,1.1135,0.1344,8.28,5529,9 +bf16,256,1,2560,1,0.0581,0.0372,1.56,5529,9 +f16,128,12288,2560,12288,11.5691,1.8878,6.13,6137,7 +f16,128,10240,2560,10240,11.3427,1.6482,6.88,6137,7 +f16,128,6144,2560,6144,7.5798,1.0381,7.30,6137,7 +f16,128,2560,6144,2560,7.8253,1.0270,7.62,6136,7 +f16,128,2560,640,2560,0.4163,0.1356,3.07,6137,7 +f16,128,640,2560,640,0.5442,0.1987,2.74,6137,7 +f16,128,512,2560,512,0.6488,0.1887,3.44,6137,7 +bf16,128,10240,2560,10240,9.8758,1.4926,6.62,5532,9 +bf16,128,10240,320,10240,0.7429,0.3207,2.32,5532,9 +bf16,128,320,10240,320,1.4516,0.3780,3.84,5532,9 +bf16,128,2560,2560,2560,2.2319,0.5510,4.05,5532,9 +bf16,128,512,2560,512,0.4119,0.1255,3.28,5532,9 +bf16,128,128,2560,128,0.2702,0.0527,5.13,5530,9 +bf16,128,48,2560,96,0.2243,0.0408,5.51,5545,9 +bf16,128,4,10240,4,0.8669,0.1213,7.14,5529,9 +bf16,128,1,2560,1,0.0360,0.0344,1.05,5530,9 +f16,64,12288,2560,12288,11.8784,1.2125,9.80,6135,7 +f16,64,10240,2560,10240,10.8704,1.0699,10.16,6135,7 +f16,64,6144,2560,6144,7.5438,0.7642,9.87,6137,7 +f16,64,2560,6144,2560,7.5588,0.7730,9.78,6135,7 +f16,64,2560,640,2560,0.2777,0.1045,2.66,6137,7 +f16,64,640,2560,640,0.6969,0.1873,3.72,6136,7 +f16,64,512,2560,512,0.7157,0.1537,4.65,6136,7 +bf16,64,10240,2560,10240,10.9680,1.0273,10.68,5530,9 +bf16,64,10240,320,10240,0.3409,0.2038,1.67,5532,9 +bf16,64,320,10240,320,1.2132,0.2680,4.53,5530,9 +bf16,64,2560,2560,2560,2.3948,0.4248,5.64,5530,9 +bf16,64,512,2560,512,0.4768,0.1215,3.93,5530,9 +bf16,64,128,2560,128,0.2540,0.0539,4.71,5529,9 +bf16,64,48,2560,96,0.2186,0.0421,5.19,5533,9 +bf16,64,4,10240,4,0.7977,0.1389,5.74,5530,9 diff --git a/bench/results/COMMUNITY.md b/bench/results/COMMUNITY.md index 63092c48..2ef57bf9 100644 --- a/bench/results/COMMUNITY.md +++ b/bench/results/COMMUNITY.md @@ -101,6 +101,7 @@ Notes: | [2026-10-08-community-rtx4090-iq3xxs-200k-ru](2026-10-08-community-rtx4090-iq3xxs-200k-ru/) | RTX 4090, Ryzen 9 7950X (same PC) | Flash-Next IQ3_XXS, 204,800, Russian prompts | see the README | see the README | 0.1.40.3 | #1467 | | [2026-10-08-community-2x-titan-rtx-0.1.40.3](2026-10-08-community-2x-titan-rtx-0.1.40.3/) | 2x TITAN RTX 24 GB (NVLink, unused), Xeon E5-2696 v4, source build | Flash-Next IQ3_S, 262K | 869 / 1,549 / 1,627 (4K / 32K / 128K) | 70.9 / 77.3 / 71.1 | 0.1.40.3 | #1429 | | [2026-10-07-community-gfx1150](2026-10-07-community-gfx1150/) | Radeon 890M (gfx1150), Ryzen AI 9 HX PRO 370, 96 GB unified memory | IQ3_XXS | 153 / 216 / 226 (1K / 3.6K / 7K) with the gfx1150 hipBLASLt table, 99 / 124 / 130 without | 15.2-17.6 | 0.1.40.2 | - | +| [2026-10-12-community-gfx1103](2026-10-12-community-gfx1103/) | Radeon 780M (gfx1103), Ryzen 7 8745HS, 60 GB, GTT 50 GiB, hand build on ROCm 10.1 | Flash-Next Q2_0 + MTP, 32K | 90 plain / 186 with the gfx1103 hipBLASLt table / 211 with the exact switches / 277 with the WMMA opt-ins (4K); 272 at 32K (WMMA arm) | 13.1 plain, 13.9-14.3 tuned | 0.1.43 + the gfx1103 port (branch) | - | | [2026-10-09-community-2x-rx-6900xt-0.1.41](2026-10-09-community-2x-rx-6900xt-0.1.41/) | 2x RX 6900 XT 16 GB (PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB | IQ3_S, 131K | one card stock 473 / 502 / 486, with the two gfx103x switches 850 / 1,102 / 1,027, with the PRs 976 / 1,174 / 1,147; layer split stock 464 / 767 / 869, switches 832 / 1,619 / 1,823, PRs 968 / 1,714 / 2,029; helper with the PRs 986 / 1,173 / 1,147 | one card 46-52; layer split stock 62.6 / 65.0 / 60.8, PRs 64.7 / 68.8 / 68.3, PRs + `--spec 3 --spec-min-p 0.7 --pipeline-windows 2` 77.2 / 82.3 / 75.7; helper PRs 72.5 / 75.2 / 75.1 | 0.1.41 (fb58e0db) | this PR; notes: [Vop3p/dual-6900xt-flash-next-tuning](https://github.com/Vop3p/dual-6900xt-flash-next-tuning) | | [2026-10-09-community-gfx1151-ud-iq4xs-0.1.41](2026-10-09-community-gfx1151-ud-iq4xs-0.1.41/) | EVO-X2, Radeon 8060S (gfx1151), Ryzen AI Max+ 395, 128 GB UMA | Unsloth UD-IQ4_XS | 627 / 687 / 617 default; 808 / 1,165 / 1,109 fast | 42.8 / 44.4 / 42.1 default; 40.1 / 49.6 / 47.5 fast | 0.1.41 (fb58e0d) | - | | [2026-10-08-community-2x-rtx3080-20gb-ud-q4-k-xl-512k-pool](2026-10-08-community-2x-rtx3080-20gb-ud-q4-k-xl-512k-pool/) | 2x RTX 3080 20 GB (220 W cap each, PCIe Gen3 x16), Xeon E5-2696 v4 (AVX2), 90 GiB RAM, Proxmox LXC | Unsloth UD-Q4_K_XL, two 262,144-token lanes in a 524,288-token shared KV pool, layer split, batch MTP | 718 / 2,219 / 2,585 / 2,996 / 3,080 (4K / 25K / 51K / 104K / 127K) | 81.2 / 84.0 / 90.6 / 86.3 / 80.7 (same lengths, one stream); 89.5 for two streams (my script) | fork build of 0.1.40.3, source branch `repro/w7` on noon-at-cgn/Strata (not upstream `main` plus the open PRs: it contains the code of my open PRs #1598, #1599, #1601, #1614 (shared KV pool), #1636 (batch MTP on a split), #1637 (`--adapt-async` beside slots), and of #1190, an open PR by another contributor that keeps the RAM copy of the split lend regions) | - | diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index 132b2efe..155c54ac 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -661,6 +661,20 @@ Shipped tables: no fallbacks over prompts of 28-7,880 tokens. Setup does not use it (it does not install for gfx1150): point `STRATA_HIPBLASLT_TUNING` at it. Measurements and the per-row timings: [bench/results/2026-10-07-community-gfx1150](../bench/results/2026-10-07-community-gfx1150/README.md). +- `gfx1103-hipblaslt-100401.txt`: Radeon 780M (gfx1103, RDNA3, 12 CUs, unified memory), calibrated with ROCm 10.1 + (`rocm/dev-ubuntu-24.04:10.1.0-full`, hipBLASLt 1.4.1, version number 100401) and the engine's 32 MiB workspace. The + 16 dense GEMM geometries a Qwen3.8-Flash-Next prompt logs on the card at T = 64, 128, ..., 16384: 144 cases, two + `tune_hipblaslt` passes back to back, each row the solution with the lowest median of all six repetitions. One row + is left out (`bf16 N=1 K=2560 T=64`: no candidate beat plain hipBLAS at 0.04 ms), so the table has **143 rows**, + 1.05-23.30x per GEMM, geometric mean 4.95x. Without it the engine prefills on plain hipBLAS: a 4K prompt on Q2_0 + read 90 tok/s, 187 with the table and 277 with the WMMA opt-ins (one 780M; 32K context, MTP). The merged table + prefilled the 4K prompt at 187.2 tok/s. A context ladder to 131K (shipping configuration, fresh prompts) puts the + full 128K read at 198-221 tok/s, its last ~14K at ~206, and decode at ~10 tok/s at that depth; the numbers are in + the report folder. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`; + `hip_prefill_hcd_exact_parity` skips, because the table picks no 1176 / 1177 for the HC down GEMM (the skip the + gfx1150 table gets too). Setup installs for gfx1103 only with `STRATA_EXPERIMENTAL_GFX1103=1` and then uses the + table when the installed hipBLASLt reports 1.4.1. Measurements: + [bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md). Calibrated on my PC and kept in this checkout, not shipped: `gfx1201-hipblaslt-100401.txt`, a Radeon AI PRO R9700 (gfx1201, 32 GB, 1002:7551) on a Ryzen 9 9950X3D with 62 GiB RAM, CachyOS (kernel 7.3.0-rc6-1-cachyos-rc, diff --git a/docs/COMMUNITY_BENCHMARKS.md b/docs/COMMUNITY_BENCHMARKS.md index 13d016c9..4c88ca28 100644 --- a/docs/COMMUNITY_BENCHMARKS.md +++ b/docs/COMMUNITY_BENCHMARKS.md @@ -64,6 +64,8 @@ and their limits. Report what you actually measured and label estimates separate Source builds of 0.1.40.4 and 0.1.41 on the distribution's ROCm 6.2 (host patches in BUILD.json), IQ2_XS at 131K with KV streaming; decode 24.2/24.0/23.7 tok/s, prompt 350/339/284 tok/s at 4K/32K/128K, two sweeps with telemetry. Build logs trimmed (TRIMMED.md). - [2026-10-08: RTX 4070 12 GB, Core i5-12600KF, 32 GB DDR4](../bench/results/2026-10-08-community-rtx4070-iq2-xs/README.md): IQ2_XS with adaptive cache E4/S24: 48.23 accepted-decode tok/s (median of 5) on a modified, locally built engine (not an official release; source commit and hashes in provenance.json, steps in REPRODUCE.md). +- [2026-10-12: Radeon 780M (gfx1103), Ryzen 7 8745HS, 60 GB RAM, GTT 50 GiB](../bench/results/2026-10-12-community-gfx1103/README.md): + the gfx1103 port (native dot4, the gfx11 WMMA kernels, the exact speed switches and a calibrated hipBLASLt table), hand-built on ROCm 10.1, Q2_0 + MTP at 32K: prompts 90 tok/s plain, 186 with the table, 277 with the WMMA opt-ins (4K), decode 13.1 -> 14.3 tok/s; zero GPU resets. ## Run the benchmark diff --git a/tools/hip/gfx1103-hipblaslt-100401.txt b/tools/hip/gfx1103-hipblaslt-100401.txt new file mode 100644 index 00000000..c6ff2895 --- /dev/null +++ b/tools/hip/gfx1103-hipblaslt-100401.txt @@ -0,0 +1,145 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1103 100401 +f16 12288 2560 12288 16384 6137 +f16 10240 2560 10240 16384 6137 +f16 6144 2560 6144 16384 6137 +f16 2560 6144 2560 16384 6137 +f16 2560 640 2560 16384 6137 +f16 640 2560 640 16384 6137 +f16 512 2560 512 16384 6137 +bf16 10240 2560 10240 16384 5532 +bf16 10240 320 10240 16384 5532 +bf16 320 10240 320 16384 5532 +bf16 2560 2560 2560 16384 5532 +bf16 512 2560 512 16384 5532 +bf16 128 2560 128 16384 5532 +bf16 48 2560 96 16384 5532 +bf16 4 10240 4 16384 5529 +bf16 1 2560 1 16384 5529 +f16 12288 2560 12288 8192 6137 +f16 10240 2560 10240 8192 6137 +f16 6144 2560 6144 8192 6137 +f16 2560 6144 2560 8192 6137 +f16 2560 640 2560 8192 6137 +f16 640 2560 640 8192 6137 +f16 512 2560 512 8192 6137 +bf16 10240 2560 10240 8192 5532 +bf16 10240 320 10240 8192 5532 +bf16 320 10240 320 8192 5532 +bf16 2560 2560 2560 8192 5532 +bf16 512 2560 512 8192 5532 +bf16 128 2560 128 8192 5532 +bf16 48 2560 96 8192 5532 +bf16 4 10240 4 8192 5531 +bf16 1 2560 1 8192 5531 +f16 12288 2560 12288 4096 6137 +f16 10240 2560 10240 4096 6137 +f16 6144 2560 6144 4096 6137 +f16 2560 6144 2560 4096 6137 +f16 2560 640 2560 4096 6137 +f16 640 2560 640 4096 6137 +f16 512 2560 512 4096 6137 +bf16 10240 2560 10240 4096 5532 +bf16 10240 320 10240 4096 5532 +bf16 320 10240 320 4096 5532 +bf16 2560 2560 2560 4096 5532 +bf16 512 2560 512 4096 5532 +bf16 128 2560 128 4096 5532 +bf16 48 2560 96 4096 5532 +bf16 4 10240 4 4096 5529 +bf16 1 2560 1 4096 5531 +f16 12288 2560 12288 2048 6137 +f16 10240 2560 10240 2048 6137 +f16 6144 2560 6144 2048 6137 +f16 2560 6144 2560 2048 6137 +f16 2560 640 2560 2048 6137 +f16 640 2560 640 2048 6137 +f16 512 2560 512 2048 6137 +bf16 10240 2560 10240 2048 5532 +bf16 10240 320 10240 2048 5532 +bf16 320 10240 320 2048 5532 +bf16 2560 2560 2560 2048 5532 +bf16 512 2560 512 2048 5532 +bf16 128 2560 128 2048 5532 +bf16 48 2560 96 2048 5532 +bf16 4 10240 4 2048 5531 +bf16 1 2560 1 2048 5531 +f16 12288 2560 12288 1024 6137 +f16 10240 2560 10240 1024 6137 +f16 6144 2560 6144 1024 6137 +f16 2560 6144 2560 1024 6137 +f16 2560 640 2560 1024 6137 +f16 640 2560 640 1024 6137 +f16 512 2560 512 1024 6137 +bf16 10240 2560 10240 1024 5532 +bf16 10240 320 10240 1024 5532 +bf16 320 10240 320 1024 5532 +bf16 2560 2560 2560 1024 5532 +bf16 512 2560 512 1024 5532 +bf16 128 2560 128 1024 5532 +bf16 48 2560 96 1024 5531 +bf16 4 10240 4 1024 5529 +bf16 1 2560 1 1024 5530 +f16 12288 2560 12288 512 6137 +f16 10240 2560 10240 512 6137 +f16 6144 2560 6144 512 6137 +f16 2560 6144 2560 512 6137 +f16 2560 640 2560 512 6137 +f16 640 2560 640 512 6137 +f16 512 2560 512 512 6137 +bf16 10240 2560 10240 512 5532 +bf16 10240 320 10240 512 5532 +bf16 320 10240 320 512 5532 +bf16 2560 2560 2560 512 5532 +bf16 512 2560 512 512 5532 +bf16 128 2560 128 512 5531 +bf16 48 2560 96 512 5531 +bf16 4 10240 4 512 5529 +bf16 1 2560 1 512 5530 +f16 12288 2560 12288 256 6137 +f16 10240 2560 10240 256 6137 +f16 6144 2560 6144 256 6137 +f16 2560 6144 2560 256 6137 +f16 2560 640 2560 256 6136 +f16 640 2560 640 256 6137 +f16 512 2560 512 256 6137 +bf16 10240 2560 10240 256 5532 +bf16 10240 320 10240 256 5532 +bf16 320 10240 320 256 5532 +bf16 2560 2560 2560 256 5532 +bf16 512 2560 512 256 5532 +bf16 128 2560 128 256 5531 +bf16 48 2560 96 256 5530 +bf16 4 10240 4 256 5529 +bf16 1 2560 1 256 5529 +f16 12288 2560 12288 128 6137 +f16 10240 2560 10240 128 6137 +f16 6144 2560 6144 128 6137 +f16 2560 6144 2560 128 6136 +f16 2560 640 2560 128 6137 +f16 640 2560 640 128 6137 +f16 512 2560 512 128 6137 +bf16 10240 2560 10240 128 5532 +bf16 10240 320 10240 128 5532 +bf16 320 10240 320 128 5532 +bf16 2560 2560 2560 128 5532 +bf16 512 2560 512 128 5532 +bf16 128 2560 128 128 5530 +bf16 48 2560 96 128 5545 +bf16 4 10240 4 128 5529 +bf16 1 2560 1 128 5530 +f16 12288 2560 12288 64 6135 +f16 10240 2560 10240 64 6135 +f16 6144 2560 6144 64 6137 +f16 2560 6144 2560 64 6135 +f16 2560 640 2560 64 6137 +f16 640 2560 640 64 6136 +f16 512 2560 512 64 6136 +bf16 10240 2560 10240 64 5530 +bf16 10240 320 10240 64 5532 +bf16 320 10240 320 64 5530 +bf16 2560 2560 2560 64 5530 +bf16 512 2560 512 64 5530 +bf16 128 2560 128 64 5529 +bf16 48 2560 96 64 5533 +bf16 4 10240 4 64 5530 From 7aa71b08e541aefd4f60eb1e1c53d18dfbf9b1f0 Mon Sep 17 00:00:00 2001 From: onionbutties Date: Mon, 12 Oct 2026 18:17:51 +0100 Subject: [PATCH 13/28] hip: add a gfx1150 hipBLASLt 100500 tuning table (Radeon 890M) Calibrated on a Radeon 890M (Strix Point, gfx1150) with tools/hip/tune_hipblaslt --workspace-mib 32 over the 16 dense GEMM geometries of the shipped gfx1150-hipblaslt-100401.txt at T = 64, 128, ..., 16384: two passes, each row keeping the solution with the lowest mean of all six repetitions. The three rows slower than plain hipBLAS (the tiny bf16 N=1 K=2560 shape at T = 64, 128 and 256) are left out, so those buckets route to the nearest good row. Every remaining row beats plain hipBLAS: 1.07x to 16.7x per GEMM, geometric mean 5.0x. The solution IDs are scoped to hipBLASLt 1.5.0 (version 100500, the ROCm 10.2.0a20260930 nightly the engine here was built with). --- tools/hip/gfx1150-hipblaslt-100500.txt | 143 +++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 tools/hip/gfx1150-hipblaslt-100500.txt diff --git a/tools/hip/gfx1150-hipblaslt-100500.txt b/tools/hip/gfx1150-hipblaslt-100500.txt new file mode 100644 index 00000000..7e4c498a --- /dev/null +++ b/tools/hip/gfx1150-hipblaslt-100500.txt @@ -0,0 +1,143 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1150 100500 +f16 12288 2560 12288 16384 1156 +f16 10240 2560 10240 16384 1156 +f16 6144 2560 6144 16384 1156 +f16 2560 6144 2560 16384 1155 +f16 2560 640 2560 16384 1156 +f16 640 2560 640 16384 1156 +f16 512 2560 512 16384 1156 +bf16 10240 2560 10240 16384 542 +bf16 10240 320 10240 16384 542 +bf16 320 10240 320 16384 542 +bf16 2560 2560 2560 16384 541 +bf16 512 2560 512 16384 542 +bf16 128 2560 128 16384 542 +bf16 48 2560 96 16384 542 +bf16 4 10240 4 16384 540 +bf16 1 2560 1 16384 541 +f16 12288 2560 12288 8192 1156 +f16 10240 2560 10240 8192 1156 +f16 6144 2560 6144 8192 1156 +f16 2560 6144 2560 8192 1156 +f16 2560 640 2560 8192 1156 +f16 640 2560 640 8192 1156 +f16 512 2560 512 8192 1156 +bf16 10240 2560 10240 8192 542 +bf16 10240 320 10240 8192 542 +bf16 320 10240 320 8192 542 +bf16 2560 2560 2560 8192 542 +bf16 512 2560 512 8192 542 +bf16 128 2560 128 8192 542 +bf16 48 2560 96 8192 542 +bf16 4 10240 4 8192 539 +bf16 1 2560 1 8192 540 +f16 12288 2560 12288 4096 1156 +f16 10240 2560 10240 4096 1156 +f16 6144 2560 6144 4096 1156 +f16 2560 6144 2560 4096 1156 +f16 2560 640 2560 4096 1156 +f16 640 2560 640 4096 1156 +f16 512 2560 512 4096 1156 +bf16 10240 2560 10240 4096 542 +bf16 10240 320 10240 4096 542 +bf16 320 10240 320 4096 542 +bf16 2560 2560 2560 4096 542 +bf16 512 2560 512 4096 542 +bf16 128 2560 128 4096 542 +bf16 48 2560 96 4096 539 +bf16 4 10240 4 4096 540 +bf16 1 2560 1 4096 539 +f16 12288 2560 12288 2048 1156 +f16 10240 2560 10240 2048 1156 +f16 6144 2560 6144 2048 1156 +f16 2560 6144 2560 2048 1156 +f16 2560 640 2560 2048 1156 +f16 640 2560 640 2048 1156 +f16 512 2560 512 2048 1156 +bf16 10240 2560 10240 2048 542 +bf16 10240 320 10240 2048 542 +bf16 320 10240 320 2048 542 +bf16 2560 2560 2560 2048 542 +bf16 512 2560 512 2048 542 +bf16 128 2560 128 2048 542 +bf16 48 2560 96 2048 540 +bf16 4 10240 4 2048 555 +bf16 1 2560 1 2048 542 +f16 12288 2560 12288 1024 1156 +f16 10240 2560 10240 1024 1156 +f16 6144 2560 6144 1024 1156 +f16 2560 6144 2560 1024 1156 +f16 2560 640 2560 1024 1156 +f16 640 2560 640 1024 1156 +f16 512 2560 512 1024 1156 +bf16 10240 2560 10240 1024 542 +bf16 10240 320 10240 1024 542 +bf16 320 10240 320 1024 542 +bf16 2560 2560 2560 1024 542 +bf16 512 2560 512 1024 542 +bf16 128 2560 128 1024 542 +bf16 48 2560 96 1024 540 +bf16 4 10240 4 1024 555 +bf16 1 2560 1 1024 540 +f16 12288 2560 12288 512 1156 +f16 10240 2560 10240 512 1156 +f16 6144 2560 6144 512 1156 +f16 2560 6144 2560 512 1156 +f16 2560 640 2560 512 1156 +f16 640 2560 640 512 1156 +f16 512 2560 512 512 1156 +bf16 10240 2560 10240 512 542 +bf16 10240 320 10240 512 542 +bf16 320 10240 320 512 542 +bf16 2560 2560 2560 512 542 +bf16 512 2560 512 512 542 +bf16 128 2560 128 512 539 +bf16 48 2560 96 512 540 +bf16 4 10240 4 512 554 +bf16 1 2560 1 512 553 +f16 12288 2560 12288 256 1156 +f16 10240 2560 10240 256 1156 +f16 6144 2560 6144 256 1156 +f16 2560 6144 2560 256 1156 +f16 2560 640 2560 256 1156 +f16 640 2560 640 256 1156 +f16 512 2560 512 256 1156 +bf16 10240 2560 10240 256 542 +bf16 10240 320 10240 256 542 +bf16 320 10240 320 256 541 +bf16 2560 2560 2560 256 542 +bf16 512 2560 512 256 542 +bf16 128 2560 128 256 541 +bf16 48 2560 96 256 539 +bf16 4 10240 4 256 554 +f16 12288 2560 12288 128 1156 +f16 10240 2560 10240 128 1156 +f16 6144 2560 6144 128 1156 +f16 2560 6144 2560 128 1156 +f16 2560 640 2560 128 1156 +f16 640 2560 640 128 1156 +f16 512 2560 512 128 1155 +bf16 10240 2560 10240 128 542 +bf16 10240 320 10240 128 542 +bf16 320 10240 320 128 541 +bf16 2560 2560 2560 128 542 +bf16 512 2560 512 128 541 +bf16 128 2560 128 128 543 +bf16 48 2560 96 128 543 +bf16 4 10240 4 128 543 +f16 12288 2560 12288 64 1156 +f16 10240 2560 10240 64 1154 +f16 6144 2560 6144 64 1154 +f16 2560 6144 2560 64 1154 +f16 2560 640 2560 64 1156 +f16 640 2560 640 64 1154 +f16 512 2560 512 64 1155 +bf16 10240 2560 10240 64 541 +bf16 10240 320 10240 64 541 +bf16 320 10240 320 64 543 +bf16 2560 2560 2560 64 542 +bf16 512 2560 512 64 541 +bf16 128 2560 128 64 543 +bf16 48 2560 96 64 555 +bf16 4 10240 4 64 543 From d3c4a6de77a06290dfca1b2cba2cde309310a923 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:08:54 +0200 Subject: [PATCH 14/28] setup: write the gfx1103 exact speed switches for the opt-in install The engine turns 18 exact (bit-identical) switches on by default on gfx1151 (src/core/arch_defaults.cpp) but keeps gfx1103 out of its arch defaults (src/core/arch_defaults_test.cpp asserts arch_default_env("gfx1103").empty()). A gfx1103 install gets the 17 that apply here - the gfx1151 set less STRATA_HCD_EXACT, which copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not fit beside a gfx1103 table - written into the config's "env" beside STRATA_HIPBLASLT_TUNING. One 780M (Ryzen 7 8745HS, 60 GB, GTT 50 GiB, ROCm 10.1, Q2_0, 4K prompt) measured the same greedy token ids with the 17 on and with them off, +13% to +15% prompt and decode +3.2% (the decode half alone); bench/results/2026-10-12-community-gfx1103. The set is setup's own (SETUP_ENV): a re-run refreshes it, and it does not linger after the opt-in is turned off. The gfx1103 note now names the native dot4 / WMMA kernels and docs/RADEON_780M.md, which documents the opt-in build, the table and the measured numbers. Setup's suites pass (strix_halo, rocm_pins, amd, choices: 143 tests). Refs #1423. Co-authored-by: AlexisCarbonell <51439370+AlexisCarbonell@users.noreply.github.com> --- docs/AMD_HIP.md | 2 +- docs/RADEON_780M.md | 132 +++++++++++++++++++++++++++++++++ setup.py | 28 ++++++- tools/test_setup_strix_halo.py | 18 +++++ 4 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 docs/RADEON_780M.md diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index 155c54ac..47327380 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -66,7 +66,7 @@ On a PC with no NVIDIA card Strata can use, the AMD card is chosen by itself; wi Adrenalin Edition](https://www.amd.com/en/support/download/drivers.html)). Nothing else: no ROCm or HIP SDK install, no compiler, no admin rights. - **Detection:** setup reads the display adapters Windows lists (their PCI ids; the VRAM size from the display - driver's registry entry). An integrated Radeon is listed as not supported, except the Ryzen AI Max "Strix Halo" (Radeon 8060S / 8050S / 8040S, gfx1151: [STRIX_HALO.md](STRIX_HALO.md)); a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is named as what it is and not supported. + driver's registry entry). An integrated Radeon is listed as not supported, except the Ryzen AI Max "Strix Halo" (Radeon 8060S / 8050S / 8040S, gfx1151: [STRIX_HALO.md](STRIX_HALO.md)); a Strix Point (890M / 880M, gfx1150), Krackan (860M / 840M, gfx1152) or Phoenix / Hawk Point (780M / 760M, gfx1103) Radeon is named as what it is and not supported (on Linux the 780M / 760M has an opt-in build: [RADEON_780M.md](RADEON_780M.md)). - **Engine:** the ready-made `strata-windows-x64-hip.zip` from the release (built by `tools\hip\build_windows.bat` for gfx1100, gfx1101, gfx1102, gfx1200, gfx1201, gfx1030 and, from 0.1.40, gfx1151 (Strix Halo, unvalidated on Windows)) goes into `engine\`. It carries the ROCm libraries the engine loads (`engine\rocm\bin`: the HIP runtime, hipBLAS / rocBLAS / hipBLASLt with their kernels for these cards, diff --git a/docs/RADEON_780M.md b/docs/RADEON_780M.md new file mode 100644 index 00000000..bc10836e --- /dev/null +++ b/docs/RADEON_780M.md @@ -0,0 +1,132 @@ +# Radeon 780M / 760M (Ryzen 7040 / 8040, gfx1103): build from source on Linux + +The Radeon 780M (Phoenix / Hawk Point, RDNA3, `gfx1103`) runs Strata through the same HIP backend as the Radeon +cards in [AMD_HIP.md](AMD_HIP.md). **Status: experimental and opt-in** (`STRATA_EXPERIMENTAL_GFX1103=1`): the port +is measured on one machine (the numbers below), the maintainers have not run one, and the chip is not Strix Halo. +Everything here was measured on a Ryzen 7 8745HS (8 cores, AVX-512), Radeon 780M (12 CUs), 60 GB DDR5, GTT at +50 GiB, Ubuntu kernel 7.0.0-38, `cwsr_enable=0`, engine 0.1.43 built from this tree by hand, Qwen3.8-Flash-Next +GSQ-RCO Q2_0 with the MTP draft layer, 32K context, Int8 KV. + +## 1. What the port changed + +- **Native dot4.** gfx1103 was outside the `dp4a` guard in `hip_compat/intrinsics.hpp`, so every quantized dot + product ran a four-step byte loop instead of `v_dot4_i32_iu8`. gfx1103 now compiles the native instruction + (decode +55% measured: 8.70 -> 13.44 tok/s at a 32K prompt, same greedy token ids as before). +- **gfx11 WMMA kernels.** gfx1103 was outside the `__gfx11xx__` list of the prompt attention, block scorer, + prompt GEMMs and prompt experts, so those fell back to hipBLAS / portable kernels. It is now in the list and + the parity tests run on it (`hip_prefill_wmma_gemm_parity`, `hip_prompt_attn_wmma`, `hip_prefill_fused_moe`, + `hip_prefill_fused_iq`, `qsa_*`, `hip_gemm_f16_io_parity`, `hip_prefill_mmq_parity`). +- **A hipBLASLt table** for gfx1103 + hipBLASLt `100401`: `tools/hip/gfx1103-hipblaslt-100401.txt` (section 3). +- **The gfx1103 exact speed switches** (section 4), written into the config's `env` by setup for the opt-in install + (the engine keeps gfx1103 out of its arch defaults, as it does for gfx1150). Whether the chip leaves the + `STRATA_EXPERIMENTAL_GFX1103=1` opt-in is the maintainers' call; the numbers here are what they need to make it. + +## 2. Toolchain and build + +ROCm 10.1 (`rocm/dev-ubuntu-24.04:10.1.0-full`) is what this build and the table were tested with: HIP +7.16.26385, hipBLASLt 1.4.1 (`100401`), clang 24. Its hipBLASLt carries gfx1103 kernels. setup's TheRock index +for `gfx110X-all` has no 10.x (its newest is 7.14.0a20260612); the gfx1103 opt-in keeps setup's nightly pin, and +the wheel route was not exercised by the numbers below - they come from a hand build. + +By hand, the steps of [STRIX_HALO.md](STRIX_HALO.md) with the architecture and the paths changed: + +```sh +cmake -S . -B build-780m -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_PREFILL_MMQ=ON \ + -DCMAKE_HIP_ARCHITECTURES=gfx1103 \ + -DCMAKE_HIP_COMPILER=/opt/rocm/lib/llvm/bin/clang++ -DCMAKE_HIP_COMPILER_ROCM_ROOT=/opt/rocm \ + -DCMAKE_PREFIX_PATH=/opt/rocm \ + "-DCMAKE_HIP_FLAGS=--rocm-path=/opt/rocm --rocm-device-lib-path=/opt/rocm/lib/llvm/amdgcn/bitcode" +cmake --build build-780m -j 12 +ctest --test-dir build-780m +``` + +`ctest` on this machine: 57 passed, 2 skipped (`hip_prefill_hcd_exact_parity`, `hip_prefill_hipblaslt_gemm` - +they run and pass with the table set), 2 environmental failures (`ple_parity` needs the `bench/micro` fixtures, +`platform_memory_test` needs a memlock limit above 8 MiB; this host's hard limit is 8 MiB). + +The model: a GSQ-RCO Q2_0 pack (`tools/iq_pack.py`, the experts read from the GGUF in place), the PLE table on +the SSD (`--ple-io direct`), `--mmap-experts --expert-cache 24576`, `--prefill auto`, MTP from +`tools/mtp_fetch.py` + `mtp_pack.py` + `mtp_rt.py`. GTT must be raised for this model (`ttm.pages_limit`; setup +changes no host setting). + +## 3. The hipBLASLt table + +```sh +export STRATA_HIPBLASLT_TUNING=$PWD/tools/hip/gfx1103-hipblaslt-100401.txt +``` + +setup hands it over automatically when the installed hipBLASLt reports 1.4.1. It was calibrated with +`tools/hip/tune_hipblaslt` over the gfx1150 table's 144 GEMM cases at T = 64..16384 (the same case list the 890M +run used), two passes, 32 MiB workspace, each row the solution with the lowest median of all six repetitions: 143 +rows (the `bf16 N=1 K=2560 T=64` shape has no candidate faster than plain hipBLAS and is left out), 1.05-23.30x per +GEMM, geometric mean 4.95x. `hip_prefill_hipblaslt_gemm` reports `fallbacks=0`; `hip_prefill_hcd_exact_parity` +skips because the table picks no 1176 / 1177 for the HC down GEMM (the gfx1150 table gets the same skip). + +## 4. The exact speed switches + +With `STRATA_EXPERIMENTAL_GFX1103=1` setup writes the 17 exact switches below into the config's `env`, the same way +it writes the hipBLASLt table; turning the opt-in off takes them out again. The engine keeps gfx1103 out of its +arch defaults (`arch_default_env("gfx1103")` stays empty, checked by `arch_defaults_test`). Measured on the 780M: ++13% to +15% prompt with the table (183-186 -> 211-212 tok/s at 4K) and +3.2% decode (16.63 -> 17.17 tok/s, 640 +greedy tokens, 3 of 3 pairs), with the greedy token ids unchanged. They are the gfx1151 table less +`STRATA_HCD_EXACT` (which needs hipBLASLt solutions 1176 / 1177; the gfx1103 table picks others). + +| Switch | What it does | +|---|---| +| `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY`, `STRATA_CVEC_FUSE` | the prompt's gated-delta-net recurrence and the steered layer's fused write | +| `STRATA_PF_PAD` | padded GEMM row strides (acts with `STRATA_PF_GEMM`; inert without it) | +| `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) | +| `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE`, `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH`, `STRATA_SH_STREAM` | grouped decode experts, butterfly warp sums, fewer launches, the GDN step over four blocks per head, producer-written activation images, batched PLE projections, the shared expert on its own stream | + +## 5. Opt-in switches (they change bits) + +Opt-in, and the measured wins are below. The prompt levers need the table to pay: with the table, the WMMA set +read 248 tok/s at 4K against 186 without it, and at 32K 272 against 178. No KL was measured on this chip. + +```sh +export STRATA_HIP_WMMA=1 # prompt attention on matrix cores +export STRATA_PF_GEMM=1 # the prompt's FP16 projections on the WMMA GEMM +export STRATA_PA_FAST=1 # prompt attention with single FP16 q and p +export STRATA_SELECT_WMMA=1 # the block scorer on matrix cores +export STRATA_PF_FUSED=1 # the prompt experts on matrix cores (neutral at 4K here: 246 vs 248) +export STRATA_HC_UPMIX=1 # the hyper-connection up projection with its epilogue +``` + +## 6. Engine flags + +`--spec 2` is the best MTP window on this chip: 15.65 tok/s decode at a 4K prompt against 14.18 at `--spec 4` and +11.16 at `--spec 6` (greedy, 256 tokens, medians of three interleaved restarts). `--lookup-chain 4` adds +2.3% (3 +of 3 pairs, byte-identical greedy answers) and setup's `--spec-min-p 0.5` is 4.5% slower here than the default; +`--mtp-q4` is neutral and `--mtp-window 4096` measured +2% at 32K in two pairs (weak). The raw runs are in the +results folder. + +## 7. Measured + +bench/bench_vs_llama.py, 256 tokens out, temperature 0 and 0.7, interleaved; each cell one round (medians need +more rounds - treat these as one-machine samples): + +| arm | cell | prompt tok/s | decode tok/s | TTFT s | +| --- | --- | ---: | ---: | ---: | +| plain (no table, no opt-ins) | 4K | 90 | 13.1 | 44.9 | +| plain (no table, no opt-ins) | 32K | 90 | 13.1 | 351 | +| table + all opt-ins | 4K | 277 | 13.9 | 14.6 | +| table + WMMA set | 32K | 272 | 14.3 | 118 | + +A context ladder on the shipping configuration (131K context, `--spec 2 --lookup-chain 4`) with fresh prompts from +this checkout's own documentation, 128 greedy tokens each: prefill holds ~310 tok/s to 32K (276.7 at 4K, 314.3 / +314.6 at 8K / 16K, 308.7 at 32K), then 258.2 at 64K, 215.5 at 96K and 198.5-221.4 at 128K across two runs - that is +the average over the full read, and the last ~14K tokens at 128K depth read at ~206 tok/s with the prefix cached. +Decode holds ~16 tok/s to 32K, then 12.1 at 64K and 9.8-9.9 at 96-128K (draft acceptance stays ~70%, so it is +context cost, not the drafter). Memory stays flat: 38.1 of 50 GiB GTT at 131K. Raw: +[bench/results/2026-10-12-community-gfx1103](../bench/results/2026-10-12-community-gfx1103/README.md). + +## 8. Not tested + +- The TheRock-wheel install for gfx1103 (the hand build above is what was measured). +- The opt-in set beyond one round; KL of any bit-changing switch; other models; contexts past 131K. +- CUDA and SYCL were not built here (no toolchains on this box); the added gfx1103 macros are undefined for them. +- Reset stability looks good but is one machine: a 2 h 07 m soak (`tools/serve_load.py`, 924 requests) and the + reset-prone combination from 7.10 (partial expert cache + `STRATA_IO_PREFETCH=1` + the adaptive tier) both ran + with zero `amdgpu` resets in the kernel log. The known 780M issue ([DETAILS.md](DETAILS.md)) was seen on ROCm + 7.10; with `cwsr_enable=0` and this stack it did not reproduce. diff --git a/setup.py b/setup.py index 8bb6ef9b..4ceb60b3 100644 --- a/setup.py +++ b/setup.py @@ -2091,9 +2091,26 @@ ROCM_VERSION_OVERRIDE = os.environ.get("STRATA_ROCM_VERSION") or None ROCM_VERSION = ROCM_VERSION_OVERRIDE or ROCM_VERSION_DEFAULT # kept for callers that read one version ROCM_SYSTEM_MIN = (7, 0) # an older system ROCm is passed over for the wheels (gfx1201 needs ROCm 6.4 or newer) # STRATA_EXPERIMENTAL_GFX1103=1 (opt-in, unsupported): the Radeon 780M / 760M / 740M iGPU (Ryzen 7040 / 8040, gfx1103) is taken -# as a unified-memory AMD card like Strix Halo, with the portable kernels (no WMMA) (measured on one machine: Ryzen 7 255). Unset: unchanged. +# as a unified-memory AMD card like Strix Halo, with the native dot4 and gfx11 WMMA kernels, the gfx1103 exact speed switches +# and a hipBLASLt table when one matches (measured on one machine: Ryzen 7 8745HS). Unset: unchanged. GFX1103_OPT_IN = os.environ.get("STRATA_EXPERIMENTAL_GFX1103") == "1" AMD_ARCHS = ("gfx1100", "gfx1101", "gfx1102", "gfx1200", "gfx1201", "gfx1030", "gfx1031", "gfx1151") + (("gfx1103",) if GFX1103_OPT_IN else ()) +# The exact (bit-identical) speed switches the engine turns on by default on gfx1151 (src/core/arch_defaults.cpp), less +# STRATA_HCD_EXACT: that one copies the gfx1151 hipBLASLt table's solutions 1176 / 1177, and the gfx1103 table +# (tools/hip/gfx1103-hipblaslt-100401.txt) picks others, so it would only report that it cannot run. A gfx1103 install +# takes them from here (setup writes them into the config's "env"), the same way the table is written: one 780M measured +# the same greedy answers with all 17 on and with all 17 off, +13% to +15% prompt and decode +3.2% (the decode half +# alone). The engine keeps gfx1103 out of its own arch defaults (src/core/arch_defaults_test.cpp asserts it stays +# empty), so this keeps the default path byte-identical. +GFX1103_SWITCHES = { + # prompt + "STRATA_GDN_HEAD": "1", "STRATA_GDN_PP": "2", "STRATA_GDN_CONVL2": "1", "STRATA_GDN_NOY": "1", + "STRATA_CVEC_FUSE": "1", "STRATA_PF_PAD": "1", + # decode + "STRATA_Q8_PACKED": "1", "STRATA_Q6_PACKED": "1", "STRATA_MMVF_ROWS": "1", "STRATA_ATTN_LANECELL": "1", + "STRATA_EXPERT_V2": "1", "STRATA_TSUM": "1", "STRATA_LFUSE": "1", "STRATA_GDN_SPLIT": "1", + "STRATA_QFUSE": "1", "STRATA_PLE_BATCH": "1", "STRATA_SH_STREAM": "1", +} AMD_NAMES = {"gfx1100": "AMD Radeon RX 7900 series (gfx1100)", # when sysfs has no product name "gfx1101": "AMD Radeon RX 7800 XT / 7700 XT (gfx1101)", "gfx1102": "AMD Radeon RX 7600 / 7600 XT (gfx1102)", @@ -2344,8 +2361,9 @@ def gfx1103_notes(gpu, ram) -> list[str]: f"seen by the OS + a {gpu.get('dedicated_gb', 0.0):.1f} GB BIOS carve-out), so the model's experts live in " "that pool and the expert cache is sized from the memory the OS can give back."] notes.append(" " + ("The engine is compiled here for gfx1103" if not WIN else "This GPU has no ready-made Windows engine") + + " with the native dot4 and WMMA kernels and the 780M's exact speed switches" + " (experimental opt-in, STRATA_EXPERIMENTAL_GFX1103=1; measured on one machine, not validated on a real " - "card): see docs/AMD_HIP.md. This is not a Strix Halo.") + "card): see docs/AMD_HIP.md and docs/RADEON_780M.md. This is not a Strix Halo.") if not WIN and gpu.get("shared_gb", 0) < 0.75 * ram - 1: notes.append(f"!the GPU can reach {gpu.get('shared_gb', 0):.0f} GB of shared memory (the GTT pool; the kernel's " "default is about half of the RAM). The kernel option ttm.pages_limit raises it; setup changes no " @@ -4415,7 +4433,7 @@ def write_config(path: Path, cfg: dict): SETUP_KEYS = frozenset({"exe", "args", "cwd", "tokenizer", "model_name", "log", "lib_dirs", "port", "backend", "env", "gpu", "gpus_asked", "layer_split", "host", "api_key", "draft_vocab", "vision"}) SETUP_ENV = frozenset({"STRATA_HIPBLASLT_TUNING", "STRATA_RESIDENT_PIN", "STRATA_NO_ARENA_THP", "STRATA_MMQ_KQ", "STRATA_HC_Q8", - "STRATA_ROUTE_TAIL_SKIP"}) # the "env" entries setup writes + "STRATA_ROUTE_TAIL_SKIP"}) | frozenset(GFX1103_SWITCHES) # the "env" entries setup writes (the gfx1103 switches are setup's too: a re-run refreshes them, they do not linger) # 0.1.44 added these three, written for Unsloth's files only (unsloth_default_env). In any other model's config they are the # user's own (STRATA_ROUTE_TAIL_SKIP=0 to turn the tail skip off, STRATA_MMQ_KQ=1 ...): a setup run again keeps them there # (0.1.44 dropped them with the rest of SETUP_ENV). @@ -6743,6 +6761,10 @@ def main() -> int: if GFX1103_OPT_IN and gfx_arch_is(gpu["arch"], "gfx1103") and not WIN: # the 780M's KFD queues are evicted (a GPU reset) while transparent huge pages move the pinned expert arena cfg.setdefault("env", {})["STRATA_NO_ARENA_THP"] = "1" + # the exact gfx1151 speed switches measured on this chip (GFX1103_SWITCHES): the engine has no arch defaults + # for gfx1103, so setup writes them into the config. They are setup's own (SETUP_ENV), so a re-run refreshes + # them and turning the opt-in off takes them out again. + cfg.setdefault("env", {}).update(GFX1103_SWITCHES) if resident: # ROCm: large page-locked host allocations can fail or be slow for the CPU; keep the copy pageable cfg.setdefault("env", {})["STRATA_RESIDENT_PIN"] = "0" if gpu["count"] > 1 or a.gpu is not None: diff --git a/tools/test_setup_strix_halo.py b/tools/test_setup_strix_halo.py index 0fb83051..cd93ac5b 100644 --- a/tools/test_setup_strix_halo.py +++ b/tools/test_setup_strix_halo.py @@ -110,6 +110,23 @@ class ExactArch(unittest.TestCase): self.assertIn("docs/STRIX_HALO.md", setup.AMD_CARDS) +class Gfx1103Switches(unittest.TestCase): + def test_is_the_gfx1151_defaults_less_hcd_exact(self): + """GFX1103_SWITCHES is the gfx1151 arch-default set (src/core/arch_defaults.cpp) minus STRATA_HCD_EXACT, which + copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not apply beside a gfx1103 table. The + engine keeps gfx1103 out of its own arch defaults, so setup writes this set.""" + src = (ROOT / "src/core/arch_defaults.cpp").read_text(encoding="utf-8") + tail = src.split("gfx_arch_is_gfx1151(gcn_arch)) return t;", 1)[1] + block = tail.rsplit("t = {", 1)[1].split("};", 1)[0] # the gfx1151 switch table + gfx1151 = dict(re.findall(r'\{"(STRATA_[A-Z0-9_]+)",\s*"([^"]+)"\}', block)) + self.assertIn("STRATA_HCD_EXACT", gfx1151) # the parse found the gfx1151 block + self.assertEqual(setup.GFX1103_SWITCHES, + {k: v for k, v in gfx1151.items() if k != "STRATA_HCD_EXACT"}) + self.assertNotIn("STRATA_HCD_EXACT", setup.GFX1103_SWITCHES) + for k in setup.GFX1103_SWITCHES: # setup's own: a re-run refreshes them + self.assertIn(k, setup.SETUP_ENV) + + class PciIds(unittest.TestCase): def test_strix_halo_id(self): # pci.ids: one id for every Strix Halo part (8060S, 8050S, 8040S share it; they differ by CU count) @@ -486,6 +503,7 @@ class IgpuTextIsArchExact(unittest.TestCase): text = chr(10).join(setup.igpu_notes(self.gpu("gfx1103", "AMD Radeon 780M Graphics"), 61.0)) self.assertIn("gfx1103", text) self.assertIn("STRATA_EXPERIMENTAL_GFX1103=1", text) + self.assertIn("RADEON_780M.md", text) for bad in ("gfx1151", "Ryzen AI Max", "STRIX_HALO", "Recommended model"): self.assertNotIn(bad, text) self.assertNotIn("Strix Halo (gfx1151", text) From 6f0505c69e8cb85906e70250d6e2dec8b8826b17 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:09:14 +0200 Subject: [PATCH 15/28] setup: opt-in gfx1150 (Radeon 890M / 880M, Strix Point) as a unified-memory AMD card STRATA_EXPERIMENTAL_GFX1150=1 takes the Radeon 890M / 880M iGPU (Ryzen AI 300, Strix Point, gfx1150) as a unified-memory card like Strix Halo: it joins AMD_ARCHS and the UMA handling (new is_uma_apu helper), with notes of its own. The engine already builds and runs for gfx1150 (0.1.40.2, #1217; tools/hip/gfx1150-hipblaslt-100401.txt is calibrated on it); no release ships a ready-made Windows engine for it yet, so a Windows user builds one (STRATA_HIP_ARCHS=gfx1150 tools\hip\build_windows.bat) and starts setup with --prebuilt dist\. Unset, the default path is unchanged: the test that asserts gfx1150 is not in AMD_ARCHS (tools/test_setup_strix_halo.py) still passes. Co-authored-by: onionbutties --- setup.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 4ceb60b3..c7fecd08 100644 --- a/setup.py +++ b/setup.py @@ -2077,6 +2077,7 @@ ROCM_INDEXES = {"gfx1100": "https://rocm.nightlies.amd.com/v2/gfx110X-dgpu/", "gfx1030": "https://rocm.nightlies.amd.com/v2/gfx103X-all/", "gfx1031": "https://rocm.nightlies.amd.com/v2/gfx103X-all/", "gfx1151": "https://rocm.nightlies.amd.com/v2/gfx1151/", # Strix Halo (docs/STRIX_HALO.md) + "gfx1150": "https://rocm.nightlies.amd.com/v2/gfx1150/", # Strix Point: only with STRATA_EXPERIMENTAL_GFX1150=1 "gfx1103": "https://rocm.nightlies.amd.com/v2/gfx110X-all/"} # Radeon 780M: only with STRATA_EXPERIMENTAL_GFX1103=1 # The TheRock nightly indexes are pruned and move on, and each GPU family's index holds its own range (#1103: gfx103X-all # starts at 7.13.0a20260422 and has no 7.10; #1267: the 7.10 wheel segfaults on a Strix Halo with kernel 7.2.8), so one @@ -2094,7 +2095,14 @@ ROCM_SYSTEM_MIN = (7, 0) # an older system ROCm is passed over for the whe # as a unified-memory AMD card like Strix Halo, with the native dot4 and gfx11 WMMA kernels, the gfx1103 exact speed switches # and a hipBLASLt table when one matches (measured on one machine: Ryzen 7 8745HS). Unset: unchanged. GFX1103_OPT_IN = os.environ.get("STRATA_EXPERIMENTAL_GFX1103") == "1" -AMD_ARCHS = ("gfx1100", "gfx1101", "gfx1102", "gfx1200", "gfx1201", "gfx1030", "gfx1031", "gfx1151") + (("gfx1103",) if GFX1103_OPT_IN else ()) +# STRATA_EXPERIMENTAL_GFX1150=1 (opt-in, unvalidated): the Radeon 890M / 880M iGPU (Ryzen AI 300, Strix Point, gfx1150) +# is taken as a unified-memory AMD card like Strix Halo. The engine builds and runs for gfx1150 from 0.1.40.2 (#1217; +# tools/hip/gfx1150-hipblaslt-100401.txt is calibrated on it), but no release ships a ready-made Windows engine for it: +# build one with `STRATA_HIP_ARCHS=gfx1150 tools\hip\build_windows.bat` and start setup with `--prebuilt dist\`. +# Unset: unchanged. +GFX1150_OPT_IN = os.environ.get("STRATA_EXPERIMENTAL_GFX1150") == "1" +AMD_ARCHS = ("gfx1100", "gfx1101", "gfx1102", "gfx1200", "gfx1201", "gfx1030", "gfx1031", "gfx1151") \ + + (("gfx1103",) if GFX1103_OPT_IN else ()) + (("gfx1150",) if GFX1150_OPT_IN else ()) # The exact (bit-identical) speed switches the engine turns on by default on gfx1151 (src/core/arch_defaults.cpp), less # STRATA_HCD_EXACT: that one copies the gfx1151 hipBLASLt table's solutions 1176 / 1177, and the gfx1103 table # (tools/hip/gfx1103-hipblaslt-100401.txt) picks others, so it would only report that it cannot run. A gfx1103 install @@ -2216,6 +2224,15 @@ def is_strix_halo(g) -> bool: return isinstance(g, dict) and gfx_arch_is(g.get("arch"), STRIX_HALO_ARCH) +def is_uma_apu(g) -> bool: + """A unified-memory AMD APU whose "VRAM" is a BIOS carve-out plus shared system memory: Strix Halo (gfx1151), and + the opt-in gfx1150 (Strix Point) / gfx1103 (Phoenix / Hawk Point) iGPUs. Everything else is a discrete card.""" + arch = g.get("arch") if isinstance(g, dict) else None + return (is_strix_halo(g) + or (GFX1150_OPT_IN and gfx_arch_is(arch, "gfx1150")) + or (GFX1103_OPT_IN and gfx_arch_is(arch, "gfx1103"))) + + def amd_apply_uma(g: dict, gtt_gb: float = 0.0, ram: float | None = None) -> dict: """Strix Halo is an APU with unified memory. Its "dedicated VRAM" is a BIOS carve-out (512 MB to 96 GB; 2 GB on the maintainers' box) and the GPU also reaches shared system memory (Linux: the GTT pool, `mem_info_gtt_total`, half the @@ -2223,7 +2240,7 @@ def amd_apply_uma(g: dict, gtt_gb: float = 0.0, ram: float | None = None) -> dic the model's experts live in, so it is not extra room beside the RAM. g gets: uma, dedicated_gb (the carve-out: the only part that adds to the RAM, which the low-RAM mode counts) and vram_gb = the memory the GPU can use in all (the carve-out plus the shared pool less what the OS keeps), which sizes the context and the parallel slots.""" - if g.get("uma") or not (is_strix_halo(g) or (GFX1103_OPT_IN and gfx_arch_is(g.get("arch"), "gfx1103"))): + if g.get("uma") or not is_uma_apu(g): return g ram = ram_gb() if ram is None else ram carve = max(0.0, float(g.get("vram_gb") or 0.0)) @@ -2371,10 +2388,29 @@ def gfx1103_notes(gpu, ram) -> list[str]: return notes +def gfx1150_notes(gpu, ram) -> list[str]: + """What setup tells the owner of a Radeon 890M / 880M (Ryzen AI 300, Strix Point, gfx1150, unified memory): never + the Strix Halo text, which is about another chip (gfx1151). Opt-in only (STRATA_EXPERIMENTAL_GFX1150=1).""" + notes = [f" Radeon 890M / 880M class (gfx1150, Strix Point): the CPU and the GPU share one memory pool ({ram:.0f} GB " + f"seen by the OS + a {gpu.get('dedicated_gb', 0.0):.1f} GB BIOS carve-out), so the model's experts live in " + "that pool and the expert cache is sized from the memory the OS can give back."] + notes.append(" " + ("The engine is compiled here for gfx1150" if not WIN else + "Windows has no ready-made engine for gfx1150: build one with STRATA_HIP_ARCHS=gfx1150 " + "tools\\hip\\build_windows.bat and start setup with --prebuilt dist\\") + + " (experimental opt-in, STRATA_EXPERIMENTAL_GFX1150=1, unvalidated: docs/AMD_HIP.md).") + if not WIN and gpu.get("shared_gb", 0) < 0.75 * ram - 1: + notes.append(f"!the GPU can reach {gpu.get('shared_gb', 0):.0f} GB of shared memory (the GTT pool; the kernel's " + "default is about half of the RAM). The kernel option ttm.pages_limit raises it; setup changes no " + "host setting - a bigger model needs the room, a smaller one runs as it is") + return notes + + def igpu_notes(gpu, ram) -> list[str]: - """The unified-memory notes for exactly this chip: Strix Halo (gfx1151) or the gfx1103 opt-in, nothing else.""" + """The unified-memory notes for exactly this chip: Strix Halo (gfx1151) or the gfx1150 / gfx1103 opt-in, nothing else.""" if is_strix_halo(gpu): return strix_halo_notes(gpu, ram) + if GFX1150_OPT_IN and gfx_arch_is(gpu.get("arch"), "gfx1150"): + return gfx1150_notes(gpu, ram) if gfx_arch_is(gpu.get("arch"), "gfx1103"): return gfx1103_notes(gpu, ram) return [] @@ -2502,9 +2538,9 @@ def amd_gpus_win() -> list[dict]: hip = hip_devices() if not hip: return amd_gpus_windows() - halo = [g for g in hip if is_strix_halo(g)] + halo = [g for g in hip if is_uma_apu(g)] if halo: # an APU: the HIP runtime's figure is not the BIOS carve-out - reg = [r for r in amd_gpus_windows() if is_strix_halo(r)] + reg = [r for r in amd_gpus_windows() if is_uma_apu(r)] for k, g in enumerate(halo): reported = g["vram_gb"] g["vram_gb"] = reg[k]["dedicated_gb"] if k < len(reg) else 0.0 From 01e1bc5c0e4d221cfb13c3b907ad881dd9d9e6e6 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:09:46 +0200 Subject: [PATCH 16/28] setup: write the gfx1150 speed switches for the opt-in install The engine turns 18 exact (bit-identical) switches on by default on gfx1151 (src/core/arch_defaults.cpp) but keeps gfx1150 out of its arch defaults (src/core/arch_defaults_test.cpp asserts arch_default_env("gfx1150").empty()). A gfx1150 install gets the 17 that apply here - the gfx1151 set less STRATA_HCD_EXACT, which copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not fit beside a gfx1150 table - written into the config's "env" beside STRATA_HIPBLASLT_TUNING. The Radeon 890M report (docs/AMD_HIP.md; bench/results/2026-10-07-community-gfx1150) measured the same greedy answers with all 17 on and with all 17 off, decode +2% and prompts +3-6%. The set is setup's own (SETUP_ENV): a re-run refreshes it, and it does not linger after the opt-in is turned off. A new test (tools/test_setup_strix_halo.py, Gfx1150Switches) keeps GFX1150_SWITCHES equal to the gfx1151 arch-default table minus STRATA_HCD_EXACT, keeps the engine's own default path for gfx1150 empty, and checks the SETUP_ENV wiring. Setup's suites pass (strix_halo 40, amd 36, choices 47). Co-authored-by: onionbutties --- setup.py | 12 +++++++++++- tools/test_setup_strix_halo.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c7fecd08..ee9a932d 100644 --- a/setup.py +++ b/setup.py @@ -2119,6 +2119,11 @@ GFX1103_SWITCHES = { "STRATA_EXPERT_V2": "1", "STRATA_TSUM": "1", "STRATA_LFUSE": "1", "STRATA_GDN_SPLIT": "1", "STRATA_QFUSE": "1", "STRATA_PLE_BATCH": "1", "STRATA_SH_STREAM": "1", } +# The same set for a gfx1150 install (Radeon 890M / 880M): less STRATA_HCD_EXACT as well, because a gfx1150 table picks other +# solutions than the gfx1151 one. The Radeon 890M report (docs/AMD_HIP.md; bench/results/2026-10-07-community-gfx1150) measured the +# same greedy answers with all 17 on and with all 17 off, decode +2% and prompts +3-6%. The engine's arch defaults are not used +# for gfx1150 (src/core/arch_defaults_test.cpp asserts gfx1150 stays empty), so this keeps the default path byte-identical. +GFX1150_SWITCHES = dict(GFX1103_SWITCHES) AMD_NAMES = {"gfx1100": "AMD Radeon RX 7900 series (gfx1100)", # when sysfs has no product name "gfx1101": "AMD Radeon RX 7800 XT / 7700 XT (gfx1101)", "gfx1102": "AMD Radeon RX 7600 / 7600 XT (gfx1102)", @@ -4469,7 +4474,7 @@ def write_config(path: Path, cfg: dict): SETUP_KEYS = frozenset({"exe", "args", "cwd", "tokenizer", "model_name", "log", "lib_dirs", "port", "backend", "env", "gpu", "gpus_asked", "layer_split", "host", "api_key", "draft_vocab", "vision"}) SETUP_ENV = frozenset({"STRATA_HIPBLASLT_TUNING", "STRATA_RESIDENT_PIN", "STRATA_NO_ARENA_THP", "STRATA_MMQ_KQ", "STRATA_HC_Q8", - "STRATA_ROUTE_TAIL_SKIP"}) | frozenset(GFX1103_SWITCHES) # the "env" entries setup writes (the gfx1103 switches are setup's too: a re-run refreshes them, they do not linger) + "STRATA_ROUTE_TAIL_SKIP"}) | frozenset(GFX1103_SWITCHES) | frozenset(GFX1150_SWITCHES) # the "env" entries setup writes (the gfx1103 switches are setup's too: a re-run refreshes them, they do not linger) # 0.1.44 added these three, written for Unsloth's files only (unsloth_default_env). In any other model's config they are the # user's own (STRATA_ROUTE_TAIL_SKIP=0 to turn the tail skip off, STRATA_MMQ_KQ=1 ...): a setup run again keeps them there # (0.1.44 dropped them with the rest of SETUP_ENV). @@ -6801,6 +6806,11 @@ def main() -> int: # for gfx1103, so setup writes them into the config. They are setup's own (SETUP_ENV), so a re-run refreshes # them and turning the opt-in off takes them out again. cfg.setdefault("env", {}).update(GFX1103_SWITCHES) + if GFX1150_OPT_IN and gfx_arch_is(gpu["arch"], "gfx1150"): + # the exact gfx1151 speed switches measured on this chip (GFX1150_SWITCHES): the engine has no arch defaults + # for gfx1150, so setup writes them into the config. They are setup's own (SETUP_ENV), so a re-run refreshes + # them and turning the opt-in off takes them out again. + cfg.setdefault("env", {}).update(GFX1150_SWITCHES) if resident: # ROCm: large page-locked host allocations can fail or be slow for the CPU; keep the copy pageable cfg.setdefault("env", {})["STRATA_RESIDENT_PIN"] = "0" if gpu["count"] > 1 or a.gpu is not None: diff --git a/tools/test_setup_strix_halo.py b/tools/test_setup_strix_halo.py index cd93ac5b..adb62d04 100644 --- a/tools/test_setup_strix_halo.py +++ b/tools/test_setup_strix_halo.py @@ -127,6 +127,25 @@ class Gfx1103Switches(unittest.TestCase): self.assertIn(k, setup.SETUP_ENV) +class Gfx1150Switches(unittest.TestCase): + def test_is_the_gfx1151_defaults_less_hcd_exact(self): + """GFX1150_SWITCHES is the gfx1151 arch-default set (src/core/arch_defaults.cpp) minus STRATA_HCD_EXACT, which + copies the gfx1151 hipBLASLt table's solutions 1176 / 1177 and so does not apply beside a gfx1150 table. The + engine keeps gfx1150 out of its own arch defaults (src/core/arch_defaults_test.cpp), so setup writes this set.""" + src = (ROOT / "src/core/arch_defaults.cpp").read_text(encoding="utf-8") + tail = src.split("gfx_arch_is_gfx1151(gcn_arch)) return t;", 1)[1] + block = tail.rsplit("t = {", 1)[1].split("};", 1)[0] # the gfx1151 switch table + gfx1151 = dict(re.findall(r'\{"(STRATA_[A-Z0-9_]+)",\s*"([^"]+)"\}', block)) + self.assertIn("STRATA_HCD_EXACT", gfx1151) # the parse found the gfx1151 block + self.assertEqual(setup.GFX1150_SWITCHES, + {k: v for k, v in gfx1151.items() if k != "STRATA_HCD_EXACT"}) + self.assertNotIn("STRATA_HCD_EXACT", setup.GFX1150_SWITCHES) + for k in setup.GFX1150_SWITCHES: # setup's own: a re-run refreshes them + self.assertIn(k, setup.SETUP_ENV) + self.assertIn('arch_default_env("gfx1150").empty()', + (ROOT / "src/core/arch_defaults_test.cpp").read_text(encoding="utf-8")) + + class PciIds(unittest.TestCase): def test_strix_halo_id(self): # pci.ids: one id for every Strix Halo part (8060S, 8050S, 8040S share it; they differ by CU count) From b0e88eb12f9e7c95a63c5a61eb5705516374ba11 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:10:26 +0200 Subject: [PATCH 17/28] =?UTF-8?q?pcie:=20the=20in-window=20share=20refinem?= =?UTF-8?q?ent=20(PcieAuto)=20on=20HIP=20too=20=E2=80=94=20gfx1100=20port?= =?UTF-8?q?=20of=20the=20XeStrata=20stabilization=20cluster's=20finding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream aa7b0cb gates PcieAuto to CUDA single-GPU (#if !defined(STRATA_USE_HIP)); the machinery itself is engine-generic (pool ms per missed expert + miss counts vs the probed link rate), and this build's start-up H2D probe is already best-of-4 with a +-0.7% spread, so the HIP exclusion was unmeasured-only, the same class as the ROUTE_TAIL_SKIP gate. Same opt-outs as CUDA: layer splits excluded, STRATA_PCIE_FRAC_DEFAULT=old restores the fixed start-up rule. Provenance: MistVVK/XeStrata commits 05309096/055cf9b0/c71cac34/ 5952e8e7 (their measurement-stabilization cluster) demonstrated the failure mode and the fix class; their exact subsystem is not portable (it is their own engine code). (cherry picked from commit acb3deb0522a8fc351a4047d2bd11b8ab7a73dca) Co-authored-by: Zac Chen --- src/program/generate.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index ef8965f2..1655b8d8 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -590,7 +590,7 @@ struct Options { /// Plan v0.3 P6: the share (0..1) of each layer's distinct missed experts the GPU reads over PCIe from the /// pinned arena while the CPU computes the rest (verify windows). double pcie_frac = -1.0; ///< < 0: the model's default (0.2 direct for the Q2_0 pack, 0.55 DMA for native packs) - bool pcie_frac_auto = false; ///< CUDA single-GPU serve, no --pcie-frac: the share is refined in the first decode windows (PcieAuto) + bool pcie_frac_auto = false; ///< single-GPU serve (CUDA + HIP/gfx1100), no --pcie-frac: the share is refined in the first decode windows (PcieAuto) double pcie_probe_gbps = 0.0; ///< the start-up probe's reading (for PcieAuto) std::string pcie_mode = "auto"; ///< auto | dma | kernel | direct /// Plan v0.3 P6: every `adapt_every` rounds, swap up to `adapt_swaps` of the most-routed missing experts into @@ -1648,6 +1648,22 @@ static bool pcie_auto_split_ok() { #endif } +// gfx1100 (RX 7900 XT/XTX/GRE): the same refinement, gate-measured on the one other arch it has run +// on (paired no-regression: 4 alternating starts at 64K, prefill 2189 base vs 2180 with it, decode +// 65.4 vs 65.4; engagement under serve measured: the share refines 0.55 -> 0.25 from the pool's +// 42-45 us/missed expert and the probed 28.4-28.5 GB/s link). Nothing is claimed for the unmeasured +// archs: they keep the gate's "earlier behaviour". +[[maybe_unused]] static bool pcie_auto_fork_arch_ok() { +#if defined(STRATA_USE_HIP) + int dev = 0; + cudaDeviceProp p{}; + return cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&p, dev) == cudaSuccess && + strata::kernels::gfx_arch_is(p.gcnArchName, "gfx1100"); +#else + return false; +#endif +} + // The effective host->device bandwidth of the PCIe link: copies from pinned host memory, as the expert arena's // reads are. The native default share (0.55) was measured on x16 links (~26-28 GB/s); a x8 card in a x8 slot // carries about half of that. Returns < 0 when the probe cannot run (then the caller keeps the default). @@ -2888,7 +2904,13 @@ int main(int argc, char** argv) { o.pcie_frac = pcie_frac_for_gbps(bw, base); std::fprintf(stderr, "strata generate: PCIe probe: %.1f GB/s host->device (best of %s) -> pcie_frac %.2f " "(default %.2f)\n", bw, bursts.c_str(), o.pcie_frac, base); - o.pcie_frac_auto = (o.layer_split.empty() || pcie_auto_split_ok()) && decode_defaults_arch_ok() && !pf_old; + // 0.1.43 upstream: split opt-in + gfx12 default-on (decode_defaults_arch_ok). gfx1100 joins it: + // the refinement is engine-generic (pool timings + miss counts vs the probed link), the start-up + // probe here is already best-of-4 with +-0.7% spread, and on gfx1100 it is gate-measured + // (pcie_auto_fork_arch_ok). Every other AMD part keeps its earlier behaviour; + // STRATA_PCIE_FRAC_DEFAULT=old keeps the start-up rule everywhere. + o.pcie_frac_auto = (o.layer_split.empty() || pcie_auto_split_ok()) && !pf_old && + (decode_defaults_arch_ok() || pcie_auto_fork_arch_ok()); o.pcie_probe_gbps = bw; } else { o.pcie_frac = base; From 82922f55e2d952c9c98a73c7e1bb9347f0f5a090 Mon Sep 17 00:00:00 2001 From: sa Date: Thu, 8 Oct 2026 17:04:06 +0500 Subject: [PATCH 18/28] topk: compile the wide kernel on HIP too (it was CUDA-only; every deep context on AMD paid the ref radix) block_topk_wide_kernel is plain shared-memory / atomicAdd code with no sm_90 feature, but its definition and the dispatch branch sat behind #if !defined(__HIPCC__), so on AMD a context past the register kernel's reach (about 135K cells) always fell back to the 4-pass ref radix. The ids are identical by construction (the same radix rule), which the bench states: 256/256 at 256 queries x 65537 blocks, 1/1 at nq=1. Measured on a Ryzen AI Max+ 395 (gfx1151, ROCm 10.1), qsa_select_bench: - nq=1, 131073 blocks (a decode window at 512K context): 2.24 -> 0.77 ms (2.9x) - nq=256, 65537 blocks (a prompt batch at 262K): 3.16 -> 1.43 ms (2.2x) End to end this moved the deep-context decode of a 512K-token prompt from 19-22 to 24-26 tok/s and the 512K prefill from 473 to 634 tok/s on that PC (together with the split scorer of another change). STRATA_TOPK_STREAM=0 still restores the register kernel. --- src/kernels/cuda/qsa_select.cu | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu index cb06396a..a8ea4ec3 100644 --- a/src/kernels/cuda/qsa_select.cu +++ b/src/kernels/cuda/qsa_select.cu @@ -690,13 +690,14 @@ __global__ void __launch_bounds__(TK_T) block_topk_reg_kernel(const float* __res } } -#if !defined(__HIPCC__) // ---- a query with more blocks than the register kernel holds (contexts past 4 * 1024 * TK_PER cells): the register // kernel's threads, per-warp histograms and warp scans, with each key read from memory again on every pass. A // histogram has no order, so on the four radix passes thread t reads blocks t, t + 1024, ...: a warp reads 32 // neighbours at a time. The cells are emitted ascending in the order (warp, row, lane): warp w holds the `per` rows // of 32 consecutive blocks from block w * 32 * per. block_topk_kernel's selection rule (radix threshold, ties to the // lowest index): identical ids. +// campaign3: also compiled on HIP (gfx11: plain shared/atomic code, no sm_90 features; the dispatch still needs +// reach > fit, i.e. the deep contexts where the ref radix was the only option on AMD). __global__ void __launch_bounds__(TK_T) block_topk_wide_kernel(const float* __restrict__ scores, const int32_t* __restrict__ steps, int64_t max_blocks, int64_t cap, int32_t* __restrict__ ids) { @@ -807,7 +808,6 @@ __global__ void __launch_bounds__(TK_T) block_topk_wide_kernel(const float* __re run_sel += __shfl_sync(0xffffffffu, ps, 31); } } -#endif // Block scores with every key block read ONCE for all of a call's queries (block_scores_kernel's grid is @@ -1332,7 +1332,8 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 #if defined(__HIPCC__) constexpr int64_t kRegMinBlocks = 7168; // gfx1201: below ~28K cells the 1,024-thread kernel's fixed cost loses to the ref const bool too_small = counted && reach < kRegMinBlocks; - if (old || too_small || reach > fit) { + // campaign3: `reach > fit` no longer forces the ref radix - the wide kernel below takes it (same ids). + if (old || too_small) { #else constexpr int64_t kWideMinBlocks = 4608; // RTX 3060: a prompt batch below ~18K cells is faster on the ref const bool too_small = reach > fit && active_blocks > 0 && active_blocks < kWideMinBlocks; @@ -1345,10 +1346,11 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 std::fprintf(stderr, "qsa_block_topk: unsupported geometry or cap\n"); std::exit(1); } -#if !defined(__HIPCC__) // Turing prefill (the `counted` bound) above ~90K cells (22,528 blocks): the wide kernel, which reads the keys // coalesced, instead of the register kernel's uncoalesced per-thread runs (PR #743: 131K, 1.03 -> 0.75 ms); the // same ids. STRATA_TOPK_STREAM=0 restores the register kernel there. + // campaign3: on HIP too (was CUDA-only; gfx11 has no sm_90 cluster path and fell to the ref radix past the + // register kernel's reach - the deep-decode top-k cost). Same ids as the ref kernel. static const bool turing_wide = [] { const char* v = std::getenv("STRATA_TOPK_STREAM"); return v == nullptr || v[0] != '0'; @@ -1356,7 +1358,6 @@ void qsa_block_topk(const float* scores, const int32_t* steps, int64_t nq, int64 if (reach > fit || (turing_wide && counted && reach > 22528)) // past the register kernel's reach, or Turing's band block_topk_wide_kernel<<<(unsigned) nq, TK_T, 0, (cudaStream_t) stream>>>(scores, steps, max_blocks, cap, ids); else -#endif if (reach <= (int64_t) TK_T * TK_PER) block_topk_reg_kernel<<<(unsigned) nq, TK_T, 0, (cudaStream_t) stream>>>(scores, steps, max_blocks, cap, ids); else From e5d91bf239a07baee7ac8d6c1af974fbcb6d14b5 Mon Sep 17 00:00:00 2001 From: 2jztricks <96335554+2jztricks@users.noreply.github.com> Date: Sun, 11 Oct 2026 13:44:16 +0300 Subject: [PATCH 19/28] hip: add opt-in exact gfx1100 QSA prefill scorer --- CMakeLists.txt | 15 + .../2026-10-11-gfx1100-qsa-scores/README.md | 216 ++++ .../benchmark.py | 137 +++ .../correctness.json | 19 + .../hipblaslt-gfx1100-100401.txt | 34 + .../measurements.json | 1091 +++++++++++++++++ .../prompt-source.txt.gz | Bin 0 -> 20964 bytes .../provenance.json | 168 +++ docs/AMD_HIP.md | 11 + src/kernels/cuda/qsa_scores_gfx1100_test.cu | 32 + src/kernels/cuda/qsa_select.cu | 122 ++ src/kernels/qsa_scores_gfx1100_parity.cpp | 185 +++ 12 files changed, 2030 insertions(+) create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/README.md create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz create mode 100644 bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json create mode 100644 src/kernels/cuda/qsa_scores_gfx1100_test.cu create mode 100644 src/kernels/qsa_scores_gfx1100_parity.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d4fd1d..a82802bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -393,6 +393,21 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) src/ngram/ple_reader.cpp src/platform/direct_file.cpp) target_link_libraries(strata_kernels PUBLIC strata_core strata_artifact) + # Exact gfx1100 prompt scorer (PR1825 method port): optional standalone test, + # also available where the published source omits tests/. + option(STRATA_PARITY_GFX1100_QSA_SCORES "Build the exact gfx1100 QSA score/ID check" OFF) + if(STRATA_ENABLE_HIP AND (STRATA_BUILD_TESTS OR STRATA_PARITY_GFX1100_QSA_SCORES)) + set_source_files_properties(src/kernels/cuda/qsa_scores_gfx1100_test.cu + src/kernels/qsa_scores_gfx1100_parity.cpp PROPERTIES LANGUAGE HIP) + add_executable(qsa_scores_gfx1100_parity src/kernels/qsa_scores_gfx1100_parity.cpp + src/kernels/cuda/qsa_scores_gfx1100_test.cu) + target_include_directories(qsa_scores_gfx1100_parity PRIVATE ${_strata_gpu_include_directories}) + target_link_libraries(qsa_scores_gfx1100_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) + enable_testing() + add_test(NAME qsa_scores_gfx1100_parity COMMAND qsa_scores_gfx1100_parity --full) + set_tests_properties(qsa_scores_gfx1100_parity PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 180 + ENVIRONMENT "STRATA_SCORES_THREAD=1;STRATA_SCORES_THREAD_TRACE=1") + endif() # perf-review D-1: the tensor-core prompt attention vs the FP32 kernel and FP64 (GPU, synthetic, no model); with # the tests, or alone with -DSTRATA_PARITY_PROMPT_ATTN=ON. CUDA only: HIP compiles the tensor-core kernel out. if((STRATA_BUILD_TESTS OR STRATA_PARITY_PROMPT_ATTN) AND STRATA_ENABLE_CUDA) diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/README.md b/bench/results/2026-10-11-gfx1100-qsa-scores/README.md new file mode 100644 index 00000000..82e31bf7 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/README.md @@ -0,0 +1,216 @@ +# Exact gfx1100 QSA scorer: measured prefill benefit, opt-in only + +Measured on 2026-10-11 on one RX 7900 XTX. This accompanies the HIP port of the +four-lanes-per-query score kernel from [PR #1825](https://github.com/Niko1221/Strata/pull/1825) +by xrip, pinned to `14bf32150490bb9f5fc4d9c7c5dcfdc96dd98797`. That PR's code excludes +HIP; its algorithm and reduction order are the source of this port. This is an +AMD extension, not a claim to invent that method. + +The measured benefit is fresh long-prompt processing. The correction-inclusive +coding pilot was 3.3% slower overall. The new path is disabled by default and was +not promoted into the tested machine's production setup. + +## Dispatch and implementation + +Set `STRATA_SCORES_THREAD=1` **before starting the engine**. Dispatch also requires: + +- HIP on the exact `gfx1100` architecture (normal feature suffixes are accepted). +- At least 64 queries and a supplied live bound of at least 16,385 index blocks. +- A live bound no larger than the allocated score capacity. Allocating a 256K + context alone does not select the new kernel. +- The already supported indexer geometry: four heads, dimension 128, block size 4. + +Otherwise the existing scorer runs. Decode, top-k, weights, expert placement, +PLE storage, and sampling are not changed by this patch. CUDA does not compile +the HIP addition. No extra persistent weights or conversation state are allocated. + +The kernel uses four wave32 lanes per query and keeps all four heads in registers. +Each key tile in LDS serves 64 queries. The original FP32 per-lane expression and +xor reduction tree are preserved; the existing tail scorer handles the final block. +The retained layout is 64 queries by 32 key blocks, 512 key blocks per workgroup, +256 threads. Four layout variants were screened; none improved stage time by the +predeclared 10% threshold over this one, so the first layout was retained. + +`STRATA_SCORES_THREAD_TRACE=1` optionally prints one engagement line per host thread. +No trace output is enabled by default. + +## Machine and shared settings + +- RX 7900 XTX, 24 GiB nominal VRAM, gfx1100; PCIe 4.0 x16 observed; fixed 272 W cap. +- Ryzen 9 7950X3D; 64 GiB installed RAM, approximately 62 GiB reported by Linux. +- Nobara 44; kernel `7.2.9-200.nobara.fc44.x86_64`; ROCm SDK 10.0.0. +- [OrcaRouter Qwen3.8 Flash Next Uncensored](https://huggingface.co/orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF), + IQ3_S. Exact shard names, pack/profile hashes, and configuration are in + [provenance.json](provenance.json). The Hugging Face revision was not recorded. +- One GPU, one server, 15 CPU expert workers; logical context 262,144; int8 KV, + 32,768 resident KV cells; prefill chunk 16,384; spec/MTP 6, floor 0.70, maximum T 6. +- Same balanced expert profile in every arm; 8,144 actual GPU expert slots, + 16,622,003,200 blob bytes; 34 GiB resident budget and 1,024 MiB conversation cache. +- NVMe model storage; PLE lookup shard on a dedicated ext4 SSD partition with + direct I/O. The lookup was not moved into RAM. GPU vision was enabled but no + image prompt was used in these measurements. +- Private experiment cgroup: 56 GiB memory cap, swap limit zero; at least 8 GiB + available host memory required. This is not a claim that system-wide swap was disabled. +- Same local prefix-cache frontend and chat template for both arms. Its hashes + are recorded. The stock latest Python frontend was not benchmarked here. + +The repeated model tests used the reconstructed tuned 0.1.40.3 engine, including +PR #1107 prefix reuse and resident-budget loans in **both** arms. They compare the +installed control against its reconstructed candidate, not two official release +binaries. A separate comparison builds current main at +`61b3fb5dd3f1e8ec09cf7e4e05208bc6d3c46406` plus this patch and uses the **same binary** +with `STRATA_SCORES_THREAD=0` and `1`. Those families are never pooled. + +## Before and after + +The full per-request values, native prompt/decode timing, token counts, output +hashes, means, medians, and ranges are in [measurements.json](measurements.json). +These are **non-streaming request times with a one-token cap**. Model loading and +queueing were excluded; streaming time to first token and sustained generation +throughput were not measured by this screen. + +Each fresh case starts a new private model worker. Actual reused prefix tokens +were zero. The OS file cache was not flushed, so these are fresh model prompts, +not cold-boot storage benchmarks. Inputs are repeated numerical source code, +greedy sampling, seed 6300, reasoning disabled. They are a prefill screen, not a +quality evaluation or representative project-completion benchmark. + +| Engine family | Actual fresh tokens | Pairs | Before mean | After mean | Less elapsed time | +| --- | ---: | ---: | ---: | ---: | ---: | +| tuned-v0.1.40.3 | 130,978 | 3 | 66.741 s | 59.769 s | 10.45% | +| tuned-v0.1.40.3 | 239,906 | 3 | 142.718 s | 110.407 s | 22.64% | +| current-main-same-binary | 130,978 | 1 | 68.872 s | 60.020 s | 12.85% | +| current-main-same-binary | 239,906 | 1 | 142.843 s | 111.828 s | 21.71% | + +| Tuned build fresh tokens | Before median (range) | After median (range) | +| --- | ---: | ---: | +| 130,978 | 67.514 (64.257–68.451) s | 59.465 (58.863–60.979) s | +| 239,906 | 142.059 (141.660–144.436) s | 110.438 (109.549–111.232) s | + +**Cached follow-ups (2,085 new tokens):** + +| Engine family | Reused prefix | Pairs | Before mean | After mean | Less elapsed time | +| --- | ---: | ---: | ---: | ---: | ---: | +| tuned-v0.1.40.3 | 130,978 | 2 | 2.829 s | 2.658 s | 6.023% | +| tuned-v0.1.40.3 | 239,906 | 2 | 3.418 s | 3.417 s | 0.035% | +| current-main-same-binary | 130,978 | 1 | 2.896 s | 2.781 s | 3.965% | +| current-main-same-binary | 239,906 | 1 | 3.522 s | 2.958 s | 16.037% | + +The repeated near240K cached result is effectively flat (0.035%). The current-main +follow-ups are single pairs and do not establish a repeatable cached-prefix gain. + +**Submitted CMake scorer microbenchmark:** + +| Scorer-only live context | Queries | Before | After | Stage speedup | +| --- | ---: | ---: | ---: | ---: | +| 131,072 | 256 | 3.065300 ms | 0.742917 ms | 4.126x | +| 240,000 | 256 | 5.264949 ms | 1.389344 ms | 3.790x | + +The repeated family used orders off/on, on/off, off/on. All three fresh request +pairs at each length had the same input hash, output hash, and output count. +Cached continuations in trials 2 and 3 added 2,085 actually processed tokens and +reused the preceding 130,978 or 239,906 tokens. Trial 1's much smaller continuation +is retained in the raw data but excluded from the 2K continuation summary. +The follow-up inserts a fixed synthetic assistant message; it does not use the +one generated token as a complete conversational answer. This isolates prefix +reuse and incremental prompt processing. + +## Correctness and build checks + +The submitted HIP CMake target passed 35 cases comparing against the unchanged +warp scorer: **223,664,777 score values bitwise equal**, and **11,895,800 ID buffer +entries equal**, including padding. Allocation guards passed. Cases cover +query counts 1/6/8/9/63/64/65/127/128/129/256/1024; the 65,535–65,539 boundary, +128K and 256K; capacity versus live extent; absent/negative/oversized bounds; +random and wide-exponent floats, ties, signed zero, NaN/Inf and cancellation. + +The same compiled CMake test provides warmed, interleaved ABBA GPU-event timings +with four trials and ten calls per trial. See [correctness.json](correctness.json). +At the real 256-query batch size, this tests the scorer stage rather than making +a claim about whole-request or whole-task speed from a microbenchmark. + +On the tuned model, the 4K/131K prefill plus first generated token matched the +control's main state byte for byte. Separate 64-token continuations and +STOP/resend output checks matched. Full internal state after 64 speculative tokens +was not always byte-identical; the original binary also produced differing +speculative states across repeats. This does not establish the cause of the coding +pilot's different repair paths. No claim of universal bitwise model output is made. + +- Current-main full HIP engine and the standalone CMake test target built with + ROCm 10.0.0, Release, gfx1100, native experts and optional prefill MMQ enabled. +- The touched `qsa_select.cu` also compiled with CUDA 13.0 for sm_89. There was no + CUDA GPU test or full CUDA-engine build. No SYCL source was changed. +- Current-main off/on model requests completed with matching input/output hashes. +- Unsupported GPU architectures were not runtime-tested on hardware. + +Build and run the standalone check even from the published tree without `tests/`: + +```bash +cmake -S . -B build-qsa -G Ninja -DCMAKE_BUILD_TYPE=Release \ + -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1100 \ + -DSTRATA_BUILD_TESTS=OFF -DSTRATA_PARITY_GFX1100_QSA_SCORES=ON +cmake --build build-qsa --target qsa_scores_gfx1100_parity -j 6 +ctest --test-dir build-qsa --output-on-failure -R '^qsa_scores_gfx1100_parity$' +``` + +Supply your normal ROCm compiler/package paths if they are not discoverable. +CTest sets the opt-in and engagement-trace variables and skips non-gfx1100 cards +with return code 77. + +## Coding pilot and limitations + +Two official Exercism/Aider Polyglot tasks, Go alphametics and Rust xorcism, were +embedded in a 196,608-token source archive, leaving 65,536 tokens within the 256K +window for tool results and repairs. xhigh, 8,192 reasoning tokens, 2,048 answer +reserve, temperature 0.3, top_p 0.95, top_k 20, min_p 0; one matched trial per task, +seeds 7830/7831. Tools and full-suite checks ran until the first pass, with no +post-pass requests. This is a long-context stress pilot, **not an official Aider +leaderboard score**. Its test and correction time is included. + +| Task | Original | New scorer | Original/new turns | Result | +| --- | ---: | ---: | ---: | --- | +| go/alphametics | 209.136 s | 400.318 s | 3 / 5 | Both full suites passed | +| rust/xorcism | 473.734 s | 304.906 s | 6 / 6 | Both full suites passed | +| Total | 682.870 s | 705.225 s | | New scorer **3.27% slower** | + +The different Go run generated more tokens and took extra repair turns despite +matching normalized inputs through the first three requests. The cause remains +unresolved. The combined pilot did not meet the predeclared promotion gate. More +coding repeats, the held-out extension, and the full 24-task suite were therefore +not run. No Luna, frontier-model, or overall agent-quality superiority is claimed. + +An earlier 240K-archive pilot ran out of continuation space: the Rust history +reached 262,714 tokens, beyond 262,144. Its partial attempt is listed separately +in the data and was not reused in the 192K score. It was a benchmark-protocol +failure, not evidence of a scorer crash. + +## Reproducing the request screen + +[benchmark.py](benchmark.py) generates the exact frozen fresh/continuation request +hashes used here from the included compressed numerical-source fixture. It reads +the model pack's tokenizer and uses only Python plus the existing tokenizer's +`regex` dependency. The supplied [hipBLASLt table](hipblaslt-gfx1100-100401.txt) is +specific to this SDK/device pair; do not assume its solution IDs transfer to another +version. The balanced expert profile is identified by hash, not included; use the +same profile and other settings in your two arms. + +Run a loaded private server with the same binary and settings, changing only +`STRATA_SCORES_THREAD=0` or `1` **at startup**. Restart that worker between every +length/arm invocation, preserve every observation, and repeat in both orders: + +```bash +python bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py \ + --url http://127.0.0.1:8080 --tokenizer /path/to/pack/tokenizer \ + --model strata-qwen38-iq3s-uncensored --length 131072 \ + --variant off --output off-128k-trial1.json +``` + +Then restart with the scorer enabled and use `--variant on` and a new output file. +Repeat with `--length 240000`, then reverse arm order. Use `--prepare-only` to +check request hashes without inference. `STRATA_API_KEY` can supply an API key; +it is never written to results. The script refuses to overwrite any attempt and +records a failure if a fresh prompt reused cached tokens. + +The label does not control the server's environment: confirm the startup setting +and, in the enabled arm, the engagement trace. Measure your model's full output +and correction-inclusive workload separately before adopting the feature. diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py b/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py new file mode 100644 index 00000000..e22d547a --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/benchmark.py @@ -0,0 +1,137 @@ +"""One fresh prompt and one cached continuation; restart the server between invocations. + +Use the same engine/config with STRATA_SCORES_THREAD=0 or 1 at server startup. +Model loading is excluded. This measures request latency, not streaming TTFT or coding quality. +""" +import argparse +import gzip +import hashlib +import importlib.util +import json +import os +from pathlib import Path +import time +import urllib.error +import urllib.request + +HERE = Path(__file__).resolve().parent +REPO = HERE.parents[2] + + +def digest(data): + return hashlib.sha256(data).hexdigest() + + +def load_tokenizer(folder): + spec = importlib.util.spec_from_file_location('qsa_bench_tokenizer', REPO / 'tools/strata_tokenizer.py') + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + vocab = json.loads((folder / 'vocab.json').read_text()) + tokens = [None] * len(vocab) + for token, index in vocab.items(): + tokens[index] = token + return module.Tokenizer(tokens, (folder / 'merges.txt').read_text().split('\n'), + json.loads((folder / 'token_type.json').read_text())) + + +def make_requests(tokenizer, source, length, model, follow_tokens): + ids = tokenizer.encode(source) + if not ids or not 0 <= follow_tokens <= len(ids): + raise ValueError('Empty source or invalid continuation size') + text = tokenizer.decode((ids * (length // len(ids) + 1))[:length - 128]) + body = dict(model=model, temperature=0, top_p=1, top_k=1, seed=6300, + reasoning_effort='none', max_tokens=1, messages=[ + dict(role='system', content='You are a precise coding assistant.'), + dict(role='user', content=text + '\nReview the numerical implementation and synchronization in detail.')]) + follow = json.loads(json.dumps(body)) + follow['messages'].extend([ + dict(role='assistant', content='I will inspect the numerical implementation.'), + dict(role='user', content='Continue with a detailed review of synchronization and memory lifetime.')]) + if follow_tokens: + follow['messages'][-1]['content'] += '\nADDITIONAL_SOURCE\n' + tokenizer.decode(ids[-follow_tokens:]) + return [('fresh-' + str(length), body), ('follow-' + str(length), follow)] + + +def fetch(url, body=None): + headers = {'Content-Type': 'application/json'} + key = os.environ.get('STRATA_API_KEY') + if key: + headers['Authorization'] = 'Bearer ' + key + req = urllib.request.Request(url, data=json.dumps(body).encode() if body is not None else None, + headers=headers) + with urllib.request.urlopen(req, timeout=900) as response: + return json.load(response) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--url', default='http://127.0.0.1:8080') + parser.add_argument('--tokenizer', type=Path, required=True) + parser.add_argument('--model', default='strata-qwen38-iq3s-uncensored') + parser.add_argument('--length', type=int, choices=[131072, 240000], required=True) + parser.add_argument('--follow-tokens', type=int, default=2048) + parser.add_argument('--source', type=Path, default=HERE / 'prompt-source.txt.gz') + parser.add_argument('--variant', choices=['off', 'on'], required=True) + parser.add_argument('--output', type=Path, required=True) + parser.add_argument('--prepare-only', action='store_true') + args = parser.parse_args() + source = gzip.decompress(args.source.read_bytes()) if args.source.suffix == '.gz' else args.source.read_bytes() + requests = make_requests(load_tokenizer(args.tokenizer), source.decode(), args.length, + args.model, args.follow_tokens) + receipt = dict(variant=args.variant, length=args.length, output_cap=1, seed=6300, + temperature=0, reasoning_effort='none', follow_source_tokens=args.follow_tokens, + source_sha256=digest(source), script_sha256=digest(Path(__file__).read_bytes()), + prepare_only=args.prepare_only, rows=[], status='prepared') + # Refuse to overwrite previous observations, including failed attempts. + with args.output.open('x') as output: + def save(): + output.seek(0) + json.dump(receipt, output, indent=2) + output.write('\n') + output.truncate() + output.flush() + try: + save() + if args.prepare_only: + receipt['request_hashes'] = {case: digest(json.dumps(body).encode()) for case, body in requests} + save() + return + health = fetch(args.url.rstrip('/') + '/health') + if not health.get('loaded') or health.get('max_context') != 262144: + raise RuntimeError('Requires an already loaded 262144-context server') + for case, body in requests: + started = time.monotonic() + response = fetch(args.url.rstrip('/') + '/v1/chat/completions', body) + elapsed = time.monotonic() - started + metrics = fetch(args.url.rstrip('/') + '/metrics?requests=all') + native = max(metrics['requests'], key=lambda row: row['time']) + choice = response['choices'][0] + message = choice.get('message', {}) + row = dict(case=case, seconds=elapsed, usage=response.get('usage'), + finish_reason=choice['finish_reason'], + request_sha256=digest(json.dumps(body).encode()), + output_sha256=digest(((message.get('reasoning_content') or '') + '\n' + + (message.get('content') or '')).encode()), + native={k: native.get(k) for k in ( + 'prompt_tokens', 'reused', 'prompt_read', 'output_tokens', 'engine_generated', + 'prompt_ms', 'decode_ms', 'drafts_offered', 'drafts_accepted', + 'hit_rate', 'ram_blobs', 'file_blobs', 'file_mb')}) + receipt['rows'].append(row) + save() + if choice['finish_reason'] not in ('length', 'stop'): + raise RuntimeError('Request did not complete normally') + if case.startswith('fresh-') and native.get('reused') != 0: + raise RuntimeError('Fresh prompt reused a prefix: restart the server and use a NEW output file') + receipt['status'] = 'complete' + save() + except Exception as error: + receipt['status'] = 'failed' + receipt['error'] = str(error) + if isinstance(error, urllib.error.HTTPError): + receipt['http_status'] = error.code + save() + raise + + +if __name__ == '__main__': + main() diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json b/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json new file mode 100644 index 00000000..0fc79c15 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/correctness.json @@ -0,0 +1,19 @@ +{ + "returncode": 0, + "bitwise_qualification": "1: QUALIFIED cases=35 expected_thread_cases=26 scores=223664777 ids=11895800 bitwise_scores=true bitwise_ids=true guards=true", + "dispatch_observed": true, + "timings": [ + "1: TIMING ctx=131072 nq=256 baseline_ms=3.065300 candidate_ms=0.742917 speedup=4.126034 trials=4 repeats_per_trial=10", + "1: TIMING ctx=240000 nq=256 baseline_ms=5.264949 candidate_ms=1.389344 speedup=3.789521 trials=4 repeats_per_trial=10", + "1: TIMING ctx=140000 nq=1024 baseline_ms=13.833862 candidate_ms=3.112324 speedup=4.444866 trials=4 repeats_per_trial=10", + "1: TIMING ctx=240000 nq=1024 baseline_ms=25.035099 candidate_ms=4.841821 speedup=5.170596 trials=4 repeats_per_trial=10" + ], + "resource_pass": true, + "cases": 35, + "scores_checked": 223664777, + "id_entries_checked": 11895800, + "numeric_scope": "Synthetic scores/selected IDs, including padding and allocation guards", + "real_model_state_scope": "4K/131K prefill and first token byte-exact against tuned control; longer MTP sequences may have different internal speculative states even on original binary", + "continuation_scope": "64-token original/candidate output and STOP/resend output match; not full-state equality after64MTPtokens", + "unsupported_architecture_runtime_tested": false +} diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt b/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt new file mode 100644 index 00000000..839434c5 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/hipblaslt-gfx1100-100401.txt @@ -0,0 +1,34 @@ +# solution IDs are scoped to this hipBLASLt version and device architecture +STRATA_HIPBLASLT_TUNING_V1 gfx1100 100401 +bf16 1 2560 1 4096 1035 +bf16 4 10240 4 8192 1033 +bf16 48 2560 96 4096 1035 +bf16 48 2560 96 8192 1036 +bf16 128 2560 128 4096 1036 +bf16 128 2560 128 8192 1036 +bf16 320 10240 320 4096 1036 +bf16 320 10240 320 8192 1036 +bf16 512 2560 512 8192 1036 +bf16 2560 2560 2560 8192 1036 +bf16 10240 320 10240 4096 1036 +bf16 10240 320 10240 8192 1036 +f16 512 2560 512 4096 2106 +f16 512 2560 512 8192 2106 +f16 640 2560 640 4096 2106 +f16 640 2560 640 8192 2106 +f16 2560 640 2560 4096 2106 +f16 2560 640 2560 8192 2106 +f16 2560 6144 2560 4096 2106 +f16 2560 6144 2560 8192 2106 +f16 6144 2560 6144 4096 2106 +f16 6144 2560 6144 8192 2106 +f16 10240 2560 10240 4096 2106 +f16 10240 2560 10240 8192 2106 +f16 12288 2560 12288 4096 2106 +f16 12288 2560 12288 8192 2106 +bf16 1 2560 1 8192 1035 +bf16 10240 2560 10240 4096 1036 +bf16 10240 2560 10240 8192 1036 +bf16 2560 2560 2560 4096 1036 +bf16 4 10240 4 4096 1035 +bf16 512 2560 512 4096 1036 diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json b/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json new file mode 100644 index 00000000..a191c647 --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/measurements.json @@ -0,0 +1,1091 @@ +{ + "units": { + "seconds": "client request elapsed seconds", + "native_prompt_ms": "engine prefill milliseconds", + "native_decode_ms": "engine generation milliseconds" + }, + "model_loading_included": false, + "streaming_ttft_measured": false, + "logical_context": 262144, + "settings": { + "temperature": 0, + "top_p": 1, + "top_k": 1, + "seed": 6300, + "reasoning_effort": "none", + "output_cap": 1 + }, + "fresh_os_cache_state": "uncontrolled; OS cache not flushed", + "source": { + "file": "prompt-source.txt.gz", + "uncompressed_sha256": "43caa800023d7e223629ab8c6a28bd10c50b56c2dd7232b2b5fa4c00144b2e98" + }, + "rows": [ + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 0, + "seconds": 64.25693084098748, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 64157.7, + "native_decode_ms": 27.1, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 0, + "seconds": 0.34837336000055075, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "04d4aba48d6b685765f804b257d6a2872758acf1c10c942ab83d93dd55649fde", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 131010, + "reused_tokens": 130978, + "freshly_processed_tokens": 32, + "native_prompt_ms": 303.6, + "native_decode_ms": 19.4, + "hit_rate": 0.769, + "ram_blobs": 111, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 0, + "seconds": 142.0591052029922, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 141910.0, + "native_decode_ms": 28.8, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 0, + "seconds": 0.3739995119976811, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "bd5c8f85d96ecd7db994611c323e1a644be0b8c66fd6ec2386ae2b23dbdafb34", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 239938, + "reused_tokens": 239906, + "freshly_processed_tokens": 32, + "native_prompt_ms": 302.6, + "native_decode_ms": 21.4, + "hit_rate": 0.756, + "ram_blobs": 117, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 0, + "seconds": 60.97881687400513, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 60863.3, + "native_decode_ms": 40.1, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 0, + "seconds": 0.36607142200227827, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "04d4aba48d6b685765f804b257d6a2872758acf1c10c942ab83d93dd55649fde", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 131010, + "reused_tokens": 130978, + "freshly_processed_tokens": 32, + "native_prompt_ms": 316.8, + "native_decode_ms": 20.0, + "hit_rate": 0.769, + "ram_blobs": 111, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 0, + "seconds": 109.54931649801438, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 109397.8, + "native_decode_ms": 29.1, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native1", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 0, + "seconds": 0.3701446990016848, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "bd5c8f85d96ecd7db994611c323e1a644be0b8c66fd6ec2386ae2b23dbdafb34", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 239938, + "reused_tokens": 239906, + "freshly_processed_tokens": 32, + "native_prompt_ms": 300.3, + "native_decode_ms": 21.4, + "hit_rate": 0.756, + "ram_blobs": 117, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 58.86296121100895, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 58764.6, + "native_decode_ms": 27.6, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.629391199006932, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2580.1, + "native_decode_ms": 20.5, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 110.438449467998, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 110293.6, + "native_decode_ms": 29.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "0-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.935525797016453, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3865.4, + "native_decode_ms": 22.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 68.45079464002629, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 68353.8, + "native_decode_ms": 27.6, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.858728800987592, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2809.2, + "native_decode_ms": 20.2, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 141.66012979499646, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 141512.5, + "native_decode_ms": 28.6, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native2", + "arm": "1-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.2768524099956267, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3203.6, + "native_decode_ms": 21.5, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 67.51405035398784, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 67406.7, + "native_decode_ms": 36.3, + "hit_rate": 0.792, + "ram_blobs": 100, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.798884452000493, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2747.8, + "native_decode_ms": 20.4, + "hit_rate": 0.765, + "ram_blobs": 113, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 144.43555261398433, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 144288.4, + "native_decode_ms": 29.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.558641466021072, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3486.1, + "native_decode_ms": 21.2, + "hit_rate": 0.775, + "ram_blobs": 108, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 59.46537054501823, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 59369.3, + "native_decode_ms": 27.0, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.687445471994579, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2634.6, + "native_decode_ms": 20.5, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 111.23212432701257, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 111085.7, + "native_decode_ms": 31.8, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "tuned-v0.1.40.3", + "trial": "qsa-exact-native3", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 2.8976090920041315, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2821.8, + "native_decode_ms": 21.2, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 68.87175908501376, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 68771.6, + "native_decode_ms": 28.8, + "hit_rate": 0.785, + "ram_blobs": 103, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.8957397949998267, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2847.5, + "native_decode_ms": 20.1, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 142.8425963030022, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 142694.7, + "native_decode_ms": 29.4, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "0-A-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 3.522451185999671, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 3445.8, + "native_decode_ms": 22.3, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-131072", + "case": "fresh-131072", + "follow_source_tokens": 2048, + "seconds": 60.01953978999518, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "029dc64c403bd9597b2a143399fa64555b40b8a4910c708fe3f7c3ddc5a1ad25", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 130978, + "reused_tokens": 0, + "freshly_processed_tokens": 130978, + "native_prompt_ms": 59918.8, + "native_decode_ms": 27.0, + "hit_rate": 0.787, + "ram_blobs": 102, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-131072", + "case": "follow-131072", + "follow_source_tokens": 2048, + "seconds": 2.780924443999538, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "9f2979c0f702e087be57384d4b312a89f606961d08f0beaff64abd550b91b41d", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 133063, + "reused_tokens": 130978, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2730.0, + "native_decode_ms": 21.3, + "hit_rate": 0.758, + "ram_blobs": 116, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-240000", + "case": "fresh-240000", + "follow_source_tokens": 2048, + "seconds": 111.82761004997883, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "dbb6d4004af260501404a2674660c00523b1c455ba557d431395dab5cee7c4dd", + "output_sha256": "d6fadeb81a0f0a9f23a6a06f4c0f266f0afe25f436a0aa575ac593e2d695c969", + "prompt_tokens": 239906, + "reused_tokens": 0, + "freshly_processed_tokens": 239906, + "native_prompt_ms": 111680.4, + "native_decode_ms": 28.7, + "hit_rate": 0.779, + "ram_blobs": 106, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + }, + { + "family": "current-main-same-binary", + "trial": "qsa-exact-current-main1", + "arm": "1-B-240000", + "case": "follow-240000", + "follow_source_tokens": 2048, + "seconds": 2.957570611004485, + "success": true, + "finish_reason": "length", + "output_cap": 1, + "generated_tokens": 1, + "request_sha256": "523b45e7fa9be241cf0434f58ef29285c15a565df7779dae176d8f5a4df2626e", + "output_sha256": "33462c6ad8d3c9823e7b43633ff1a94f7671c4d155888e47618b5f60027701e5", + "prompt_tokens": 241991, + "reused_tokens": 239906, + "freshly_processed_tokens": 2085, + "native_prompt_ms": 2884.7, + "native_decode_ms": 21.3, + "hit_rate": 0.777, + "ram_blobs": 107, + "file_blobs": 0, + "file_mb": 0.0, + "drafts_offered": 0, + "drafts_accepted": 0, + "power_cap_w": 272.0 + } + ], + "summaries": [ + { + "family": "tuned-v0.1.40.3", + "case": "fresh-131072", + "off": { + "n": 3, + "mean_seconds": 66.74059194500053, + "median_seconds": 67.51405035398784, + "min_seconds": 64.25693084098748, + "max_seconds": 68.45079464002629 + }, + "on": { + "n": 3, + "mean_seconds": 59.7690495433441, + "median_seconds": 59.46537054501823, + "min_seconds": 58.86296121100895, + "max_seconds": 60.97881687400513 + }, + "mean_elapsed_reduction": 0.10445730549410659, + "median_elapsed_reduction": 0.11921488589069962 + }, + { + "family": "tuned-v0.1.40.3", + "case": "fresh-240000", + "off": { + "n": 3, + "mean_seconds": 142.71826253732434, + "median_seconds": 142.0591052029922, + "min_seconds": 141.66012979499646, + "max_seconds": 144.43555261398433 + }, + "on": { + "n": 3, + "mean_seconds": 110.40663009767498, + "median_seconds": 110.438449467998, + "min_seconds": 109.54931649801438, + "max_seconds": 111.23212432701257 + }, + "mean_elapsed_reduction": 0.22640152609200292, + "median_elapsed_reduction": 0.22258802552508394 + }, + { + "family": "current-main-same-binary", + "case": "fresh-131072", + "off": { + "n": 1, + "mean_seconds": 68.87175908501376, + "median_seconds": 68.87175908501376, + "min_seconds": 68.87175908501376, + "max_seconds": 68.87175908501376 + }, + "on": { + "n": 1, + "mean_seconds": 60.01953978999518, + "median_seconds": 60.01953978999518, + "min_seconds": 60.01953978999518, + "max_seconds": 60.01953978999518 + }, + "mean_elapsed_reduction": 0.12853191805499842, + "median_elapsed_reduction": 0.12853191805499842 + }, + { + "family": "current-main-same-binary", + "case": "fresh-240000", + "off": { + "n": 1, + "mean_seconds": 142.8425963030022, + "median_seconds": 142.8425963030022, + "min_seconds": 142.8425963030022, + "max_seconds": 142.8425963030022 + }, + "on": { + "n": 1, + "mean_seconds": 111.82761004997883, + "median_seconds": 111.82761004997883, + "min_seconds": 111.82761004997883, + "max_seconds": 111.82761004997883 + }, + "mean_elapsed_reduction": 0.2171270129201055, + "median_elapsed_reduction": 0.2171270129201055 + }, + { + "family": "tuned-v0.1.40.3", + "case": "follow-131072", + "off": { + "n": 2, + "mean_seconds": 2.8288066264940426, + "median_seconds": 2.8288066264940426, + "min_seconds": 2.798884452000493, + "max_seconds": 2.858728800987592 + }, + "on": { + "n": 2, + "mean_seconds": 2.6584183355007553, + "median_seconds": 2.6584183355007553, + "min_seconds": 2.629391199006932, + "max_seconds": 2.687445471994579 + }, + "mean_elapsed_reduction": 0.06023327625065078, + "median_elapsed_reduction": 0.06023327625065078 + }, + { + "family": "tuned-v0.1.40.3", + "case": "follow-240000", + "off": { + "n": 2, + "mean_seconds": 3.4177469380083494, + "median_seconds": 3.4177469380083494, + "min_seconds": 3.2768524099956267, + "max_seconds": 3.558641466021072 + }, + "on": { + "n": 2, + "mean_seconds": 3.4165674445102923, + "median_seconds": 3.4165674445102923, + "min_seconds": 2.8976090920041315, + "max_seconds": 3.935525797016453 + }, + "mean_elapsed_reduction": 0.00034510849382674014, + "median_elapsed_reduction": 0.00034510849382674014 + }, + { + "family": "current-main-same-binary", + "case": "follow-131072", + "off": { + "n": 1, + "mean_seconds": 2.8957397949998267, + "median_seconds": 2.8957397949998267, + "min_seconds": 2.8957397949998267, + "max_seconds": 2.8957397949998267 + }, + "on": { + "n": 1, + "mean_seconds": 2.780924443999538, + "median_seconds": 2.780924443999538, + "min_seconds": 2.780924443999538, + "max_seconds": 2.780924443999538 + }, + "mean_elapsed_reduction": 0.039649747259247525, + "median_elapsed_reduction": 0.039649747259247525 + }, + { + "family": "current-main-same-binary", + "case": "follow-240000", + "off": { + "n": 1, + "mean_seconds": 3.522451185999671, + "median_seconds": 3.522451185999671, + "min_seconds": 3.522451185999671, + "max_seconds": 3.522451185999671 + }, + "on": { + "n": 1, + "mean_seconds": 2.957570611004485, + "median_seconds": 2.957570611004485, + "min_seconds": 2.957570611004485, + "max_seconds": 2.957570611004485 + }, + "mean_elapsed_reduction": 0.1603657638295627, + "median_elapsed_reduction": 0.1603657638295627 + } + ], + "coding_pilot": { + "scope": "Two official Exercism/Aider Polyglot tasks embedded in a192K source archive; not an official leaderboard run", + "seeds": [ + 7830, + 7831 + ], + "reasoning_effort": "xhigh", + "reasoning_budget_tokens": 8192, + "answer_reserve_tokens": 2048, + "temperature": 0.3, + "top_p": 0.95, + "top_k": 20, + "min_p": 0, + "archive_context": 196608, + "logical_context": 262144, + "paired_trials_per_task": 1, + "correction_time_included": true, + "completion_policy": "stop at first full-suite pass", + "rows": [ + { + "task": "go/alphametics", + "arm": "deployed", + "seconds": 209.1360279940127, + "turns": 3, + "success": true + }, + { + "task": "go/alphametics", + "arm": "candidate", + "seconds": 400.3182297559979, + "turns": 5, + "success": true + }, + { + "task": "rust/xorcism", + "arm": "candidate", + "seconds": 304.9063483380014, + "turns": 6, + "success": true + }, + { + "task": "rust/xorcism", + "arm": "deployed", + "seconds": 473.7341761919961, + "turns": 6, + "success": true + } + ], + "totals_seconds": { + "deployed": 682.8702041860088, + "candidate": 705.2245780939993 + }, + "elapsed_reduction": -0.03273590467259768, + "all_passed": true, + "minimum_available_gib": 8.621219635009766, + "resource_pass": true, + "general_promotion": false + }, + "abandoned_240k_archive_pilot": { + "status": "infrastructure_failure", + "reason": "Insufficient continuation headroom: Rust history reached262714tokens, exceeding262144", + "go_pair_seconds": { + "off": 325.555172590015, + "on": 323.6994908300112 + }, + "both_go_passed": true, + "rust_on_model_seconds_before_failure": 311, + "rust_off_not_attempted": true, + "pooled_with_192k_family": false + }, + "full24_run": false, + "cloud_comparison_run": false +} diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz b/bench/results/2026-10-11-gfx1100-qsa-scores/prompt-source.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..436f2a826f654a977e0eb646187ac4919dbef5c3 GIT binary patch literal 20964 zcmV(`K-0e;iwFP!00002|Lwhdchko9Km0$hLeNFA!3nmk7?Y56r4ZUIZfO!q&&uI( zWm`@}e2Zo0@}qoT`}5g*W~7lck}okda1z?YmS*d6#Z$Yz3{s&|3u@0`+G1(0c8+ynf)(*XM)b z)yO|S8C!)`(Xz{Sbp^j_*5QfAEn4nmd@>jXvi6=g>iI$75BioLSSQ}dYhGE$BMioC zmoQ7{%b;VmPTbM4SF*+f^!&;idZPdp2F`6~RN{@d+RWgU(A0IKj4yjmPI+bta=e z8uqwadw}WVc0YMoZ9JhGok6!dxS%n%2K}~ALkrgBD$?S*&B3|H!xGEiAB@p!(G^;e zVYJfnRdC{VyH?Ya(}%_}*=~GfBkD#lrp@hkt>IwA?IuU8_Tu61JJ!Lwmxmv=_jjz_ z18Z;p-JiQJc3xQbwh!?AUdj5fd-(gi_lFir>~Ft4{EzkSrM3O`Kh~?=w=YW8&R=`` zI|m2WyM2PT`)2R;?hYRBzJ31s{fphVzgfSc>f3kN@VnUdfP46k+mz6DcMb^No1OjV zzvJunue+~z5C2mlSTA=E-xB1P@Aj>2Yj1o1aQFH9*W3Hn-uwN%cLzJ@#0x-vyZiR# zJ{sD2v-9?F6%FH=weu&wSO>pvzkW@v5xDL57{)$z)O!AI??3yyzx{q_{r>Ltiyb`t zbqD?1{`K{aXbq!#{(5`&P04z({bu{O9j^5bfOwEpQgqY$@cRxurB=7`-}A%WcW-Gt z&)>a0+{f1vhP!_l*8Z@2uv4s*~aHUUtd$&~c{} zIjc7+jSeu&*qc()KWoU3se*Q`F%Bj@!npLjW8H0gfa$dhjmGc0d(WRY8bz%+wbhfYvC$W&)U1sckTdH1!M1WI09-JTYtQ=HZ6Otwvl{Zrx#T_^?cX(_|F&n1Sk0z zdvxyrFC5bgGyM0!5{<*(_jk5m9H_3{!H_0EyML^``n5Y~onjaket;`Gw$<)!@V5!7 z*Bf*bySTxQD)z_t^RttqYU&x4tK;F9jj)Y+#n46|>P6KUlvc|wCu>>lbX&D}rD|+A zs^Ce_4Ni@HtvMg_$EwWX0B|S2{6HR{~Bw6Hew9!%Dt=Jy(};0kj$*^t{oy5P%RKbPDPO z6|K!ptMa5~{roe?3;(#EeCHIiAjtE@=?Nw3Y#}E&5WfXZ1NcrJ`hfUK4Ng z`V|!|g@@WOSVOU{ShX2p%Q;F9C>s5mVTPRe1cgP;L?Hzv}twFOs9aZ&oi>T zp>^F!zje}R4krC}&}bB5gmDQSK$+w2py_ro-1C9owj{%+#9j^Np9B+7U?N-0%0ue_ ztn1-+WADZ523Y&U{oUt>=vv~)yU_@Yp{OdBOMCceP%ALE92vRdw_75S-FuB}@MUf){br3t`8T1}dC7J8n0 zqbo}kvUpzObI!D=YLa&(x`jKW!~>K4yE^jG1#p@lS3$S>)_wj=we-2aFL=>St6bD; zv;zgc9TeImn(Gy>dvt;e|F}Du;RH1rO4bPo$B?4Vb$ZlKHpt0vA%M}bj6pM;$M4{9 z98=F|ZjI-Ij}EXtz&A#H2#`8$|J;W>sc`HQ67IO|Hod4|d((Fa7&?WOW1JtzvL{2p zEZ(3)hhq`s;qUd>Q48oC@-f8U8*}b3lpR)u4E;W2dKM&84d`4NXKRgDVk~}d*lnEm zdS@1idpsfdCSf=_?%`&DlpS|4NxoL6-|YYkpws|?EySlGaRAP{rR;Yn+3zML4Xk9b z6GehnDffL(y=IBX&k%{MmG0yp{&roR(r~AB8nl(l*fkr;7rpRB9%VzP1r&^LJtLy# z(Ia1{Um|31-Yrwf!g=?o{1JqXRd9d|u>Y-}t@35LBmQj|YgSav%A7S%M4N^46WJ&_ z_v{(iH?CSKi+|>-m9T1M&Z^ufkM|$$g0WCV6sm|q6=NZ6!3s)ALg>Ywvt0miAekeZ zX5eEf{;Cqa0$#1)by=a86kIz27ZWMRlm*^U!qke~QXs_Jb)Z5NEATKLVn0WyF)Z0j zmL$NvsNk36jwaFHT8A+-?|WN3E#RrFBB@;}wt7kJiXN?qCs*o8Z#F_dLo3WN}KH!M(*1)NlY1j;7)_CqP}$R0vi zQjSB)N0KY^2@tfoBMvcHg7EPtpr6V{q9awCzy^rQHwq6GFX=jvk66G9o zxf4QS>RVw&efUI#o2^zRR0X(`%WzB5XI=^QwooWw1cY0wooa`$?Ejqr<^E$nR0S&T z(E604YXGIK5K61u!YdT8`Jy-pDJ^Qbl5E*tpk*i3vYp>@;xZ3f`J1NBdj{P#SMTu> z(HdU+eva@EcAzgdA^^vZvUWiUbWIo-CJF-o7O3LNRy#1=H#p+;=|`OE6TW+tJm3*T zbulrS7#?%&4PQv&t=h3M2}pvnBjSySv`LAHEf7?ELfiPzu7{*2+tPS_57^o2w+7u{ zvjS4mZGp{zZAk!}B)APCH!Id?aA6fN_YQp$9Bt4e%Zpb>lLI9 z-pCaeE(CDJ4O*m`hCBkM8_?L&wN)a9xo`ai4gMI`I;(fa9tHwV=2>$v=voKV(yJ{4 zqbk&;4_P>rE8<93mnUS*vlO>JzMjVhm}h1>S%6ft0^u zrmSD29(g^6RKvo*zJB-o)j?x#XTJdh6w*VJHu|BZ&n9s%yGdL<_S;I<_b|cXUKKN$ z-l#tI4xw}I?877zox0R{7d5bp8npWa&rIEVrPBlB-tdUv(fRoNWh0IxPMgG?Qm-Fd z1t{Vl(?G#S((`AD2E|hPS+tZ2b@aGYmLD8HZj|P)ru!_ol zkOX)7xK3|$4roGvbq?vg|`K52r|oAT;NJxkABp5(@Elv#4KZh3Cf4`lF@GyF->Cms=eZM zJ+dB!LF%M`x~lGC{qD3_h7Ylyz0$mb5R27VWXl>1prN9-M051%R>dK|VhO)TCaS{N zl<7a*|6ut}J(fk|8k~%{s1t)|VG#bgFfnZn+Fme=9LY|wj?&Oz@k?~-HJW4_VHv#+(JYB%0)4E)eXPr3pn5bfU@4T4~WkShAro=9C|!1V;b z@D<2)!lMRq{o0u32O-xJgt~nr>GYbj5S?x>n>@F(sd7P%+sh%sZxDHF-;%etlKlaa=vBXUQR2^zpnN}TN3^dx3DBSc#BkAQ6uZztL_(Rtp zk)FF!TOkcC(Xm3})b+>XuD3#xB9}C7Dz(_%&LwA5 z*HmK?KA|=#Nqxywb?m%!c$VUp1n2WYWD=KZHk2WkB!H@m^=(%D@4QN0Cr8QavrJnb z1<9vraW~ARiLN6n5!AbH)lG#^COGjsV_A|FKveuOTL>G=i;@MYzmTo4GDim{r1zby zj-7zX414C}_DmMFqpmqwU6Vx%s&gb}SFOc+NKdGXRiSn^!xO{g0so`G7lApe#;g3? z?+QISE75ITiCz`|%(YIWB0SQ9+p?M?{+X*W-F{9Eg@IE*+a&^((ErA?zcJQ;b=f{^ zmsxjgGH7g9r80L;+@PrB>Z^Z;A5Upw#ja+hM?FP0#*Wh_bKWcb8z+XeCGsOHaLtB7 z2Bsfa5ij&>fLZ$zcQ#d)cEJB73bQX!$qHLHC{r`k()3_qWHS+$d#?20@+hvlB4ecD zk?iTmd_`8eZpdlIRY}z>Rnmph@s<+!yd6_35#f+#P2rTrylJHtGN&n3k;b1cou90l z)j!o+^^b|4RCLM>V<_3PaRH7J!&x#*S)ayI(hUA!JZ1Hkr@ZAUufu^)6O z;)4h^F&UAzh4{*`+w6LRyW9|L7r0Est)Sb)?H_yX1ZT-GalgP8Mw$rwXHFlcxLlPS zMhWNe;8tLpT*B`%gs&_0Dt^`0@XL9MUsd{K+x!~W6aK?{8xO0ngj>Vs8cNmif2C3- z2h=I-txdgX@K_pRHh4RnIlO7GQYturq&N{Fpz+(wzn+$B#XC}|yZz?HdK57R3^>Zj znFYy>I4N2%g4P80_?Sr}3N#}dhDY8y2)lEZpEsJ|Zt3o>%ULy8Q$4iKt9HIg5Et7j z=yO~&8fKj}poQ)e-L4)LF?@*I8-sQ``IwEFj9|R3PyI;Pc`g%mh zpY*rZl|ad+w=6JH#%~RxDz zm$C?>Ank*7XB2Yqk9jIY%;8&3p$jOu<~PR`ApY~bea)8;SN9Cq#i^v z%A~ML`gI6t3`wqt35!c;!U;?n0VLG_I2et;4zi^zRcQj?lz_&+jf6#>-?WTnDTjDj zVwQhf&f=tvY^(MUC2OgFLs5$pS=82xKbpKHej(n52>(%-{=hf=miVJSV1z$m2P?O?eeYpa={ZJ7l&BFmj z6p)SslP03;%M>TX?Fn&$OfN!q8X}OK?sgVIhwJ6k>G|ev0W@Js##QYP|q9P9v|68ub^?U}`wFK{8 zyMYGRu+xdGsOigNB}&gU!LH}lcGBk44P`A5i2%a3iZfYecXKSWlV!2|sUGTP+NwXg zEW{XG`uR}J;e9<_K^5Z|&5V@i?7>#7m`p~RRw;F?38fI*4PZogD7did@00UAIxg)!r zrBTM9kjx63jFYyqJ@8=U?J6cjDKg2%T%-Z?#}jV)Vle3Bfml)F1G8VgbomSg~ile@yyJU(6(XJboD8+7f**r447c4!6*Arw7@ zkW-@iI{wr)cQlNb*onr~mib2ypdBw(sYK;qpPpT=uF6#yVpchOO$F{QC(3=5 z)1;r}Zth{GQnH(5rfz3Xk6vyqdv+@NsIw9&mWN5E=iUojzU_PB$~T5N@o#cQb+FJNP&`)bIq+I_t`dODN-dC z8rizmTLAyz4A5g&NJ@ruc`HM@l_AX_L)y&wv2Xz(3R-!!YVB3mg}D|TuGQ5#sNSL1 zVtp_qOt8`LI}}lsZL^y0xOE~@v1b3EZEF5qKQads*k4b^$Fi&vO&jhX++jF0Z3G*T z;REO;>_MW-4SH+}PSEt&vGn4^M}%i=Y`z#rZa-*^{3Za9v%CnpEC*DvRAPCzIlyoV z9Bx(2@XB}~FHt0}$JKgVl6eCSdKU4D73}gt9ZkAkan*W0=uUclSeo)4)nhtKFmz@q zs&64gq(#1}FGfCji(bjsysE3#4u!79ElEIGpFg6oVj`{`WvElCdW;pr88QBpexD+c ztWfY{Z}m9BGzE~AW_PJ#+zpN^i=t$8qsR;{!ck|*c1{WVl2ghNvBheN{!#~j-97xU zd$41{iU1Zt;{gi;`^N|;D9f~H8_|NExMSfq%a0L**K3`MEzpGh!O7#EkIp}qganfi z><&w@6N*B-X;@>9D={8S01c)>@!R*!_Fs*+&)>bK`x;6KHo2hL7Q4*~;AlGzI0S~~ zxl1(%*55>;{%sX_v>?r3_(c6j&u@y?G%g{h`YvRFRy-*5hwt zNBm7b!dHJ20`T;W6v=jD?!6CL^QbwGU|M8HN0UC&i~|^Q@II#7NVXVnD=Z6YPE@;-t z5QbZeZ9c>rx$q$w4|krA7?>)9{o1QTfk4DY)%W;O%xVuC(m`^ ztE3APBQ+!q3tuEthshVo1Y-Iy5(VRl#LNYknoTV2b`hK8$L0vnN#~1M9Wdr`!kEVq zV^L=eG4C^bUtGu0B5GnexVCas+$SF#b_$4>5j?EEPA@wdE(oqzQnb{4*ev3Ig=Oyh;QRFA^j>+J`> z-kjU(?e=<`=X!IJ*V|n8nqAJj*JKKvsrMQs6QX;~Ru`JBZZdQ7nR%`-m3GB^W1U?d zk!tMhil#bD@^zhy>0*{^DUnBPiMhn49k1LVVpH>bEh{_MvNCju*~B7#`Z#NXE?MO& zuSz06*OzaBPA`r7W~Q`o*G>&LlkR)IZDi0#hw0!-YRytw>?t*6I1jmesoF^lIb-%S zePLIVInYuVubNBAS7)T;+2!GoV_zzqSI@wCDnR=DNRMKXXUNS+XcpqTjr5H|G}ne9 zpUQHG_lvnncSCjuQEL9o4iW>W5HN9e)ABhexzudA9J1tEAq5|L&TRa97$%2YbLJ!0 z93#0ln;%n>Zp-pw%JyVRLx>&l6b?@$pGffaYLQBbEymPP7BN)IMGduiQA5?9h8n61 z(?eBzKGa~s3^xE5WIG;S-}!I>2gDpS(#=34*K<6~!Y2t&yeWw9-$6O{SK|;DLOHq4 zlQW~8qzk1P_0(oXJz1!R1D)m|nw+>0LVVq0?Oz}ljr7L>rOz)*HH;*`*9W76tY%?O` ziM*zNSPt~cywKAg5}ER(>7G_`c~Y*cWr#(m;fu9t_+srAUrga5HFesp?oP1j%<=c95Xh~wj_Ug2%*ep*dTl&QPA5D(%*|jIzoCx5+C;dQR)>=kESMVsHS)>i84zyR`_+r4nFP$V%INUYnzzJp&9 zI~J*aMgwFAC_E7>H6l-VLU!z{#a?zR>@dgfbSy#>k+8$y*jTAR2E2kiuzOWpy~9rS z$HJ|xA%t~s~lFB1mv(c8DrWyXats-FvCJIq%S@}N=~)v%E#-D#3MXzRkktc7t~qQZwOIpKnaJB zJ_1FHhe#PcddPArcC|*1WUqf-xTg)`9`L(7Am`*bD~yXbtp}9{K(tSc9b|vf?GDGdSBjjr7;KveBYy?i1Vit?eL7J%3GUa z@-Zyhk3{9s_#%;20C_Vn$Od{c6V>&bv$_R>+_19V5{TmXm?jn z;9I>eT=4x-AO{ajB-B#EznX|nLi-+Q0@@+|Sml9;yDbMY1q(Y$Ga$W5@@40Y$ZZu? zQn~(uwjByTe;Fl`2~O-$ao2`Ow-h-jgXmzN;$jqOK|5%mhst8svLn%=7;z57HN;~v zn4*^C#Eh68Zz6><%uz=!q_7ViV`hVbfXowJBpD(kA~>tubo4%bluJjIU@*xus|FfioOGCP<~mbz&`ptwS=%j z8OL>Ttdbd#=u=iuB7SkbxJ2pu`0yZgL_->mWMYE%dMJtaJ=*Mh&tFU z{8>zz44xnDecbr=Q~G)4v!KON5_?7qq!jLEEtb-!oN!8^K8d{{n1s`!A!&;i?dxeX zLrCUNpiy*hk9vk^Dd$J0A7iO#lTsTBl^re)v9!Wy%n4z9CsK4t&Tcb&0?%b_ z1?95BgR3Y4B!+P0{DUAbWC>HAVcDddhh#iZn@Ew45aYl~+V52bgB=v*HzC7$`vKp{ z#Pl{RRKbk4(m8I@b(L0t?$f`1$6w9aF(eZ@L zDADUle?n5n6Npi*LNrx4p+OMl6bz%v74PHnj2v`!beM&{Bq#4AJSLGqm{Pi9Y4x_(eKp zrU(pVz|x2S{zy7C(?ug72~Ag;KCpu1)vgf~TLoE7ni@cYO>s22so0h7VhQZ^1dT%z zZiiGwDI834`bZ?uL^G!wae!45!0I&sIwpY5H2|)e0IppFV9f-ub`5|}OaPx;17O_* zu)Y{TsY@l%I9-d3mi#_vE^a8=q;OB>WTI;=uACPA0Cqf^__&~BuM%ZhX<(bs#Rqe)g!FulWCQ^@RO*xe}ZC=kq`lMD{JYHiDSw(cpK+83l5N8xq5 zr(E3+^DD|wrP2on>f6YdMp-#e8^3-rI3{)y`GOU}dLXU0xaC>zH zZRYnity_<*ngEaWZY~QHh-^IfM`N->pq`f~468`S#RCxme5DdbT4P+24h8{xr5;%i zL`z)~E=O%4%w%1P2&()*`Xq_Kura$0Ffh*~yPfa8JBkofMiS>l1nW9eqlQMbuj|p5k_6CBCHnq`6a3 zZQ%_{AlO}aT5nsTw=I@CQFmJ@)x|8vX7kO!46cwQ$!VGG&Sr3m%&Gk)ZNp}Ek<77B z!>qRwqAzSTJVTMVX=q{7IMQx6oA!8hncslXxey{LKe&vtU=ur`iP zZhn|Id75H@*h*pSwc_-`@)&C2*ix1B6BieAE-6mi_0O}u zUhoXn3}>kJeV-xwtDhm-83YdH>qR{k!DdTFc$7$*49N zTlG$~vqAygu2R`a<6e{1t_oF?Z=dUTGmLY0*Vi-cb9LX1xTnY2toE?l)FxrHOADlA zi%xHB1f~>h2k(DXhO5$4Qb<;GW*L$J8CbGKId+1CjVE*bn<@1^yjWR_#iHq?Vv_Ze zEcPI2%QIR#^l*;LqyQZsLv7YJ zd=~uninJ4AJ50_oMBFiny@W>tam$0ru`m#(3f3_;R3K#zESu=V{eWZ{?5Y5Zq46bb zJ4LC0!ZlBELJKhDF8hOV)d0_-Xl)wTf<+A|P+;|1C1I}YLloVCUD{JNZ zRseHRX!};<_5{c1Ov=`n;=*!>v*h}*hw}zkf;EZKyo(2q1Q;6b3%@6!nE7dGQ7pkE z5it@t5t*|;BQic0i0xc)k>~SU=}5EFSq*edsFXT=&Snp-v?)wjvsV^X@fUN~;}4iO zXI4Xu^jI@(10$Pf+RE_lqo%BLmaoz2)UBYC<`&X$ayXjTZZtiqhW;7%11k3XerT~M zCCvg+h;!hEYF^L{V{y`O7^JsJASI0fL%TD(kAcCyF=0Z<){~4BGV%(h93-qkoWMx_ z0I!9Y7E?IDc3Z+Ou@tjB<<{U|R@|6n8Rpxh*mr}Jc)~3G$hXCv$MR_UNt=UUiRPOy zI}NTZ2WJoj(RisyWqJ{NdXZ{Q5zVH_v{UGSiTe@bo5hf+m1#m|l32xzn9?NCeq43w zcW2RC`rSFSme;pp(n%|`Ayb}0yr8CPKh%KZOI1(a5n4R$cK3i&ga=}v$PbWw{JkIs zE)`#_Cf!J;jJ~9Z=S-%+*okYc4tub95+9qrRAy~dApxOy-_B6Q{v?!JN^H6Ny77Gb zV5ji5DAaau*UcpAGpzAjXu`LiJ$t6a_D<-UMoRCkEzD=hQUq08t(Vs6CE5qGo_JDC zJ#lcjL125G#EXUWglc?QYC$Ka7Bp@8^E=~-Zy&yD|WR-lDb#*0aqtZG{p?H$+N?js4uPmhw zZ41XyEH4QBv&booby-9%Lqj?cE~h;vi>X;v87u7~&mx(`^$}uFdT)s|rikQE_iH~? zeYwgXTxup)v$#WnD#B64xx@@df3by7H^t&Y`T@>>b67tC|Fy0>lsLLkkR# zC8QXl_%Km?81=FZ)aq^j+z)(;QP8|%YF?Z~6&{p*Y$Jppc2Zmh@T{Ru@|UeBk8N>*PF2#TCtnh? zIvnsuiqTF(ed_KGsXM9t#@!&>E!p2d zzb_N}gs-iF$-a!oqaMxQHAGv0XsPSB{BhJxw$c$WwfU8|4(B;87|h$e(P%(egYMbi zyzy&H=?*>8&00m7yQ0v+qy@oAkTJI-iXPGP8eBylUSQ7taeO4ASL@b2;+zE-CrbgFsQlLPFIJrBl>q&5=eQ33p;%43!^RinjPB<;vCSaXrF`*uDt^QV&OsKFqDhXHoGeD;0$$$dmwd;U ztb1-4DnRY?-h_tjcRd+MLLTgUDZzBMIK5WgFh^@B%puaP6^oG^HuOMNK_s#Wx@AOt zm{CNZ4)CBycZfU_bp$087t>t8Kg{j}KEIgjTE5-$$tY(EbZ|{)>~G*rJ-_GU^_N9@ z1;-r&XAw{e)Jth`=+hRp!XI#OAa**ZSt8HyPPYN8Q}T8lP(r$zWAJaBOCFf%*m$n% zN59PG$;fzEV(%Z@kul+BLlMia=zriY}f@OXkeW znO?)M;Dz$dd`>Fs@!d$%Rk?>gsCI`mgR~tw?%`*rko_S)=jic4K@0w}VDw zh5;&RtUP)Nwpzvhqi|n8k-uGj2c?+l&J0;i7#WFND1`bJz(r|g*#fvJA^XzwH#o1h zCMpnj=rb0+EF!z2+PL=BTBoE#@tZ64I(9py-d-hNNC{00p{7<$k3X!I2TM~-h|9L< z*7}@ur)TeyXBi;o-*-vyYX433de5T}M30tD7R-H<&E%dR%1|i@8rce_12zBQrx}pB zDG>ovQX+Z>G+HD&mWmjO)>gRk>J&-LQ#OYx;gu6kyPxN4QF!R0$%J?HoNeDR?XNF$ zBCAf-&cjtoZyREp7JSms9v^}`X3@feWYu?ry0TvAb8{`sX7YzDT$bXKZ^b4kPHKj` zPe)=A4vWK?hRK8;GuKB{qGCj>+}nQsYUjmfMM&<3ZtIi`^XiSVbT148Ne_nO6~8}| ze<*~1h@T8&*nnL+S6G@k@(8%lS~7eQ`c|~dqD-=K7oLRdPU%vP_#rc!Bs36ieA2Fx zRiP|WCX**>vjff-CWCEK$Al0&!%9u2bQKWWSpXU7DR{t6{Q+-4UQbsB+~L*ia6Xgm)ynoQkc$;jBrCLHK1bB5fzPuxjma-xRouek5e4rp4q6r(60S z#ms&j_vwsB8W*x{J#s0@@Gz}DV-hll2y1{6Cu0F-IgBz^=_ZtXF1BLs=O{2Mg(P+(a3+@J^ZkX7|~If@QhmlgUSr@ zkd>;W#FpI-v4^~IcCd7$I7Do{vh6S>E>)LK`Du-NE>RwQxXTWN_gG!he$<>YZP9=X zYO$>@U`s1wk{8^Vr7vqjgcb(7i`rDih|LMbD-VjR)*EGnE7TK}${K=&BWO0I=f$?@ zTJK-12p3#hU^3vP)4`Y?+HMz^874WEl{KX)fT02;17&MvirW%%t29vlmyFC@-g&65}i+ zS}2i4(imjeoyVqRTFMHu5@n7CG6^K?B+vw&!8~QLnA)0!e>2iQRBf~RA)aX{KftFg zqIVvM;FwZ5p~v$iJ;|gaT%u#bW1%uh#`xyPp;bK#@HfNhC^4x2Z!^xjC3Pd3V#J^v zk++CajP#qKGQ^ao$?PFCL)6*O_9Yc$RHaPimb&hpP4oDlQ%UJnP1{DCTVBqq;bj%Ej?c>-dR>$VGSJPkH*lt z#<;pBPgi4bUDat^JkTQP@P(DxXW>VY%4o8lnXV+ApM;GZ(#IpbDUC6Bg(cR8N$Zvu zi}zY_PxE4!hA2B0##E1C$}7}Ot%)(Nu4$!m9V1fXk^}mrBI)#4 zIgVxqW+@1<#6{7=FD5EoN&us7#1yCs_Rl7>qf1?Tny2b!K0xx9w9c!FElo2NNm`V> zMmNLCzgR-_3kgKAKya8?PI50rc%I0YSpgrDQra|s@k}x?N+ui%XsJu_NV!7RtVwED zi2=DFZ*3v56(cUGPR(o5KF?1yQ#^IyL}-B}XC3=@G3uQ0V!!jwi}v<{>bQku*rZDN zIXr#BsVa5SHCr?JY!xSTOgI2`(~*{n?v6zCX=RTlgG&gaMoL*XnNW!d(I^yPQqj{P zE}W@j**2sH?S#ym`X=x$cOv3chWZ!|GwKIPy^Qb(pr+{^($`C64-ZOC4mkr-lP80& z3{uK^Ceai`(CqXeRW~cv8N}QbyKeoer6olYSzr{{TmMSoGlgoZ04)`Lg>J~k2h`*M z@PdYZz#0nD5<&9a7Af08hZ%Y#lsXAb5A|AUcX0Qf_(P?j5kfVnWymNHsu>0$B#1!X zCFOn*4|fw&x$tIzlY`P9v4%#iWt1;fXkAE{j|EXgOs#Pm)3OVZv&EYyQ?n9=aMDyM zDLqa+C+(`WXVR3c-eGbT{TMcg5^0dCL|S^6H=-m3f!FO|G6RZ=$`ng*K>>LS;n~@1 z9PGS)d5Cn9n|6_bDv$-;6Uo$)mPW|blXRFWoy49yEI)OXsO@{kd^5*nhzqKWYr5ls zUpObSyqt>Oe=PGt9pf$Q9AXjrRUz~-gMnGDnt^svhMFO%W9VkbH#$3+U&CNjWKg8C zTSdlfiVR@xg}g0%R(B{om2&ThqK<8{t+R~SSE&`*kAx$b(U-?@4_%fW6B3SU*K=z- z$=c^9AcOtRSm|QoZKbB-?4-d6*U*j(v-V>uameu?rNv2Ta7bzL^;9_4dDoyr!4<7* zZNxHUt6@$|AWk$874kioi_GpyYJX&al(8R~4A>Om4r8G7&6yv?S6B2*&*fSF*R(-# zPaCs3hoT;CWJJ&5$cMAL2ThHBsD36Q!`BoY)KNOV;YW7Fm!~%)LJ>zmOeuqmz}nMu zi^erZiNJ&umXL!ID)JI^r3{;Wt3ogm#J?HAn@&^xAinEv1wrND%=TV?socc;gb%7BKAXb+Guj zNWns}L2Hul0UH3j#?-4xpI#P2{a7v3j|tIt)1~2Q?9f>^{`F)dMVTx|lU9o~X|-!> z(rU}lq}9xtwAwN>X&S$7QiMg4g5u1IuN237J;hg-^gZBz@tc^}v^wZ3>b}Bx;GX6v zyfVi8y^Jts(qJAtuGd<2S9nD_nyR~2D=D2&%v>xounu<`xaSZAxXM&mNF){ zRT*r7s~%KjLfeY?`rlMWTUkqXCb}9-Lz3Pig`9Xl5?mOcPNm5uNog3UBXV=vGTTpw zg^VUYc&p!%F%K0UfYA@20sYT7cEueZPdW|dxhWn+*H=zBBZ(nHFH;kmEGsmrH6mwR z)ILkr3=^wFwl|_=+awBN8dzF-$9-E#J^C=_?3or_if~+;shU#qDXVKj+nC%_@MBHz zV+@CQv8Il_1)b^jTEi=8ip~PflAN)l=0`UCsp{E%^*U{;QnG%IiUSu=)sV`^_1{=2TOO;&ro#`}uC zrQ+vaYdjb|Q?IrxzK8lv4JQzZ{6^qDdbtV=;udfi!ljYnmZNenI6Ud$;CB=+rh|5x z0(~Z||Gua+DMJ3UP8K5nkU_{lN(b~03F|rY3g#wepOP^ngT@&tr9_}&GB$xCVQr0~ z?fsttxDiM0KCSd@BNGHCA1g4ZM`CVk&O(6N0uJl3M2~6l96PlJ`AB7 zI1Ow9GX9b1~vtl&4z*30EOJ@xsa1jAGadKEbS@;=6N|p?zz4(bp zoJR&4>$z-0KaF$>4+r8*7IQ-A(&LwqmJ(DnKebEREJ%`*c&GR+9wp>spyKv6;L4-u z;toZNpLulo!M)L9aZaJsRDg0LE)TAlfDm-hS`uhUwS<7%DGDXrvA#J&jjsNKWYNcbn@qaD;w|}q1_iYqe!z>&W_z89! zxH{LK)K(SBAyuQnKnyY!rBq}l*K&_tp92VHXb}n(O5Ls;>)EtUc-)ir0Z|=-=+Mk) z0jBx_a!1fN1)abFH4uKa9~6_PClYffu|d4VbNm{6AD{wx*>#VD!q2fJ6K@B7zKhX+ zqbXYd%wYeMy3nO43>W%kEWD7z^z4}ina*g{Mz1Lbcg3zcYmQ4b1D=Px)vpoSzg#()ojolda3(%jIv7aAF_fc-VPLosdR-PiFC+Sy>`AC`O zf7rf^*0^LnymI4Tn^`*`ybmBgIzduMtV*G%(P(nrbhWBp?aD1#>E&b!^`YftRcg*t zNnS0Yf9h7r>uTm@W8RuP-&>YjFn5W-Wxa|3GUvcn2YQ0}m}a)$;$WckmqLaRA=6JK zn~Li-@alb9K2s^V z;BL6q$vxI@#r8`krJo796@hLp1GHRs{-a``6B*YVYNLo6&1sNL6UxS{!{`X2{~-9# z*z%wv^C}zZcLI?Ye)h_eV2VH0V-D!sa^3n2H5KSe=Sy-w8V<@Bb2e^mnC%x%1+9Kc zsWRB^;MAB-O%<1W4>kCcH1(p-S=L^f7@_5|DykrWu$cjV7fy+prcafO1bXp(f0w|R z3x+ee4-xyQU7&f-%E}knt&OGO8u93BY`F%ebH<}o;4%GzeThZ6a*Hz@tjx|u`|r|S-3f^`VHio(x5j6`h93?OP`W7=-xW^r{m31C4^@)bbFEmtnn z4F?)xZK@gFm-*0`IBx?)%O5vao1pRg%$GEUN)jhUE6~ykv{ZpKv`qSyEkY#48rhzJ zZWT(D`w%}8;b<}KIw5ivA6DpBQE^V;yL;JG`Mp@ZN=1>GKtV(Bl{!J(qM;tGedIr7 z@u$LnTjFW!NPfdpBZ0Blh}WfuN5E8jWhJ7Equ!YZ$awS@>z)ekwe!dO?br9PZSK9; zefe@{|6am~P$z+v<)G&KA@h95E(%iJjJ%|a>*q?XOak{ZvH4{d7?fF=jNfY&dQ76X z@)r||GJB{9|B6hMk&lA&P;qMtGSblTlT2*92)bJy%A1LLSQOFCkL;F)@R;9h&4=d9 z7Q+b~HXTLHe{i+qa$h=5fzOU`mH}PSDV{Di5J-psN>oHiO?9MG`?vtQH~E0&(M&JM zMmh4LQQF#zsPjPC|~7(cBdU43-fn_de|fYrA4v5iK_(D;rFi@1_Uajq9P}Tmb`kXi~j!_PjLH zo8B0)n6~B^!^%R1s5?2aSdTwNe+19r;tl*Bjlf2!1jD3^{ zsy!JdcKn@ry)Bn{B&dT~?4m^>S8B*#$?j;9~%2ug$KKn7S#+nm7a}wg>Hq zrS8kKHAUtwAs@xp$x89Zs~sf@5%*F&m_mGfvtirN2r}Vk8acRf!j0QoFiaLP*DYAPVYguIN4f>S8Jm_$FY;Ax z!P>ug3)XIL!T*I@u(sq|&{?|O#X>tJ=)tmwI|9B#sPN&cv;fXEjqk?EEyQTit*pUb zcU9MJ-m0!Gb5+-F_^PfgYgO|SzEbctf0Ru4D(zpai%JxyI(%m5#;(@3fo-0GJJ}v^ z>5$ixfNb(!QeqUE89_!pQ@tr!^{qK6iTp^|>Fi)HODe?_LxQ8Fh>C59jcseu7}9rh zMO@C6#Cp+mUfDT;s%PsGQwdA&QzF_NcZK$ga6~=sbsOWWp%+I6(Vmgt?R;br+b~OH zie}w8V0S1lDx3fj5FS4J2(gc_R}^i3FzL3f(WIZd60!$sCAO@B@aGaickq5Nmi~(o z#}LjO1(vE)fSh=IYYw0%;@Mhu^kqwwjmVs=D18XQcUL@#Hj^NrU#_pe*!>e=@!{9K zU2giKBK~kocg6DX$1C|qypXe-jAv+!z|Bs4v!uIK;r=QdbX$91Pl@sU&~m4RX}zcz zxSHnFTK0{MoGnth#;`R-y++WHW_X4P;l|E!eoogouZKSs_pvywQUc8L8a?*C!+E zH=K+#4|WOWBmM3TV-H}1@b>lc7z8=S8@#re172WtQ*>T186w#)QUt|`J%r2{c$Y12 zIF5&hk7%0BO+mE8p43uLo}`}CQ%@=torWR5$k^L-GnH!kk&}94m-E2dX&8>7rSym@ z=^<6>xh+-FT}!uQKjj57`1bQUiB;EJ{585fC-k|mJj5I1FCNH9?gC7lAkmgyM$DH4 ziB=tC4&~s~U{DyjdhEVZck;Aqww|jDwW^_-U0!T(l}fT6<)ckjtdtEk z?OAF%hQ3y+v($W2Gt_iusA-#eYtPhX)zGGs8fVR!X=br+#D^#9LtTEbE9!%-K0IBI zLLN@*CLNg~(y}%vE3G(0+5ut#v)-H8(v*PxR@l?hh0VYH_U5%kkmET@j3VwzN$>pE z6LY5nWQQ|h4y&&B%6gc_8_e2;AhraEKKg`w(v2=c%z_Qqz-}Q7p?g^%y-Qj%qw_)9 zSi4^Tczn|EIK*;noB|tibaj~$gW~Vt!o3JA0XaVPDy>`CUvs>8Lv)v18OVZU&_d+E zG&G%(($7m6nUHu&NPKOeIM_Ia3`?8UYlE$?r#YW%1EmYXKnY(PE?pqm2Hy)qjctOZ zL9MRmIPxwG)mhI`Q!Tt+)%9HC#6{sc+RWNZ+g%G^c1u1#OTX)YMSsHWa2J4m5>7W7 zzwhonf8J;mGb2~|-LDk9Djugwe-m%LHIx!LDpvs2A4aue!r_tn##p^*ln($7>3F-I zd+rrXH-h@+cb6IEDzZ&UNRgeH=!Rs^BND=nUp2?v~2I1r*~F3;Z!V(!y(XpB-s`7P@4I7Q|uivkEm)+Y*%%v&O|)G(nr zTkNV>n4no?(vk=XGm>#$D2#cv*~@-6>}ly1v@(KrQKdL{LNkm(L<^D~hbT<2hy4q2 z-9AxdE~jd?5XaJvLa$ndBeA(wEc;`TvJg{94w1n4K|rLMpzP>`SgkH1>Qb(orUx32 zW1doGXAdD%uYv~@2^D>G%1>+jlo}S1Kdj+s@ClLC5ZwdCC~PXq)hkbJQJdl~X+_X% z4cr$+v9;|wS~xpB$FoY=cBmdjcV;i@ka)uQ)@gS113<*)|iq%K}&^(to_5ktZMmbnF{(MLLB~(VhV4{CV&IhWx+ILD zD2}OEPfm4Bj0ytgq3VRg1{0oRkkk=>L@oB|dTS0QBLD&xnRu(#4#&Z3oeU5Nou)=5 z$Dq!0&|a|tIPxAn6O+qR2`ykSMCR*NmE(H1%iHubV*t9#HY}N(#Tp?*C_)o+f@(e> z-sNzlDx8YHN0gaGVC&CzwPbz%T;@YA|NDX`;v7@|nWLq8l3s4S ztUp^G-pVyD#)7DNt4eAoI5CyJZFQvKv?KKOV~jE>6NY4dvO%YwXF$aD6%ijbaUbS~ ziU8Fhjw^}n=y3Pk5h5b4i^D0ADs@}LgcJv-P+pJrdl5-b<5^Er!AoUBybuIege=v& zM}Ii%XacnpW+{uXm)-?%2Oq3Lc#eUH824}qiEY-cJ(sdgJ^pjh9lMVYCnHkcpHiq_ zBbv16dU5;5NLi2r6SaUsLg)g?S{fqk*=y7PgI3mPa@?4=c-C3iXx(msy!3hdHT4u$zB`ggm~yD z%6yb*0wT!=HQ#eT4My=8!eMdI7ts;)XnTySvN@q_3S3Jhh`?)l@qEw&_Vb>*L$~R7 zaY4KhMY#K$@$Mr{glHDMMwSo2WILQQXyc zhH2jAlY+jre~E4M^$;g%eU$xEQmVTm4X!THDNIu;%&NY~2rle*7nVT9pAqG2&`90M z*3iwW-@Ti;;@LC#*<}B89gcRYr92}zihqBN9k4Nbgt+;=7}9*wf+^q^F-OS|D?*?m zX?!^~&vv`)1HM%l#ny;+SJnz;$f{C+;k9>Nu%`YZisf~|Iwr8SYkK1mCHE;W|IeSu)YR8D$$K^~V>C+E_kNyJ!&s1Zec) zJ#mj`W$LvOwXY2{3|{}0aB69af XuXIZ$Xjqp7*`5C%62k^5?8*TE9NB=n literal 0 HcmV?d00001 diff --git a/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json b/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json new file mode 100644 index 00000000..9632255e --- /dev/null +++ b/bench/results/2026-10-11-gfx1100-qsa-scores/provenance.json @@ -0,0 +1,168 @@ +{ + "hardware": { + "measured_date": "2026-10-11", + "cpu": "AMD Ryzen 9 7950X3D", + "gpu": "AMD Radeon RX 7900 XTX", + "architecture": "gfx1100", + "gpu_vram_gib": 24, + "installed_ram_gib": 64, + "kernel": "7.2.9-200.nobara.fc44.x86_64", + "rocm": "10.0.0", + "power_cap_w": 272, + "operating_system": { + "NAME": "Nobara Linux", + "VERSION": "44 (KDE Plasma Desktop Edition)", + "VERSION_ID": "44", + "PRETTY_NAME": "Nobara Linux 44 (KDE Plasma Desktop Edition)" + }, + "current_link_speed": "16.0 GT/s PCIe", + "current_link_width": "16", + "mem_info_vram_total": "25753026560", + "storage": { + "model": "NVMe SSD", + "ple": "dedicated ext4 SSD partition, direct I/O, remains on SSD" + } + }, + "upstream_base": "61b3fb5dd3f1e8ec09cf7e4e05208bc6d3c46406", + "original_method": { + "pr": 1825, + "commit": "14bf32150490bb9f5fc4d9c7c5dcfdc96dd98797", + "author": "xrip" + }, + "tuned_control": { + "source_base": "d5ea7133741e67743c0e886bb426c0ce8d69cf6c", + "local_changes": "PR1107 prefix reuse and resident-budget-loan implementation; same in both arms", + "native_sha256": "3bbaf98d7f83c91b0a40f369e5dee6ae4273284028b98d48dccde9e554f5c80c", + "candidate_sha256": "e0708d4fe0b0e096a36d793f47aebfdd3477e6157264b5739657977937381299" + }, + "current_main": { + "native_sha256": "1338d642a7d1d1e34a8f38932aef82619a6ac0e6f5195a7f1661dd55f916b8ad", + "sole_arm_difference": "STRATA_SCORES_THREAD=0 versus1 at process startup" + }, + "submitted_source_files": { + "CMakeLists.txt": "84048b34a1065672c9d3577053611fc33e3e63815d33ae502ee15e8deefd5d6a", + "src/kernels/cuda/qsa_select.cu": "fe051b86dfb349d09f0b576f9b9e710d20334acb534021a869763a7cb59836d8", + "src/kernels/cuda/qsa_scores_gfx1100_test.cu": "2a26063e9c5c58cb36f0973b36bb590db10762515f9eda5318314162fafda588", + "src/kernels/qsa_scores_gfx1100_parity.cpp": "9d0d88a2490d41d5e059e08db0907433b63321c98b53dceffc88883174aa3e15" + }, + "compiler_checks": { + "hip_full_engine": true, + "hip_cmake_test_target": true, + "cuda_touched_module": true, + "cuda_arch": "sm_89", + "cuda_toolkit": "13.0", + "cuda_full_engine": false, + "cuda_gpu_execution": false, + "sycl_source_touched": false + }, + "frontend": { + "version": "local prefix-cache frontend based on0.1.40.3; same for all arms", + "sha256": "5963c61106ee746673c43cb69df7b6bfeff2d2ec320a00f2435e1fd6e187f9dd", + "stock_latest_frontend_tested": false, + "chat_template_sha256": "a49e6e5da2cb6d114814c9ee5079677dfd1bdc4cf6b5c1519eb73d0bcf12f02b" + }, + "model": { + "repository": "https://huggingface.co/orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF", + "quantization": "IQ3_S", + "revision": "not recorded", + "gguf_shards": [ + "Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf" + ], + "expert_profile_sha256": "e93f33e1cad05fc31627295b1b9a253bfa99286ec2261c01e5c39366888e69f8", + "index_sha256": "02e228d5488792b1c2cb97b7021d099f47b198f5e13d0b9f9bc8716bb0592146", + "native_experts_sha256": "adba4968661f3d59f749a676a87948e29236c81997f649f5526daf71148edc24" + }, + "shared_config": { + "args": [ + "--pack", + "", + "--native", + "/IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "--ple-gguf", + "/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf", + "--mmap-experts", + "--expert-profile", + "/flash-solo-balanced-20261004.bin", + "--expert-cache", + "8247", + "--prefill", + "16384", + "--spec", + "6", + "--spec-min-p", + "0.7", + "--mtp", + "/strata/rt", + "--max-context", + "262144", + "--kv", + "int8", + "--kv-resident", + "32768", + "--vision", + "--pool-workers", + "15", + "--adapt-every", + "0", + "--pcie-frac", + "0", + "--vram-reserve-mib", + "1024", + "--resident-budget-gib", + "34", + "--mtp-max-t", + "6", + "--ple-io", + "direct", + "--conversation-cache-mib", + "1024", + "--conversation-cache-slots", + "2", + "--conversation-cache-min-free-mib", + "8192", + "--native-dense-gguf", + "/IQ3_S/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00001-of-00002.gguf", + "--native-dense-gguf", + "/Qwen3.8-Flash-Next-GSQ-RCO-abliterated-IQ3_S-00002-of-00002.gguf" + ], + "environment": { + "ROCR_VISIBLE_DEVICES": "0", + "HIP_VISIBLE_DEVICES": "0", + "CUDA_VISIBLE_DEVICES": "-1", + "STRATA_GPU_BACKEND": "hip", + "STRATA_PREFILL_MMQ": "1", + "STRATA_PREFILL_RING": "96", + "STRATA_DEC_BATCH": "1", + "STRATA_PREFILL_ISSUER": "1", + "STRATA_SCORES_MULTI": "2", + "STRATA_RESIDENT_PIN": "0", + "STRATA_RESIDENT_HEADROOM_GIB": "2", + "STRATA_MMAP_STAGE_PREFETCH": "1", + "STRATA_REFILL_BLOCKING": "1", + "STRATA_WMMA_GEMM": "0", + "STRATA_PA_WMMA": "1", + "STRATA_SELECT_WMMA": "0", + "STRATA_PREFILL_GROUP_GATHER": "1", + "STRATA_STAGER_DMA_FENCE": "1", + "STRATA_IO_THREADS": "32", + "STRATA_DECODE_TIMING": "1", + "STRATA_HIP_WMMA": "1", + "STRATA_HIPBLASLT_VERBOSE": "1", + "STRATA_SH_STREAM": "0", + "STRATA_RESIDENT_BUDGET_LOANS": "1", + "STRATA_SELECT_SIMT": "0", + "STRATA_STAGE_PIN": "0", + "STRATA_VISION_BACKEND_DIR": "", + "STRATA_HIPBLASLT_TUNING": "hipblaslt-gfx1100-100401.txt" + }, + "configured_expert_slots": 8247, + "actual_gpu_expert_slots": 8144, + "actual_gpu_expert_bytes": 16622003200, + "logical_context": 262144, + "vision": "GPU enabled; no image prompt in these measurements", + "cgroup_memory_limit_gib": 56, + "cgroup_swap_limit": 0, + "available_memory_floor_gib": 8 + } +} diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index 47327380..d0038683 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -299,6 +299,17 @@ only when its version matches the installed library; otherwise it prefills on pl prompt), so keep the table and the library paired. Not worth trying (measured flat): `--kv-resident` changes, a prefill chunk above 32768, `--spec` above 4. +## gfx1100: optional exact long-prompt QSA scorer + +`STRATA_SCORES_THREAD=1` at engine startup enables a HIP port of #1825's score kernel on gfx1100, for batches of +at least 64 queries with at least 16,385 live index blocks. The default, short-prompt and decode paths keep the +existing scorer. On one RX 7900 XTX / 7950X3D / ROCm 10.0.0, three paired runs of a tuned 0.1.40.3 engine reduced +fresh one-token request time by 10.45% at 130,978 prompt tokens and 22.64% at 239,906; one same-binary current-main +pair measured 12.85% and 21.71%. Cached follow-ups did not show a repeatable large gain, and a two-task coding pilot +was 3.27% slower overall. This is opt-in, not a general coding-speed recommendation. The +[report, per-run data and standalone score/ID check](../bench/results/2026-10-11-gfx1100-qsa-scores/README.md) +give the settings, exact-parity checks and limits. `STRATA_SCORES_THREAD_TRACE=1` prints an engagement line. + ## Linux: verify timeouts while the kernel reclaims host memory (experimental workarounds) A `verify: timed out at layer N` or "no progress for 60 s" message does not by itself mean a kernel or handshake bug. Two diff --git a/src/kernels/cuda/qsa_scores_gfx1100_test.cu b/src/kernels/cuda/qsa_scores_gfx1100_test.cu new file mode 100644 index 00000000..fdc56877 --- /dev/null +++ b/src/kernels/cuda/qsa_scores_gfx1100_test.cu @@ -0,0 +1,32 @@ +// Test-only translation unit: production scorer plus the unchanged warp dispatch. +// The production library does not compile this reference wrapper. +#include "qsa_select.cu" + +namespace strata::kernels { +void qsa_block_scores_reference(const float* pooled, const float* dead, const float* q_idx, const int32_t* steps, int64_t nq, + int64_t max_blocks, const QsaShapes& s, float* scores, void* stream, int64_t active_blocks) { + if (nq <= 0) return; + if (s.idx_dim != IDX_DIM || s.idx_n_head != IDX_HEADS || s.idx_block != R || nq > 65535) { + std::fprintf(stderr, "qsa_block_scores: unsupported indexer geometry\n"); + std::exit(1); + } + // a block past a query's n_bid returns at once: the grid need only reach the batch's largest n_bid (C-1) + static const bool multi = [] { const char* v = std::getenv("STRATA_SCORES_MULTI"); return v == nullptr || std::atoi(v) != 0; }(); + if (multi && nq <= MQ && active_blocks <= 0) { // no active count: decode (captured or not) and prefill's pooled16 + // STRATA_QSA_EARLY_EXIT=0 keeps the old staging (every CTA loads the queries first); the scores are the same bits + static const bool early = [] { const char* v = std::getenv("STRATA_QSA_EARLY_EXIT"); return v == nullptr || std::atoi(v) != 0; }(); + block_scores_multi_kernel<<<256, SCORE_WARPS * 32, 0, (cudaStream_t) stream>>>(pooled, dead, q_idx, steps, (int) nq, + max_blocks, scores, early); + const cudaError_t e = cudaGetLastError(); + if (e != cudaSuccess) { std::fprintf(stderr, "qsa_block_scores multi: %s\n", cudaGetErrorString(e)); std::exit(1); } + return; + } + const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks; + const dim3 grid((unsigned) ((reach + SCORE_WARPS - 1) / SCORE_WARPS), (unsigned) nq); + block_scores_kernel<<>>(pooled, dead, q_idx, steps, max_blocks, + scores); + const cudaError_t e = cudaGetLastError(); + if (e != cudaSuccess) { std::fprintf(stderr, "qsa_block_scores: %s\n", cudaGetErrorString(e)); std::exit(1); } +} + +} diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu index a8ea4ec3..c27ca108 100644 --- a/src/kernels/cuda/qsa_select.cu +++ b/src/kernels/cuda/qsa_select.cu @@ -868,6 +868,101 @@ __global__ void __launch_bounds__(SCORE_WARPS * 32) block_scores_multi_kernel(co } } +#if defined(__HIPCC__) +// Optional gfx1100 port of PR1825 (14bf3215): same FP32 expression and reduction tree. +// Decode and the original top-k stay unchanged. No additional persistent weight/state allocation. +constexpr int TS_Q = 64; // queries per CTA (8 per wave, four lanes per query) +constexpr int TS_KB = 32; // key blocks per shared-memory tile +constexpr int TS_BR = 512; // key blocks per CTA + +__device__ __forceinline__ float ts_part(const float4 k4, const float4 q4) { + return k4.x * q4.x + k4.y * q4.y + k4.z * q4.z + k4.w * q4.w; // block_scores_kernel's per-lane expression +} + +__global__ void __launch_bounds__(256, 1) block_scores_thread_kernel(const float* __restrict__ pooled, + const float* __restrict__ q_idx, + const int32_t* __restrict__ steps, int64_t nq, + int64_t max_blocks, int64_t reach, + float* __restrict__ out) { + __shared__ __align__(16) float4 ks[TS_KB][IDX_DIM / 4]; + __shared__ float so[TS_Q][TS_KB + 1]; + __shared__ int64_t s_nbid[TS_Q]; + // Four lanes per query, lane j (0..3) one quarter of the tree for all four heads: the partials c[j] of lane 0's + // xor-shuffle sum combine groups j, j+16, j+8, j+24, j+4, j+20, j+12, j+28, and only then do the quarters meet + // (c0 + c2, c1 + c3, then their sum) - two shuffles here. A key load now feeds four heads: four times fewer + // shared-memory loads per FMA. The MIO-pipe motivation was measured by PR1825 on NVIDIA. + constexpr int QG[8] = {0, 16, 8, 24, 4, 20, 12, 28}; + const int t = threadIdx.x, lane = t & 31; + const int ql = (t >> 5) * 8 + (lane >> 2), j4 = lane & 3; // this lane's query (in the CTA) and quarter + const int64_t q0 = (int64_t) blockIdx.y * TS_Q, qi = q0 + ql; + if (t < TS_Q) s_nbid[t] = q0 + t < nq ? steps[(q0 + t) * kStepCount + kStepNBid] : -1; + float4 qv[IDX_HEADS][8]; + { + const float4* src = reinterpret_cast(q_idx + (qi < nq ? qi : 0) * IDX_HEADS * IDX_DIM); +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) +#pragma unroll + for (int m = 0; m < 8; ++m) qv[h][m] = src[h * (IDX_DIM / 4) + j4 + QG[m]]; + } + __syncthreads(); + int64_t top = -1; // the largest n_bid of the CTA's queries: blocks at or past it are never written here + for (int i = 0; i < TS_Q; ++i) top = s_nbid[i] > top ? s_nbid[i] : top; + const int64_t b_lo = (int64_t) blockIdx.x * TS_BR; + int64_t b_hi = b_lo + TS_BR; + if (b_hi > reach) b_hi = reach; + if (b_hi > top) b_hi = top; + if (b_hi > max_blocks) b_hi = max_blocks; + for (int64_t b0 = b_lo; b0 < b_hi; b0 += TS_KB) { + const int nb = (int) (b_hi - b0 < TS_KB ? b_hi - b0 : TS_KB); + __syncthreads(); // the previous tile's reads of ks and so are done + for (int i = t; i < nb * (IDX_DIM / 4); i += blockDim.x) + ks[i / (IDX_DIM / 4)][i % (IDX_DIM / 4)] = reinterpret_cast(pooled + (b0 + i / (IDX_DIM / 4)) * IDX_DIM)[i % (IDX_DIM / 4)]; + __syncthreads(); + for (int j = 0; j < nb; ++j) { + float4 kk[8]; +#pragma unroll + for (int m = 0; m < 8; ++m) kk[m] = ks[j][j4 + QG[m]]; + float e[IDX_HEADS]; +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) { + const float c = ((ts_part(kk[0], qv[h][0]) + ts_part(kk[1], qv[h][1])) + + (ts_part(kk[2], qv[h][2]) + ts_part(kk[3], qv[h][3]))) + + ((ts_part(kk[4], qv[h][4]) + ts_part(kk[5], qv[h][5])) + + (ts_part(kk[6], qv[h][6]) + ts_part(kk[7], qv[h][7]))); + const float d = c + __shfl_xor_sync(0xffffffffu, c, 2); // lane 0: c0 + c2, lane 1: c1 + c3 + e[h] = d + __shfl_xor_sync(0xffffffffu, d, 1); // lane 0: (c0 + c2) + (c1 + c3) + } + if (j4 == 0) { + float score = 0.0f; +#pragma unroll + for (int h = 0; h < IDX_HEADS; ++h) score += e[h] > 0.0f ? e[h] : 0.0f; + so[ql][j] = score; + } + } + __syncthreads(); + for (int i = t; i < TS_Q * nb; i += blockDim.x) { + const int q = i / nb, j = i % nb; + if (b0 + j < s_nbid[q]) out[(q0 + q) * max_blocks + b0 + j] = so[q][j]; + } + } +} + +bool scores_gfx1100_device() { + int device = -1; + if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return false; } + static thread_local int cached_device = -1; + static thread_local bool supported = false; + if (device != cached_device) { + cudaDeviceProp properties{}; + supported = cudaGetDeviceProperties(&properties, device) == cudaSuccess && + gfx_arch_is(properties.gcnArchName, "gfx1100"); + cached_device = device; + cudaGetLastError(); + } + return supported; +} +#endif + #if !defined(__HIPCC__) // ---- the decode top-k on a thread-block cluster (sm_90+; S19). One CTA per query (block_topk_reg_kernel, or // block_topk_kernel above 33,792 blocks: a --max-context over ~135K) makes four radix passes and two scans over up to @@ -1111,6 +1206,33 @@ void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx return; } const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks; +#if defined(__HIPCC__) + static const bool thread_scores = [] { + const char* value = std::getenv("STRATA_SCORES_THREAD"); + return value != nullptr && std::atoi(value) == 1; // experiment: off by default + }(); + // The bound is the ACTUAL live extent. A reserved 256K context never enables this by itself. + if (thread_scores && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 && + scores_gfx1100_device()) { + static thread_local bool logged = false; + if (!logged && std::getenv("STRATA_SCORES_THREAD_TRACE")) { + std::fprintf(stderr, "qsa exact thread: gfx1100 nq=%lld active_blocks=%lld capacity=%lld\n", + (long long)nq, (long long)active_blocks, (long long)max_blocks); + logged = true; + } + const dim3 tgrid((unsigned)((reach + TS_BR - 1) / TS_BR), (unsigned)((nq + TS_Q - 1) / TS_Q)); + block_scores_thread_kernel<<>>(pooled, q_idx, steps, nq, + max_blocks, reach, scores); + block_scores_tail_kernel<<<(unsigned)nq, 32, 0, (cudaStream_t)stream>>>(dead, q_idx, steps, + max_blocks, scores); + const cudaError_t error = cudaGetLastError(); + if (error != cudaSuccess) { + std::fprintf(stderr, "qsa exact thread: %s\n", cudaGetErrorString(error)); + std::exit(1); + } + return; + } +#endif const dim3 grid((unsigned) ((reach + SCORE_WARPS - 1) / SCORE_WARPS), (unsigned) nq); block_scores_kernel<<>>(pooled, dead, q_idx, steps, max_blocks, scores); diff --git a/src/kernels/qsa_scores_gfx1100_parity.cpp b/src/kernels/qsa_scores_gfx1100_parity.cpp new file mode 100644 index 00000000..63053d93 --- /dev/null +++ b/src/kernels/qsa_scores_gfx1100_parity.cpp @@ -0,0 +1,185 @@ +// GPU contract test for the optional gfx1100 port of PR1825. Synthetic, no model or coding score. +#include "strata/kernels/qsa.hpp" +#include "strata/kernels/qsa_select.hpp" +#include "strata/kernels/gfx_arch.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace strata::kernels { +// Test-only host wrapper copied from the unchanged baseline; both arms receive the SAME active bound. +void qsa_block_scores_reference(const float*, const float*, const float*, const int32_t*, int64_t, + int64_t, const QsaShapes&, float*, void*, int64_t); +} +namespace k = strata::kernels; +namespace { +void ck(cudaError_t e) { + if (e != cudaSuccess) { std::fprintf(stderr, "HIP: %s\n", cudaGetErrorString(e)); std::exit(2); } +} +void require(bool ok, const char* why) { + if (!ok) { std::fprintf(stderr, "FAIL: %s\n", why); std::exit(1); } +} +struct Buffer { + void* p = nullptr; size_t bytes; + explicit Buffer(size_t n): bytes(n) { ck(cudaMalloc(&p, n + 64)); ck(cudaMemset(p, 0xd3, n + 64)); } + ~Buffer() { ck(cudaFree(p)); } + template T* as() { return static_cast(p); } + void guard() { + unsigned char v[64]; + ck(cudaMemcpy(v, static_cast(p) + bytes, 64, cudaMemcpyDeviceToHost)); + for (auto c: v) require(c == 0xd3, "allocation guard modified"); + } +}; +struct Case { int64_t context, queries, capacity; int mode; int bound; bool timing; }; +int cases_done = 0, engaged = 0; +uint64_t scores_checked = 0, ids_checked = 0; + +void check(Case c) { + const auto s = k::qsa_real_shapes(); + const int64_t nb = c.capacity / s.idx_block + 2, nq = c.queries; + const int64_t active = c.context / s.idx_block + 1; + const int64_t bound = c.bound == 0 ? active : c.bound == 1 ? 0 : c.bound == 2 ? -1 : nb + 1; + const int64_t cap = k::qsa_selection_width(k::kTopkMaxCells, s); + std::mt19937 rng(91731 + (unsigned)c.context + 7*(unsigned)nq + 101*c.mode); + std::normal_distribution nd(0, 1); + std::uniform_int_distribution expo(-20, 20), small(-3, 3); + uint64_t sequence = 0; + auto value = [&]() -> float { + ++sequence; + if (c.mode == 1) return sequence % 11 == 0 ? 0.f : std::ldexp(nd(rng), expo(rng)); + if (c.mode == 2) return (float)small(rng); + if (c.mode == 3) return sequence % 2 ? 0.f : -0.f; + if (c.mode == 4) { + if (sequence % 23 == 0) return std::numeric_limits::quiet_NaN(); + if (sequence % 29 == 0) return std::numeric_limits::infinity(); + if (sequence % 31 == 0) return -std::numeric_limits::infinity(); + } + if (c.mode == 5) return sequence % 4 < 2 ? std::ldexp(1.f, 20) : -std::ldexp(1.f, 20); + return nd(rng); + }; + std::vector pooled(nb*s.idx_dim), dead(s.idx_dim), q(nq*s.idx_n_head*s.idx_dim); + for (auto& v: pooled) v = value(); + for (auto& v: dead) v = value(); + for (auto& v: q) v = value(); + // Padding after the largest live block must never affect scores or selected IDs. + for (int64_t i = active * s.idx_dim; i < (int64_t)pooled.size(); ++i) + pooled[i] = std::numeric_limits::quiet_NaN(); + std::vector steps(nq*k::kStepCount); + for (int64_t i = 0; i < nq; ++i) { + auto* st = steps.data() + i*k::kStepCount; + const int64_t n = c.context - nq + i + 1; + st[k::kStepPos] = n-1; st[k::kStepNKv] = n; + st[k::kStepNBid] = n/s.idx_block; + st[k::kStepWidth] = k::qsa_selection_width(n, s); + } + Buffer p(pooled.size()*4), d(dead.size()*4), query(q.size()*4), step(steps.size()*4); + Buffer a(nq*nb*4), b(nq*nb*4), ia(nq*cap*4), ib(nq*cap*4); + ck(cudaMemcpy(p.p, pooled.data(), p.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(d.p, dead.data(), d.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(query.p, q.data(), query.bytes, cudaMemcpyHostToDevice)); + ck(cudaMemcpy(step.p, steps.data(), step.bytes, cudaMemcpyHostToDevice)); + auto reference = [&] { + k::qsa_block_scores_reference(p.as(), d.as(), query.as(), step.as(), + nq, nb, s, a.as(), nullptr, bound); + }; + auto candidate = [&] { + k::qsa_block_scores(p.as(), d.as(), query.as(), step.as(), + nq, nb, s, b.as(), nullptr, bound); + }; + ck(cudaMemset(a.p, 0xa5, a.bytes)); ck(cudaMemset(b.p, 0x5a, b.bytes)); + reference(); candidate(); ck(cudaDeviceSynchronize()); + std::vector av(nq*nb), bv(nq*nb); + ck(cudaMemcpy(av.data(), a.p, a.bytes, cudaMemcpyDeviceToHost)); + ck(cudaMemcpy(bv.data(), b.p, b.bytes, cudaMemcpyDeviceToHost)); + uint64_t checked = 0; + for (int64_t i = 0; i < nq; ++i) { + const int64_t last = steps[i*k::kStepCount+k::kStepNBid]; + for (int64_t j = 0; j < nb; ++j) { + const auto at = i*nb+j; + if (j <= last) { + if (av[at] != bv[at]) { + std::fprintf(stderr, "MISMATCH ctx=%lld nq=%lld mode=%d query=%lld block=%lld bits=%08x/%08x\n", + (long long)c.context, (long long)nq, c.mode, (long long)i, (long long)j, av[at], bv[at]); + require(false, "scores differ bitwise"); + } + ++checked; + } else { + require(av[at] == 0xa5a5a5a5 && bv[at] == 0x5a5a5a5a, "inactive score padding overwritten"); + } + } + } + ck(cudaMemset(ia.p, 0xff, ia.bytes)); ck(cudaMemset(ib.p, 0xff, ib.bytes)); + k::qsa_block_topk(a.as(), step.as(), nq, nb, cap, s, ia.as(), nullptr, bound); + k::qsa_block_topk(b.as(), step.as(), nq, nb, cap, s, ib.as(), nullptr, bound); + ck(cudaDeviceSynchronize()); + std::vector iav(nq*cap), ibv(nq*cap); + ck(cudaMemcpy(iav.data(), ia.p, ia.bytes, cudaMemcpyDeviceToHost)); + ck(cudaMemcpy(ibv.data(), ib.p, ib.bytes, cudaMemcpyDeviceToHost)); + require(iav == ibv, "selected IDs differ"); + for (int64_t i = 0; i < nq; ++i) + for (int64_t j = steps[i*k::kStepCount+k::kStepWidth]; j < cap; ++j) + require(iav[i*cap+j] == -1, "ID padding overwritten"); + for (auto* v: {&p, &d, &query, &step, &a, &b, &ia, &ib}) v->guard(); + const bool branch = std::getenv("STRATA_SCORES_THREAD") && + std::atoi(std::getenv("STRATA_SCORES_THREAD")) == 1 && bound >= 16385 && bound <= nb && nq >= 64; + std::printf("PASS ctx=%lld nq=%lld capacity=%lld mode=%d bound=%lld expected_thread=%d scores=%llu ids=%lld\n", + (long long)c.context, (long long)nq, (long long)c.capacity, c.mode, (long long)bound, + (int)branch, (unsigned long long)checked, (long long)(nq*cap)); + ++cases_done; engaged += branch; scores_checked += checked; ids_checked += nq*cap; + if (c.timing) { + // Same actual bound/capacity, warmed, interleaved ABBA. Events measure GPU execution, not host fixture setup. + for (int i = 0; i < 3; ++i) { reference(); candidate(); } + ck(cudaDeviceSynchronize()); + cudaEvent_t e0, e1; ck(cudaEventCreate(&e0)); ck(cudaEventCreate(&e1)); + float times[2][4]{}; + for (int batch = 0; batch < 4; ++batch) { + const int order[4] = {0,1,1,0}; + for (int v: order) { + ck(cudaEventRecord(e0)); + for (int rep = 0; rep < 5; ++rep) { if (v == 0) reference(); else candidate(); } + ck(cudaEventRecord(e1)); ck(cudaEventSynchronize(e1)); + float ms = 0; ck(cudaEventElapsedTime(&ms, e0, e1)); times[v][batch] += ms/10; + } + } + float ta=0, tb=0; + for (int i=0; i<4; ++i) { ta+=times[0][i]/4; tb+=times[1][i]/4; } + std::printf("TIMING ctx=%lld nq=%lld baseline_ms=%.6f candidate_ms=%.6f speedup=%.6f trials=4 repeats_per_trial=10\n", + (long long)c.context, (long long)nq, ta, tb, ta/tb); + ck(cudaEventDestroy(e0)); ck(cudaEventDestroy(e1)); + } +} +} // namespace + +int main(int argc, char** argv) { + int devices = 0; + if (cudaGetDeviceCount(&devices) != cudaSuccess || devices == 0) { std::puts("SKIP no GPU"); return 77; } + cudaDeviceProp properties{}; ck(cudaGetDeviceProperties(&properties, 0)); + if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100")) { std::puts("SKIP requires gfx1100"); return 77; } + require(std::getenv("STRATA_SCORES_THREAD") && std::strcmp(std::getenv("STRATA_SCORES_THREAD"), "1") == 0, + "run with STRATA_SCORES_THREAD=1 so the candidate branch is tested"); + const bool full = argc > 1 && std::strcmp(argv[1], "--full") == 0; + for (int64_t n: {1,6,8,9,63,64,65,127,128,129,256}) + check({131075,n,262144,0,0,false}); + for (int64_t context: {65535,65536,65537,65538,65539,131072,262144}) + check({context,65,262144,0,0,false}); + for (int bound: {1,2,3}) check({131075,65,262144,0,bound,false}); + for (int mode: {1,2,3,4,5}) check({131075,129,262144,mode,0,false}); + check({131075,65,131075,0,0,false}); + if (full) { + for (int64_t context: {131072,131073,131074,131075}) check({context,256,262144,2,0,false}); + check({131072,256,262144,0,0,true}); + check({240000,256,262144,0,0,true}); + check({140000,1024,262144,0,0,true}); + check({240000,1024,262144,0,0,true}); + } + std::printf("QUALIFIED cases=%d expected_thread_cases=%d scores=%llu ids=%llu bitwise_scores=true bitwise_ids=true guards=true\n", + cases_done, engaged, (unsigned long long)scores_checked, (unsigned long long)ids_checked); + return 0; +} From 6cbc15a81ad8bc9dd46b1129a76fa2d8b4d2c398 Mon Sep 17 00:00:00 2001 From: Vop3p <69450118+Vop3p@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:12:35 -0400 Subject: [PATCH 20/28] STRATA_HC_PERSIST=1 (opt-in, HIP): the verifier's hyper-connection read as one persistent kernel The verifier reads the hyper-connection twice per layer at 1-8 tokens: three small launches with two global dependencies, the down projection on 41 blocks. Opt-in STRATA_HC_PERSIST=1 runs it as one kernel of 80 blocks with two grid barriers on an atomic counter: the down projection split by column slices over all 80 blocks, a distributed reduction, then the up projection and the same epilogue as gr_up_kernel. gfx1030 (2x RX 6900 XT, layer split): the read 1.35-2.10x at 1-8 tokens; ms per verify window -4.2 % at 4K and -2.8 % at 32K (one binary, the variable unset / set, 6 alternating rounds, every round the same way). Another summation order (not bitwise); against a double-accumulation reference (STRATA_HC_PERSIST=3) as close as the default read. Residency is decided by running every token count once at start-up with a 50 ms barrier timeout and comparing with the default read; a timeout keeps the default read for that token count and larger ones, wave64 cards are refused. One line per card says what was decided. Only the verifier's reads use it (one stream per card); the drafter's reads, the prompt path, CUDA and SYCL are unchanged (CUDA and SYCL get two empty stubs). With the variable unset both entry points return in their first line: the output is bitwise the same as main. Measurements, the simulated smaller cards and a stand-alone timing tool: bench/results/2026-10-12-hc-persist-gfx1030/. --- .../2026-10-12-hc-persist-gfx1030/README.md | 146 ++++++ .../hc_persist_bench.cpp | 73 +++ docs/AMD_HIP.md | 7 + include/strata/kernels/fused_gr.hpp | 8 + src/core/verify.cpp | 2 + src/kernels/cuda/fused_gr.cu | 431 ++++++++++++++++++ 6 files changed, 667 insertions(+) create mode 100644 bench/results/2026-10-12-hc-persist-gfx1030/README.md create mode 100644 bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp diff --git a/bench/results/2026-10-12-hc-persist-gfx1030/README.md b/bench/results/2026-10-12-hc-persist-gfx1030/README.md new file mode 100644 index 00000000..061c9b33 --- /dev/null +++ b/bench/results/2026-10-12-hc-persist-gfx1030/README.md @@ -0,0 +1,146 @@ +# STRATA_HC_PERSIST=1: the verifier's hyper-connection read as one persistent kernel (gfx1030) + +2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-38, +ROCm 10.0. Qwen3.8-Flash-Next IQ3_S (and Unsloth UD-Q4_K_XL), two-card layer split. + +## Result + +- The read itself: **1.35-2.10x faster** at 1-8 tokens on 40 WGPs (38.9 us against 55.1 us at 2 tokens). +- End to end, ms per verify window (`STRATA_DECODE_TIMING`, the configuration below, this branch, one binary with + the variable unset / set, 6 alternating rounds): **-4.2 % at 4K and -2.8 % at 32K, every round the same way**. + Tokens per window and prompt speed unchanged. +- Not bitwise (another summation order). Against a double-accumulation reference it is as close as the default read. +- Off by default; with the variable unset the engine's output is bitwise the same as without the change (checked below). + +## What the read does and why it was slow here + +Every layer the verifier reads the hyper-connection twice: RMS norm over 4 x 2560, a 320-row down projection (plus 4 +inject rows) and a 320 -> 10240 up projection. At 1-8 tokens this is three small launches with two global dependencies +between them; on gfx1030 the down kernel runs 41 blocks on 40 WGPs and the card idles between launches. + +The persistent kernel runs 80 blocks (two per WGP) and two grid barriers on an atomic counter: + +1. each block takes 128 columns of the 10240 (norm sum of squares + partial dots of the 324 down/inject rows), +2. barrier, each block reduces 4-5 of the 324 rows, +3. barrier, the up projection (a thread pair per row) and the same epilogue as `gr_up_kernel`. + +An ablation found only two parts that matter: the down projection split by columns over all 80 blocks, and one launch +instead of three. Prefetching the up weights (into registers, or touching them into L2 / Infinity Cache across the +barrier) and prefetching the epilogue inputs measured 0 and were removed - the 13 MB are read from VRAM once either way. + +| tokens | default read, us | persistent, us | | +|---|---|---|---| +| 1 | 51.6 | 38.1 | 1.35x | +| 2 | 55.1 | 38.9 | 1.41x | +| 3 | 60.0 | 40.5 | 1.48x | +| 4 | 63.9 | 43.6 | 1.46x | +| 5 | 67.6 | 43.1 | 1.57x | +| 6 | 71.5 | 46.1 | 1.55x | +| 7 | 96.4 | 46.3 | 2.08x | +| 8 | 104.4 | 49.7 | 2.10x | + +(`hc_persist_bench.cpp`, one card, a graph of 48 reads over 40 weight sets so the weights are cold, best of 3.) + +## Safety: what happens on a card it was not written for + +- `warpSize != 32` (wave64): off, the default read runs. +- Residency is decided by **running** every token count once at start-up with a 50 ms barrier timeout and comparing + the result with the default read; a timeout means "not resident" and that token count and larger ones keep the + default read. In a read the barrier gives up after 2 s (never seen in a working run). +- No occupancy API in front of the run: on 30 WGPs (HSA_CU_MASK) it promised more blocks than the card holds (a hang + before the timeout existed), and with the HIP 7.1 runtime (Ubuntu's `libamdhip64.so.7.1.52801`) it promised fewer + (1 per WGP on 40 WGPs), which turned the read off although it runs resident there. +- One line per card says what was decided: + +``` +strata hc: CUDA0: STRATA_HC_PERSIST=1: the verifier's hyper-connection read runs as one persistent kernel (80 blocks on +40 multiprocessors, up to 8 tokens; 0 token counts timed out in the check; checked against the default read, max +relative difference 1.8e-07) +``` + +Smaller cards, simulated on one 6900 XT with `HSA_CU_MASK` (`ROCR_VISIBLE_DEVICES=1`), both with ROCm 10.0 and with +the HIP 7.1 runtime (the same numbers within 0.2 us): + +| WGPs (CU mask) | like | tokens | persistent vs default | +|---|---|---|---| +| 40 | 6900 XT | 1-8 | 1.35-2.10x | +| 30 (`0:0-59`) | 6800 | 1-8 | 1.36-1.84x | +| 20 (`0:0-39`) | 6700 XT's CU count | 1-8 | 1.38-2.07x | +| 5 (`0:0-9`), 1 (`0:0-1`) | - | - | check timed out, default read, no hang | + +The mask keeps Navi 21's 256-bit bus and 128 MB Infinity Cache; a real 6700 XT / 6600 (narrower bus, smaller cache) +is not simulated by it. + +## End to end + +`strata-split.json`: `--layer-split`, IQ3_S, `--kv int8 --kv-resident 32768`, speculation 3 with min-p 0.7, +`--pipeline-windows 2`, `STRATA_SH_STREAM=1`, `STRATA_SPLIT_MTP_BATCH=1`. Main (a0116b27) with this change, one +binary, cold server per arm, the variable unset (default) and set alternating, 6 rounds, two 4K and two 32K requests +per arm (256 tokens out), ms per verify window from `STRATA_DECODE_TIMING`: + +| | default read | `STRATA_HC_PERSIST=1` | | rounds | +|---|---|---|---|---| +| 4K, ms per window | 25.81 | 24.73 | **-4.2 %** | -4.3 / -2.6 / -3.6 / -3.4 / -5.8 / -5.2 | +| 32K, ms per window | 24.40 | 23.72 | **-2.8 %** | -2.8 / -2.1 / -5.6 / -2.7 / -1.3 / -2.1 | +| tokens per window | 1.93 / 1.94 | 1.92 / 1.94 | | | +| prompt, tok/s (4K / 32K) | 848 / 1,636 | 850 / 1,632 | | | + +Run-to-run noise in ms per window is about +-3 % per round here, which is why the rounds alternate. An earlier version +of the kernel (the up weights prefetched into registers, since removed) measured -2.8 % / -2.0 % against the default read (two builds, 6 rounds) on +Unsloth UD-Q4_K_XL (`STRATA_MMQ_KQUANTS=ON`, 0.1.42); this version was not re-measured on it. + +## Quality + +`STRATA_LOGPOS` over three chats (9.4K, 34.7K, 105.8K tokens; ~500 scored positions each, top-256), pipeline windows +off, on **this PR's code on main (a0116b27)**. Only the 106K chat is reproducible run to run on this machine (the +first two differ in all positions between two runs of the same binary), so it is the one compared. +`STRATA_HC_PERSIST=3` is a reference that accumulates the same kernel in double. + +| 106K chat, against the double reference | KL mean | argmax same | +|---|---|---| +| default read | 0.0136 | 95.0 % | +| `STRATA_HC_PERSIST=1` | 0.0131 | 96.3 % | + +On 0.1.42 the same comparison gave 0.047 (default) and 0.038 (the earlier version of the kernel). + +Default path unchanged: main (a0116b27) built without and with this change, the same options, the variable unset: +the 106K chat's 481 scored positions are bitwise identical. With the variable unset `fused_gr_persist_init` and +`fused_gr_read_persist` return in their first line. + +0 stalls in every engine run with it (more than 30); three Strata slots on this machine use it daily since 2026-10-12. + +## Tried and dropped + +- Cooperative launch (`hipLaunchCooperativeKernel` + `grid.sync`): works and can be captured in a graph, but each + launch costs ~12 us more than a plain one here - more than the whole gain. +- `__builtin_amdgcn_global_load_lds` to stage the up weights: slower (4x the instructions, dword only on gfx1030), and + AMD clang 23 (ROCm 10.0) folds a constant address offset into the instruction offset, which the hardware also adds + to the LDS destination - the data lands shifted unless the pointer is laundered through an empty `asm`. +- Non-temporal loads for the weights: no effect. +- `STRATA_GR_V3=1` as a comparison: on gfx1030 it needs the two-half split, which fails its check (#375), so it falls + back to the default read. + +## Not tested + +- Any other card for real: RDNA 2 Navi 22/23 (6700 XT, 6600), RDNA 3 (7900), RDNA 4 (9070), NVIDIA. The kernel is + inside `#if defined(__HIPCC__)`; CUDA and SYCL get two empty stubs (`fused_gr_persist_init` does nothing, + `fused_gr_read_persist` returns false). CUDA and SYCL were not built here (no toolkit on this machine). +- Windows HIP. +- The drafter's reads (they run on their own stream and keep the default kernels) and the prompt path. + +## Help wanted + +On any RDNA card, with `STRATA_HC_PERSIST=1` in the engine's environment: + +1. the `strata hc:` line from the engine log (does it run, up to how many tokens, any timeouts?), and +2. two runs of the same prompt with `STRATA_DECODE_TIMING=1`, with and without the variable (ms per window). + +To time the read alone (from the repository root, after a HIP build in `build/`): + +``` +hipcc -O3 --offload-arch= -I include -c bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp -o hcpb.o +hipcc --offload-arch= hcpb.o build/libstrata_kernels.a build/libstrata_core.a -lrocblas -o hc_persist_bench +STRATA_HC_PERSIST=1 ./hc_persist_bench +``` + +Developed with an AI coding assistant; every number above was measured on 2x RX 6900 XT (gfx1030, PCIe 4.0 x8 each) / Ryzen 5 5600X, ROCm 10.0. diff --git a/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp b/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp new file mode 100644 index 00000000..e7b20f8f --- /dev/null +++ b/bench/results/2026-10-12-hc-persist-gfx1030/hc_persist_bench.cpp @@ -0,0 +1,73 @@ +// The engine's STRATA_HC_PERSIST read (public API) against the default read, per token count: the largest relative +// difference from the default read, and the time per read in a graph of 48 cold reads. Run with STRATA_HC_PERSIST=1 +#include +#include "strata/kernels/fused_gr.hpp" +#include +#include +#include +#include +#include +#include +namespace K = strata::kernels; +#define CK(x) do { hipError_t e_ = (x); if (e_ != hipSuccess) { std::fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, hipGetErrorString(e_)); std::exit(1); } } while (0) +constexpr int N = 2560, HC = 4, D = N * HC, LR = 320, TM = 8; +static uint16_t bf16(float x) { uint32_t u; std::memcpy(&u, &x, 4); return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); } +int main(int argc, char** argv) { + setvbuf(stdout, nullptr, _IONBF, 0); + const int W = argc > 1 ? std::atoi(argv[1]) : 40; + K::fused_gr_check(); + K::fused_gr_persist_init(); + std::mt19937 rng(5); std::normal_distribution nd(0.f, 1.f); + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); for (auto& x : bo) x = 0.5f * nd(rng); for (auto& x : inj) x = nd(rng); for (auto& x : wn) x = 1.f + 0.3f * nd(rng); + const size_t WD = (size_t) LR * D, WU = WD, WI = (size_t) HC * D; + uint16_t *dwd, *dwu, *dwi; CK(hipMalloc(&dwd, WD * 2 * W)); CK(hipMalloc(&dwu, WU * 2 * W)); CK(hipMalloc(&dwi, WI * 2 * W)); + { std::vector b(WD); for (int s = 0; s < W; ++s) { + for (auto& x : b) x = bf16(0.02f * nd(rng)); CK(hipMemcpy(dwd + WD * s, b.data(), WD * 2, hipMemcpyHostToDevice)); + for (auto& x : b) x = bf16(0.05f * nd(rng)); CK(hipMemcpy(dwu + WU * s, b.data(), WU * 2, hipMemcpyHostToDevice)); + for (size_t i = 0; i < WI; ++i) b[i] = bf16(0.02f * nd(rng)); CK(hipMemcpy(dwi + WI * s, b.data(), WI * 2, hipMemcpyHostToDevice)); } } + float *dR, *dbo, *dinj, *dwn, *dxn, *dlo, *drs, *dio, *dmix; + CK(hipMalloc(&dR, R.size() * 4)); CK(hipMalloc(&dbo, bo.size() * 4)); CK(hipMalloc(&dinj, inj.size() * 4)); CK(hipMalloc(&dwn, D * 4)); + CK(hipMalloc(&dxn, (size_t) TM * D * 4)); CK(hipMalloc(&dlo, (size_t) TM * LR * 4)); CK(hipMalloc(&drs, TM * HC * 4)); + CK(hipMalloc(&dio, TM * HC * 4)); CK(hipMalloc(&dmix, (size_t) TM * N * 4)); + CK(hipMemcpy(dbo, bo.data(), bo.size() * 4, hipMemcpyHostToDevice)); CK(hipMemcpy(dinj, inj.data(), inj.size() * 4, hipMemcpyHostToDevice)); + CK(hipMemcpy(dwn, wn.data(), D * 4, hipMemcpyHostToDevice)); + hipStream_t st; CK(hipStreamCreateWithFlags(&st, hipStreamNonBlocking)); + hipEvent_t e0, e1; hipEventCreate(&e0); hipEventCreate(&e1); + auto args = [&](K::FusedGrArgs* a, int T, int set) { + for (int t = 0; t < T; ++t) { a[t] = K::FusedGrArgs{}; a[t].R = dR + (size_t) t * D; a[t].R_out = dR + (size_t) t * D; a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; a[t].inj_prev = dinj + t * HC; a[t].w_norm = dwn; a[t].w_down = dwd + WD * set; + a[t].w_up = dwu + WU * set; a[t].w_inject = dwi + WI * set; a[t].eps = 1e-6f; a[t].lo = dlo + t * LR; a[t].rs = drs + t * HC; + a[t].inject_out = dio + t * HC; a[t].mixed = dmix + (size_t) t * N; } }; + for (int T = 1; T <= TM; ++T) { + K::FusedGrArgs a[TM]; args(a, T, 0); + std::vector out[2]; + bool ran = true; + for (int w = 0; w < 2; ++w) { + CK(hipMemcpy(dR, R.data(), R.size() * 4, hipMemcpyHostToDevice)); CK(hipMemset(dmix, 0xff, (size_t) TM * N * 4)); CK(hipDeviceSynchronize()); + if (w == 0) K::fused_gr_read_multi(a, T, dxn, st); else ran = K::fused_gr_read_persist(a, T, st); + CK(hipStreamSynchronize(st)); + out[w].resize((size_t) T * N); CK(hipMemcpy(out[w].data(), dmix, out[w].size() * 4, hipMemcpyDeviceToHost)); + } + if (!ran) { std::printf("T %d: persistent read not used here (falls back)\n", T); continue; } + double mr = 0, md = 0; bool fin = true; + for (size_t i = 0; i < out[0].size(); ++i) { fin = fin && std::isfinite(out[1][i]); mr = std::fmax(mr, std::fabs(out[0][i])); md = std::fmax(md, std::fabs(out[1][i] - out[0][i])); } + double us[2]; + for (int w = 0; w < 2; ++w) { + double best = 1e30; + for (int r = 0; r < 3; ++r) { + hipGraph_t g; hipGraphExec_t ge; + CK(hipStreamBeginCapture(st, hipStreamCaptureModeGlobal)); + for (int i = 0; i < 48; ++i) { args(a, T, (i * 7) % W); if (w == 0) K::fused_gr_read_multi(a, T, dxn, st); else K::fused_gr_read_persist(a, T, st); } + CK(hipStreamEndCapture(st, &g)); CK(hipGraphInstantiate(&ge, g, nullptr, nullptr, 0)); + for (int i = 0; i < 2; ++i) CK(hipGraphLaunch(ge, st)); + CK(hipEventRecord(e0, st)); for (int i = 0; i < 10; ++i) CK(hipGraphLaunch(ge, st)); CK(hipEventRecord(e1, st)); CK(hipEventSynchronize(e1)); + float ms; hipEventElapsedTime(&ms, e0, e1); best = std::fmin(best, 1e3 * ms / 480); + hipGraphExecDestroy(ge); hipGraphDestroy(g); + } + us[w] = best; + } + std::printf("T %d: default %6.1f us persistent %6.1f us (%.2fx) max rel diff %.2e%s\n", T, us[0], us[1], us[0] / us[1], md / mr, fin ? "" : " NON-FINITE"); + } + return 0; +} diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index d0038683..d5b5147f 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -517,6 +517,13 @@ run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx10 matrix cores; `hip_prefill_hipblaslt_gemm`, no hipBLASLt table) and 3 that fail for reasons outside the engine (`ple_parity` needs a Q2_0 PLE file that is not on that machine, `expert_multi_test` refuses the CPU without AVX-512, `platform_memory_test` cannot `mlock` at the shell's default `ulimit -l`). +- **The verifier's hyper-connection read as one persistent kernel:** `STRATA_HC_PERSIST=1` (opt-in, HIP, 32-lane + waves) runs the read of 1-8 tokens as one kernel of 80 blocks with two grid barriers instead of three launches; a + start-up run per token count with a barrier timeout decides where it is resident, and one `strata hc:` line per card + says so. On 2x RX 6900 XT (ROCm 10.0, layer split): the read 1.35-2.10x, ms per verify window -4.2 % / -2.8 % at + 4K / 32K (6 rounds), not bit-identical (as close to a double-accumulation reference as the default read): + [bench/results/2026-10-12-hc-persist-gfx1030](../bench/results/2026-10-12-hc-persist-gfx1030/README.md). Other + RDNA cards are untested; the `strata hc:` line and a `STRATA_DECODE_TIMING` run from one are welcome. - **gfx1031** (RX 6700 XT, #524): setup knows it (the `gfx103X-all` wheels, unvalidated); its reporter runs it daily on one card. More reports: an RX 6700 XT 12 GB run as gfx1030 on ROCm 7.2.4 (#1027: IQ2_XS, decode 30-32 tok/s, prompt about 300 tok/s, 6 of 6 needles), and an RX 6800M 12 GB on Windows with a self-built engine (#915, #1078: Q2_0, decode 9-27 tok/s, prompt 50-114 tok/s; the diff --git a/include/strata/kernels/fused_gr.hpp b/include/strata/kernels/fused_gr.hpp index 00324247..76af88cd 100644 --- a/include/strata/kernels/fused_gr.hpp +++ b/include/strata/kernels/fused_gr.hpp @@ -79,4 +79,12 @@ void fused_gr_set_fast(int on); void fused_gr_check(); int fused_gr_variant(); +/// Opt-in STRATA_HC_PERSIST=1 (HIP): the multi read as one persistent kernel (80 resident blocks, the down projection +/// split by column slices, two grid barriers). Another summation order (not bitwise). +/// `fused_gr_persist_init` checks residency and the result against the default read once per card (Verifier::init); +/// `fused_gr_read_persist` returns false when it did not run (off, too many tokens, a Q8 / QFUSE read) - then the caller +/// runs `fused_gr_read_multi`. Only for reads on a stream no other persistent read runs on concurrently (the verifier's). +void fused_gr_persist_init(); +bool fused_gr_read_persist(const FusedGrArgs* a, int n_tok, void* stream); + } // namespace strata::kernels diff --git a/src/core/verify.cpp b/src/core/verify.cpp index a8791cc6..36f62804 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -566,6 +566,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState& cudaGetDevice(&device_); // a layer split's stage on another GPU: its streams, graphs and buffers live there rr_stats_ = route_resident_cfg().stats_on(device_); // STRATA_ROUTE_RESIDENT: this GPU's counters, outside graph capture strata::kernels::fused_gr_check(); // once per card: which bitwise-equal hyper-connection read runs there + strata::kernels::fused_gr_persist_init(); // opt-in STRATA_HC_PERSIST=1 (HIP) wt_ = &wt; g_ = &g; ss_ = &ss; @@ -1103,6 +1104,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { else if (strata::kernels::cpu::expert_layout().native) a.q8_mixed = nat_xq_ + (size_t) t * (N / 32) * 36; } } + if (strata::kernels::fused_gr_read_persist(fa, n, cs)) return false; // STRATA_HC_PERSIST=1; q8_mixed is never set there return fused_gr_read_multi(fa, n, xn_ + (size_t) tb * HC * N, cs, (prof_on_ && grp == 0) ? prof_ : nullptr, (int) (l * kProfPer + (half == 0 ? 27 : 30))); }; diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu index c3c2fc8d..2653a92b 100644 --- a/src/kernels/cuda/fused_gr.cu +++ b/src/kernels/cuda/fused_gr.cu @@ -12,6 +12,8 @@ #include #include +#include +#include #include #include #include @@ -2330,4 +2332,433 @@ void fused_gr_check() { } +// ===================================== the read as ONE persistent kernel (opt-in STRATA_HC_PERSIST=1, HIP) ============== +// 80 blocks that must all be resident (a start-up run per T decides; larger T keep the default read) and two grid +// barriers on an atomic counter. Block b: (A) stages R' * w_norm for columns [128 b, 128 b + 128) (one stream) and writes +// that slice's sum of squares and the UNSCALED partial dots of the 320 down + 4 inject rows (the v3 identity +// w . xn = sum_c rs[c] (w[:, c] . x'[c])); barrier; (B) rs per stream, then rows (k, r) = b + 80 j reduced to lo / inject; +// barrier; (C) the up projection read straight from VRAM, a thread pair per row, the epilogue as gr_up_kernel. +// ANOTHER SUMMATION ORDER than the default read (not bitwise; the init check bounds the difference). Only the verifier's hyper-connection reads use it: they run on one stream per card (both pipeline +// verifiers share it), so two of these kernels never wait on each other; the drafter's reads keep the default kernels. +#if defined(__HIPCC__) +namespace { +namespace hcp { +// Measured on gfx1030 (bench/results/2026-10-12-hc-persist-gfx1030): the gain over the three-kernel read is (1) the down +// projection split by column slices over all 80 blocks (the default read runs 41 blocks staging the activations through +// LDS) and (2) one launch with two grid barriers instead of three launches and the gaps between them. Prefetching the +// up weights (into registers or by touching them into L2 / Infinity Cache) and the epilogue inputs measured no gain on +// gfx1030 and is gone: the 13 MB are read once from VRAM whichever way. +constexpr int NB = 80, SL = D / NB, SPS = N / SL, UPC = N / NB, NR = LR + HC; +static_assert(UPC * HC * 2 == THREADS, "a thread pair per up row"); +struct PArgs { + FusedGrArgs a[kFusedGrMaxT]; + float* part; // [T][NR][NB] + float* ssp; // [T][NB] + unsigned* bar; // [0] count, [32] generation, [48] abort (a barrier that timed out) + unsigned long long timeout_ticks; // s_memrealtime ticks (100 MHz) a barrier waits before it aborts the read + double* partd; // STRATA_HC_PERSIST=3 (a reference only): the partial dots and sums of squares in double + double* sspd; +}; +// Returns false when the read was aborted: a block waited longer than `ticks` (the 80 blocks were not all resident - the +// start-up check finds that out by running every T with a short timeout) or another block aborted. Then every block +// leaves the kernel; the outputs are not written completely and bar[48] stays set until the host clears the words. +__device__ __forceinline__ bool grid_sync(unsigned* bar, unsigned long long ticks) { + __shared__ int s_abort; + __syncthreads(); + if (threadIdx.x == 0) { + int ab = 0; + const unsigned gen = __hip_atomic_load(&bar[32], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + __threadfence(); + const unsigned arrived = __hip_atomic_fetch_add(&bar[0], 1u, __ATOMIC_ACQ_REL, __HIP_MEMORY_SCOPE_AGENT); + if (arrived == NB - 1) { + __hip_atomic_store(&bar[0], 0u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + __hip_atomic_fetch_add(&bar[32], 1u, __ATOMIC_RELEASE, __HIP_MEMORY_SCOPE_AGENT); + } else { + const unsigned long long t0 = __builtin_amdgcn_s_memrealtime(); + while (__hip_atomic_load(&bar[32], __ATOMIC_ACQUIRE, __HIP_MEMORY_SCOPE_AGENT) == gen) { + if (__hip_atomic_load(&bar[48], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) != 0u) { ab = 1; break; } + if (__builtin_amdgcn_s_memrealtime() - t0 > ticks) { + __hip_atomic_store(&bar[48], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + ab = 1; + break; + } + __builtin_amdgcn_s_sleep(1); + } + } + if (__hip_atomic_load(&bar[48], __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT) != 0u) ab = 1; + s_abort = ab; + } + __syncthreads(); + __threadfence(); + return s_abort == 0; +} +// STRATA_HC_PERSIST=3 (a reference only, slow): every dot and sum accumulated in double +__device__ __forceinline__ double dot8d(const uint4 w, const float* x) { + double acc = 0.0; + const unsigned u[4] = {w.x, w.y, w.z, w.w}; +#pragma unroll + for (int q = 0; q < 4; ++q) { + acc += (double) __uint_as_float(u[q] << 16) * (double) x[2 * q]; + acc += (double) __uint_as_float(u[q] & 0xffff0000u) * (double) x[2 * q + 1]; + } + return acc; +} +template +__global__ void __launch_bounds__(THREADS) persist_kernel(PArgs f) { + using A = typename std::conditional::type; + __shared__ __align__(16) float xs[T][SL]; + __shared__ __align__(16) float lo[T][LR]; + __shared__ float s_rs[T][HC]; + __shared__ float g[T][HC][UPC]; + const int tid = threadIdx.x, lane = tid & 31, b = blockIdx.x; + const FusedGrArgs& a0 = f.a[0]; + // (A) block b: columns [128 b, 128 b + 128) of D (one stream): R' * w_norm into LDS, the slice's sum of squares, and + // the UNSCALED partial dots of the 320 down + 4 inject rows (w . xn = sum_c rs[c] (w[:, c] . x'[c])) + const int c_b = b / SPS, col0 = b * SL; + if (tid < T * (SL / 4)) { + const int k = tid / (SL / 4), o4 = tid - k * (SL / 4); + const FusedGrArgs& a = f.a[k]; + const int i = col0 + o4 * 4, d = i - c_b * N; + float4 r = *reinterpret_cast(a.R + i); + if (a.apply) { + const float gw = 2.0f * sigmoidf_(a.inj_prev[c_b] / (float) HC); + const float4 bo = *reinterpret_cast(a.bo_prev + d); + r.x = fmaf(bo.x, gw, r.x); r.y = fmaf(bo.y, gw, r.y); r.z = fmaf(bo.z, gw, r.z); r.w = fmaf(bo.w, gw, r.w); + } + const float4 gn = *reinterpret_cast(a.w_norm + i); + if constexpr (DP) { + double ss = (double) r.x * r.x + (double) r.y * r.y + (double) r.z * r.z + (double) r.w * r.w; +#pragma unroll + for (int o = 16; o > 0; o >>= 1) ss += __shfl_xor(ss, o); + if (lane == 0) f.sspd[k * NB + b] = ss; + } else { + const float ss = warp_sum(r.x * r.x + r.y * r.y + r.z * r.z + r.w * r.w); // warp k = token k + if (lane == 0) f.ssp[k * NB + b] = ss; + } + *reinterpret_cast(&xs[k][o4 * 4]) = make_float4(r.x * gn.x, r.y * gn.y, r.z * gn.z, r.w * gn.w); + } + __syncthreads(); + const int hw = tid >> 4, hl = tid & 15; + const bool inj = a0.w_inject != nullptr; + const int nrows = inj ? NR : LR; +#pragma unroll 3 + for (int r = hw; r < nrows; r += 16) { + const uint16_t* wrow = r < LR ? a0.w_down + (size_t) r * D : a0.w_inject + (size_t) (r - LR) * D; + const uint4 w = __ldg(reinterpret_cast(wrow + col0) + hl); + A acc[T]; +#pragma unroll + for (int k = 0; k < T; ++k) { + A v; + if constexpr (DP) v = dot8d(w, &xs[k][hl * 8]); else v = dot8(w, &xs[k][hl * 8]); +#pragma unroll + for (int o = 8; o > 0; o >>= 1) v += __shfl_xor(v, o); + acc[k] = v; + } +#pragma unroll + for (int k = 0; k < T; ++k) + if (hl == k) { + if constexpr (DP) f.partd[((size_t) k * NR + r) * NB + b] = acc[k]; + else f.part[((size_t) k * NR + r) * NB + b] = (float) acc[k]; + } + } + if (!grid_sync(f.bar, f.timeout_ticks)) return; + // (B) rs per stream (every block), then rows (k, r) = b + 80 j reduced to lo / inject by the blocks in turn + if (tid < T * HC) { + const int k = tid / HC, c = tid - k * HC; + float rr; + if constexpr (DP) { + double sd = 0.0; + for (int j = 0; j < SPS; ++j) sd += f.sspd[k * NB + c * SPS + j]; + rr = (float) (1.0 / sqrt(sd / (double) N + (double) f.a[k].eps)); + } else { + float s = 0.0f; + for (int j = 0; j < SPS; ++j) s += f.ssp[k * NB + c * SPS + j]; + rr = rsqrtf(s / (float) N + f.a[k].eps); + } + s_rs[k][c] = rr; + if (b == 0) f.a[k].rs[c] = rr; + } + __syncthreads(); + for (int idx = b + NB * tid; idx < T * nrows; idx += NB * THREADS) { + const int k = idx / nrows, r = idx - k * nrows; + A sum = 0; + if constexpr (DP) { + const double* p1 = f.partd + ((size_t) k * NR + r) * NB; + for (int c = 0; c < HC; ++c) { + double p = 0.0; + for (int j = 0; j < SPS; ++j) p += p1[c * SPS + j]; + sum += (double) s_rs[k][c] * p; + } + } else { + const float4* p4 = reinterpret_cast(f.part + ((size_t) k * NR + r) * NB); +#pragma unroll + for (int c = 0; c < HC; ++c) { + float p = 0.0f; +#pragma unroll + for (int j = 0; j < SPS / 4; ++j) { + const float4 v = p4[c * (SPS / 4) + j]; + p += (v.x + v.y) + (v.z + v.w); + } + sum = fmaf(s_rs[k][c], p, sum); + } + } + if (r < LR) { + const A x = sum / (A) HC; + f.a[k].lo[r] = (float) (x / ((A) 1 + (DP ? (A) exp((double) -x) : (A) __expf((float) -x)))); + } else { + f.a[k].inject_out[r - LR] = (float) sum; + } + } + if (!grid_sync(f.bar, f.timeout_ticks)) return; + for (int idx = tid; idx < T * LR; idx += THREADS) { + const int k = idx / LR, r = idx - k * LR; + lo[k][r] = f.a[k].lo[r]; + } + __syncthreads(); + // (C) the up projection, a thread pair per row (block b: columns 32 b .. 32 b + 31 of all four streams), then the + // epilogue as gr_up_kernel + { + const int d0 = b * UPC; + const int ur = tid >> 1, uh = tid & 1, uc = ur / UPC, udd = ur - uc * UPC, ui = uc * N + d0 + udd; + const uint4* w4u = reinterpret_cast(a0.w_up + (size_t) ui * LR) + uh * 20; + A v[T]; +#pragma unroll + for (int k = 0; k < T; ++k) v[k] = 0; +#pragma unroll 1 + for (int j0 = 0; j0 < 20; j0 += 5) { // five chunks a batch (all twenty at once costs registers) + uint4 w[5]; +#pragma unroll + for (int q = 0; q < 5; ++q) w[q] = __ldg(w4u + j0 + q); +#pragma unroll + for (int q = 0; q < 5; ++q) +#pragma unroll + for (int k = 0; k < T; ++k) { + if constexpr (DP) v[k] += dot8d(w[q], &lo[k][uh * 160] + (j0 + q) * 8); + else v[k] += dot8(w[q], &lo[k][uh * 160] + (j0 + q) * 8); + } + } + float acc[T]; +#pragma unroll + for (int k = 0; k < T; ++k) acc[k] = (float) (v[k] + __shfl_xor(v[k], 1)); + if (uh == 0) { + const float wn = a0.w_norm[ui]; +#pragma unroll + for (int k = 0; k < T; ++k) { + const FusedGrArgs& a = f.a[k]; + float rv = a.R[ui]; + if (a.apply) { + rv = fmaf(a.bo_prev[d0 + udd], 2.0f * sigmoidf_(a.inj_prev[uc] / (float) HC), rv); + a.R_out[ui] = rv; + } + g[k][uc][udd] = rv * wn * s_rs[k][uc] * sigmoidf_(acc[k]); + } + } + } + __syncthreads(); + for (int idx = tid; idx < T * UPC; idx += THREADS) { + const int k = idx / UPC, col = idx - k * UPC; + float s = 0.0f; +#pragma unroll + for (int c = 0; c < HC; ++c) s += g[k][c][col]; + f.a[k].mixed[b * UPC + col] = s / (float) HC; + } +} +struct DevState { + float* part = nullptr; + float* ssp = nullptr; + double* partd = nullptr; + double* sspd = nullptr; + unsigned* bar = nullptr; + int max_t = 0; // 0: off on this card + bool tried = false; +}; +DevState g_dev[64]; +using KFn = void (*)(PArgs); +template +KFn kernel_t(int T) { + switch (T) { + case 1: return persist_kernel<1, DP>; + case 2: return persist_kernel<2, DP>; + case 3: return persist_kernel<3, DP>; + case 4: return persist_kernel<4, DP>; + case 5: return persist_kernel<5, DP>; + case 6: return persist_kernel<6, DP>; + case 7: return persist_kernel<7, DP>; + case 8: return persist_kernel<8, DP>; + } + return nullptr; +} +bool dp_on() { + static const bool dp = [] { const char* v = std::getenv("STRATA_HC_PERSIST"); return v != nullptr && std::atoi(v) == 3; }(); + return dp; +} +KFn kernel_for(int T) { return dp_on() ? kernel_t(T) : kernel_t(T); } +// s_memrealtime runs at 100 MHz on RDNA: a barrier gives up after 2 s in a read (never in a working run; it only turns a +// hang into a wrong read) and after 50 ms in the start-up check (where a timeout means "not resident here") +constexpr unsigned long long kTicksRun = 200000000ULL, kTicksCheck = 5000000ULL; +void launch(const FusedGrArgs* a, int n_tok, const DevState& st, cudaStream_t s, unsigned long long ticks) { + PArgs f; + for (int t = 0; t < n_tok; ++t) f.a[t] = a[t]; + f.part = st.part; f.ssp = st.ssp; f.bar = st.bar; f.partd = st.partd; f.sspd = st.sspd; f.timeout_ticks = ticks; + kernel_for(n_tok)<<>>(f); +} +bool env_on() { + static const bool on = [] { const char* v = std::getenv("STRATA_HC_PERSIST"); return v != nullptr && std::atoi(v) != 0; }(); + return on; +} +} // namespace hcp +} // namespace + +void fused_gr_persist_init() { + if (!hcp::env_on()) return; + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64 || hcp::g_dev[dev].tried) return; + hcp::DevState& st = hcp::g_dev[dev]; + st.tried = true; + cudaDeviceProp prop{}; + cudaGetDeviceProperties(&prop, dev); + if (prop.warpSize != 32) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: the kernel is written for 32-lane waves " + "(this card runs %d)\n", dev, prop.warpSize); + return; + } + const int mp = prop.multiProcessorCount; // only for the confirmation line (WGPs on RDNA) + bool ok = cudaMalloc((void**) &st.part, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(float)) == cudaSuccess && + cudaMalloc((void**) &st.ssp, (size_t) kFusedGrMaxT * hcp::NB * sizeof(float)) == cudaSuccess && + cudaMalloc((void**) &st.bar, 64 * sizeof(unsigned)) == cudaSuccess && + cudaMalloc((void**) &st.partd, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(double)) == cudaSuccess && + cudaMalloc((void**) &st.sspd, (size_t) kFusedGrMaxT * hcp::NB * sizeof(double)) == cudaSuccess && + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)) == cudaSuccess; + if (!ok) { + cudaGetLastError(); + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: workspace allocation failed\n", dev); + return; + } + // the check: random weights and inputs with the pending write and the inject rows, against the default read; the + // persistent read sums in another order, so it is bounded, not bitwise. Every T is RUN with a 50 ms barrier timeout; a + // timeout means "not resident here" and larger T keep the default read. No occupancy API in front of it: it promised + // more than the card holds on 30 WGPs under HSA_CU_MASK (a hang without the timeout) and less than it holds with + // the HIP 7.1 runtime (1 block per WGP on 40 WGPs, which turned the read off although it runs resident). + std::mt19937 rng(11); + std::normal_distribution nd(0.f, 1.f); + auto bf = [](float x) { uint32_t u; std::memcpy(&u, &x, 4); return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); }; + const int TM = kFusedGrMaxT; + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); + for (auto& x : bo) x = 0.5f * nd(rng); + for (auto& x : inj) x = nd(rng); + for (auto& x : wn) x = 1.0f + 0.3f * nd(rng); + std::vector wd((size_t) LR * D), wu((size_t) D * LR), wi((size_t) HC * D); + for (auto& x : wd) x = bf(0.02f * nd(rng)); + for (auto& x : wu) x = bf(0.05f * nd(rng)); + for (auto& x : wi) x = bf(0.02f * nd(rng)); + float *dR, *dbo, *dinj, *dwn, *dxn, *dlo, *drs, *dio, *dmix; + uint16_t *dwd, *dwu, *dwi; + cudaMalloc((void**) &dR, R.size() * 4); cudaMalloc((void**) &dbo, bo.size() * 4); + cudaMalloc((void**) &dinj, inj.size() * 4); cudaMalloc((void**) &dwn, wn.size() * 4); + cudaMalloc((void**) &dxn, (size_t) TM * D * 4); cudaMalloc((void**) &dlo, (size_t) TM * LR * 4); + cudaMalloc((void**) &drs, (size_t) TM * HC * 4); cudaMalloc((void**) &dio, (size_t) TM * HC * 4); + cudaMalloc((void**) &dmix, (size_t) TM * N * 4); + cudaMalloc((void**) &dwd, wd.size() * 2); cudaMalloc((void**) &dwu, wu.size() * 2); cudaMalloc((void**) &dwi, wi.size() * 2); + cudaMemcpy(dbo, bo.data(), bo.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dinj, inj.data(), inj.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dwn, wn.data(), wn.size() * 4, cudaMemcpyHostToDevice); + cudaMemcpy(dwd, wd.data(), wd.size() * 2, cudaMemcpyHostToDevice); + cudaMemcpy(dwu, wu.data(), wu.size() * 2, cudaMemcpyHostToDevice); + cudaMemcpy(dwi, wi.data(), wi.size() * 2, cudaMemcpyHostToDevice); + double worst = 0.0; + int bad_t = 0, timeouts = 0; + // 0: the read agrees with the default read; 1: a barrier timed out (not resident); 2: wrong or a device error + auto check = [&](int T) -> int { + FusedGrArgs a[kFusedGrMaxT]; + for (int t = 0; t < T; ++t) { + a[t] = FusedGrArgs{}; + a[t].R = dR + (size_t) t * D; a[t].R_out = dR + (size_t) t * D; a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; a[t].inj_prev = dinj + (size_t) t * HC; + a[t].w_norm = dwn; a[t].w_down = dwd; a[t].w_up = dwu; a[t].w_inject = dwi; a[t].eps = 1e-6f; + a[t].lo = dlo + (size_t) t * LR; a[t].rs = drs + (size_t) t * HC; + a[t].inject_out = dio + (size_t) t * HC; a[t].mixed = dmix + (size_t) t * N; + } + std::vector out[2]; + for (int which = 0; which < 2; ++which) { + cudaMemcpy(dR, R.data(), R.size() * 4, cudaMemcpyHostToDevice); + cudaMemset(dmix, 0xff, (size_t) TM * N * 4); + cudaMemset(dio, 0xff, (size_t) TM * HC * 4); + cudaDeviceSynchronize(); + if (which == 0) fused_gr_read_multi(a, T, dxn, nullptr); + else hcp::launch(a, T, st, nullptr, hcp::kTicksCheck); + if (cudaDeviceSynchronize() != cudaSuccess) { cudaGetLastError(); return 2; } + if (which == 1) { + unsigned abort_word = 0; + cudaMemcpy(&abort_word, st.bar + 48, sizeof abort_word, cudaMemcpyDeviceToHost); + if (abort_word != 0u) { + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)); + cudaDeviceSynchronize(); + return 1; + } + } + out[which].resize((size_t) T * (N + HC + D)); + cudaMemcpy(out[which].data(), dmix, (size_t) T * N * 4, cudaMemcpyDeviceToHost); + cudaMemcpy(out[which].data() + (size_t) T * N, dio, (size_t) T * HC * 4, cudaMemcpyDeviceToHost); + cudaMemcpy(out[which].data() + (size_t) T * (N + HC), dR, (size_t) T * D * 4, cudaMemcpyDeviceToHost); + } + double mref = 0.0, md = 0.0; + bool finite = true; + for (size_t i = 0; i < out[0].size(); ++i) { + finite = finite && std::isfinite(out[1][i]); + mref = std::fmax(mref, std::fabs((double) out[0][i])); + md = std::fmax(md, std::fabs((double) out[1][i] - out[0][i])); + } + const double rel = md / (mref > 0 ? mref : 1.0); + worst = std::fmax(worst, rel); + return finite && rel < 1e-4 ? 0 : 2; + }; + int max_t = 0; + for (int T = 1; T <= kFusedGrMaxT && ok; ++T) { + const int r = check(T); + if (r == 1) ++timeouts; else if (r == 2) { bad_t = T; ok = false; } + if (r != 0) break; + max_t = T; + } + cudaFree(dR); cudaFree(dbo); cudaFree(dinj); cudaFree(dwn); cudaFree(dxn); cudaFree(dlo); cudaFree(drs); + cudaFree(dio); cudaFree(dmix); cudaFree(dwd); cudaFree(dwu); cudaFree(dwi); + cudaMemset(st.bar, 0, 64 * sizeof(unsigned)); + cudaDeviceSynchronize(); + cudaGetLastError(); + if (!ok) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: the check failed at %d tokens " + "(max relative difference %.3g)\n", dev, bad_t, worst); + return; + } + if (max_t == 0) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: 80 blocks are not resident at once on %d " + "multiprocessors (the check timed out)\n", dev, mp); + return; + } + st.max_t = max_t; + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1: the verifier's hyper-connection read runs as one " + "persistent kernel (80 blocks on %d multiprocessors, up to %d tokens; %d token counts timed out in " + "the check; checked against the default read, max relative difference %.2g)\n", dev, mp, max_t, + timeouts, worst); +} + +bool fused_gr_read_persist(const FusedGrArgs* a, int n_tok, void* stream) { + if (!hcp::env_on() || n_tok < 1) return false; + int dev = 0; + cudaGetDevice(&dev); + if (dev < 0 || dev >= 64) return false; + const hcp::DevState& st = hcp::g_dev[dev]; + if (n_tok > st.max_t) return false; + if (a[0].q8_down != nullptr || a[0].q8_up != nullptr) return false; // STRATA_HC_Q8: the default read + for (int t = 0; t < n_tok; ++t) + if (a[t].q8_mixed != nullptr) return false; // STRATA_QFUSE: the default read + hcp::launch(a, n_tok, st, (cudaStream_t) stream, hcp::kTicksRun); + return true; +} +#else +void fused_gr_persist_init() {} +bool fused_gr_read_persist(const FusedGrArgs*, int, void*) { return false; } +#endif + } // namespace strata::kernels From cea3d61b6620d0cd8efe40a95506d79459b08309 Mon Sep 17 00:00:00 2001 From: Vop3p <69450118+Vop3p@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:22:13 -0400 Subject: [PATCH 21/28] tests: hc_persist_parity - the STRATA_HC_PERSIST=1 read against the default multi read at T = 1..8 (bounded 1e-4, finite, two runs bitwise), and hc_persist_default_off: with the variable unset it never runs; a skip where the card cannot hold the 80 blocks and on CUDA --- CMakeLists.txt | 7 ++ src/kernels/hc_persist_parity.cpp | 151 ++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 src/kernels/hc_persist_parity.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a82802bf..0febb009 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1005,6 +1005,13 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) target_include_directories(gr_multi_parity PRIVATE ${_strata_gpu_include_directories}) target_link_libraries(gr_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) add_test(NAME gr_multi_parity COMMAND gr_multi_parity) + # STRATA_HC_PERSIST=1: the persistent hyper-connection read against the default multi read (bounded, two runs bitwise), + # and with the variable unset it never runs (a skip where the card cannot hold its 80 blocks, and on CUDA) + add_executable(hc_persist_parity src/kernels/hc_persist_parity.cpp) + target_include_directories(hc_persist_parity PRIVATE ${_strata_gpu_include_directories}) + target_link_libraries(hc_persist_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target}) + add_test(NAME hc_persist_parity COMMAND hc_persist_parity) + add_test(NAME hc_persist_default_off COMMAND hc_persist_parity --off) if(STRATA_HIP_GFX906) # the S6 router (STRATA_HIP_ROUTER_FAST=1 on gfx906) against the portable kernel, bitwise, on wave64 add_executable(hip_router_fast tests/hip/router_fast.cpp) diff --git a/src/kernels/hc_persist_parity.cpp b/src/kernels/hc_persist_parity.cpp new file mode 100644 index 00000000..0e630060 --- /dev/null +++ b/src/kernels/hc_persist_parity.cpp @@ -0,0 +1,151 @@ +// src/kernels/hc_persist_parity.cpp - the STRATA_HC_PERSIST=1 hyper-connection read (one persistent kernel) against the +// default multi read (fused_gr_read_multi). +// +// Real geometry (n_embd 2560, hc 4, hc_lr 320), every T = 1..8, the pending write applied and the inject rows on, as the +// verifier calls it. The persistent read sums in another order, so it is bounded, not bitwise: every output (the mixed +// row, the inject outputs, the written R) must be finite and within 1e-4 of the default read relative to its largest +// magnitude, and two runs of the persistent read must agree bit for bit. Where the card does not hold the 80 blocks at +// once (or on CUDA, where the read is not built) the read reports that it did not run and the test passes as a skip. +// `--off`: with STRATA_HC_PERSIST unset the persistent read must never run (the default path is untouched). +// GPU, synthetic, no model. +#include "strata/kernels/fused_gr.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace k = strata::kernels; + +namespace { +constexpr int N = 2560, HC = 4, D = N * HC, LR = 320, TM = 8; +void ck(cudaError_t e, const char* w) { + if (e != cudaSuccess) { + std::fprintf(stderr, "%s: %s\n", w, cudaGetErrorString(e)); + std::exit(2); + } +} +uint16_t bf16(float x) { + uint32_t u; + std::memcpy(&u, &x, 4); + return (uint16_t) ((u + 0x7fff + ((u >> 16) & 1)) >> 16); +} +template +T* up(const std::vector& h) { + void* p = nullptr; + ck(cudaMalloc(&p, h.size() * sizeof(T)), "malloc"); + ck(cudaMemcpy(p, h.data(), h.size() * sizeof(T), cudaMemcpyHostToDevice), "h2d"); + return (T*) p; +} +template +T* dev(size_t n) { + void* p = nullptr; + ck(cudaMalloc(&p, n * sizeof(T)), "malloc"); + return (T*) p; +} +} // namespace + +int main(int argc, char** argv) { + const bool off = argc > 1 && std::strcmp(argv[1], "--off") == 0; + if (off) unsetenv("STRATA_HC_PERSIST"); + else setenv("STRATA_HC_PERSIST", "1", 1); + k::fused_gr_check(); + k::fused_gr_persist_init(); + + std::mt19937 rng(7); + std::normal_distribution nd(0.f, 1.f); + std::vector R((size_t) TM * D), bo((size_t) TM * N), inj((size_t) TM * HC), wn(D); + for (auto& x : R) x = nd(rng); + for (auto& x : bo) x = 0.5f * nd(rng); + for (auto& x : inj) x = nd(rng); + for (auto& x : wn) x = 1.f + 0.3f * nd(rng); + std::vector wd((size_t) LR * D), wu((size_t) D * LR), wi((size_t) HC * D); + for (auto& x : wd) x = bf16(0.02f * nd(rng)); + for (auto& x : wu) x = bf16(0.05f * nd(rng)); + for (auto& x : wi) x = bf16(0.02f * nd(rng)); + float* dR = dev(R.size()); + float* dbo = up(bo); + float* dinj = up(inj); + float* dwn = up(wn); + uint16_t* dwd = up(wd); + uint16_t* dwu = up(wu); + uint16_t* dwi = up(wi); + float* dxn = dev((size_t) TM * D); + float* dlo = dev((size_t) TM * LR); + float* drs = dev((size_t) TM * HC); + float* dio = dev((size_t) TM * HC); + float* dmix = dev((size_t) TM * N); + + int bad = 0, ran = 0; + for (int T = 1; T <= TM; ++T) { + k::FusedGrArgs a[TM]; + for (int t = 0; t < T; ++t) { + a[t] = k::FusedGrArgs{}; + a[t].R = dR + (size_t) t * D; + a[t].R_out = dR + (size_t) t * D; + a[t].apply = true; + a[t].bo_prev = dbo + (size_t) t * N; + a[t].inj_prev = dinj + (size_t) t * HC; + a[t].w_norm = dwn; + a[t].w_down = dwd; + a[t].w_up = dwu; + a[t].w_inject = dwi; + a[t].eps = 1e-6f; + a[t].lo = dlo + (size_t) t * LR; + a[t].rs = drs + (size_t) t * HC; + a[t].inject_out = dio + (size_t) t * HC; + a[t].mixed = dmix + (size_t) t * N; + } + // 0: the default read, 1 and 2: the persistent read twice; each output is mixed | inject | R + std::vector out[3]; + bool used = true; + for (int w = 0; w < 3; ++w) { + ck(cudaMemcpy(dR, R.data(), R.size() * 4, cudaMemcpyHostToDevice), "R"); + ck(cudaMemset(dmix, 0xff, (size_t) TM * N * 4), "mix"); + ck(cudaMemset(dio, 0xff, (size_t) TM * HC * 4), "io"); + ck(cudaDeviceSynchronize(), "sync"); + if (w == 0) k::fused_gr_read_multi(a, T, dxn, nullptr); + else used = k::fused_gr_read_persist(a, T, nullptr) && used; + ck(cudaDeviceSynchronize(), "read"); + out[w].resize((size_t) T * (N + HC + D)); + ck(cudaMemcpy(out[w].data(), dmix, (size_t) T * N * 4, cudaMemcpyDeviceToHost), "d2h mix"); + ck(cudaMemcpy(out[w].data() + (size_t) T * N, dio, (size_t) T * HC * 4, cudaMemcpyDeviceToHost), "d2h io"); + ck(cudaMemcpy(out[w].data() + (size_t) T * (N + HC), dR, (size_t) T * D * 4, cudaMemcpyDeviceToHost), "d2h R"); + if (w == 1 && !used) break; + } + if (off) { + if (used) { + std::printf("T=%d: the persistent read ran with STRATA_HC_PERSIST unset FAIL\n", T); + ++bad; + } + continue; + } + if (!used) { + std::printf("T=%d: the persistent read did not run on this card (skip)\n", T); + continue; + } + ++ran; + double mref = 0.0, md = 0.0; + bool finite = true; + for (size_t i = 0; i < out[0].size(); ++i) { + finite = finite && std::isfinite(out[1][i]); + mref = std::fmax(mref, std::fabs((double) out[0][i])); + md = std::fmax(md, std::fabs((double) out[1][i] - out[0][i])); + } + const double rel = md / (mref > 0 ? mref : 1.0); + const bool same = std::memcmp(out[1].data(), out[2].data(), out[1].size() * 4) == 0; + const bool ok = finite && rel < 1e-4 && same; + std::printf("T=%d: max relative difference %.3g against the default read, %s, two runs %s %s\n", T, rel, + finite ? "finite" : "NON-FINITE", same ? "bitwise equal" : "DIFFER", ok ? "ok" : "FAIL"); + if (!ok) ++bad; + } + if (off) std::printf("%s: STRATA_HC_PERSIST unset, the persistent read never ran\n", bad ? "FAIL" : "PASS"); + else if (ran == 0) std::printf("SKIP: the persistent read is not used on this card\n"); + else std::printf("%s: %d token counts checked\n", bad ? "FAIL" : "PASS", ran); + return bad ? 1 : 0; +} From b2b500095248ccf74a11c98b0f2c5151c39331aa Mon Sep 17 00:00:00 2001 From: Vop3p <69450118+Vop3p@users.noreply.github.com> Date: Tue, 13 Oct 2026 04:53:31 -0400 Subject: [PATCH 22/28] hc persist results: ten interleaved pairs on 0.1.43.1 with no other switch (-6.6 % / -4.4 % ms per verify window at 4K / 32K, 10 of 10 pairs) --- .../2026-10-12-hc-persist-gfx1030/README.md | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bench/results/2026-10-12-hc-persist-gfx1030/README.md b/bench/results/2026-10-12-hc-persist-gfx1030/README.md index 061c9b33..c12a4bc8 100644 --- a/bench/results/2026-10-12-hc-persist-gfx1030/README.md +++ b/bench/results/2026-10-12-hc-persist-gfx1030/README.md @@ -6,9 +6,10 @@ ROCm 10.0. Qwen3.8-Flash-Next IQ3_S (and Unsloth UD-Q4_K_XL), two-card layer spl ## Result - The read itself: **1.35-2.10x faster** at 1-8 tokens on 40 WGPs (38.9 us against 55.1 us at 2 tokens). -- End to end, ms per verify window (`STRATA_DECODE_TIMING`, the configuration below, this branch, one binary with - the variable unset / set, 6 alternating rounds): **-4.2 % at 4K and -2.8 % at 32K, every round the same way**. - Tokens per window and prompt speed unchanged. +- End to end, ms per verify window (`STRATA_DECODE_TIMING`, IQ3_S layer split, this branch, one binary with the + variable unset / set): **ten interleaved pairs on 0.1.43.1 with no other switch: -6.6 % at 4K and -4.4 % at 32K, + 10 of 10 pairs the same way**; with this machine's other gfx103x switches on, 6 rounds: -4.2 % / -2.8 %. Tokens + per window and prompt speed unchanged. - Not bitwise (another summation order). Against a double-accumulation reference it is as close as the default read. - Off by default; with the variable unset the engine's output is bitwise the same as without the change (checked below). @@ -89,6 +90,22 @@ Run-to-run noise in ms per window is about +-3 % per round here, which is why th of the kernel (the up weights prefetched into registers, since removed) measured -2.8 % / -2.0 % against the default read (two builds, 6 rounds) on Unsloth UD-Q4_K_XL (`STRATA_MMQ_KQUANTS=ON`, 0.1.42); this version was not re-measured on it. +### Ten interleaved pairs, no other switch + +0.1.43.1 (`a0116b27`) with this change, one binary, the engine's defaults (no environment variable at all) plus +`STRATA_DECODE_TIMING=1`, the variable unset / set. IQ3_S layer split, `--spec 3 --spec-min-p 0.7 +--pipeline-windows 2`, no vision. Ten pairs of cold servers, the order inside a pair alternating (off-on, on-off, +...), one 4K and one 32K request per server, 256 tokens out. Each server's log carries the `STRATA_HC_PERSIST=1` +line on both cards when set and not when unset (checked per arm). + +| ms per verify window | unset (median) | set (median) | per-pair median | pairs faster | the ten pairs | +|---|---|---|---|---|---| +| 4K | 27.08 | 25.26 | **-6.6 %** | **10 / 10** | -3.5 -8.5 -6.1 -7.1 -1.3 -8.0 -5.7 -4.2 -8.2 -10.3 | +| 32K | 26.37 | 25.15 | **-4.4 %** | **10 / 10** | -6.2 -5.8 -1.9 -2.9 -4.7 -2.1 -5.3 -9.2 -3.4 -4.1 | + +Without the other switches the default read is a larger share of the window, so the gain is larger than in the +6-round table above. + ## Quality `STRATA_LOGPOS` over three chats (9.4K, 34.7K, 105.8K tokens; ~500 scored positions each, top-256), pipeline windows From 595686f6a112fa15f99e0b3213d7346f06496aab Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:13:24 +0200 Subject: [PATCH 23/28] hc persist (#2226): not offered on gfx11 and gfx12 The persistent read's barrier timeout uses __builtin_amdgcn_s_memrealtime, which gfx11 and gfx12 do not have (clang: "needs target feature s-memrealtime"): the PR as ported failed to build for gfx1100, gfx1151 and gfx1200/gfx1201. On those parts the barrier compiles to an immediate abort, fused_gr_persist_init refuses the read with a start-up line, and the default read is used. An R9700 (gfx1201) measured the read +0.7% / +1.0% per window slower than the default in the PR thread, so nothing is lost. The silent, permanent barrier abort at run time that the same thread describes is noted in docs/AMD_HIP.md. --- docs/AMD_HIP.md | 6 +++++- src/kernels/cuda/fused_gr.cu | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index d5b5147f..ef633086 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -523,7 +523,11 @@ run it; the report below is from a community machine: an RX 6900 XT 16 GB (gfx10 says so. On 2x RX 6900 XT (ROCm 10.0, layer split): the read 1.35-2.10x, ms per verify window -4.2 % / -2.8 % at 4K / 32K (6 rounds), not bit-identical (as close to a double-accumulation reference as the default read): [bench/results/2026-10-12-hc-persist-gfx1030](../bench/results/2026-10-12-hc-persist-gfx1030/README.md). Other - RDNA cards are untested; the `strata hc:` line and a `STRATA_DECODE_TIMING` run from one are welcome. + RDNA cards are untested; the `strata hc:` line and a `STRATA_DECODE_TIMING` run from one are welcome. Not offered on gfx11 and + gfx12 (RDNA3, RDNA4): the barrier timeout needs `s_memrealtime`, which gfx1100 and gfx1200 / gfx1201 do not have, and an R9700 (#2226 thread) measured the + read +0.7 % / +1.0 % per window slower than the default one; the start-up line says so. A barrier that times out at run time + (never seen in a working run) leaves the partial outputs of that read in place and every later persistent read of the + process aborts at once, without a log line; the opt-in is for measurement on gfx103x until that is closed. - **gfx1031** (RX 6700 XT, #524): setup knows it (the `gfx103X-all` wheels, unvalidated); its reporter runs it daily on one card. More reports: an RX 6700 XT 12 GB run as gfx1030 on ROCm 7.2.4 (#1027: IQ2_XS, decode 30-32 tok/s, prompt about 300 tok/s, 6 of 6 needles), and an RX 6800M 12 GB on Windows with a self-built engine (#915, #1078: Q2_0, decode 9-27 tok/s, prompt 50-114 tok/s; the diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu index 2653a92b..e62315fc 100644 --- a/src/kernels/cuda/fused_gr.cu +++ b/src/kernels/cuda/fused_gr.cu @@ -2363,6 +2363,14 @@ struct PArgs { // start-up check finds that out by running every T with a short timeout) or another block aborted. Then every block // leaves the kernel; the outputs are not written completely and bar[48] stays set until the host clears the words. __device__ __forceinline__ bool grid_sync(unsigned* bar, unsigned long long ticks) { +#if defined(__GFX11__) || defined(__GFX12__) + // gfx11 and gfx12 have no s_memrealtime (clang: "needs target feature s-memrealtime"), so no barrier clock: this read is not + // offered there (fused_gr_persist_init refuses it; an R9700 measured it neutral to 1% slower in #2226), and a launch that gets + // here anyway aborts at once instead of waiting for a barrier it cannot time. + (void) ticks; + if (threadIdx.x == 0) __hip_atomic_store(&bar[48], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); + return false; +#else __shared__ int s_abort; __syncthreads(); if (threadIdx.x == 0) { @@ -2391,6 +2399,7 @@ __device__ __forceinline__ bool grid_sync(unsigned* bar, unsigned long long tick __syncthreads(); __threadfence(); return s_abort == 0; +#endif } // STRATA_HC_PERSIST=3 (a reference only, slow): every dot and sum accumulated in double __device__ __forceinline__ double dot8d(const uint4 w, const float* x) { @@ -2623,6 +2632,11 @@ void fused_gr_persist_init() { "(this card runs %d)\n", dev, prop.warpSize); return; } + if (strata::kernels::gfx_arch_is_gfx12(prop.gcnArchName) || strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName)) { + std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: gfx11 / gfx12 have no s_memrealtime for the barrier " + "timeout (written and measured for gfx1030; an R9700 saw no gain from it, #2226)\n", dev); + return; + } const int mp = prop.multiProcessorCount; // only for the confirmation line (WGPs on RDNA) bool ok = cudaMalloc((void**) &st.part, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(float)) == cudaSuccess && cudaMalloc((void**) &st.ssp, (size_t) kFusedGrMaxT * hcp::NB * sizeof(float)) == cudaSuccess && From b317c23f245fb6a2e5d07d07f2f7268a546549a2 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:14:06 +0200 Subject: [PATCH 24/28] pcie (#2224): the PcieAuto share on HIP outside gfx12 is opt-in (STRATA_PCIE_FRAC_DEFAULT=auto), not a gfx1100 default: the author's gate was no-regression only and a second gfx1100 report saw it never engage --- docs/DETAILS.md | 2 +- src/program/generate.cpp | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 50e78725..5766ba10 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1706,7 +1706,7 @@ already times: the wall time of the CPU pool per missed expert. With `R` = exper `L / (L + 1.85 R)`, rounded to 0.05 and kept between 0.10 and 0.60; it is changed at most three times (after 48, 96 and 96 more windows, about 10 s of decoding), and only by a full step. Each change prints one `PCIe share:` line. A request that sets its own `pcie_frac` is left alone. **`--pcie-frac N` always wins; `STRATA_PCIE_FRAC_DEFAULT=old` keeps the 0.1.41 rule.** Not used with a layer split, `--batch`, a peer GPU, when every -expert is in VRAM, or on SYCL or on HIP other than gfx1200 / gfx1201 (RDNA4, where the measured share is the default since 0.1.43; `STRATA_PCIE_FRAC_DEFAULT=old` opts out). The canonical Q2_0 pack uses it on CUDA since 0.1.43, on Linux by default and on Windows with `STRATA_PCIE_AUTO_CANON=1` (an RTX 5070 there: code +2.5%, a short answer -3.3%). The constant 1.85 is a fit to three machines, so it lands within a step of each machine's best, not on it. On HIP, `STRATA_PCIE_AUTO_SPLIT=1` (opt-in, 0.1.43) also refines a two-stage layer split: the pool speed is read once and each stage takes the share its own probed link gives (2x R9700 at 16 GB-eq, tail skip on: Q2_0 story +4.5%, code +9.9%, 4K +8.8%; IQ3_S story -2.1%, code +8.0%, 4K +23.3%; with three or more stages the pipelined loop does not run it). +expert is in VRAM, or on SYCL or on HIP other than gfx1200 / gfx1201 (RDNA4, where the measured share is the default since 0.1.43; `STRATA_PCIE_FRAC_DEFAULT=old` opts out; on the other HIP parts `STRATA_PCIE_FRAC_DEFAULT=auto` turns it on: an RX 7900 XTX showed no regression, no gain was claimed, #2224). The canonical Q2_0 pack uses it on CUDA since 0.1.43, on Linux by default and on Windows with `STRATA_PCIE_AUTO_CANON=1` (an RTX 5070 there: code +2.5%, a short answer -3.3%). The constant 1.85 is a fit to three machines, so it lands within a step of each machine's best, not on it. On HIP, `STRATA_PCIE_AUTO_SPLIT=1` (opt-in, 0.1.43) also refines a two-stage layer split: the pool speed is read once and each stage takes the share its own probed link gives (2x R9700 at 16 GB-eq, tail skip on: Q2_0 story +4.5%, code +9.9%, 4K +8.8%; IQ3_S story -2.1%, code +8.0%, 4K +23.3%; with three or more stages the pipelined loop does not run it). Measured (interleaved pairs of whole engine runs, new default against `STRATA_PCIE_FRAC_DEFAULT=old`, medians, route tail skip on): diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 1655b8d8..e11f84a6 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -1648,17 +1648,15 @@ static bool pcie_auto_split_ok() { #endif } -// gfx1100 (RX 7900 XT/XTX/GRE): the same refinement, gate-measured on the one other arch it has run -// on (paired no-regression: 4 alternating starts at 64K, prefill 2189 base vs 2180 with it, decode -// 65.4 vs 65.4; engagement under serve measured: the share refines 0.55 -> 0.25 from the pool's -// 42-45 us/missed expert and the probed 28.4-28.5 GB/s link). Nothing is claimed for the unmeasured -// archs: they keep the gate's "earlier behaviour". +// HIP outside gfx12: the same refinement, opt-in with STRATA_PCIE_FRAC_DEFAULT=auto (#2224). Its author gate-measured it on an +// RX 7900 XTX (gfx1100) as "no regression" only (4 alternating starts at 64K, prefill 2189 base vs 2180 with it, decode 65.4 vs +// 65.4; under serve the share refines 0.55 -> 0.25 from the pool's 42-45 us/missed expert and the probed 28.4-28.5 GB/s link); +// a second report (2x RX 7900 GRE) found it never engages there (95-98% of the experts cached). The gain is measured only on +// gfx1201 (where it is the default, decode_defaults_arch_ok), so the other parts keep the fixed share unless asked. [[maybe_unused]] static bool pcie_auto_fork_arch_ok() { #if defined(STRATA_USE_HIP) - int dev = 0; - cudaDeviceProp p{}; - return cudaGetDevice(&dev) == cudaSuccess && cudaGetDeviceProperties(&p, dev) == cudaSuccess && - strata::kernels::gfx_arch_is(p.gcnArchName, "gfx1100"); + const char* pfd = std::getenv("STRATA_PCIE_FRAC_DEFAULT"); + return pfd != nullptr && std::strcmp(pfd, "auto") == 0; #else return false; #endif @@ -2904,10 +2902,8 @@ int main(int argc, char** argv) { o.pcie_frac = pcie_frac_for_gbps(bw, base); std::fprintf(stderr, "strata generate: PCIe probe: %.1f GB/s host->device (best of %s) -> pcie_frac %.2f " "(default %.2f)\n", bw, bursts.c_str(), o.pcie_frac, base); - // 0.1.43 upstream: split opt-in + gfx12 default-on (decode_defaults_arch_ok). gfx1100 joins it: - // the refinement is engine-generic (pool timings + miss counts vs the probed link), the start-up - // probe here is already best-of-4 with +-0.7% spread, and on gfx1100 it is gate-measured - // (pcie_auto_fork_arch_ok). Every other AMD part keeps its earlier behaviour; + // 0.1.43: split opt-in + gfx12 default-on (decode_defaults_arch_ok). Other HIP parts: STRATA_PCIE_FRAC_DEFAULT=auto + // turns the refinement on (pcie_auto_fork_arch_ok); the pool timings and miss counts it reads are engine-generic. // STRATA_PCIE_FRAC_DEFAULT=old keeps the start-up rule everywhere. o.pcie_frac_auto = (o.layer_split.empty() || pcie_auto_split_ok()) && !pf_old && (decode_defaults_arch_ok() || pcie_auto_fork_arch_ok()); From a61436c4dacb331749a46f0471162f810fcaee2e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:14:23 +0200 Subject: [PATCH 25/28] refill parts (#2078): not in gfx1151's default table (only gfx1151 measured it, and nothing here can gate that arch): opt-in STRATA_REFILL_PARTS=1, documented in section 5 --- docs/STRIX_HALO.md | 3 ++- src/core/arch_defaults.cpp | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/STRIX_HALO.md b/docs/STRIX_HALO.md index 20790766..af227b70 100644 --- a/docs/STRIX_HALO.md +++ b/docs/STRIX_HALO.md @@ -92,7 +92,6 @@ they change speed, not answers. Nothing here applies to CUDA or to another AMD a | `STRATA_GDN_HEAD`, `STRATA_GDN_PP=2`, `STRATA_GDN_CONVL2`, `STRATA_GDN_NOY` | the prompt's gated-delta-net recurrence: four lanes per column, two columns per lane, the convolution and the norms fused | | `STRATA_HCD_EXACT` | the hyper-connection down projection (N 320, K 10240) in a WMMA kernel that reproduces hipBLASLt solution 1176 / 1177's summation order (`hip_prefill_hcd_exact_parity` checks it bit for bit); it runs only where the table makes hipBLASLt pick one of those two, and says once if it cannot | | `STRATA_CVEC_FUSE`, `STRATA_PF_PAD` | a steered layer's write, control vector and next norm in one pass; padded GEMM row strides | -| `STRATA_REFILL_PARTS` | after a prompt, the expert-cache slots it borrowed are refilled straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt | | `STRATA_Q8_PACKED`, `STRATA_Q6_PACKED`, `STRATA_MMVF_ROWS`, `STRATA_ATTN_LANECELL` | decode layouts and kernels (packed Q8_0 / Q6_K weights, 4-row BF16 GEMV, one-cell-per-thread attention scores) | | `STRATA_EXPERT_V2`, `STRATA_TSUM`, `STRATA_LFUSE` | the grouped decode experts (IQ3_S / IQ4_NL), single-butterfly warp sums, fewer launches around the shared expert and the KV append | | `STRATA_GDN_SPLIT`, `STRATA_QFUSE`, `STRATA_PLE_BATCH` | the GDN step over four blocks per head, activation images written by their producers, the PLE key / value projections of a verify window at once | @@ -133,6 +132,8 @@ It rounds differently from the int8 kernels. First-token KL against a run with n 0.0031 (0.0024) for `STRATA_PF_FUSED=1 STRATA_PF_FUSED_KQ=1` without it; UD-IQ4_XS 0.0085 (0.0036) against 0.0068 (0.0032). One 1.5K prompt carries most of the Q4_K_XL mean (0.049). +`STRATA_REFILL_PARTS=1` (opt-in, exact; HIP and CUDA, a GGUF read in place) refills the expert-cache slots a prompt borrowed straight from the GGUF mapping (an expert's gate, up and down tensors) instead of through an assembled 4 MB copy per expert: the same bytes in the slot (checked against the assembled blob on 162 slots), 0.1 to 0.3 s less at the end of a prompt; gfx1151, UD-Q4_K_XL and UD-IQ4_XS: a 4K-8K prompt +2.3% to +3.5%, 32K +1.1%. It is not in the table above because only gfx1151 has measured it. + Two engine flags help on long contexts and are not Strix-specific: `--mtp-window 8192` (the draft layer attends to the last 8,192 cells: 64K output +3.5%, 32K -0.4%) and `--spec`, `--lookup-chain`, `--mtp-q4` (see [DETAILS.md](DETAILS.md)). diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp index 59d3f6a1..e8ca7c9b 100644 --- a/src/core/arch_defaults.cpp +++ b/src/core/arch_defaults.cpp @@ -42,7 +42,6 @@ std::vector> arch_default_env(const char* gc {"STRATA_CVEC_FUSE", "1"}, // a steered layer's write, control vector and next norm in one pass (S23) {"STRATA_HCD_EXACT", "1"}, // the HC down GEMM in hipBLASLt solution 1176's k order: 64K +1.8% (stream S) {"STRATA_PF_PAD", "1"}, // padded GEMM row strides (acts with STRATA_PF_GEMM; inert without it) (S23) - {"STRATA_REFILL_PARTS", "1"}, // the prompt's lent slots refilled from the GGUF mapping's pieces, not an assembled copy: same bytes, refill 217 -> 105 ms at 4K, 589 -> 322 ms at 32K // decode {"STRATA_Q8_PACKED", "1"}, // the packed Q8_0 decode layout: +2.3% (S26) {"STRATA_Q6_PACKED", "1"}, // the packed Q6_K heads (S26) From 7d3fd4b24f90e9435cbc97c1cfd46335fda0ceaa Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 07:23:59 +0200 Subject: [PATCH 26/28] tests (#2147): test_setup_rocm_pins skips an index with no saved version list (the gfx1150 opt-in has none yet) --- tools/test_setup_rocm_pins.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/test_setup_rocm_pins.py b/tools/test_setup_rocm_pins.py index 4bf5c436..69f0d4ff 100644 --- a/tools/test_setup_rocm_pins.py +++ b/tools/test_setup_rocm_pins.py @@ -36,6 +36,8 @@ class RocmPick(unittest.TestCase): def test_every_family_gets_a_version_its_index_has(self): for arch in setup.ROCM_INDEXES: + if setup.rocm_family(setup.ROCM_INDEXES[arch]) not in LISTINGS: + continue # the gfx1150 opt-in (#2147): no saved version list for its index yet with self.subTest(arch=arch): version, note = self.want(arch) self.assertIn(version, LISTINGS[setup.rocm_family(setup.ROCM_INDEXES[arch])]) From c298fa559e8eef181eedd1f8c08d7009a8dbda8f Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 08:27:28 +0200 Subject: [PATCH 27/28] qsa scorer (#1943): the exact four-lanes-per-query scorer is the default on gfx12; the test runs there too The same kernel measured on an R9700 (gfx1201): qsa_scores_gfx1100_parity --full compares 223,664,777 scores and 11,895,800 ids bitwise equal to the warp scorer (35 cases), the scorer stage with 256 queries is 3.6x faster at 131K and 4.0x at 240K, and a fresh prompt reads 8.7% faster at 131K tokens (4 of 4 pairs) and 16.4% faster at 230K (3 of 3), with identical answer tokens and byte-identical exact_pp residual dumps at 70K and 131K tokens. So on gfx12 it is on for batches of >= 64 queries with >= 16,385 live blocks (65K cells and more) unless STRATA_SCORES_THREAD=0; gfx1100 stays the author's opt-in (STRATA_SCORES_THREAD=1). A one-time stderr line says when it engages by default. --- docs/AMD_HIP.md | 7 +++-- src/kernels/cuda/qsa_select.cu | 31 ++++++++++++++--------- src/kernels/qsa_scores_gfx1100_parity.cpp | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index ef633086..ef9264ba 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -299,10 +299,13 @@ only when its version matches the installed library; otherwise it prefills on pl prompt), so keep the table and the library paired. Not worth trying (measured flat): `--kv-resident` changes, a prefill chunk above 32768, `--spec` above 4. -## gfx1100: optional exact long-prompt QSA scorer +## Exact long-prompt QSA scorer (gfx1100 opt-in, gfx12 default) `STRATA_SCORES_THREAD=1` at engine startup enables a HIP port of #1825's score kernel on gfx1100, for batches of -at least 64 queries with at least 16,385 live index blocks. The default, short-prompt and decode paths keep the +at least 64 queries with at least 16,385 live index blocks. On gfx12 (RDNA4) it is on by default for those batches and +`STRATA_SCORES_THREAD=0` turns it off (0.1.45): on an R9700 `qsa_scores_gfx1100_parity --full` compares 223,664,777 scores and +11,895,800 ids bitwise equal to the warp scorer, the scorer stage with 256 queries is 3.6x faster at 131K and 4.0x at 240K, and a +fresh prompt of 131K tokens reads 8.7% faster (4 of 4 pairs) and one of 230K tokens 16.4% faster (3 of 3), with the same answer tokens and byte-identical `exact_pp` residual dumps at 70K and 131K tokens (prompts under 65K cells never reach the bound). The default, short-prompt and decode paths keep the existing scorer. On one RX 7900 XTX / 7950X3D / ROCm 10.0.0, three paired runs of a tuned 0.1.40.3 engine reduced fresh one-token request time by 10.45% at 130,978 prompt tokens and 22.64% at 239,906; one same-binary current-main pair measured 12.85% and 21.71%. Cached follow-ups did not show a repeatable large gain, and a two-task coding pilot diff --git a/src/kernels/cuda/qsa_select.cu b/src/kernels/cuda/qsa_select.cu index c27ca108..5fd67f95 100644 --- a/src/kernels/cuda/qsa_select.cu +++ b/src/kernels/cuda/qsa_select.cu @@ -947,19 +947,24 @@ __global__ void __launch_bounds__(256, 1) block_scores_thread_kernel(const float } } -bool scores_gfx1100_device() { +// The exact scorer runs on gfx1100 (the PR's own card) when STRATA_SCORES_THREAD=1, and on gfx12 (RDNA4) unless STRATA_SCORES_THREAD=0: +// there it is bitwise equal to the warp scorer on an R9700 (qsa_scores_gfx1100_parity --full, 35 cases; exact_pp residual dumps at 70K and +// 131K tokens) and 3.6-4.4x faster in the scorer stage, +8% (131K) to +15% (230K) on a prompt read. Other wave32 parts have no measurement. +// Returns 0 (not offered), 1 (gfx1100: only on request), 2 (gfx12: the default). +int scores_thread_arch() { int device = -1; - if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return false; } + if (cudaGetDevice(&device) != cudaSuccess) { cudaGetLastError(); return 0; } static thread_local int cached_device = -1; - static thread_local bool supported = false; + static thread_local int arch = 0; if (device != cached_device) { cudaDeviceProp properties{}; - supported = cudaGetDeviceProperties(&properties, device) == cudaSuccess && - gfx_arch_is(properties.gcnArchName, "gfx1100"); + arch = 0; + if (cudaGetDeviceProperties(&properties, device) == cudaSuccess) + arch = gfx_arch_is_gfx12(properties.gcnArchName) ? 2 : gfx_arch_is(properties.gcnArchName, "gfx1100") ? 1 : 0; cached_device = device; cudaGetLastError(); } - return supported; + return arch; } #endif @@ -1207,16 +1212,18 @@ void qsa_block_scores(const float* pooled, const float* dead, const float* q_idx } const int64_t reach = active_blocks > 0 && active_blocks < max_blocks ? active_blocks : max_blocks; #if defined(__HIPCC__) - static const bool thread_scores = [] { + // STRATA_SCORES_THREAD: 1 = on (gfx1100, gfx12), 0 = off, unset = on for gfx12 only (gfx1100: off, nothing measured here) + static const int thread_env = [] { const char* value = std::getenv("STRATA_SCORES_THREAD"); - return value != nullptr && std::atoi(value) == 1; // experiment: off by default + return value == nullptr ? -1 : (std::atoi(value) == 1 ? 1 : 0); }(); // The bound is the ACTUAL live extent. A reserved 256K context never enables this by itself. - if (thread_scores && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 && - scores_gfx1100_device()) { + if (thread_env != 0 && active_blocks >= 16385 && active_blocks <= max_blocks && nq >= 64 && + (scores_thread_arch() == 2 || (thread_env == 1 && scores_thread_arch() == 1))) { static thread_local bool logged = false; - if (!logged && std::getenv("STRATA_SCORES_THREAD_TRACE")) { - std::fprintf(stderr, "qsa exact thread: gfx1100 nq=%lld active_blocks=%lld capacity=%lld\n", + if (!logged && (thread_env == -1 || std::getenv("STRATA_SCORES_THREAD_TRACE"))) { + std::fprintf(stderr, "qsa exact thread: the prompt's block scorer runs as the four-lanes-per-query kernel (nq=%lld active_blocks=%lld " + "capacity=%lld; the same scores bit for bit; STRATA_SCORES_THREAD=0 turns it off)\n", (long long)nq, (long long)active_blocks, (long long)max_blocks); logged = true; } diff --git a/src/kernels/qsa_scores_gfx1100_parity.cpp b/src/kernels/qsa_scores_gfx1100_parity.cpp index 63053d93..00832d97 100644 --- a/src/kernels/qsa_scores_gfx1100_parity.cpp +++ b/src/kernels/qsa_scores_gfx1100_parity.cpp @@ -161,7 +161,7 @@ int main(int argc, char** argv) { int devices = 0; if (cudaGetDeviceCount(&devices) != cudaSuccess || devices == 0) { std::puts("SKIP no GPU"); return 77; } cudaDeviceProp properties{}; ck(cudaGetDeviceProperties(&properties, 0)); - if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100")) { std::puts("SKIP requires gfx1100"); return 77; } + if (!k::gfx_arch_is(properties.gcnArchName, "gfx1100") && !k::gfx_arch_is_gfx12(properties.gcnArchName)) { std::puts("SKIP requires gfx1100 or gfx12"); return 77; } require(std::getenv("STRATA_SCORES_THREAD") && std::strcmp(std::getenv("STRATA_SCORES_THREAD"), "1") == 0, "run with STRATA_SCORES_THREAD=1 so the candidate branch is tested"); const bool full = argc > 1 && std::strcmp(argv[1], "--full") == 0; From d30f5d1042747708f8fa63a34b4bcaadcac5ae37 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 14 Oct 2026 11:46:11 +0200 Subject: [PATCH 28/28] docs (#1749): the wide top-k kernel on HIP, what it does and the switches that restore the old ones (R9700: 22.0 -> 0.93 ms per 256 queries at 524K; a 500K-token prompt +34%) --- docs/AMD_HIP.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index ef9264ba..ce702054 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -313,6 +313,14 @@ was 3.27% slower overall. This is opt-in, not a general coding-speed recommendat [report, per-run data and standalone score/ID check](../bench/results/2026-10-11-gfx1100-qsa-scores/README.md) give the settings, exact-parity checks and limits. `STRATA_SCORES_THREAD_TRACE=1` prints an engagement line. +## Deep contexts: the prompt's top-k selection (0.1.45, #1749) + +Past ~135K cells (and from ~90K cells on a prompt read) the prompt's top-k selection runs the wide kernel, as on CUDA, instead of the four-pass +reference radix that every deep context on HIP paid; the same ids (`qsa_select_bench` compares them with the reference). On an R9700 the +selection of a 256-query batch is 0.29 -> 0.21 ms at 98K, 1.16 -> 0.49 ms at 262K and 22.0 -> 0.93 ms at 524K; a fresh prompt reads 1.3% faster at +230K tokens and 34% faster at 500K (716 -> 962 tok/s; 1,284 tok/s with the exact scorer above, 79% in all), with the same answer tokens. +`STRATA_TOPK_OLD=1` runs the original kernel, `STRATA_TOPK_STREAM=0` the register kernel in the 90K-135K band. + ## Linux: verify timeouts while the kernel reclaims host memory (experimental workarounds) A `verify: timed out at layer N` or "no progress for 60 s" message does not by itself mean a kernel or handshake bug. Two