okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-027-gh-eng: GitHub engine items for 0.2.76ca60e9a0

main
20.4 KiB443 linesraw
1// src/kernels/tq_pascal_bench.cpp - the Gyro trellis decode kernels (TQ2_T 144, TQK6 145, TQK7 146 and Gyro-L's TQP5-7 147-149) on synthetic blocks.
2//
3//     build/tq_pascal_bench            checks: the decode-once kernels against the per-column ones (bitwise), and a
4//                                      checksum of every output, so two builds can be compared byte for byte
5//     build/tq_pascal_bench --bench    the checks, then microseconds per call
6//
7// Random bytes are valid trellis codes (any 15-bit state indexes the codebook); only the fp16 block scales are set,
8// small enough that the grouped path's SwiGLU output keeps a finite fp16 q8_1 scale.  No model, needs the GPU.
9// The checksum lines ("SUM ...") are what two builds are compared by: same lines, same bits.
10#include "strata/kernels/f16_bits.hpp"
11#include "strata/kernels/iq_kernels.hpp"
12#include "strata/kernels/native_mmvq.hpp"
13
14#include "ggml-common-tq.h"   // tq_lut_f16: the codebook, as host data
15
16#include <cuda_runtime.h>
17
18#include <algorithm>
19#include <cmath>
20#include <cstdint>
21#include <cstdio>
22#include <cstdlib>
23#include <cstring>
24#include <numeric>
25#include <random>
26#include <string>
27#include <vector>
28
29namespace k = strata::kernels;
30
31namespace {
32
33int g_fail = 0;
34
35void ck(cudaError_t e, const char* w) {
36    if (e != cudaSuccess) {
37        std::fprintf(stderr, "CUDA error in %s: %s\n", w, cudaGetErrorString(e));
38        std::exit(2);
39    }
40}
41
42template<typename T>
43T* dalloc(size_t n) {
44    T* p = nullptr;
45    ck(cudaMalloc(&p, n * sizeof(T) + 256), "malloc");
46    ck(cudaMemset(p, 0, n * sizeof(T) + 256), "memset");
47    return p;
48}
49
50const char* name_of(int t) {
51    return t == 144 ? "TQ2_T" : t == 145 ? "TQK6" : t == 146 ? "TQK7" : t == 147 ? "TQP5" : t == 148 ? "TQP6" : t == 149 ? "TQP7"
52         : t == 42 ? "Q2_0" : "?";
53}
54
55uint64_t fnv(const void* p, size_t n, uint64_t h = 1469598103934665603ull) {
56    const uint8_t* b = (const uint8_t*) p;
57    for (size_t i = 0; i < n; ++i) h = (h ^ b[i]) * 1099511628211ull;
58    return h;
59}
60
61std::vector<uint8_t> random_rows(int t, int64_t rows, int64_t n, std::mt19937& rng) {
62    const int bv = t == 42 ? 64 : 128;
63    const size_t rb = k::iq_row_bytes(t, n), bs = k::iq_row_bytes(t, bv);
64    std::vector<uint8_t> w((size_t) rows * rb);
65    std::uniform_int_distribution<int> byte(0, 255), ex(2, 8), man(0, 1023), sgn(0, 3);
66    for (auto& b : w) b = (uint8_t) byte(rng);
67    for (size_t o = 0; o < w.size(); o += bs) {
68        const uint16_t h = (uint16_t) ((sgn(rng) == 0 ? 0x8000 : 0) | (ex(rng) << 10) | man(rng));   // 2^-13 .. 2^-6
69        std::memcpy(&w[o], &h, 2);
70    }
71    return w;
72}
73
74std::vector<float> random_x(size_t n, std::mt19937& rng) {
75    std::normal_distribution<float> nd(0.f, 1.f);
76    std::vector<float> x(n);
77    for (auto& v : x) v = nd(rng);
78    return x;
79}
80
81void check_mmvq(int t, int n_in, int n_out, cudaStream_t s, std::mt19937& rng) {
82    const auto w = random_rows(t, n_out, n_in, rng);
83    uint8_t* dw = dalloc<uint8_t>(w.size());
84    ck(cudaMemcpy(dw, w.data(), w.size(), cudaMemcpyHostToDevice), "w");
85    const int max_cols = 8;
86    const auto x = random_x((size_t) max_cols * n_in, rng);
87    float* dx = dalloc<float>(x.size());
88    ck(cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice), "x");
89    uint8_t* dxq = dalloc<uint8_t>((size_t) max_cols * (n_in / 32) * 36);
90    k::quantize_q8_1_rows(dx, max_cols, n_in, dxq, s);
91    float* dy_old = dalloc<float>((size_t) max_cols * n_out);
92    float* dy_new = dalloc<float>((size_t) max_cols * n_out);
93    std::vector<float> y_old((size_t) max_cols * n_out), y_new(y_old.size());
94    uint64_t sum = 1469598103934665603ull;
95    int bad = 0;
96    for (int nc = 1; nc <= max_cols; ++nc) {
97        ck(cudaMemset(dy_old, 0xFF, y_old.size() * 4), "memset");
98        ck(cudaMemset(dy_new, 0xFF, y_new.size() * 4), "memset");
99        k::iq_set_old_kernels(true);
100        k::iq_mmvq(t, dw, dxq, dy_old, n_in, n_out, nc, s);
101        k::iq_set_old_kernels(false);
102        k::iq_mmvq(t, dw, dxq, dy_new, n_in, n_out, nc, s);
103        ck(cudaStreamSynchronize(s), "sync");
104        ck(cudaMemcpy(y_old.data(), dy_old, y_old.size() * 4, cudaMemcpyDeviceToHost), "y_old");
105        ck(cudaMemcpy(y_new.data(), dy_new, y_new.size() * 4, cudaMemcpyDeviceToHost), "y_new");
106        size_t diff = 0;
107        bool finite = true;
108        for (size_t i = 0; i < (size_t) nc * n_out; ++i) {
109            diff += std::memcmp(&y_old[i], &y_new[i], 4) != 0;
110            finite = finite && std::isfinite(y_new[i]);
111        }
112        if (diff || !finite) { std::printf("  %s mmvq nc %d: %zu differ%s FAIL\n", name_of(t), nc, diff, finite ? "" : ", non-finite"); ++bad; }
113        sum = fnv(y_new.data(), (size_t) nc * n_out * 4, sum);
114    }
115    std::printf("SUM mmvq %-6s %5d x %5d  %016llx  %s\n", name_of(t), n_out, n_in, (unsigned long long) sum,
116                bad ? "FAIL" : "decode-once == per-column");
117    g_fail += bad;
118    cudaFree(dw); cudaFree(dx); cudaFree(dxq); cudaFree(dy_old); cudaFree(dy_new);
119}
120
121struct Grouped {
122    k::NativeExpertLayout L;
123    int n_groups = 0, n_ent = 0, cap_groups = 0, cap_ent = 0, n_tok = 0;
124    std::vector<uint8_t*> blobs;
125    unsigned long long* dptr = nullptr;
126    int32_t *dstart = nullptr, *dn = nullptr, *ddst = nullptr, *dtok = nullptr;
127    float* dx = nullptr;
128    uint8_t *dxq = nullptr, *dscr = nullptr;
129    float* dout = nullptr;
130    size_t out_floats = 0;
131
132    Grouped(int gu, int dt, int64_t H, int64_t FF, const std::vector<int>& counts, int tokens, std::mt19937& rng) {
133        L = k::native_expert_layout(gu, dt, H, FF);
134        n_groups = (int) counts.size();
135        cap_groups = n_groups + 2;
136        n_tok = tokens;
137        std::vector<int32_t> start(1, 0), tok, dst;
138        for (int c : counts) start.push_back(start.back() + c);
139        n_ent = start.back();
140        cap_ent = n_ent + 3;
141        std::uniform_int_distribution<int> tk(0, tokens - 1);
142        for (int e = 0; e < n_ent; ++e) tok.push_back(tk(rng));
143        dst.resize(n_ent);
144        std::iota(dst.begin(), dst.end(), 0);
145        std::shuffle(dst.begin(), dst.end(), rng);
146        std::vector<unsigned long long> ptr;
147        for (int g = 0; g < n_groups; ++g) {
148            auto b = random_rows(gu, 2 * FF, H, rng);
149            const auto d = random_rows(dt, H, FF, rng);
150            b.insert(b.end(), d.begin(), d.end());
151            if (b.size() != L.bytes) { std::fprintf(stderr, "blob size %zu != %zu\n", b.size(), L.bytes); std::exit(2); }
152            uint8_t* db = dalloc<uint8_t>(b.size());
153            ck(cudaMemcpy(db, b.data(), b.size(), cudaMemcpyHostToDevice), "blob");
154            blobs.push_back(db);
155            ptr.push_back((unsigned long long) db);
156        }
157        dptr = dalloc<unsigned long long>(cap_groups);
158        dstart = dalloc<int32_t>(cap_groups + 1);
159        dn = dalloc<int32_t>(1);
160        ddst = dalloc<int32_t>(cap_ent);
161        dtok = dalloc<int32_t>(cap_ent);
162        ck(cudaMemcpy(dptr, ptr.data(), ptr.size() * 8, cudaMemcpyHostToDevice), "ptr");
163        ck(cudaMemcpy(dstart, start.data(), start.size() * 4, cudaMemcpyHostToDevice), "start");
164        ck(cudaMemcpy(dn, &n_groups, 4, cudaMemcpyHostToDevice), "n");
165        if (n_ent) {
166            ck(cudaMemcpy(ddst, dst.data(), dst.size() * 4, cudaMemcpyHostToDevice), "dst");
167            ck(cudaMemcpy(dtok, tok.data(), tok.size() * 4, cudaMemcpyHostToDevice), "tok");
168        }
169        const auto x = random_x((size_t) tokens * H, rng);
170        dx = dalloc<float>(x.size());
171        ck(cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice), "x");
172        dxq = dalloc<uint8_t>((size_t) tokens * (H / 32) * 36);
173        dscr = dalloc<uint8_t>(k::native_expert_scratch_bytes(cap_ent, FF));
174        out_floats = (size_t) cap_ent * H;
175        dout = dalloc<float>(out_floats);
176    }
177    ~Grouped() {
178        for (auto* b : blobs) cudaFree(b);
179        cudaFree(dptr); cudaFree(dstart); cudaFree(dn); cudaFree(ddst); cudaFree(dtok);
180        cudaFree(dx); cudaFree(dxq); cudaFree(dscr); cudaFree(dout);
181    }
182    void run(bool old, cudaStream_t s) {
183        k::iq_set_old_kernels(old);
184        k::quantize_q8_1_rows(dx, n_tok, L.n_embd, dxq, s);
185        k::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, cap_groups, cap_ent, dxq, dscr, dout, s);
186        k::iq_set_old_kernels(false);
187    }
188    std::vector<float> result(bool old, cudaStream_t s) {
189        ck(cudaMemset(dout, 0xFF, out_floats * 4), "memset");
190        ck(cudaMemset(dscr, 0, k::native_expert_scratch_bytes(cap_ent, L.n_ff)), "memset");
191        run(old, s);
192        ck(cudaStreamSynchronize(s), "sync");
193        std::vector<float> o(out_floats);
194        ck(cudaMemcpy(o.data(), dout, o.size() * 4, cudaMemcpyDeviceToHost), "out");
195        return o;
196    }
197};
198
199void check_grouped(int gu, int dt, int64_t H, int64_t FF, cudaStream_t s, std::mt19937& rng) {
200    Grouped G(gu, dt, H, FF, {1, 3, 4, 5, 0, 8, 2, 11, 1}, 8, rng);
201    const auto a = G.result(true, s), b = G.result(false, s);
202    size_t diff = 0;
203    bool finite = true;
204    for (size_t i = 0; i < a.size(); ++i) {
205        diff += std::memcmp(&a[i], &b[i], 4) != 0;
206        if (i < (size_t) G.n_ent * H) finite = finite && std::isfinite(b[i]);
207    }
208    const bool ok = diff == 0 && finite;
209    std::printf("SUM grouped %-6s/%-6s %5lld x %4lld  %016llx  %s\n", name_of(gu), name_of(dt), (long long) H, (long long) FF,
210                (unsigned long long) fnv(b.data(), b.size() * 4), ok ? "decode-once == per-column" : "FAIL");
211    if (!ok) { std::printf("  %zu of %zu floats differ%s\n", diff, a.size(), finite ? "" : ", non-finite outputs"); ++g_fail; }
212}
213
214// ---- Gyro-L pair trellis (TQP5/6/7, ggml 147-149) against a reference written from the format definition (no ggml):
215// state t of a block = the 16 stream bits that start at bit (63 - t) * K, LSB first, circular over 64 * K bits (15 bits
216// are used); the step's two weights are the first pair of the state's codebook entry, times the block's fp16 scale.
217uint32_t tqp_ref_state(const uint8_t* qs, int K, int t) {
218    const int nbits = 64 * K;
219    uint32_t s = 0;
220    for (int b = 0; b < 16; ++b) {
221        const int pos = ((63 - t) * K + b) % nbits;
222        s |= (uint32_t) ((qs[pos >> 3] >> (pos & 7)) & 1) << b;
223    }
224    return s & 0x7FFFu;
225}
226
227float half_to_f(uint16_t h) {   // normal and subnormal fp16 (no inf / nan in these tests)
228    const int e = (h >> 10) & 31, m = h & 1023;
229    const float v = e == 0 ? std::ldexp((float) m, -24) : std::ldexp((float) (1024 + m), e - 25);
230    return (h & 0x8000) ? -v : v;
231}
232
233uint16_t f_to_half_rn(float f) {   // round to nearest even, the GPU's __float2half_rn
234    uint32_t x;
235    std::memcpy(&x, &f, 4);
236    const uint32_t sign = (x >> 16) & 0x8000u;
237    const int e = (int) ((x >> 23) & 0xFF) - 127 + 15;
238    uint32_t m = x & 0x7FFFFFu;
239    if (e >= 31) return (uint16_t) (sign | 0x7C00u);
240    if (e <= 0) {
241        if (e < -10) return (uint16_t) sign;
242        m |= 0x800000u;
243        const int shift = 14 - e;
244        uint32_t half = m >> shift;
245        const uint32_t rem = m & ((1u << shift) - 1), mid = 1u << (shift - 1);
246        if (rem > mid || (rem == mid && (half & 1u))) ++half;
247        return (uint16_t) (sign | half);
248    }
249    uint32_t half = ((uint32_t) e << 10) | (m >> 13);
250    const uint32_t rem = m & 0x1FFFu;
251    if (rem > 0x1000u || (rem == 0x1000u && (half & 1u))) ++half;
252    return (uint16_t) (sign | half);
253}
254
255// the weights of `rows` rows of `n` values, as floats (d * codebook, unrounded)
256std::vector<float> tqp_ref_weights(int t, const std::vector<uint8_t>& w, int64_t rows, int64_t n) {
257    const int K = t - 142;   // 147 -> 5, 148 -> 6, 149 -> 7
258    const size_t bs = k::iq_row_bytes(t, 128);
259    std::vector<float> out((size_t) (rows * n));
260    for (size_t b = 0; b < (size_t) (rows * n / 128); ++b) {
261        const uint8_t* blk = &w[b * bs];
262        uint16_t hd;
263        std::memcpy(&hd, blk, 2);
264        const float d = half_to_f(hd);
265        for (int step = 0; step < 64; ++step) {
266            const uint32_t s = tqp_ref_state(blk + 2, K, step);
267            const uint32_t x = (s & 0x7FFFu) * 0x9e3779b1u;
268            const uint32_t pt = x >> 21;
269            out[b * 128 + 2 * step + 0] = d * half_to_f(tq_lut_f16[2 * pt + 0]);
270            out[b * 128 + 2 * step + 1] = d * half_to_f(tq_lut_f16[2 * pt + 1]);
271        }
272    }
273    return out;
274}
275
276void check_tqp_reference(int t, int n_in, int n_out, cudaStream_t s, std::mt19937& rng) {
277    const auto w = random_rows(t, n_out, n_in, rng);
278    const auto ref = tqp_ref_weights(t, w, n_out, n_in);
279    uint8_t* dw = dalloc<uint8_t>(w.size());
280    ck(cudaMemcpy(dw, w.data(), w.size(), cudaMemcpyHostToDevice), "w");
281    // (1) the prompt path's fp16 dequantizer: bit for bit the fp16 of the reference weights
282    const int64_t nv = (int64_t) n_out * n_in;
283    uint16_t* dh = dalloc<uint16_t>((size_t) nv);
284    k::iq_dequant_f16(t, dw, nv, dh, s);
285    ck(cudaStreamSynchronize(s), "sync");
286    std::vector<uint16_t> h((size_t) nv);
287    ck(cudaMemcpy(h.data(), dh, h.size() * 2, cudaMemcpyDeviceToHost), "h");
288    size_t bad = 0;
289    for (size_t i = 0; i < h.size(); ++i) bad += h[i] != f_to_half_rn(ref[i]);
290    std::printf("tqp ref %-6s dequant_f16 %5d x %5d: %zu of %zu fp16 values differ from the definition  %s\n", name_of(t), n_out, n_in,
291                bad, h.size(), bad ? "FAIL" : "bitwise equal");
292    g_fail += bad != 0;
293    // (2) the decode kernels (int8 codebook, q8_1 activations): relative L1 error against the float weights . the
294    // dequantized q8_1 activations, in double, below the 3e-2 every expert type gets in native_expert_parity
295    const int nc = 3;
296    const auto x = random_x((size_t) nc * n_in, rng);
297    float* dx = dalloc<float>(x.size());
298    ck(cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice), "x");
299    uint8_t* dxq = dalloc<uint8_t>((size_t) nc * (n_in / 32) * 36);
300    k::quantize_q8_1_rows(dx, nc, n_in, dxq, s);
301    float* dy = dalloc<float>((size_t) nc * n_out);
302    k::iq_mmvq(t, dw, dxq, dy, n_in, n_out, nc, s);
303    ck(cudaStreamSynchronize(s), "sync");
304    std::vector<float> y((size_t) nc * n_out);
305    ck(cudaMemcpy(y.data(), dy, y.size() * 4, cudaMemcpyDeviceToHost), "y");
306    std::vector<uint8_t> xq((size_t) nc * (n_in / 32) * 36);
307    ck(cudaMemcpy(xq.data(), dxq, xq.size(), cudaMemcpyDeviceToHost), "xq");
308    double l1 = 0, l1ref = 0;
309    for (int c = 0; c < nc; ++c) {
310        std::vector<double> xd((size_t) n_in);
311        for (int b = 0; b < n_in / 32; ++b) {
312            const uint8_t* blk = &xq[((size_t) c * (n_in / 32) + b) * 36];
313            uint16_t hd;
314            std::memcpy(&hd, blk, 2);
315            const double d = half_to_f(hd);
316            for (int j = 0; j < 32; ++j) xd[(size_t) b * 32 + j] = d * (double) (int8_t) blk[4 + j];
317        }
318        for (int r = 0; r < n_out; ++r) {
319            double acc = 0;
320            for (int i = 0; i < n_in; ++i) acc += (double) ref[(size_t) r * n_in + i] * xd[(size_t) i];
321            l1 += std::fabs((double) y[(size_t) c * n_out + r] - acc);
322            l1ref += std::fabs(acc);
323        }
324    }
325    const double rel = l1 / l1ref;
326    std::printf("tqp ref %-6s mmvq %5d x %5d x %d cols: relative L1 error %.2e (bound 3e-2)  %s\n", name_of(t), n_out, n_in, nc, rel,
327                rel < 3e-2 ? "ok" : "FAIL");
328    g_fail += !(rel < 3e-2);
329    cudaFree(dw); cudaFree(dh); cudaFree(dx); cudaFree(dxq); cudaFree(dy);
330}
331
332float time_ms(cudaStream_t s, int it, const auto& fn) {
333    cudaEvent_t e0, e1;
334    cudaEventCreate(&e0);
335    cudaEventCreate(&e1);
336    fn();
337    ck(cudaStreamSynchronize(s), "warm");
338    cudaEventRecord(e0, s);
339    for (int i = 0; i < it; ++i) fn();
340    cudaEventRecord(e1, s);
341    ck(cudaEventSynchronize(e1), "bench");
342    float ms = 0;
343    cudaEventElapsedTime(&ms, e0, e1);
344    cudaEventDestroy(e0);
345    cudaEventDestroy(e1);
346    return ms / it;
347}
348
349void bench(cudaStream_t s, std::mt19937& rng) {
350    std::printf("\n--bench: microseconds per call (idle GPU assumed)\n");
351    const int n_in = 2560, n_out = 8192, it = 100;
352    for (int t : {144, 145, 146, 42}) {
353        const auto w = random_rows(t, n_out, n_in, rng);
354        uint8_t* dw = dalloc<uint8_t>(w.size());
355        ck(cudaMemcpy(dw, w.data(), w.size(), cudaMemcpyHostToDevice), "w");
356        const auto x = random_x((size_t) 8 * n_in, rng);
357        float* dx = dalloc<float>(x.size());
358        ck(cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice), "x");
359        uint8_t* dxq = dalloc<uint8_t>((size_t) 8 * (n_in / 32) * 36);
360        k::quantize_q8_1_rows(dx, 8, n_in, dxq, s);
361        float* dy = dalloc<float>((size_t) 8 * n_out);
362        const double gb = (double) w.size() / 1e9;
363        std::printf("BENCH mmvq %-6s %d x %d (%.3f GB):", name_of(t), n_out, n_in, gb);
364        for (int nc : {1, 2, 3, 4, 8}) {
365            const float us = 1e3f * time_ms(s, it, [&] { k::iq_mmvq(t, dw, dxq, dy, n_in, n_out, nc, s); });
366            std::printf("  nc%d %.1f us (%.0f GB/s)", nc, us, gb / (us * 1e-6));
367        }
368        std::printf("\n");
369        cudaFree(dw); cudaFree(dx); cudaFree(dxq); cudaFree(dy);
370    }
371    // the same 21M weights as rows of different lengths: a per-row cost shows as a falling time with longer rows
372    for (int t : {145}) {
373        for (auto rc : {std::pair<int, int>{8192, 2560}, {4096, 5120}, {2048, 10240}, {1024, 20480}}) {
374            const int ni = rc.second, no = rc.first;
375            const auto w = random_rows(t, no, ni, rng);
376            uint8_t* dw = dalloc<uint8_t>(w.size());
377            ck(cudaMemcpy(dw, w.data(), w.size(), cudaMemcpyHostToDevice), "w");
378            const auto x = random_x((size_t) 8 * ni, rng);
379            float* dx = dalloc<float>(x.size());
380            ck(cudaMemcpy(dx, x.data(), x.size() * 4, cudaMemcpyHostToDevice), "x");
381            uint8_t* dxq = dalloc<uint8_t>((size_t) 8 * (ni / 32) * 36);
382            k::quantize_q8_1_rows(dx, 8, ni, dxq, s);
383            float* dy = dalloc<float>((size_t) 8 * no);
384            const float us = 1e3f * time_ms(s, it, [&] { k::iq_mmvq(t, dw, dxq, dy, ni, no, 1, s); });
385            std::printf("BENCH rows %-6s %5d x %5d nc1 %.1f us\n", name_of(t), no, ni, us);
386            cudaFree(dw); cudaFree(dx); cudaFree(dxq); cudaFree(dy);
387        }
388    }
389    // the verify window's shape: 2560 x 640 experts, 16 groups of m entries each
390    for (auto gd : {std::pair<int, int>{145, 146}, {145, 144}, {144, 144}, {144, 146}}) {
391        std::printf("BENCH grouped %-6s/%-6s 16 groups of m entries:", name_of(gd.first), name_of(gd.second));
392        for (int m : {1, 2, 3, 4, 8}) {
393            Grouped G(gd.first, gd.second, 2560, 640, std::vector<int>(16, m), 8, rng);
394            const float us = 1e3f * time_ms(s, 30, [&] { G.run(false, s); });
395            const double gb = 16.0 * (double) G.L.bytes / 1e9;
396            std::printf("  m=%d %.1f us (%.0f GB/s)", m, us, gb / (us * 1e-6));
397        }
398        std::printf("\n");
399    }
400}
401
402}  // namespace
403
404int main(int argc, char** argv) {
405    const bool do_bench = argc > 1 && std::string(argv[1]) == "--bench";
406    cudaStream_t s;
407    ck(cudaStreamCreate(&s), "stream");
408    cudaDeviceProp prop;
409    cudaGetDeviceProperties(&prop, 0);
410    std::printf("device %s cc %d.%d\n", prop.name, prop.major, prop.minor);
411    std::mt19937 rng(18);
412    // Gyro-S / Gyro-M types first, on the generator they always had: their "SUM" lines are the same bits as before the pair types
413    for (int t : {144, 145, 146}) {
414        check_mmvq(t, 2560, 67, s, rng);
415        check_mmvq(t, 1024, 5, s, rng);
416    }
417    for (int gu : {144, 145})
418        for (int dt : {144, 146}) check_grouped(gu, dt, 2560, 640, s, rng);
419    // other geometries: a longer hidden row (the staged gate/up falls back from its 80-block activation buffer), a shorter
420    // expert row (the 8-lane down rows need n_ff 640)
421    for (int gu : {144, 145}) {
422        check_grouped(gu, 146, 5120, 640, s, rng);
423        check_grouped(gu, 144, 2560, 512, s, rng);
424        check_grouped(gu, 146, 2048, 256, s, rng);
425    }
426    // Gyro-L's pair trellis (own generator): decode-once == per-column, then a reference from the format definition
427    // (fp16 dequantizer bit for bit, decode kernels to 3e-2)
428    std::mt19937 rng_p(19);
429    for (int t : {147, 148, 149}) {
430        check_mmvq(t, 2560, 67, s, rng_p);
431        check_mmvq(t, 1024, 5, s, rng_p);
432        check_tqp_reference(t, 2560, 67, s, rng_p);
433        check_tqp_reference(t, 1024, 5, s, rng_p);
434        check_grouped(t, t, 2560, 640, s, rng_p);   // the pair trellis in both roles, as its file has it (tqp6 / tqp6)
435        check_grouped(t, t, 5120, 640, s, rng_p);
436    }
437    check_grouped(148, 146, 2560, 640, s, rng_p);
438    check_grouped(145, 148, 2560, 640, s, rng_p);
439    if (do_bench) bench(s, rng);
440    std::printf("tq_pascal_bench: %d failures\n", g_fail);
441    cudaStreamDestroy(s);
442    return g_fail ? 1 : 0;
443}