okami.mom/strata

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

Niko1221Merge f-q4-sycl (41717f29c): the Intel Arc (SYCL) engine follows the compiled geometry, so q4_lite/q4_mid/q4_big build; default build unchanged (CUDA SASS 3573/3573, HIP gfx1201 3920/3920, gfx1151 string offsets only, Metal 85/85 objects, SYCL 22/22 checksums); A750 gate 2 q4_lite 0.00021 vs floor 0.00017; one conflict with f-clean-6-0 in sycl/src/prefill/prefill.cpp resolved as tested by Q4-SYMERGE (Qwen4 prep)db137d917

main
21.3 KiB361 linesraw
1// src/kernels/native_expert_parity.cpp - plan v0.3 P6: one native expert three ways, on real GGUF rows.
2//
3//     build/native_expert_parity <shard1.gguf> [layer ...]
4//
5// (a) float reference: ggml's own dequantizer (`to_float`) and a float SwiGLU expert, (b) the CPU path
6// (ggml-cpu vec_dot with its quantized activations), (c) the GPU path (`native_expert_grouped`, q8_1
7// activations).  (b) and (c) each differ from (a) by their activation rounding only (a few 1e-3 relative).
8#include "strata/artifact/gguf_reader.hpp"
9#include "strata/kernels/cpu/native_expert.hpp"
10#include "strata/kernels/cpu/expert.hpp"
11#include "strata/kernels/cpu/iq_avx512.hpp"
12#include "strata/kernels/cpu/iq_avx2.hpp"
13#include "strata/kernels/cpu/expert_layout.hpp"
14#include "ggml-cpu.h"
15#include "strata/kernels/iq_kernels.hpp"
16
17#include "ggml.h"
18
19#include <sycl/sycl.hpp>
20#include <dpct/dpct.hpp>   // SYCL port: hand-ported (dpct needs ggml-cpu.h to parse this file)
21
22#include <chrono>
23#include <cmath>
24#include <cstdio>
25#include <cstdlib>
26#include <cstring>
27#include <memory>
28#include <random>
29#include <string>
30#include <vector>
31
32namespace cpu = strata::kernels::cpu;
33
34// Round 0214: --synthetic GU/DOWN ... : random weights quantized by ggml (ggml type names, e.g. iq2_xs/q5_0) in place of real
35// rows, as the CUDA/HIP tree's native_expert_parity does; the checks below are the same.
36static int type_of(std::string name) {
37    for (auto& c : name) c = (char) std::tolower((unsigned char) c);
38    for (int t = 0; t < GGML_TYPE_COUNT; ++t) {
39        const char* n = ggml_type_name((ggml_type) t);
40        if (n == nullptr) continue;
41        std::string m(n);
42        for (auto& c : m) c = (char) std::tolower((unsigned char) c);
43        if (m == name) return t;
44    }
45    return -1;
46}
47
48static std::vector<uint8_t> synthetic_blob(const cpu::NativeFmt& f, int seed, int64_t H, int64_t FF) {
49    std::vector<uint8_t> blob(f.bytes);
50    std::mt19937 rng(seed);
51    std::normal_distribution<float> nd(0.f, 1.f);
52    auto quant = [&](int type, int64_t rows, int64_t cols, uint8_t* dst) {
53        std::vector<float> w((size_t) (rows * cols));
54        for (int64_t r = 0; r < rows; ++r) {
55            const float scale = 0.02f * (0.5f + (float) (r % 7) / 7.0f);
56            for (int64_t c = 0; c < cols; ++c) w[(size_t) (r * cols + c)] = scale * nd(rng);
57        }
58        const std::vector<float> imatrix((size_t) cols, 1.0f);
59        ggml_quantize_chunk((ggml_type) type, w.data(), dst, 0, rows, cols,
60                            ggml_quantize_requires_imatrix((ggml_type) type) ? imatrix.data() : nullptr);
61    };
62    quant(f.gu_type, FF, H, blob.data());
63    quant(f.gu_type, FF, H, blob.data() + f.up_off);
64    quant(f.d_type, H, FF, blob.data() + f.down_off);
65    return blob;
66}
67
68static double rel(const std::vector<float>& a, const std::vector<float>& b) {
69    double n = 0, d = 0;
70    for (size_t i = 0; i < a.size(); ++i) { n += std::fabs((double) a[i] - b[i]); d += std::fabs((double) b[i]); }
71    return n / (d + 1e-30);
72}
73
74int main(int argc, char** argv) {
75    setvbuf(stdout, nullptr, _IONBF, 0);   // keep the trail on a crash
76    if (argc < 2) { std::fprintf(stderr, "usage: native_expert_parity <shard1.gguf> [layer ...] | --synthetic GU/DOWN ...\n"); return 2; }
77    const bool synthetic = std::string(argv[1]) == "--synthetic";
78    std::unique_ptr<strata::GgufFile> gguf_p;
79    if (!synthetic) gguf_p.reset(new strata::GgufFile(argv[1]));
80    std::vector<int> layers;
81    std::vector<std::string> pair_names;
82    for (int i = 2; i < argc; ++i) {
83        if (synthetic) { pair_names.push_back(argv[i]); layers.push_back((int) pair_names.size() - 1); }
84        else layers.push_back(std::atoi(argv[i]));
85    }
86    if (layers.empty() && !synthetic) layers = {0, 1, 2, 3, 20, 47};
87    const int NT = 3, E = 7;
88    int64_t H = 2560, FF = 640;   // Q4KQ_PARITY_EMBD / Q4KQ_PARITY_FF override them (Q4-KQ, as the CUDA tree's test: expert widths 512 and 1024; Q4-SYCL: the q4_* builds)
89    if (const char* e = std::getenv("Q4KQ_PARITY_EMBD")) H = std::atoll(e);
90    if (const char* e = std::getenv("Q4KQ_PARITY_FF")) FF = std::atoll(e);
91    int failures = 0;
92    sycl::queue* s = &dpct::get_in_order_queue();
93    for (int l : layers) {
94        cpu::NativeFmt f;
95        std::string err;
96        std::vector<uint8_t> blob;
97        if (synthetic) {
98            const std::string arg = pair_names[(size_t) l];
99            const size_t slash = arg.find('/');
100            const int gu = slash == std::string::npos ? -1 : type_of(arg.substr(0, slash));
101            const int dn = slash == std::string::npos ? -1 : type_of(arg.substr(slash + 1));
102            if (gu < 0 || dn < 0 || !cpu::native_fmt(gu, dn, H, FF, f, err) ||
103                !strata::kernels::native_expert_supported(gu, dn, H, FF)) {
104                std::printf("%s: %s\n", arg.c_str(), err.empty() ? "not a pair the GPU expert kernels take" : err.c_str());
105                ++failures;
106                continue;
107            }
108            blob = synthetic_blob(f, l, H, FF);
109        } else {
110            strata::GgufFile& gguf = *gguf_p;
111            const strata::TensorInfo* t[3] = {};
112            const char* roles[3] = {"gate", "up", "down"};
113            for (const auto& ti : gguf.tensors())
114                for (int r = 0; r < 3; ++r)
115                    if (ti.name == "blk." + std::to_string(l) + ".ffn_" + roles[r] + "_exps.weight") t[r] = &ti;
116            if (!t[0] || !t[1] || !t[2]) { std::printf("layer %d: no expert tensors\n", l); ++failures; continue; }
117            if (!cpu::native_fmt((int) t[0]->type, (int) t[2]->type, H, FF, f, err)) {
118                std::printf("layer %d: %s\n", l, err.c_str()); ++failures; continue;
119            }
120            blob.resize(f.bytes);
121            std::memcpy(blob.data(), gguf.tensor_data(*t[0]) + (size_t) E * f.up_off, f.up_off);
122            std::memcpy(blob.data() + f.up_off, gguf.tensor_data(*t[1]) + (size_t) E * f.up_off, f.up_off);
123            std::memcpy(blob.data() + f.down_off, gguf.tensor_data(*t[2]) + (size_t) E * (f.bytes - f.down_off),
124                        f.bytes - f.down_off);
125        }
126        // (a) the float reference
127        const auto* tg = ggml_get_type_traits((ggml_type) f.gu_type);
128        const auto* td = ggml_get_type_traits((ggml_type) f.d_type);
129        std::vector<float> G((size_t) FF * H), U((size_t) FF * H), D((size_t) H * FF);
130        for (int64_t r = 0; r < FF; ++r) {
131            tg->to_float(blob.data() + r * f.gu_row, G.data() + r * H, H);
132            tg->to_float(blob.data() + f.up_off + r * f.gu_row, U.data() + r * H, H);
133        }
134        for (int64_t r = 0; r < H; ++r) td->to_float(blob.data() + f.down_off + r * f.d_row, D.data() + r * FF, FF);
135        std::mt19937 rng(11 + l);
136        std::normal_distribution<float> nd(0.f, 1.f);
137        std::vector<float> x((size_t) NT * H);
138        for (auto& v : x) v = nd(rng);
139        std::vector<float> ref((size_t) NT * H), got_c((size_t) NT * H), got_g((size_t) NT * H);
140        for (int k = 0; k < NT; ++k) {
141            std::vector<float> h(FF);
142            for (int64_t r = 0; r < FF; ++r) {
143                double g = 0, u = 0;
144                for (int64_t i = 0; i < H; ++i) { g += (double) G[r * H + i] * x[k * H + i]; u += (double) U[r * H + i] * x[k * H + i]; }
145                h[r] = (float) (g / (1.0 + std::exp(-g)) * u);
146            }
147            for (int64_t r = 0; r < H; ++r) {
148                double o = 0;
149                for (int64_t i = 0; i < FF; ++i) o += (double) D[r * FF + i] * h[i];
150                ref[k * H + r] = (float) o;
151            }
152        }
153        // (b) the CPU
154        {
155            std::vector<std::vector<uint8_t>> act(NT, std::vector<uint8_t>(cpu::kNativeActBytes));
156            std::vector<std::vector<uint8_t>> hq(NT, std::vector<uint8_t>(cpu::kNativeHBytes));
157            std::vector<std::vector<float>> ff(NT, std::vector<float>(FF));
158            const void* a[NT];
159            float* ffp[NT];
160            const void* hp[NT];
161            float* op[NT];
162            for (int k = 0; k < NT; ++k) {
163                cpu::native_quant_act(f, x.data() + k * H, act[k].data());
164                a[k] = act[k].data();
165                ffp[k] = ff[k].data();
166            }
167            cpu::native_gu_rows(f, blob.data(), a, NT, ffp, 0, (int) FF);
168            if (cpu::iq512_supported(f.gu_type)) {
169                // ggml's own vec_dot, same Q8_K activations: the reference for both multi-token kernels
170                // (float-order differences only)
171                const auto* tc = ggml_get_type_traits_cpu((ggml_type) f.gu_type);
172                std::vector<float> gref((size_t) NT * FF);
173                for (int k = 0; k < NT; ++k)
174                    for (int64_t r = 0; r < FF; ++r)
175                        tc->vec_dot((int) H, &gref[k * FF + r], 0, blob.data() + r * f.gu_row, 0, a[k], 0, 1);
176                double usg = 0.0;
177                {   // ggml single-token throughput, the weights cache-resident (compute bound)
178                    const int it = 50;
179                    auto t0 = std::chrono::steady_clock::now();
180                    for (int i = 0; i < it; ++i)
181                        for (int64_t r = 0; r < FF; ++r) {
182                            float gg, uu;
183                            tc->vec_dot((int) H, &gg, 0, blob.data() + r * f.gu_row, 0, a[0], 0, 1);
184                            tc->vec_dot((int) H, &uu, 0, blob.data() + f.up_off + r * f.gu_row, 0, a[0], 0, 1);
185                        }
186                    auto t1 = std::chrono::steady_clock::now();
187                    usg = std::chrono::duration<double, std::micro>(t1 - t0).count() / it;
188                }
189                // one multi-token kernel: parity against ggml's vec_dot, then one-token and NT-token throughput
190                auto check = [&](const char* tag, bool is512) {
191                    std::vector<float> g((size_t) NT * FF);
192                    float* gp[NT];
193                    for (int k = 0; k < NT; ++k) gp[k] = g.data() + k * FF;
194                    (is512 ? cpu::iq512_rows : cpu::iq256_rows)(f.gu_type, blob.data(), f.gu_row, (int) H, a, NT, gp, 0, (int) FF);
195                    const double rg = rel(g, gref);
196                    std::printf("          %s %s gate rows vs ggml vec_dot: rel %.2e\n",
197                                ggml_type_name((ggml_type) f.gu_type), tag, rg);
198                    if (rg > 1e-5) {   // ggml's own vec_dot is the reference: above 1e-5 it is a real mismatch,
199                        std::printf("          %s %s gate rows MISMATCH (rel %.2e > 1e-5)\n",
200                                    ggml_type_name((ggml_type) f.gu_type), tag, rg);   // not rounding (measured 3e-8)
201                        ++failures;
202                    }
203                    float* f1[1] = {ffp[0]};
204                    const int it = 50;
205                    const auto gu = is512 ? cpu::iq512_gu_rows : cpu::iq256_gu_rows;
206                    auto t0 = std::chrono::steady_clock::now();
207                    for (int i = 0; i < it; ++i) gu(f.gu_type, blob.data(), f.gu_row, f.up_off, (int) H, a, 1, f1, 0, (int) FF);
208                    auto t1 = std::chrono::steady_clock::now();
209                    for (int i = 0; i < it; ++i) gu(f.gu_type, blob.data(), f.gu_row, f.up_off, (int) H, a, NT, ffp, 0, (int) FF);
210                    auto t2 = std::chrono::steady_clock::now();
211                    const double us1 = std::chrono::duration<double, std::micro>(t1 - t0).count() / it;
212                    const double usn = std::chrono::duration<double, std::micro>(t2 - t1).count() / it;
213                    std::printf("          gate+up one token one thread: %s %.0f us (%.2f GB/s), ggml %.0f us (%.2f GB/s)\n",
214                                tag, us1, 2.0 * f.up_off / us1 / 1e3, usg, 2.0 * f.up_off / usg / 1e3);
215                    std::printf("          gate+up %d tokens one thread: %s %.0f us vs ggml %d x %.0f us\n", NT, tag, usn, NT, usg);
216                };
217                if (cpu::cpu_avx512_ok()) check("avx512", true);   // guarded: the binary runs on AVX-2 CPUs too
218                check("avx2", false);
219            }
220            for (int k = 0; k < NT; ++k) {
221                cpu::native_quant_h(f, ff[k].data(), hq[k].data());
222                hp[k] = hq[k].data();
223                op[k] = got_c.data() + k * H;
224            }
225            cpu::native_down_rows(f, blob.data(), hp, NT, op, 0, (int) H);
226            if (f.d_type == 42) {
227                // (b2) the GGUF-layout Q2_0 kernel the pool uses for Q2_0 down projections - the AVX-512 one
228                // where the CPU has it, the AVX-2 one (q2_avx2.cpp) where it does not.  Calling the AVX-512
229                // kernel unconditionally faults on a Zen 2/3 CPU.
230                std::vector<cpu::ActQ> a2(NT);
231                const cpu::ActQ* ap[NT];
232                std::vector<float> alt((size_t) NT * H);
233                float* altp[NT];
234                for (int k = 0; k < NT; ++k) {
235                    cpu::act_quant_any(ff[k].data(), (int) FF, a2[k]);   // gated: AVX-512 or AVX-2 per CPU
236                    ap[k] = &a2[k];
237                    altp[k] = alt.data() + k * H;
238                }
239                cpu::q2_rows_any(blob.data() + f.down_off, f.d_row, (int) (FF / 64), ap, NT, altp, 0, (int) H);
240                std::printf("          q2_0 %s down vs ggml down: rel %.2e\n",
241                            cpu::cpu_avx512_ok() ? "AVX-512" : "AVX-2", rel(alt, got_c));
242            }
243            if (f.d_type == 20) {
244                // (b3) the IQ4_NL multi-token AVX-2 kernel the pool now uses for IQ4_NL down projections,
245                // against ggml-cpu's single-token vec_dot on the SAME Q8_0 activations (h), plus timing.
246                std::vector<float> alt((size_t) NT * H), refd((size_t) NT * H);
247                float* altp[NT];
248                for (int k = 0; k < NT; ++k) altp[k] = alt.data() + k * H;
249                cpu::iq4nl256_down_rows(blob.data() + f.down_off, f.d_row, (int) FF, hp, NT, altp, 0, (int) H);
250                const auto* tdc = ggml_get_type_traits_cpu((ggml_type) f.d_type);
251                for (int k = 0; k < NT; ++k)
252                    for (int64_t r = 0; r < H; ++r)
253                        tdc->vec_dot((int) FF, refd.data() + k * H + r, 0,
254                                     blob.data() + f.down_off + (size_t) r * f.d_row, 0, hp[k], 0, 1);
255                const double rdn = rel(alt, refd);
256                std::printf("          iq4_nl AVX-2 multi-token down vs ggml down: rel %.2e\n", rdn);
257                if (rdn > 1e-5) {   // measured 1e-7; same reasoning as the gate/up rows above
258                    std::printf("          iq4_nl down MISMATCH (rel %.2e > 1e-5)\n", rdn);
259                    ++failures;
260                }
261                const int it = 50;
262                const auto t0 = std::chrono::steady_clock::now();
263                for (int i = 0; i < it; ++i)
264                    cpu::iq4nl256_down_rows(blob.data() + f.down_off, f.d_row, (int) FF, hp, NT, altp, 0, (int) H);
265                const auto t1 = std::chrono::steady_clock::now();
266                for (int i = 0; i < it; ++i)
267                    for (int k = 0; k < NT; ++k)
268                        for (int64_t r = 0; r < H; ++r)
269                            tdc->vec_dot((int) FF, refd.data() + k * H + r, 0,
270                                        blob.data() + f.down_off + (size_t) r * f.d_row, 0, hp[k], 0, 1);
271                const auto t2 = std::chrono::steady_clock::now();
272                const double usn = std::chrono::duration<double, std::micro>(t1 - t0).count() / it;
273                const double usg = std::chrono::duration<double, std::micro>(t2 - t1).count() / it;
274                std::printf("          down %d tokens one thread: avx2 %.0f us (%.2f GB/s) vs ggml %.0f us (%.2f GB/s)\n",
275                            NT, usn, (double) (f.bytes - f.down_off) / usn / 1e3, usg,
276                            (double) (f.bytes - f.down_off) / usg / 1e3);
277            }
278        }
279        // (c) the GPU: one group holding the NT entries
280        {
281            const auto L = strata::kernels::native_expert_layout(f.gu_type, f.d_type, H, FF);
282            void *dblob, *dx, *dxq, *dscr;
283            float* dout;
284            unsigned long long* dptr;
285            int32_t *dstart, *dn, *ddst, *dtok;
286            dblob = (decltype(dblob)) sycl::malloc_device(blob.size(), *s);
287            dx = (decltype(dx)) sycl::malloc_device(x.size() * 4, *s);
288            dxq = (decltype(dxq)) sycl::malloc_device((size_t) NT * H / 32 * 36, *s);
289            dscr = (decltype(dscr)) sycl::malloc_device(strata::kernels::native_expert_scratch_bytes(NT, FF), *s);
290            dout = (decltype(dout)) sycl::malloc_device((size_t) NT * H * 4, *s);
291            dptr = (decltype(dptr)) sycl::malloc_device(8, *s);
292            dstart = (decltype(dstart)) sycl::malloc_device(8, *s);
293            dn = (decltype(dn)) sycl::malloc_device(4, *s);
294            ddst = (decltype(ddst)) sycl::malloc_device(NT * 4, *s);
295            dtok = (decltype(dtok)) sycl::malloc_device(NT * 4, *s);
296            s->memcpy(dblob, blob.data(), blob.size()).wait();
297            s->memcpy(dx, x.data(), x.size() * 4).wait();
298            const unsigned long long p = (unsigned long long) dblob;
299            const int32_t st[2] = {0, NT}, one = 1, idx[NT] = {0, 1, 2};
300            s->memcpy(dptr, &p, 8).wait();
301            s->memcpy(dstart, st, 8).wait();
302            s->memcpy(dn, &one, 4).wait();
303            s->memcpy(ddst, idx, NT * 4).wait();
304            s->memcpy(dtok, idx, NT * 4).wait();
305            strata::kernels::quantize_q8_1_rows((const float*) dx, NT, H, dxq, s);
306            strata::kernels::native_expert_grouped(L, dptr, dstart, dn, ddst, dtok, 1, NT, dxq, dscr, dout, s);
307            s->wait();
308            s->memcpy(got_g.data(), dout, got_g.size() * 4).wait();
309            if (std::getenv("NATIVE_BENCH") != nullptr) {   // SYCL port: one layer's worth of hits, timed
310                // G distinct experts (copies of this blob at different addresses), E entries each = a T-token window
311                const int G = 10, E = 4, NE = G * E, iters = 20;
312                std::vector<void*> blobs((size_t) G);
313                std::vector<unsigned long long> ptrs((size_t) G);
314                for (int g = 0; g < G; ++g) {
315                    blobs[(size_t) g] = sycl::malloc_device(blob.size(), *s);
316                    s->memcpy(blobs[(size_t) g], blob.data(), blob.size()).wait();
317                    ptrs[(size_t) g] = (unsigned long long) blobs[(size_t) g];
318                }
319                std::vector<int32_t> starts((size_t) G + 1), dst((size_t) NE), tokv((size_t) NE);
320                for (int g = 0; g <= G; ++g) starts[(size_t) g] = g * E;
321                for (int e = 0; e < NE; ++e) { dst[(size_t) e] = e; tokv[(size_t) e] = e % NT; }
322                unsigned long long* bptr = sycl::malloc_device<unsigned long long>((size_t) G, *s);
323                int32_t* bstart = sycl::malloc_device<int32_t>((size_t) G + 1, *s);
324                int32_t* bn = sycl::malloc_device<int32_t>(1, *s);
325                int32_t* bdst = sycl::malloc_device<int32_t>((size_t) NE, *s);
326                int32_t* btok = sycl::malloc_device<int32_t>((size_t) NE, *s);
327                void* bscr = sycl::malloc_device(strata::kernels::native_expert_scratch_bytes(NE, FF), *s);
328                float* bout = sycl::malloc_device<float>((size_t) NE * H, *s);
329                const int32_t gn = G;
330                s->memcpy(bptr, ptrs.data(), (size_t) G * 8).wait();
331                s->memcpy(bstart, starts.data(), ((size_t) G + 1) * 4).wait();
332                s->memcpy(bn, &gn, 4).wait();
333                s->memcpy(bdst, dst.data(), (size_t) NE * 4).wait();
334                s->memcpy(btok, tokv.data(), (size_t) NE * 4).wait();
335                strata::kernels::native_expert_grouped(L, bptr, bstart, bn, bdst, btok, G, NE, dxq, bscr, bout, s);
336                s->wait();
337                const auto b0 = std::chrono::steady_clock::now();
338                for (int i = 0; i < iters; ++i)
339                    strata::kernels::native_expert_grouped(L, bptr, bstart, bn, bdst, btok, G, NE, dxq, bscr, bout, s);
340                s->wait();
341                const double ms = std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - b0).count() / iters;
342                std::printf("          GPU grouped: %d experts x %d entries: %.3f ms per layer call  (%.1f GB/s of expert bytes)\n",
343                            G, E, ms, (double) G * (double) blob.size() / ms / 1e6);
344                for (int g = 0; g < G; ++g) sycl::free(blobs[(size_t) g], *s);
345                sycl::free(bptr, *s); sycl::free(bstart, *s); sycl::free(bn, *s); sycl::free(bdst, *s); sycl::free(btok, *s);
346                sycl::free(bscr, *s); sycl::free(bout, *s);
347            }
348            sycl::free(dblob, *s); sycl::free(dx, *s); sycl::free(dxq, *s); sycl::free(dscr, *s); sycl::free(dout, *s); sycl::free(dptr, *s);
349            sycl::free(dstart, *s); sycl::free(dn, *s); sycl::free(ddst, *s); sycl::free(dtok, *s);
350        }
351        const double ec = rel(got_c, ref), eg = rel(got_g, ref), ecg = rel(got_c, got_g);
352        const double gpu_limit = f.d_type == 6 ? 1.8e-2 : 3e-2;   // Q5_0 down: the quantized-sum offset (round 0214) makes it as accurate as the rest
353        const bool ok = ec < 3e-2 && eg < gpu_limit && std::isfinite(ec) && std::isfinite(eg);
354        std::printf("%s %2d  %-8s/%-7s blob %8zu  cpu rel %.2e  gpu rel %.2e  cpu-gpu %.2e  %s\n", synthetic ? "pair " : "layer", l,
355                    ggml_type_name((ggml_type) f.gu_type), ggml_type_name((ggml_type) f.d_type), f.bytes, ec, eg, ecg,
356                    ok ? "ok" : "FAIL");
357        if (!ok) ++failures;
358    }
359    std::printf("native_expert_parity: %d failures\n", failures);
360    return failures ? 1 : 0;
361}