From e6a06be558b9789dae9967c4d910b6035627019e Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 1 Oct 2026 13:06:56 +0200 Subject: [PATCH] HIP (S6): STRATA_HIP_WMMA=1 also takes a 96-slot prompt expert ring (9070 XT 4K prompts 718 -> 1,211 tok/s with it); docs/AMD_HIP.md: the router and WMMA switches, with credit to PR #329's equal-speed kernel --- docs/AMD_HIP.md | 13 +++++++++++++ src/prefill/prefill.cpp | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index 39a47002..767b1bdd 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -176,6 +176,19 @@ an RX 9070 XT 16 GB and a Radeon AI PRO R9700 32 GB (both gfx1201), a Ryzen 9 39 starts. `"split_skip_if_fits": true` in the config (0.1.31, opt-in) runs such a pair on the first card alone when it holds every profiled expert: with the R9700 first, 4K prompts 1,776 tok/s (split: 1,244) and decode ~60 tok/s (split: ~51), the tokens of the R9700 alone (docs/MULTI_GPU.md). +- **Speed switches (engine 0.1.32, measured on the R9700 / 9070 XT with the Coder IQ1_M pack):** + - the MoE router (`router_top10`) runs a HIP kernel without its serial FP64 sum and block barriers by default: the + same ids and weights bit for bit (`hip_router_fast` checks 65,536 rows), 39 -> 9-12 us per call, decode + 62.4 -> 70.0 tok/s on the R9700 and +4% on the 9070 XT, the same greedy tokens (5 + 5 starts). + `STRATA_HIP_ROUTER_OLD=1` runs the portable kernel. + - `STRATA_HIP_WMMA=1` (opt-in, gfx12 only, int8 KV): the prompt path's QSA attention on RDNA4 matrix cores + (`v_wmma_f32_16x16x16_f16`, FP16 hi + lo halves like the CUDA tensor-core kernel; `hip_prompt_attn_wmma` bounds it + against the FP32 kernel and FP64). 7.2-7.5x the portable kernel; R9700 prompts 4K 1,784 -> 2,427 tok/s, 16K + 1,797 -> 2,700. Not bitwise: greedy text differs from token ~50 on, as with the CUDA tensor-core attention. With it + the prompt path's expert ring is 96 slots (as STRATA_PREFILL_RING=96): with the default 384 the 9070 XT's 4K + prompts fell to 718 tok/s; with 96 they gain (1,017 -> 1,211; 16K 1,518 -> 2,032). PR #329 + (bsorensen110) contributed an equivalent gfx12 WMMA kernel of the same speed (within 1%); this one also masks KV + pages that KV streaming has not made resident, as the decode kernel does. - **Known:** rarely (about 1 start in 10) a HIP run's greedy output differs from another start's at some token, on one card or two and on engine 0.1.29 as well; not yet explained. - **Not validated:** images, long contexts beyond 16K, answer-quality benchmarks. diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 278f92e6..72a1b88d 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -89,6 +89,15 @@ double g_pinned_share = 1.0; int g_ring_override = 0; // #340: set by a layer split (Prefill::set_ring_override); 0 = the rule below inline int ring_slots(size_t T) { const char* v = std::getenv("STRATA_PREFILL_RING"); +#if defined(STRATA_USE_HIP) + // S6: with the opt-in RDNA4 matrix-core attention (STRATA_HIP_WMMA=1) a 96-slot ring: measured with it, 9070 XT + // 4K prompts 718 -> 1,211 tok/s (16K 1,949 -> 2,032), R9700 4K 2,426 -> 2,483 (16K the same) + static const bool wmma = [] { + const char* e = std::getenv("STRATA_HIP_WMMA"); + return e != nullptr && e[0] == '1'; + }(); + if (!v && g_ring_override <= 0 && wmma) return (int64_t) T >= stream_all_min() ? 96 : STAGE; +#endif const int r = v ? std::atoi(v) : g_ring_override > 0 ? g_ring_override : (g_pinned_share >= 0.9 ? 384 : 96); if (v && r == STAGE) return STAGE; // Explicit opt-in to routed-only staging, including large chunks. const int big = r < 16 ? 16 : r > RING_MAX ? RING_MAX : r;