gfx906: K-quant/Q5_1/Q8_0 experts take the CUDA layout; gr_down K-split opt-in; gfx906-aware ctest

- native_expert_grouped: the AMD layouts handle the IQ packs' gate/up and down types only; Unsloth's Q4_K / Q5_K
  gate/up and Q5_1 / Q8_0 down now take the CUDA layout instead of exiting (native_grouped_parity found it).
- fused_gr_read_multi: the K-split gr_down (fixed-order finish) sums in another order than the single-token
  fused_gr_read, so it broke gr_parity's multi == single contract; it is now opt-in (STRATA_GR_SPLIT=1). The
  latency-hidden norm/up (same sums, same order) run in the default read (STRATA_GR_FAST=0: off).
- mmvq_multi_parity: on gfx906 the wave64 MMVQ is the same exact kernel for every column count, so the negative
  control has nothing to find; a second ctest entry runs it on the CUDA layout (STRATA_MMVQ_WAVE=0), where it has
  power.
- kv_hybrid_parity: the tensor-core prompt attention refuses on gfx906 as on the RDNA backend.

ctest on 2x MI50 (gfx906): 34 of 34 pass (iq_parity and ple_parity need fixture files and are not counted).
This commit is contained in:
JeanP00l authored and Niko1221 committed 2026-10-03 23:33:00 +02:00
1 parent 8e8e641245
commit 6b8b54963b
7 files changed
+50 -11

No files matched your search

+4
View File
@@ -608,6 +608,10 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)
target_include_directories(mmvq_multi_parity PRIVATE ${_strata_gpu_include_directories})
target_link_libraries(mmvq_multi_parity PRIVATE strata_kernels ${_strata_gpu_runtime_target})
add_test(NAME mmvq_multi_parity COMMAND mmvq_multi_parity)
if(STRATA_HIP_GFX906) # the CUDA layout, where the negative control has power (the wave64 one is exact at every T)
add_test(NAME mmvq_multi_parity_cuda_layout COMMAND mmvq_multi_parity)
set_tests_properties(mmvq_multi_parity_cuda_layout PROPERTIES ENVIRONMENT "STRATA_MMVQ_WAVE=0")
endif()
endif()
# the IQ kernels that decode a weight part once for every column/entry, bitwise vs the per-column ones
# (GPU, synthetic, no model; --bench adds old/new timings)
+2 -2
View File
@@ -380,11 +380,11 @@ container with `--device=/dev/kfd --device=/dev/dri --group-add video --ipc=host
| | gfx906 | switch |
|---|---|---|
| grouped native experts | mode 7: signs as `dp4a(g ^ m, u) - dp4a(m, u)` (no byte SIMD), grids and activations in LDS, one weight load per group | `STRATA_EXP_MODE=2` (previous AMD layout) |
| grouped native experts | mode 7: signs as `dp4a(g ^ m, u) - dp4a(m, u)` (no byte SIMD), grids and activations in LDS, one weight load per group; the IQ formats only (Unsloth's K-quant / Q5_1 / Q8_0 experts take the CUDA layout) | `STRATA_EXP_MODE=2` (previous AMD layout) |
| MMVQ | one wavefront per row, 64-lane butterfly, no LDS | `STRATA_MMVQ_WAVE=0` |
| router top-10 | one wavefront, register argmax | - |
| `gr_down_multi` | split along K (8 rows x 5 slices of 2048) | `STRATA_GR_SPLIT=0` |
| hyper-connection read | norm loads in flight, 8 lanes per row for `up` | `STRATA_GR_FAST=0` |
| `gr_down_multi`, opt-in | split along K (8 rows x 5 slices of 2048), ~3% per window; sums in another order than the single-token read, so off by default | `STRATA_GR_SPLIT=1` |
| IQ4 table lookup | llama.cpp's `v_perm_b32` sequence (HIP's `__byte_perm` is a scratch array) | - |
| QSA prompt attention | the FP32 kernel (no tensor cores / WMMA) | - |
+23 -4
View File
@@ -763,9 +763,24 @@ int down_chunk(bool staged, int* tile_out) {
// many tokens as fit the card, the up projection; the profile's stamps after the norm and after the down projection.
// kHcPlain is the default read exactly as before (never main's opt-in STRATA_GR_V3 path, which fused_gr_read_multi
// takes first).
#if defined(STRATA_HIP_GFX906)
__global__ void __launch_bounds__(THREADS) gr_norm_fast_kernel(GrMulti m); // below, with the AMD fast path
__global__ void __launch_bounds__(THREADS) gr_up_fast_kernel(GrMulti m);
} // namespace
static bool gr_fast();
namespace {
#endif
void launch_multi(const GrMulti& m, int variant, cudaStream_t st, unsigned long long* stamp_buf, int stamp_i0) {
const int n_tok = m.T;
#if defined(STRATA_HIP_GFX906)
// gfx906: the latency-hidden norm/up (STRATA_GR_FAST=0: off) - the same sums in the same order as the kernels
// they replace (gr_parity checks the multi-token read against single-token calls bitwise)
const bool fast = gr_fast();
#else
const bool fast = false;
#endif
if (variant >= kHcSplit) gr_norm_split_kernel<<<dim3((unsigned) n_tok, HC), THREADS, 0, st>>>(m);
else if (fast) gr_norm_fast_kernel<<<n_tok, THREADS, 0, st>>>(m);
else gr_norm_multi_kernel<<<n_tok, THREADS, 0, st>>>(m);
if (stamp_buf) gpu_stamp(stamp_buf, stamp_i0, (void*) st);
const bool staged = variant >= kHcStaged;
@@ -800,7 +815,8 @@ void launch_multi(const GrMulti& m, int variant, cudaStream_t st, unsigned long
}
}
if (stamp_buf) gpu_stamp(stamp_buf, stamp_i0 + 1, (void*) st);
gr_up_multi_kernel<<<UPM_BLOCKS, THREADS, 0, st>>>(m);
if (fast) gr_up_fast_kernel<<<UPM_BLOCKS, THREADS, 0, st>>>(m);
else gr_up_multi_kernel<<<UPM_BLOCKS, THREADS, 0, st>>>(m);
}
/// STRATA_HC_SPLIT: unset or 2 = the newest the check accepts (staged), 1 = at most split, 0 = the plain read
@@ -1102,9 +1118,12 @@ void fused_gr_read_multi(const FusedGrArgs* a, int n_tok, float* xn_scratch, voi
return;
}
#if defined(STRATA_HIP_GFX906)
// gfx906: the latency-hidden norm/up (STRATA_GR_FAST) and the K-split down (STRATA_GR_SPLIT=0: the CUDA layout's read)
static const bool split_off = std::getenv("STRATA_GR_SPLIT") && std::string(std::getenv("STRATA_GR_SPLIT")) == "0";
if (!split_off) {
// gfx906, opt-in STRATA_GR_SPLIT=1: the latency-hidden norm/up (STRATA_GR_FAST) with the K-split down (~3% faster
// per verify window). Its fixed-order finish sums the K slices in another order than the single-token
// fused_gr_read, so the multi-token read is then no longer bitwise equal to T single-token calls (gr_parity's
// contract); off by default for that reason.
static const bool split_on = std::getenv("STRATA_GR_SPLIT") && std::string(std::getenv("STRATA_GR_SPLIT")) == "1";
if (split_on) {
const bool fast = gr_fast();
if (fast) gr_norm_fast_kernel<<<n_tok, THREADS, 0, st>>>(m);
else gr_norm_multi_kernel<<<n_tok, THREADS, 0, st>>>(m);
+7 -4
View File
@@ -2162,11 +2162,13 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
case T: if (em == 1) native_gu_amd_kernel<T, 1><<<ggu_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); \
else if (em == 4) native_gu_amd_kernel<T, 4><<<ggu_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); \
else native_gu_amd_kernel<T, 2><<<ggu_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, gate, up); break;
if (em == 1 || em == 2 || em == 4) {
// the AMD layouts cover the IQ packs' gate/up types; Unsloth's Q4_K / Q5_K take the CUDA layout below
const bool amd_gu = L.gu_type == 16 || L.gu_type == 17 || L.gu_type == 18 || L.gu_type == 21 || L.gu_type == 22 ||
L.gu_type == 23 || L.gu_type == 29 || L.gu_type == 42;
if ((em == 1 || em == 2 || em == 4) && amd_gu) {
switch (L.gu_type) {
STRATA_GU_AMD(16) STRATA_GU_AMD(17) STRATA_GU_AMD(18) STRATA_GU_AMD(21) STRATA_GU_AMD(22) STRATA_GU_AMD(23)
STRATA_GU_AMD(29) STRATA_GU_AMD(42)
default: std::fprintf(stderr, "native_expert_grouped: gate/up type %d\n", L.gu_type); std::exit(1);
}
} else
#undef STRATA_GU_AMD
@@ -2216,10 +2218,11 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
case T: if (em == 1) native_down_amd_kernel<T, 1><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); \
else if (em == 4) native_down_amd_kernel<T, 4><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); \
else native_down_amd_kernel<T, 2><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
if (em == 1 || em == 2 || em == 4) {
// the AMD layouts cover the IQ packs' down types; the others (Unsloth's Q4_K / Q5_K / Q5_1 / Q8_0) take the
// CUDA layout below
if ((em == 1 || em == 2 || em == 4) && (L.d_type == 20 || L.d_type == 23 || L.d_type == 42)) {
switch (L.d_type) {
STRATA_D_AMD(20) STRATA_D_AMD(23) STRATA_D_AMD(42)
default: std::fprintf(stderr, "native_expert_grouped: down type %d\n", L.d_type); std::exit(1);
}
} else
#undef STRATA_D_AMD
+1 -1
View File
@@ -329,7 +329,7 @@ int main() {
float* d_at4 = dalloc<float>((size_t) QH * D);
const bool took = k::qsa_prompt_attn_batch(d_q, pools, d_ids, d_step, cells, s, d_at4, 1, nullptr);
if (!took) {
#if defined(STRATA_USE_HIP)
#if defined(STRATA_USE_HIP) || defined(STRATA_HIP_GFX906)
// AMD: the tensor-core prompt path is CUDA-only, so it refuses every pool and the old kernel runs
std::printf("[5/5] qsa_prompt_attn mode 3: PASS (refused on HIP - the old kernel runs)\n");
#else
+12
View File
@@ -36,6 +36,8 @@
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <random>
#include <vector>
@@ -236,6 +238,16 @@ int main() {
}
// THE NEGATIVE CONTROL, asserted where it can see something: past T = 4 the generic layout is a different one,
// so if it still finds no difference the comparison cannot tell the layouts apart and the pass proves nothing.
#if defined(STRATA_HIP_GFX906)
// gfx906: the wave64 layout (one wavefront per row) is the same kernel for every column count, so multi_exact
// has nothing to switch and the control cannot see a difference. The control with power is the CUDA layout:
// ctest's mmvq_multi_parity_cuda_layout runs this with STRATA_MMVQ_WAVE=0.
if (off.powerless_cases != 0 && !(std::getenv("STRATA_MMVQ_WAVE") && std::string(std::getenv("STRATA_MMVQ_WAVE")) == "0")) {
std::printf("\nmmvq_multi_parity: ok (gfx906 wave64 layout: every column count runs the same exact kernel, "
"so the negative control has no other layout to find; mmvq_multi_parity_cuda_layout checks it).\n");
return 0;
}
#endif
if (off.powerless_cases != 0) {
std::printf("\nmmvq_multi_parity: FAILED (no power). In %d case(s) no output differs with multi_exact off at "
"any T > %d, where the generic layout is not the exact one: for those cases this comparison "
+1
View File
@@ -3,6 +3,7 @@ expert_profile_save_test expert_profile_save_test
dequant_s2_parity dequant_s2_parity --selftest
s2_gemv_parity s2_gemv_parity --selftest
mmvq_multi_parity mmvq_multi_parity
mmvq_multi_parity_cuda_layout env STRATA_MMVQ_WAVE=0 ./mmvq_multi_parity
iq_multi_parity iq_multi_parity
native_grouped_parity native_grouped_parity
shared_expert_parity shared_expert_parity --selftest