mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 08:18:54 +00:00
decode: 16-warp gate/up and down expert kernels for Qwen4's K-quant / Q8_0 experts (STRATA_GU_NT512)
native_gu_fused_kernel launches (n_ff / 32) x groups = 16 x 8 = 128 blocks of 8 warps for a one-token step (fewer blocks than the card has SMs) and native_down_lds_kernel 32 x 8, so the expert kernels of a decode step run at about 0.7 TB/s of 1.8. Both kernels get a thread-count template parameter NT (default 256 = the existing code, unchanged); NT = 512 spreads the same 64 / 64 weight rows over 16 warps (r0 = p*32 + warp, r1 = r0 + 16 in 2 passes instead of p*16 + warp, +8 in 4 passes). The per-row arithmetic (lane-strided k loop, warp_sum) is untouched, so the results are bit-identical. Launched only for n_embd 2048 and a Q8_0, Q4_K, Q5_K or Q6_K gate/up or down (Qwen4-35B-A3B's Unsloth GGUFs; Flash-Next, Inkling, Ling and every IQ format keep the 256-thread kernels). STRATA_GU_NT512: 1 on, 0 off, unset = on for compute capability 12.0 and 8.9, off elsewhere. Decode, plain --spec 2, 200-token continuation, 5 interleaved pairs ABBA, one engine process per arm, medians (off -> on): RTX 5090 UD-Q4_K_XL 278.0 -> 290.7 (+4.6 %), UD-Q6_K_XL 248.7 -> 269.5 (+8.4 %), 5/5 pairs each; RTX 4090 UD-Q4_K_XL 185.8 -> 189.4 (+1.9 %), UD-Q6_K_XL 161.6 -> 171.4 (+6.1 %); RTX 3090 no gain (159.7 -> 159.9, 148.1 -> 150.3), so it stays off on sm_86. The unset default was checked on the 5090 (271 / 270 / 274 with the switch unset, 252 / 251 / 252 with 0). Prefill is untouched. Identity: the logits dump of all 36 golden probes (5,760 rows x top-256) is sha256-identical between the switch off and on for UD-Q4_K_XL, UD-Q5_K_XL and UD-Q6_K_XL on the 5090 (all experts resident). Partial expert caches (UD-Q8_K_XL, any model on a 24 GB card) are not bit-reproducible run to run even with the adaptive tier off, so there the golden top-1 / KL of off and on sit inside that noise (RTX 5090 UD-Q8_K_XL off 0.98003 / 0.012144 and 0.98090 / 0.012231, on 0.98038 / 0.011435). Shared file: iq_kernels.cu compiled for sm_120 at the default (Flash-Next) geometry and at q4_lite, base tree against this one, per function: 724 / 730 existing functions have identical SASS, none differs; the only additions are the ten 512-thread instantiations (native_gu_fused_kernel<8|10|11|12|13|14, 512>, native_down_lds_kernel<8|12|13|14, 512>), which are not launched for another n_embd. Not compiled on HIP or Windows here. Settings register and docs/SETTINGS.md regenerated with tools/settings_register.py (the register diff is the tool's own refresh).
This commit is contained in:
1 parent
a530abfb24
commit
c0120dde42
3 files changed
+1031
-900
No files matched your search
+12
-11
@@ -490,7 +490,7 @@ Off unless you set them. The last column says where each one is described.
|
||||
| `STRATA_WATCHDOG_S` | text | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
|
||||
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
|
||||
|
||||
## Switches that go back to earlier behaviour (197)
|
||||
## Switches that go back to earlier behaviour (198)
|
||||
|
||||
These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
|
||||
version made it the default.
|
||||
@@ -520,6 +520,7 @@ version made it the default.
|
||||
| `STRATA_GFX12_DEFAULTS` | on / off | NVIDIA and AMD | v0.2.16 | [DETAILS.md](DETAILS.md) |
|
||||
| `STRATA_GFX12_EXP8` | text | AMD | v0.2.20 | - |
|
||||
| `STRATA_GR_V3` | number | NVIDIA and AMD, Intel Arc | v0.2.16 | [DETAILS.md](DETAILS.md), [README.md](bench-results/2026-10-03-community-rx7900xtx-rocm102-nightly/README.md), [README.md](bench-results/2026-10-04-community-rx7900xtx-hipblaslt-100500/README.md) |
|
||||
| `STRATA_GU_NT512` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_HC_Q8_ALL_STAGES` | on / off | NVIDIA and AMD | v0.2.16 | - |
|
||||
| `STRATA_HIPBLASLT` | number | AMD | v0.2.19 | - |
|
||||
| `STRATA_HIP_CPU_SPLIT` | on / off | AMD | v0.2.21 | - |
|
||||
@@ -584,7 +585,7 @@ version made it the default.
|
||||
| `STRATA_INK_SM120_PF` | number | NVIDIA | v0.2.21 | - |
|
||||
| `STRATA_INK_SM120_PFQ` | on / off | NVIDIA | v0.2.23 | - |
|
||||
| `STRATA_INK_SPLIT` | on / off | NVIDIA and AMD | v0.2.21 | - |
|
||||
| `STRATA_INK_TC_ATTN_DEFAULT` | on / off | NVIDIA and AMD | - | [INKLING_SM120.md](INKLING_SM120.md) |
|
||||
| `STRATA_INK_TC_ATTN_DEFAULT` | on / off | NVIDIA and AMD | v0.2.26 | [INKLING_SM120.md](INKLING_SM120.md) |
|
||||
| `STRATA_INK_TIER` | on / off | NVIDIA and AMD | v0.2.21 | - |
|
||||
| `STRATA_INK_VRAM_GUARD` | on / off | NVIDIA and AMD | v0.2.25 | [INKLING_KV.md](INKLING_KV.md) |
|
||||
| `STRATA_IQ_MT_MIN` | on / off | NVIDIA and AMD, CPU | v0.2.16 | [BATCHING.md](BATCHING.md), [DETAILS.md](DETAILS.md), [OLDER_GPUS.md](OLDER_GPUS.md) |
|
||||
@@ -649,15 +650,15 @@ version made it the default.
|
||||
| `STRATA_Q2_WARP` | on / off | NVIDIA and AMD | v0.2.16 | [DETAILS.md](DETAILS.md) |
|
||||
| `STRATA_Q36_CHUNK` | number | NVIDIA and AMD | v0.2.16 | [QWEN36.md](QWEN36.md) |
|
||||
| `STRATA_Q36_KEEP_STAGING` | on / off | NVIDIA and AMD | v0.2.17 | - |
|
||||
| `STRATA_Q4_ATTN_EAGER` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_GRAPH` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_HIP_NO_CHUNK` | on / off | AMD | - | - |
|
||||
| `STRATA_Q4_NOFUSE` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_NO_CHUNK` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_NO_PACK` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_ONE_STREAM` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_OPT` | on / off | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_TC_MIN_N` | number | NVIDIA and AMD | - | - |
|
||||
| `STRATA_Q4_ATTN_EAGER` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_GRAPH` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_HIP_NO_CHUNK` | on / off | AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_NOFUSE` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_NO_CHUNK` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_NO_PACK` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_ONE_STREAM` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_OPT` | on / off | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_Q4_TC_MIN_N` | number | NVIDIA and AMD | v0.2.26 | - |
|
||||
| `STRATA_QFUSE_HC_LOCAL` | text | NVIDIA and AMD | v0.2.16 | - |
|
||||
| `STRATA_QSA_EARLY_EXIT` | number | NVIDIA and AMD, Intel Arc | v0.2.16 | - |
|
||||
| `STRATA_QSA_FUSE_NR` | on / off | NVIDIA and AMD | v0.2.16 | - |
|
||||
|
||||
@@ -6354,14 +6354,16 @@ __global__ void __launch_bounds__(256) native_gu_lds_kernel(const unsigned long
|
||||
|
||||
// ---- 7 (down): the group's q8_1 h rows in LDS, the tokens inside the k loop, the R2 row pairs of mode 2 -
|
||||
// the same per-(row, entry) sums in the same order: bitwise the mode-2 output.
|
||||
template<int TD>
|
||||
__global__ void __launch_bounds__(256) native_down_lds_kernel(const unsigned long long* __restrict__ grp_ptr,
|
||||
template<int TD, int NT = 256> // NT = 512 (STRATA_GU_NT512, n_embd 2048 K-quant / Q8_0 down only): the same rows over 16 warps, bit-identical
|
||||
__global__ void __launch_bounds__(NT) native_down_lds_kernel(const unsigned long long* __restrict__ grp_ptr,
|
||||
const int32_t* __restrict__ grp_start,
|
||||
const int32_t* __restrict__ n_groups,
|
||||
const int32_t* __restrict__ ent_dst,
|
||||
const block_q8_1* __restrict__ hq, NativeExpertLayout L,
|
||||
float* __restrict__ out) {
|
||||
using F = Fmt<TD>;
|
||||
static_assert(NT == 256 || (NT == 512 && (TD == 8 || TD == 12 || TD == 13 || TD == 14)), "native_down_lds_kernel: NT = 512 is for the K-quant and Q8_0 formats");
|
||||
constexpr int kWarps = NT / 32;
|
||||
constexpr bool kStageSplit = (TD == 18 || TD == 21);
|
||||
constexpr int kGridN = (TD == 21) ? 1024 : (TD == 18) ? 512 : 1;
|
||||
__shared__ uint32_t sgrid[kGridN];
|
||||
@@ -6388,14 +6390,14 @@ __global__ void __launch_bounds__(256) native_down_lds_kernel(const unsigned lon
|
||||
constexpr bool kDownSplit = kSplit<TD> || (TD == 7);
|
||||
constexpr bool kCanSub8 = kDownSplit && (TD != 8);
|
||||
constexpr bool kCanSub16 = kSplit<TD> && (TD != 40 && TD != 42 && TD != 20);
|
||||
const bool use_sub8 = kCanSub8 && (n_items == 40 || n_items == 20 || n_items == 24);
|
||||
const bool use_sub16 = kCanSub16 && !use_sub8 && (n_items == 80 || n_items == 16 || n_items == 48);
|
||||
const bool use_sub8 = NT == 256 && kCanSub8 && (n_items == 40 || n_items == 20 || n_items == 24);
|
||||
const bool use_sub16 = NT == 256 && kCanSub16 && !use_sub8 && (n_items == 80 || n_items == 16 || n_items == 48);
|
||||
for (int c0 = e0; c0 < e1; c0 += LDS_NT) {
|
||||
const int cn = min(LDS_NT, e1 - c0);
|
||||
__syncthreads();
|
||||
{
|
||||
const int* src = (const int*) (hq + (size_t) c0 * hb); // the chunk's entries are contiguous
|
||||
for (int i = tid; i < cn * hb * 9; i += 256) sh_raw[i] = src[i];
|
||||
for (int i = tid; i < cn * hb * 9; i += NT) sh_raw[i] = src[i];
|
||||
}
|
||||
__syncthreads();
|
||||
if constexpr (kCanSub8) if (use_sub8) {
|
||||
@@ -6538,8 +6540,8 @@ __global__ void __launch_bounds__(256) native_down_lds_kernel(const unsigned lon
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int p = 0; p < LDS_RB / 16; ++p) {
|
||||
const int r0 = blockIdx.x * LDS_RB + p * 16 + warp, r1 = r0 + 8;
|
||||
for (int p = 0; p < LDS_RB / (2 * kWarps); ++p) {
|
||||
const int r0 = blockIdx.x * LDS_RB + p * (2 * kWarps) + warp, r1 = r0 + kWarps;
|
||||
if (r0 >= nrow) break;
|
||||
const bool two = r1 < nrow;
|
||||
const uint8_t* w0 = blob + L.down_off + (size_t) r0 * L.d_row;
|
||||
@@ -6596,8 +6598,26 @@ __global__ void __launch_bounds__(256) native_down_lds_kernel(const unsigned lon
|
||||
// bitwise the separate kernels' hq, two launches fewer per call.
|
||||
// Hoists Split<TG>::load outside the per-entry loop (j = 0..NTC-1) so multi-token verify hits decode weights ONCE
|
||||
// instead of NTC times, and supports all Unsloth K-quants, Q8_0, IQ*, Q2_0, and NVFP4 with exact tail scales.
|
||||
template<int TG>
|
||||
__global__ void __launch_bounds__(256) native_gu_fused_kernel(const unsigned long long* __restrict__ grp_ptr,
|
||||
// STRATA_GU_NT512: native_gu_fused_kernel and native_down_lds_kernel with 16 warps a block (512 threads) for the K-quant / Q8_0 experts of an n_embd 2048 model (Qwen4-35B-A3B's Unsloth GGUFs):
|
||||
// the same per-row arithmetic, so the logits are bit-identical; 1 = on, 0 = off, unset = on for compute capability 12.0 and 8.9 (decode, interleaved A/B, 5 pairs each, 5/5 faster: RTX 5090 UD-Q4_K_XL +4.6 %,
|
||||
// UD-Q6_K_XL +8.4 %; RTX 4090 +1.9 % / +6.1 %), off elsewhere (the other cards are not measured). Decided per card (the card the calling thread is on).
|
||||
bool gu_nt512() {
|
||||
static const int env = [] { const char* v = std::getenv("STRATA_GU_NT512"); return v == nullptr || v[0] == '\0' ? -1 : (v[0] != '0' ? 1 : 0); }();
|
||||
if (env >= 0) return env == 1;
|
||||
static int per_dev[64]; // 0 unknown, 1 off, 2 on
|
||||
int dev = 0;
|
||||
if (cudaGetDevice(&dev) != cudaSuccess || dev < 0 || dev >= 64) return false;
|
||||
if (!per_dev[dev]) {
|
||||
int major = 0, minor = 0;
|
||||
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
|
||||
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
|
||||
per_dev[dev] = (major == 12 && minor == 0) || (major == 8 && minor == 9) ? 2 : 1;
|
||||
}
|
||||
return per_dev[dev] == 2;
|
||||
}
|
||||
|
||||
template<int TG, int NT = 256> // NT = 512 (STRATA_GU_NT512, n_embd 2048 K-quant / Q8_0 gate-up only): the same rows over 16 warps, bit-identical
|
||||
__global__ void __launch_bounds__(NT) native_gu_fused_kernel(const unsigned long long* __restrict__ grp_ptr,
|
||||
const int32_t* __restrict__ grp_start,
|
||||
const int32_t* __restrict__ n_groups,
|
||||
const int32_t* __restrict__ ent_tok,
|
||||
@@ -6605,6 +6625,8 @@ __global__ void __launch_bounds__(256) native_gu_fused_kernel(const unsigned lon
|
||||
block_q8_1* __restrict__ hq) {
|
||||
using F = Fmt<TG>;
|
||||
constexpr bool kHasGrid = (TG == 16 || TG == 17 || TG == 18 || TG == 21 || TG == 22);
|
||||
static_assert(NT == 256 || (NT == 512 && !kHasGrid && TG != 40), "native_gu_fused_kernel: NT = 512 is for the K-quant and Q8_0 formats");
|
||||
constexpr int kWarps = NT / 32, kPasses = 32 / kWarps;
|
||||
// TG == 18 (IQ3_XXS): 256 grid + 256 sign masks = 512 u32s; TG == 21 (IQ3_S): 512 grid + 512 sign masks = 1024 u32s!
|
||||
constexpr int kGridN = kHasGrid ? (TG == 22 ? 1024 : TG == 21 ? 1024 : (TG == 17 || TG == 18) ? 512 : 256) : 1;
|
||||
using GT = typename std::conditional<(TG == 16 || TG == 17 || TG == 22), uint64_t, uint32_t>::type;
|
||||
@@ -6618,7 +6640,7 @@ __global__ void __launch_bounds__(256) native_gu_fused_kernel(const unsigned lon
|
||||
const int tid = threadIdx.x, lane = tid & 31, warp = tid >> 5;
|
||||
if constexpr (kHasGrid) {
|
||||
const GT* gsrc = GridOf<TG>::src();
|
||||
for (int i = tid; i < GridOf<TG>::N; i += 256) sgrid[i] = gsrc[i];
|
||||
for (int i = tid; i < GridOf<TG>::N; i += NT) sgrid[i] = gsrc[i];
|
||||
if constexpr (TG == 18) {
|
||||
stage_iq3xxs_masks((uint32_t*) sgrid, tid, 256);
|
||||
} else if constexpr (TG == 21) {
|
||||
@@ -6644,10 +6666,10 @@ __global__ void __launch_bounds__(256) native_gu_fused_kernel(const unsigned lon
|
||||
__syncthreads();
|
||||
for (int j = 0; j < cn; ++j) {
|
||||
const int* src = (const int*) (xq + (size_t) ent_tok[c0 + j] * xb);
|
||||
for (int i = tid; i < xb * 9; i += 256) sx_raw[j * xb * 9 + i] = src[i];
|
||||
for (int i = tid; i < xb * 9; i += NT) sx_raw[j * xb * 9 + i] = src[i];
|
||||
}
|
||||
__syncthreads();
|
||||
if (kSplit<TG> && (nb * F::ipb == 80)) {
|
||||
if (NT == 256 && kSplit<TG> && (nb * F::ipb == 80)) {
|
||||
// 16-lane sub-warp dual-row (gate+up pair): 16 pairs/pass x 2 passes = 64 rows, 100% active lanes (0 idle
|
||||
// lanes on k=64..79), halves shared activation reads, bitwise identical addition tree to warp_sum!
|
||||
const int sub = tid >> 4;
|
||||
@@ -6680,8 +6702,8 @@ __global__ void __launch_bounds__(256) native_gu_fused_kernel(const unsigned lon
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int p = 0; p < 4; ++p) {
|
||||
const int i0 = p * 16 + warp, i1 = i0 + 8;
|
||||
for (int p = 0; p < kPasses; ++p) {
|
||||
const int i0 = p * (2 * kWarps) + warp, i1 = i0 + kWarps;
|
||||
const uint8_t* w0 = wrow(i0);
|
||||
const uint8_t* w1 = wrow(i1);
|
||||
auto pass = [&](auto ntc) {
|
||||
@@ -7247,6 +7269,24 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
|
||||
if (fused_gu && g_exp_phase != 2) {
|
||||
const dim3 gl((unsigned) (L.n_ff / 32), (unsigned) cap_groups);
|
||||
const size_t sh = (size_t) LDS_NT * (size_t) (L.n_embd / 32) * sizeof(block_q8_1);
|
||||
const bool nt512 = gu_nt512() && L.n_embd == 2048 && (L.gu_type == 8 || (L.gu_type >= 10 && L.gu_type <= 13)
|
||||
#ifdef STRATA_Q6K_EXPERTS
|
||||
|| L.gu_type == 14
|
||||
#endif
|
||||
); // K-quant / Q8_0 gate-up of Qwen4's width: 16 warps a block (STRATA_GU_NT512=1)
|
||||
if (nt512) {
|
||||
switch (L.gu_type) {
|
||||
case 8: native_gu_fused_kernel<8, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
case 10: native_gu_fused_kernel<10, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
case 11: native_gu_fused_kernel<11, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
case 12: native_gu_fused_kernel<12, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
case 13: native_gu_fused_kernel<13, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
#ifdef STRATA_Q6K_EXPERTS
|
||||
case 14: native_gu_fused_kernel<14, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
} else
|
||||
switch (L.gu_type) {
|
||||
case 8: native_gu_fused_kernel<8><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
case 10: native_gu_fused_kernel<10><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_tok, X, L, hq); break;
|
||||
@@ -7399,6 +7439,21 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
|
||||
if ((em0d == 7 || em0d == 8) && lds_down_ok) {
|
||||
const dim3 gl((unsigned) ((L.n_embd + LDS_RB - 1) / LDS_RB), (unsigned) cap_groups);
|
||||
const size_t sh = (size_t) LDS_NT * (size_t) (L.n_ff / 32) * sizeof(block_q8_1);
|
||||
if (gu_nt512() && L.n_embd == 2048 && (L.d_type == 8 || L.d_type == 12 || L.d_type == 13
|
||||
#ifdef STRATA_Q6K_EXPERTS
|
||||
|| L.d_type == 14
|
||||
#endif
|
||||
)) { // K-quant / Q8_0 down of Qwen4's width: 16 warps a block (STRATA_GU_NT512=1)
|
||||
switch (L.d_type) {
|
||||
case 8: native_down_lds_kernel<8, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
case 12: native_down_lds_kernel<12, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
case 13: native_down_lds_kernel<13, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
#ifdef STRATA_Q6K_EXPERTS
|
||||
case 14: native_down_lds_kernel<14, 512><<<gl, 512, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
} else
|
||||
switch (L.d_type) {
|
||||
case 8: native_down_lds_kernel<8><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
case 12: native_down_lds_kernel<12><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); break;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user