prefill: weight staging for the Q8_0 gate/up and down, the Q6_K gate/up and the Q5_0 down kernels, and the 128-row tile for the Q6_K / Q8_0 gate/up class on sm_86 with 40+ SMs

The staging mechanism of the IQ3_S pack's kernels (cp.async copies of each row's slot into a two-slot shared-memory ring, the product's own loaders on the shared-memory address, three activation stages) now also covers, per instance at compile time (sw_on), 512-thread 128-row, non-F16, CUDA sm_80+: gate/up Q8_0 and Q6_K, down Q8_0 and Q5_0.
- Q8_0 (gate/up and down) and Q5_0 (down): a slot is four 32-value blocks (two stages), 136 B / 88 B, 10 / 7 chunks of the aligned window; the decode is load_unit on the shared-memory address as for IQ4_NL.
- Q6_K gate/up: a slot is half a super-block gathered from three windows (ql 64 B, qh 32 B, scales + d: 10 chunks, 160 B a row in the ring); the 14 words of kq_lean_load<T_Q6_K> are rebuilt from the windows at the same offsets, kq_lean_expand and the arithmetic are unchanged.
Rings at 128 rows: Q8_0 and Q6_K 40,960 B, Q5_0 28,672 B; the largest instance is 96,768 B of shared memory against the 101,376 B a block can get (static_assert per staged instance). The kernels of the previous staging commit (IQ3_XXS / IQ3_S / IQ4_XS gate/up, IQ4_NL down) are byte-identical in device code. Unstaged: Q5_1 down and Q2_0 (staged they lose), Q4_K / Q5_K, IQ2_*, the trellis types, WW 4, NT 256, F16, HIP.

Tile rule (fused_tile_rule.hpp): the staged rule (gate/up staged: 128 rows at every size on sm_86 / sm_120 cards under 80 SMs) now takes the Q8_0 / Q6_K launches too. The "wide" line stays, widened to sm_86 with 40+ SMs: a Q6_K or Q8_0 gate/up above 112 rows an expert takes 128 rows (Why::kS86Wide); below 80 SMs the staged rule already covers it, the line moves the 80+ SM cards. Evidence for the 80+ SM class, from lane P4-Q36 (RTX A6000, Qwen3.6 UD-Q6_K_XL, every expert in VRAM, end to end, ratio to MMQ at 2K / 8K / 20K): today's rule 0.95 / 0.90 / 0.92, tile 128 0.95 / 0.98 / 0.99; no staged-kernel row exists on an 80+ SM card. The i-quant pairs keep the rule gated by lane OWN-4X on that class. Unit cases at 84 SMs on both sides of 112 rows and a sweep of card flags x SM counts x staged x expert counts x rows (the unit test compares wide = false with the previous rule, 20,945,664 combinations, only the line's cells move, 64 -> 128).

Gate, RTX A4000 (sm_86, 48 SMs), one layer, real routing (UD-Q4_K_XL / UD-IQ4_XS ids), ms, tile 128 staged against the same tile unstaged, MMQ beside it (base and head interleaved in one job):
| pair | 2K | 8K | 20K | 32K |
| Q8_0 / Q8_0, MMQ / head | 1.882 | 1.412 | 1.143 | 1.030 |
| same, head against base at 128 rows | +26.0% | +22.2% | +19.4% | +20.2% |
| Q6_K + Q8_0, MMQ / head | 1.499 | 1.188 | 0.998 | 0.918 |
| same, head against base at 128 rows | +24.2% | +22.7% | +20.1% | +22.4% |
| IQ3_S / Q8_0, MMQ / head | 1.708 | 1.379 | 1.211 | 1.060 |
| same, head against base at 128 rows | +11.7% | +11.6% | +13.4% | +14.3% |
| IQ4_XS / Q5_0 (no MMQ tile), head against base at 128 rows | +12.2% | +13.2% | +13.6% | +15.1% |
The unstaged 64-row ratios MMQ / base 64 were Q8_0 / Q8_0 1.326 / 0.955 / 0.783 / 0.649 and Q6_K + Q8_0 1.059 / 0.787 / 0.638 / 0.547. Controls unchanged: IQ3_S / IQ4_NL +5.6 / +8.0 / +9.6 / +11.4% (its kernels are the previous commit's), IQ2_S / Q2_0 0.0 / 0.0 / -0.2 / +0.1%; head 64 against base 64 within 1.3% everywhere.
Output bits: 84 of 84 hashes equal to the previous kernels (Q8_0 / Q8_0, Q6_K + Q8_0, IQ3_S / Q8_0, IQ4_XS / Q5_0, IQ3_S / IQ4_NL, IQ2_S / Q2_0; tile 64 / 128 / default; 2K / 8K / 20K real ids + 32K uniform; blob bases shifted by 2 and 14 bytes). Device code of moe_fused_iq.cu.o (sm_86, 70 functions): against the previous staging commit 4 functions differ (native_kernel<14,true>, <8,true>, <8,false>, <6,false> at 128 rows / 512 threads), against the unstaged base 8, base against base rebuilt 0.
This commit is contained in:
Niko1221 committed 2026-11-12 01:53:20 +01:00
1 parent 9f15c32d76
commit f689435345
3 files changed
+81 -30

No files matched your search

+9 -6
View File
@@ -25,7 +25,7 @@ struct Card {
bool s86 = false; // compute capability 8.6 (appended last: the aggregate initializers {s120, s121, sms} of the callers and the test stay valid)
};
enum class Why { kBand, kS121, kS120Large, kS120Mid, kS120Small, kStaged, kS86Small };
enum class Why { kBand, kS121, kS120Large, kS120Mid, kS120Small, kStaged, kS86Wide };
struct Pick {
int ww; // 2 (128 routed rows) or 4 (64)
@@ -44,11 +44,12 @@ constexpr Pick pick(const Card& c, int64_t n, int n_expert, bool staged = false,
// cell) and +4.3% at 32K in the second pair, with 4K neutral-to-slightly-worse (0.989x, 0.962x, intervals spanning 1.0). So on this part the 128-row tile is taken from
// 65,536 routed rows a launch (about an 11K-token prompt at six experts) up; 4K keeps 64.
if (c.s121) return {n >= 65536 ? 2 : 4, Why::kS121};
// Staged launches (weight staging: a gate/up kernel of IQ3_XXS / IQ3_S / IQ4_XS) on an sm_86 or sm_120 card under 80 SMs: 128 rows from every size. The 128-row staged kernels
// Staged launches (weight staging: a gate/up kernel of IQ3_XXS / IQ3_S / IQ4_XS / Q8_0 / Q6_K) on an sm_86 or sm_120 card under 80 SMs: 128 rows from every size. The 128-row staged kernels
// against the 64-row unstaged ones (RTX A4000, sm_86, 48 SMs, one layer, REAL routing, ms, 2,048 / 8,192 / 20,000 tokens): IQ3_S / IQ4_NL 12.37 / 31.46 / 67.33 against 13.18 / 36.71 / 81.65,
// IQ3_XXS / IQ4_NL 11.72 / 30.04 / 64.44 against 12.07 / 33.97 / 76.16, IQ4_XS / IQ4_NL 11.97 / 30.60 / 65.33 against 13.10 / 36.17 / 80.54, IQ3_S / Q2_0 (the Q2_0 down is not staged)
// 11.89 / 30.48 / 65.19 against 12.27 / 34.35 / 76.42 (RESULTS-P4-SM.md S1). Nothing below 48 SMs is measured, and no sm_120 card under 80 SMs with staging. sm_89 / sm_80 are not in
// the class (no DevInfo flag, not measured); launches without a staged gate/up and every other class keep the rules below.
// the class (no DevInfo flag, not measured); launches without a staged gate/up and every other class keep the rules below. With Q8_0 / Q6_K staged (RTX A4000, one layer, real routing, MMQ / head 128 at 2K / 8K / 20K / 32K):
// Q8_0 / Q8_0 1.882 / 1.412 / 1.143 / 1.030 (64-row unstaged 1.326 / 0.955 / 0.783 / 0.649), Q6_K + Q8_0 1.499 / 1.188 / 0.998 / 0.918 (1.059 / 0.787 / 0.638 / 0.547), IQ3_S / Q8_0 1.708 / 1.379 / 1.211 / 1.060 (1.407 / 1.076 / 0.912 / 0.768).
if (staged && (c.s86 || c.s120) && c.sms > 0 && c.sms < 80) return {2, Why::kStaged};
// sm_120 with 80 SMs and up (the cards that take these kernels by default: RTX 5080 / 5090, PRO 5000 / 6000): 128 rows from 159.9 rows an expert on, the first
// measured point at or above 1.000 on every pair of the PRO 5000 and PRO 6000 rows above. Below it the answer depends on the card (the PRO 6000 loses 3-7% at 80
@@ -62,12 +63,14 @@ constexpr Pick pick(const Card& c, int64_t n, int n_expert, bool staged = false,
// everything else (sm_80 / 86 / 89, sm_120 outside the classes above, HIP builds): 128 rows when an expert has about one such tile (56 to 112 rows on average), else 64.
// Measured on the RTX 5070 with uniform routing (tests/cuda/prefill_fused_iq_test, a layer of 2048 / 3584 / 8192 tokens, ms, 64 -> 128): IQ2_S 5.2 -> 6.7, 9.5 -> 9.3, 17.5 -> 19.5;
// IQ2_XXS 4.2 -> 5.8, 7.4 -> 7.6, 13.6 -> 16.5; IQ3_S 5.6 -> 6.6, 10.2 -> 8.8, 18.4 -> 19.0; IQ3_XXS 5.1 -> 6.3, 9.1 -> 8.3, 16.5 -> 17.5 (256 rows was slower still).
// sm_86 with 40 to 79 SMs, a Q6_K or Q8_0 gate/up (Q6_K + Q8_0, Q8_0 / Q8_0; CUDA opt-ins), above 112 rows an expert: 128 rows. Measured on the RTX A4000 (sm_86, 48 SMs, one layer, ms, tile 64 -> tile 128, output bits
// sm_86 with 40 SMs and up (the 40-79 SM cards and the 80+ SM ones), a Q6_K or Q8_0 gate/up (Q6_K + Q8_0, Q8_0 / Q8_0; CUDA opt-ins), above 112 rows an expert: 128 rows (below 80 SMs the staged rule above already
// takes 128 at every size once these formats are staged; this line is the one that moves the 80+ SM cards). Measured on the RTX A4000 (sm_86, 48 SMs, one layer, ms, tile 64 -> tile 128, output bits
// equal): Qwen3.6's shape (256 experts, top 8; lane P4-Q36, z440-20261111-2126-783b) Q6_K + Q8_0 4,096 / 8,192 / 20,000 tokens 17.65 -> 13.14, 31.91 -> 22.78, 73.46 -> 55.80 (MMQ 13.58 / 20.05 / 38.12);
// Qwen3.8-Flash-Next's shape (512 experts, top 10, real routing, RESULTS-P4-SM.md S0) at 8,192 / 20,000 / 32,768 tokens: Q6_K + Q8_0 64.97 -> 52.56, 142.17 -> 110.45, 241.14 -> 173.50; Q8_0 / Q8_0
// 50.64 -> 42.02, 109.88 -> 89.91, 186.36 -> 140.29. The class is narrow on purpose: the same cards run the 64-row tile faster above 112 rows for the unstaged IQ2_S / Q2_0 pair at 8K (33.80 against 35.05) and
// for Q2_0 / Q2_0 (26.52 against 28.56 at 8K), so the line does not take every pair. Staging these two formats (planned) takes 128 rows at every size through the staged rule above.
if (wide && c.s86 && c.sms >= 40 && c.sms < 80 && avg > 112.0) return {2, Why::kS86Small};
// for Q2_0 / Q2_0 (26.52 against 28.56 at 8K), so the line does not take every pair. On the RTX A6000 (sm_86, 84 SMs; lane P4-Q36, Boston jobs boston-20261111-2158-c9cf / -1d66 / -2209-d899) Qwen3.6 UD-Q6_K_XL with every expert in VRAM, end to end,
// ratio to MMQ at 2K / 8K / 20K: today's tile rule 0.95 / 0.90 / 0.92 (five rounds, spread under 0.02), STRATA_PF_FUSED_TILE=128 0.95 / 0.98 / 0.99 (three rounds). The i-quant pairs keep the rule lane OWN-4X gated on that class.
if (wide && c.s86 && c.sms >= 40 && avg > 112.0) return {2, Why::kS86Wide};
return {avg > 56.0 && avg <= 112.0 ? 2 : 4, Why::kBand};
}
+57 -15
View File
@@ -134,8 +134,9 @@ __host__ __device__ constexpr int grid_bytes(int t) {
// cp.async (a ring of two slots, issued two slots ahead) instead of every decode thread reading it from global memory in 2- and 4-byte loads; the decode
// then runs the same load_unit on the shared-memory address, so the bits are the same. It is chosen per instance at compile time, only where it was measured
// faster (RTX A4000, one layer: +10..+16% for these pairs); every other instance keeps its code and its shared memory unchanged.
// A slot is the bytes of SPB stages (64 values of K each) of a row: a 256-value block for the gate/up i-quants, two stages of 32-value blocks for IQ4_NL. The
// GGUF blocks are only 2-byte aligned, so a slot is copied as the 16-byte chunks of the aligned window around it (SW_CHUNKS of them).
// A slot is the bytes of SPB stages (64 values of K each) of a row: a 256-value block for the gate/up i-quants, two stages of 32-value blocks (four blocks) for IQ4_NL / Q5_0 / Q8_0 on either side,
// and for the Q6_K gate/up half a super-block gathered from three windows (ql, qh, scales + d). The GGUF blocks are only 2-byte aligned, so a slot is copied as the 16-byte chunks of the aligned
// window around it (SW_CHUNKS of them).
constexpr int kSwAst = 3; // the staged instances' activation stages (the ring needs SPB >= AST - 1; 4 stages would not fit the ring beside it)
constexpr size_t kSmemOptIn = 101376; // 99 KB: the opt-in shared memory a block gets on sm_86 / sm_89 / sm_120 / sm_121
__host__ __device__ constexpr bool sw_on(int t, bool gu) {
@@ -143,13 +144,19 @@ __host__ __device__ constexpr bool sw_on(int t, bool gu) {
(void) t; (void) gu;
return false;
#else
return gu ? (t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS) : t == T_IQ4_NL;
return gu ? (t == T_IQ3_XXS || t == T_IQ3_S || t == T_IQ4_XS || t == T_Q8_0 || t == T_Q6_K) : (t == T_IQ4_NL || t == T_Q8_0 || t == T_Q5_0);
#endif
}
__host__ __device__ constexpr bool sw_inst(int t, bool gu, int ww, int nt, bool f16) { return sw_on(t, gu) && ww == 2 && nt == THREADS && !f16; }
__host__ __device__ constexpr int sw_spb(int t, bool gu) { return gu && t != T_IQ4_NL ? 4 : 2; } // stages a slot: a 256-value block (gate/up), two 32-value blocks a stage (IQ4_NL down)
__host__ __device__ constexpr int sw_slot_bytes(int t, bool gu) { return gu ? block_bytes(t) : sw_spb(t, gu) * 2 * block_bytes(t); }
__host__ __device__ constexpr int sw_chunks(int t, bool gu) { return (sw_slot_bytes(t, gu) + 14 + 15) / 16; } // the aligned window: at most slot + 14 bytes
// the 32-value-block formats (two blocks a 64-value stage), gate/up (Q8_0) or down
__host__ __device__ constexpr bool sw_b32(int t) { return t == T_IQ4_NL || t == T_Q5_0 || t == T_Q8_0; }
// the gate/up formats whose block spans 256 values (the kernel's GU256: one block per four stages)
__host__ __device__ constexpr bool sw_gu256(int t, bool gu) { return gu && t != T_Q2_0 && t != T_Q8_0 && !is_tq(t); }
// stages a slot: a whole 256-value block (gate/up i-quants), else two (four 32-value blocks; the Q6_K gate/up: half a super-block)
__host__ __device__ constexpr int sw_spb(int t, bool gu) { return sw_gu256(t, gu) && t != T_Q6_K ? 4 : 2; }
__host__ __device__ constexpr int sw_slot_bytes(int t, bool gu) { return sw_gu256(t, gu) ? block_bytes(t) : sw_spb(t, gu) * 2 * block_bytes(t); } // (Q6_K: unused, its slot is three windows)
// 16-byte chunks of a row's slot: the aligned window is at most slot + 14 bytes; Q6_K: ql 64 B (5) + qh 32 B (3) + scales and d, at most 18 B (2)
__host__ __device__ constexpr int sw_chunks(int t, bool gu) { return t == T_Q6_K ? 10 : (sw_slot_bytes(t, gu) + 14 + 15) / 16; }
constexpr int WLDH = 144; // F16: bytes per decoded weight row of a stage: 64 halves + 16 (ldmatrix rows apart)
// shared memory of an instance. `astages` is the device's depth (host_astages()); a staged instance takes kSwAst instead and adds its ring, sized for ITS side
// (gu) only: a failed shared-memory set-up makes dev_info() drop every fused kernel
@@ -917,21 +924,56 @@ native_kernel(const BatchOf<NT> b, const NativeGeom geo, const Tables tb, const
const int rr = c / SW_NCH, k = c - SW_NCH * rr; // weight row rr of the item (the numbering of ur above)
const uint8_t* rp = GU ? blob + ((rr & 8) ? geo.up_off : 0) + (size_t) (fb * (WR / 2) + 8 * (rr >> 4) + (rr & 7)) * geo.gu_row
: blob + geo.down_off + (size_t) (rbase + rr) * geo.d_row;
const uint8_t* a = rp + (size_t) j * SW_SB;
const uint8_t* cs = (const uint8_t*) ((uintptr_t) a & ~(uintptr_t) 15) + 16 * k;
if (cs < a + SW_SB) cp16(d + rr * SW_ROW + 16 * k, cs);
if constexpr (WT == T_Q6_K) { // slot j = half n of super-block j / 2: three windows, chunks 0-4 ql (64 B), 5-7 qh (32 B), 8-9 scales + d (the bytes up to the end of d)
const uint8_t* bb = rp + (size_t) (j >> 1) * BS;
const int n = j & 1;
const uint8_t *a, *e;
int dk;
if (k < 5) { a = bb + 64 * n; e = a + 64; dk = k; }
else if (k < 8) { a = bb + 128 + 32 * n; e = a + 32; dk = k - 5; }
else { a = bb + 192 + 8 * n; e = bb + 210; dk = k - 8; }
const uint8_t* cs = (const uint8_t*) ((uintptr_t) a & ~(uintptr_t) 15) + 16 * dk;
if (cs < e) cp16(d + rr * SW_ROW + 16 * k, cs);
} else { // (the S1 form, unchanged)
const uint8_t* a = rp + (size_t) j * SW_SB;
const uint8_t* cs = (const uint8_t*) ((uintptr_t) a & ~(uintptr_t) 15) + 16 * k;
if (cs < a + SW_SB) cp16(d + rr * SW_ROW + 16 * k, cs);
}
}
}
};
// (staging) the shared-memory address that stands for unit(s): the same bytes at the same offset inside the window
auto sw_unit = [&](int s) -> const uint8_t* {
static_assert(!SWT || (!KLEAN && (GU256 || !GU)), "staging: the gate/up i-quants' 256-value blocks and the IQ4_NL down's 32-value ones only");
static_assert(!SWT || GU256 || sw_b32(WT), "staging: the gate/up i-quants' 256-value blocks and the 32-value-block formats (IQ4_NL, Q5_0, Q8_0) only");
const int j = s / SW_SPB, si = s - SW_SPB * j;
const uint8_t* p0 = sraw + (j & 1) * (WR * SW_ROW) + ur * SW_ROW + ((uintptr_t) (wrow + (size_t) j * SW_SB) & 15);
if constexpr (GU256) return p0;
else return p0 + (2 * si + uj) * BS; // IQ4_NL down: 32-value blocks, two a stage
else return p0 + (2 * si + uj) * BS; // 32-value blocks (IQ4_NL / Q5_0 / Q8_0, gate/up or down): two a stage
};
// (staging, Q6_K gate/up) kq_lean_load<T_Q6_K>'s 14 words from the three gathered windows: the same bytes at the same offsets inside each window (ql: bb + 64 n + 32 (r & 1) + ..., qh:
// bb + 128 + 32 n + 16 uj + ..., scales / d: bb + 192 + 8 n + 2 r and bb + 208), bb = the slot's super-block
auto sw_q6 = [&](int s, uint32_t (&w)[RAW]) {
if constexpr (SWT && WT == T_Q6_K) {
const int j = s >> 1, n = j & 1, r = sub(s) & 3;
const uint8_t* slot = sraw + (j & 1) * (WR * SW_ROW) + ur * SW_ROW;
const uint8_t* bb = wrow + (size_t) (j >> 1) * BS;
const uint8_t* pa = slot + ((uintptr_t) (bb + 64 * n) & 15);
const uint8_t* pb = slot + 80 + ((uintptr_t) (bb + 128 + 32 * n) & 15);
const uint8_t* pq = slot + 128 + ((uintptr_t) (bb + 192 + 8 * n) & 15);
#pragma unroll
for (int k = 0; k < 8; ++k) w[k] = ld32(pa + 32 * (r & 1) + 4 * k);
#pragma unroll
for (int k = 0; k < 4; ++k) w[8 + k] = ld32(pb + 16 * uj + 4 * k);
w[12] = ld16(pq + 16 - 8 * n) | (ld16(pq + 2 * r) << 16);
w[13] = (uint32_t) r;
}
};
auto load_sw = [&](int s, uint32_t (&w)[RAW]) {
if constexpr (SWT) {
if constexpr (WT == T_Q6_K) sw_q6(s, w);
else load_unit<WT>(sw_unit(s), sub(s), w);
}
};
auto load_sw = [&](int s, uint32_t (&w)[RAW]) { if constexpr (SWT) load_unit<WT>(sw_unit(s), sub(s), w); };
// the weight bytes into L2 ahead of the register loads (one stage ahead only - less than a DRAM round trip):
// gate/up PF super-blocks ahead (the row's two threads take a block's first and last line), down the whole row
// slice at once (180 or 360 bytes a row)
@@ -2494,7 +2536,7 @@ void check_staged_blobs(const Batch& b, const NativeGeom& g) {
}
#endif
// `staged`: the launch's gate/up kernel is a weight-staging instance (sw_on); the rule then takes 128 rows from every size on the sm_86 / sm_120 cards under 80 SMs.
// `wide`: the launch's gate/up is Q6_K or Q8_0: on sm_86 cards with 40-79 SMs the rule takes 128 rows above 112 rows an expert (fused_tile_rule.hpp).
// `wide`: the launch's gate/up is Q6_K or Q8_0: on sm_86 cards with 40+ SMs the rule takes 128 rows above 112 rows an expert (fused_tile_rule.hpp).
int pick_ww(int64_t n, int n_expert, bool staged, bool wide) {
static const int forced = [] {
const char* v = std::getenv("STRATA_PF_FUSED_TILE");
@@ -2511,7 +2553,7 @@ int pick_ww(int64_t n, int n_expert, bool staged, bool wide) {
static const bool dbg = [] { const char* v = std::getenv("STRATA_PF_TILE_DEBUG"); return v != nullptr && v[0] == '1'; }();
if (dbg) {
const double avg = (double) n / std::max(n_expert, 1);
const char* cls = pk.why == Why::kS121 ? "s121" : pk.why == Why::kS120Small ? "s120 small" : pk.why == Why::kStaged ? "staged" : pk.why == Why::kS86Small ? "s86 small" : "s120";
const char* cls = pk.why == Why::kS121 ? "s121" : pk.why == Why::kS120Small ? "s120 small" : pk.why == Why::kStaged ? "staged" : pk.why == Why::kS86Wide ? "s86 wide" : "s120";
std::fprintf(stderr, "strata: fused tile: rows %lld experts %d avg %.1f %s yes -> ww %d\n", (long long) n, n_expert, avg, cls, pk.ww);
}
}
@@ -2768,7 +2810,7 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n
}
// the launch's gate/up kernel is a staging instance: the tile rule then takes 128 rows (the gate/up is about two thirds of the layer; a down that is not staged, Q2_0 or Q8_0 or Q5_0,
// still ran faster in the 128-row tile with it: IQ3_S / Q2_0 on the RTX A4000, RESULTS-P4-SM.md S1). Either kernel staged: the blob check.
const bool staged = sw_on(g.gu_type, true), wide = g.gu_type == T_Q6_K || g.gu_type == T_Q8_0; // wide: the Q6_K / Q8_0 gate/up class of the sm_86 40-79 SM tile line
const bool staged = sw_on(g.gu_type, true), wide = g.gu_type == T_Q6_K || g.gu_type == T_Q8_0; // wide: the Q6_K / Q8_0 gate/up class of the sm_86 tile line (40+ SMs)
#if !defined(__HIPCC__)
if (staged || sw_on(g.d_type, false)) check_staged_blobs(b, g);
#endif
+15 -9
View File
@@ -100,22 +100,28 @@ int main() {
CHECK(pick(a4000s, 81910, E, false).ww == 4 && pick(a4000s, 81910, E, true).ww == 2);
CHECK(pick(a4000s, 40960, E, false).ww == 2 && pick(a4000s, 20000, E, false).ww == 4 && pick(a4000s, 20000, E, true).ww == 2); // band: 80 rows 128, 39 rows 64
}
// ---- the Q6_K / Q8_0 gate/up class (wide) on sm_86 cards with 40-79 SMs: 128 rows above 112 rows an expert, everything else as it was
// ---- the Q6_K / Q8_0 gate/up class (wide) on sm_86 cards with 40+ SMs (the 40-79 SM cards and the 80+ SM ones such as the A6000): 128 rows above 112 rows an expert, everything else as it was
{
const Card a4000w{false, false, 48, true}, s86at39{false, false, 39, true}, s86at40{false, false, 40, true}, s86at79{false, false, 79, true}, s86at80{false, false, 80, true},
s120at48{true, false, 48, false}, s89{false, false, 60, false};
CHECK(pick(a4000w, 57344, E, false, true).ww == 2 && pick(a4000w, 57344, E, false, true).why == Why::kBand); // 112.0 rows an expert: the old band's top, 128 as before
CHECK(pick(a4000w, 57345, E, false, true).ww == 2 && pick(a4000w, 57345, E, false, true).why == Why::kS86Small); // 112.002: the line
CHECK(pick(a4000w, 57345, E, false, true).ww == 2 && pick(a4000w, 57345, E, false, true).why == Why::kS86Wide); // 112.002: the line
CHECK(pick(a4000w, 57345, E, false, false).ww == 4 && pick(a4000w, 57345, E, false, false).why == Why::kBand); // not the class: 64 as before
CHECK(pick(a4000w, 81910, E, false, true).ww == 2 && pick(a4000w, 320000, E, false, true).ww == 2);
CHECK(pick(a4000w, 28672, E, false, true).ww == 4 && pick(a4000w, 28673, E, false, true).ww == 2); // below 112: the band, unchanged
// the same count of rows on Qwen3.6's 256 experts: 4,096 tokens x 8 = 32,768 rows = 128 an expert (the line), 2,048 tokens = 64 an expert (the band)
CHECK(pick(a4000w, 32768, 256, false, true).ww == 2 && pick(a4000w, 32768, 256, false, true).why == Why::kS86Small && pick(a4000w, 16384, 256, false, true).why == Why::kBand);
// the class edges: 39 SMs and 80 SMs keep the old rule, 40 and 79 take the line; other cards (sm_120, sm_89 / sm_80) never do
CHECK(pick(s86at39, 81910, E, false, true).ww == 4 && pick(s86at80, 81910, E, false, true).ww == 4);
CHECK(pick(s86at40, 81910, E, false, true).ww == 2 && pick(s86at79, 81910, E, false, true).ww == 2);
CHECK(pick(a4000w, 32768, 256, false, true).ww == 2 && pick(a4000w, 32768, 256, false, true).why == Why::kS86Wide && pick(a4000w, 16384, 256, false, true).why == Why::kBand);
// the class edges: 39 SMs keeps the old rule, 40 / 79 / 80 take the line; other cards (sm_120, sm_89 / sm_80) never do
CHECK(pick(s86at39, 81910, E, false, true).ww == 4);
CHECK(pick(s86at40, 81910, E, false, true).ww == 2 && pick(s86at79, 81910, E, false, true).ww == 2 && pick(s86at80, 81910, E, false, true).ww == 2);
// the RTX A6000 (sm_86, 84 SMs): both sides of 112 rows an expert, and the i-quant pairs (not wide) keep the rule OWN-4X gated (64 rows above the band)
const Card a6000w{false, false, 84, true};
CHECK(pick(a6000w, 57344, E, false, true).ww == 2 && pick(a6000w, 57344, E, false, true).why == Why::kBand);
CHECK(pick(a6000w, 57345, E, false, true).ww == 2 && pick(a6000w, 57345, E, false, true).why == Why::kS86Wide);
CHECK(pick(a6000w, 57345, E, false, false).ww == 4 && pick(a6000w, 81910, E, false, false).ww == 4 && pick(a6000w, 81910, E, false, true).ww == 2 && pick(a6000w, 320000, E, false, true).ww == 2);
CHECK(pick(a6000w, 32768, 256, false, true).why == Why::kS86Wide && pick(a6000w, 16384, 256, false, true).why == Why::kBand && pick(a6000w, 16384, 256, false, true).ww == 2); // Qwen3.6: 4K tokens 128 an expert, 2K tokens 64
CHECK(pick(s120at48, 40960, E, false, true).why == pick(s120at48, 40960, E, false, false).why && pick(s89, 81910, E, false, true).ww == 4);
// wide = false is the rule of the previous commit for every class; wide = true moves only sm_86 with 40-79 SMs above 112 rows an expert, and only from 64 to 128
// wide = false is the rule of the previous commit for every class; wide = true moves only sm_86 with 40+ SMs above 112 rows an expert, and only from 64 to 128
long long cmpw = 0, badw = 0;
for (int s120 = 0; s120 < 2; ++s120)
for (int s121 = 0; s121 < 2; ++s121)
@@ -129,8 +135,8 @@ int main() {
++cmpw;
const double avg = (double) n / (ne > 1 ? ne : 1);
const bool line = !s121 && !(staged && (s86 || s120) && sms > 0 && sms < 80) && !(s120 && sms >= 40 && sms < 80) && !(s120 && sms >= 80 && (avg >= 159.9 || (sms >= 100 && sms < 150 && avg > 112.0))) &&
s86 && sms >= 40 && sms < 80 && avg > 112.0;
if (line ? !(b.ww == 2 && b.why == Why::kS86Small) : (a.ww != b.ww || a.why != b.why)) ++badw;
s86 && sms >= 40 && avg > 112.0;
if (line ? !(b.ww == 2 && b.why == Why::kS86Wide) : (a.ww != b.ww || a.why != b.why)) ++badw;
}
CHECK(badw == 0);
std::printf("fused_tile_rule_test: wide class: %lld card / launch combinations checked (%lld wrong)\n", cmpw, badw);