diff --git a/.crumb b/.crumb index bdf2bded7..2603dca3e 100644 --- a/.crumb +++ b/.crumb @@ -51,8 +51,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "28840d48abe117c5e29a9fc7f352475deee0c546157edfcb09ebe61a1d364da1", - "last_commit": "cff342b", + "digest": "e156df1e52268bb3346ded9bf7afcb426960e643a8889e1d76865a83a3a5a642", + "last_commit": "55d05d6", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -64,7 +64,7 @@ }, { "digest": "25dc918988768c936cdd41410a68c18df3c9acf7cd129812bc030c6a070cc67c", - "last_commit": "cff342b", + "last_commit": "55d05d6", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -87,33 +87,33 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "839e2dd4f0aa249d7b552e9d3eafdf3ae94f13a4a4c17c3bed1ce603a07659d8", - "last_commit": "cff342b", + "digest": "fab4c6952b54567c65c8bd843e46bcd238c688940ed1d1830af2b584b057781b", + "last_commit": "55d05d6", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "7f8951ba438340bc36223d5722c1055efd8fdd01efe3a43bcf8f2e61ce68dea7", - "last_commit": "cff342b", + "digest": "9eb57c43d48ae70bce44757cbf075c38a03a090e0da529260d88e197e602c767", + "last_commit": "55d05d6", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "49be2149359521a3a0f87c12aa31e565c6575309bd099aff8daa216b25052ed6", + "digest": "9e08561d488a03e636cb8622b6667636230ac21cce1711e0ff6a45cf7f5c5761", "last_commit": "00f54b6", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:f5cd48815a1e17f58c9a56231edbc7e6d4cb19045afc1f03cba9a5c92b20d6f4", - "compiled_at": "2026-10-04T18:54:29Z", + "children_root": "sha256:59067587092f050563a42fe041880c24f8c92e7c0c09bc01e5885b712222826b", + "compiled_at": "2026-10-04T19:57:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:16e57dc9bcda740ae51c4709c0fd61944bf2690f670206423904038ad95a7bb7", + "digest": "sha256:55e53e69b40dc3fd8b30b97f8a493fda44b457f717f3048e3a37eb9c163589c4", "evidence_files": 1289, "evidence_root": "sha256:748eb7ce0bd377815585505582eb76663350e35af3d876a488897ceea120ba3f", "files": 3049, - "generated_at_commit": "cff342b400ec0bc6b2b68e1004212872d490bb07", - "source_tree": "sha256:63e49ae9974a0c96e66aef44ec14d08e19354be518c670f04e2b6d1dab924b6f" + "generated_at_commit": "55d05d6a53e55dddc06f5eb689bee10c8830f52d", + "source_tree": "sha256:a1f0fb11e0348083ced716d80bdce7f58050b2f26cb1c146206fb4244f1af0ed" }, "owner_lane": "", "provenance": { diff --git a/docs/.crumb b/docs/.crumb index 1b27715f9..a5012d5ce 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -70,7 +70,7 @@ }, { "digest": "e9baaaeec04be41a57c4a2d6a540b01a682c70d4db96cb4af4e1a9912a133aa9", - "last_commit": "00f54b6", + "last_commit": "55d05d6", "name": "dual", "purpose": "DUAL (ARCH-0031) documents in omega: applicability experiment method and findings (APPLICABILITY" }, @@ -81,7 +81,7 @@ "purpose": "Directory docs/estimation. Purpose not yet described by a human." }, { - "digest": "042face6780c6bd762a7e41b10d62c1b3d8f2828e20eaa391ecb1f691cda201a", + "digest": "4272674cbb644368ae8fef74a5775144b11dbd3aac3eb25f073bd898f0268329", "last_commit": "bceec7b", "name": "numeric", "purpose": "Directory docs/numeric. Purpose not yet described by a human." @@ -117,15 +117,15 @@ "purpose": "Directory docs/turing. Purpose not yet described by a human." } ], - "children_root": "sha256:7010ef7e3e982e3828bfeb2ff1a1fe5c8cfeceb6aef820c34c175fe1d0208734", - "compiled_at": "2026-10-04T18:54:28Z", + "children_root": "sha256:c86da32ec6d7b7bc1f8db4bdf024fadf35ae5d588cbadf733db2292beb32691f", + "compiled_at": "2026-10-04T19:57:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:28840d48abe117c5e29a9fc7f352475deee0c546157edfcb09ebe61a1d364da1", + "digest": "sha256:e156df1e52268bb3346ded9bf7afcb426960e643a8889e1d76865a83a3a5a642", "evidence_files": 26, "evidence_root": "sha256:f58236184eadc5f8c8f95499127a9f43c2f4dc702ddca267853d8c3dee0690f1", "files": 100, - "generated_at_commit": "500a510f818ce4b973f4862c96e9361b9c450890", - "source_tree": "sha256:769aaad946a229b703b2def73085c781284fb13666223c34d2fdb16020a3f11b" + "generated_at_commit": "55d05d6a53e55dddc06f5eb689bee10c8830f52d", + "source_tree": "sha256:a6ae94eae6a9333187ad07cf8161cb7261242e9ad567e32d80602224c4556887" }, "owner_lane": "", "provenance": { diff --git a/docs/numeric/.crumb b/docs/numeric/.crumb index dd14119ed..211f49913 100644 --- a/docs/numeric/.crumb +++ b/docs/numeric/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T13:47:05Z", + "compiled_at": "2026-10-04T19:07:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:042face6780c6bd762a7e41b10d62c1b3d8f2828e20eaa391ecb1f691cda201a", + "digest": "sha256:4272674cbb644368ae8fef74a5775144b11dbd3aac3eb25f073bd898f0268329", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 10, - "generated_at_commit": "834ee93e4314a42c1127a2fcda8b29cf3b511245", - "source_tree": "sha256:fb1c6be4cdf35159ea84a5e576a86dfb2121ad73df861aa4af5f80db1ef2b0d0" + "generated_at_commit": "3a3144d4a2cbc4fd55a60da85fe94bd7ed5a9a39", + "source_tree": "sha256:804ae75ce73ff6bc90b9a9a820a86ec37274225b1528c09617df150ad4d5ec6c" }, "owner_lane": "", "provenance": { diff --git a/docs/numeric/FB1_CUT5_ATTENTION.md b/docs/numeric/FB1_CUT5_ATTENTION.md index c535f727b..1bd32ea20 100644 --- a/docs/numeric/FB1_CUT5_ATTENTION.md +++ b/docs/numeric/FB1_CUT5_ATTENTION.md @@ -76,6 +76,14 @@ kernel itself walks the (renumbered) block table. | KV_HEAD | reads kv head `(h / ratio) ^ 1` | every context length including 1 | | SLOT | K read from slot `(t + 1) % block_size`, V from slot t | every context >= 2 (with one token the softmax weight is 1 whatever K says). Shifting both K and V would only permute matched pairs inside a full block, which softmax cannot see, so the mutant is K-only | | NO_RESCALE | accumulator not multiplied by alpha when the max moves | context > 64 (more than one chunk) | +| Q_ROW | q loaded from query-head row `h ^ 1` (kv head and output row stay `h`): a wrong query-head-row address | every context (heads h and h^1 come out swapped); needs num_q_heads even | +| OUT_ROW | the correct result for head `h` stored in flattened output row `h ^ 1`: a wrong output-head slot (merge order) | every context; needs num_q_heads even | + +The enum ends in `OMEGA_GPU_ATTN_MUTANT_COUNT`; every battery (host-only digests, simulator, +chip, JSON `mutants` summary) enumerates `1 .. COUNT-1` and fails if any mutant never ran or +was ever missed, so a mutant added to the enum without a battery entry fails the gate. Host-only +also checks that every mutant's kernel digest differs from the baseline and from every other +mutant's. Names come from `omega_gpu_attention_mutant_name` (table checked against COUNT). Negative control: the comparison must reject the oracle with kv heads swapped. Repeat run on a cache hit must be bit-identical. diff --git a/src/.crumb b/src/.crumb index 541f6f71a..ab1ce0cd5 100644 --- a/src/.crumb +++ b/src/.crumb @@ -170,14 +170,14 @@ } ], "children_root": "sha256:607467f8ea6e425bf33f7a0df65a411055a569e302b8127ab84822a0b4559109", - "compiled_at": "2026-10-04T18:54:28Z", + "compiled_at": "2026-10-04T19:57:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:839e2dd4f0aa249d7b552e9d3eafdf3ae94f13a4a4c17c3bed1ce603a07659d8", + "digest": "sha256:fab4c6952b54567c65c8bd843e46bcd238c688940ed1d1830af2b584b057781b", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 403, - "generated_at_commit": "500a510f818ce4b973f4862c96e9361b9c450890", - "source_tree": "sha256:e98bb9c0ddc0aa8281597e44376154c18782109c91224cc49e83aa7a59cc1834" + "generated_at_commit": "55d05d6a53e55dddc06f5eb689bee10c8830f52d", + "source_tree": "sha256:bf53ea9b7e9ea01435d1b4889e9fae8f7dadddbbe66137845af1c377c0e6b667" }, "owner_lane": "", "provenance": { diff --git a/src/omega_gpu_attention_api.c b/src/omega_gpu_attention_api.c index 53884ae44..d680009ea 100644 --- a/src/omega_gpu_attention_api.c +++ b/src/omega_gpu_attention_api.c @@ -197,15 +197,26 @@ static void gen_attention(Em *e, const KSpec *k) { movi(e, c1, 1); movi(e, c4, 4); movi(e, c32, 32); movi(e, c64, 64); movi(e, c256, SH_S); movi(e, c512, SH_O); movi(e, c768, SH_R); movi(e, c896, SH_R + 128); movrz(e, zero); - /* q[tid] -> shared; out address kept for the end */ + /* q[tid] -> shared; out address kept for the end. Row = seq * num_q_heads + head for + * both q and out (flattened head-major, the oracle's layout). The head-wiring mutants + * swap the row of head h with h ^ 1 on one side only. */ int tid4 = V(e), qrow = V(e), qoff = V(e), qaddr = V64(e), qv = V(e), oaddr = V64(e); + int hq = h, ho = h; + if (k->mutant == OMEGA_GPU_ATTN_MUTANT_Q_ROW) { hq = V(e); lop3xor(e, hq, h, c1); } + if (k->mutant == OMEGA_GPU_ATTN_MUTANT_OUT_ROW) { ho = V(e); lop3xor(e, ho, h, c1); } imadi(e, tid4, tid, 4, NOREG); - imadr(e, qrow, seq, p_nqh, h); + imadr(e, qrow, seq, p_nqh, hq); imadi(e, qoff, qrow, HD * 4, tid4); wide(e, qaddr, qoff, 1, A); ldg(e, qv, qaddr, udesc); sts32(e, tid4, qv); /* SH_Q + tid*4 */ - wide(e, oaddr, qoff, 1, C); + if (ho == hq) wide(e, oaddr, qoff, 1, C); + else { + int orow = V(e), ooff = V(e); + imadr(e, orow, seq, p_nqh, ho); + imadi(e, ooff, orow, HD * 4, tid4); + wide(e, oaddr, ooff, 1, C); + } /* kv head offset, this sequence's table row and context length */ int kvh = V(e), kvoff = V(e), t1 = V(e), tab = V64(e), ca = V64(e), ctx = V(e), vb = V64(e); @@ -745,6 +756,15 @@ int omega_gpu_paged_attention_batch_bf16(const float *q, const void *pool, const return rc; } +static const char *const k_mutant_names[OMEGA_GPU_ATTN_MUTANT_COUNT] = { + "none", "NO_MAX", "KV_HEAD", "SLOT", "NO_RESCALE", "Q_ROW", "OUT_ROW" +}; +_Static_assert(sizeof k_mutant_names / sizeof k_mutant_names[0] == OMEGA_GPU_ATTN_MUTANT_COUNT, "mutant name table"); + +const char *omega_gpu_attention_mutant_name(OmegaGpuAttnMutant m) { + return (m >= 0 && m < OMEGA_GPU_ATTN_MUTANT_COUNT && k_mutant_names[m]) ? k_mutant_names[m] : "?"; +} + const char *omega_gpu_attention_rc_name(int rc) { switch (rc) { case OMEGA_GPU_ATTN_OK: return "OK"; diff --git a/src/omega_gpu_attention_api.h b/src/omega_gpu_attention_api.h index ab47354f4..d498eef98 100644 --- a/src/omega_gpu_attention_api.h +++ b/src/omega_gpu_attention_api.h @@ -136,9 +136,17 @@ typedef enum { OMEGA_GPU_ATTN_MUTANT_NO_MAX, /* softmax without the running-max subtraction (overflows for large scores) */ OMEGA_GPU_ATTN_MUTANT_KV_HEAD, /* reads kv head (h / ratio) ^ 1 */ OMEGA_GPU_ATTN_MUTANT_SLOT, /* K read from slot (t + 1) % block_size while V keeps slot t (K/V mismatch) */ - OMEGA_GPU_ATTN_MUTANT_NO_RESCALE /* the accumulator is not rescaled when the max moves between chunks */ + OMEGA_GPU_ATTN_MUTANT_NO_RESCALE, /* the accumulator is not rescaled when the max moves between chunks */ + /* Head-wiring mutants (attention hardening cut, 2026-10-04). Both swap the rows of + * query heads h and h ^ 1, so they need num_q_heads even (>= 2); never run them on a + * one-head shape (row h ^ 1 of the last sequence would be past the buffer). */ + OMEGA_GPU_ATTN_MUTANT_Q_ROW, /* q loaded from query-head row h ^ 1 (kv head and output row stay h) */ + OMEGA_GPU_ATTN_MUTANT_OUT_ROW, /* the correct result for head h stored in flattened output row h ^ 1 */ + OMEGA_GPU_ATTN_MUTANT_COUNT /* one past the last mutant: every battery enumerates 1 .. COUNT-1 */ } OmegaGpuAttnMutant; void omega_gpu_attention_test_set_mutant(OmegaGpuAttnMutant m); +/* "none", "NO_MAX", ... ; "?" past COUNT. The table is checked against COUNT at compile time. */ +const char *omega_gpu_attention_mutant_name(OmegaGpuAttnMutant m); /* Generate a kernel without launching (host tests, nvdisasm listings). * log2_block_size: shift for token -> block; log2_gqa: shift for query head -> kv head. */ diff --git a/tests/.crumb b/tests/.crumb index 5a2e5c5c1..0843844a9 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -284,14 +284,14 @@ } ], "children_root": "sha256:0a4e348cf355e1fa5924f9c76a460d1d49bc285687b134365ef0fb9dab4f0855", - "compiled_at": "2026-10-04T18:54:28Z", + "compiled_at": "2026-10-04T19:57:19Z", "compiler": "crumb-compile/1", - "digest": "sha256:7f8951ba438340bc36223d5722c1055efd8fdd01efe3a43bcf8f2e61ce68dea7", + "digest": "sha256:9eb57c43d48ae70bce44757cbf075c38a03a090e0da529260d88e197e602c767", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", "files": 790, - "generated_at_commit": "500a510f818ce4b973f4862c96e9361b9c450890", - "source_tree": "sha256:9e8f9ed5339ccf473907a174516a6af9de8ed850a96934abd3c7474c4bf136a6" + "generated_at_commit": "55d05d6a53e55dddc06f5eb689bee10c8830f52d", + "source_tree": "sha256:c3ad53ad3ba707657f944d28dcf4aa052510d627d52b5318e31172e7f13cc243" }, "owner_lane": "", "provenance": { diff --git a/tests/gpu_attention_test.c b/tests/gpu_attention_test.c index 82d7de7e9..03a64a470 100644 --- a/tests/gpu_attention_test.c +++ b/tests/gpu_attention_test.c @@ -5,7 +5,8 @@ * ./gpu_attention_test --timing [--out r.json] cut 4b gate: 1 query x 32 heads x 2048 ctx, 100 calls * through the persistent session, median under 3 ms * ./gpu_attention_test --out receipt.json chip gate: every shape against the host oracle, the - * mutants (deliberately wrong kernels) which the same + * mutants (deliberately wrong kernels, all of + * 1 .. OMEGA_GPU_ATTN_MUTANT_COUNT-1) which the same * check must catch, a negative control, timings * * Oracles re-state aien-sovereign-core crates/aien-inference-abi/src/backend.rs (main 8b5caed) in C: @@ -189,18 +190,26 @@ static void host_only(void) { int rc = omega_gpu_attention_codegen(f32 != 0, f32 ? 12 : 4, 3, &k); CHECK(rc == OMEGA_GPU_ATTN_OK && k.code_size > 0 && k.gpr_count <= 64, "%s kernel generated (rc %s, %zu insns, %u gprs)", name, omega_gpu_attention_rc_name(rc), k.insn_count, k.gpr_count); printf("codegen %s: %zu insns, %u gprs, %u ugprs\n", name, k.insn_count, k.gpr_count, k.uniform_gpr_count); - uint8_t digest[32]; memcpy(digest, k.code_digest, 32); + /* every mutant (1 .. COUNT-1) is a distinct kernel: different from the baseline and from + * every other mutant, named, and inside the register budget */ + uint8_t digests[OMEGA_GPU_ATTN_MUTANT_COUNT][32]; memcpy(digests[0], k.code_digest, 32); free(k.code); - for (int m = 1; m <= 4; m++) { + for (int m = 1; m < OMEGA_GPU_ATTN_MUTANT_COUNT; m++) { omega_gpu_attention_test_set_mutant((OmegaGpuAttnMutant)m); memset(&k, 0, sizeof k); - CHECK(omega_gpu_attention_codegen(f32 != 0, f32 ? 12 : 4, 3, &k) == OMEGA_GPU_ATTN_OK && memcmp(digest, k.code_digest, 32) != 0, "%s mutant %d kernel differs", name, m); + int mrc = omega_gpu_attention_codegen(f32 != 0, f32 ? 12 : 4, 3, &k); + CHECK(mrc == OMEGA_GPU_ATTN_OK && k.gpr_count <= 64, "%s mutant %s generated (rc %s, %u gprs)", name, omega_gpu_attention_mutant_name((OmegaGpuAttnMutant)m), omega_gpu_attention_rc_name(mrc), k.gpr_count); + CHECK(strcmp(omega_gpu_attention_mutant_name((OmegaGpuAttnMutant)m), "?") != 0, "mutant %d has a name", m); + memcpy(digests[m], k.code_digest, 32); free(k.code); omega_gpu_attention_test_set_mutant(OMEGA_GPU_ATTN_MUTANT_NONE); + for (int o = 0; o < m; o++) + CHECK(memcmp(digests[o], digests[m], 32) != 0, "%s mutant %s kernel differs from %s", name, omega_gpu_attention_mutant_name((OmegaGpuAttnMutant)m), omega_gpu_attention_mutant_name((OmegaGpuAttnMutant)o)); } + CHECK(strcmp(omega_gpu_attention_mutant_name(OMEGA_GPU_ATTN_MUTANT_COUNT), "?") == 0, "COUNT has no name"); /* a different shape key is a different kernel */ memset(&k, 0, sizeof k); - CHECK(omega_gpu_attention_codegen(f32 != 0, f32 ? 12 : 4, 2, &k) == OMEGA_GPU_ATTN_OK && memcmp(digest, k.code_digest, 32) != 0, "%s log2gqa 2 kernel differs from log2gqa 3", name); + CHECK(omega_gpu_attention_codegen(f32 != 0, f32 ? 12 : 4, 2, &k) == OMEGA_GPU_ATTN_OK && memcmp(digests[0], k.code_digest, 32) != 0, "%s log2gqa 2 kernel differs from log2gqa 3", name); free(k.code); CHECK(nvdisasm_check(f32 != 0, name, f32 ? must_f32 : must_bf16, f32 ? 11 : 14) == 0, "%s nvdisasm listing decodes and shows the expected instructions", name); } @@ -208,9 +217,9 @@ static void host_only(void) { /* ------------------------------------------------------------- chip gate */ typedef struct { const char *name; size_t n; int rc; size_t bad; double worst; int pass; uint64_t chip_ns, call_ns; uint32_t calls, unwritten; - int mutants_run, mutants_caught; char mutant_note[160]; } Case; + int mutants_run, mutants_caught; char mutant_note[400]; } Case; static Case g_cases[32]; static int g_ncases; -static int g_mutant_caught[5], g_mutant_run[5]; +static int g_mutant_caught[OMEGA_GPU_ATTN_MUTANT_COUNT], g_mutant_run[OMEGA_GPU_ATTN_MUTANT_COUNT]; static void record(Case c, FILE *out) { g_cases[g_ncases++] = c; @@ -224,12 +233,12 @@ static void record(Case c, FILE *out) { c.mutants_run, c.mutants_caught, c.mutant_note); } -static const char *mutant_name(int m) { static const char *n[5] = { "none", "NO_MAX", "KV_HEAD", "SLOT", "NO_RESCALE" }; return n[m]; } +static const char *mutant_name(int m) { return omega_gpu_attention_mutant_name((OmegaGpuAttnMutant)m); } /* Runs the mutants listed in `ms` (terminated by 0) through `run` and counts the catches. */ typedef int (*RunFn)(void *ctx, float *got, OmegaGpuAttnInfo *info); static void run_mutants(Case *c, const int *ms, RunFn run, void *ctx, float *got, const float *want, size_t n, double rel, double abs_tol) { - size_t pos = 0; + size_t pos = strlen(c->mutant_note); /* appends: a case may call this more than once */ for (int i = 0; ms[i]; i++) { OmegaGpuAttnInfo info; double w; omega_gpu_attention_test_set_mutant((OmegaGpuAttnMutant)ms[i]); @@ -286,7 +295,7 @@ static int chip(const char *out_path) { size_t neg = compare(got, wrong, n, 2e-4, 2e-5, &w2); CHECK(neg > n / 2, "%s negative control: wrong expectation flagged (%zu of %zu)", name, neg, n); free(wrong); - static const int ms[3] = { OMEGA_GPU_ATTN_MUTANT_SLOT, OMEGA_GPU_ATTN_MUTANT_NO_RESCALE, 0 }; + static const int ms[5] = { OMEGA_GPU_ATTN_MUTANT_SLOT, OMEGA_GPU_ATTN_MUTANT_NO_RESCALE, OMEGA_GPU_ATTN_MUTANT_Q_ROW, OMEGA_GPU_ATTN_MUTANT_OUT_ROW, 0 }; run_mutants(&c, ms, run_gqa, &gc, got, want, n, 2e-4, 2e-5); } else if (ci == 1 && sh == 1) { static const int ms[2] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, 0 }; @@ -310,6 +319,33 @@ static int chip(const char *out_path) { run_mutants(&c, ms, run_gqa, &gc, got, want, n, 1e-3, 1e-4); record(c, out); free(q); free(kc); free(vc); free(got); free(want); } + /* 2b. MHA (16q/16kv, ratio 1, ctx 300 = 4 full chunks + a partial one): the head-wiring + * mutants Q_ROW and OUT_ROW are observably different here (Q_ROW keeps kv head h, OUT_ROW + * lands on kv head h^1), unlike GQA where both swap the same pair of outputs. */ + { + uint32_t nqh = 16, nkv = 16, seq = 300; size_t n = (size_t)nqh * hd, nkvs = (size_t)seq * nkv * hd; + float *q = malloc(n * 4), *kc = malloc(nkvs * 4), *vc = malloc(nkvs * 4), *got = malloc(n * 4), *want = malloc(n * 4), *got_q = malloc(n * 4); + for (size_t i = 0; i < n; i++) q[i] = frand(&seed, -1.0f, 1.0f); + for (size_t i = 0; i < nkvs; i++) { kc[i] = frand(&seed, -1.0f, 1.0f); vc[i] = frand(&seed, -1.0f, 1.0f); } + oracle_gqa(q, kc, vc, seq, nqh, nkv, hd, want); + Case c = { .name = "gqa_f32_mha_16q16kv_ctx300", .n = n }; + OmegaGpuAttnInfo info; GqaCtx gc = { q, kc, vc, seq, nqh, nkv }; + c.rc = run_gqa(&gc, got, &info); + c.bad = compare(got, want, n, 2e-4, 2e-5, &c.worst); + c.pass = c.rc == OMEGA_GPU_ATTN_OK && c.bad == 0; c.chip_ns = info.elapsed_ns; c.call_ns = info.call_ns; c.calls = info.chip_calls; c.unwritten = info.unwritten_words; + static const int ms_q[2] = { OMEGA_GPU_ATTN_MUTANT_Q_ROW, 0 }; + static const int ms_o[3] = { OMEGA_GPU_ATTN_MUTANT_OUT_ROW, OMEGA_GPU_ATTN_MUTANT_KV_HEAD, 0 }; + run_mutants(&c, ms_q, run_gqa, &gc, got, want, n, 2e-4, 2e-5); + memcpy(got_q, got, n * 4); /* Q_ROW output */ + run_mutants(&c, ms_o, run_gqa, &gc, got, want, n, 2e-4, 2e-5); + /* `got` now holds the KV_HEAD output; rerun OUT_ROW alone to compare it with Q_ROW */ + omega_gpu_attention_test_set_mutant(OMEGA_GPU_ATTN_MUTANT_OUT_ROW); + OmegaGpuAttnInfo i3; int rc3 = run_gqa(&gc, got, &i3); + omega_gpu_attention_test_set_mutant(OMEGA_GPU_ATTN_MUTANT_NONE); + double wq; size_t differ = compare(got, got_q, n, 2e-4, 2e-5, &wq); + CHECK(rc3 == OMEGA_GPU_ATTN_OK && differ > n / 2, "mha: Q_ROW and OUT_ROW outputs are distinct wrong answers (%zu of %zu differ)", differ, n); + record(c, out); free(q); free(kc); free(vc); free(got); free(want); free(got_q); + } /* 3. paged bf16 KV, block size 16, 2 layers (layer 1 under test), scattered block ids */ for (int sh = 0; sh < 2; sh++) for (int ci = 0; ci < 9; ci++) { uint32_t nqh = shapes[sh].nqh, nkv = shapes[sh].nkv, ctx = ctxs[ci], bs = 16, layers = 2, layer = 1; @@ -331,7 +367,7 @@ static int chip(const char *out_path) { c.pass = c.rc == OMEGA_GPU_ATTN_OK && c.bad == 0; c.chip_ns = info.elapsed_ns; c.call_ns = info.call_ns; c.calls = info.chip_calls; c.unwritten = info.unwritten_words; if (ci == 3) { /* NO_MAX cannot overflow on unit-scale scores (softmax is shift invariant); it is caught by the large-score gqa case */ - static const int ms3[4] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, OMEGA_GPU_ATTN_MUTANT_SLOT, OMEGA_GPU_ATTN_MUTANT_NO_RESCALE, 0 }; + static const int ms3[6] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, OMEGA_GPU_ATTN_MUTANT_SLOT, OMEGA_GPU_ATTN_MUTANT_NO_RESCALE, OMEGA_GPU_ATTN_MUTANT_Q_ROW, OMEGA_GPU_ATTN_MUTANT_OUT_ROW, 0 }; run_mutants(&c, ms3, run_paged, &pc, got, want, n, 2e-4, 2e-5); } else if (ci == 1) { static const int ms[3] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, OMEGA_GPU_ATTN_MUTANT_SLOT, 0 }; @@ -369,19 +405,21 @@ static int chip(const char *out_path) { c.pass = c.rc == OMEGA_GPU_ATTN_OK && c.bad == 0; c.chip_ns = info.elapsed_ns; c.call_ns = info.call_ns; c.calls = info.chip_calls; c.unwritten = info.unwritten_words; int zeros = 1; for (size_t i = 0; i < (size_t)nqh * hd; i++) if (got[(size_t)nqh * hd + i] != 0.0f) zeros = 0; CHECK(zeros, "batch: the empty sequence is all zeros"); - static const int ms[3] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, OMEGA_GPU_ATTN_MUTANT_SLOT, 0 }; + static const int ms[5] = { OMEGA_GPU_ATTN_MUTANT_KV_HEAD, OMEGA_GPU_ATTN_MUTANT_SLOT, OMEGA_GPU_ATTN_MUTANT_Q_ROW, OMEGA_GPU_ATTN_MUTANT_OUT_ROW, 0 }; run_mutants(&c, ms, run_batch, &bc, got, want, n, 2e-4, 2e-5); record(c, out); free(pool); free(tables); free(q); free(got); free(want); } - for (int m = 1; m <= 4; m++) { + /* every mutant the API knows (1 .. COUNT-1) ran at least once and was caught every time; + * a mutant added to the enum without a battery entry fails here */ + for (int m = 1; m < OMEGA_GPU_ATTN_MUTANT_COUNT; m++) { CHECK(g_mutant_run[m] > 0 && g_mutant_caught[m] == g_mutant_run[m], "mutant %s caught %d of %d runs", mutant_name(m), g_mutant_caught[m], g_mutant_run[m]); printf("mutant %s: caught %d of %d\n", mutant_name(m), g_mutant_caught[m], g_mutant_run[m]); } CHECK(omega_gpu_session_open_count() == (g_sim_mode ? 0u : 1u), "device opened %s for the battery (opens=%u)", g_sim_mode ? "never (simulator)" : "once", omega_gpu_session_open_count()); printf("device_opens=%u\n", omega_gpu_session_open_count()); if (out) { - fprintf(out, "],\"mutants\":{"); - for (int m = 1; m <= 4; m++) fprintf(out, "%s\"%s\":{\"run\":%d,\"caught\":%d}", m > 1 ? "," : "", mutant_name(m), g_mutant_run[m], g_mutant_caught[m]); + fprintf(out, "],\"mutant_count\":%d,\"mutants\":{", OMEGA_GPU_ATTN_MUTANT_COUNT - 1); + for (int m = 1; m < OMEGA_GPU_ATTN_MUTANT_COUNT; m++) fprintf(out, "%s\"%s\":{\"run\":%d,\"caught\":%d}", m > 1 ? "," : "", mutant_name(m), g_mutant_run[m], g_mutant_caught[m]); fprintf(out, "},\"device_opens\":%u,\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", omega_gpu_session_open_count(), g_checks, g_failed, g_failed == 0 ? "OMEGA_GPU_ATTENTION_PASS" : "OMEGA_GPU_ATTENTION_FAIL"); fclose(out); } diff --git a/tools/.crumb b/tools/.crumb index db7d883c2..49b41d808 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -38,7 +38,7 @@ }, { "digest": "64fe22fe57fab7e61e65cb7652e73dbde613c260cb8677b05d8b98a067231e83", - "last_commit": "", + "last_commit": "00f54b6", "name": "dual_experiment", "purpose": "Runner for the DUAL applicability experiment: runs the pre-registered campaign and writes result" }, @@ -56,14 +56,14 @@ } ], "children_root": "sha256:0920c282c31e3be9b4745fab718ceb60dbfe2ea90dda2108986f60fc2ac53e23", - "compiled_at": "2026-10-04T18:11:13Z", + "compiled_at": "2026-10-04T19:07:57Z", "compiler": "crumb-compile/1", - "digest": "sha256:49be2149359521a3a0f87c12aa31e565c6575309bd099aff8daa216b25052ed6", + "digest": "sha256:9e08561d488a03e636cb8622b6667636230ac21cce1711e0ff6a45cf7f5c5761", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 120, - "generated_at_commit": "cb7cc216147664549484fcca8e8ceadbd6f6cdbf", - "source_tree": "sha256:c4f08a23f53d0fee5dccc1efe157efdf0275735fbb68200875e19d63f0c5ada9" + "generated_at_commit": "3a3144d4a2cbc4fd55a60da85fe94bd7ed5a9a39", + "source_tree": "sha256:172b5a4666f700959782e204a6278eaf02307c5fe94fcf6f9441ae5bd8918412" }, "owner_lane": "", "provenance": { diff --git a/tools/run_gpu_attention_chip.sh b/tools/run_gpu_attention_chip.sh index 4e3753a98..ac2ba9bd0 100755 --- a/tools/run_gpu_attention_chip.sh +++ b/tools/run_gpu_attention_chip.sh @@ -3,7 +3,7 @@ # FB-1 cut 5 chip gate: gqa_attention (f32 KV) and paged_attention (+ batch, bf16 KV) # for the TinyLlama (32q/4kv) and Llama-3.2-1B (32q/8kv) head shapes at context # 1, 17, 256 and 2048, each against the host oracle (the ReferenceCpuBackend math), -# then against the mutant kernels (NO_MAX, KV_HEAD, SLOT, NO_RESCALE), with a +# then against every mutant kernel (NO_MAX, KV_HEAD, SLOT, NO_RESCALE, Q_ROW, OUT_ROW), with a # negative control and a cache-hit repeat. Sealed receipt folder # OUT_ROOT/FB1-CUT5-/ (default ~/workspace/evidence-out): # receipt.json machine-readable verdict per case run.log test output