From a83c0f813e720090adff1b20adf680389d4ca875 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 07:00:54 -0500 Subject: [PATCH 1/8] q36 stroke lever 3: the FP8 GEMM loads the next step's x' words one step ahead The dense trunk GEMMs (mix, o_proj) at M = 8 ran at about half the memory ceiling, and a CTA-budget sweep (48..768 CTAs) did not move them: the cost was the x' staging inside every K step (LDG, STS, BAR.SYNC, compute), whose latency sat in the open once per step. The same kernel at one row per pass streams at 270 GB/s. The kernel now loads the staging words of step s+1 into registers during step s on scoreboard 5 (the weights already do this on 3 and 4) and stores them to shared memory at the start of the step that reads them (consume(5) before the STS). Step 0 is loaded in the pass prologue; the last step of the last iteration re-reads its own step (nf 0), never past the rows; scoreboard 5 is drained after the K loop. Registers 107 -> 110 (k 2048 mt 8, 16 warps, declared 112); rowmap mt 4: 112 (declared 120). NJ > 16 is refused. Tests: host-only 59 PASS, warp simulator 21 PASS (every point bit-identical to the emulation, mutants 1-3 caught plain and rowmap, the empty-segment guard caught). The test gains --shape mix (12288 x 2048, the 35B GDN layer's mixer) and marks mutant 3 by construction at --mt 1. Co-Authored-By: Claude Fable 5.1 --- src/omega_blackwell_codegen_gemm.c | 58 ++++++++++++++++++++---------- src/omega_blackwell_codegen_gemm.h | 7 ++-- tests/gpu_fp8gemm_test.c | 7 ++-- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/omega_blackwell_codegen_gemm.c b/src/omega_blackwell_codegen_gemm.c index 10bf71b4..5953a514 100644 --- a/src/omega_blackwell_codegen_gemm.c +++ b/src/omega_blackwell_codegen_gemm.c @@ -2,7 +2,8 @@ /* omega_blackwell_codegen_gemm.c: FP8 e4m3 block-scaled grouped GEMM for prefill (OWN-30B builder F item 26). See the * header for the contract. The emitter helpers are copies of omega_blackwell_codegen_moe.c's (same chip-learned * scheduling rules) plus one addition: weight and scale prefetch loads use scoreboards 3 (buffer A) and 4 (buffer B) - * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes. */ + * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes; the + * staging words of x' are loaded one step ahead the same way on scoreboard 5 (L312 lever 3, 2026-10-21). */ #include "omega_blackwell_codegen_gemm.h" #ifndef OMEGA_GPU_NO_POSIX #include @@ -128,6 +129,22 @@ static void ldw_pf(Em *e, BlackwellIROpcode op, int d, int addr64, uint32_t imm, } static void consume(Em *e, unsigned sb) { e->pending |= e->held & (1u << sb); e->held &= ~(1u << sb); } +/* The staging words of one K step (NJ per thread) into xv[], loaded one step AHEAD on scoreboard 5 (L312 lever 3): the + * STS of the step that reads them waits for them (consume(5)), so the x' latency hides behind the previous step's + * compute instead of sitting between its barriers. Addresses in rounds of 4 so the temporaries stay few; every load + * sets SB_RD and the next waits on it (the address read), as every load batch of this file does. xs (plain) or xso (rowmap) + * already point at the step to load. */ +static void x_prefetch(Em *e, uint32_t NJ, uint32_t T, uint32_t ROWW, uint32_t K, int RM, int one, int xs, int xso, const int *xb, const int *xv, int udesc) { + for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { + const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; + int xa[4]; + for (uint32_t q = 0; q < nj; q++) xa[q] = V64(e); + if (e->err) return; + for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } + for (uint32_t q = 0; q < nj; q++) ldw_pf(e, BW_IR_LDG_E, xv[j0 + q], xa[q], 0, udesc, 5); + } +} + static int log2u(uint32_t v) { int l = 0; while ((1u << l) < v) l++; return (1u << l) == v ? l : -1; } static int spec_ok(const OmegaFp8GemmSpec *s) { @@ -220,6 +237,10 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (int q = 0; q < 4; q++) xq[q] = V128(e); for (int b = 0; b < 2; b++) { wq[b] = LB == 16 ? V128(e) : V64(e); sc[b] = V(e); } for (int i = 0; i < 4; i++) fr[i] = V(e); + /* the next K step's staging words, loaded one step ahead (x_prefetch); NJ > 16 (8 warps at mt 16) is not a served shape */ + int xv[16]; + if (NJ > 16u) return -1; + for (uint32_t j = 0; j < NJ; j++) xv[j] = V(e); if (e->err) return -1; /* ---- weight-row loop (uniform per CTA) ---- */ @@ -259,6 +280,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (uint32_t m = 0; m < MT; m++) movrz(e, acc[m]); ldw_pf(e, ldw, wq[0], pwc, 0, udesc, 3); ldw_pf(e, BW_IR_LDG_E, sc[0], psc, 0, udesc, 3); + x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); /* step 0's x' words */ movi(e, cntk, KS / U); /* ---- K loop: U steps per iteration ---- */ @@ -267,17 +289,17 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (uint32_t us = 0; us < U; us++) { const int cur = (int)(us & 1u), nxt = 1 - cur; const unsigned sbc = cur ? 4u : 3u, sbn = nxt ? 4u : 3u; - /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back; the - * staging words go in rounds of 4 so the temporaries stay few */ + /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back */ const int last = us + 1 == U, prefetch = !last || KS > U; - int pwn = -1, psn = -1; + int pwn = -1, psn = -1, nf = -1; if (prefetch) { pwn = V64(e); psn = V64(e); } int sa = V(e); if (e->err) return -1; if (prefetch && !last) { imadw(e, pwn, one, (us + 1) * 32u * LB, pwc); imadw(e, psn, one, spec->mutant == 2 ? 0u : (us + 1) * BPS * 4u, psc); } else if (prefetch) { /* the next iteration's step 0; the last iteration re-reads its own step (harmless, drained after the loop) */ - int nf = V(e), inc = V(e), inc2 = V(e); + int inc = V(e), inc2 = V(e); + nf = V(e); if (e->err) return -1; imadi(e, nf, one, 0, 0xfffffffeu, cntk); /* cntk - 2 */ shr(e, nf, nf, 0, 31); /* 1 iff cntk == 1 (the last iteration) */ @@ -285,18 +307,17 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell imadi(e, inc, nf, 0, U * 32u * LB, NOREG); imadi(e, inc2, nf, 0, spec->mutant == 2 ? 0u : U * BPS * 4u, NOREG); imadw(e, pwn, inc, 1, pwc); imadw(e, psn, inc2, 1, psc); } - for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { - const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; - int xv[4], xa[4]; - for (uint32_t q = 0; q < nj; q++) { xv[q] = V(e); xa[q] = V64(e); } - if (e->err) return -1; - for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } - for (uint32_t q = 0; q < nj; q++) ldg32(e, xv[q], xa[q], udesc, q == 0); - if (prefetch && j0 == 0) { - ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); - ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); - } - for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xv[q]); } + /* stage this step's x' words: they were loaded one step ago (the pass prologue for step 0), scoreboard 5 */ + consume(e, 5); + for (uint32_t j = 0; j < NJ; j++) { imadi(e, sa, one, 0, j * T * 4u, sa0); sts32(e, sa, xv[j]); } + if (prefetch) { + ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); + ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); + /* the next step's x' words, into the registers the STS above has read (its SB_RD wait orders the two); the last + * step of the last iteration re-reads its own step (nf 0), never past the rows */ + if (!last) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } + else { if (RM) imadi(e, xso, nf, 0, ROWW * 4u, xso); else imadw(e, xs, nf, ROWW * 4u, xs); } + x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); } bar_sync(e); consume(e, sbc); @@ -319,7 +340,6 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell else ffma(e, acc[m], dot[m], sc[cur], 0, acc[m]); } bar_sync(e); - if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } imadw(e, pwc, one, U * 32u * LB, pwc); imadw(e, psc, one, spec->mutant == 2 ? 0u : U * BPS * 4u, psc); @@ -327,7 +347,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell isetp_ge_u32(e, cntk, one); bra_if_p0(e, L_k); loop_end(e); - consume(e, 3); consume(e, 4); + consume(e, 3); consume(e, 4); consume(e, 5); /* the last step's re-read x' words land before their registers go out of scope */ /* ---- reduce and store, per row of the pass ---- */ for (uint32_t m = 0; m < MT; m++) diff --git a/src/omega_blackwell_codegen_gemm.h b/src/omega_blackwell_codegen_gemm.h index 74abbcfa..83b35691 100644 --- a/src/omega_blackwell_codegen_gemm.h +++ b/src/omega_blackwell_codegen_gemm.h @@ -16,9 +16,10 @@ * x' rows arrive PRE-PERMUTED by the host (omega_gpu_fp8gemm_api): for a row, column c = s*32*LB + L*LB + w*4 + e * (K step s, lane L, word w, element e) sits at index s*32*LB + (w*32 + L)*4 + e, scaled by 2^64 as the GEMV. The CTA * stages one K step of MT rows (MT*32*LB*4 <= 16384 bytes: the QMD shared-memory limit of omega_blackwell_qmd.h) in - * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage, - * BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s computes (two register - * sets, scoreboards 3 and 4 held until the step that uses them). + * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage (STS of + * words loaded one step ahead), BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s + * computes (two register sets, scoreboards 3 and 4 held until the step that uses them), and so are the staging words of + * x' for step s+1 (scoreboard 5, L312 lever 3): neither latency sits between the barriers. * * Segment table (device, 32 bytes per segment, ctaid.y = segment): { w_va u64, s_va u64, row0 u32, cnt u32, pad[8] }. * Constant bank 0 argument words (cbank + 0x380): diff --git a/tests/gpu_fp8gemm_test.c b/tests/gpu_fp8gemm_test.c index 988d8a24..f94247ec 100644 --- a/tests/gpu_fp8gemm_test.c +++ b/tests/gpu_fp8gemm_test.c @@ -394,6 +394,7 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { if (rc != 0) printf("chip mutant %d: call returned %s: %s\n", m, omega_gpu_fp8gemm_rc_name(rc), omega_gpu_fp8gemm_last_error()); int caught = rc == 0 && b != 0; if (m == 2 && info.k / (32u * info.lane_bytes) < 2) caught = 1; /* single-step k: mutant 2 has no effect by construction */ + if (m == 3 && info.mt < 2) caught = 1; /* one row per pass (--mt 1): mutant 3 has no neighbour row */ CHECK(caught, "%s: chip mutant %d must be caught", S->name, m); printf("chip mutant %d: %s (%zu of %zu outputs differ)\n", m, caught ? "caught" : "NOT CAUGHT", b, (size_t)M * S->n); if (g_out) fprintf(g_out, "%s{\"point\":\"%s mutant %d\",\"caught\":%d}", g_first ? "" : ",", S->name, m, caught), g_first = 0; @@ -452,9 +453,9 @@ int main(int argc, char **argv) { else if (strcmp(argv[i], "--no-evict") == 0) g_evict = 0; else { printf("unknown argument %s\n", argv[i]); return 2; } } - Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 } }; + Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 }, { "mix", 1, 12288, 2048, tokens, 1 } }; unsigned selected = 0; - for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++; + for (unsigned i = 0; i < 6; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++; if (!selected) { fprintf(stderr, "gpu_fp8gemm_test: INVALID shape '%s'\n", shape); return 2; } if (host) host_only(); if (sim) sim_battery(); @@ -463,7 +464,7 @@ int main(int argc, char **argv) { if (ctas) omega_gpu_fp8gemm_set_cta_budget(ctas); (void)omega_gpu_session_set_spin_us(spin); if (out_path) { g_out = test_out_open(out_path); if (g_out) fprintf(g_out, "{\"receipt\":\"OMEGA_GPU_FP8GEMM_V1\",\"reps\":%u,\"evict\":%d,\"tokens\":%u,\"spin_us\":%u,\"points\":[", reps ? reps : 1, g_evict, tokens, omega_gpu_session_spin_us()); } - for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i); + for (unsigned i = 0; i < 6; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i); if (g_out) { fprintf(g_out, "],\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", g_checks, g_failed, !g_checks ? "NOT_RUN" : g_failed ? "FAIL" : "PASS"); fclose(g_out); } omega_gpu_session_close(); } From db8fc080196084efbdd69f76bbee209fb0f4f0bd Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:54:21 -0500 Subject: [PATCH 2/8] fp8gemm: gate L312 lever 3 (x' staging one K step ahead) behind spec.x_ahead, default off (DRA-67, #215) Replaces the unconditional lever-3 program with Hive's gated form (5b73efa): OmegaFp8GemmSpec gains x_ahead (appended after rowmap); x_ahead 0 builds the incumbent program byte for byte, x_ahead 1 loads the next step's staging words on scoreboard 5 (NJ <= 16, spec_ok refuses others). The API turns it on only with AIEN_OMEGA_FP8GEMM_X_AHEAD=1 (read once), so served tokens are unchanged until the stroke gate passes on chip. Host evidence: test-gpu-fp8gemm 74 + 42 PASS (sim battery x_ahead 0 and 1 bit-identical), 5 env-gate checks (src/omega_gpu_fp8gemm_internal.h stroke-spec hook, --spec-of), bw_hazard sweep now covers K 512 and rowmap x x_ahead (fp8gemm 456 kernels, 0 findings), gpr-boundary 310 PASS. Mutants: consume(e,5) dropped -> bw_hazard 2372 of 2632 FAIL; default-on parse -> env-gate FAIL. --- Makefile | 9 +++- src/omega_blackwell_codegen_gemm.c | 58 +++++++++++++++++-------- src/omega_blackwell_codegen_gemm.h | 11 +++-- src/omega_gpu_fp8gemm_api.c | 14 ++++++ src/omega_gpu_fp8gemm_internal.h | 9 ++++ tests/bw_hazard_test.c | 11 ++--- tests/gpu_fp8gemm_test.c | 70 +++++++++++++++++++++++++----- tests/gpu_gpr_boundary_test.c | 10 ++--- 8 files changed, 148 insertions(+), 44 deletions(-) create mode 100644 src/omega_gpu_fp8gemm_internal.h diff --git a/Makefile b/Makefile index 0a8a8b80..4ee615e9 100644 --- a/Makefile +++ b/Makefile @@ -330,11 +330,18 @@ $(OUT_DIR)/gpu_lmhead_fp8_study: tests/gpu_lmhead_fp8_study.c src/omega_gpu_bf16 # permutation, budgets) plus the warp simulator (512 threads); the chip gate is tools/run_gpu_fp8gemm_chip.sh under the GB10 lock. .PHONY: test-gpu-fp8gemm GPU_FP8GEMM_TEST = $(OUT_DIR)/gpu_fp8gemm_test -$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a +$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_gpu_fp8gemm_internal.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_fp8gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +# P-DRA-4 DRA-67: the decode levers are env-gated and OFF by default; --spec-of checks the spec the stroke path resolves. +FP8GEMM_STROKE_GU = --spec-of 2048,16,4,1 test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) $(GPU_FP8GEMM_TEST) --host-only $(GPU_FP8GEMM_TEST) --sim + env -u AIEN_OMEGA_FP8GEMM_X_AHEAD $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=0 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=yes $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=1" + env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,16,8,0 --warps 4 --expect "x_ahead=0" # OWN-30B (2026-10-13): host-only audit that every launcher declares peak + 2 registers (the chip hung at peak + 1). .PHONY: test-gpu-gpr-boundary diff --git a/src/omega_blackwell_codegen_gemm.c b/src/omega_blackwell_codegen_gemm.c index 5953a514..d0ee0987 100644 --- a/src/omega_blackwell_codegen_gemm.c +++ b/src/omega_blackwell_codegen_gemm.c @@ -157,6 +157,7 @@ static int spec_ok(const OmegaFp8GemmSpec *s) { if (ks % 2u && ks > 3u) return 0; /* odd step counts are fully unrolled: at most 3 */ if (s->mutant < 0 || s->mutant > 4) return 0; if (s->rowmap > 1u || (s->rowmap && s->mt > 4u)) return 0; /* the mapped form keeps NJ row bases and MT y rows in registers: mt 8 needs 135 at 16 warps, past the file */ + if (s->x_ahead > 1u || (s->x_ahead && s->mt * s->lane_bytes / s->warps > 16u)) return 0; /* lever 3 holds NJ staging words in registers: NJ > 16 (under 8 warps at mt * lane_bytes 128) is not a served shape */ return 1; } uint32_t omega_fp8gemm_steps(const OmegaFp8GemmSpec *spec) { return spec_ok(spec) ? spec->k / (32u * spec->lane_bytes) : 0; } @@ -237,10 +238,11 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (int q = 0; q < 4; q++) xq[q] = V128(e); for (int b = 0; b < 2; b++) { wq[b] = LB == 16 ? V128(e) : V64(e); sc[b] = V(e); } for (int i = 0; i < 4; i++) fr[i] = V(e); - /* the next K step's staging words, loaded one step ahead (x_prefetch); NJ > 16 (8 warps at mt 16) is not a served shape */ + /* x_ahead (L312 lever 3): the next K step's staging words, loaded one step ahead (x_prefetch) into NJ registers held + * across the step; x_ahead 0 keeps the incumbent program byte for byte (the staging words loaded inside the step) */ + const int XA = spec->x_ahead != 0; int xv[16]; - if (NJ > 16u) return -1; - for (uint32_t j = 0; j < NJ; j++) xv[j] = V(e); + if (XA) for (uint32_t j = 0; j < NJ; j++) xv[j] = V(e); if (e->err) return -1; /* ---- weight-row loop (uniform per CTA) ---- */ @@ -280,7 +282,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell for (uint32_t m = 0; m < MT; m++) movrz(e, acc[m]); ldw_pf(e, ldw, wq[0], pwc, 0, udesc, 3); ldw_pf(e, BW_IR_LDG_E, sc[0], psc, 0, udesc, 3); - x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); /* step 0's x' words */ + if (XA) x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); /* step 0's x' words */ movi(e, cntk, KS / U); /* ---- K loop: U steps per iteration ---- */ @@ -298,8 +300,9 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell if (prefetch && !last) { imadw(e, pwn, one, (us + 1) * 32u * LB, pwc); imadw(e, psn, one, spec->mutant == 2 ? 0u : (us + 1) * BPS * 4u, psc); } else if (prefetch) { /* the next iteration's step 0; the last iteration re-reads its own step (harmless, drained after the loop) */ - int inc = V(e), inc2 = V(e); - nf = V(e); + int inc, inc2; + if (XA) { inc = V(e); inc2 = V(e); nf = V(e); } + else { nf = V(e); inc = V(e); inc2 = V(e); } if (e->err) return -1; imadi(e, nf, one, 0, 0xfffffffeu, cntk); /* cntk - 2 */ shr(e, nf, nf, 0, 31); /* 1 iff cntk == 1 (the last iteration) */ @@ -307,17 +310,34 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell imadi(e, inc, nf, 0, U * 32u * LB, NOREG); imadi(e, inc2, nf, 0, spec->mutant == 2 ? 0u : U * BPS * 4u, NOREG); imadw(e, pwn, inc, 1, pwc); imadw(e, psn, inc2, 1, psc); } - /* stage this step's x' words: they were loaded one step ago (the pass prologue for step 0), scoreboard 5 */ - consume(e, 5); - for (uint32_t j = 0; j < NJ; j++) { imadi(e, sa, one, 0, j * T * 4u, sa0); sts32(e, sa, xv[j]); } - if (prefetch) { - ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); - ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); - /* the next step's x' words, into the registers the STS above has read (its SB_RD wait orders the two); the last - * step of the last iteration re-reads its own step (nf 0), never past the rows */ - if (!last) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } - else { if (RM) imadi(e, xso, nf, 0, ROWW * 4u, xso); else imadw(e, xs, nf, ROWW * 4u, xs); } - x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); + if (XA) { + /* stage this step's x' words: they were loaded one step ago (the pass prologue for step 0), scoreboard 5 */ + consume(e, 5); + for (uint32_t j = 0; j < NJ; j++) { imadi(e, sa, one, 0, j * T * 4u, sa0); sts32(e, sa, xv[j]); } + if (prefetch) { + ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); + ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); + /* the next step's x' words, into the registers the STS above has read (its SB_RD wait orders the two); the + * last step of the last iteration re-reads its own step (nf 0), never past the rows */ + if (!last) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } + else { if (RM) imadi(e, xso, nf, 0, ROWW * 4u, xso); else imadw(e, xs, nf, ROWW * 4u, xs); } + x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); + } + } else { + /* the incumbent: this step's staging words loaded and stored inside the step, in rounds of 4 */ + for (uint32_t j0 = 0; j0 < NJ; j0 += 4) { + const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4; + int xw[4], xa[4]; + for (uint32_t q = 0; q < nj; q++) { xw[q] = V(e); xa[q] = V64(e); } + if (e->err) return -1; + for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); } + for (uint32_t q = 0; q < nj; q++) ldg32(e, xw[q], xa[q], udesc, q == 0); + if (prefetch && j0 == 0) { + ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn); + ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn); + } + for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xw[q]); } + } } bar_sync(e); consume(e, sbc); @@ -340,6 +360,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell else ffma(e, acc[m], dot[m], sc[cur], 0, acc[m]); } bar_sync(e); + if (!XA) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); } } imadw(e, pwc, one, U * 32u * LB, pwc); imadw(e, psc, one, spec->mutant == 2 ? 0u : U * BPS * 4u, psc); @@ -347,7 +368,8 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell isetp_ge_u32(e, cntk, one); bra_if_p0(e, L_k); loop_end(e); - consume(e, 3); consume(e, 4); consume(e, 5); /* the last step's re-read x' words land before their registers go out of scope */ + consume(e, 3); consume(e, 4); + if (XA) consume(e, 5); /* the last step's re-read x' words land before their registers go out of scope */ /* ---- reduce and store, per row of the pass ---- */ for (uint32_t m = 0; m < MT; m++) diff --git a/src/omega_blackwell_codegen_gemm.h b/src/omega_blackwell_codegen_gemm.h index 83b35691..8e5220f4 100644 --- a/src/omega_blackwell_codegen_gemm.h +++ b/src/omega_blackwell_codegen_gemm.h @@ -16,10 +16,10 @@ * x' rows arrive PRE-PERMUTED by the host (omega_gpu_fp8gemm_api): for a row, column c = s*32*LB + L*LB + w*4 + e * (K step s, lane L, word w, element e) sits at index s*32*LB + (w*32 + L)*4 + e, scaled by 2^64 as the GEMV. The CTA * stages one K step of MT rows (MT*32*LB*4 <= 16384 bytes: the QMD shared-memory limit of omega_blackwell_qmd.h) in - * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage (STS of - * words loaded one step ahead), BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s - * computes (two register sets, scoreboards 3 and 4 held until the step that uses them), and so are the staging words of - * x' for step s+1 (scoreboard 5, L312 lever 3): neither latency sits between the barriers. + * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage, + * BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s computes (two register + * sets, scoreboards 3 and 4 held until the step that uses them); with x_ahead 1 (L312 lever 3) so are the staging words + * of x' for step s+1 (scoreboard 5, stored at the start of the step that reads them): neither latency sits between the barriers. * * Segment table (device, 32 bytes per segment, ctaid.y = segment): { w_va u64, s_va u64, row0 u32, cnt u32, pad[8] }. * Constant bank 0 argument words (cbank + 0x380): @@ -67,6 +67,9 @@ typedef struct { * expert on the chip; the x' buffer holds one permuted row per head, the outputs land in head order). 0: the * prefill form, x' row i and y row i are sorted row i. mt <= 4 (registers); the dense trunk of a stroke (one * segment, the heads' rows in head order) needs no map and runs at mt 8. */ + uint32_t x_ahead; /* 1 (L312 lever 3): the staging words of x' for step s+1 are loaded during step s on scoreboard 5 and + * stored at the start of the step that reads them; NJ = mt * lane_bytes / warps <= 16 (registers). 0: the + * incumbent program, byte for byte (the staging words loaded inside the step that stores them). */ } OmegaFp8GemmSpec; int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, BlackwellIRProgram *prog); diff --git a/src/omega_gpu_fp8gemm_api.c b/src/omega_gpu_fp8gemm_api.c index 6487abba..150a99d1 100644 --- a/src/omega_gpu_fp8gemm_api.c +++ b/src/omega_gpu_fp8gemm_api.c @@ -3,6 +3,7 @@ * See the header. Submission path and buffer policy are the FP8 GEMV API's: every buffer both sides touch is * GPU-uncached (nvos.h NVOS32_ATTR2_GPU_CACHEABLE), one launch = omega_gpu_session_launch. */ #include "omega_gpu_fp8gemm_api.h" +#include "omega_gpu_fp8gemm_internal.h" #include "omega_gpu_session.h" #include "omega_gpu_cmdlist.h" #include "omega_gpu_fmt.h" @@ -96,6 +97,14 @@ void omega_gpu_fp8gemm_shape_for(uint32_t k, uint32_t *mt, uint32_t *warps, uint if (mt) *mt = g.mt ? g.mt : 4u; if (warps) *warps = g.warps ? g.warps : 16u; } +/* L312 lever 3: x' staging words one K step ahead, OFF unless AIEN_OMEGA_FP8GEMM_X_AHEAD=1 (read once; P-DRA-4 DRA-67: + * decode changes are env-gated, default off, until the stroke gate passes), and only where the NJ = mt * lane_bytes / + * warps staging words fit the registers the program holds for them (NJ <= 16); call after mt is final */ +static void x_ahead_for(OmegaFp8GemmSpec *spec) { + static int on = -1; + if (on < 0) { const char *e = getenv("AIEN_OMEGA_FP8GEMM_X_AHEAD"); on = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + spec->x_ahead = on && spec->mt * spec->lane_bytes / spec->warps <= 16u ? 1u : 0u; +} /* dense = a few distinct experts with many rows each (qkv, o): 8 rows per pass measured best there */ static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) { memset(spec, 0, sizeof *spec); @@ -103,6 +112,7 @@ static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) { omega_gpu_fp8gemm_shape_for(k, &spec->mt, &spec->warps, &spec->lane_bytes); if (!g.mt && segs < 8u) spec->mt = 8u; spec->mutant = g.mutant; + x_ahead_for(spec); } static int g_rec; /* 1 while a record call runs (lock held): kernel_for must not evict */ @@ -210,6 +220,10 @@ static void spec_for_stroke(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, spec_for(k, segs, spec); if (mt) spec->mt = mt; spec->rowmap = rowmap ? 1u : 0u; + x_ahead_for(spec); +} +void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec) { + spec_for_stroke(k, segs, mt, rowmap, spec); } int omega_gpu_fp8gemm_prepare_shape(uint32_t k, uint32_t segs, uint32_t mt, int rowmap) { OmegaFp8GemmSpec spec; spec_for_stroke(k, segs, mt, rowmap, &spec); diff --git a/src/omega_gpu_fp8gemm_internal.h b/src/omega_gpu_fp8gemm_internal.h new file mode 100644 index 00000000..31b7f1ea --- /dev/null +++ b/src/omega_gpu_fp8gemm_internal.h @@ -0,0 +1,9 @@ +#ifndef OMEGA_GPU_FP8GEMM_INTERNAL_H +#define OMEGA_GPU_FP8GEMM_INTERNAL_H +/* Library-internal view of omega_gpu_fp8gemm_api.c for the host tests. Not part of the public ABI (no manifest entry). */ +#include "omega_blackwell_codegen_gemm.h" +#include +/* The program spec omega_gpu_fp8gemm_prepare_shape / _record would build for (k, segs, mt, rowmap) under the process's + * environment and setters (AIEN_OMEGA_FP8GEMM_X_AHEAD, omega_gpu_fp8gemm_set_shape, ...). Host only: opens no device. */ +void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec); +#endif diff --git a/tests/bw_hazard_test.c b/tests/bw_hazard_test.c index e052b090..eb54a7e4 100644 --- a/tests/bw_hazard_test.c +++ b/tests/bw_hazard_test.c @@ -416,11 +416,12 @@ static void sweep(void) { snprintf(v, sizeof v, "k%u rows%u warps%u depth%u", ks[a], rows, w, dp); if (BUILD(omega_blackwell_codegen_bf16_gemv_prog(&s, &g_prog))) sweep_prog("bf16_gemv", v, P_NONE); } } - /* fp8 grouped GEMM */ - { unsigned ks[] = { 768, 2048, 4096 }; - for (unsigned a = 0; a < 3; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2) { - OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w }; - snprintf(v, sizeof v, "k%u lane%u mt%u warps%u", ks[a], lb, mt, w); + /* fp8 grouped GEMM: the incumbent, rowmap (the stroke's expert form) and x_ahead (L312 lever 3, scoreboard 5) */ + { unsigned ks[] = { 512, 768, 2048, 4096 }; + for (unsigned a = 0; a < 4; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2) + for (unsigned rm = 0; rm <= 1; rm++) for (unsigned xa = 0; xa <= 1; xa++) { + OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w, .rowmap = rm, .x_ahead = xa }; + snprintf(v, sizeof v, "k%u lane%u mt%u warps%u%s%s", ks[a], lb, mt, w, rm ? " rowmap" : "", xa ? " x_ahead" : ""); if (BUILD(omega_blackwell_codegen_fp8gemm_prog(&s, &g_prog))) sweep_prog("fp8gemm", v, P_NONE); } } /* ternary GEMV */ diff --git a/tests/gpu_fp8gemm_test.c b/tests/gpu_fp8gemm_test.c index f94247ec..6ca2302a 100644 --- a/tests/gpu_fp8gemm_test.c +++ b/tests/gpu_fp8gemm_test.c @@ -12,6 +12,7 @@ * Verdict line last: "gpu_fp8gemm_test: N checks, F failed: PASS|FAIL". */ #include "omega_gpu_fp8gemm_api.h" +#include "omega_gpu_fp8gemm_internal.h" #include "omega_gpu_fp8_api.h" #include "omega_gpu_session.h" #include "bw_warp_sim_k.h" @@ -118,19 +119,35 @@ static void host_only(void) { CHECK(p[(1 * 32 + 5) * 4 + 2] / 18446744073709551616.0f == x[86], "column 86 sits at lane 5 word 1 element 2"); } struct { uint32_t k, lb, mt, w; } shp[] = { { 2048, 16, 8, 16 }, { 4096, 16, 8, 16 }, { 1024, 16, 8, 16 }, { 768, 8, 8, 16 }, { 768, 8, 8, 8 }, { 2048, 8, 8, 16 }, { 2048, 16, 4, 16 }, { 2048, 16, 8, 32 }, { 2048, 16, 8, 8 }, { 2048, 16, 4, 8 }, { 4096, 16, 4, 8 } }; for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) for (int m = 0; m <= 3; m++) { - OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0 }; uint32_t n = 0, gp = 0; + OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0, 0 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); uint32_t decl = ((gp + 1 + 7) / 8) * 8; CHECK(rc == 0 && n <= 1024, "codegen k %u lb %u mt %u warps %u mutant %d: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, m, rc, n, gp); if (m == 0 && rc == 0) printf("codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u, register file %u of 65536)%s, shared %u B\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT", omega_fp8gemm_shared_bytes(&s)); } - { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); } - { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 5, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 5 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); } - { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); } + { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); } + { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 5, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 5 refused"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); } + /* L312 lever 3 (x_ahead): every shape above and the rowmap form at mt 4 build with the NJ prefetch registers (fit is + * printed as above: warps 32 does not fit either way); NJ > 16 and x_ahead 2 are refused */ + for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) { + OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, 0, 0, 1 }; uint32_t n = 0, gp = 0; + int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); + uint32_t decl = ((gp + 1 + 7) / 8) * 8; + CHECK(rc == 0 && n <= 1024, "x_ahead codegen k %u lb %u mt %u warps %u: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, rc, n, gp); + if (rc == 0) printf("x_ahead codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u)%s\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT"); + } + { OmegaFp8GemmSpec s = { 2048, 16, 4, 16, 0, 1, 1 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); + uint32_t decl = ((gp + 1 + 7) / 8) * 8; + CHECK(rc == 0 && 32u * s.warps * decl <= 65536u, "x_ahead rowmap mt 4: rc %d gprs %u", rc, gp); + printf("x_ahead codegen k 2048 lane 16 mt 4 warps 16 rowmap: %u instructions, %u registers (declared %u)\n", n, gp, decl); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 4, 0, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead at NJ 32 refused (registers)"); + s.x_ahead = 0; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) == 0, "the same shape without x_ahead is accepted"); } + { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead 2 refused"); } { uint32_t ks[] = { 2048, 4096, 512, 768 }; for (unsigned i = 0; i < 4; i++) { - OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1 }; uint32_t n = 0, gp = 0; + OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1, 0 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp); uint32_t decl = ((gp + 1 + 7) / 8) * 8; CHECK(rc == 0 && n <= 1024 && 32u * s.warps * decl <= 65536u, "codegen k %u mt 4 rowmap: rc %d insns %u gprs %u", ks[i], rc, n, gp); @@ -143,10 +160,11 @@ static void host_only(void) { /* ------------------------------------------------------------- simulator */ static uint64_t g_sim_issues; +static uint32_t g_xa; /* the battery runs once with x_ahead 0 (the incumbent) and once with x_ahead 1 (L312 lever 3) */ typedef struct { uint32_t k, n, lb, mt, w, grid; uint32_t counts[4]; uint32_t nseg; } SimPt; static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_t msgn, size_t *bad) { static BlackwellIRProgram prog; - OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0 }; + OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0, g_xa }; if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; } uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g]; Weights W; weights_make(&W, p->nseg, p->n, p->k, seed); @@ -198,7 +216,7 @@ static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_ * result must equal the emulation moved through YMAP and differ from the unmoved one. budget: the simulator's step budget. */ static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int empty_at, uint64_t budget, char *msg, size_t msgn, size_t *bad, int *moved) { static BlackwellIRProgram prog; - OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap }; + OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap, g_xa }; if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; } uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g]; Weights W; weights_make(&W, p->nseg, p->n, p->k, seed); @@ -268,7 +286,8 @@ static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int return err; } -static void sim_battery(void) { +static void sim_battery_one(void) { + printf("sim battery, x_ahead %u\n", g_xa); SimPt pts[] = { { 2048, 40, 16, 8, 16, 2, { 1, 5, 9 }, 3 }, /* lane 16, KS 4 (2 iterations), 2 passes in segment 3, row clamping (n 40 < 2 x 32 x 1) */ { 4096, 20, 16, 8, 16, 1, { 3, 8 }, 2 }, /* KS 8: 4 iterations */ @@ -325,6 +344,7 @@ static void sim_battery(void) { } printf("sim: %" PRIu64 " warp issues in total\n", g_sim_issues); } +static void sim_battery(void) { for (g_xa = 0; g_xa <= 1; g_xa++) sim_battery_one(); } /* ------------------------------------------------------------- chip */ static int g_evict = 1; @@ -437,8 +457,27 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) { free(ids); free(trow); free(picks); free(x); free(y); free(yref); free(y2); weights_free(&W); } +/* --spec-of K,SEGS,MT,ROWMAP: the spec the stroke path resolves under this process's environment, printed as one line; + * with --expect "f=v ...", every listed field must hold (the env-gate checks of the decode levers: default off). */ +static int spec_of(const char *arg, const char *expect) { + unsigned k = 0, segs = 0, mt = 0, rowmap = 0; + if (sscanf(arg, "%u,%u,%u,%u", &k, &segs, &mt, &rowmap) != 4) { printf("spec-of: bad argument %s\n", arg); return 2; } + OmegaFp8GemmSpec s; omega_gpu_fp8gemm_stroke_spec(k, segs, mt, (int)rowmap, &s); + char line[256]; + snprintf(line, sizeof line, " k=%u lane_bytes=%u mt=%u warps=%u mutant=%d rowmap=%u x_ahead=%u ", s.k, s.lane_bytes, s.mt, s.warps, s.mutant, s.rowmap, s.x_ahead); + printf("spec-of %s:%s\n", arg, line); + if (!expect) return 0; + char want[64]; const char *p = expect; int n = 0, bad = 0; + while (sscanf(p, " %62s%n", want + 1, &n) == 1) { + want[0] = ' '; size_t w = strlen(want); want[w] = ' '; want[w + 1] = 0; + g_checks++; if (!strstr(line, want)) { g_failed++; bad = 1; printf("spec-of %s: FAIL expected%s\n", arg, want); } + p += n; + } + return bad; +} + int main(int argc, char **argv) { - int host = 0, sim = 0; const char *out_path = NULL, *shape = "all"; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64; + int host = 0, sim = 0; const char *out_path = NULL, *shape = "all", *spec_arg = NULL, *expect = NULL; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64; for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--host-only") == 0) host = 1; else if (strcmp(argv[i], "--sim") == 0) sim = 1; @@ -451,8 +490,17 @@ int main(int argc, char **argv) { else if (strcmp(argv[i], "--tokens") == 0 && i + 1 < argc) tokens = (uint32_t)atoi(argv[++i]); else if (strcmp(argv[i], "--spin-us") == 0 && i + 1 < argc) spin = (uint32_t)atoi(argv[++i]); else if (strcmp(argv[i], "--no-evict") == 0) g_evict = 0; + else if (strcmp(argv[i], "--spec-of") == 0 && i + 1 < argc) spec_arg = argv[++i]; + else if (strcmp(argv[i], "--expect") == 0 && i + 1 < argc) expect = argv[++i]; else { printf("unknown argument %s\n", argv[i]); return 2; } } + if (spec_arg) { + if (mt || warps) omega_gpu_fp8gemm_set_shape(mt, warps); + int rc = spec_of(spec_arg, expect); + if (rc == 2 || !expect) return rc; + printf("gpu_fp8gemm_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); + return g_failed ? 1 : 0; + } Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 }, { "mix", 1, 12288, 2048, tokens, 1 } }; unsigned selected = 0; for (unsigned i = 0; i < 6; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++; diff --git a/tests/gpu_gpr_boundary_test.c b/tests/gpu_gpr_boundary_test.c index 21046454..34428ec9 100644 --- a/tests/gpu_gpr_boundary_test.c +++ b/tests/gpu_gpr_boundary_test.c @@ -56,11 +56,11 @@ int main(void) { { unsigned ks[] = { 2048, 4096 }; for (unsigned i = 0; i < 2; i++) { OmegaBf16GemvSpec s; memset(&s, 0, sizeof s); s.k = ks[i]; uint32_t c; omega_gpu_bf16_shape_for(s.k, &s.rows, &s.warps, &s.depth, &c); uint32_t peak = 0, decl = 0; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, &peak) == 0, "bf16 k%u builds", ks[i]); (void)omega_gpu_bf16_kernel_fits(&s, &decl); CHECK(omega_bw_gpr_declared_ok(decl, peak), "bf16 gemv k%u: peak %u declared %u", ks[i], peak, decl); } } - /* fp8 grouped GEMM (all shapes we launch) */ - { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) { - OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0 }; uint32_t peak = 0, decl = 0; - CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u builds", ks[i], mts[j]); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl); - CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u: peak %u declared %u", ks[i], mts[j], peak, decl); } } + /* fp8 grouped GEMM (all shapes we launch, with and without the L312 lever 3 x' prefetch) */ + { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned xa = 0; xa < 2; xa++) for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) { + OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0, xa }; uint32_t peak = 0, decl = 0; + CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u x_ahead %u builds", ks[i], mts[j], xa); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl); + CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u x_ahead %u: peak %u declared %u", ks[i], mts[j], xa, peak, decl); } } /* router and decode attention: the launcher uses omega_bw_gpr_declared(peak) (static), so check the helper on the real peak */ { OmegaRouterSpec s = { .warps = OMEGA_GPU_ROUTER_WARPS, .depth = OMEGA_GPU_ROUTER_DEPTH }; uint32_t peak = 0; CHECK(omega_router_prog_stats(&s, NULL, &peak) == 0 && omega_bw_gpr_declared_ok(omega_bw_gpr_declared(peak), peak), "router peak %u", peak); printf("router peak %u -> declared %u\n", peak, omega_bw_gpr_declared(peak)); } From 3620969f4bed34f0f38a02dabc09e0bf8adfc935 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 08:58:46 -0500 Subject: [PATCH 3/8] tests: q36_dec_sim_test and q36_codegen_hash from omega-mv 6de999da, legacy hash pin (DRA-67, #215) Imports the two host-only Qwen3.6-35B tests that existed only in omega-mv (6de999da + SPDX line) and adds test-q36-dec-sim and test-q36-codegen-hash to HOST_TESTS. test-q36-codegen-hash now fails unless every line of the listing at CUDApp main 4bbccf08 (tests/fixtures/q36_codegen_hash/main-4bbccf08.txt, 509 lines, sha256 54cf5c03...) appears verbatim: levers may add programs, never change an existing one. At this head (lever 3 present, all levers off) the listing is byte-identical to main's (509 lines, same digest). The 143 "refused rc=-1" lines are the enumerator's cartesian sweep hitting spec rules, not defects: dec AXPY (k1) stride 0 9 (gen_axpy: stride == 0) dec GATHER (k5) width 0 or stride 0 15 (gen_gather: N == 0 || IS == 0) dec RES (k2) modes 0/8 (no ADD|COMBINE|NORM) 18 (gen_res: (M & 7) == 0) dec RES ADD and COMBINE together (3,7,11,15) 36 dec RES ROWS|COMBINE with stride 0 (10,14) 18 (L356 rule: stride 16-aligned, nonzero) dec RES COMBINE at width != 2048 (2,6) 12 dec RES width 17408 > RES_MAX_VALS (1,4,5,9,12,13) 18 router depth 3 (depth must be 1, 2, 4 or 8) 15 pattn256 mutant 3, 4 (mutant must be 0..2) 2 143 --- Makefile | 25 +- .../q36_codegen_hash/main-4bbccf08.txt | 509 ++++++++++++++++++ tests/q36_codegen_hash.c | 97 ++++ tests/q36_dec_sim_test.c | 255 +++++++++ 4 files changed, 885 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/q36_codegen_hash/main-4bbccf08.txt create mode 100644 tests/q36_codegen_hash.c create mode 100644 tests/q36_dec_sim_test.c diff --git a/Makefile b/Makefile index 4ee615e9..2c7314c3 100644 --- a/Makefile +++ b/Makefile @@ -343,6 +343,28 @@ test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=1" env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,16,8,0 --warps 4 --expect "x_ahead=0" +# P-DRA-4 DRA-67 (Qwen3.6-35B, sc L306 / L312, ported from omega-mv 6de999da): host-only simulator checks of the decode +# glue kernels, and the codegen hash pin. q36_codegen_hash prints one sha256 line per kernel program (or "refused" where the +# spec rules reject the enumerated combination). test-q36-codegen-hash requires every line of the listing at CUDApp main +# 4bbccf08 (tests/fixtures/q36_codegen_hash/main-4bbccf08.txt) to appear verbatim: levers may add programs, never change one. +.PHONY: test-q36-dec-sim test-q36-codegen-hash +Q36_DEC_SIM_TEST = $(OUT_DIR)/q36_dec_sim_test +$(Q36_DEC_SIM_TEST): tests/q36_dec_sim_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h $(OUT_DIR)/libomega_gpu.a + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/q36_dec_sim_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +test-q36-dec-sim: $(Q36_DEC_SIM_TEST) + $(Q36_DEC_SIM_TEST) +Q36_CODEGEN_HASH = $(OUT_DIR)/q36_codegen_hash +Q36_CODEGEN_BASE = tests/fixtures/q36_codegen_hash/main-4bbccf08.txt +$(Q36_CODEGEN_HASH): tests/q36_codegen_hash.c $(OUT_DIR)/libomega_gpu.a + $(CC) $(CFLAGS) -Itests -o $@ tests/q36_codegen_hash.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +test-q36-codegen-hash: $(Q36_CODEGEN_HASH) + $(Q36_CODEGEN_HASH) > $(OUT_DIR)/q36_codegen_hash.txt + @grep -vxFf $(OUT_DIR)/q36_codegen_hash.txt $(Q36_CODEGEN_BASE) > $(OUT_DIR)/q36_codegen_hash.changed || true + @printf 'q36_codegen_hash: %s lines (digest %s); base %s lines (digest %s); %s base lines changed or missing\n' \ + "$$(wc -l < $(OUT_DIR)/q36_codegen_hash.txt)" "$$(sha256sum < $(OUT_DIR)/q36_codegen_hash.txt | cut -c1-16)" \ + "$$(wc -l < $(Q36_CODEGEN_BASE))" "$$(sha256sum < $(Q36_CODEGEN_BASE) | cut -c1-16)" "$$(wc -l < $(OUT_DIR)/q36_codegen_hash.changed)" + @test ! -s $(OUT_DIR)/q36_codegen_hash.changed || { head -5 $(OUT_DIR)/q36_codegen_hash.changed; echo 'q36_codegen_hash: FAIL'; exit 1; } + # OWN-30B (2026-10-13): host-only audit that every launcher declares peak + 2 registers (the chip hung at peak + 1). .PHONY: test-gpu-gpr-boundary GPU_GPR_BOUNDARY_TEST = $(OUT_DIR)/gpu_gpr_boundary_test @@ -556,7 +578,8 @@ HOST_TESTS = test-drift test-gpu-matmul-api test-gpu-elementwise test-gpu-reconv test-native-artifact zero-cuda-gate verify-vendored test-swap-cli test-om-encoder test-om-spec-encoder test-om-cubin \ test-portable-receipts test-gpu-qmd-shared test-model-capacity test-gpu-qmd-shared-clean-build \ test-omega-slice-runner test-omega-arch-guard test-omega-barrier-contract test-omega-binding-portable \ - test-gpu-imadhi-rc test-dagsim test-costmodel test-gpu-fp8-slots test-bw-hazard test-mufu-ftz $(CARRIED_HOST_TESTS) + test-gpu-imadhi-rc test-dagsim test-costmodel test-gpu-fp8-slots test-bw-hazard test-mufu-ftz test-q36-dec-sim \ + test-q36-codegen-hash $(CARRIED_HOST_TESTS) ifneq ($(CUDAPP_TARGET_ONLY_TESTS),) HOST_TESTS := $(filter-out $(CUDAPP_TARGET_ONLY_TESTS),$(HOST_TESTS)) test-omega-target-only endif diff --git a/tests/fixtures/q36_codegen_hash/main-4bbccf08.txt b/tests/fixtures/q36_codegen_hash/main-4bbccf08.txt new file mode 100644 index 00000000..8ad15b29 --- /dev/null +++ b/tests/fixtures/q36_codegen_hash/main-4bbccf08.txt @@ -0,0 +1,509 @@ +gdn.decode.m0 10752 7259c166e30a6244793b6633362d61f03b8e99fe701e821677ba535ec1f15b59 +gdn.prep.m0 4608 0e40974fa5a06faf38aff0f9e115fd54bfd68638e2fc6694251412353fa8aaff +gdn.scan.m0 8576 b9cf8c8a8ce0ef9030052e1c6ee43de0f40d485a45986929e5f555a550352a50 +gdn.post.m0 1536 70861179244523be8866e0bd60282ae3435adb7b82227b22593fca4acdb2ff7e +gdn.decode.m1 10624 ca4e3da1d7f8dbe316bcd74ef11f76c8514f4b643b01187107e62a1620aa2cd8 +gdn.prep.m1 4608 fd4a85f7f808eb987db99a89c19d0a055f7bda84e6fdd9c0e4c122eba64cf0c0 +gdn.scan.m1 8576 b9cf8c8a8ce0ef9030052e1c6ee43de0f40d485a45986929e5f555a550352a50 +gdn.post.m1 1536 70861179244523be8866e0bd60282ae3435adb7b82227b22593fca4acdb2ff7e +gdn.decode.m2 10624 242d36552f2fed1995ba68d8934bd560a803ae34d80a6817b5efb7eb0338dbb6 +gdn.prep.m2 4608 98cc888a557c05b27be55afe5b9cd5e66f3980feeebec2b988b76be1ebbebcfc +gdn.scan.m2 8576 b9cf8c8a8ce0ef9030052e1c6ee43de0f40d485a45986929e5f555a550352a50 +gdn.post.m2 1536 70861179244523be8866e0bd60282ae3435adb7b82227b22593fca4acdb2ff7e +gdn.decode.m3 10368 5685fc4f7080f5e975cc90a0927215b0b771c3ab55b54ca9778b8d183a5b4811 +gdn.prep.m3 4608 0e40974fa5a06faf38aff0f9e115fd54bfd68638e2fc6694251412353fa8aaff +gdn.scan.m3 8576 b9cf8c8a8ce0ef9030052e1c6ee43de0f40d485a45986929e5f555a550352a50 +gdn.post.m3 1152 487d0cfa435aaea7b62927f55b73a4d2570555419f51706f4ffdac329f5870d4 +gdn.decode.m4 10624 c0f7e0c6db16a2c15c4dc2ae5df5390039ac0e2a1102773449348529b9b37365 +gdn.prep.m4 4608 0e40974fa5a06faf38aff0f9e115fd54bfd68638e2fc6694251412353fa8aaff +gdn.scan.m4 7936 370f20ac55b4c9593bd26e5910fb328540f3cb64320b5b4f8816a8464d6f3ccb +gdn.post.m4 1536 70861179244523be8866e0bd60282ae3435adb7b82227b22593fca4acdb2ff7e +gdn.copy1 512 e08c6fe7867148594dcf6df77b12508bb59ef397f0f93eb01d09098a0f6f040a +gdn.copy2 512 fc014a07116b3c0625e28bf65fca956aa18f305d33347095c846f10f05d5901a +attn256.d1.m0.p0 14080 87365f1df4de844525e0fa92f0a9b5d318ae0a3de010cc24f84432dc9bb804f7 +attn256.d1.m0.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d1.m1.p0 13824 a5e21fd9d80ebf075414a3292364c0c32fb829f974b1b9cc5481780c90dcdb48 +attn256.d1.m1.p1 5120 91928bbafd9498df003325ddaf7593bf85e3a8445faae73dae86d28328ccac41 +attn256.d1.m2.p0 14080 24a0817c9730af2d5f88f96a4aaf711247ded1616a3d9d96aa55eb2820354aff +attn256.d1.m2.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d1.m3.p0 12928 f5926d7685b7dfcbbc966a5d5517734ed88042637a15290cb9510cd3aae89cb3 +attn256.d1.m3.p1 4224 df142f5d0776fe32013fbd2a2a755bbe730e9a03bb76aef63bf6005b91087e6b +attn256.d1.m4.p0 13952 ffaf74aa3edd2755eba415f063fc1a4d4bf6d7a44c8971b4e85074c6e137f82b +attn256.d1.m4.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d1.m5.p0 14080 97943934cc36c4d61886e8e6473673a453ea19f0eaad360a274bf609ca5fadc1 +attn256.d1.m5.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d2.m0.p0 14208 a2f3aaf3542c868c838299f69849049506cb1816af74b7e075493694564b65fa +attn256.d2.m0.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d2.m1.p0 13952 0c5e94b67087df6f962ad2d1b974885a507f0b98cbaafaebf3a4e6c4c8a59f06 +attn256.d2.m1.p1 5120 91928bbafd9498df003325ddaf7593bf85e3a8445faae73dae86d28328ccac41 +attn256.d2.m2.p0 14208 a5256447c12e7d2d96e65ec289114ab3e16641469ba6f652179a1c8bac60f93b +attn256.d2.m2.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d2.m3.p0 13056 d6b12b27d3120677bcc63b8e45cba2128845f5bac9b56cc448ce365486ff100f +attn256.d2.m3.p1 4224 df142f5d0776fe32013fbd2a2a755bbe730e9a03bb76aef63bf6005b91087e6b +attn256.d2.m4.p0 14080 d0cfe11edb87caa78df09b06a2ceb9b696fd777b06fefa61b5db22cd53cee13a +attn256.d2.m4.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d2.m5.p0 14208 40aa6b5f7177185ab954c4b451e23b6d323e405f8f5820bf5ea87bb007f75a73 +attn256.d2.m5.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d3.m0.p0 14336 8550b0858f2d7f7a737721b1709f461ea94956d778c5f442a1cea9538242fe7b +attn256.d3.m0.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d3.m1.p0 14080 43e5c7fa4e18db945882caff25358b69edc275414d3bd1b8bdc2f30a4418910f +attn256.d3.m1.p1 5120 91928bbafd9498df003325ddaf7593bf85e3a8445faae73dae86d28328ccac41 +attn256.d3.m2.p0 14336 4a74e5bc9588eb37b0f9392bf486c2272565f80c9dcef3412f49a253de9ccbff +attn256.d3.m2.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d3.m3.p0 13184 32024ff6f8f9b35de1c3b00599ed49d9fa47b4faed2f94b1f9245692afb0bb45 +attn256.d3.m3.p1 4224 df142f5d0776fe32013fbd2a2a755bbe730e9a03bb76aef63bf6005b91087e6b +attn256.d3.m4.p0 14208 4f6951e5b400640b796c6b2e00702c20a2dc967b3fb8983cbe8fe295228fd5a3 +attn256.d3.m4.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d3.m5.p0 14336 9cc55824878cf00fa33409964c814226d87aabf8177c6bb1743a73fafaa0a54c +attn256.d3.m5.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d4.m0.p0 14464 1e7ddc7d0f46fc2876edb2fe472f2b0ddbe1d3b1e724eb3ab6f6eeeb0d4b94d3 +attn256.d4.m0.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d4.m1.p0 14208 840c3504fe1014d639217ab307f8a788f739f4dbd6c0906bf0229b9c443f44d8 +attn256.d4.m1.p1 5120 91928bbafd9498df003325ddaf7593bf85e3a8445faae73dae86d28328ccac41 +attn256.d4.m2.p0 14464 26f777acfccf1fbe009eec1a976abbca23954845dcc8b6bf4cb5bc99fea318d4 +attn256.d4.m2.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d4.m3.p0 13312 15633650848388f01f0a9387a5afce0ac3397d63fab946feef5c036d75f2c62d +attn256.d4.m3.p1 4224 df142f5d0776fe32013fbd2a2a755bbe730e9a03bb76aef63bf6005b91087e6b +attn256.d4.m4.p0 14336 dbf3ff01c80525f94d7ad6a15efb0a17a258dfb90dddfc38435d9b8dc8857315 +attn256.d4.m4.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +attn256.d4.m5.p0 14464 7424dfab72fed5e83b3ec0ae148f0d3ee4da7a41f8a89afa9df55687e06be051 +attn256.d4.m5.p1 5376 2abdba2799a2f644cf1b86a42603560a72e16e52de038b383cfa383dc7e0c9ee +pattn256.m0 10112 d378f705ed9c04a13075ea760e72c990470f43e77ef5cac1ad5d2f784b639f98 +pattn256.m1 9600 238aa92cd89d1f484c7660ded18bcaf4b38a066c955005b7e24f2d0b57865027 +pattn256.m2 9088 30a2efee28bf38f8ab4e0aad4a719a1e0a8125be8114901dad30b4eb496e9e21 +pattn256.m3 refused rc=-1 +pattn256.m4 refused rc=-1 +router.w8.d1.m0 9088 98dc8df6810a3098d9e285a6b0ab5a5bd5bc119de1c97d057c828ee378a7920f +router.w8.d1.m1 8960 4a1e5dbac3af0eee53eda2d103f0004bd0fb6933446dd85842ca78318a7071e3 +router.w8.d1.m2 9088 b52b233468d06098e029d2a57b6e7af037ae4b211a96b58c597959aad8738473 +router.w8.d1.m3 9088 c30bb57523dfe1c81fc7a3fba68346398d751b4259b2b4a70d10bf4ed34328b4 +router.w8.d1.m4 9088 ebac41cd4f25e5f4c9376bc1fb92d5d8a2c6fa2901697ead1b15224692af4dd2 +router.w8.d2.m0 9088 30320986adcf14ec27c1c221402c622d38d2a8f29061534da4de91dbce9e25ff +router.w8.d2.m1 8960 0b43b85a501fa1531ddabad1101cbf5994ecf2251875039148e7bf5a4717d43a +router.w8.d2.m2 9088 5b4b16f7997df434c269cc187b1e2a6f8e5b91b3a3733918509a3287a3b3619c +router.w8.d2.m3 9088 2d39f21189a5216625afb048a82ce9e6e6840c76dfb166a3d08ed958909068ce +router.w8.d2.m4 9088 930fdbab13fc47669923ddcfb5fee59995bcca26ffc56d6a70d4189af5f1acb6 +router.w8.d3.m0 refused rc=-1 +router.w8.d3.m1 refused rc=-1 +router.w8.d3.m2 refused rc=-1 +router.w8.d3.m3 refused rc=-1 +router.w8.d3.m4 refused rc=-1 +router.w8.d4.m0 9088 b081dd66e4a2ce5301013c77bba6f518a69e88ff70b9e8d5f853065bb234c522 +router.w8.d4.m1 8960 935ef5c02b5e15aece735f7eecf2326e379827e2608ba086d5b02a24df703406 +router.w8.d4.m2 9088 7a6e81770956216fc15fab4dfe4983846cbae7f0427d1d727ef1193034f3d5f8 +router.w8.d4.m3 9088 cc40d30514370c45d51dd05b4c53ea9f731a9a757a694123d09bb0635bdc0f1c +router.w8.d4.m4 9088 090f6afd7e5d17d604c57186104b9251030c39a5f64a5571d4d36a48ec686a79 +router.w16.d1.m0 8704 c61ef8e57c670493a5b734088935866842ca5722b5f19858c9f39a606ca2ce98 +router.w16.d1.m1 8704 a4bbaa07252a71e7f20befdad25f3ff6afbb004d770b0d58a1933c1b79b35a82 +router.w16.d1.m2 8704 0d5b7c8fd4a8c3a89f2a34001a2a94d3176c60165734ebf622cc9b47007c98fa +router.w16.d1.m3 8704 8aa7084fce33610d7707ac778b8ba21b2de282d5b5e52b7c3fb3f0bc7a41b654 +router.w16.d1.m4 8704 005c8c4d5124c1e5eb340a8f4089eae07b812cab3f259e5bf5acccf7d1872755 +router.w16.d2.m0 8704 678b4ce0ccfcba241c23ebf4fe163551412d6ee78a12da3d7881d208e1b0983b +router.w16.d2.m1 8704 9989ce853b40efa846aca96313a135c9a2d0c0ebbcf4b51dd137e15d9b991b8c +router.w16.d2.m2 8704 5e19bdb0f7b5c8d607c9c065054bc0b953987451dc94d97d8b42d1509a482ea5 +router.w16.d2.m3 8704 d0bf391625a3662e9e8f8474a59e9de64824710532baffd1676bc25ff2bdd8ea +router.w16.d2.m4 8704 de90a39fc99d4af026f0bc93c6c7d167e3427a48bfb040282d5921c137ff1f2e +router.w16.d3.m0 refused rc=-1 +router.w16.d3.m1 refused rc=-1 +router.w16.d3.m2 refused rc=-1 +router.w16.d3.m3 refused rc=-1 +router.w16.d3.m4 refused rc=-1 +router.w16.d4.m0 8704 ec72a61ae1af935a4a24e355f9eefd31eae80cd4a0dfa360a479d9bea494d49e +router.w16.d4.m1 8704 97fcc93d473a72b17fa9e7c76b136f8f261bcae847ca1c1874d624bf9a206480 +router.w16.d4.m2 8704 12c4885849d23307399aa8e25e1446cfdfb5114f65cda9989b37cb02729d6622 +router.w16.d4.m3 8704 7a5edf44917f4c5c3e44da456fbb50de70a8f986f765aa454f4bccf3e9314fde +router.w16.d4.m4 8704 3d86102863d4960d04b20da68be5e4ab054c85734adad3afd75b0583bfc8b24d +router.w32.d1.m0 8832 671c2e0415994f5beecd978f13cf53542e5bd7bcac05c3cb052ff3e5959849b0 +router.w32.d1.m1 8832 8637bb49a6d6c9410d72e10f4273e730f301998fb82c121100e6821cc6f7e145 +router.w32.d1.m2 8832 ec9fd961f1d45fdcb9037cb3829302dbb17f44cfe4736ac7cc3c8b95840d45d4 +router.w32.d1.m3 8832 baaf5cdee16db85e0bd49cfced0390246447b50b075c4da2a41df7d538991f4b +router.w32.d1.m4 8832 86e6ccc5dabf61cebf318b03d9067fa5109bd771e600b80f75204c3f6f3f4188 +router.w32.d2.m0 8832 ba4485318658f9007a017d49e1e63350116563f7a118a99e4244ee7775ed0767 +router.w32.d2.m1 8832 e969f0cf3677c2c1741d4a7065e59b27578e050254389a19dd44f0a0a611f11e +router.w32.d2.m2 8832 21c79abd7868b27850f92c2da3d4379804c1faa19eb4d697927435398c6a7c19 +router.w32.d2.m3 8832 50521aa2b2c0cbd616603b9ee4219e095739d12ad29242c81e228e00d9b714b8 +router.w32.d2.m4 8832 99396c104001bd67805c2a0955334dd729518369fbb0a2831038f8947372e9ee +router.w32.d3.m0 refused rc=-1 +router.w32.d3.m1 refused rc=-1 +router.w32.d3.m2 refused rc=-1 +router.w32.d3.m3 refused rc=-1 +router.w32.d3.m4 refused rc=-1 +router.w32.d4.m0 8832 e2361cb65efe1c04eb9bf24eb1527ce6419a4e5402bc67c5ad68143992aff695 +router.w32.d4.m1 8832 ce9a6410998131a2ef72708beb9888fbae0109d2f379e7888b0b57ded1e0f0b7 +router.w32.d4.m2 8832 fa59d91d54f704ac4b86f43389fed53a250db9d20e0375953743308c31e83997 +router.w32.d4.m3 8832 e6875e4a6ec15de1387bdd4cd6cd04d18949bf9ff097bd693a702f296b21b846 +router.w32.d4.m4 8832 1139d6d9f7a9aef22f71ec14c3735d3e25706749a4477fcc00bcd44e3cdd69fb +router256s.rows.w8.d4.m0 10752 6dbd31dfd0d38b3c6d83061ed39af64162793d0be71615ff2d7cd6b4b3613086 +router256s.rows.w8.d4.m6 10752 561f0f8d6c871b593a9f96c3c9a9f35e9f32055e3c355a3e7d8fdb1c7db0b0dc +router256s.rows.w16.d4.m0 10368 a072e029cecb989d5db847bb986d84f48364e1ee0a6f32fe5fb1456c49d40363 +router256s.rows.w16.d4.m6 10368 3093afb107d76696f03094cc1f3a928c1a80244cd176088e8ed00f3ba102cd24 +router256s.rows.w32.d4.m0 10496 8fcfb6387713eef2d8783b79ee8c1a4548dbc6d20fa0206957cb830e4bde8007 +router256s.rows.w32.d4.m6 10496 ef17bcd3411561b3a8b37908569adcd7defb2df6be3df51af3698a672d363e48 +dec.k1.mode0.m0.w0.s0 refused rc=-1 +dec.k1.mode0.m0.w0.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m0.w0.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m0.w5120.s0 refused rc=-1 +dec.k1.mode0.m0.w5120.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m0.w5120.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m0.w17408.s0 refused rc=-1 +dec.k1.mode0.m0.w17408.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m0.w17408.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m1.w0.s0 refused rc=-1 +dec.k1.mode0.m1.w0.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m1.w0.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m1.w5120.s0 refused rc=-1 +dec.k1.mode0.m1.w5120.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m1.w5120.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m1.w17408.s0 refused rc=-1 +dec.k1.mode0.m1.w17408.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m1.w17408.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m2.w0.s0 refused rc=-1 +dec.k1.mode0.m2.w0.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m2.w0.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m2.w5120.s0 refused rc=-1 +dec.k1.mode0.m2.w5120.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m2.w5120.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k1.mode0.m2.w17408.s0 refused rc=-1 +dec.k1.mode0.m2.w17408.s256 512 8e07df9d325283ca9330e76dda51df7cbeb34405f564f08c4c96159e3468bfee +dec.k1.mode0.m2.w17408.s65536 512 aced200962cb0533dc80c31e613f0022a0176c57dda478c7bfb1b707444695ac +dec.k2.mode0.m0.w0.s0 refused rc=-1 +dec.k2.mode0.m0.w5120.s0 refused rc=-1 +dec.k2.mode0.m0.w17408.s0 refused rc=-1 +dec.k2.mode0.m1.w0.s0 refused rc=-1 +dec.k2.mode0.m1.w5120.s0 refused rc=-1 +dec.k2.mode0.m1.w17408.s0 refused rc=-1 +dec.k2.mode0.m2.w0.s0 refused rc=-1 +dec.k2.mode0.m2.w5120.s0 refused rc=-1 +dec.k2.mode0.m2.w17408.s0 refused rc=-1 +dec.k2.mode1.m0.w0.s0 768 f5ca9d1c4f13e4e4c57c84aa47e2c029e29736cd20fce6b14357f61962b62e49 +dec.k2.mode1.m0.w5120.s0 1408 13f66ad33a53a3c2a6e1596b4be9da06c2eb8b9f415b3932cb516a47b13c3f03 +dec.k2.mode1.m0.w17408.s0 refused rc=-1 +dec.k2.mode1.m1.w0.s0 768 f5ca9d1c4f13e4e4c57c84aa47e2c029e29736cd20fce6b14357f61962b62e49 +dec.k2.mode1.m1.w5120.s0 1408 13f66ad33a53a3c2a6e1596b4be9da06c2eb8b9f415b3932cb516a47b13c3f03 +dec.k2.mode1.m1.w17408.s0 refused rc=-1 +dec.k2.mode1.m2.w0.s0 768 f5ca9d1c4f13e4e4c57c84aa47e2c029e29736cd20fce6b14357f61962b62e49 +dec.k2.mode1.m2.w5120.s0 1408 13f66ad33a53a3c2a6e1596b4be9da06c2eb8b9f415b3932cb516a47b13c3f03 +dec.k2.mode1.m2.w17408.s0 refused rc=-1 +dec.k2.mode2.m0.w0.s0 2944 50d692355a9960a9538e902d19e2368d6bcb4097249f82a3f8264b4f4d190af1 +dec.k2.mode2.m0.w5120.s0 refused rc=-1 +dec.k2.mode2.m0.w17408.s0 refused rc=-1 +dec.k2.mode2.m1.w0.s0 2944 50d692355a9960a9538e902d19e2368d6bcb4097249f82a3f8264b4f4d190af1 +dec.k2.mode2.m1.w5120.s0 refused rc=-1 +dec.k2.mode2.m1.w17408.s0 refused rc=-1 +dec.k2.mode2.m2.w0.s0 2688 e3554fe3460d4d7da61b3822573b3290902943835b0fba309b1e0a0974141232 +dec.k2.mode2.m2.w5120.s0 refused rc=-1 +dec.k2.mode2.m2.w17408.s0 refused rc=-1 +dec.k2.mode3.m0.w0.s0 refused rc=-1 +dec.k2.mode3.m0.w5120.s0 refused rc=-1 +dec.k2.mode3.m0.w17408.s0 refused rc=-1 +dec.k2.mode3.m1.w0.s0 refused rc=-1 +dec.k2.mode3.m1.w5120.s0 refused rc=-1 +dec.k2.mode3.m1.w17408.s0 refused rc=-1 +dec.k2.mode3.m2.w0.s0 refused rc=-1 +dec.k2.mode3.m2.w5120.s0 refused rc=-1 +dec.k2.mode3.m2.w17408.s0 refused rc=-1 +dec.k2.mode4.m0.w0.s0 1664 48703b73bcf2813f8946abd13806be20f32a1a1acac68f3cb9faaf349c0b0737 +dec.k2.mode4.m0.w5120.s0 2944 a8f3bc536bb94448f62173ea08e49e6466a32ac04098341c811a3f6ee2b37396 +dec.k2.mode4.m0.w17408.s0 refused rc=-1 +dec.k2.mode4.m1.w0.s0 1536 ed8ca7cba154ea662952e288cdfccb744845641cbcf84ad1031e514df134706c +dec.k2.mode4.m1.w5120.s0 2560 1aa9a4d75a1268f06ef40ce5954f953b1265e535365ff0a264e25396bd5a6ada +dec.k2.mode4.m1.w17408.s0 refused rc=-1 +dec.k2.mode4.m2.w0.s0 1664 48703b73bcf2813f8946abd13806be20f32a1a1acac68f3cb9faaf349c0b0737 +dec.k2.mode4.m2.w5120.s0 2944 a8f3bc536bb94448f62173ea08e49e6466a32ac04098341c811a3f6ee2b37396 +dec.k2.mode4.m2.w17408.s0 refused rc=-1 +dec.k2.mode5.m0.w0.s0 2048 9ce4cf6b77f8272af3384bffadcfb8fa2c447ee0210b47b1a4eab956a895a38d +dec.k2.mode5.m0.w5120.s0 3968 52785c1cdb9db2dcef1e4b626ff0389f6db3e35a4f1b0f96f52058fac43a524d +dec.k2.mode5.m0.w17408.s0 refused rc=-1 +dec.k2.mode5.m1.w0.s0 1920 f46aa01124fe0cd2ca090bcc10676ebe6bbc44d9a8024a7332fbf049950f97e5 +dec.k2.mode5.m1.w5120.s0 3712 f463a6ca475ea0220100005285dfa399c705840bb2edeb8319e164a8602c112f +dec.k2.mode5.m1.w17408.s0 refused rc=-1 +dec.k2.mode5.m2.w0.s0 2048 9ce4cf6b77f8272af3384bffadcfb8fa2c447ee0210b47b1a4eab956a895a38d +dec.k2.mode5.m2.w5120.s0 3968 52785c1cdb9db2dcef1e4b626ff0389f6db3e35a4f1b0f96f52058fac43a524d +dec.k2.mode5.m2.w17408.s0 refused rc=-1 +dec.k2.mode6.m0.w0.s0 4224 52164f37acd2ff92280d8b1aac2d472c4c5d40092ff6b38d8b13e8f8034149af +dec.k2.mode6.m0.w5120.s0 refused rc=-1 +dec.k2.mode6.m0.w17408.s0 refused rc=-1 +dec.k2.mode6.m1.w0.s0 4096 9665b8b57e13d4e1b2e3f7dd90c83ae0a30884e602a9093301fb8fe460f0ca9e +dec.k2.mode6.m1.w5120.s0 refused rc=-1 +dec.k2.mode6.m1.w17408.s0 refused rc=-1 +dec.k2.mode6.m2.w0.s0 3968 c76b32775762149e6478c5337190b23ad6f4cb3731d9888301b09a3c75e3f4fd +dec.k2.mode6.m2.w5120.s0 refused rc=-1 +dec.k2.mode6.m2.w17408.s0 refused rc=-1 +dec.k2.mode7.m0.w0.s0 refused rc=-1 +dec.k2.mode7.m0.w5120.s0 refused rc=-1 +dec.k2.mode7.m0.w17408.s0 refused rc=-1 +dec.k2.mode7.m1.w0.s0 refused rc=-1 +dec.k2.mode7.m1.w5120.s0 refused rc=-1 +dec.k2.mode7.m1.w17408.s0 refused rc=-1 +dec.k2.mode7.m2.w0.s0 refused rc=-1 +dec.k2.mode7.m2.w5120.s0 refused rc=-1 +dec.k2.mode7.m2.w17408.s0 refused rc=-1 +dec.k2.mode8.m0.w0.s0 refused rc=-1 +dec.k2.mode8.m0.w5120.s0 refused rc=-1 +dec.k2.mode8.m0.w17408.s0 refused rc=-1 +dec.k2.mode8.m1.w0.s0 refused rc=-1 +dec.k2.mode8.m1.w5120.s0 refused rc=-1 +dec.k2.mode8.m1.w17408.s0 refused rc=-1 +dec.k2.mode8.m2.w0.s0 refused rc=-1 +dec.k2.mode8.m2.w5120.s0 refused rc=-1 +dec.k2.mode8.m2.w17408.s0 refused rc=-1 +dec.k2.mode9.m0.w0.s0 768 ade18ed0b682cc4a3261d8f8e60de96a99c02c1746d0bc1e4c80599e580387d1 +dec.k2.mode9.m0.w5120.s0 1536 e9758a494886e39fd71b5dcfcf4016180dd7a5a70d6dcb04477af1c4be6c0a04 +dec.k2.mode9.m0.w17408.s0 refused rc=-1 +dec.k2.mode9.m1.w0.s0 768 ade18ed0b682cc4a3261d8f8e60de96a99c02c1746d0bc1e4c80599e580387d1 +dec.k2.mode9.m1.w5120.s0 1536 e9758a494886e39fd71b5dcfcf4016180dd7a5a70d6dcb04477af1c4be6c0a04 +dec.k2.mode9.m1.w17408.s0 refused rc=-1 +dec.k2.mode9.m2.w0.s0 768 ade18ed0b682cc4a3261d8f8e60de96a99c02c1746d0bc1e4c80599e580387d1 +dec.k2.mode9.m2.w5120.s0 1536 e9758a494886e39fd71b5dcfcf4016180dd7a5a70d6dcb04477af1c4be6c0a04 +dec.k2.mode9.m2.w17408.s0 refused rc=-1 +dec.k2.mode10.m0.w0.s0 refused rc=-1 +dec.k2.mode10.m0.w5120.s0 refused rc=-1 +dec.k2.mode10.m0.w17408.s0 refused rc=-1 +dec.k2.mode10.m1.w0.s0 refused rc=-1 +dec.k2.mode10.m1.w5120.s0 refused rc=-1 +dec.k2.mode10.m1.w17408.s0 refused rc=-1 +dec.k2.mode10.m2.w0.s0 refused rc=-1 +dec.k2.mode10.m2.w5120.s0 refused rc=-1 +dec.k2.mode10.m2.w17408.s0 refused rc=-1 +dec.k2.mode11.m0.w0.s0 refused rc=-1 +dec.k2.mode11.m0.w5120.s0 refused rc=-1 +dec.k2.mode11.m0.w17408.s0 refused rc=-1 +dec.k2.mode11.m1.w0.s0 refused rc=-1 +dec.k2.mode11.m1.w5120.s0 refused rc=-1 +dec.k2.mode11.m1.w17408.s0 refused rc=-1 +dec.k2.mode11.m2.w0.s0 refused rc=-1 +dec.k2.mode11.m2.w5120.s0 refused rc=-1 +dec.k2.mode11.m2.w17408.s0 refused rc=-1 +dec.k2.mode12.m0.w0.s0 1664 e2052cb53597993971d118cc58a02e09f0877aa8591fcb568aa8e0c0a7725818 +dec.k2.mode12.m0.w5120.s0 2944 ef01c67fca03850d0f19b3dd6cc966d994e349a1db162042fced5f9abd375f51 +dec.k2.mode12.m0.w17408.s0 refused rc=-1 +dec.k2.mode12.m1.w0.s0 1536 5f9dc32a1e2c67e17876946d404bcdac077a2d2352c80c18c23f60ea7e053c26 +dec.k2.mode12.m1.w5120.s0 2688 76210289c46162cc030cb8a763679a07a7e2554cbdddb459056589d49ca5d69b +dec.k2.mode12.m1.w17408.s0 refused rc=-1 +dec.k2.mode12.m2.w0.s0 1664 e2052cb53597993971d118cc58a02e09f0877aa8591fcb568aa8e0c0a7725818 +dec.k2.mode12.m2.w5120.s0 2944 ef01c67fca03850d0f19b3dd6cc966d994e349a1db162042fced5f9abd375f51 +dec.k2.mode12.m2.w17408.s0 refused rc=-1 +dec.k2.mode13.m0.w0.s0 2176 8f72b9499e67503285773b0ca281fbe940630927d54ffe7558e94a7d504229e8 +dec.k2.mode13.m0.w5120.s0 3968 8f97197bc7d6d4cd7153cdbaeda6771eab15296f4f6afdb5c3ecd6f3ad587066 +dec.k2.mode13.m0.w17408.s0 refused rc=-1 +dec.k2.mode13.m1.w0.s0 2048 14b422536041032b3c4528e270af4b0eb157ac1654f11d698277332feef0e841 +dec.k2.mode13.m1.w5120.s0 3712 783bf2503823d59bc74ab8abef8dec81dee839be78db7014854935b242030c9f +dec.k2.mode13.m1.w17408.s0 refused rc=-1 +dec.k2.mode13.m2.w0.s0 2176 8f72b9499e67503285773b0ca281fbe940630927d54ffe7558e94a7d504229e8 +dec.k2.mode13.m2.w5120.s0 3968 8f97197bc7d6d4cd7153cdbaeda6771eab15296f4f6afdb5c3ecd6f3ad587066 +dec.k2.mode13.m2.w17408.s0 refused rc=-1 +dec.k2.mode14.m0.w0.s0 refused rc=-1 +dec.k2.mode14.m0.w5120.s0 refused rc=-1 +dec.k2.mode14.m0.w17408.s0 refused rc=-1 +dec.k2.mode14.m1.w0.s0 refused rc=-1 +dec.k2.mode14.m1.w5120.s0 refused rc=-1 +dec.k2.mode14.m1.w17408.s0 refused rc=-1 +dec.k2.mode14.m2.w0.s0 refused rc=-1 +dec.k2.mode14.m2.w5120.s0 refused rc=-1 +dec.k2.mode14.m2.w17408.s0 refused rc=-1 +dec.k2.mode15.m0.w0.s0 refused rc=-1 +dec.k2.mode15.m0.w5120.s0 refused rc=-1 +dec.k2.mode15.m0.w17408.s0 refused rc=-1 +dec.k2.mode15.m1.w0.s0 refused rc=-1 +dec.k2.mode15.m1.w5120.s0 refused rc=-1 +dec.k2.mode15.m1.w17408.s0 refused rc=-1 +dec.k2.mode15.m2.w0.s0 refused rc=-1 +dec.k2.mode15.m2.w5120.s0 refused rc=-1 +dec.k2.mode15.m2.w17408.s0 refused rc=-1 +dec.k3.mode0.m0.w0.s0 512 70030e94bd4c5a03912f7b348acefbac582b0215fae3f2b8fcfcc64c7ee759b2 +dec.k3.mode0.m0.w5120.s0 512 5b89617d5c804b0b9377b712d8bc74f2291eafad6f46db779a3309430d188f52 +dec.k3.mode0.m0.w17408.s0 512 e539655ed6a596780de677aae6b08dfde9cc71f6e1eabfba1f7b5fe26fcad733 +dec.k3.mode0.m1.w0.s0 512 cd6157b4c8a92ccb44a2b04fbda200f0668c3930172056950c22497b68be2833 +dec.k3.mode0.m1.w5120.s0 512 c01779ffb1a8f03923558887496e450f5f072fd592a871a95cec45806bd6568f +dec.k3.mode0.m1.w17408.s0 512 989fbdad4ede19e9c761ec1d6e5385f936a109a635ae0c7254dcc795d67e0c0f +dec.k3.mode0.m2.w0.s0 512 70030e94bd4c5a03912f7b348acefbac582b0215fae3f2b8fcfcc64c7ee759b2 +dec.k3.mode0.m2.w5120.s0 512 5b89617d5c804b0b9377b712d8bc74f2291eafad6f46db779a3309430d188f52 +dec.k3.mode0.m2.w17408.s0 512 e539655ed6a596780de677aae6b08dfde9cc71f6e1eabfba1f7b5fe26fcad733 +dec.k4.mode0.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode0.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode0.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode0.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode0.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode0.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode0.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode0.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode0.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode1.m0.w0.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode1.m0.w5120.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode1.m0.w17408.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode1.m1.w0.s0 2432 5837ddf950d9cb233e6acfa071df767359d5b3f7089d0f52d7c57f0146424cf5 +dec.k4.mode1.m1.w5120.s0 2432 5837ddf950d9cb233e6acfa071df767359d5b3f7089d0f52d7c57f0146424cf5 +dec.k4.mode1.m1.w17408.s0 2432 5837ddf950d9cb233e6acfa071df767359d5b3f7089d0f52d7c57f0146424cf5 +dec.k4.mode1.m2.w0.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode1.m2.w5120.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode1.m2.w17408.s0 2560 549472487b7f0d739ccc455d807e589f89f6ef8f2ef7862e0afacfabe723486d +dec.k4.mode2.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode2.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode2.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode2.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode2.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode2.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode2.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode2.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode2.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode3.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode3.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode3.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode3.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode4.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode4.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode4.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode4.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode5.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode5.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode5.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode5.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode6.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode6.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode6.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode6.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode7.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode7.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode7.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode7.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode8.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode8.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode8.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode8.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode9.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode9.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode9.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode9.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode10.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode10.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode10.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode10.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode11.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode11.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode11.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode11.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode12.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode12.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode12.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode12.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode13.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode13.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode13.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode13.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode14.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode14.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode14.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode14.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m0.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m0.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m0.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m1.w0.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode15.m1.w5120.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode15.m1.w17408.s0 2560 8a8d7e742c404a39cf9a522474719384297c009c46ab6dd940ab6e5a2e3e1f42 +dec.k4.mode15.m2.w0.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m2.w5120.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k4.mode15.m2.w17408.s0 2688 4b8dd771194db1297bf54692b856a29d01e850aab1ca5962a1d4980aef620646 +dec.k5.mode0.m0.w0.s0 refused rc=-1 +dec.k5.mode0.m0.w0.s256 refused rc=-1 +dec.k5.mode0.m0.w0.s65536 refused rc=-1 +dec.k5.mode0.m0.w5120.s0 refused rc=-1 +dec.k5.mode0.m0.w5120.s256 512 8aefa876f6289c391cd36e838f77b54899b2c0e5038d4f3fc1a4332a0247d47b +dec.k5.mode0.m0.w5120.s65536 512 7f09481601a07b31e6d3e0e274c00bed23b6675130235aaf198a262907148c93 +dec.k5.mode0.m0.w17408.s0 refused rc=-1 +dec.k5.mode0.m0.w17408.s256 512 9b7fe879f366ddcdefadb4a85a50cb4537ffbcb1299343170df739ef95587098 +dec.k5.mode0.m0.w17408.s65536 512 4a44105cad4b42231f86db81f8893db0a4b16e951fd81009ba37b1cf5b5820a6 +dec.k5.mode0.m1.w0.s0 refused rc=-1 +dec.k5.mode0.m1.w0.s256 refused rc=-1 +dec.k5.mode0.m1.w0.s65536 refused rc=-1 +dec.k5.mode0.m1.w5120.s0 refused rc=-1 +dec.k5.mode0.m1.w5120.s256 512 ff9813b391d2093f853d54b58b476cde80347b79498d85058924e587c7c43d86 +dec.k5.mode0.m1.w5120.s65536 512 46149de1e119a514d5c17eb1a58544599cd7483586e2d28ac1b1b7e8bfbca0b8 +dec.k5.mode0.m1.w17408.s0 refused rc=-1 +dec.k5.mode0.m1.w17408.s256 512 37b2fcf1ade7ab53db534e3fe7422129663758ed21b760dacd31a4c9365e9999 +dec.k5.mode0.m1.w17408.s65536 512 d3ab13c8cceb90447581374b1a5f1a2ca6b802b3ae789e1c333481a05a014c3b +dec.k5.mode0.m2.w0.s0 refused rc=-1 +dec.k5.mode0.m2.w0.s256 refused rc=-1 +dec.k5.mode0.m2.w0.s65536 refused rc=-1 +dec.k5.mode0.m2.w5120.s0 refused rc=-1 +dec.k5.mode0.m2.w5120.s256 512 8aefa876f6289c391cd36e838f77b54899b2c0e5038d4f3fc1a4332a0247d47b +dec.k5.mode0.m2.w5120.s65536 512 7f09481601a07b31e6d3e0e274c00bed23b6675130235aaf198a262907148c93 +dec.k5.mode0.m2.w17408.s0 refused rc=-1 +dec.k5.mode0.m2.w17408.s256 512 9b7fe879f366ddcdefadb4a85a50cb4537ffbcb1299343170df739ef95587098 +dec.k5.mode0.m2.w17408.s65536 512 4a44105cad4b42231f86db81f8893db0a4b16e951fd81009ba37b1cf5b5820a6 +dec.k6.mode0.m0.w0.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k6.mode0.m0.w5120.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k6.mode0.m0.w17408.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k6.mode0.m1.w0.s0 512 6faed703dbe516f93371a0cb08e1163d443a13584de503c5febec1c08aaba58c +dec.k6.mode0.m1.w5120.s0 512 6faed703dbe516f93371a0cb08e1163d443a13584de503c5febec1c08aaba58c +dec.k6.mode0.m1.w17408.s0 512 6faed703dbe516f93371a0cb08e1163d443a13584de503c5febec1c08aaba58c +dec.k6.mode0.m2.w0.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k6.mode0.m2.w5120.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k6.mode0.m2.w17408.s0 512 4b51a712079ebae7d38eff0da1b3a1653cd6dd4f47e206c5416ea558a6876fb8 +dec.k7.g0.m0 3328 d19b62ea820855e59db95cc18e1790fc20d34413e055437afa426370040404f8 +dec.k7.g0.m1 3328 5441611f756960d1e0387add3d0cbdbf13a21e54ef2d924215eee324d2bb910f +dec.k7.g0.m2 3328 af7bbdddfdfae04c80137d2daf90f98b30634ecf7afc7c2f9a7203decff7d3eb +dec.k7.g0.m3 2560 89c0b879a577bac735dab656cbba344a85021b869a95bda5206d33cf96bb0217 +dec.k7.g9.m0 3328 e907982c9f6e6fd03c5685e2505ecc7ebe222c95bfc5d4896518fabf8962f1b6 +dec.k7.g9.m1 3328 c74fe9b2d1602930410c2bddd92c8ee73a9c9960548c0fda785ebdea19b6ccdf +dec.k7.g9.m2 3328 09368bd52cf6e6bb77a3d30d8fb33bd1a8fed9500e28554417d6bf569ed00de6 +dec.k7.g9.m3 2560 2fbe221c1dfe02c3b9ac126d150652624f004eacdb633d7fdbfdd91578e8dff6 diff --git a/tests/q36_codegen_hash.c b/tests/q36_codegen_hash.c new file mode 100644 index 00000000..82ba76e2 --- /dev/null +++ b/tests/q36_codegen_hash.c @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* + * q36_codegen_hash: sha256 of the encoded program of every kernel shape the 27B / 30B engines build (host only, no + * device). Run before and after a shape parameterisation: the old shapes' lines must be byte-identical (Q36, sc L306). + * Extra lines for the new shapes are printed after "# new" (they have no "before"). + */ +#include "omega_blackwell_codegen.h" +#include "omega_blackwell_codegen_gdn.h" +#include "omega_blackwell_codegen_attn256.h" +#include "omega_blackwell_codegen_pattn256.h" +#include "omega_blackwell_codegen_router.h" +#include "omega_blackwell_codegen_dec.h" +#include "sha256.h" +#include +#include +#include + +static BlackwellIRProgram *prog; +static uint8_t code[1u << 22]; + +static void emit(const char *name, int rc) { + size_t len = 0; + if (rc == 0) rc = omega_bw_encode_program(prog, code, sizeof code, &len); + if (rc != 0) { printf("%-40s refused rc=%d\n", name, rc); return; } + uint8_t d[32]; + sha256_ctx c; + sha256_init(&c); sha256_update(&c, code, len); sha256_final(&c, d); + printf("%-40s %7zu ", name, len); + for (int i = 0; i < 32; i++) printf("%02x", d[i]); + printf("\n"); +} + +int main(void) { + prog = calloc(1, sizeof *prog); + char n[64]; + for (int m = 0; m <= 4; m++) { + OmegaGdnSpec s = {.mutant = m}; + snprintf(n, sizeof n, "gdn.decode.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_prog(&s, prog)); + snprintf(n, sizeof n, "gdn.prep.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_prep_prog(&s, prog)); + snprintf(n, sizeof n, "gdn.scan.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_scan_prog(&s, prog)); + snprintf(n, sizeof n, "gdn.post.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_post_prog(&s, prog)); + } + for (int c = 1; c <= 2; c++) { + OmegaGdnSpec s = {.copy = c}; + snprintf(n, sizeof n, "gdn.copy%d", c); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_copy_prog(&s, prog)); + } + for (uint32_t d = 1; d <= 4; d++) + for (int m = 0; m <= 5; m++) + for (uint32_t p = 0; p <= 1; p++) { + OmegaDecodeAttn256Spec s = {.depth = d, .mutant = m, .prep = p}; + snprintf(n, sizeof n, "attn256.d%u.m%d.p%u", d, m, p); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_decode_attn256_prog(&s, prog)); + } + for (int m = 0; m <= 4; m++) { + OmegaPrefillAttn256Spec s = {.mutant = m}; + snprintf(n, sizeof n, "pattn256.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_prefill_attn256_prog(&s, prog)); + } + uint32_t warps[3] = {8, 16, 32}; + for (int w = 0; w < 3; w++) + for (uint32_t d = 1; d <= 4; d++) + for (int m = 0; m <= 4; m++) { + OmegaRouterSpec s = {.warps = warps[w], .depth = d, .mutant = m}; + snprintf(n, sizeof n, "router.w%u.d%u.m%d", warps[w], d, m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_router_prog(&s, prog)); + } + for (int w = 0; w < 3; w++) /* the ROWS form (L312 lever 2) at the stroke's strides, plain and mutant 6 */ + for (int m = 0; m <= 6; m += 6) { + OmegaRouterSpec s = {.warps = warps[w], .depth = 4, .mutant = m, .experts = 256, .shared = 1, .xstride = 8192, .lbstride = 16896}; + snprintf(n, sizeof n, "router256s.rows.w%u.d4.m%d", warps[w], m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_router_prog(&s, prog)); + } + /* the decode glue kernels (RES / SWIGLU / ARGMAX / GATHER / GATE / AXPY) at the widths the 30B and 27B graphs use */ + const uint32_t widths[3] = {0, 5120, 17408}, strides[3] = {0, 256, 65536}; + for (int k = 1; k <= 6; k++) + for (uint32_t mode = 0; mode <= 15; mode++) + for (int m = 0; m <= 2; m++) + for (int wi = 0; wi < 3; wi++) + for (int si = 0; si < 3; si++) { + if ((k != OMEGA_DEC_RES && k != OMEGA_DEC_ARGMAX && mode) || (k != OMEGA_DEC_AXPY && k != OMEGA_DEC_GATHER && si)) continue; + OmegaDecSpec s = {.kind = (OmegaDecKind)k, .mode = mode, .stride = strides[si], .mutant = m, .width = widths[wi]}; + snprintf(n, sizeof n, "dec.k%d.mode%u.m%d.w%u.s%u", k, mode, m, widths[wi], strides[si]); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_dec_prog(&s, prog)); + } + /* GROUP (the stroke v2 sort of N heads x S picks into expert segments): S = 8 (0) and 9 (the 35B), mutants 0..3 */ + for (uint32_t gr = 0; gr <= 9; gr += 9) + for (int m = 0; m <= 3; m++) { + OmegaDecSpec s = {.kind = OMEGA_DEC_GROUP, .groups = gr, .mutant = m}; + snprintf(n, sizeof n, "dec.k7.g%u.m%d", gr, m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_dec_prog(&s, prog)); + } +#ifdef Q36_NEW_SHAPES + printf("# new\n"); + Q36_NEW_SHAPES +#endif + free(prog); + return 0; +} diff --git a/tests/q36_dec_sim_test.c b/tests/q36_dec_sim_test.c new file mode 100644 index 00000000..51078778 --- /dev/null +++ b/tests/q36_dec_sim_test.c @@ -0,0 +1,255 @@ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* + * q36_dec_sim_test: warp-simulator checks of the decode glue kernels at the Qwen3.6-35B-A3B MoE shapes (sc L306): + * RES COMBINE|NORM with 9 groups (8 routed experts + the shared expert in slot 8): x += sum_g w[g] * d[g], then + * y = RMSNorm(x) * nw * scale, against a double oracle; mutants 2 (expert 7 skipped) and 3 (shared slot skipped) + * must be caught. SWIGLU at width 512 over 9 groups (grid 2 x 9) against a double oracle; mutant 1 caught. + * GROUP (L312 v2, the stroke): N heads x 9 slots of expert ids to the grouped-GEMM segment tables and row maps, byte + * for byte against a host sort (heads 1, 2, 3, 8; all heads alike); mutants 1 (no tie-break), 2 (cnt short), 3 (empties + * unwritten) caught. + * COMBINE|NORM in the rows form (L356, one launch for N heads): bit-identical to the one-head program per head (1, 3, + * 8 heads); mutant 3 caught. + * Host only (no device). Verdict line last: "q36_dec_sim_test: N checks, F failed: PASS|FAIL". + */ +#include "omega_blackwell_codegen_dec.h" +#include "bw_warp_sim_k.h" +#include +#include +#include +#include + +static int g_checks, g_failed; +#define CHECK(cond, ...) do { g_checks++; if (!(cond)) { g_failed++; printf("FAIL: "); printf(__VA_ARGS__); printf("\n"); } } while (0) +static uint32_t lcg(uint32_t *s) { *s = *s * 1664525u + 1013904223u; return *s; } +static float frand(uint32_t *s, float lo, float hi) { return lo + (hi - lo) * ((float)(lcg(s) >> 8) / 16777216.0f); } + +#define H 2048u +#define G 9u +#define I 512u +static const float EPS = 1e-6f; +static void put64(WsSim *s, uint32_t off, const void *p) { uintptr_t v = (uintptr_t)p; s->cbank[off / 4] = (uint32_t)v; s->cbank[off / 4 + 1] = (uint32_t)((uint64_t)v >> 32); } + +/* worst relative error of x and y against the oracle, or -1 on a simulator error */ +static double combine_point(int mutant, uint32_t seed, float scale, char *msg, size_t n) { + static BlackwellIRProgram prog; + OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM, .mutant = mutant, .groups = G }; + if (omega_blackwell_codegen_dec_prog(&sp, &prog) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + float *x = aligned_alloc(16, H * 4), *d = aligned_alloc(16, (size_t)G * H * 4), *w = aligned_alloc(16, 64), *nw = aligned_alloc(16, H * 4), *y = aligned_alloc(16, H * 4); + double *xr = malloc(H * sizeof(double)), *yr = malloc(H * sizeof(double)); + uint32_t s = seed; + for (unsigned i = 0; i < H; i++) { x[i] = frand(&s, -2.0f, 2.0f); nw[i] = frand(&s, 0.8f, 1.2f); y[i] = -999.0f; } + for (size_t i = 0; i < (size_t)G * H; i++) d[i] = frand(&s, -1.0f, 1.0f); + for (unsigned g = 0; g < 16; g++) w[g] = g < G ? frand(&s, 0.05f, 0.4f) : 0.0f; + for (unsigned i = 0; i < H; i++) { double m = 0; for (unsigned g = 0; g < G; g++) m += (double)w[g] * d[(size_t)g * H + i]; xr[i] = (double)x[i] + m; } + double ss = 0; for (unsigned i = 0; i < H; i++) ss += xr[i] * xr[i]; + const double r = 1.0 / sqrt(ss / H + (double)EPS); + for (unsigned i = 0; i < H; i++) yr[i] = xr[i] * r * nw[i] * scale; + WsSim sim; memset(&sim, 0, sizeof sim); + static uint8_t smem[OMEGA_DEC_SHARED_BYTES]; + sim.p = &prog; sim.threads = 256; sim.smem = smem; sim.smem_bytes = OMEGA_DEC_SHARED_BYTES; + put64(&sim, OMEGA_DEC_RES_X, x); put64(&sim, OMEGA_DEC_RES_A, d); put64(&sim, OMEGA_DEC_RES_W, w); put64(&sim, OMEGA_DEC_RES_NW, nw); put64(&sim, OMEGA_DEC_RES_Y, y); + memcpy(&sim.cbank[OMEGA_DEC_RES_EPS / 4], &EPS, 4); memcpy(&sim.cbank[OMEGA_DEC_RES_SCALE / 4], &scale, 4); + sim.nranges = 5; + sim.ranges[0] = (WsRange){ (uintptr_t)x, (uintptr_t)x + H * 4 }; sim.ranges[1] = (WsRange){ (uintptr_t)d, (uintptr_t)d + (size_t)G * H * 4 }; + sim.ranges[2] = (WsRange){ (uintptr_t)w, (uintptr_t)w + 64 }; sim.ranges[3] = (WsRange){ (uintptr_t)nw, (uintptr_t)nw + H * 4 }; + sim.ranges[4] = (WsRange){ (uintptr_t)y, (uintptr_t)y + H * 4 }; + double worst = -1; + if (ws_run(&sim, 1, 1) != 0) snprintf(msg, n, "sim: %.150s (pc %d)", sim.msg, sim.err_pc); + else { + worst = 0; + double xmax = 0, ymax = 0; for (unsigned i = 0; i < H; i++) { if (fabs(xr[i]) > xmax) xmax = fabs(xr[i]); if (fabs(yr[i]) > ymax) ymax = fabs(yr[i]); } + for (unsigned i = 0; i < H; i++) { + double ex = fabs((double)x[i] - xr[i]) / xmax, ey = fabs((double)y[i] - yr[i]) / ymax; + if (ex > worst) worst = ex; + if (ey > worst) worst = ey; + } + snprintf(msg, n, "x and y worst rel %.2e", worst); + } + free(x); free(d); free(w); free(nw); free(y); free(xr); free(yr); + return worst; +} + +/* L356: COMBINE|NORM in the rows form (one launch for N heads) against the one-head program run on each head's slice: + * x and y must be bit-identical (the same arithmetic per row); the weights move by a 256-byte stride, the down outputs by + * 9 x 2048 floats per head. Returns the number of differing floats, or -1 on a simulator error. */ +static long rows_point(int mutant, uint32_t heads, uint32_t seed, char *msg, size_t n) { + static BlackwellIRProgram p1, pr; + const uint32_t WS = 256u; /* bytes between heads' weights (the router buffer stride is 256-aligned) */ + OmegaDecSpec s1 = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM, .groups = G }; + OmegaDecSpec sr = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS, .groups = G, .stride = WS, .mutant = mutant }; + if (omega_blackwell_codegen_dec_prog(&s1, &p1) != 0 || omega_blackwell_codegen_dec_prog(&sr, &pr) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + const size_t NX = (size_t)heads * H, ND = (size_t)heads * G * H, NW = (size_t)heads * WS / 4u; + float *x0 = aligned_alloc(16, NX * 4), *x1 = aligned_alloc(16, NX * 4), *xr = aligned_alloc(16, NX * 4), *d = aligned_alloc(16, ND * 4); + float *w = aligned_alloc(16, NW * 4), *nw = aligned_alloc(16, H * 4), *y1 = aligned_alloc(16, NX * 4), *yr = aligned_alloc(16, NX * 4); + uint32_t s = seed; + for (size_t i = 0; i < NX; i++) { x0[i] = frand(&s, -2.0f, 2.0f); y1[i] = yr[i] = -999.0f; } + for (unsigned i = 0; i < H; i++) nw[i] = frand(&s, 0.8f, 1.2f); + for (size_t i = 0; i < ND; i++) d[i] = frand(&s, -1.0f, 1.0f); + for (size_t i = 0; i < NW; i++) w[i] = frand(&s, 0.05f, 0.4f); + memcpy(x1, x0, NX * 4); memcpy(xr, x0, NX * 4); + const float scale = 18446744073709551616.0f; + static uint8_t smem[OMEGA_DEC_SHARED_BYTES]; + long bad = 0; + for (uint32_t h = 0; h <= heads && bad >= 0; h++) { /* h < heads: the one-head program on head h; h == heads: the rows program */ + WsSim sim; memset(&sim, 0, sizeof sim); + const int rows = h == heads; + sim.p = rows ? &pr : &p1; sim.threads = 256; sim.smem = smem; sim.smem_bytes = OMEGA_DEC_SHARED_BYTES; + float *xx = rows ? xr : x1 + (size_t)h * H, *yy = rows ? yr : y1 + (size_t)h * H; + put64(&sim, OMEGA_DEC_RES_X, xx); put64(&sim, OMEGA_DEC_RES_A, rows ? d : d + (size_t)h * G * H); + put64(&sim, OMEGA_DEC_RES_W, rows ? w : w + (size_t)h * WS / 4u); put64(&sim, OMEGA_DEC_RES_NW, nw); put64(&sim, OMEGA_DEC_RES_Y, yy); + memcpy(&sim.cbank[OMEGA_DEC_RES_EPS / 4], &EPS, 4); memcpy(&sim.cbank[OMEGA_DEC_RES_SCALE / 4], &scale, 4); + sim.nranges = 5; + sim.ranges[0] = (WsRange){ (uintptr_t)xx, (uintptr_t)xx + (rows ? NX : H) * 4 }; + sim.ranges[1] = (WsRange){ (uintptr_t)d, (uintptr_t)d + ND * 4 }; + sim.ranges[2] = (WsRange){ (uintptr_t)w, (uintptr_t)w + NW * 4 }; + sim.ranges[3] = (WsRange){ (uintptr_t)nw, (uintptr_t)nw + H * 4 }; + sim.ranges[4] = (WsRange){ (uintptr_t)yy, (uintptr_t)yy + (rows ? NX : H) * 4 }; + if (ws_run(&sim, 1, rows ? heads : 1) != 0) { snprintf(msg, n, "sim (%s): %.150s (pc %d)", rows ? "rows" : "one head", sim.msg, sim.err_pc); bad = -1; } + } + if (bad == 0) { + for (size_t i = 0; i < NX; i++) bad += memcmp(&x1[i], &xr[i], 4) != 0; + for (size_t i = 0; i < NX; i++) bad += memcmp(&y1[i], &yr[i], 4) != 0; + snprintf(msg, n, "%u heads: %ld of %zu x and y floats differ from the one-head program", heads, bad, 2 * NX); + } + free(x0); free(x1); free(xr); free(d); free(w); free(nw); free(y1); free(yr); + return bad; +} + +static double swiglu_point(int mutant, uint32_t seed, char *msg, size_t n) { + static BlackwellIRProgram prog; + OmegaDecSpec sp = { .kind = OMEGA_DEC_SWIGLU, .mutant = mutant, .width = I }; + if (omega_blackwell_codegen_dec_prog(&sp, &prog) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + float *gu = aligned_alloc(16, (size_t)G * 2 * I * 4), *act = aligned_alloc(16, (size_t)G * I * 4); + const float scale = 18446744073709551616.0f; /* 2^64: the FP8 GEMV x' row */ + uint32_t s = seed; + for (size_t i = 0; i < (size_t)G * 2 * I; i++) gu[i] = frand(&s, -4.0f, 4.0f); + for (size_t i = 0; i < (size_t)G * I; i++) act[i] = -999.0f; + WsSim sim; memset(&sim, 0, sizeof sim); + static uint8_t smem[OMEGA_DEC_SHARED_BYTES]; + sim.p = &prog; sim.threads = 256; sim.smem = smem; sim.smem_bytes = OMEGA_DEC_SHARED_BYTES; + put64(&sim, OMEGA_DEC_SW_GU, gu); put64(&sim, OMEGA_DEC_SW_ACT, act); memcpy(&sim.cbank[OMEGA_DEC_SW_SCALE / 4], &scale, 4); + sim.nranges = 2; + sim.ranges[0] = (WsRange){ (uintptr_t)gu, (uintptr_t)gu + (size_t)G * 2 * I * 4 }; sim.ranges[1] = (WsRange){ (uintptr_t)act, (uintptr_t)act + (size_t)G * I * 4 }; + double worst = -1; + if (ws_run(&sim, I / 256u, G) != 0) snprintf(msg, n, "sim: %.150s (pc %d)", sim.msg, sim.err_pc); + else { + worst = 0; + for (unsigned g = 0; g < G; g++) for (unsigned c = 0; c < I; c++) { + const double v = gu[(size_t)g * 2 * I + c], u = gu[(size_t)g * 2 * I + I + c]; + const double ref = v / (1.0 + exp(-v)) * u * scale, got = act[(size_t)g * I + c]; + const double e = fabs(got - ref) / (fabs(ref) + 1e-3 * scale); + if (e > worst) worst = e; + } + snprintf(msg, n, "act worst rel %.2e", worst); + } + free(gu); free(act); + return worst; +} + +/* GROUP (L312 v2): N heads x 9 slots of expert ids -> the two segment tables and the two maps, byte for byte against a + * host sort. all_same: every head picks the same 8 experts (9 segments of cnt N: the heaviest overlap). */ +typedef struct { uint64_t w, s; uint32_t row0, cnt, pad[2]; } Seg; +static uint64_t fake_w(uint32_t id) { return 0x100000ull + (uint64_t)id * 0x1000ull; } +static uint64_t fake_s(uint32_t id) { return 0x900000ull + (uint64_t)id * 0x100ull; } +static int group_point(int mutant, uint32_t heads, int all_same, uint32_t seed, char *msg, size_t n) { + static BlackwellIRProgram prog; + OmegaDecSpec sp = { .kind = OMEGA_DEC_GROUP, .mutant = mutant, .groups = G }; + if (omega_blackwell_codegen_dec_prog(&sp, &prog) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + const uint32_t R = heads * G, STRIDE = 4096u, PAD = OMEGA_DEC_GR_PAD; + uint8_t *lb = aligned_alloc(16, (size_t)heads * STRIDE); memset(lb, 0, (size_t)heads * STRIDE); + Seg *sgu = aligned_alloc(16, (size_t)R * sizeof(Seg)), *sdn = aligned_alloc(16, (size_t)R * sizeof(Seg)); + uint32_t *xm = aligned_alloc(16, (size_t)(R + PAD) * 4), *ym = aligned_alloc(16, (size_t)(R + PAD) * 4); + memset(sgu, 0xEE, (size_t)R * sizeof(Seg)); memset(sdn, 0xEE, (size_t)R * sizeof(Seg)); memset(xm, 0xEE, (size_t)(R + PAD) * 4); memset(ym, 0xEE, (size_t)(R + PAD) * 4); + uint32_t s = seed, ids[16 * G]; + for (uint32_t h = 0; h < heads; h++) { + uint32_t *row = ids + h * G; + if (all_same && h) memcpy(row, ids, G * 4); + else { + for (uint32_t j = 0; j < 8; j++) { int dup; do { row[j] = lcg(&s) % 256u; dup = 0; for (uint32_t q = 0; q < j; q++) if (row[q] == row[j]) dup = 1; } while (dup); } + row[8] = 256u; /* the shared expert */ + } + uint32_t *idp = (uint32_t *)(lb + (size_t)h * STRIDE); uint64_t *tg = (uint64_t *)(lb + (size_t)h * STRIDE + 1024), *td = (uint64_t *)(lb + (size_t)h * STRIDE + 2048); + for (uint32_t j = 0; j < G; j++) { idp[j] = row[j]; tg[2 * j] = fake_w(row[j]); tg[2 * j + 1] = fake_s(row[j]); td[2 * j] = fake_w(row[j]) + 7u; td[2 * j + 1] = fake_s(row[j]) + 3u; } + } + /* host reference */ + Seg *egu = calloc(R, sizeof(Seg)), *edn = calloc(R, sizeof(Seg)); uint32_t *exm = calloc(R + PAD, 4), *eym = calloc(R + PAD, 4); + uint32_t rank[16 * G]; + for (uint32_t t = 0; t < R; t++) { uint32_t p = 0; for (uint32_t q = 0; q < R; q++) if (ids[q] * 128u + q < ids[t] * 128u + t) p++; rank[t] = p; exm[p] = t / G; eym[p] = t; } + uint32_t D = 0; + for (uint32_t t = 0; t < R; t++) { + int first = 1; uint32_t cnt = 0, below = 0; + for (uint32_t q = 0; q < R; q++) { if (ids[q] == ids[t]) { cnt++; if (q < t) first = 0; } } + if (!first) continue; + for (uint32_t q = 0; q < R; q++) { int fq = 1; for (uint32_t z = 0; z < q; z++) if (ids[z] == ids[q]) fq = 0; if (fq && ids[q] < ids[t]) below++; } + egu[below] = (Seg){ fake_w(ids[t]), fake_s(ids[t]), rank[t], cnt, { 0, 0 } }; + edn[below] = (Seg){ fake_w(ids[t]) + 7u, fake_s(ids[t]) + 3u, rank[t], cnt, { 0, 0 } }; + D++; + } + WsSim sim; memset(&sim, 0, sizeof sim); + static uint8_t smem[OMEGA_DEC_GR_SHARED_BYTES]; + sim.p = &prog; sim.threads = 256; sim.smem = smem; sim.smem_bytes = OMEGA_DEC_GR_SHARED_BYTES; + put64(&sim, OMEGA_DEC_GR_IDS, lb); put64(&sim, OMEGA_DEC_GR_TGU, lb + 1024); put64(&sim, OMEGA_DEC_GR_TDN, lb + 2048); + put64(&sim, OMEGA_DEC_GR_SGU, sgu); put64(&sim, OMEGA_DEC_GR_SDN, sdn); put64(&sim, OMEGA_DEC_GR_XMAP, xm); put64(&sim, OMEGA_DEC_GR_YMAP, ym); + sim.cbank[OMEGA_DEC_GR_STRIDE / 4] = STRIDE; sim.cbank[OMEGA_DEC_GR_HEADS / 4] = heads; + sim.nranges = 5; + sim.ranges[0] = (WsRange){ (uintptr_t)lb, (uintptr_t)lb + (size_t)heads * STRIDE }; + sim.ranges[1] = (WsRange){ (uintptr_t)sgu, (uintptr_t)sgu + (size_t)R * sizeof(Seg) }; sim.ranges[2] = (WsRange){ (uintptr_t)sdn, (uintptr_t)sdn + (size_t)R * sizeof(Seg) }; + sim.ranges[3] = (WsRange){ (uintptr_t)xm, (uintptr_t)xm + (size_t)(R + PAD) * 4 }; sim.ranges[4] = (WsRange){ (uintptr_t)ym, (uintptr_t)ym + (size_t)(R + PAD) * 4 }; + int bad = -1; + if (ws_run(&sim, 1, 1) != 0) snprintf(msg, n, "sim: %.150s (pc %d)", sim.msg, sim.err_pc); + else { + int bg = memcmp(sgu, egu, (size_t)R * sizeof(Seg)) != 0, bd = memcmp(sdn, edn, (size_t)R * sizeof(Seg)) != 0; + int bx = memcmp(xm, exm, (size_t)(R + PAD) * 4) != 0, by = memcmp(ym, eym, (size_t)(R + PAD) * 4) != 0; + bad = bg + bd + bx + by; + snprintf(msg, n, "heads %u rows %u distinct %u: seg_gu %s, seg_dn %s, xmap %s, ymap %s", heads, R, D, bg ? "WRONG" : "ok", bd ? "WRONG" : "ok", bx ? "WRONG" : "ok", by ? "WRONG" : "ok"); + } + free(lb); free(sgu); free(sdn); free(xm); free(ym); free(egu); free(edn); free(exm); free(eym); + return bad; +} + +int main(void) { + char msg[300]; + { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_ADD | OMEGA_DEC_RES_NORM, .groups = 9 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "groups 9 without COMBINE refused"); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE, .groups = 7 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "groups 7 refused"); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE, .mutant = 3 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "mutant 3 without the shared slot refused"); } + const struct { uint32_t seed; float scale; } pts[] = { { 1, 1.0f }, { 2, 18446744073709551616.0f }, { 3, 1.0f } }; + for (unsigned i = 0; i < 3; i++) { + double w = combine_point(0, pts[i].seed, pts[i].scale, msg, sizeof msg); + CHECK(w >= 0 && w < 2e-6, "COMBINE|NORM 9 groups seed %u: %s", pts[i].seed, msg); + printf("COMBINE|NORM 9 groups seed %u scale %s: %s\n", pts[i].seed, pts[i].scale > 2.0f ? "2^64" : "1", msg); + } + for (int m = 2; m <= 3; m++) { + double w = combine_point(m, 7, 1.0f, msg, sizeof msg); + CHECK(w > 1e-3, "COMBINE mutant %d must be caught: %s", m, msg); + printf("COMBINE mutant %d: %s (%s)\n", m, w > 1e-3 ? "caught" : "NOT CAUGHT", msg); + } + for (uint32_t seed = 11; seed <= 12; seed++) { + double w = swiglu_point(0, seed, msg, sizeof msg); + CHECK(w >= 0 && w < 1e-5, "SWIGLU 512 x 9 seed %u: %s", seed, msg); + printf("SWIGLU width 512 x 9 groups seed %u: %s\n", seed, msg); + } + { double w = swiglu_point(1, 13, msg, sizeof msg); CHECK(w > 1e-3, "SWIGLU mutant 1 must be caught: %s", msg); printf("SWIGLU mutant 1: %s (%s)\n", w > 1e-3 ? "caught" : "NOT CAUGHT", msg); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_GROUP, .groups = 17 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "GROUP 17 slots refused"); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_GROUP, .groups = G }; uint32_t ins = 0, gp = 0; CHECK(omega_dec_prog_stats(&sp, &ins, &gp) == 0, "GROUP codegen"); printf("GROUP 9 slots: %u instructions, %u registers\n", ins, gp); } + const struct { uint32_t heads; int same; uint32_t seed; } gpts[] = { { 8, 0, 21 }, { 8, 1, 22 }, { 1, 0, 23 }, { 3, 0, 24 }, { 8, 0, 25 }, { 2, 1, 26 } }; + for (unsigned i = 0; i < sizeof gpts / sizeof gpts[0]; i++) { + int b = group_point(0, gpts[i].heads, gpts[i].same, gpts[i].seed, msg, sizeof msg); + CHECK(b == 0, "GROUP heads %u%s seed %u: %s", gpts[i].heads, gpts[i].same ? " all-same" : "", gpts[i].seed, msg); + printf("GROUP%s seed %u: %s\n", gpts[i].same ? " all-same" : "", gpts[i].seed, msg); + } + for (int m = 1; m <= 3; m++) { + int b = group_point(m, 8, 0, 27, msg, sizeof msg); + CHECK(b != 0, "GROUP mutant %d must be caught: %s", m, msg); + printf("GROUP mutant %d: %s (%s)\n", m, b != 0 ? "caught" : "NOT CAUGHT", msg); + } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS, .groups = G, .stride = 8 }; + CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "COMBINE rows with a weights stride not a multiple of 16 refused"); } + for (uint32_t hh = 1; hh <= 8; hh += hh < 3 ? 2 : 5) { + long b = rows_point(0, hh, 40 + hh, msg, sizeof msg); + CHECK(b == 0, "COMBINE|NORM rows: %s", msg); + printf("COMBINE|NORM rows (L356): %s\n", msg); + } + { long b = rows_point(3, 8, 49, msg, sizeof msg); CHECK(b > 0, "COMBINE rows mutant 3 must be caught: %s", msg); printf("COMBINE rows mutant 3: %s (%s)\n", b > 0 ? "caught" : "NOT CAUGHT", msg); } + printf("q36_dec_sim_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); + return g_failed ? 1 : 0; +} From e37bb831d3ac722e2a82f3351b450aa5ec0c6bc7 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:03:36 -0500 Subject: [PATCH 4/8] q36 stroke lever 4: GDN step of every head in one launch, AIEN_OMEGA_Q36_GDN_HEADS=1 (DRA-67, #215) Port of omega-mv e29c78e1 (replayed onto 6de999da as 380969f05). One launch per GDN layer steps up to 8 conversations on grid (r, 16 N); each conversation's seven pointers come from a 64-byte table entry (OMEGA_GDN_ARG_TAB) instead of the constant bank. spec.heads = 1 selects the form; the plain program stays byte-identical (q36_codegen_hash: all 509 base lines unchanged, gdn.heads.m0..4 added). - codegen_gdn: OmegaGdnSpec.heads, table layout, key head cy & 15, conversation cy >> 4 (669 insns, peak 120 registers; plain 665, 116). - gdn_api: OmegaGpuGdnHead, omega_gpu_gdn_prepare_heads, omega_gpu_gdn_record_heads. - q36_graph (hand-ported): record_layer_heads takes the heads launch plus one K_PERM_O over attN only when AIEN_OMEGA_Q36_GDN_HEADS=1; set_batch prepares the heads kernel only then. Default OFF: per-head launches. - tests: gpu_gdn_test heads codegen budgets/refusals, sim heads battery (2 conversations bit-identical to plain, f32 and bf16 state, mutants 0..4, negative control entry 1 -> conversation 0), WS_MAX_RANGES 16. Host: test-gpu-gdn 75 (--host-only) + 57 (--sim) checks PASS. Mutant (key head cy & 14): sim heads "conversation 1 differs from its plain launch" FAIL. Chip: NOT_RUN. --- src/omega_blackwell_codegen_gdn.c | 50 ++++++-- src/omega_blackwell_codegen_gdn.h | 18 +++ src/omega_gpu_gdn_api.c | 80 ++++++++++++- src/omega_gpu_gdn_api.h | 13 +++ src/omega_gpu_q36_graph.c | 25 +++- tests/bw_warp_sim_k.h | 2 +- tests/gpu_gdn_test.c | 186 +++++++++++++++++++++++++++++- tests/q36_codegen_hash.c | 2 + 8 files changed, 358 insertions(+), 18 deletions(-) diff --git a/src/omega_blackwell_codegen_gdn.c b/src/omega_blackwell_codegen_gdn.c index c1abd4c6..b7ba7fa1 100644 --- a/src/omega_blackwell_codegen_gdn.c +++ b/src/omega_blackwell_codegen_gdn.c @@ -217,12 +217,16 @@ int omega_gdn_shape(const OmegaGdnSpec *spec, OmegaGdnShape *s) { } int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) { - if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1; + if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4 || spec->heads > 1u) return -1; OmegaGdnShape G; if (omega_gdn_shape(spec, &G)) return -1; const uint32_t RR = G.r, NC = 2u + G.r; (void)RR; (void)NC; const int MUT = spec->mutant; + /* HF: the heads form (header, OMEGA_GDN_ARG_TAB). Every difference from the plain kernel sits behind this flag, so the plain + * program stays byte-identical: the key head is cy & 15 instead of cy, and the seven pointers are LDG.E.64 from the + * conversation's table entry (atab) where the plain kernel does LDC64. */ + const int HF = spec->heads != 0; const uint32_t C_LOG2E = fbits(1.44269504f), C_NLOG2E = fbits(-1.44269504f), C_LN2 = fbits(0.693147181f); const uint32_t C_ONE = fbits(1.0f), C_M1 = fbits(-1.0f), C_INV128 = fbits(1.0f / 128.0f); const float qs = 0.0883883476f; /* 1 / sqrt(128) */ @@ -233,13 +237,28 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra int udesc = UV64(e); int tid = V(e), cx = V(e), cy = V(e), h = V(e), warp = V(e), lane = V(e), one = V(e); int ps = V64(e), sa = V64(e), toff = V(e), sq[16]; + int hk = cy, atab = -1, pqkv = -1, ppar = -1, ptail = -1, pout = -1; /* heads form: fresh registers, loaded here */ + if (HF) { hk = V(e); atab = V64(e); pqkv = V64(e); ppar = V64(e); ptail = V64(e); } for (unsigned r = 0; r < 16; r++) sq[r] = V128(e); if (e->err) return -1; ldcu64(e, udesc, 0x358); - ldc64(e, ps, OMEGA_GDN_ARG_STATE); + if (!HF) ldc64(e, ps, OMEGA_GDN_ARG_STATE); s2r(e, tid, BW_SR_TID_X); s2r(e, cx, BW_SR_CTAID_X); s2r(e, cy, BW_SR_CTAID_Y); movi(e, one, 1); - imadi(e, R(h), R(cy), RR, cx); + if (HF) { + /* conversation cy >> 4, key head cy & 15; the entry's four prologue pointers in one chain (one cache line) */ + int ptab = V64(e), hd = V(e); + if (e->err) return -1; + ldc64(e, ptab, OMEGA_GDN_ARG_TAB); + shr(e, hd, cy, 4); + andi(e, R(hk), R(cy), 15u); + imadw(e, atab, hd, OMEGA_GDN_TAB_ENTRY_BYTES, ptab); + ldg_wide(e, BW_IR_LDG_E_64, ps, atab, OMEGA_GDN_TAB_STATE, udesc, 1); + ldg_wide(e, BW_IR_LDG_E_64, pqkv, atab, OMEGA_GDN_TAB_QKV, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, ppar, atab, OMEGA_GDN_TAB_PAR, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, ptail, atab, OMEGA_GDN_TAB_TAIL, udesc, 0); + } + imadi(e, R(h), R(hk), RR, cx); shr(e, warp, tid, 5); andi(e, R(lane), R(tid), 31u); /* the state element size: 4 (f32) or 2 (bf16, L313); this thread holds rows 16 warp .. +15, columns 4 lane .. +3 */ @@ -251,16 +270,16 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra /* ---- phase A: conv + SiLU of channel A (q or k) and channel V ---- */ int half = V(e), c = V(e), gi = V(e), slv = V(e); - int pqkv = V64(e), ppar = V64(e), ptail = V64(e); + if (!HF) { pqkv = V64(e); ppar = V64(e); ptail = V64(e); } int axA = V64(e), awA = V64(e), atA = V64(e), axV = V64(e), awV = V64(e), atV = V64(e); int xA = V(e), xV = V(e), wA = V128(e), wV = V128(e), tA = V128(e), tV = V128(e); int insc = V(e), accA = V(e), accV = V(e), t1 = V(e), cnl2e = V(e), fone = V(e); if (e->err) return -1; - ldc64(e, pqkv, OMEGA_GDN_ARG_QKV); ldc64(e, ppar, OMEGA_GDN_ARG_PAR); ldc64(e, ptail, OMEGA_GDN_ARG_TAIL); + if (!HF) { ldc64(e, pqkv, OMEGA_GDN_ARG_QKV); ldc64(e, ppar, OMEGA_GDN_ARG_PAR); ldc64(e, ptail, OMEGA_GDN_ARG_TAIL); } ldc32(e, insc, OMEGA_GDN_ARG_IN_SCALE); shr(e, half, tid, 7); andi(e, R(c), R(tid), 127u); - imadi(e, R(gi), R(cy), OMEGA_GDN_HEAD_DIM, tid); /* q channel hk*128 + t; k channel 2048 + hk*128 + (t - 128) */ + imadi(e, R(gi), R(hk), OMEGA_GDN_HEAD_DIM, tid); /* q channel hk*128 + t; k channel 2048 + hk*128 + (t - 128) */ imadi(e, R(gi), R(half), 2048u - 128u, gi); imadw(e, axA, gi, 4u, pqkv); imadw(e, awA, gi, 16u, ppar); imadi(e, R(gi), R(h), OMEGA_GDN_HEAD_DIM, c); /* v channel 4096 + h*128 + c */ @@ -330,7 +349,8 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra int pab = V64(e), aab = V64(e), asc = V64(e), abq = V64(e), scq = V64(e); int xs = V(e), mn = V(e), sp = V(e), dec = V(e), beta = V(e), cl2e = V(e); if (e->err) return -1; - ldc64(e, pab, OMEGA_GDN_ARG_AB); + if (HF) ldg_wide(e, BW_IR_LDG_E_64, pab, atab, OMEGA_GDN_TAB_AB, udesc, 1); + else ldc64(e, pab, OMEGA_GDN_ARG_AB); imadw(e, aab, h, 8u, pab); imadw(e, asc, h, 8u, ppar); ldg_wide(e, BW_IR_LDG_E_64, abq, aab, 0, udesc, 1); ldg_wide(e, BW_IR_LDG_E_64, scq, asc, G.par_scal, udesc, 0); @@ -390,8 +410,13 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra } /* the gate prefetch: z[h] and the norm weight, consumed in phase E */ int pz = V64(e), ppar2 = V64(e), az = V64(e), an = V64(e), zq = V128(e), nq = V128(e); + if (HF) pout = V64(e); if (e->err) return -1; - ldc64(e, pz, OMEGA_GDN_ARG_Z); ldc64(e, ppar2, OMEGA_GDN_ARG_PAR); + if (HF) { /* the entry's last three pointers (out is kept for phase E: after the register peak) */ + ldg_wide(e, BW_IR_LDG_E_64, pz, atab, OMEGA_GDN_TAB_Z, udesc, 1); + ldg_wide(e, BW_IR_LDG_E_64, ppar2, atab, OMEGA_GDN_TAB_PAR, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, pout, atab, OMEGA_GDN_TAB_OUT, udesc, 0); + } else { ldc64(e, pz, OMEGA_GDN_ARG_Z); ldc64(e, ppar2, OMEGA_GDN_ARG_PAR); } imadw(e, az, lane, 16u, pz); imadw(e, az, h, OMEGA_GDN_HEAD_DIM * 4u, az); imadw(e, an, lane, 16u, ppar2); ldg_pf(e, zq, az, 0, udesc, SB_GATE); @@ -410,7 +435,9 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra cross_warp_sum(e, p, pa, one, la); /* ---- phase E: gated RMSNorm, the output ---- */ - int ss = V(e), en = V(e), osc = V(e), pout = V64(e), ao = V64(e), g = V(e); + int ss = V(e), en = V(e), osc = V(e); + if (!HF) pout = V64(e); + int ao = V64(e), g = V(e); if (e->err) return -1; fmul(e, R(ss), R(p[0]), R(p[0])); for (unsigned j = 1; j < 4; j++) ffma(e, R(ss), R(p[j]), R(p[j]), R(ss)); @@ -418,7 +445,8 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra imadi(e, R(ra), R(warp), 4u, NOREG); imadi(e, R(ra), R(one), OMEGA_GDN_SM_RED2, ra); lane0_sts(e, lane, one, ra, R(ss)); bar_sync(e); - ldc32(e, en, OMEGA_GDN_ARG_EPS_NORM); ldc32(e, osc, OMEGA_GDN_ARG_OUT_SCALE); ldc64(e, pout, OMEGA_GDN_ARG_OUT); + ldc32(e, en, OMEGA_GDN_ARG_EPS_NORM); ldc32(e, osc, OMEGA_GDN_ARG_OUT_SCALE); + if (!HF) ldc64(e, pout, OMEGA_GDN_ARG_OUT); lds32(e, R(ss), ra, 0); movi(e, t1, C_INV128); ffma(e, R(ss), R(ss), R(t1), R(en)); @@ -447,7 +475,7 @@ int omega_gdn_prog_stats(const OmegaGdnSpec *spec, uint32_t *insns, uint32_t *gp /* ======== state copy / zero (see the header) ======== */ int omega_blackwell_codegen_gdn_copy_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) { - if (!spec || !prog || spec->mutant || (spec->copy != OMEGA_GDN_COPY && spec->copy != OMEGA_GDN_ZERO)) return -1; + if (!spec || !prog || spec->mutant || spec->heads || (spec->copy != OMEGA_GDN_COPY && spec->copy != OMEGA_GDN_ZERO)) return -1; omega_bw_ir_init(prog); Em em; memset(&em, 0, sizeof em); em.p = prog; Em *e = &em; int udesc = UV64(e), tid = V(e), cx = V(e), w = V(e), pd = V64(e), ad = V64(e), v[4]; diff --git a/src/omega_blackwell_codegen_gdn.h b/src/omega_blackwell_codegen_gdn.h index d82e7c97..d08780c3 100644 --- a/src/omega_blackwell_codegen_gdn.h +++ b/src/omega_blackwell_codegen_gdn.h @@ -66,6 +66,22 @@ #define OMEGA_GDN_ARG_IN_SCALE 0x3c0u /* f32: qkv and z are multiplied by it on read */ #define OMEGA_GDN_ARG_OUT_SCALE 0x3c4u /* f32: y is multiplied by it */ #define OMEGA_GDN_ARGS_WORDS 18u +/* The heads form (L312 lever 4, 2026-10-21): N <= OMEGA_GDN_MAX_HEADS conversations in ONE launch, grid (r, 16 N). CTA (cx, cy) + * does value head (cy & 15) * r + cx of conversation cy >> 4 exactly as the plain launch does it; its seven pointers come from + * a 64-byte table entry (TAB + 64 * conversation: eight u64 in the order of the plain args QKV, Z, AB, PAR, TAIL, STATE, OUT, 0) + * instead of the constant bank, because every conversation's tail, state and parameters are their own allocation. One program + * serves any N (nothing in the code depends on N). Arg words 0..13 are unused (zero); the scalars keep their offsets. */ +#define OMEGA_GDN_ARG_TAB 0x3c8u +#define OMEGA_GDN_HEADS_ARGS_WORDS 20u +#define OMEGA_GDN_MAX_HEADS 8u +#define OMEGA_GDN_TAB_ENTRY_BYTES 64u +#define OMEGA_GDN_TAB_QKV 0u +#define OMEGA_GDN_TAB_Z 8u +#define OMEGA_GDN_TAB_AB 16u +#define OMEGA_GDN_TAB_PAR 24u +#define OMEGA_GDN_TAB_TAIL 32u +#define OMEGA_GDN_TAB_STATE 40u +#define OMEGA_GDN_TAB_OUT 48u /* shared memory map (bytes) */ #define OMEGA_GDN_SM_Q 0u /* q[128] f32, normalised and / sqrt(128) */ @@ -88,6 +104,8 @@ typedef struct { * this field existed); 2 = Qwen3.6-35B-A3B (32 value heads, conv 8192). Appended last. */ uint32_t state_bf16; /* L313: 1 = the state is stored bf16 (round to nearest even on store, exact widen on load), half the * bytes; compute stays f32. 0 = f32 (the program before this field existed). Appended last. */ + uint32_t heads; /* 0: the plain decode kernel (pointers in the constant bank). 1: the heads form (OMEGA_GDN_ARG_TAB), decode + * only (refused with copy; the prefill and multi-token programs ignore it). Appended last (L312 lever 4). */ } OmegaGdnSpec; /* The shape a spec selects (Q36, sc L306). The 27B constants above are the ratio-3 values. */ diff --git a/src/omega_gpu_gdn_api.c b/src/omega_gpu_gdn_api.c index c8fd2be4..cea494b7 100644 --- a/src/omega_gpu_gdn_api.c +++ b/src/omega_gpu_gdn_api.c @@ -38,7 +38,9 @@ struct OmegaGpuGdn { int bf16; /* L313: the state is stored bf16 (AIEN_OMEGA_GDN_STATE_BF16=1 at alloc); set/get_state keep the f32 layout */ OmegaGpuMem stage; /* cached: uncached staging for set_state / get_state, [state of one layer][tail of one layer] */ OmegaGpuScratch pf; /* prefill scratch (see pf_layout) */ + OmegaGpuMem tab; /* the heads form's pointer table, [layers][OMEGA_GDN_MAX_HEADS] entries (uncached; record_heads writes row `layer`) */ }; +#define TAB_ROW_BYTES (OMEGA_GDN_MAX_HEADS * OMEGA_GDN_TAB_ENTRY_BYTES) typedef struct { bool valid; @@ -48,8 +50,8 @@ typedef struct { uint32_t insns; } Slot; -/* the resident kernels: decode, prefill prep, scan, post; the state copy and zero */ -enum { KK_DECODE, KK_PREP, KK_SCAN, KK_POST, KK_COPY, KK_ZERO, KK_MULTI, KK_N }; +/* the resident kernels: decode, prefill prep, scan, post; the state copy and zero; the multi-token decode (L369); the decode heads form (L312 lever 4) */ +enum { KK_DECODE, KK_PREP, KK_SCAN, KK_POST, KK_COPY, KK_ZERO, KK_MULTI, KK_HEADS, KK_N }; static const uint32_t kk_threads[KK_N] = { OMEGA_GDN_THREADS, OMEGA_GDN_PREP_THREADS, OMEGA_GDN_THREADS, OMEGA_GDN_THREADS, OMEGA_GDN_COPY_THREADS, OMEGA_GDN_COPY_THREADS, OMEGA_GDN_THREADS }; static struct { @@ -172,10 +174,13 @@ int omega_gpu_gdn_alloc_ratio(uint32_t layers, uint32_t ratio, OmegaGpuGdn **out if (rc == OMEGA_GPU_GDN_OK && alloc_ts((size_t)layers * g->sh.tail_bytes, &g->tail) != 0) rc = OMEGA_GPU_GDN_CHIP_FAIL; if (rc == OMEGA_GPU_GDN_OK && alloc_ts((size_t)layers * g->sh.state_bytes, &g->state) != 0) rc = OMEGA_GPU_GDN_CHIP_FAIL; if (rc == OMEGA_GPU_GDN_OK && omega_gpu_session_alloc(LB_BYTES, &g->lb) != 0) rc = OMEGA_GPU_GDN_CHIP_FAIL; + if (rc == OMEGA_GPU_GDN_OK && omega_gpu_session_alloc((size_t)layers * TAB_ROW_BYTES, &g->tab) != 0) rc = OMEGA_GPU_GDN_CHIP_FAIL; if (rc == OMEGA_GPU_GDN_OK) { memset(g->par.cpu, 0, (size_t)layers * g->sh.par_bytes); memset(g->lb.cpu, 0, LB_BYTES); - if (omega_gpu_session_sync_to_gpu(&g->par) != 0 || omega_gpu_session_sync_to_gpu(&g->lb) != 0) rc = OMEGA_GPU_GDN_CHIP_FAIL; + memset(g->tab.cpu, 0, (size_t)layers * TAB_ROW_BYTES); + if (omega_gpu_session_sync_to_gpu(&g->par) != 0 || omega_gpu_session_sync_to_gpu(&g->lb) != 0 || omega_gpu_session_sync_to_gpu(&g->tab) != 0) + rc = OMEGA_GPU_GDN_CHIP_FAIL; } /* tail and state start at zero (cached: zeroed by the chip, since a recycled page may still have lines in L2 that a * CPU write would not reach) */ @@ -194,6 +199,7 @@ void omega_gpu_gdn_free(OmegaGpuGdn *g) { if (g->state.cpu) omega_gpu_session_free(&g->state); if (g->lb.cpu) omega_gpu_session_free(&g->lb); if (g->stage.cpu) omega_gpu_session_free(&g->stage); + if (g->tab.cpu) omega_gpu_session_free(&g->tab); omega_gpu_session_scratch_free(&g->pf); omega_gpu_session_unlock(); omega_gpu_host_free(g); @@ -291,7 +297,7 @@ int omega_gpu_gdn_get_state(OmegaGpuGdn *g, uint32_t layer, float *tail, float * /* ---- kernel ---- */ static int kernel_build(unsigned kind, const OmegaGdnSpec *spec, BlackwellIRProgram *prog) { switch (kind) { - case KK_DECODE: return omega_blackwell_codegen_gdn_prog(spec, prog); + case KK_DECODE: case KK_HEADS: return omega_blackwell_codegen_gdn_prog(spec, prog); case KK_PREP: return omega_blackwell_codegen_gdn_prep_prog(spec, prog); case KK_SCAN: return omega_blackwell_codegen_gdn_scan_prog(spec, prog); case KK_POST: return omega_blackwell_codegen_gdn_post_prog(spec, prog); @@ -492,6 +498,72 @@ int omega_gpu_gdn_multi_record(OmegaGpuCmdList *cl, OmegaGpuGdn *g, uint32_t lay return omega_gpu_cmdlist_add(cl, &L) < 0 ? OMEGA_GPU_GDN_CHIP_FAIL : OMEGA_GPU_GDN_OK; } +/* ---- the heads form (L312 lever 4, 2026-10-21): see the header ---- */ +static void heads_spec(const OmegaGpuGdn *g, OmegaGdnSpec *spec) { + memset(spec, 0, sizeof *spec); + spec->mutant = g_k.mutant; spec->ratio = g->ratio; spec->heads = 1; + spec->state_bf16 = (uint32_t)g->bf16; /* L313: the heads form stores the state like the plain decode */ +} + +int omega_gpu_gdn_prepare_heads(OmegaGpuGdn *g) { + if (!g) return OMEGA_GPU_GDN_BAD_ARGS; + OmegaGdnSpec spec; heads_spec(g, &spec); + omega_gpu_session_lock(); + int rc = OMEGA_GPU_GDN_OK; + Slot *ks = NULL; bool hit = false; + if (!dev_open_locked()) rc = OMEGA_GPU_GDN_CHIP_FAIL; + else rc = kernel_for(KK_HEADS, &spec, &ks, &hit); + omega_gpu_session_unlock(); + return rc; +} + +/* Caller holds omega_gpu_session_lock(). */ +int omega_gpu_gdn_record_heads(OmegaGpuCmdList *cl, const OmegaGpuGdnHead *heads, uint32_t n, uint32_t layer, float eps_l2, + float eps_norm, float in_scale, float out_scale) { + if (!cl || !heads || n == 0 || n > OMEGA_GDN_MAX_HEADS || !heads[0].g) return OMEGA_GPU_GDN_BAD_ARGS; + OmegaGpuGdn *g0 = heads[0].g; + if (layer >= g0->layers || !g0->tab.cpu) return OMEGA_GPU_GDN_BAD_ARGS; + if (!isfinite(eps_l2) || !isfinite(eps_norm) || !isfinite(in_scale) || !isfinite(out_scale)) return OMEGA_GPU_GDN_BAD_ARGS; + for (uint32_t i = 0; i < n; i++) { + const OmegaGpuGdn *g = heads[i].g; + if (!g || g->ratio != g0->ratio || g->bf16 != g0->bf16 || g->layers != g0->layers || !heads[i].qkv_va || !heads[i].z_va || !heads[i].ab_va || !heads[i].out_va) + return OMEGA_GPU_GDN_BAD_ARGS; + } + OmegaGdnSpec spec; heads_spec(g0, &spec); + if (!dev_open_locked()) return OMEGA_GPU_GDN_CHIP_FAIL; + Slot *ks = NULL; bool hit = false; + g_rec = 1; + int rc = kernel_for(KK_HEADS, &spec, &ks, &hit); + g_rec = 0; + if (rc != OMEGA_GPU_GDN_OK) return rc; + /* this layer's table row: entry i holds conversation i's seven pointers in the plain args' order */ + uint64_t *row = (uint64_t *)((uint8_t *)g0->tab.cpu + (size_t)layer * TAB_ROW_BYTES); + for (uint32_t i = 0; i < n; i++) { + const OmegaGpuGdn *g = heads[i].g; + uint64_t *en = row + (size_t)i * (OMEGA_GDN_TAB_ENTRY_BYTES / 8u); + en[OMEGA_GDN_TAB_QKV / 8u] = heads[i].qkv_va; en[OMEGA_GDN_TAB_Z / 8u] = heads[i].z_va; en[OMEGA_GDN_TAB_AB / 8u] = heads[i].ab_va; + en[OMEGA_GDN_TAB_PAR / 8u] = g->par.va + (uint64_t)layer * g->sh.par_bytes; + en[OMEGA_GDN_TAB_TAIL / 8u] = g->tail.va + (uint64_t)layer * g->sh.tail_bytes; + en[OMEGA_GDN_TAB_STATE / 8u] = g->state.va + (uint64_t)layer * g->sh.state_bytes; + en[OMEGA_GDN_TAB_OUT / 8u] = heads[i].out_va; en[7] = 0; + } + if (omega_gpu_session_sync_to_gpu(&g0->tab) != 0) return OMEGA_GPU_GDN_CHIP_FAIL; + uint32_t args[OMEGA_GDN_HEADS_ARGS_WORDS]; memset(args, 0, sizeof args); + memcpy(&args[14], &eps_l2, 4); memcpy(&args[15], &eps_norm, 4); memcpy(&args[16], &in_scale, 4); memcpy(&args[17], &out_scale, 4); + const uint64_t tab = g0->tab.va + (uint64_t)layer * TAB_ROW_BYTES; + args[18] = (uint32_t)tab; args[19] = (uint32_t)(tab >> 32); + OmegaGpuLaunch L = { + .code_va = ks->code.va, .gpr_count = omega_bw_gpr_declared(ks->kernel.gpr_count), + .threads_x = OMEGA_GDN_THREADS, .threads_y = 1, .grid_x = g0->sh.r, .grid_y = OMEGA_GDN_GRID_Y * n, + .num_elements = (size_t)g0->sh.vdim * n, + .args = args, .n_args = OMEGA_GDN_HEADS_ARGS_WORDS, .timeout_ms = MARKER_TIMEOUT_MS, + .shared_bytes = OMEGA_GDN_SHARED_BYTES, + }; + if (!omega_bw_gpr_declared_ok(L.gpr_count, ks->kernel.gpr_count)) { omega_gpu_session_set_error("declared registers below peak + 2: refusing to launch"); return OMEGA_GPU_GDN_CHIP_FAIL; } + if (omega_gpu_cmdlist_add(cl, &L) < 0) return OMEGA_GPU_GDN_CHIP_FAIL; + return OMEGA_GPU_GDN_OK; +} + int omega_gpu_gdn_read_out(OmegaGpuGdn *g, float *out) { if (!g || !out) return OMEGA_GPU_GDN_BAD_ARGS; omega_gpu_session_lock(); diff --git a/src/omega_gpu_gdn_api.h b/src/omega_gpu_gdn_api.h index a2300ebc..3a74ee18 100644 --- a/src/omega_gpu_gdn_api.h +++ b/src/omega_gpu_gdn_api.h @@ -76,6 +76,19 @@ int omega_gpu_gdn_step(OmegaGpuGdn *g, uint32_t layer, const float *qkv, const f struct OmegaGpuCmdList; int omega_gpu_gdn_record(struct OmegaGpuCmdList *cl, OmegaGpuGdn *g, uint32_t layer, uint64_t qkv_va, uint64_t z_va, uint64_t ab_va, float eps_l2, float eps_norm, float in_scale, float out_scale, uint64_t *out_va); +/* The heads form (L312 lever 4, 2026-10-21; omega_blackwell_codegen_gdn.h OMEGA_GDN_ARG_TAB): ONE launch steps layer `layer` + * of n <= OMEGA_GDN_MAX_HEADS conversations on grid (r, 16 n), each exactly as omega_gpu_gdn_record steps it alone (the same + * per-thread code: bit-identical). heads[i].g is conversation i's object (all of one ratio and layer count; each carries its + * own parameters, tail and state); its qkv, z, ab and out rows are device addresses of the caller's choosing (out: [vdim] + * f32 per conversation, so the caller can lay the n rows out contiguously). The pointer table row lives in heads[0].g + * ([layers][OMEGA_GDN_MAX_HEADS] entries, written and synced here): a recorded launch stays valid until the next + * record_heads of that object and layer. The heads kernel has its own cache slot; omega_gpu_gdn_prepare_heads makes it + * resident ahead of recording (a cache miss while recording that would evict is refused, as for the plain kernel). + * Caller of record_heads holds omega_gpu_session_lock(). */ +typedef struct { OmegaGpuGdn *g; uint64_t qkv_va, z_va, ab_va, out_va; } OmegaGpuGdnHead; +int omega_gpu_gdn_prepare_heads(OmegaGpuGdn *g); +int omega_gpu_gdn_record_heads(struct OmegaGpuCmdList *cl, const OmegaGpuGdnHead *heads, uint32_t n, uint32_t layer, float eps_l2, + float eps_norm, float in_scale, float out_scale); /* Test helper: the out row the last launch wrote to the launch buffer (after a record + submit, for example). */ int omega_gpu_gdn_read_out(OmegaGpuGdn *g, float *out); const char *omega_gpu_gdn_last_error(void); diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index 31736829..ac0182e5 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -601,6 +601,13 @@ int omega_gpu_q36_graph_record_head_layer(OmegaGpuQ36Graph *g, uint32_t h, uint3 /* ---- the batch (v2, L312): every conversation of a layer in one set of launches, each weight read once per layer ---- */ typedef struct { uint64_t w_va, s_va; uint32_t row0, cnt, pad[2]; } Seg32; _Static_assert(sizeof(Seg32) == OMEGA_GEMM_SEG_BYTES, "segment entry layout"); +/* lever 4 (L312): the GDN step of every head in ONE launch (omega_gpu_gdn_record_heads) instead of one launch per head. + * OFF unless AIEN_OMEGA_Q36_GDN_HEADS=1 (chip-unqualified: the per-head launches stay the default). */ +static int g_gdn_heads = -1; +static int q36_gdn_heads(void) { + if (g_gdn_heads < 0) { const char *e = getenv("AIEN_OMEGA_Q36_GDN_HEADS"); g_gdn_heads = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + return g_gdn_heads; +} int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS; @@ -615,6 +622,8 @@ int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (rc != 0) return OMEGA_GPU_DGRAPH_CHIP_FAIL; /* lever 2: the router once per layer for every head (record_layer_heads; the ROWS kernel has its own cache slot) */ if (g->heads > 1u && omega_gpu_router_prepare_rows(g->cfg.router, H * 4u, g->lo.lb_stride) != OMEGA_GPU_ROUTER_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; + /* lever 4: the GDN step of every head in one launch (record_layer_heads; the heads kernel has its own cache slot) */ + if (q36_gdn_heads() && omega_gpu_gdn_prepare_heads(g->cfg.gdn) != OMEGA_GPU_GDN_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; /* lever 1: the bf16 lm_head read once per group of up to OMEGA_BF16_MAX_XBATCH heads (record_final_heads) */ if (!g->head8) { uint32_t n = 0, k = 0; omega_gpu_bf16_tensor_shape(g->cfg.lm_head, &n, &k); @@ -708,7 +717,21 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons if (!g->layer[l].attn) { if (rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q36_K_AB, omega_gpu_bf16_gemv_rows_record(g->cl, g->layer[l].ab, N, xq0, abN)); if (rc == OMEGA_GPU_DGRAPH_OK) rc = native_record_gemm(g, OMEGA_GPU_Q36_K_MIX, g->layer[l].mix, N, 1, segd, xp, mixN, 0, 0, 0); - for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK; h++) { + if (q36_gdn_heads()) { + /* lever 4: the GDN step of the N heads in ONE launch, each exactly as alone (omega_gpu_gdn_record_heads); the out + * rows land in attN (free in a GDN layer), N x MIXER_OUT apart, so one K_PERM_O moves them all */ + OmegaGpuGdnHead hs[OMEGA_GPU_Q36_MAX_HEADS]; + memset(hs, 0, sizeof hs); + for (uint32_t h = 0; h < N; h++) { + const uint64_t mix_h = mixN + (uint64_t)h * OMEGA_GPU_Q36_GDN_MIX * 4u; + hs[h].g = g->gdn_h[h]; hs[h].qkv_va = mix_h; hs[h].z_va = mix_h + OMEGA_GPU_Q36_GDN_QKV * 4u; + hs[h].ab_va = abN + (uint64_t)h * OMEGA_GPU_Q36_AB * 4u; hs[h].out_va = attN + h * MOS; + } + if (rc == OMEGA_GPU_DGRAPH_OK) + rc = after_op(g, OMEGA_GPU_Q36_K_GDN, omega_gpu_gdn_record_heads(g->cl, hs, N, ki, g->cfg.eps_l2, g->cfg.eps, 1.0f, SCALE_2P64)); + if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_perm(g, K_PERM_O, attN, pt4096, op, OMEGA_GPU_Q36_MIXER_OUT, N); + } + for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK && !q36_gdn_heads(); h++) { const uint64_t mix_h = mixN + (uint64_t)h * OMEGA_GPU_Q36_GDN_MIX * 4u; uint64_t mo = 0; rc = after_op(g, OMEGA_GPU_Q36_K_GDN, omega_gpu_gdn_record(g->cl, g->gdn_h[h], ki, mix_h, mix_h + OMEGA_GPU_Q36_GDN_QKV * 4u, diff --git a/tests/bw_warp_sim_k.h b/tests/bw_warp_sim_k.h index de22fb51..db34538f 100644 --- a/tests/bw_warp_sim_k.h +++ b/tests/bw_warp_sim_k.h @@ -75,7 +75,7 @@ #define WS_MAX_WARPS (WS_MAX_THREADS / WS_WARP) #define WS_MAX_FRAGS 64 #define WS_NBAR BW_RECONV_MAX_BAR -#define WS_MAX_RANGES 8 +#define WS_MAX_RANGES 16 /* the GDN heads form test declares a table and two conversations x 7 buffers (L312 lever 4) */ enum { WS_OK = 0, WS_E_SHFL_SPLIT, WS_E_SHFL_EXITED, WS_E_BAR_SPLIT, WS_E_BSYNC_UNARMED, WS_E_BSSY_REARM, diff --git a/tests/gpu_gdn_test.c b/tests/gpu_gdn_test.c index e0dc71fc..64559900 100644 --- a/tests/gpu_gdn_test.c +++ b/tests/gpu_gdn_test.c @@ -178,6 +178,21 @@ static void host_only(void) { } OmegaGdnSpec bad = { .mutant = 5, .ratio = GDN_TEST_RATIO }; CHECK(omega_gdn_prog_stats(&bad, NULL, NULL) == -1, "mutant 5 refused"); + /* the heads form (L312 lever 4): builds for every mutant within the budgets; refused as a copy spec or with heads > 1 */ + for (int m = 0; m <= 4; m++) { + OmegaGdnSpec sp = { .mutant = m, .ratio = GDN_TEST_RATIO, .heads = 1 }, pl = { .mutant = m, .ratio = GDN_TEST_RATIO }; + uint32_t ni = 0, ng = 0, pi = 0, pg = 0; + int rc = omega_gdn_prog_stats(&sp, &ni, &ng), rp = omega_gdn_prog_stats(&pl, &pi, &pg); + CHECK(rc == 0 && rp == 0 && ni <= BW_MAX_IR_INSNS && ng + 2 <= BW_PHYS_GPR_MAX && ng <= pg + 8, + "heads form mutant %d codegen: rc %d, %u insns, %u registers (plain %u insns, %u registers)", m, rc, ni, ng, pi, pg); + if (m == 0) printf("heads form: %u instructions, peak %u registers (plain %u, %u)\n", ni, ng, pi, pg); + } + { + OmegaGdnSpec h2 = { .ratio = GDN_TEST_RATIO, .heads = 2 }, hc = { .copy = OMEGA_GDN_COPY, .heads = 1 }; + static BlackwellIRProgram cp; + CHECK(omega_gdn_prog_stats(&h2, NULL, NULL) == -1, "heads 2 refused (the flag is 0 or 1)"); + CHECK(omega_blackwell_codegen_gdn_copy_prog(&hc, &cp) == -1, "copy codegen refuses the heads flag"); + } /* the state copy / zero programs (cached tail and state) */ { static BlackwellIRProgram cp; @@ -399,6 +414,113 @@ static void sim_bf16_battery(void) { layer_free(&L); } +/* ---- the heads form on the simulator (L312 lever 4): HN conversations in one grid (RT, 16 HN), every pointer from the table; + * each conversation's out, tail and state must equal its own plain launch bit for bit. Negative control: conversation 1's + * table entry pointed at conversation 0's buffers makes conversation 1 compute conversation 0's step (and leaves its own + * buffers untouched), so the table is really what the kernel reads. ---- */ +#define HN 2u +static int sim_heads_run(int mutant, int control, int bf16, char *msg, size_t n) { + static BlackwellIRProgram plain, heads; + OmegaGdnSpec sp = { .mutant = mutant, .ratio = GDN_TEST_RATIO, .state_bf16 = (uint32_t)bf16 }, sh = { .mutant = mutant, .ratio = GDN_TEST_RATIO, .state_bf16 = (uint32_t)bf16, .heads = 1 }; + if (omega_blackwell_codegen_gdn_prog(&sp, &plain) != 0 || omega_blackwell_codegen_gdn_prog(&sh, &heads) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + const size_t SS = bf16 ? T_STATE_BYTES / 2u : T_STATE_BYTES; /* L313 bf16 state: half the bytes */ + const size_t sz[SB_N] = { CD * 4u, VD * 4u, VH * 8u, T_PAR_BYTES, T_TAIL_BYTES, SS, VD * 4u }; + uint8_t *buf[HN][SB_N], *want[HN][3]; /* want: out, tail, state of the plain launch */ + uint64_t *tab = aligned_alloc(256, 4096); + memset(tab, 0, 4096); + for (unsigned c = 0; c < HN; c++) { + Layer L; layer_make(&L, 41 + c); + Inp in; inp_make(&in, 2000 + c, 1.0f); + for (int i = 0; i < SB_N; i++) buf[c][i] = aligned_alloc(256, (sz[i] + 255) & ~(size_t)255); + memcpy(buf[c][SB_QKV], in.qkv, sz[SB_QKV]); memcpy(buf[c][SB_Z], in.z, sz[SB_Z]); memcpy(buf[c][SB_AB], in.ab, sz[SB_AB]); + omega_gdn_pack_params_r(GDN_TEST_RATIO, L.conv_w, L.a_log, L.dtb, L.nw, buf[c][SB_PAR]); + omega_gdn_pack_tail_r(GDN_TEST_RATIO, L.tail0, (float *)buf[c][SB_TAIL]); + if (bf16) for (size_t i = 0; i < NS; i++) ((uint16_t *)buf[c][SB_STATE])[i] = t_bf16_rn(L.state0[i]); + else memcpy(buf[c][SB_STATE], L.state0, SS); + want[c][0] = malloc(VD * 4u); want[c][1] = malloc(T_TAIL_BYTES); want[c][2] = malloc(SS); + inp_free(&in); layer_free(&L); + } + int err = 0; + /* the plain launch per conversation (its own grid), from the same inputs and states */ + for (unsigned c = 0; c < HN && !err; c++) { + uint8_t *tail_save = malloc(T_TAIL_BYTES), *state_save = malloc(SS); + memcpy(tail_save, buf[c][SB_TAIL], T_TAIL_BYTES); memcpy(state_save, buf[c][SB_STATE], SS); + float *yo = (float *)buf[c][SB_OUT]; + for (unsigned i = 0; i < VD; i++) yo[i] = -999.0f; + WsSim s; memset(&s, 0, sizeof s); + s.p = &plain; s.threads = OMEGA_GDN_THREADS; s.order = 0; + static uint8_t smem[OMEGA_GDN_SHARED_BYTES]; s.smem = smem; s.smem_bytes = OMEGA_GDN_SHARED_BYTES; + for (int i = 0; i < SB_N; i++) { + const uint64_t a = (uintptr_t)buf[c][i]; + s.cbank[(0x380 + 8 * i) / 4] = (uint32_t)a; s.cbank[(0x380 + 8 * i) / 4 + 1] = (uint32_t)(a >> 32); + s.ranges[i].lo = a; s.ranges[i].hi = a + sz[i]; + } + s.nranges = SB_N; + memcpy(&s.cbank[OMEGA_GDN_ARG_EPS_L2 / 4], &EPS_L2, 4); memcpy(&s.cbank[OMEGA_GDN_ARG_EPS_NORM / 4], &EPS_N, 4); + const float one = 1.0f; + memcpy(&s.cbank[OMEGA_GDN_ARG_IN_SCALE / 4], &one, 4); memcpy(&s.cbank[OMEGA_GDN_ARG_OUT_SCALE / 4], &one, 4); + err = ws_run(&s, RT, OMEGA_GDN_GRID_Y); + if (err) snprintf(msg, n, "plain conversation %u: %s (pc %d)", c, s.msg, s.err_pc); + memcpy(want[c][0], buf[c][SB_OUT], VD * 4u); memcpy(want[c][1], buf[c][SB_TAIL], T_TAIL_BYTES); memcpy(want[c][2], buf[c][SB_STATE], SS); + memcpy(buf[c][SB_TAIL], tail_save, T_TAIL_BYTES); memcpy(buf[c][SB_STATE], state_save, SS); + for (unsigned i = 0; i < VD; i++) yo[i] = -999.0f; + free(tail_save); free(state_save); + } + /* the heads launch: one grid, the table; conversation 1 keeps its own buffers but (control) its entry names conversation 0's */ + if (!err) { + for (unsigned c = 0; c < HN; c++) + for (int i = 0; i < SB_N; i++) tab[c * (OMEGA_GDN_TAB_ENTRY_BYTES / 8u) + i] = (uintptr_t)buf[control && c == 1 ? 0 : c][i]; + WsSim s; memset(&s, 0, sizeof s); + s.p = &heads; s.threads = OMEGA_GDN_THREADS; s.order = 1; + static uint8_t smem[OMEGA_GDN_SHARED_BYTES]; s.smem = smem; s.smem_bytes = OMEGA_GDN_SHARED_BYTES; + const uint64_t ta = (uintptr_t)tab; + s.cbank[OMEGA_GDN_ARG_TAB / 4] = (uint32_t)ta; s.cbank[OMEGA_GDN_ARG_TAB / 4 + 1] = (uint32_t)(ta >> 32); + s.ranges[0].lo = ta; s.ranges[0].hi = ta + HN * OMEGA_GDN_TAB_ENTRY_BYTES; + s.nranges = 1; /* the table and every conversation's seven buffers: every global access must land in one */ + for (unsigned c = 0; c < HN; c++) + for (int i = 0; i < SB_N; i++) { + const uint64_t a = (uintptr_t)buf[c][i]; + s.ranges[s.nranges].lo = a; s.ranges[s.nranges].hi = a + sz[i]; s.nranges++; + } + memcpy(&s.cbank[OMEGA_GDN_ARG_EPS_L2 / 4], &EPS_L2, 4); memcpy(&s.cbank[OMEGA_GDN_ARG_EPS_NORM / 4], &EPS_N, 4); + const float one = 1.0f; + memcpy(&s.cbank[OMEGA_GDN_ARG_IN_SCALE / 4], &one, 4); memcpy(&s.cbank[OMEGA_GDN_ARG_OUT_SCALE / 4], &one, 4); + err = ws_run(&s, RT, OMEGA_GDN_GRID_Y * HN); + if (err) snprintf(msg, n, "heads launch: %s (pc %d)", s.msg, s.err_pc); + g_sim_issues += s.warp_issues; + } + if (!err) { + for (unsigned c = 0; c < HN; c++) { + const int same = memcmp(want[c][0], buf[c][SB_OUT], VD * 4u) == 0 && memcmp(want[c][1], buf[c][SB_TAIL], T_TAIL_BYTES) == 0 && + memcmp(want[c][2], buf[c][SB_STATE], SS) == 0; + if (!control && !same) { err = -1; snprintf(msg, n, "conversation %u differs from its plain launch", c); } + if (control && c == 1 && same) { err = -1; snprintf(msg, n, "control: conversation 1 still got its own result"); } + if (control && c == 1) { /* its own buffers untouched, conversation 0's stepped twice (both CTAs wrote the same words) */ + size_t unwritten = 0; const float *yo = (const float *)buf[1][SB_OUT]; + for (unsigned i = 0; i < VD; i++) if (yo[i] == -999.0f) unwritten++; + if (unwritten != VD) { err = -1; snprintf(msg, n, "control: conversation 1's out row was written (%zu of %u words)", VD - unwritten, VD); } + } + } + } + for (unsigned c = 0; c < HN; c++) { for (int i = 0; i < SB_N; i++) free(buf[c][i]); for (int i = 0; i < 3; i++) free(want[c][i]); } + free(tab); + return err; +} +static void sim_heads_battery(void) { + for (int bf = 0; bf <= 1; bf++) /* f32 state, and the L313 bf16 state (the merge of lever 4 with L313) */ + for (int m = 0; m <= 4; m++) { + char msg[300] = ""; + double t0 = now_ms(); + int err = sim_heads_run(m, 0, bf, msg, sizeof msg); + printf("sim heads form %s state mutant %d: %u conversations bit-identical to their plain launches (%.0f ms)%s%s\n", bf ? "bf16" : "f32", m, HN, now_ms() - t0, err ? " ERROR " : "", msg); + CHECK(err == 0, "sim heads form %s state mutant %d (%s)", bf ? "bf16" : "f32", m, msg); + } + char msg[300] = ""; + int err = sim_heads_run(0, 1, 0, msg, sizeof msg); + printf("sim heads form negative control (entry 1 -> conversation 0)%s%s\n", err ? " ERROR " : ": caught", msg); + CHECK(err == 0, "sim heads form negative control (%s)", msg); +} + /* ---- prefill on the simulator (omega#543): prep, scan, post over T tokens against T oracle steps ---- */ typedef struct { uint32_t off; void *p; size_t bytes; } SimBuf; typedef struct { uint32_t off; uint32_t word; } SimWord; @@ -963,6 +1085,68 @@ static int chip_run(const char *out_path, uint32_t reps) { } free(tmp); free(y); dstate_free(&d); inp_free(&in[0]); inp_free(&in[1]); } + /* the heads form (L312 lever 4): three objects with their own parameters and states; one launch steps all three on layer 1 + * and must leave every out row, tail and state bit-identical to the object's own plain step from the same start */ + { +#define HCN 3u + OmegaGpuGdn *hg[HCN] = { NULL, NULL, NULL }; + Layer HL[HCN]; + Inp hin[HCN]; + int ok = 1; + for (unsigned c = 0; c < HCN; c++) { layer_make(&HL[c], 61 + c); inp_make(&hin[c], 1100 + c, 1.0f); } + for (unsigned c = 0; c < HCN && ok; c++) + ok = omega_gpu_gdn_alloc_ratio(2, GDN_TEST_RATIO, &hg[c]) == 0 && omega_gpu_gdn_set_layer(hg[c], 1, HL[c].conv_w, HL[c].a_log, HL[c].dtb, HL[c].nw) == 0 && + omega_gpu_gdn_set_state(hg[c], 1, HL[c].tail0, HL[c].state0) == 0; + CHECK(ok, "heads form: three objects allocated and set (%s)", ok ? "" : omega_gpu_gdn_last_error()); + float *po = malloc((size_t)HCN * VD * 4), *pt = malloc((size_t)HCN * NT * 4), *ps = malloc((size_t)HCN * NS * 4); + for (unsigned c = 0; c < HCN && ok; c++) /* the plain step (host path), its results kept, the state put back */ + ok = omega_gpu_gdn_step(hg[c], 1, hin[c].qkv, hin[c].z, hin[c].ab, EPS_L2, EPS_N, 1.0f, 1.0f, po + (size_t)c * VD, NULL) == 0 && + omega_gpu_gdn_get_state(hg[c], 1, pt + (size_t)c * NT, ps + (size_t)c * NS) == 0 && + omega_gpu_gdn_set_state(hg[c], 1, HL[c].tail0, HL[c].state0) == 0; + CHECK(ok, "heads form: the three plain steps ran (%s)", ok ? "" : omega_gpu_gdn_last_error()); + if (ok) ok = omega_gpu_gdn_prepare_heads(hg[0]) == 0; + CHECK(ok, "heads form: the heads kernel is resident (%s)", ok ? "" : omega_gpu_gdn_last_error()); + OmegaGpuCmdList *cl = NULL; + const int cl_ok = ok && omega_gpu_cmdlist_create(4, &cl) == 0; + omega_gpu_session_lock(); + OmegaGpuMem hb; memset(&hb, 0, sizeof hb); + const size_t cb = (size_t)CD * 4 + (size_t)VD * 4 + VH * 8, ob = (size_t)VD * 4; + ok = cl_ok && omega_gpu_session_open() != NULL && omega_gpu_session_alloc(HCN * (cb + ob), &hb) == 0; + OmegaGpuGdnHead hs[HCN]; + for (unsigned c = 0; ok && c < HCN; c++) { + uint8_t *p = (uint8_t *)hb.cpu + c * cb; + memcpy(p, hin[c].qkv, (size_t)CD * 4); memcpy(p + CD * 4, hin[c].z, (size_t)VD * 4); memcpy(p + CD * 4 + VD * 4, hin[c].ab, VH * 8); + float *yo = (float *)((uint8_t *)hb.cpu + HCN * cb + c * ob); + for (unsigned i = 0; i < VD; i++) yo[i] = -999.0f; + hs[c].g = hg[c]; hs[c].qkv_va = hb.va + c * cb; hs[c].z_va = hs[c].qkv_va + CD * 4; hs[c].ab_va = hs[c].z_va + VD * 4; + hs[c].out_va = hb.va + HCN * cb + c * ob; + } + if (ok) ok = omega_gpu_session_sync_to_gpu(&hb) == 0; + if (ok) ok = omega_gpu_gdn_record_heads(cl, hs, HCN, 1, EPS_L2, EPS_N, 1.0f, 1.0f) == 0; + OmegaGpuCmdListOpts opts; memset(&opts, 0, sizeof opts); + OmegaGpuCmdListStats stc; memset(&stc, 0, sizeof stc); + if (ok) ok = omega_gpu_cmdlist_submit(cl, &opts, &stc) == 0; + if (ok) ok = omega_gpu_session_sync_to_cpu(&hb) == 0; + omega_gpu_session_unlock(); + if (cl) omega_gpu_cmdlist_free(cl); + CHECK(ok, "heads form: one launch for three conversations recorded and submitted (%s)", ok ? "" : omega_gpu_gdn_last_error()); + if (ok) { + float *t = malloc((size_t)NT * 4), *s = malloc((size_t)NS * 4); + for (unsigned c = 0; c < HCN; c++) { + const float *yo = (const float *)((const uint8_t *)hb.cpu + HCN * cb + c * ob); + const int st = omega_gpu_gdn_get_state(hg[c], 1, t, s) == 0; + CHECK(st && memcmp(yo, po + (size_t)c * VD, (size_t)VD * 4) == 0, "heads form: conversation %u's out row is bit-identical to its plain step", c); + CHECK(st && memcmp(t, pt + (size_t)c * NT, (size_t)NT * 4) == 0 && memcmp(s, ps + (size_t)c * NS, (size_t)NS * 4) == 0, + "heads form: conversation %u's tail and state are bit-identical to its plain step", c); + } + printf("chip heads form: 3 conversations in one launch, compared with their plain steps bit for bit\n"); + free(t); free(s); + } + omega_gpu_session_lock(); if (hb.cpu) omega_gpu_session_free(&hb); omega_gpu_session_unlock(); + for (unsigned c = 0; c < HCN; c++) { if (hg[c]) omega_gpu_gdn_free(hg[c]); inp_free(&hin[c]); layer_free(&HL[c]); } + free(po); free(pt); free(ps); +#undef HCN + } chip_prefill(g, L, out, &first, reps); /* timing */ { @@ -1008,7 +1192,7 @@ int main(int argc, char **argv) { else { printf("unknown argument %s\n", argv[i]); return 2; } } if (host) host_only(); - if (sim) { sim_battery(); sim_bf16_battery(); sim_prefill_battery(); sim_prefill_bf16(3); sim_prefill_bf16(37); sim_copy_battery(); } + if (sim) { sim_battery(); sim_bf16_battery(); sim_heads_battery(); sim_prefill_battery(); sim_prefill_bf16(3); sim_prefill_bf16(37); sim_copy_battery(); } if (!host && !sim) { (void)omega_gpu_session_set_spin_us(spin); if (bf16) chip_bf16(out_path, reps ? reps : 50); else chip_run(out_path, reps ? reps : 50); diff --git a/tests/q36_codegen_hash.c b/tests/q36_codegen_hash.c index 82ba76e2..ba23f10e 100644 --- a/tests/q36_codegen_hash.c +++ b/tests/q36_codegen_hash.c @@ -39,6 +39,8 @@ int main(void) { snprintf(n, sizeof n, "gdn.prep.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_prep_prog(&s, prog)); snprintf(n, sizeof n, "gdn.scan.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_scan_prog(&s, prog)); snprintf(n, sizeof n, "gdn.post.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_post_prog(&s, prog)); + OmegaGdnSpec sh = {.mutant = m, .heads = 1}; /* L312 lever 4: the heads form */ + snprintf(n, sizeof n, "gdn.heads.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_gdn_prog(&sh, prog)); } for (int c = 1; c <= 2; c++) { OmegaGdnSpec s = {.copy = c}; From 07af34eb201bbe4a113d535f89fd3689cb79a6c5 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:04:43 -0500 Subject: [PATCH 5/8] q36 stroke lever 5: decode attention of every head in one launch, AIEN_OMEGA_Q36_ATTN_HEADS=1 (DRA-67, #215) Port of omega-mv ce6e4cf9 (replayed onto 6de999da as db006d4bc). The attn256 heads form reads each conversation's qkv/kc/vc/rope/qn/out/part/cnt pointers and {pos, splits, kv_stride} from a 128-byte table entry (OMEGA_DATTN256_ARG_TAB); conversation cy >> log2(vy), CTA row cy & (vy - 1); empty CTAs of a shorter conversation exit first. spec.heads = 1 selects the form (decode only); the plain program is byte-identical (q36_codegen_hash: all 509 base lines unchanged; attn heads entries added). 904 insns, 112 registers (plain 897, 108). - q36_graph (hand-ported): with AIEN_OMEGA_Q36_ATTN_HEADS=1 record_layer_heads records one omega_gpu_decode_attn256_record_heads for the N heads and the per-head loop keeps only the gate; set_batch prepares the heads kernel only then. Default OFF: per-head attention launches. - tests: gpu_decode_attn256_test heads codegen budgets/refusals, sim heads battery mutants 0..5 and control. Host: test-gpu-decode-attn256 70 (--host-only) + 21 (--sim) checks PASS. Mutant (conversation = cy >> (vysh+1)): sim heads form mutants 0..5 "conversation 1: 6144 unwritten, out DIFFER" FAIL. Chip: NOT_RUN. --- src/omega_blackwell_codegen_attn256.c | 42 +++++- src/omega_blackwell_codegen_attn256.h | 24 ++++ src/omega_gpu_decode_attn256_api.c | 93 ++++++++++++- src/omega_gpu_decode_attn256_api.h | 12 ++ src/omega_gpu_q36_graph.c | 23 +++- tests/gpu_decode_attn256_test.c | 180 +++++++++++++++++++++++++- tests/q36_codegen_hash.c | 12 ++ 7 files changed, 371 insertions(+), 15 deletions(-) diff --git a/src/omega_blackwell_codegen_attn256.c b/src/omega_blackwell_codegen_attn256.c index 1cec482d..05177a5c 100644 --- a/src/omega_blackwell_codegen_attn256.c +++ b/src/omega_blackwell_codegen_attn256.c @@ -178,11 +178,16 @@ static void rms_scale(Em *e, int qa, int qb, int sq, int ts, int rs, int addr, i int omega_blackwell_codegen_decode_attn256_prog(const OmegaDecodeAttn256Spec *spec, BlackwellIRProgram *prog) { if (!spec || !prog || spec->depth < 1 || spec->depth > OMEGA_DATTN256_MAX_DEPTH || spec->mutant < 0 || spec->mutant > 5 || spec->prep > 1 || spec->multi > 1) return -1; + if (spec->heads > 1u || (spec->heads && (spec->prep || spec->multi))) return -1; /* the heads form is decode only (L312 lever 5) */ omega_bw_ir_init(prog); Em em; memset(&em, 0, sizeof em); em.p = prog; Em *e = &em; const uint32_t D = spec->depth; OmegaDattn256Shape SH; if (omega_dattn256_shape(spec, &SH)) return -1; + const int HF = spec->heads != 0; /* the heads form (L312 lever 5): conversation cy >> log2(vy), CTA row cy & (vy - 1) */ + uint32_t vysh = 0; + while ((1u << vysh) < SH.vy) vysh++; + if (HF && (1u << vysh) != SH.vy) return -1; const uint32_t H = SH.h; /* q heads per CTA row */ const int OLD = SH.qh == OMEGA_DATTN256_Q_HEADS && SH.kvh == OMEGA_DATTN256_KV_HEADS && H == OMEGA_DATTN256_Q_PER_KV; const int MUT = spec->mutant; @@ -194,12 +199,32 @@ int omega_blackwell_codegen_decode_attn256_prog(const OmegaDecodeAttn256Spec *sp int tid = V(e), cx = V(e), cy = V(e), warp = V(e), lane = V(e), one = V(e), zero = V(e), c7fff = V(e), c16 = V(e); if (e->err) return -1; ldcu64(e, udesc, 0x358); - ldc64(e, pqkv, OMEGA_DATTN256_ARG_QKV); ldc64(e, pkc, OMEGA_DATTN256_ARG_KC); ldc64(e, pvc, OMEGA_DATTN256_ARG_VC); - ldc64(e, prope, OMEGA_DATTN256_ARG_ROPE); ldc64(e, pqn, OMEGA_DATTN256_ARG_QN); /* k_norm is read at q_norm + 1024 bytes (ARG_KN is informational) */ - ldc32(e, pos, OMEGA_DATTN256_ARG_POS); ldc32(e, per, OMEGA_DATTN256_ARG_PER_SPLIT); ldc32(e, splits, OMEGA_DATTN256_ARG_SPLITS); - ldc32(e, kvs, OMEGA_DATTN256_ARG_KV_STRIDE); ldc32(e, eps, OMEGA_DATTN256_ARG_EPS); - ldc32(e, qks, OMEGA_DATTN256_ARG_QK_SCALE); + if (!HF) { + ldc64(e, pqkv, OMEGA_DATTN256_ARG_QKV); ldc64(e, pkc, OMEGA_DATTN256_ARG_KC); ldc64(e, pvc, OMEGA_DATTN256_ARG_VC); + ldc64(e, prope, OMEGA_DATTN256_ARG_ROPE); ldc64(e, pqn, OMEGA_DATTN256_ARG_QN); /* k_norm is read at q_norm + 1024 bytes (ARG_KN is informational) */ + ldc32(e, pos, OMEGA_DATTN256_ARG_POS); ldc32(e, per, OMEGA_DATTN256_ARG_PER_SPLIT); ldc32(e, splits, OMEGA_DATTN256_ARG_SPLITS); + ldc32(e, kvs, OMEGA_DATTN256_ARG_KV_STRIDE); ldc32(e, eps, OMEGA_DATTN256_ARG_EPS); + ldc32(e, qks, OMEGA_DATTN256_ARG_QK_SCALE); + } s2r(e, tid, BW_SR_TID_X); s2r(e, cx, BW_SR_CTAID_X); s2r(e, cy, BW_SR_CTAID_Y); + int atab = -1, bra_empty = -1; + if (HF) { /* the entry of conversation cy >> log2(vy); cy becomes the CTA row within it */ + int ptab = V64(e), hd = V(e); atab = V64(e); + if (e->err) return -1; + ldc64(e, ptab, OMEGA_DATTN256_ARG_TAB); + shr(e, hd, cy, vysh); andi(e, R(cy), R(cy), SH.vy - 1u); + imadw(e, atab, hd, OMEGA_DATTN256_TAB_ENTRY_BYTES, ptab); + int sc = V128(e); /* {pos, splits, kv_stride, 0} in one 16-byte load (LDG.E carries no offset) */ + if (e->err) return -1; + ldg_wide(e, BW_IR_LDG_E_128, sc, atab, OMEGA_DATTN256_TAB_POS, udesc, 1); + ldg_wide(e, BW_IR_LDG_E_64, pqkv, atab, OMEGA_DATTN256_TAB_QKV, udesc, 0); ldg_wide(e, BW_IR_LDG_E_64, pkc, atab, OMEGA_DATTN256_TAB_KC, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, pvc, atab, OMEGA_DATTN256_TAB_VC, udesc, 0); ldg_wide(e, BW_IR_LDG_E_64, prope, atab, OMEGA_DATTN256_TAB_ROPE, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, pqn, atab, OMEGA_DATTN256_TAB_QN, udesc, 0); + ldc32(e, per, OMEGA_DATTN256_ARG_PER_SPLIT); ldc32(e, eps, OMEGA_DATTN256_ARG_EPS); ldc32(e, qks, OMEGA_DATTN256_ARG_QK_SCALE); + mov(e, R(pos), S(sc, 0)); mov(e, R(splits), S(sc, 1)); mov(e, R(kvs), S(sc, 2)); + isetp_ge_u32(e, cx, splits); /* an empty CTA of a shorter conversation leaves before it touches anything */ + bra_empty = bra_if_p0_fwd(e); + } if (spec->prep && !spec->multi) { /* prefill prep (#545): CTA cx = token cx at position pos0 + cx, its qkv row */ iadd(e, pos, pos, cx); { int rowoff = V(e); if (e->err) return -1; imadi(e, R(rowoff), R(cx), SH.qkv_words * 4u, NOREG); imadw(e, pqkv, rowoff, 1u, pqkv); } @@ -485,7 +510,11 @@ int omega_blackwell_codegen_decode_attn256_prog(const OmegaDecodeAttn256Spec *sp for (unsigned h = 0; h < 8; h++) { ep[h] = V(e); ea[h] = V(e); eb[h] = V(e); } int pout = V64(e), ppart = V64(e), pcnt = V64(e), oscale = V(e); if (e->err) return -1; - ldc64(e, pout, OMEGA_DATTN256_ARG_OUT); ldc64(e, ppart, OMEGA_DATTN256_ARG_PART); ldc64(e, pcnt, OMEGA_DATTN256_ARG_CNT); ldc32(e, oscale, OMEGA_DATTN256_ARG_OUT_SCALE); + if (HF) { /* the conversation's out row, partials and counters from its entry */ + ldg_wide(e, BW_IR_LDG_E_64, pout, atab, OMEGA_DATTN256_TAB_OUT, udesc, 1); ldg_wide(e, BW_IR_LDG_E_64, ppart, atab, OMEGA_DATTN256_TAB_PART, udesc, 0); + ldg_wide(e, BW_IR_LDG_E_64, pcnt, atab, OMEGA_DATTN256_TAB_CNT, udesc, 0); + } else { ldc64(e, pout, OMEGA_DATTN256_ARG_OUT); ldc64(e, ppart, OMEGA_DATTN256_ARG_PART); ldc64(e, pcnt, OMEGA_DATTN256_ARG_CNT); } + ldc32(e, oscale, OMEGA_DATTN256_ARG_OUT_SCALE); if (spec->multi) { /* the token's output row, partials block and counters (ctaid.y re-read: no live register) */ int tk = V(e), so = V(e); if (e->err) return -1; uint32_t lg = 0; while ((1u << lg) < SH.vy) lg++; @@ -633,6 +662,7 @@ int omega_blackwell_codegen_decode_attn256_prog(const OmegaDecodeAttn256Spec *sp /* thread 0 resets the counter for the next launch (every other CTA of this head has already added) */ isetp_ge_u32(e, tid, one); { Region r = region_skip_if_p0(e); imadw(e, pb64, cy, 4u, pcnt); stg(e, BW_IR_STG_STRONG_SYS, pb64, R(zero), udesc); region_end(e, r); } + if (HF) patch_bra(e, bra_empty, here(e)); /* the empty CTAs of the heads form land on the EXIT */ tail(e); if (e->err) return -1; return omega_bw_regalloc_solve(prog); diff --git a/src/omega_blackwell_codegen_attn256.h b/src/omega_blackwell_codegen_attn256.h index caec480e..0cb571a8 100644 --- a/src/omega_blackwell_codegen_attn256.h +++ b/src/omega_blackwell_codegen_attn256.h @@ -85,6 +85,28 @@ #define OMEGA_DATTN256_ARG_OSTRIDE 0x3e8u /* u32 bytes between output rows (attend) */ #define OMEGA_DATTN256_ARG_PSTRIDE 0x3ecu /* u32 bytes between tokens' partial blocks (attend; >= vy * splits * 6192) */ #define OMEGA_DATTN256_MULTI_ARGS_WORDS 28u +/* The heads form (L312 lever 5, 2026-10-21): ONE launch steps n <= OMEGA_DATTN256_MAX_HEADS conversations, grid (max splits, + * vy * n). CTA (cx, cy): conversation hd = cy / vy (vy must be a power of two: 4 for the 27B and the 35B), CTA row cy % vy; the + * conversation's pointers and scalars come from a 128-byte table entry at ARG_TAB + hd * 128 (LDG where the plain kernel does LDC); + * a CTA with cx >= its conversation's splits exits at the top (uniform: no barrier hazard). per_split, eps, qk_scale and + * out_scale stay in the constant bank (the same for every conversation). The plain program is byte-identical to the one + * before this form existed (tests/q36_codegen_hash.c). */ +#define OMEGA_DATTN256_ARG_TAB 0x3e8u /* u64 the launch's table (heads form only) */ +#define OMEGA_DATTN256_HEADS_ARGS_WORDS 28u +#define OMEGA_DATTN256_MAX_HEADS 8u +#define OMEGA_DATTN256_TAB_ENTRY_BYTES 128u +#define OMEGA_DATTN256_TAB_QKV 0u /* u64 f32 qkv row of the conversation */ +#define OMEGA_DATTN256_TAB_KC 8u /* u64 its K cache plane of the layer */ +#define OMEGA_DATTN256_TAB_VC 16u /* u64 its V cache plane */ +#define OMEGA_DATTN256_TAB_ROPE 24u /* u64 the RoPE table */ +#define OMEGA_DATTN256_TAB_QN 32u /* u64 q_norm of the layer (k_norm 1024 bytes after it, as ARG_QN) */ +#define OMEGA_DATTN256_TAB_OUT 40u /* u64 its out row */ +#define OMEGA_DATTN256_TAB_PART 48u /* u64 its partials */ +#define OMEGA_DATTN256_TAB_CNT 56u /* u64 its counters (zero before the launch) */ +#define OMEGA_DATTN256_TAB_POS 64u /* u32 its position */ +#define OMEGA_DATTN256_TAB_SPLITS 68u /* u32 its splits: CTAs cx >= splits exit */ +#define OMEGA_DATTN256_TAB_KV_STRIDE 72u /* u32 bytes per KV head plane */ +/* ARG_TAB shares bytes 0x3e8..0x3ef with the multi-token ARG_OSTRIDE / ARG_PSTRIDE: the two forms never meet (heads with multi is refused). */ /* shared memory map (bytes) */ #define OMEGA_DATTN256_SM_Q 0u /* q'[6][256] f32: 6144 (warps 6, 7 stage k and v at 6144.. 8191: inside SM_S, unused then) */ @@ -116,6 +138,8 @@ typedef struct { * the K/V append (the prep launch before it wrote every token's rows; a split never reads past its token); * out row t at ARG_OUT + t * ARG_OSTRIDE, partials at ARG_PART + t * ARG_PSTRIDE, counters at ARG_CNT + t * vy * 4. * Every value is the decode launch's, bit for bit (same instructions, same combine order). */ + uint32_t heads; /* 1: the heads form (OMEGA_DATTN256_ARG_TAB above; L312 lever 5): decode only, refused with prep or multi. 0: + * the plain decode kernel. Appended after the shape. */ } OmegaDecodeAttn256Spec; /* The shape a spec selects: 0 ok, -1 unsupported. */ diff --git a/src/omega_gpu_decode_attn256_api.c b/src/omega_gpu_decode_attn256_api.c index 9b9fdfae..41e3b229 100644 --- a/src/omega_gpu_decode_attn256_api.c +++ b/src/omega_gpu_decode_attn256_api.c @@ -28,7 +28,9 @@ struct OmegaGpuDecodeAttn256Cache { uint64_t plane_bytes; /* one K or V plane of a layer: 4 * max_pos * 512 + slack */ OmegaGpuMem kv[OMEGA_GPU_DATTN256_MAX_LAYERS]; /* [K plane | V plane] per layer */ OmegaGpuMem rope, norms, part, cnt, qkv, out; + OmegaGpuMem tab; /* heads form (L312 lever 5): [layers][OMEGA_DATTN256_MAX_HEADS] table entries */ }; +#define TAB_ROW_BYTES (OMEGA_DATTN256_MAX_HEADS * OMEGA_DATTN256_TAB_ENTRY_BYTES) typedef struct { bool valid; @@ -37,16 +39,17 @@ typedef struct { OmegaGpuMem code; } Slot; +#define NSLOT 4u /* resident kernels: decode, L369 multi prep + attend, L312 lever 5 heads form */ static struct { bool hooked; - Slot slot[3]; /* the decode kernel and the L369 multi-token prep and attend kernels */ + Slot slot[NSLOT]; /* the decode kernel, the L369 multi-token prep and attend kernels, the L312 heads form */ uint32_t depth, per_split; int mutant, multi_mut; OmegaGpuMem mpart, mcnt; /* L369 multi-token partials and counters, shared by every cache (launches run in order) */ } g; static int g_rec; /* 1 while a record call runs (lock held): kernel_for must not evict */ -static void slot_clear_locked(void) { for (unsigned i = 0; i < 3; i++) { if (g.slot[i].valid) omega_gpu_session_free(&g.slot[i].code); memset(&g.slot[i], 0, sizeof g.slot[i]); } } +static void slot_clear_locked(void) { for (unsigned i = 0; i < NSLOT; i++) { if (g.slot[i].valid) omega_gpu_session_free(&g.slot[i].code); memset(&g.slot[i], 0, sizeof g.slot[i]); } } static void on_session_close(void) { memset(g.slot, 0, sizeof g.slot); memset(&g.mpart, 0, sizeof g.mpart); memset(&g.mcnt, 0, sizeof g.mcnt); } static OmegaGpuSession *dev_open_locked(void) { if (!g.hooked) { (void)omega_gpu_session_on_close(on_session_close); g.hooked = true; } @@ -99,11 +102,14 @@ int omega_gpu_decode_attn256_cache_alloc_shape(uint32_t layers, uint32_t max_pos omega_gpu_session_alloc((size_t)c->sh.vy * c->max_splits * OMEGA_DATTN256_PARTIAL_WORDS * 4, &c->part) != 0 || omega_gpu_session_alloc(64, &c->cnt) != 0 || omega_gpu_session_alloc((size_t)c->sh.qkv_words * 4, &c->qkv) != 0 || - omega_gpu_session_alloc((size_t)c->sh.out_words * 4, &c->out) != 0)) rc = OMEGA_GPU_DATTN_CHIP_FAIL; + omega_gpu_session_alloc((size_t)c->sh.out_words * 4, &c->out) != 0 || + omega_gpu_session_alloc((size_t)layers * TAB_ROW_BYTES, &c->tab) != 0)) rc = OMEGA_GPU_DATTN_CHIP_FAIL; if (rc == OMEGA_GPU_DATTN_OK) { float *r = c->rope.cpu; for (uint32_t p = 0; p < max_pos; p++) omega_dattn256_rope_row(p, rope_theta, rotary_dim, r + (size_t)p * 256); memset(c->cnt.cpu, 0, 64); + memset(c->tab.cpu, 0, (size_t)layers * TAB_ROW_BYTES); + if (omega_gpu_session_sync_to_gpu(&c->tab) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; memset(c->norms.cpu, 0, (size_t)layers * 2 * HD * 4); for (uint32_t L = 0; L < layers; L++) memset(c->kv[L].cpu, 0, (size_t)(2 * c->plane_bytes)); if (omega_gpu_session_sync_to_gpu(&c->rope) != 0 || omega_gpu_session_sync_to_gpu(&c->cnt) != 0 || omega_gpu_session_sync_to_gpu(&c->norms) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; @@ -118,8 +124,8 @@ void omega_gpu_decode_attn256_cache_free(OmegaGpuDecodeAttn256Cache *c) { if (!c) return; omega_gpu_session_lock(); for (uint32_t L = 0; L < c->layers; L++) if (c->kv[L].cpu) omega_gpu_session_free(&c->kv[L]); - OmegaGpuMem *ms[] = { &c->rope, &c->norms, &c->part, &c->cnt, &c->qkv, &c->out }; - for (unsigned i = 0; i < 6; i++) if (ms[i]->cpu) omega_gpu_session_free(ms[i]); + OmegaGpuMem *ms[] = { &c->rope, &c->norms, &c->part, &c->cnt, &c->qkv, &c->out, &c->tab }; + for (unsigned i = 0; i < 7; i++) if (ms[i]->cpu) omega_gpu_session_free(ms[i]); omega_gpu_session_unlock(); omega_gpu_host_free(c); } @@ -155,8 +161,8 @@ int omega_gpu_decode_attn256_cache_read(OmegaGpuDecodeAttn256Cache *c, uint32_t /* ---- kernel ---- */ static int kernel_for(const OmegaDecodeAttn256Spec *spec, Slot **out, bool *hit) { Slot *s = NULL; - for (unsigned i = 0; i < 3; i++) if (g.slot[i].valid && memcmp(&g.slot[i].spec, spec, sizeof *spec) == 0) { *out = &g.slot[i]; *hit = true; return OMEGA_GPU_DATTN_OK; } - for (unsigned i = 0; i < 3 && !s; i++) if (!g.slot[i].valid) s = &g.slot[i]; + for (unsigned i = 0; i < NSLOT; i++) if (g.slot[i].valid && memcmp(&g.slot[i].spec, spec, sizeof *spec) == 0) { *out = &g.slot[i]; *hit = true; return OMEGA_GPU_DATTN_OK; } + for (unsigned i = 0; i < NSLOT && !s; i++) if (!g.slot[i].valid) s = &g.slot[i]; if (!s && g_rec) { omega_gpu_session_set_error("decode attn256 record: kernel cache miss would evict a resident kernel (warm up before recording)"); return OMEGA_GPU_DATTN_TOO_LARGE; } if (!s) { slot_clear_locked(); s = &g.slot[0]; } BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); @@ -275,6 +281,79 @@ int omega_gpu_decode_attn256_record(OmegaGpuCmdList *cl, OmegaGpuDecodeAttn256Ca return dattn_core(c, layer, pos, NULL, eps, out_scale, NULL, NULL, cl, qkv_va, out_va); } +/* ---- the heads form (L312 lever 5): one launch for n conversations, each exactly as alone ---- */ +static void heads_spec(const OmegaGpuDecodeAttn256Cache *c, OmegaDecodeAttn256Spec *spec) { + memset(spec, 0, sizeof *spec); + spec->depth = g.depth ? g.depth : OMEGA_GPU_DATTN256_DEPTH; spec->mutant = g.mutant; + spec->q_heads = c->shape.q_heads; spec->kv_heads = c->shape.kv_heads; spec->q_per_cta = c->shape.q_per_cta; + spec->heads = 1; +} +int omega_gpu_decode_attn256_prepare_heads(OmegaGpuDecodeAttn256Cache *c) { + if (!c) return OMEGA_GPU_DATTN_BAD_ARGS; + OmegaDecodeAttn256Spec spec; heads_spec(c, &spec); + omega_gpu_session_lock(); + int rc = OMEGA_GPU_DATTN_OK; + if (!dev_open_locked()) rc = OMEGA_GPU_DATTN_CHIP_FAIL; + else { Slot *ks = NULL; bool hit = false; rc = kernel_for(&spec, &ks, &hit); } + omega_gpu_session_unlock(); + return rc; +} +int omega_gpu_decode_attn256_record_heads(OmegaGpuCmdList *cl, const OmegaGpuDecodeAttn256Head *heads, uint32_t n, uint32_t layer, float eps, + float out_scale) { + if (!cl || !heads || n == 0 || n > OMEGA_DATTN256_MAX_HEADS || !heads[0].c) return OMEGA_GPU_DATTN_BAD_ARGS; + OmegaGpuDecodeAttn256Cache *c0 = heads[0].c; + if (layer >= c0->layers || !c0->tab.cpu) return OMEGA_GPU_DATTN_BAD_ARGS; + const uint32_t per = g.per_split ? g.per_split : OMEGA_GPU_DATTN256_PER_SPLIT; + if (per % OMEGA_DATTN256_CHUNK) return OMEGA_GPU_DATTN_BAD_ARGS; + uint32_t grid_x = 0; + for (uint32_t i = 0; i < n; i++) { + const OmegaGpuDecodeAttn256Cache *c = heads[i].c; + if (!c || c->layers != c0->layers || c->max_pos != c0->max_pos || memcmp(&c->shape, &c0->shape, sizeof c->shape) != 0) return OMEGA_GPU_DATTN_BAD_ARGS; + if (heads[i].pos >= c->max_pos || !heads[i].qkv_va || !heads[i].out_va) return OMEGA_GPU_DATTN_BAD_ARGS; + const uint32_t splits = (heads[i].pos + per) / per; + if (splits > c->max_splits) return OMEGA_GPU_DATTN_TOO_LARGE; + if (splits > grid_x) grid_x = splits; + } + OmegaDecodeAttn256Spec spec; heads_spec(c0, &spec); + /* caller holds the session lock */ + if (!dev_open_locked()) return OMEGA_GPU_DATTN_CHIP_FAIL; + Slot *ks = NULL; bool hit = false; + g_rec = 1; + int rc = kernel_for(&spec, &ks, &hit); + g_rec = 0; + if (rc != OMEGA_GPU_DATTN_OK) return rc; + /* the table row of this layer: one entry per conversation (OMEGA_DATTN256_TAB_*) */ + uint8_t *row = (uint8_t *)c0->tab.cpu + (size_t)layer * TAB_ROW_BYTES; + memset(row, 0, TAB_ROW_BYTES); + for (uint32_t i = 0; i < n; i++) { + const OmegaGpuDecodeAttn256Cache *c = heads[i].c; + uint8_t *en = row + (size_t)i * OMEGA_DATTN256_TAB_ENTRY_BYTES; + const uint64_t kc = c->kv[layer].va, nm = c->norms.va + (uint64_t)layer * 2 * HD * 4; + const uint64_t p64[8] = { heads[i].qkv_va, kc, kc + c->plane_bytes, c->rope.va, nm, heads[i].out_va, c->part.va, c->cnt.va }; + const uint32_t p32[3] = { heads[i].pos, (heads[i].pos + per) / per, (uint32_t)(c->max_pos * RB) }; + memcpy(en + OMEGA_DATTN256_TAB_QKV, p64, sizeof p64); + memcpy(en + OMEGA_DATTN256_TAB_POS, p32, sizeof p32); + } + if (omega_gpu_session_sync_to_gpu(&c0->tab) != 0) return OMEGA_GPU_DATTN_CHIP_FAIL; + uint32_t args[OMEGA_DATTN256_HEADS_ARGS_WORDS]; memset(args, 0, sizeof args); /* the per-conversation words stay 0: the heads kernel never reads them */ + float fe = eps, fo = out_scale, fq = (float)(0.0625 * 1.4426950408889634); + memcpy(&args[(OMEGA_DATTN256_ARG_EPS - 0x380u) / 4], &fe, 4); memcpy(&args[(OMEGA_DATTN256_ARG_OUT_SCALE - 0x380u) / 4], &fo, 4); + memcpy(&args[(OMEGA_DATTN256_ARG_QK_SCALE - 0x380u) / 4], &fq, 4); + args[(OMEGA_DATTN256_ARG_PER_SPLIT - 0x380u) / 4] = per; + const uint64_t tab = c0->tab.va + (uint64_t)layer * TAB_ROW_BYTES; + args[(OMEGA_DATTN256_ARG_TAB - 0x380u) / 4] = (uint32_t)tab; args[(OMEGA_DATTN256_ARG_TAB - 0x380u) / 4 + 1] = (uint32_t)(tab >> 32); + OmegaGpuLaunch L = { + .code_va = ks->code.va, .gpr_count = gpr_declared(ks->kernel.gpr_count), + .threads_x = OMEGA_DATTN256_CHUNK, .threads_y = 1, .grid_x = grid_x, .grid_y = c0->sh.vy * n, + .num_elements = (size_t)c0->sh.out_words * n, + .args = args, .n_args = OMEGA_DATTN256_HEADS_ARGS_WORDS, .timeout_ms = MARKER_TIMEOUT_MS, + .shared_bytes = OMEGA_DATTN256_SHARED_BYTES, + }; + if (!omega_bw_gpr_declared_ok(L.gpr_count, ks->kernel.gpr_count)) { omega_gpu_session_set_error("declared registers below peak + 2: refusing to launch"); return OMEGA_GPU_DATTN_CHIP_FAIL; } + if (omega_gpu_cmdlist_add(cl, &L) < 0) return OMEGA_GPU_DATTN_CHIP_FAIL; + return OMEGA_GPU_DATTN_OK; +} + int omega_gpu_decode_attn256_counters_check(OmegaGpuDecodeAttn256Cache *c) { if (!c || !c->cnt.cpu) return OMEGA_GPU_DATTN_BAD_ARGS; if (omega_gpu_session_sync_to_cpu(&c->cnt) != 0) return OMEGA_GPU_DATTN_CHIP_FAIL; diff --git a/src/omega_gpu_decode_attn256_api.h b/src/omega_gpu_decode_attn256_api.h index 4dc5cbce..de6e63bb 100644 --- a/src/omega_gpu_decode_attn256_api.h +++ b/src/omega_gpu_decode_attn256_api.h @@ -80,6 +80,18 @@ int omega_gpu_decode_attn256(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint struct OmegaGpuCmdList; int omega_gpu_decode_attn256_record(struct OmegaGpuCmdList *cl, OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos, uint64_t qkv_va, float eps, float out_scale, uint64_t out_va); +/* The heads form (L312 lever 5, 2026-10-21; omega_blackwell_codegen_attn256.h OMEGA_DATTN256_ARG_TAB): ONE launch steps layer + * `layer` of n <= OMEGA_DATTN256_MAX_HEADS conversations on grid (max splits, vy n), each exactly as omega_gpu_decode_attn256_record + * steps it alone (the same per-thread code: bit-identical out rows and appended K/V rows). heads[i].c is conversation i's cache + * (all of one shape, max_pos and layer count; each with its own history, norms, partials and counters); pos its position; qkv_va + * and out_va device rows of the caller's choosing. The table row of the layer lives in heads[0].c ([layers][8] entries, written and + * synced here): a recorded launch stays valid until the next record_heads of that cache and layer. The heads kernel has its own + * slot (the plain kernel stays resident); omega_gpu_decode_attn256_prepare_heads makes it resident ahead of recording (a miss while + * recording is refused). record_heads: caller holds omega_gpu_session_lock(); prepare_heads takes it. */ +typedef struct { OmegaGpuDecodeAttn256Cache *c; uint32_t pos; uint64_t qkv_va, out_va; } OmegaGpuDecodeAttn256Head; +int omega_gpu_decode_attn256_prepare_heads(OmegaGpuDecodeAttn256Cache *c); +int omega_gpu_decode_attn256_record_heads(struct OmegaGpuCmdList *cl, const OmegaGpuDecodeAttn256Head *heads, uint32_t n, uint32_t layer, + float eps, float out_scale); /* Caller holds the lock, after the list ran: OK when the four split counters are zero, else CHIP_FAIL. */ int omega_gpu_decode_attn256_counters_check(OmegaGpuDecodeAttn256Cache *c); /* L369 multi-token prompt attention: tokens prompt tokens of one conversation at positions pos0 .. pos0 + tokens - 1 (qkv rows diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index ac0182e5..33edf175 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -608,6 +608,13 @@ static int q36_gdn_heads(void) { if (g_gdn_heads < 0) { const char *e = getenv("AIEN_OMEGA_Q36_GDN_HEADS"); g_gdn_heads = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } return g_gdn_heads; } +/* lever 5 (L312): the decode attention of every head in ONE launch (omega_gpu_decode_attn256_record_heads) instead of one + * launch per head. OFF unless AIEN_OMEGA_Q36_ATTN_HEADS=1 (chip-unqualified: the per-head launches stay the default). */ +static int g_attn_heads = -1; +static int q36_attn_heads(void) { + if (g_attn_heads < 0) { const char *e = getenv("AIEN_OMEGA_Q36_ATTN_HEADS"); g_attn_heads = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + return g_attn_heads; +} int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS; @@ -624,6 +631,8 @@ int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (g->heads > 1u && omega_gpu_router_prepare_rows(g->cfg.router, H * 4u, g->lo.lb_stride) != OMEGA_GPU_ROUTER_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; /* lever 4: the GDN step of every head in one launch (record_layer_heads; the heads kernel has its own cache slot) */ if (q36_gdn_heads() && omega_gpu_gdn_prepare_heads(g->cfg.gdn) != OMEGA_GPU_GDN_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; + /* lever 5: the attention of every head in one launch (record_layer_heads; its own cache slot) */ + if (q36_attn_heads() && omega_gpu_decode_attn256_prepare_heads(g->cfg.attn) != OMEGA_GPU_DATTN_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; /* lever 1: the bf16 lm_head read once per group of up to OMEGA_BF16_MAX_XBATCH heads (record_final_heads) */ if (!g->head8) { uint32_t n = 0, k = 0; omega_gpu_bf16_tensor_shape(g->cfg.lm_head, &n, &k); @@ -745,9 +754,21 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons if (rc == OMEGA_GPU_DGRAPH_OK) rc = add_glue(g, OMEGA_GPU_Q36_K_GATHER, g->mutant == 2 ? K_GATHER_M1 : K_GATHER, (OMEGA_GPU_Q36_ATT_MIX + OMEGA_DEC_THREADS - 1) / OMEGA_DEC_THREADS, N, (size_t)OMEGA_GPU_Q36_ATT_MIX * N, w, OMEGA_DEC_GA_WORDS); + if (q36_attn_heads()) { + /* lever 5: ONE attention launch for the N heads (each conversation's cache, position and rows from the table) */ + OmegaGpuDecodeAttn256Head hs[OMEGA_GPU_Q36_MAX_HEADS]; + memset(hs, 0, sizeof hs); + for (uint32_t h = 0; h < N; h++) { + hs[h].c = g->attn_h[h]; hs[h].pos = pos[h]; + hs[h].qkv_va = aggN + (uint64_t)h * OMEGA_GPU_Q36_ATT_MIX * 4u; hs[h].out_va = attN + h * MOS; + } + if (rc == OMEGA_GPU_DGRAPH_OK) + rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record_heads(g->cl, hs, N, ki, g->cfg.eps, SCALE_2P64)); + } for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK; h++) { const uint64_t agg_h = aggN + (uint64_t)h * OMEGA_GPU_Q36_ATT_MIX * 4u, att_h = attN + h * MOS; - rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record(g->cl, g->attn_h[h], ki, pos[h], agg_h, g->cfg.eps, SCALE_2P64, att_h)); + if (!q36_attn_heads()) + rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record(g->cl, g->attn_h[h], ki, pos[h], agg_h, g->cfg.eps, SCALE_2P64, att_h)); uint32_t w2[OMEGA_DEC_GT_WORDS]; memset(w2, 0, sizeof w2); put64(w2, OMEGA_DEC_GT_A, att_h); put64(w2, OMEGA_DEC_GT_G, agg_h + OMEGA_GPU_Q36_ATT_QKV * 4u); put64(w2, OMEGA_DEC_GT_OUT, att_h); w2[(OMEGA_DEC_GT_N - 0x380) / 4] = OMEGA_GPU_Q36_MIXER_OUT; diff --git a/tests/gpu_decode_attn256_test.c b/tests/gpu_decode_attn256_test.c index 0229af33..d73f51f0 100644 --- a/tests/gpu_decode_attn256_test.c +++ b/tests/gpu_decode_attn256_test.c @@ -21,6 +21,7 @@ */ #include "omega_gpu_decode_attn256_api.h" #include "omega_gpu_session.h" +#include "omega_gpu_cmdlist.h" #include "omega_gpu_hostmath.h" #include "bw_warp_sim_k.h" #include @@ -247,6 +248,18 @@ static void host_only(void) { CHECK(omega_gpu_decode_attn256_cache_alloc_shape(1, 131072 + 256, THETA, 64, QH, KVH, QPC, &c) == OMEGA_GPU_DATTN_BAD_ARGS && c == NULL, "max_pos > 131072 refused"); } CHECK(OMEGA_DATTN256_SHARED_BYTES <= 16384u, "shared memory within the QMD cap (%u)", OMEGA_DATTN256_SHARED_BYTES); CHECK(OMEGA_DATTN256_SM_FLAG + 16u == OMEGA_DATTN256_SHARED_BYTES && OMEGA_DATTN256_SM_S + 8192u <= OMEGA_DATTN256_SM_M && OMEGA_DATTN256_SM_M + 288u <= OMEGA_DATTN256_SM_L && OMEGA_DATTN256_SM_L + 256u <= OMEGA_DATTN256_SM_FLAG, "shared map does not overlap"); + /* L312 lever 5: the heads form (one launch for N conversations) builds for every mutant within the budget, and its refusals hold */ + for (int m = 0; m <= 5; m++) { + OmegaDecodeAttn256Spec p = { .depth = 4, .mutant = m SPEC_SHAPE }, h = p; h.heads = 1; + uint32_t np = 0, gp = 0, nh = 0, gh = 0; + int rp = omega_decode_attn256_prog_stats(&p, &np, &gp), rh = omega_decode_attn256_prog_stats(&h, &nh, &gh); + CHECK(rp == 0 && rh == 0 && nh <= np + 24 && gh <= 126, "heads form mutant %d: rc %d insns %u (plain %u) gprs %u (plain %u)", m, rh, nh, np, gh, gp); + if (m == 0 && rh == 0) printf("heads form: %u instructions, %u registers (plain %u, %u)\n", nh, gh, np, gp); + } + { OmegaDecodeAttn256Spec s = { .depth = 4, .heads = 2 SPEC_SHAPE }; CHECK(omega_decode_attn256_prog_stats(&s, NULL, NULL) != 0, "heads 2 refused"); + s.heads = 1; s.prep = 1; CHECK(omega_decode_attn256_prog_stats(&s, NULL, NULL) != 0, "the prep form with heads refused"); } + CHECK(OMEGA_DATTN256_TAB_KV_STRIDE + 4u <= OMEGA_DATTN256_TAB_ENTRY_BYTES && OMEGA_DATTN256_ARG_TAB + 8u == 0x380u + 4u * OMEGA_DATTN256_HEADS_ARGS_WORDS && OMEGA_DATTN256_TAB_POS % 16u == 0u, + "heads form: table entry and argument layout"); } /* ------------------------------------------------------------- simulator */ @@ -334,6 +347,115 @@ static void sim_battery(void) { printf("sim: %" PRIu64 " warp issues in total\n", g_sim_issues); } +/* L312 lever 5: the heads form in the simulator. HN conversations with histories, positions (contexts 7 and 301: 1 and 2 splits, so + * conversation 0's second CTA column exits empty), norms and buffers of their own run in ONE launch of the heads program on grid + * (2, VY * HN); each must be bit-identical (out row, appended K/V rows) to its own plain launch, with its counters back to zero. + * control: entry 1's qkv is pointed at conversation 0's row, so conversation 1 must differ from its plain result. */ +#define HN 2u +static int sim_heads_run(int mutant, int control, char *msg, size_t n) { + static BlackwellIRProgram prog, hprog; + OmegaDecodeAttn256Spec spec = { .depth = 2, .mutant = mutant SPEC_SHAPE }, hspec = spec; hspec.heads = 1; + if (omega_blackwell_codegen_decode_attn256_prog(&spec, &prog) != 0 || omega_blackwell_codegen_decode_attn256_prog(&hspec, &hprog) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + const uint32_t max_pos = 512, per = 256, posv[HN] = { 6, 300 }; + const size_t plane = (size_t)KVH * max_pos * OMEGA_DATTN256_ROW_BYTES + OMEGA_DATTN256_PLANE_SLACK, hist = (size_t)KVH * max_pos * OMEGA_DATTN256_ROW_BYTES; + const size_t rows = (size_t)KVH * OMEGA_DATTN256_ROW_BYTES; + float *rope = aligned_alloc(16, (size_t)max_pos * OMEGA_DATTN256_ROPE_ROW_BYTES); + for (uint32_t p = 0; p < max_pos; p++) omega_dattn256_rope_row(p, THETA, 64, rope + (size_t)p * 256); + Case c[HN]; uint16_t *kcp[HN]; uint8_t *kv[HN], *prow[HN]; float *norms[HN], *qkv[HN], *out[HN], *plain[HN], *part[HN]; uint32_t *cnt[HN], splits[HN], gx = 0; + for (unsigned i = 0; i < HN; i++) { + case_make(&c[i], max_pos, posv[i], 64, 300 + i, 1.0f); kcp[i] = case_kc_perm(&c[i]); + splits[i] = (posv[i] + per) / per; if (splits[i] > gx) gx = splits[i]; + kv[i] = aligned_alloc(16, 2 * plane); norms[i] = aligned_alloc(16, 2048); qkv[i] = aligned_alloc(16, sizeof c[i].qkv); + case_kernel_inputs(&c[i], qkv[i], norms[i], norms[i] + HD); + out[i] = aligned_alloc(16, OW * 4); plain[i] = malloc(OW * 4); prow[i] = malloc(2 * rows); + part[i] = aligned_alloc(16, (size_t)VY * splits[i] * OMEGA_DATTN256_PARTIAL_WORDS * 4); cnt[i] = aligned_alloc(16, 16); + } + uint8_t *tab = aligned_alloc(16, HN * OMEGA_DATTN256_TAB_ENTRY_BYTES); memset(tab, 0, HN * OMEGA_DATTN256_TAB_ENTRY_BYTES); + float fe = EPS, fo = 1.0f, fq = (float)((1.0 / 16.0) * 1.4426950408889634); + static uint8_t smem[OMEGA_DATTN256_SHARED_BYTES]; + int err = 0; +#define FRESH(i) do { memset(cnt[i], 0, 16); for (unsigned k = 0; k < OW; k++) out[i][k] = -999.0f; memset(kv[i], 0, 2 * plane); memcpy(kv[i], kcp[i], hist); memcpy(kv[i] + plane, c[i].vc, hist); } while (0) +#define ROWS_OF(i, dst) do { for (unsigned g = 0; g < KVH; g++) { \ + memcpy((dst) + g * OMEGA_DATTN256_ROW_BYTES, kv[i] + ((size_t)g * max_pos + posv[i]) * OMEGA_DATTN256_ROW_BYTES, OMEGA_DATTN256_ROW_BYTES); \ + memcpy((dst) + rows + g * OMEGA_DATTN256_ROW_BYTES, kv[i] + plane + ((size_t)g * max_pos + posv[i]) * OMEGA_DATTN256_ROW_BYTES, OMEGA_DATTN256_ROW_BYTES); } } while (0) + for (unsigned i = 0; i < HN && !err; i++) { /* each conversation alone, the plain program */ + WsSim s; memset(&s, 0, sizeof s); s.p = &prog; s.threads = 256; s.smem = smem; s.smem_bytes = OMEGA_DATTN256_SHARED_BYTES; + FRESH(i); + uint64_t A[9] = { (uintptr_t)qkv[i], (uintptr_t)kv[i], (uintptr_t)(kv[i] + plane), (uintptr_t)rope, (uintptr_t)norms[i], (uintptr_t)(norms[i] + HD), (uintptr_t)out[i], (uintptr_t)part[i], (uintptr_t)cnt[i] }; + for (unsigned k = 0; k < 9; k++) { s.cbank[(0x380 + 8 * k) / 4] = (uint32_t)A[k]; s.cbank[(0x380 + 8 * k) / 4 + 1] = (uint32_t)(A[k] >> 32); } + memcpy(&s.cbank[OMEGA_DATTN256_ARG_EPS / 4], &fe, 4); memcpy(&s.cbank[OMEGA_DATTN256_ARG_OUT_SCALE / 4], &fo, 4); memcpy(&s.cbank[OMEGA_DATTN256_ARG_QK_SCALE / 4], &fq, 4); + s.cbank[OMEGA_DATTN256_ARG_POS / 4] = posv[i]; s.cbank[OMEGA_DATTN256_ARG_PER_SPLIT / 4] = per; s.cbank[OMEGA_DATTN256_ARG_SPLITS / 4] = splits[i]; s.cbank[OMEGA_DATTN256_ARG_KV_STRIDE / 4] = max_pos * OMEGA_DATTN256_ROW_BYTES; + s.nranges = 7; + s.ranges[0].lo = (uintptr_t)qkv[i]; s.ranges[0].hi = (uintptr_t)qkv[i] + sizeof c[i].qkv; + s.ranges[1].lo = (uintptr_t)kv[i]; s.ranges[1].hi = (uintptr_t)kv[i] + 2 * plane; + s.ranges[2].lo = (uintptr_t)rope; s.ranges[2].hi = (uintptr_t)rope + (size_t)max_pos * OMEGA_DATTN256_ROPE_ROW_BYTES; + s.ranges[3].lo = (uintptr_t)norms[i]; s.ranges[3].hi = (uintptr_t)norms[i] + 2048; + s.ranges[4].lo = (uintptr_t)out[i]; s.ranges[4].hi = (uintptr_t)out[i] + OW * 4; + s.ranges[5].lo = (uintptr_t)part[i]; s.ranges[5].hi = (uintptr_t)part[i] + (size_t)VY * splits[i] * OMEGA_DATTN256_PARTIAL_WORDS * 4; + s.ranges[6].lo = (uintptr_t)cnt[i]; s.ranges[6].hi = (uintptr_t)cnt[i] + 16; + err = ws_run(&s, splits[i], VY); + if (err) { snprintf(msg, n, "plain %u: %s (pc %d)", i, s.msg, s.err_pc); break; } + memcpy(plain[i], out[i], OW * 4); ROWS_OF(i, prow[i]); + } + if (!err) { /* the HN conversations in one launch of the heads program */ + WsSim s; memset(&s, 0, sizeof s); s.p = &hprog; s.threads = 256; s.smem = smem; s.smem_bytes = OMEGA_DATTN256_SHARED_BYTES; + for (unsigned i = 0; i < HN; i++) { + FRESH(i); + uint8_t *en = tab + i * OMEGA_DATTN256_TAB_ENTRY_BYTES; + const float *q = control && i == 1 ? qkv[0] : qkv[i]; + uint64_t p64[8] = { (uintptr_t)q, (uintptr_t)kv[i], (uintptr_t)(kv[i] + plane), (uintptr_t)rope, (uintptr_t)norms[i], (uintptr_t)out[i], (uintptr_t)part[i], (uintptr_t)cnt[i] }; + uint32_t p32[3] = { posv[i], splits[i], max_pos * OMEGA_DATTN256_ROW_BYTES }; + memcpy(en + OMEGA_DATTN256_TAB_QKV, p64, sizeof p64); memcpy(en + OMEGA_DATTN256_TAB_POS, p32, sizeof p32); + const unsigned r = 2 + 6 * i; + s.ranges[r + 0].lo = (uintptr_t)qkv[i]; s.ranges[r + 0].hi = (uintptr_t)qkv[i] + sizeof c[i].qkv; + s.ranges[r + 1].lo = (uintptr_t)kv[i]; s.ranges[r + 1].hi = (uintptr_t)kv[i] + 2 * plane; + s.ranges[r + 2].lo = (uintptr_t)norms[i]; s.ranges[r + 2].hi = (uintptr_t)norms[i] + 2048; + s.ranges[r + 3].lo = (uintptr_t)out[i]; s.ranges[r + 3].hi = (uintptr_t)out[i] + OW * 4; + s.ranges[r + 4].lo = (uintptr_t)part[i]; s.ranges[r + 4].hi = (uintptr_t)part[i] + (size_t)VY * splits[i] * OMEGA_DATTN256_PARTIAL_WORDS * 4; + s.ranges[r + 5].lo = (uintptr_t)cnt[i]; s.ranges[r + 5].hi = (uintptr_t)cnt[i] + 16; + } + s.ranges[0].lo = (uintptr_t)tab; s.ranges[0].hi = (uintptr_t)tab + HN * OMEGA_DATTN256_TAB_ENTRY_BYTES; + s.ranges[1].lo = (uintptr_t)rope; s.ranges[1].hi = (uintptr_t)rope + (size_t)max_pos * OMEGA_DATTN256_ROPE_ROW_BYTES; + s.nranges = 2 + 6 * HN; + memcpy(&s.cbank[OMEGA_DATTN256_ARG_EPS / 4], &fe, 4); memcpy(&s.cbank[OMEGA_DATTN256_ARG_OUT_SCALE / 4], &fo, 4); memcpy(&s.cbank[OMEGA_DATTN256_ARG_QK_SCALE / 4], &fq, 4); + s.cbank[OMEGA_DATTN256_ARG_PER_SPLIT / 4] = per; + s.cbank[OMEGA_DATTN256_ARG_TAB / 4] = (uint32_t)(uintptr_t)tab; s.cbank[OMEGA_DATTN256_ARG_TAB / 4 + 1] = (uint32_t)((uintptr_t)tab >> 32); + err = ws_run(&s, gx, VY * HN); + if (err) snprintf(msg, n, "heads launch: %s (pc %d)", s.msg, s.err_pc); + else { + g_sim_issues += s.warp_issues; + uint8_t *hrow = malloc(2 * rows); + for (unsigned i = 0; i < HN && !err; i++) { + size_t unwritten = 0; for (unsigned k = 0; k < OW; k++) if (out[i][k] == -999.0f) unwritten++; + ROWS_OF(i, hrow); + const int same_out = memcmp(plain[i], out[i], OW * 4) == 0, same_rows = memcmp(prow[i], hrow, 2 * rows) == 0; + const int same = unwritten == 0 && same_out && same_rows, cz = (cnt[i][0] | cnt[i][1] | cnt[i][2] | cnt[i][3]) == 0; + if (control && i == 1) { if (same) { err = -1; snprintf(msg, n, "control NOT caught: conversation 1 equals its plain result with conversation 0's qkv"); } } + else if (!same || !cz) { err = -1; snprintf(msg, n, "conversation %u: %zu unwritten, out %s, rows %s, counters %s", i, unwritten, same_out ? "same" : "DIFFER", same_rows ? "same" : "DIFFER", cz ? "zero" : "NOT zero"); } + } + free(hrow); + if (!err && control) snprintf(msg, n, "control caught (conversation 0 identical, conversation 1 differs)"); + else if (!err) snprintf(msg, n, "%u conversations bit-identical to their plain launches (grid %ux%u)", HN, gx, VY * HN); + } + } +#undef FRESH +#undef ROWS_OF + for (unsigned i = 0; i < HN; i++) { free(kv[i]); free(norms[i]); free(qkv[i]); free(out[i]); free(plain[i]); free(prow[i]); free(part[i]); free(cnt[i]); free(kcp[i]); case_free(&c[i]); } + free(rope); free(tab); + return err; +} +static void sim_heads_battery(void) { + char msg[300]; + for (int m = 0; m <= 5; m++) { + int err = sim_heads_run(m, 0, msg, sizeof msg); + CHECK(err == 0, "sim heads form mutant %d: %s", m, msg); + printf("sim heads form mutant %d: %s %s\n", m, err ? "ERROR" : "ok", msg); + } + int err = sim_heads_run(0, 1, msg, sizeof msg); + CHECK(err == 0, "sim heads form control: %s", msg); + printf("sim heads form control: %s %s\n", err ? "ERROR" : "ok", msg); +} + /* ------------------------------------------------------------- chip */ static int g_evict = 1; static const char *g_only; static uint32_t g_maxp = 32768; static void evict_host_caches(void) { @@ -431,6 +553,62 @@ static int chip_run(const char *out_path, uint32_t reps) { free(y); free(y2); free(qkv_k); free(kcp); case_free(&c); if (omega_gpu_session_is_blocked()) { printf("session latched: stopping\n"); break; } } + /* L312 lever 5: the heads form on the chip. HCN caches (2 layers; histories, positions and norms of their own) step layer 1 on + * the host path one by one; their appended rows are then zeroed and ONE heads launch steps all of them (qkv rows and out rows + * in one session buffer): out rows, appended K/V rows and counters must match the plain steps bit for bit. */ + if (!g_only && !omega_gpu_session_is_blocked()) { +#define HCN 3u + const uint32_t hmax = 1024, hpos[HCN] = { 6, 300, 700 }; /* 1, 2 and 3 splits: grid (3, VY * 3) with three empty CTAs */ + OmegaGpuDecodeAttn256Cache *hc[HCN] = { NULL, NULL, NULL }; Case cc[HCN]; uint16_t *hk[HCN] = { NULL, NULL, NULL }; + float *hq[HCN] = { NULL, NULL, NULL }, *hy[HCN] = { NULL, NULL, NULL }; + static uint16_t prow[HCN][2][KVH * HD], hrow[2][KVH * HD], zk[HD], zv[HD]; + int hrc = OMEGA_GPU_DATTN_OK; + for (unsigned i = 0; i < HCN; i++) { + case_make(&cc[i], hmax, hpos[i], 64, 900 + i, 1.0f); hk[i] = case_kc_perm(&cc[i]); + hq[i] = malloc(QW * 4); hy[i] = malloc(OW * 4); float qn[HD], kn[HD]; case_kernel_inputs(&cc[i], hq[i], qn, kn); + if (hrc == OMEGA_GPU_DATTN_OK) hrc = omega_gpu_decode_attn256_cache_alloc_shape(2, hmax, THETA, 64, QH, KVH, QPC, &hc[i]); + if (hrc == OMEGA_GPU_DATTN_OK) hrc = omega_gpu_decode_attn256_set_norms(hc[i], 1, qn, kn); + for (unsigned g = 0; g < KVH && hrc == OMEGA_GPU_DATTN_OK && hpos[i]; g++) + hrc = omega_gpu_decode_attn256_cache_write(hc[i], 1, g, 0, hpos[i], hk[i] + (size_t)g * hmax * HD, cc[i].vc + (size_t)g * hmax * HD); + if (hrc == OMEGA_GPU_DATTN_OK) hrc = omega_gpu_decode_attn256(hc[i], 1, hpos[i], hq[i], EPS, 1.0f, hy[i], NULL); + for (unsigned g = 0; g < KVH && hrc == OMEGA_GPU_DATTN_OK; g++) hrc = omega_gpu_decode_attn256_cache_read(hc[i], 1, g, hpos[i], prow[i][0] + g * HD, prow[i][1] + g * HD); + for (unsigned g = 0; g < KVH && hrc == OMEGA_GPU_DATTN_OK; g++) hrc = omega_gpu_decode_attn256_cache_write(hc[i], 1, g, hpos[i], 1, zk, zv); /* the heads launch must append them itself */ + } + CHECK(hrc == OMEGA_GPU_DATTN_OK, "chip heads form: caches, histories and plain steps (%s)", omega_gpu_decode_attn_last_error()); + if (hrc == OMEGA_GPU_DATTN_OK) hrc = omega_gpu_decode_attn256_prepare_heads(hc[0]); + CHECK(hrc == OMEGA_GPU_DATTN_OK, "chip heads form: prepare (%s)", omega_gpu_decode_attn_last_error()); + if (hrc == OMEGA_GPU_DATTN_OK) { + OmegaGpuCmdList *cl = NULL; OmegaGpuMem buf; memset(&buf, 0, sizeof buf); + const int cl_ok = omega_gpu_cmdlist_create(4, &cl) == 0; + omega_gpu_session_lock(); + int ok = cl_ok && omega_gpu_session_alloc((size_t)HCN * (QW + OW) * 4, &buf) == 0; + float *b = ok ? buf.cpu : NULL; + if (ok) { + for (unsigned i = 0; i < HCN; i++) { memcpy(b + (size_t)i * QW, hq[i], QW * 4); for (unsigned k = 0; k < OW; k++) b[(size_t)HCN * QW + (size_t)i * OW + k] = -999.0f; } + ok = omega_gpu_session_sync_to_gpu(&buf) == 0; + } + OmegaGpuDecodeAttn256Head hs[HCN]; + for (unsigned i = 0; i < HCN; i++) { hs[i].c = hc[i]; hs[i].pos = hpos[i]; hs[i].qkv_va = buf.va + (uint64_t)i * QW * 4; hs[i].out_va = buf.va + ((uint64_t)HCN * QW + (uint64_t)i * OW) * 4; } + if (ok) ok = omega_gpu_decode_attn256_record_heads(cl, hs, HCN, 1, EPS, 1.0f) == OMEGA_GPU_DATTN_OK; + OmegaGpuCmdListOpts opts; memset(&opts, 0, sizeof opts); OmegaGpuCmdListStats stc; memset(&stc, 0, sizeof stc); + if (ok) ok = omega_gpu_cmdlist_submit(cl, &opts, &stc) == 0; + if (ok) ok = omega_gpu_session_sync_to_cpu(&buf) == 0; + int cz = 1; for (unsigned i = 0; i < HCN && ok; i++) cz &= omega_gpu_decode_attn256_counters_check(hc[i]) == OMEGA_GPU_DATTN_OK; + omega_gpu_session_unlock(); + CHECK(ok, "chip heads form: record and submit (%s)", omega_gpu_decode_attn_last_error()); + for (unsigned i = 0; i < HCN && ok; i++) { + int rr = OMEGA_GPU_DATTN_OK; + for (unsigned g = 0; g < KVH && rr == OMEGA_GPU_DATTN_OK; g++) rr = omega_gpu_decode_attn256_cache_read(hc[i], 1, g, hpos[i], hrow[0] + g * HD, hrow[1] + g * HD); + const int same_out = memcmp(b + (size_t)HCN * QW + (size_t)i * OW, hy[i], OW * 4) == 0, same_rows = rr == OMEGA_GPU_DATTN_OK && memcmp(prow[i], hrow, sizeof hrow) == 0; + CHECK(same_out && same_rows, "chip heads form: conversation %u (context %u) out %s, appended rows %s", i, hpos[i] + 1, same_out ? "identical" : "DIFFERS", same_rows ? "identical" : "DIFFER"); + } + CHECK(cz, "chip heads form: every conversation's split counters back to zero"); + if (ok) printf("chip heads form: %u conversations (contexts %u, %u, %u) in one launch, out rows and appended K/V rows bit-identical to their plain steps\n", HCN, hpos[0] + 1, hpos[1] + 1, hpos[2] + 1); + omega_gpu_session_lock(); if (buf.cpu) omega_gpu_session_free(&buf); omega_gpu_session_unlock(); + if (cl) omega_gpu_cmdlist_free(cl); + } + for (unsigned i = 0; i < HCN; i++) { omega_gpu_decode_attn256_cache_free(hc[i]); free(hk[i]); free(hq[i]); free(hy[i]); case_free(&cc[i]); } + } omega_gpu_decode_attn256_cache_free(cache); if (out) { fprintf(out, "],\"checks\":%d,\"failed\":%d,\"device_opens\":%u,\"verdict\":\"%s\"}\n", g_checks, g_failed, omega_gpu_session_open_count(), g_failed == 0 ? "OMEGA_GPU_DECODE_ATTN256_PASS" : "OMEGA_GPU_DECODE_ATTN256_FAIL"); fclose(out); } return 0; @@ -469,7 +647,7 @@ int main(int argc, char **argv) { if (host) host_only(); if (sim && sim_pos >= 0 && sim_max <= (uint32_t)sim_pos) sim_max = (uint32_t)sim_pos + 1u; if (sim && sim_pos >= 0) { char msg[300], rows[160]; double worst; size_t bad; int err = sim_point(sim_max, (uint32_t)sim_pos, 64, depth ? depth : 2, 0, per ? per : 256, 1.0f, 777, msg, sizeof msg, &worst, &bad, rows, sizeof rows); printf("sim pos %d: %s %s\n", sim_pos, err ? "ERROR" : bad ? "MISMATCH" : "ok", msg); return err || bad; } - if (sim) sim_battery(); + if (sim) { sim_battery(); sim_heads_battery(); } if (!host && !sim) { if (depth) omega_gpu_decode_attn256_set_depth(depth); if (per) omega_gpu_decode_attn256_set_per_split(per); diff --git a/tests/q36_codegen_hash.c b/tests/q36_codegen_hash.c index ba23f10e..908d931a 100644 --- a/tests/q36_codegen_hash.c +++ b/tests/q36_codegen_hash.c @@ -53,6 +53,18 @@ int main(void) { snprintf(n, sizeof n, "attn256.d%u.m%d.p%u", d, m, p); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_decode_attn256_prog(&s, prog)); } + for (uint32_t d = 1; d <= 4; d++) /* L312 lever 5: the heads form (27B shape), and the 35B shape plain and heads */ + for (int m = 0; m <= 5; m++) { + OmegaDecodeAttn256Spec s = {.depth = d, .mutant = m, .heads = 1}; + snprintf(n, sizeof n, "attn256.d%u.m%d.heads", d, m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_decode_attn256_prog(&s, prog)); + OmegaDecodeAttn256Spec q = {.depth = d, .mutant = m, .q_heads = 16, .kv_heads = 2, .q_per_cta = 4}; + snprintf(n, sizeof n, "attn256q36.d%u.m%d", d, m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_decode_attn256_prog(&q, prog)); + q.heads = 1; + snprintf(n, sizeof n, "attn256q36.d%u.m%d.heads", d, m); omega_bw_ir_init(prog); + emit(n, omega_blackwell_codegen_decode_attn256_prog(&q, prog)); + } for (int m = 0; m <= 4; m++) { OmegaPrefillAttn256Spec s = {.mutant = m}; snprintf(n, sizeof n, "pattn256.m%d", m); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_prefill_attn256_prog(&s, prog)); From 47a846a336709eaaf018e3072d9d5425f9e5ea81 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:09:13 -0500 Subject: [PATCH 6/8] q36 stroke lever 6: the bf16 lm_head once for 8 heads, AIEN_OMEGA_Q36_HEAD_XBATCH8=1 (DRA-67, #215) Port of omega-mv 2c3df8e3e (cherry of 6f2f54cb). The stroke8l2 timeline read the lm_head twice per stroke of 8 (two XBATCH 4 launches, 9.619 ms of 77.738 ms). One read for 8 heads stages 8 x 8 KiB = 64 KiB of x in shared memory. - codegen_bf16: XBATCH form 5..8 x rows (OMEGA_BF16_MAX_XBATCH 8), x rows read one at a time and weight halves extracted once per step (16 warps fit); 1..4 x-row programs unchanged. - qmd: word 36 per launch from shared_bytes; <= 32 KiB stays 0x04b44808, above it MIN/TARGET SM config 17 (64 KB). Cap OMEGA_BW_QMD_MAX_SHARED_BYTES 65536, OMEGA_BW_QMD_SHARED_32K_BYTES 32768. - fp8_api: the FP8 deep-kernel partial bound keeps 32 KiB (hand-ported). - q36_graph (hand-ported, !head8 path only): set_batch prep and record_final_heads group by q36_head_xbatch(): 4 by default, 8 only when AIEN_OMEGA_Q36_HEAD_XBATCH8=1 (read once per process). - tests/gpu_bf16_gemv_test.c: xb 8 budgets, sim xb 5/6/8 bit-identical, mutants caught. Host (nice 19, taskset 0-9): q36_codegen_hash "586 lines; base 509 lines (digest 54cf5c03d685f1ec); 0 base lines changed or missing"; bf16_gemv 196 + 30 PASS; qmd shared 112 PASS; cmdlist 27 + 74; gdn 75 + 57; attn256 70 + 21; q36_dec_sim 27; fp8gemm PASS; bw_hazard 260; gpr_boundary 310. Mutant (second x LDS.128 of the XSEQ path at +32 instead of +16): "FAIL: sim XBATCH k 1024 n 96 xb 8 ystride 100: SMEM at pc 506: shared access past the declared size", reverted. Chip: NOT_RUN. --- src/omega_blackwell_codegen_bf16.c | 29 ++++++++++-- src/omega_blackwell_codegen_bf16.h | 8 ++-- src/omega_blackwell_codegen_tern.h | 2 +- src/omega_blackwell_qmd.c | 10 ++-- src/omega_blackwell_qmd.h | 9 ++-- src/omega_gpu_fp8_api.c | 2 +- src/omega_gpu_q36_graph.c | 19 ++++++-- src/omega_gpu_q36_graph.h | 2 +- tests/gpu_bf16_gemv_test.c | 73 ++++++++++++++++++++++++++++-- 9 files changed, 129 insertions(+), 25 deletions(-) diff --git a/src/omega_blackwell_codegen_bf16.c b/src/omega_blackwell_codegen_bf16.c index 0a17718e..9185d710 100644 --- a/src/omega_blackwell_codegen_bf16.c +++ b/src/omega_blackwell_codegen_bf16.c @@ -137,7 +137,7 @@ static int spec_ok(const OmegaBf16GemvSpec *s) { const uint32_t xb = s->xbatch ? s->xbatch : 1u; if (xb > OMEGA_BF16_MAX_XBATCH) return 0; if (xb > 1u && (s->ystride == 0 || s->rows * xb > 16u || (uint64_t)xb * s->k * 4u > OMEGA_BW_QMD_MAX_SHARED_BYTES)) return 0; - if (xb > 1u && ((uint64_t)xb * s->k > 512u * s->warps || (uint64_t)(xb - 1u) * s->ystride * 4u >= (1ull << 31))) return 0; /* 16 staging rounds; y row offsets as immediates */ + if (xb > 1u && ((uint64_t)xb * s->k > 1024u * s->warps || (uint64_t)(xb - 1u) * s->ystride * 4u >= (1ull << 31))) return 0; /* 32 staging rounds; y row offsets as immediates */ /* mutant 4: MASK inverts the skip, XBATCH reads row 0's x for every row (the forms never mix) */ if (s->mutant < 0 || s->mutant > 4 || (s->mutant == 4 && !s->mask && xb < 2u)) return 0; if (s->ystride > (1u << 28)) return 0; /* ystride * 4 fits the 32-bit IMAD.WIDE immediate */ @@ -181,7 +181,7 @@ int omega_blackwell_codegen_bf16_gemv_prog(const OmegaBf16GemvSpec *spec, Blackw /* ---- stage x (k floats, XB rows back to back) in shared memory: one 32-bit word per thread per round ---- */ { const uint32_t rounds = XB * K / (32u * W); - int pxt = V64(e), sa0 = V(e), sa = V(e), pxs[16], xst[16]; + int pxt = V64(e), sa0 = V(e), sa = V(e), pxs[32], xst[32]; for (uint32_t j = 0; j < rounds; j++) { pxs[j] = V64(e); xst[j] = V(e); } if (e->err) return -1; imadw(e, pxt, tid, 4, px); @@ -193,9 +193,14 @@ int omega_blackwell_codegen_bf16_gemv_prog(const OmegaBf16GemvSpec *spec, Blackw } int pw = V64(e), pwr = V64(e), xl = V(e), cnt = V(e), pyr = V64(e), pya = V64(e), t = V(e), f = V(e); - int acc[4][4], wq[4][16], xq[4][2]; + /* XB > 4 (L312 lever 6, the lm_head for all 8 heads in one read): the x rows of a step are read one at a time into one + * quad pair and the eight weight halves of the step are extracted once (fx) instead of once per x row, so 16 warps + * still fit the register file; per (r, m) the FMA order is the one of the one-row kernel, every row stays bit-identical. */ + const int XSEQ = XB > 4u; + int acc[4][8], wq[4][16], xq[8][2], fx[4][8]; for (uint32_t r = 0; r < R; r++) { for (uint32_t m = 0; m < XB; m++) acc[r][m] = V(e); for (uint32_t s = 0; s < D; s++) wq[r][s] = V128(e); } - for (uint32_t m = 0; m < XB; m++) { xq[m][0] = V128(e); xq[m][1] = V128(e); } + if (XSEQ) { xq[0][0] = V128(e); xq[0][1] = V128(e); for (uint32_t r = 0; r < R; r++) for (unsigned i = 0; i < 8; i++) fx[r][i] = V(e); } + else for (uint32_t m = 0; m < XB; m++) { xq[m][0] = V128(e); xq[m][1] = V128(e); } if (e->err) return -1; /* ---- MASK form: tau once, normalized (-0 -> +0); -inf for the skipped rows ---- */ int phi = NOREG, tn = NOREG, zero = NOREG, ninf = NOREG, phr = NOREG, hv = NOREG, mv = NOREG; @@ -239,6 +244,22 @@ int omega_blackwell_codegen_bf16_gemv_prog(const OmegaBf16GemvSpec *spec, Blackw } for (uint32_t s = 0; s < D; s++) { const uint32_t xoff = spec->mutant == 2 ? 0u : s * 1024u; + if (XSEQ) { + const uint32_t words = spec->mutant == 3 ? 3u : 4u; + for (uint32_t r = 0; r < R; r++) + for (uint32_t word = 0; word < words; word++) { imadi(e, fx[r][2u * word], wq[r][s], word, 65536u, NOREG); andi(e, fx[r][2u * word + 1u], wq[r][s], word, 0xffff0000u); } + for (uint32_t m = 0; m < XB; m++) { /* x row m of this step (mutant 4: every row reads row 0), then its FMAs in the one-row order */ + const uint32_t moff = spec->mutant == 4 ? 0u : m * K * 4u; + lds128(e, xq[0][0], xl, xoff + moff, 1); lds128(e, xq[0][1], xl, xoff + moff + 16u, 0); + for (uint32_t r = 0; r < R; r++) + for (uint32_t word = 0; word < words; word++) { + const unsigned sub = (word & 1u) * 2u; + ffma(e, acc[r][m], fx[r][2u * word], xq[0][word >> 1], spec->mutant == 1 ? sub + 1u : sub, acc[r][m]); + ffma(e, acc[r][m], fx[r][2u * word + 1u], xq[0][word >> 1], spec->mutant == 1 ? sub : sub + 1u, acc[r][m]); + } + } + continue; + } for (uint32_t m = 0; m < XB; m++) { /* x row m of this step (mutant 4: every row reads row 0) */ const uint32_t moff = spec->mutant == 4 ? 0u : m * K * 4u; lds128(e, xq[m][0], xl, xoff + moff, m == 0); lds128(e, xq[m][1], xl, xoff + moff + 16u, 0); diff --git a/src/omega_blackwell_codegen_bf16.h b/src/omega_blackwell_codegen_bf16.h index 0593eb00..641dcb04 100644 --- a/src/omega_blackwell_codegen_bf16.h +++ b/src/omega_blackwell_codegen_bf16.h @@ -32,10 +32,12 @@ * is bit for bit the plain kernel's. No FSETP (never proven on the chip): h = hi + 0, t = tau + 0 (-0 becomes +0), * m = FMNMX.MAX(h, t), skip iff (m XOR h) != 0. hi and tau must not be NaN (the screen writes finite values). * - * XBATCH form (spec.xbatch 2..4, L312 stroke: the lm_head once for all heads): xbatch x rows (row m at x + m * k floats, + * XBATCH form (spec.xbatch 2..8, L312 stroke: the lm_head once for all heads): xbatch x rows (row m at x + m * k floats, * all staged in shared memory: k * 4 * xbatch bytes) share every weight read; each (weight row, x row) accumulates in the * SAME order as the one-row kernel, so every output row is bit-identical to the one-row GEMV of its own x; y row m - * goes to y + m * ystride floats (ystride >= n, required). grid_y stays 1. + * goes to y + m * ystride floats (ystride >= n, required). grid_y stays 1. Above 4 x rows (lever 6: all 8 heads in one + * read, 64 KiB of shared memory at k 2048) the x rows of a step are read one at a time and the eight weight halves are + * extracted once per step, so 16 warps still fit the register file; the programs at 1..4 x rows are unchanged. * MASK and XBATCH never mix (spec_ok refuses mask with xbatch > 1). * * mutant (tests only): 1 pairs the two halves of every word with the wrong x (low half takes the high half's x and @@ -62,7 +64,7 @@ extern "C" { #define OMEGA_BF16_ARG_TAU 0x3a8u /* MASK form: u64 tau (one f32) */ #define OMEGA_BF16_MASK_ARGS_WORDS 12u #define OMEGA_BF16_STEP_BYTES 512u /* weight bytes per row per K step (32 lanes x 16) */ -#define OMEGA_BF16_MAX_XBATCH 4u /* x rows per CTA in the XBATCH form (f32 rows staged in shared: 4 x 8 KiB at k 2048) */ +#define OMEGA_BF16_MAX_XBATCH 8u /* x rows per CTA in the XBATCH form (f32 rows staged in shared: 8 x 8 KiB = 64 KiB at k 2048) */ typedef struct { uint32_t k; /* multiple of 256 (one step) and of 32 * warps (exact staging rounds), <= OMEGA_BF16_MAX_K */ diff --git a/src/omega_blackwell_codegen_tern.h b/src/omega_blackwell_codegen_tern.h index 469dba4b..03c236e2 100644 --- a/src/omega_blackwell_codegen_tern.h +++ b/src/omega_blackwell_codegen_tern.h @@ -32,7 +32,7 @@ * per word to an int32 total T; a SHFL.DOWN tree (8, 4, 2, 1) sums its half; y = T - KSC * 2^18 (mod 2^32, exact * because |y| <= 128 * k < 2^31). * - * Shared memory: the launch descriptor allows at most OMEGA_BW_QMD_MAX_SHARED_BYTES (32 KiB, omega_blackwell_qmd.h) per CTA. + * Shared memory: the launch descriptor allows at most OMEGA_BW_QMD_MAX_SHARED_BYTES (64 KiB, omega_blackwell_qmd.h) per CTA. * x takes 2 bytes per column in shared memory, so one chunk of OMEGA_TERN_CHUNK_MAX columns uses 16 KiB, and x is staged * in chunks of at most OMEGA_TERN_CHUNK_MAX = 8192 columns (k <= 8192: one chunk; 8192 < k <= 16384: two equal chunks, * k % 512 == 0). With two chunks each lane l == 0 adds the earlier chunk's int32 y it stored itself (same thread, same diff --git a/src/omega_blackwell_qmd.c b/src/omega_blackwell_qmd.c index dd13ec5a..cb02f8c7 100644 --- a/src/omega_blackwell_qmd.c +++ b/src/omega_blackwell_qmd.c @@ -112,11 +112,15 @@ int omega_blackwell_build_qmd1(uint32_t *qmd1_words, const OmegaBlackwellQmdConf if (gpr < 16) gpr = 16; qmd1_words[35] = (tz & 0xff) | ((gpr & 0x1ff) << 8) | (1u << 17); - /* Word 36: SHARED_MEMORY_SIZE_SHIFTED7 in bits 10:0 (default 8 = 1024 bytes), then the - * MIN/MAX/TARGET_SM_CONFIG_SHARED_MEM_SIZE fields (9, 26, 9) kept as they were. */ + /* Word 36: SHARED_MEMORY_SIZE_SHIFTED7 in bits 10:0 (default 8 = 1024 bytes), then MIN_ (bits 16:11), MAX_ (22:17) + * and TARGET_SM_CONFIG_SHARED_MEM_SIZE (28:23), clcec0qmd.h MW(1168:1163) / MW(1174:1169) / MW(1180:1175). Up to + * 32 KiB the word is the long-standing 0x04b44808 (9, 26, 9: the 32 KB configuration, size_kb / 4 + 1 per mesa nak + * gv100_smem_size_to_hw); above it MIN and TARGET name the 64 KB configuration (17), the smallest SM 12.x configuration + * (0, 8, 16, 32, 64, 100 KB, nouveau_device.c) the CTA fits. MAX stays 26 (100 KB). */ if (cfg->shared_bytes > OMEGA_BW_QMD_MAX_SHARED_BYTES) return -1; uint32_t smem7 = cfg->shared_bytes ? (cfg->shared_bytes + 127u) / 128u : 8u; - qmd1_words[36] = (0x04b44808u & ~0x7ffu) | smem7; + const uint32_t sm_cfg = cfg->shared_bytes <= OMEGA_BW_QMD_SHARED_32K_BYTES ? 32u / 4u + 1u : 64u / 4u + 1u; + qmd1_words[36] = (0x04b44808u & ~0x7ffu & ~(0x3fu << 11) & ~(0x3fu << 23)) | smem7 | (sm_cfg << 11) | (sm_cfg << 23); /* Word 37: SHADER_LOCAL_MEMORY_HIGH_SIZE_SHIFTED4 = 0 (SKEDCHECK05 compliance) */ qmd1_words[37] = 0x00000000; diff --git a/src/omega_blackwell_qmd.h b/src/omega_blackwell_qmd.h index 1d56f1a9..41e77577 100644 --- a/src/omega_blackwell_qmd.h +++ b/src/omega_blackwell_qmd.h @@ -38,11 +38,14 @@ typedef struct { * 0 keeps the long-standing 1024. At most OMEGA_BW_QMD_MAX_SHARED_BYTES: word 36 declares * MIN_ and TARGET_SM_CONFIG_SHARED_MEM_SIZE 9 = 32 KB (mesa nak qmd.rs gv100_smem_size_to_hw: * size_kb / 4 + 1; SM >= 120 configs 0, 8, 16, 32, 64, 100 KB, nouveau_device.c), and a CTA must fit - * the MIN config. Raised from 16 KiB for the bf16 GEMV at k 5120 (20 KiB of x, sc #642); above - * 32 KiB the MIN / TARGET fields must follow the size (not done yet: every launch keeps one word 36). */ + * the MIN config. Raised from 16 KiB for the bf16 GEMV at k 5120 (20 KiB of x, sc #642). Up to 32 KiB the + * word stays the long-standing one (configs 9 / 26 / 9); above it (L312 lever 6: the bf16 lm_head XBATCH form + * at 8 x rows, 64 KiB of x) MIN and TARGET follow the size: the 64 KB configuration, encoded 64 / 4 + 1 = 17 + * (clcec0qmd.h MIN_SM_CONFIG_SHARED_MEM_SIZE MW(1168:1163), TARGET MW(1180:1175); SM 12.x: 99 KB per block). */ uint32_t shared_bytes; } OmegaBlackwellQmdConfig; -#define OMEGA_BW_QMD_MAX_SHARED_BYTES 32768u +#define OMEGA_BW_QMD_MAX_SHARED_BYTES 65536u +#define OMEGA_BW_QMD_SHARED_32K_BYTES 32768u /* the long-standing 32 KB configuration (word 36 unchanged up to here) */ /* Build QMD 0: GRID_NULL null-barrier grid with dependence counter 2 */ int omega_blackwell_build_qmd0(uint32_t *qmd0_words, uint64_t qmd0_va, uint64_t qmd1_va); diff --git a/src/omega_gpu_fp8_api.c b/src/omega_gpu_fp8_api.c index 48758710..122d8867 100644 --- a/src/omega_gpu_fp8_api.c +++ b/src/omega_gpu_fp8_api.c @@ -289,7 +289,7 @@ uint32_t omega_gpu_fp8_depth_for(const OmegaFp8GemvSpec *spec, uint32_t n, uint3 (void)n; if (groups != 1u || !omega_gpu_fp8_deep()) return 0; OmegaFp8GemvSpec deep = *spec; deep.depth = ks; deep.mutant = 0; - if (omega_fp8_gemv_shared_bytes(&deep) > (partial ? OMEGA_BW_QMD_MAX_SHARED_BYTES : OMEGA_GPU_FP8_DEEP_MAX_SHARED_BYTES)) return 0; + if (omega_fp8_gemv_shared_bytes(&deep) > (partial ? OMEGA_BW_QMD_SHARED_32K_BYTES : OMEGA_GPU_FP8_DEEP_MAX_SHARED_BYTES)) return 0; /* the 32 KB bound as before lever 6 */ /* The register check builds the whole kernel (codegen + register allocation). spec_for runs on every launch and every * record, so the answer is remembered per spec: SPEED-1B graph A/B (2026-10-17) measured the unremembered check at * 853..1172 us of host record time per token (48 qkv records) against 45..113 us without the deep default. The answer is diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index 33edf175..591f21a3 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -615,6 +615,14 @@ static int q36_attn_heads(void) { if (g_attn_heads < 0) { const char *e = getenv("AIEN_OMEGA_Q36_ATTN_HEADS"); g_attn_heads = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } return g_attn_heads; } +/* lever 6 (L312): the bf16 lm_head read ONCE for up to 8 heads (XBATCH form at 8 x rows, 64 KiB of shared memory, QMD + * word 36 in the 64 KB SM configuration) instead of once per 4. OFF unless AIEN_OMEGA_Q36_HEAD_XBATCH8=1 (chip-unqualified: + * groups of 4, the lever-1 launches, stay the default). */ +static int g_head_xbatch = 0; +static uint32_t q36_head_xbatch(void) { + if (!g_head_xbatch) { const char *e = getenv("AIEN_OMEGA_Q36_HEAD_XBATCH8"); g_head_xbatch = (e && e[0] == '1' && e[1] == 0) ? 8 : 4; } + return (uint32_t)g_head_xbatch; +} int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS; @@ -633,10 +641,10 @@ int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (q36_gdn_heads() && omega_gpu_gdn_prepare_heads(g->cfg.gdn) != OMEGA_GPU_GDN_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; /* lever 5: the attention of every head in one launch (record_layer_heads; its own cache slot) */ if (q36_attn_heads() && omega_gpu_decode_attn256_prepare_heads(g->cfg.attn) != OMEGA_GPU_DATTN_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; - /* lever 1: the bf16 lm_head read once per group of up to OMEGA_BF16_MAX_XBATCH heads (record_final_heads) */ + /* lever 1: the bf16 lm_head read once per group of up to q36_head_xbatch() heads (record_final_heads; lever 6: 8) */ if (!g->head8) { uint32_t n = 0, k = 0; omega_gpu_bf16_tensor_shape(g->cfg.lm_head, &n, &k); - for (uint32_t xb = 2; xb <= OMEGA_BF16_MAX_XBATCH && xb <= g->heads; xb++) + for (uint32_t xb = 2; xb <= q36_head_xbatch() && xb <= g->heads; xb++) if (omega_gpu_bf16_prepare_xbatch(k, xb, g->am_ctas * OMEGA_DEC_ARGMAX_SPAN) != OMEGA_GPU_BF16_OK) return OMEGA_GPU_DGRAPH_CHIP_FAIL; } g->batch = 1; @@ -864,7 +872,7 @@ int omega_gpu_q36_graph_record_head_final(OmegaGpuQ36Graph *g, uint32_t h) { } /* The batch's final head (v2 lever 1, L312): every head's hidden is ready after the last layer (record_layer_heads), so - * the bf16 lm_head runs once per group of up to OMEGA_BF16_MAX_XBATCH heads (the XBATCH form: x rows hidden_of(h0..), + * the bf16 lm_head runs once per group of up to q36_head_xbatch() heads (4; 8 with lever 6) (the XBATCH form: x rows hidden_of(h0..), * y rows logits_of(h0..), ystride the logits slot; each row bit-identical to its own one-head launch), then the argmax * per head. The FP8 head keeps the per-head path (stroke() calls record_head_final). */ static int record_final_heads(OmegaGpuQ36Graph *g) { @@ -873,8 +881,9 @@ static int record_final_heads(OmegaGpuQ36Graph *g) { for (uint32_t h = 0; h < N; h++) if (!g->hidden_ready[h]) return fail(g, "q36 graph: batch final before the last layer", OMEGA_GPU_DGRAPH_BAD_ARGS); int rc = OMEGA_GPU_DGRAPH_OK; - for (uint32_t h0 = 0; h0 < N && rc == OMEGA_GPU_DGRAPH_OK; h0 += OMEGA_BF16_MAX_XBATCH) { - const uint32_t xb = N - h0 < OMEGA_BF16_MAX_XBATCH ? N - h0 : OMEGA_BF16_MAX_XBATCH; + const uint32_t G = q36_head_xbatch(); + for (uint32_t h0 = 0; h0 < N && rc == OMEGA_GPU_DGRAPH_OK; h0 += G) { + const uint32_t xb = N - h0 < G ? N - h0 : G; rc = after_op(g, OMEGA_GPU_Q36_K_LM_HEAD, omega_gpu_bf16_gemv_xbatch_record(g->cl, g->cfg.lm_head, xb, va_of(g, hidden_of(g, h0)), va_of(g, logits_of(g, h0)), g->am_ctas * OMEGA_DEC_ARGMAX_SPAN)); } diff --git a/src/omega_gpu_q36_graph.h b/src/omega_gpu_q36_graph.h index 076b03f7..3059972a 100644 --- a/src/omega_gpu_q36_graph.h +++ b/src/omega_gpu_q36_graph.h @@ -170,7 +170,7 @@ void omega_q36_perm_table(uint32_t *tab, uint32_t k); * one grouped GEMM over the N x 9 rows sorted by expert (GROUP kernel: every expert any conversation picked is read once), * the per-conversation state kernels (GDN, attention, router, COMBINE) stay per head. Values are those of the per-head * stroke (the gate: every head word-identical to its run alone). The final head (lever 1): the bf16 lm_head read once per - * group of up to OMEGA_BF16_MAX_XBATCH heads (the XBATCH GEMV form), then the argmax per head; the FP8 head stays per head. + * group of up to 4 heads (8 with lever 6, AIEN_OMEGA_Q36_HEAD_XBATCH8=1; the XBATCH GEMV form), then the argmax per head; the FP8 head stays per head. * set_batch pins the GEMM and XBATCH kernels (session, once); AIEN_OMEGA_Q36_BATCH=1 at create does the same. * record_layer_heads is the per-layer step stroke() uses. */ int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on); diff --git a/tests/gpu_bf16_gemv_test.c b/tests/gpu_bf16_gemv_test.c index a721aacd..bdbe3932 100644 --- a/tests/gpu_bf16_gemv_test.c +++ b/tests/gpu_bf16_gemv_test.c @@ -11,6 +11,7 @@ */ #include "omega_gpu_bf16_gemv_api.h" #include "omega_gpu_session.h" +#include "omega_gpu_cmdlist.h" #include "bw_warp_sim_k.h" #include "out_sha.h" #include @@ -99,10 +100,17 @@ static void host_only(void) { uint32_t decl = ((gg + 1 + 7) / 8) * 8; CHECK(rc == 0 && omega_bf16_gemv_shared_bytes(&s) == 32768u && 32u * 16u * decl <= 65536u, "codegen XBATCH 4 k 2048 warps 16 depth 8: rc %d insns %u gprs %u shared %u", rc, ni, gg, omega_bf16_gemv_shared_bytes(&s)); printf("codegen XBATCH 4 k 2048 warps 16 depth 8: %u instructions, %u registers (declared %u), shared %u bytes\n", ni, gg, decl, omega_bf16_gemv_shared_bytes(&s)); } - { OmegaBf16GemvSpec s = { 2048, 1, 16, 8, 0, 249856, 5, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 5 refused"); } + { /* L312 lever 6: 8 x rows per CTA (the lm_head once for all 8 heads), 64 KiB of shared memory, 16 warps inside the register file */ + OmegaBf16GemvSpec s = { 2048, 1, 16, 8, 0, 249856, 8, 0 }; uint32_t ni = 0, gg = 0; int rc = omega_bf16_gemv_prog_stats(&s, &ni, &gg); + uint32_t decl = ((gg + 1 + 7) / 8) * 8; + CHECK(rc == 0 && ni <= 1024 && omega_bf16_gemv_shared_bytes(&s) == 65536u && 32u * 16u * decl <= 65536u, "codegen XBATCH 8 k 2048 warps 16 depth 8: rc %d insns %u gprs %u shared %u", rc, ni, gg, omega_bf16_gemv_shared_bytes(&s)); + printf("codegen XBATCH 8 k 2048 warps 16 depth 8: %u instructions, %u registers (declared %u, register file %u of 65536), shared %u bytes\n", ni, gg, decl, 32u * 16u * decl, omega_bf16_gemv_shared_bytes(&s)); + for (uint32_t xb = 5; xb <= 7; xb++) { s.xbatch = xb; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) == 0, "codegen XBATCH %u k 2048 builds", xb); } } + { OmegaBf16GemvSpec s = { 2048, 1, 16, 8, 0, 249856, 9, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 9 refused"); } { OmegaBf16GemvSpec s = { 2048, 1, 16, 8, 0, 0, 2, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch without ystride refused"); } - { OmegaBf16GemvSpec s = { 4096, 1, 16, 16, 0, 249856, 4, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 4 x k 4096 (64 KiB shared) refused"); } - { OmegaBf16GemvSpec s = { 2048, 1, 8, 8, 0, 249856, 4, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 4 x k 2048 at 8 warps (more than 16 staging rounds) refused"); } + { OmegaBf16GemvSpec s = { 8192, 1, 32, 16, 0, 249856, 4, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 4 x k 8192 (128 KiB shared) refused"); } + { OmegaBf16GemvSpec s = { 4096, 1, 16, 16, 0, 249856, 8, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 8 x k 4096 (128 KiB shared) refused"); } + { OmegaBf16GemvSpec s = { 2048, 1, 8, 8, 0, 249856, 8, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "xbatch 8 x k 2048 at 8 warps (more than 32 staging rounds) refused"); } { OmegaBf16GemvSpec s = { 2048, 1, 16, 8, 4, 249856, 1, 0 }; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, NULL) != 0, "mutant 4 at xbatch 1 refused"); } CHECK(OMEGA_BF16_ARGS_WORDS <= OMEGA_GPU_SESSION_MAX_ARGS, "argument words fit the constant bank window"); uint16_t bad[256]; memset(bad, 0, sizeof bad); bad[7] = 0x7f80; @@ -263,7 +271,8 @@ static void sim_battery(void) { } } { /* XBATCH form: every weight read feeds xb x rows; mutant 4 (every row reads x row 0) must be caught */ - struct { uint32_t k, n, xb, ystride, grid; } xp[] = { { 1024, 96, 2, 100, 2 }, { 1024, 96, 4, 96, 3 }, { 2048, 64, 2, 70, 2 }, { 1024, 40, 3, 50, 2 } }; + struct { uint32_t k, n, xb, ystride, grid; } xp[] = { { 1024, 96, 2, 100, 2 }, { 1024, 96, 4, 96, 3 }, { 2048, 64, 2, 70, 2 }, { 1024, 40, 3, 50, 2 }, + { 1024, 96, 8, 100, 2 }, { 1024, 40, 6, 44, 3 }, { 1024, 64, 5, 64, 2 } }; /* lever 6: 5..8 rows (the one-at-a-time x path) */ for (size_t i = 0; i < sizeof xp / sizeof xp[0]; i++) { char msg[300]; size_t bad = 1; int err = sim_multi_point(xp[i].k, xp[i].n, xp[i].xb, xp[i].xb, xp[i].ystride, xp[i].grid, 0, 61 + (uint32_t)i, msg, sizeof msg, &bad); @@ -274,6 +283,11 @@ static void sim_battery(void) { int err = sim_multi_point(1024, 64, 2, 2, 64, 2, 4, 79, msg, sizeof msg, &bad); CHECK(!err && bad != 0, "sim XBATCH mutant 4 must be caught: %s", msg); printf("sim XBATCH mutant 4: %s %s\n", err ? "ERROR" : bad ? "caught" : "NOT CAUGHT", msg); + for (int m = 1; m <= 4; m++) { /* lever 6: every mutant caught on the 8-row path too */ + bad = 0; err = sim_multi_point(1024, 64, 8, 8, 64, 2, m, 80 + (uint32_t)m, msg, sizeof msg, &bad); + CHECK(!err && bad != 0, "sim XBATCH 8 mutant %d must be caught: %s", m, msg); + printf("sim XBATCH 8 mutant %d: %s %s\n", m, err ? "ERROR" : bad ? "caught" : "NOT CAUGHT", msg); + } } struct { uint32_t k, n, rows, warps, depth, grid; } pts[] = { { 2048, 100, 1, 8, 8, 2 }, { 2048, 100, 1, 8, 4, 3 }, { 2048, 64, 1, 8, 1, 2 }, { 2048, 96, 2, 8, 4, 2 }, { 2048, 96, 4, 8, 4, 1 }, @@ -386,6 +400,57 @@ static int chip_run(const char *out_path, uint32_t reps, uint32_t N, uint32_t K) } omega_gpu_bf16_tensor_free(ts); } + /* L312 lever 6: the XBATCH form on the chip, 4 x rows (32 KiB of shared memory, the known configuration) then 8 x rows + * (64 KiB: the first launch above the 32 KB configuration, word 36 MIN/TARGET 17): every y row bit-identical to the + * one-row emulation of its own x, the ystride gap untouched; mutant 4 (every row reads x row 0) caught at 8 rows. */ + if (!omega_gpu_session_is_blocked()) { + const uint32_t MN = 4096, YS = MN + 8; OmegaGpuBf16Tensor *ts = NULL; + rc = omega_gpu_bf16_tensor_upload(MN, K, w, &ts); + CHECK(rc == 0, "xbatch tensor upload"); + static const uint32_t xbs[] = { 4, 8 }; + for (size_t i = 0; i < 2 && rc == 0; i++) { + const uint32_t xb = xbs[i]; + float *xs = malloc((size_t)xb * K * 4); + for (uint32_t r = 0; r < xb; r++) { float *t = make_x(K, 90010 + r); memcpy(xs + (size_t)r * K, t, (size_t)K * 4); free(t); } + for (int mut = 0; mut <= (xb == 8 ? 4 : 0); mut += 4) { + omega_gpu_bf16_test_set_mutant(mut); + int prc = omega_gpu_bf16_prepare_xbatch(K, xb, YS); + CHECK(prc == 0, "chip XBATCH %u mutant %d prepare: %s %s", xb, mut, omega_gpu_bf16_rc_name(prc), prc ? omega_gpu_bf16_last_error() : ""); + OmegaGpuCmdList *cl = NULL; OmegaGpuMem bx, by; memset(&bx, 0, sizeof bx); memset(&by, 0, sizeof by); + int ok = prc == 0 && omega_gpu_cmdlist_create(2, &cl) == 0; + omega_gpu_session_lock(); + if (ok) ok = omega_gpu_session_alloc((size_t)xb * K * 4, &bx) == 0 && omega_gpu_session_alloc((size_t)xb * YS * 4, &by) == 0; + if (ok) { + memcpy(bx.cpu, xs, (size_t)xb * K * 4); float *yb = by.cpu; for (size_t j = 0; j < (size_t)xb * YS; j++) yb[j] = -999.0f; + ok = omega_gpu_session_sync_to_gpu(&bx) == 0 && omega_gpu_session_sync_to_gpu(&by) == 0; + } + if (ok) ok = omega_gpu_bf16_gemv_xbatch_record(cl, ts, xb, bx.va, by.va, YS) == 0; + OmegaGpuCmdListOpts opts; memset(&opts, 0, sizeof opts); OmegaGpuCmdListStats stc; memset(&stc, 0, sizeof stc); + if (ok) ok = omega_gpu_cmdlist_submit(cl, &opts, &stc) == 0; + if (ok) ok = omega_gpu_session_sync_to_cpu(&by) == 0; + size_t bad = 0, gap = 0; + if (ok) { + const float *yb = by.cpu; + for (uint32_t r = 0; r < xb; r++) { size_t f; bad += compare_emu(w, xs + (size_t)r * K, MN, K, yb + (size_t)r * YS, &f); for (uint32_t j = MN; j < YS; j++) if (yb[(size_t)r * YS + j] != -999.0f) gap++; } + } + if (bx.cpu) omega_gpu_session_free(&bx); + if (by.cpu) omega_gpu_session_free(&by); + omega_gpu_session_unlock(); + if (cl) omega_gpu_cmdlist_free(cl); + if (mut == 0) { + CHECK(ok && bad == 0 && gap == 0, "chip XBATCH %u (%u bytes of shared memory): %s, %zu of %u x %u rows differ, %zu gap words written", xb, K * 4 * xb, ok ? "ran" : omega_gpu_bf16_last_error(), bad, MN, xb, gap); + printf("chip XBATCH %u (%u bytes of shared memory): %s, %zu of %u x %u rows differ from the emulation%s\n", xb, K * 4 * xb, ok ? "ran" : "FAILED", bad, MN, xb, ok && !bad ? " (bit-identical)" : ""); + } else { + CHECK(ok && bad != 0, "chip XBATCH %u mutant 4 must be caught (%s, %zu rows differ)", xb, ok ? "ran" : omega_gpu_bf16_last_error(), bad); + printf("chip XBATCH %u mutant 4: %s (%zu rows differ)\n", xb, ok && bad ? "caught" : "NOT CAUGHT", bad); + } + if (out) fprintf(out, ",{\"point\":\"xbatch %u mutant %d\",\"ok\":%d,\"rows_bad\":%zu,\"shared_bytes\":%u}", xb, mut, ok, bad, K * 4 * xb); + } + omega_gpu_bf16_test_set_mutant(0); + free(xs); + } + omega_gpu_bf16_tensor_free(ts); + } free(w); free(x); free(y); free(y2); if (out) { fprintf(out, "],\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); fclose(out); } return g_failed ? 1 : 0; From 93caa81843cb5437710993181c21d837dfde89c5 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:11:03 -0500 Subject: [PATCH 7/8] q36 stroke lever 7: the attention gate of every head in one launch, AIEN_OMEGA_Q36_GATE_ROWS=1 (DRA-67, #215) Port of omega-mv 424d25c94 (cherry of 881f4397) with the 0473989f merge resolution (one GATE rows form, L369's layout: a/out by width, g by stride). - codegen_dec: GATE mode 1 refuses a rows spec without width or stride, mode 2+ refused; mutant 2 (rows: every row reads row 0's gate). Existing program hashes unchanged. - q36_graph (hand-ported): K_GATE_M1_R (graph mutant 3 on the rows form); record_layer_heads records ONE K_GATE_R launch (grid MIXER_OUT/256 x N) after the last attention instead of N. OFF unless AIEN_OMEGA_Q36_GATE_ROWS=1 (omega-mv had it on unless =0; here default off, chip-unqualified). With the switch on and lever 5 off, the per-head loop keeps only attention. - tests: q36_dec_sim gate rows 1/3/8 heads bit-identical, mutants 1 and 2 caught (.width = C from 0473989f); gpu_cmdlist combine+norm rows and gate rows chip cases (s.width = ROWS_GC from 0473989f); q36_codegen_hash enumerates the GATE rows and RES rows+stride forms. - omega-mv 4eaa4ffe (cmdlist designated initializers) needs no port: CUDApp 62008d6 already names the fields. Host (nice 19, taskset 0-9): q36_codegen_hash "685 lines (digest a6f667712ba05601); base 509 lines (digest 54cf5c03d685f1ec); 0 base lines changed or missing"; q36_dec_sim 34 PASS; cmdlist 27 + 74; bf16_gemv 196 + 30; qmd shared 112; gdn 75 + 57; attn256 70 + 21; fp8gemm PASS; bw_hazard 260; gpr_boundary 310. Mutant (rows g offset by width instead of stride): "FAIL: GATE rows: 3 heads: 8192 of 12288 gate outputs differ from the one-row program", 34 checks 2 failed; reverted. Chip: NOT_RUN. --- src/omega_blackwell_codegen_dec.c | 9 ++-- src/omega_blackwell_codegen_dec.h | 5 +- src/omega_gpu_q36_graph.c | 36 +++++++++++---- tests/gpu_cmdlist_test.c | 76 ++++++++++++++++++++++++++++++- tests/q36_codegen_hash.c | 3 +- tests/q36_dec_sim_test.c | 47 +++++++++++++++++++ 6 files changed, 161 insertions(+), 15 deletions(-) diff --git a/src/omega_blackwell_codegen_dec.c b/src/omega_blackwell_codegen_dec.c index 8ad70f50..b2cb114d 100644 --- a/src/omega_blackwell_codegen_dec.c +++ b/src/omega_blackwell_codegen_dec.c @@ -69,6 +69,7 @@ static void movrz(Em *e, Op d) { BlackwellIRInsn i = I0(BW_IR_MOV_RZ); i.dst_vre static void imadi(Em *e, Op d, Op a, uint32_t imm, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d.v; i.dst_subreg = (uint8_t)d.s; i.src1_vreg = a.v; i.src1_subreg = (uint8_t)a.s; i.imm = imm; i.src3_vreg = c; emit(e, i, K_FIXED); } static void imadw(Em *e, int d64, int a, uint32_t imm, int c64) { BlackwellIRInsn i = I0(BW_IR_IMAD_WIDE); i.dst_vreg = d64; i.src1_vreg = a; i.imm = imm; i.src3_vreg = c64; emit(e, i, K_FIXED); } static void mov(Em *e, Op d, Op a) { imadi(e, d, a, 1u, NOREG); } +static void imadr(Em *e, int d, int a, int b, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; i.src3_vreg = c; emit(e, i, K_FIXED); } static void shr(Em *e, int d, int a, uint32_t imm) { BlackwellIRInsn i = I0(BW_IR_SHF_R); i.dst_vreg = d; i.src1_vreg = a; i.imm = imm; emit(e, i, K_FIXED); } static void andi(Em *e, Op d, Op a, uint32_t imm) { BlackwellIRInsn i = I0(BW_IR_LOP3_AND); i.dst_vreg = d.v; i.dst_subreg = (uint8_t)d.s; i.src1_vreg = a.v; i.src1_subreg = (uint8_t)a.s; i.imm = imm; emit(e, i, K_FIXED); } static void xorr(Em *e, Op d, Op a, Op b) { BlackwellIRInsn i = I0(BW_IR_LOP3_XOR); i.dst_vreg = d.v; i.dst_subreg = (uint8_t)d.s; i.src1_vreg = a.v; i.src1_subreg = (uint8_t)a.s; i.src2_vreg = b.v; i.src2_subreg = (uint8_t)b.s; emit(e, i, K_FIXED); } @@ -410,6 +411,8 @@ static int gen_gather(Em *e, const OmegaDecSpec *sp) { } static int gen_gate(Em *e, const OmegaDecSpec *sp) { + const int rows = sp->mode == 1; /* rows form (L369, L312 lever 7): needs a row width and a g stride */ + if (sp->mode > 1 || (rows && (!sp->stride || !sp->width))) return -1; int udesc = UV64(e), pa = V64(e), pg = V64(e), pout = V64(e), lim = V(e), tid = V(e), cx = V(e), n = V(e); int aa = V64(e), ga = V64(e), oa = V64(e), av = V(e), gv = V(e), t = V(e), cst = V(e); if (e->err) return -1; @@ -419,11 +422,12 @@ static int gen_gate(Em *e, const OmegaDecSpec *sp) { imadi(e, R(n), R(cx), OMEGA_DEC_THREADS, tid); isetp_ge_u32(e, n, lim); Region r = region_skip_if_p0(e); - if (sp->mode & 1u) { /* rows (L369): row ctaid.y; a and out move by width floats a row, g by stride floats */ + if (rows) { /* rows (L369; L312 lever 7 shares it): row ctaid.y; a and out move by width floats a row, g by stride floats */ int cy = V(e), ro = V(e); if (e->err) return -1; s2r(e, cy, BW_SR_CTAID_Y); imadi(e, R(ro), R(cy), sp->width, n); imadw(e, aa, ro, 4u, pa); imadw(e, oa, ro, 4u, pout); - imadi(e, R(ro), R(cy), sp->stride, n); imadw(e, ga, ro, 4u, pg); + if (sp->mutant == 2) imadw(e, ga, n, 4u, pg); /* mutant 2: every row reads row 0's gate (must be caught) */ + else { imadi(e, R(ro), R(cy), sp->stride, n); imadw(e, ga, ro, 4u, pg); } } else { imadw(e, aa, n, 4u, pa); imadw(e, ga, n, 4u, pg); imadw(e, oa, n, 4u, pout); } ldg(e, BW_IR_LDG_E, av, aa, 0, udesc, 1); ldg(e, BW_IR_LDG_E, gv, ga, 0, udesc, 0); @@ -521,7 +525,6 @@ static int gen_xbound(Em *e, const OmegaDecSpec *sp) { /* ---- GROUP: the stroke's segment table (L312 v2) ---- */ static void lds32(Em *e, int d, int addr) { BlackwellIRInsn i = I0(BW_IR_LDS32); i.dst_vreg = d; i.src1_vreg = addr; emit(e, i, K_VAR); } -static void imadr(Em *e, int d, int a, int b, int c) { BlackwellIRInsn i = I0(BW_IR_IMAD); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; i.src3_vreg = c; emit(e, i, K_FIXED); } /* store v at base64 + off (tmp64 scratch; one = a register holding 1) */ static void stg_at(Em *e, int tmp64, int one, int base64, uint32_t off, Op v, int udesc) { imadw(e, tmp64, one, off, base64); stg(e, tmp64, v, udesc); } /* d = 1 iff a < b (unsigned, both < 2^31): (a - b) >> 31 */ diff --git a/src/omega_blackwell_codegen_dec.h b/src/omega_blackwell_codegen_dec.h index 70744b18..368fbd9b 100644 --- a/src/omega_blackwell_codegen_dec.h +++ b/src/omega_blackwell_codegen_dec.h @@ -21,6 +21,9 @@ * attention: the fused q|gate|k|v GEMV row to the attention kernel's permuted q|k|v plus the gate (sc #642; * the permutation crosses the FP8 weights' 128-row scale blocks, so it cannot be folded into the weights). * GATE out[n] = a[n] * sigmoid(g[n]) for n < count, sigmoid(v) = RCP(1 + EX2(-v * log2 e)): the attention output gate. + * mode 1 (rows, L369; L312 lever 7 records every head's gate with it): row r = ctaid.y, a and out at + * + r * width floats, g at + r * stride floats; mode 1 without a width or a stride, and mode 2+, are refused. + * Mutant 1 skips the sigmoid; mutant 2 (rows) makes every row read row 0's gate. * XBOUND (HUM L314 exact two-pass head) every CTA computes t = sum h^2 + 2^-100 over the 2048 plain hidden values and * hn = t * RSQ(t) * (1 + 2^-10) >= |h| (the widening covers the f32 sum, RSQ and the products); then row r * (r = ctaid * 256 + tid < count) writes B = c[r] * hn + |s[r]| * 2^-20 + 2^-100, lo = s + (-B), hi = s + B, so @@ -133,7 +136,7 @@ typedef struct { the routing weights row stride (bytes, a multiple of 16) */ int mutant; /* TEST ONLY. RES: 1 = norm without the weight; 2 = COMBINE skips expert 7. SWIGLU: 1 = up half read at +767. ARGMAX: 1 = last equal index instead of first. - GATHER: 1 = source index + 1. GATE: 1 = the gate dropped (out = a). + GATHER: 1 = source index + 1. GATE: 1 = the gate dropped (out = a); 2 (mode 1) = every row reads row 0's gate. GROUP: 1 = sort key without the row tie-break; 2 = segment cnt one short; 3 = the trailing empty segments left unwritten. 0 none */ uint32_t width; /* RES: the row width (0 = OMEGA_DEC_HIDDEN; a multiple of 1024 up to 8192, COMBINE only at 2048). diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index 591f21a3..45782061 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -30,7 +30,8 @@ /* glue kernels */ enum { K_NORM, K_ADD, K_CN, K_SW, K_GATHER, K_GATE, K_AM0, K_AM1, K_SW_M1, K_GATHER_M1, K_GATE_M1, K_CN_M3, K_COPY, K_NORM_R, K_ADD_R, K_PERM_XQ, K_PERM_O, K_PERM_XO, K_PERM_ACT, K_GROUP, K_XS, K_XB, K_XB_M1, - K_CN_R, K_CN_R_M3, K_GATE_R, K_COUNT }; /* K_NORM_R .. K_GROUP: the batch (v2) kernels; K_XS .. K_XB_M1: the exact head; K_CN_R: COMBINE|NORM of every head in one launch (L356) */ + K_CN_R, K_CN_R_M3, K_GATE_R, K_GATE_M1_R, K_COUNT }; /* K_NORM_R .. K_GROUP: the batch (v2) kernels; K_XS .. K_XB_M1: the exact head; K_CN_R: COMBINE|NORM of every head in one launch (L356) */ + /* K_GATE_R: every row's attention gate in one launch (L369 prefill tokens, L312 lever 7 stroke heads) */ #define SEGD_ROWS 2u /* dense segment entries per layer in the batch: mix, o */ #define COPY_ROW 256u /* K_COPY: GATHER rows of 256 floats through the identity table */ @@ -272,6 +273,7 @@ int omega_gpu_q36_graph_create_heads(const OmegaGpuQ36GraphConfig *cfg, uint32_t [K_CN_R] = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS, .groups = NG }, /* stride set below */ [K_CN_R_M3] = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM | OMEGA_DEC_RES_ROWS, .groups = NG, .mutant = 3 }, [K_GATE_R] = { .kind = OMEGA_DEC_GATE, .mode = 1, .width = OMEGA_GPU_Q36_MIXER_OUT, .stride = OMEGA_GPU_Q36_ATT_MIX }, /* L369 prefill: every token's gate */ + [K_GATE_M1_R] = { .kind = OMEGA_DEC_GATE, .mode = 1, .width = OMEGA_GPU_Q36_MIXER_OUT, .stride = OMEGA_GPU_Q36_ATT_MIX, .mutant = 1 }, }; spec[K_PERM_XO].stride = L->lb_stride / 4u; spec[K_CN_R].stride = L->lb_stride; spec[K_CN_R_M3].stride = L->lb_stride; /* head h's routing weights: wts_va + h * lb_stride */ @@ -623,6 +625,13 @@ static uint32_t q36_head_xbatch(void) { if (!g_head_xbatch) { const char *e = getenv("AIEN_OMEGA_Q36_HEAD_XBATCH8"); g_head_xbatch = (e && e[0] == '1' && e[1] == 0) ? 8 : 4; } return (uint32_t)g_head_xbatch; } +/* lever 7 (L312): the attention gate of every head in ONE launch (K_GATE_R, the rows form, grid MIXER_OUT / 256 x N) instead of + * one launch per head. OFF unless AIEN_OMEGA_Q36_GATE_ROWS=1 (chip-unqualified: the per-head launches stay the default). */ +static int g_gate_rows = -1; +static int q36_gate_rows(void) { + if (g_gate_rows < 0) { const char *e = getenv("AIEN_OMEGA_Q36_GATE_ROWS"); g_gate_rows = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; } + return g_gate_rows; +} int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on) { if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS; @@ -773,16 +782,25 @@ int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t l, cons if (rc == OMEGA_GPU_DGRAPH_OK) rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record_heads(g->cl, hs, N, ki, g->cfg.eps, SCALE_2P64)); } - for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK; h++) { - const uint64_t agg_h = aggN + (uint64_t)h * OMEGA_GPU_Q36_ATT_MIX * 4u, att_h = attN + h * MOS; - if (!q36_attn_heads()) - rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record(g->cl, g->attn_h[h], ki, pos[h], agg_h, g->cfg.eps, SCALE_2P64, att_h)); + if (!q36_gate_rows() || !q36_attn_heads()) + for (uint32_t h = 0; h < N && rc == OMEGA_GPU_DGRAPH_OK; h++) { + const uint64_t agg_h = aggN + (uint64_t)h * OMEGA_GPU_Q36_ATT_MIX * 4u, att_h = attN + h * MOS; + if (!q36_attn_heads()) + rc = after_op(g, OMEGA_GPU_Q36_K_ATTN, omega_gpu_decode_attn256_record(g->cl, g->attn_h[h], ki, pos[h], agg_h, g->cfg.eps, SCALE_2P64, att_h)); + if (q36_gate_rows()) continue; /* lever 7: the gate of every head below, after the last attention */ + uint32_t w2[OMEGA_DEC_GT_WORDS]; memset(w2, 0, sizeof w2); + put64(w2, OMEGA_DEC_GT_A, att_h); put64(w2, OMEGA_DEC_GT_G, agg_h + OMEGA_GPU_Q36_ATT_QKV * 4u); put64(w2, OMEGA_DEC_GT_OUT, att_h); + w2[(OMEGA_DEC_GT_N - 0x380) / 4] = OMEGA_GPU_Q36_MIXER_OUT; + if (rc == OMEGA_GPU_DGRAPH_OK) + rc = add_glue(g, OMEGA_GPU_Q36_K_GATE, g->mutant == 3 ? K_GATE_M1 : K_GATE, OMEGA_GPU_Q36_MIXER_OUT / OMEGA_DEC_THREADS, 1, + OMEGA_GPU_Q36_MIXER_OUT, w2, OMEGA_DEC_GT_WORDS); + } + if (q36_gate_rows() && rc == OMEGA_GPU_DGRAPH_OK) { /* lever 7: ONE gate launch for the N heads (a/out move by MIXER_OUT, g by ATT_MIX) */ uint32_t w2[OMEGA_DEC_GT_WORDS]; memset(w2, 0, sizeof w2); - put64(w2, OMEGA_DEC_GT_A, att_h); put64(w2, OMEGA_DEC_GT_G, agg_h + OMEGA_GPU_Q36_ATT_QKV * 4u); put64(w2, OMEGA_DEC_GT_OUT, att_h); + put64(w2, OMEGA_DEC_GT_A, attN); put64(w2, OMEGA_DEC_GT_G, aggN + OMEGA_GPU_Q36_ATT_QKV * 4u); put64(w2, OMEGA_DEC_GT_OUT, attN); w2[(OMEGA_DEC_GT_N - 0x380) / 4] = OMEGA_GPU_Q36_MIXER_OUT; - if (rc == OMEGA_GPU_DGRAPH_OK) - rc = add_glue(g, OMEGA_GPU_Q36_K_GATE, g->mutant == 3 ? K_GATE_M1 : K_GATE, OMEGA_GPU_Q36_MIXER_OUT / OMEGA_DEC_THREADS, 1, - OMEGA_GPU_Q36_MIXER_OUT, w2, OMEGA_DEC_GT_WORDS); + rc = add_glue(g, OMEGA_GPU_Q36_K_GATE, g->mutant == 3 ? K_GATE_M1_R : K_GATE_R, OMEGA_GPU_Q36_MIXER_OUT / OMEGA_DEC_THREADS, N, + (size_t)OMEGA_GPU_Q36_MIXER_OUT * N, w2, OMEGA_DEC_GT_WORDS); } if (rc == OMEGA_GPU_DGRAPH_OK) rc = rec_perm(g, K_PERM_O, attN, pt4096, op, OMEGA_GPU_Q36_MIXER_OUT, N); } diff --git a/tests/gpu_cmdlist_test.c b/tests/gpu_cmdlist_test.c index 2d80c106..db034171 100644 --- a/tests/gpu_cmdlist_test.c +++ b/tests/gpu_cmdlist_test.c @@ -85,6 +85,11 @@ static void glue_fill(Glue *g, uint32_t seed, int tie) { /* ---- kernels ---- */ typedef struct { BlackwellIRProgram prog; OmegaGpuMem code; uint32_t gpr; int built; } Kern; static Kern K_axpy, K_res_an, K_res_cn, K_sw, K_am0, K_am1, K_res_m1, K_res_m2, K_res_cn_m1, K_sw_m1, K_am_m1, K_axpy_big; +#define ROWS_N 3u /* heads in the rows chip check */ +#define ROWS_WS 256u /* bytes between one head's routing weights and the next */ +#define ROWS_GS 9216u /* floats between one head's attention mix row and the next (the gate at + 5120) */ +#define ROWS_GC 4096u /* gate outputs per head */ +static Kern K_cn9, K_cn9r, K_cn9r_m3, K_gate, K_gate_r, K_gate_r_m2; /* the rows forms (L356 combine+norm, L312 lever 7 gate) */ static int kern_prog(Kern *k, const OmegaDecSpec *sp) { k->built = 0; return omega_blackwell_codegen_dec_prog(sp, &k->prog); } static int kern_upload(Kern *k) { @@ -118,6 +123,12 @@ static int specs_build(void) { memset(&s, 0, sizeof s); s.kind = OMEGA_DEC_ARGMAX; s.mode = 0; if (kern_prog(&K_am0, &s)) return -1; memset(&s, 0, sizeof s); s.kind = OMEGA_DEC_ARGMAX; s.mode = 1; if (kern_prog(&K_am1, &s)) return -1; memset(&s, 0, sizeof s); s.kind = OMEGA_DEC_ARGMAX; s.mode = 0; s.mutant = 1; if (kern_prog(&K_am_m1, &s)) return -1; + memset(&s, 0, sizeof s); s.kind = OMEGA_DEC_RES; s.mode = OMEGA_DEC_RES_COMBINE | OMEGA_DEC_RES_NORM; s.groups = 9; if (kern_prog(&K_cn9, &s)) return -1; + s.mode |= OMEGA_DEC_RES_ROWS; s.stride = ROWS_WS; if (kern_prog(&K_cn9r, &s)) return -1; + s.mutant = 3; if (kern_prog(&K_cn9r_m3, &s)) return -1; + memset(&s, 0, sizeof s); s.kind = OMEGA_DEC_GATE; if (kern_prog(&K_gate, &s)) return -1; + s.mode = 1; s.width = ROWS_GC; s.stride = ROWS_GS; if (kern_prog(&K_gate_r, &s)) return -1; + s.mutant = 2; if (kern_prog(&K_gate_r_m2, &s)) return -1; return 0; } @@ -389,7 +400,8 @@ static int chip_run(const char *out_path, uint32_t reps) { OmegaGpuCmdList *cl = NULL; if (omega_gpu_cmdlist_create(OMEGA_GPU_CMDLIST_MAX_LAUNCHES, &cl) != 0) return chip_fail("cmdlist create"); omega_gpu_session_lock(); - Kern *ks[] = { &K_axpy, &K_axpy_big, &K_res_an, &K_res_cn, &K_res_m1, &K_res_m2, &K_res_cn_m1, &K_sw, &K_sw_m1, &K_am0, &K_am1, &K_am_m1 }; + Kern *ks[] = { &K_axpy, &K_axpy_big, &K_res_an, &K_res_cn, &K_res_m1, &K_res_m2, &K_res_cn_m1, &K_sw, &K_sw_m1, &K_am0, &K_am1, &K_am_m1, + &K_cn9, &K_cn9r, &K_cn9r_m3, &K_gate, &K_gate_r, &K_gate_r_m2 }; for (unsigned i = 0; i < sizeof ks / sizeof ks[0]; i++) if (kern_upload(ks[i])) { omega_gpu_session_unlock(); return chip_fail("kernel upload"); } OmegaGpuMem bx, ba, bx0; const size_t big = (size_t)AXPY_BIG_STRIDE * AXPY_BIG_ITERS * 4u; @@ -592,6 +604,68 @@ static int chip_run(const char *out_path, uint32_t reps) { } if (omega_gpu_cmdlist_is_latched()) break; } +#undef VA + omega_gpu_session_free(&m); + } + /* the rows forms (L356 COMBINE|NORM 9 groups, L312 lever 7 GATE): ROWS_N heads as ROWS_N one-row launches and as ONE rows + * launch in the same list; x, y and the gate outputs must be bit-identical. Pass 1: the rows mutants (combine skips the + * shared slot; every row reads row 0's gate) must differ (gate: rows 1.. only). */ + if (!omega_gpu_cmdlist_is_latched()) { + const size_t NX = (size_t)ROWS_N * H, ND = NX * 9u, NW = ROWS_N * ROWS_WS / 4u, NA = (size_t)ROWS_N * ROWS_GC, NG = (size_t)ROWS_N * ROWS_GS; + OmegaGpuMem m; if (omega_gpu_session_alloc(4u * (2 * NX + ND + NW + H + 2 * NX + 2 * NA + NG), &m)) { omega_gpu_session_unlock(); return chip_fail("alloc rows"); } + float *p = m.cpu; uint64_t va = m.va; + float *xp = p, *xr = xp + NX, *d = xr + NX, *w = d + ND, *nw = w + NW, *yp = nw + H, *yr = yp + NX, *ap = yr + NX, *ar = ap + NA, *gg = ar + NA; +#define VA(ptr) (va + (uint64_t)((const uint8_t *)(ptr) - (const uint8_t *)p)) + for (int mut = 0; mut < 2 && !omega_gpu_cmdlist_is_latched(); mut++) { + uint32_t s = 700 + (uint32_t)mut; + for (size_t i = 0; i < NX; i++) { xp[i] = xr[i] = frand(&s, -2, 2); yp[i] = yr[i] = -999.0f; } + for (size_t i = 0; i < ND; i++) d[i] = frand(&s, -1, 1); + for (size_t i = 0; i < NW; i++) w[i] = (i % (ROWS_WS / 4u)) < 9u ? frand(&s, 0.05f, 0.4f) : 0.0f; + for (unsigned i = 0; i < H; i++) nw[i] = frand(&s, 0.8f, 1.2f); + for (size_t i = 0; i < NA; i++) ap[i] = ar[i] = frand(&s, -2, 2); + for (size_t i = 0; i < NG; i++) gg[i] = frand(&s, -4, 4); + omega_gpu_session_sync_to_gpu(&m); + static uint32_t wa[ROWS_N + 1][OMEGA_DEC_RES_WORDS], wg[ROWS_N + 1][OMEGA_DEC_GT_WORDS]; + OmegaGpuLaunch l[2 * ROWS_N + 2]; memset(l, 0, sizeof l); memset(wa, 0, sizeof wa); memset(wg, 0, sizeof wg); + for (unsigned r = 0; r <= ROWS_N; r++) { /* r < ROWS_N: head r alone; r == ROWS_N: the rows launch */ + const int rows = r == ROWS_N; const size_t o = rows ? 0 : r; + Kern *kc = rows ? (mut ? &K_cn9r_m3 : &K_cn9r) : &K_cn9, *kg = rows ? (mut ? &K_gate_r_m2 : &K_gate_r) : &K_gate; + put64(wa[r], OMEGA_DEC_RES_X, VA((rows ? xr : xp) + o * H)); put64(wa[r], OMEGA_DEC_RES_A, VA(d + o * 9u * H)); + put64(wa[r], OMEGA_DEC_RES_W, VA(w + o * (ROWS_WS / 4u))); put64(wa[r], OMEGA_DEC_RES_NW, VA(nw)); + put64(wa[r], OMEGA_DEC_RES_Y, VA((rows ? yr : yp) + o * H)); putf(wa[r], OMEGA_DEC_RES_EPS, EPS); putf(wa[r], OMEGA_DEC_RES_SCALE, SCALE_2P64); + float *aa = (rows ? ar : ap) + o * ROWS_GC; + put64(wg[r], OMEGA_DEC_GT_A, VA(aa)); put64(wg[r], OMEGA_DEC_GT_G, VA(gg + o * ROWS_GS + 5120u)); put64(wg[r], OMEGA_DEC_GT_OUT, VA(aa)); + wg[r][(OMEGA_DEC_GT_N - 0x380) / 4] = ROWS_GC; + OmegaGpuLaunch *lc = &l[2 * r], *lg = &l[2 * r + 1]; + lc->code_va = kc->code.va; lc->gpr_count = kc->gpr; lc->grid_x = 1; lc->grid_y = rows ? ROWS_N : 1; lc->num_elements = rows ? NX : H; lc->args = wa[r]; lc->n_args = OMEGA_DEC_RES_WORDS; + lg->code_va = kg->code.va; lg->gpr_count = kg->gpr; lg->grid_x = ROWS_GC / OMEGA_DEC_THREADS; lg->grid_y = rows ? ROWS_N : 1; lg->num_elements = rows ? NA : ROWS_GC; lg->args = wg[r]; lg->n_args = OMEGA_DEC_GT_WORDS; + } + for (unsigned i = 0; i < 2 * ROWS_N + 2; i++) { l[i].threads_x = OMEGA_DEC_THREADS; l[i].threads_y = 1; l[i].timeout_ms = 20000; } + omega_gpu_cmdlist_reset(cl); + int ok = 1; for (unsigned i = 0; i < 2 * ROWS_N + 2; i++) if (omega_gpu_cmdlist_add(cl, &l[i]) < 0) { ok = 0; chip_fail("rows add"); } + if (!ok) break; + OmegaGpuCmdListOpts o; memset(&o, 0, sizeof o); o.mode = OMEGA_GPU_CMDLIST_PCAS; o.timeout_ms = 20000; + OmegaGpuCmdListStats st; int rc = omega_gpu_cmdlist_submit(cl, &o, &st); + omega_gpu_session_sync_to_cpu(&m); + unsigned xmask = 0, ymask = 0, gmask = 0, ybad = 0; + for (unsigned r = 0; r < ROWS_N; r++) { + if (memcmp(xp + (size_t)r * H, xr + (size_t)r * H, H * 4u)) xmask |= 1u << r; + if (memcmp(yp + (size_t)r * H, yr + (size_t)r * H, H * 4u)) ymask |= 1u << r; + if (memcmp(ap + (size_t)r * ROWS_GC, ar + (size_t)r * ROWS_GC, ROWS_GC * 4u)) gmask |= 1u << r; + } + for (size_t i = 0; i < NX; i++) ybad += yp[i] == -999.0f; /* the one-row launches must have written every y */ + const unsigned all = (1u << ROWS_N) - 1u; + if (mut == 0) { + CHECK(rc == 0, "rows list rc %d (%s)", rc, rc ? omega_gpu_session_last_error() : ""); + CHECK(ybad == 0, "rows: the one-row combine+norm wrote every y (%u unwritten)", ybad); + CHECK(xmask == 0 && ymask == 0, "rows: COMBINE|NORM rows (9 groups) bit-identical to %u one-row launches (x rows differ %#x, y %#x)", ROWS_N, xmask, ymask); + CHECK(gmask == 0, "rows: GATE rows bit-identical to %u one-row launches (rows differ %#x)", ROWS_N, gmask); + } else { + CHECK(rc == 0 && (ymask == all) && gmask == (all & ~1u), "rows mutants caught: combine mutant 3 y rows differ %#x (want %#x), gate mutant 2 rows differ %#x (want %#x)", ymask, all, gmask, all & ~1u); + } + printf("rows %s: rc %d, %u launches %.1f us chip; combine+norm x differ %#x y differ %#x, gate differ %#x\n", mut ? "mutants" : "real", rc, 2 * ROWS_N + 2, st.elapsed_ns / 1e3, xmask, ymask, gmask); + if (out) fprintf(out, "\"rows_%s\":{\"rc\":%d,\"heads\":%u,\"chip_ns\":%" PRIu64 ",\"cn_x_differ\":%u,\"cn_y_differ\":%u,\"gate_differ\":%u},", mut ? "mutants" : "real", rc, ROWS_N, st.elapsed_ns, xmask, ymask, gmask); + } #undef VA omega_gpu_session_free(&m); } diff --git a/tests/q36_codegen_hash.c b/tests/q36_codegen_hash.c index 908d931a..0fa1272e 100644 --- a/tests/q36_codegen_hash.c +++ b/tests/q36_codegen_hash.c @@ -90,7 +90,8 @@ int main(void) { for (int m = 0; m <= 2; m++) for (int wi = 0; wi < 3; wi++) for (int si = 0; si < 3; si++) { - if ((k != OMEGA_DEC_RES && k != OMEGA_DEC_ARGMAX && mode) || (k != OMEGA_DEC_AXPY && k != OMEGA_DEC_GATHER && si)) continue; + const int gr = k == OMEGA_DEC_GATE && mode == 1, cr = k == OMEGA_DEC_RES && (mode & 10u) == 10u; /* rows forms with a stride (L356, L312 lever 7) */ + if ((k != OMEGA_DEC_RES && k != OMEGA_DEC_ARGMAX && !gr && mode) || (k != OMEGA_DEC_AXPY && k != OMEGA_DEC_GATHER && !gr && !cr && si)) continue; OmegaDecSpec s = {.kind = (OmegaDecKind)k, .mode = mode, .stride = strides[si], .mutant = m, .width = widths[wi]}; snprintf(n, sizeof n, "dec.k%d.mode%u.m%d.w%u.s%u", k, mode, m, widths[wi], strides[si]); omega_bw_ir_init(prog); emit(n, omega_blackwell_codegen_dec_prog(&s, prog)); diff --git a/tests/q36_dec_sim_test.c b/tests/q36_dec_sim_test.c index 51078778..166702f3 100644 --- a/tests/q36_dec_sim_test.c +++ b/tests/q36_dec_sim_test.c @@ -9,6 +9,8 @@ * unwritten) caught. * COMBINE|NORM in the rows form (L356, one launch for N heads): bit-identical to the one-head program per head (1, 3, * 8 heads); mutant 3 caught. + * GATE in the rows form (L312 lever 7, the attention gate of N heads in one launch): bit-identical to the one-row program + * per head (1, 3, 8 heads); mutants 1 (gate dropped) and 2 (row 0's gate for every row) caught. * Host only (no device). Verdict line last: "q36_dec_sim_test: N checks, F failed: PASS|FAIL". */ #include "omega_blackwell_codegen_dec.h" @@ -115,6 +117,43 @@ static long rows_point(int mutant, uint32_t heads, uint32_t seed, char *msg, siz return bad; } +/* L312 lever 7: GATE in the rows form (one launch for N heads) against the one-row program run on each head's slice: out must + * be bit-identical per row; a and out move by width (= count) floats per row, g by the attention mix row (9216 floats). Returns the + * number of differing floats, or -1 on a simulator error. */ +static long gate_rows_point(int mutant, uint32_t heads, uint32_t seed, char *msg, size_t n) { + static BlackwellIRProgram p1, pr; + const uint32_t C = 4096u, GS = 9216u; /* MIXER_OUT, ATT_MIX */ + OmegaDecSpec s1 = { .kind = OMEGA_DEC_GATE }; + OmegaDecSpec sr = { .kind = OMEGA_DEC_GATE, .mode = 1, .width = C, .stride = GS, .mutant = mutant }; /* L369's rows layout */ + if (omega_blackwell_codegen_dec_prog(&s1, &p1) != 0 || omega_blackwell_codegen_dec_prog(&sr, &pr) != 0) { snprintf(msg, n, "codegen refused"); return -1; } + const size_t NA = (size_t)heads * C, NG = (size_t)heads * GS; + float *a = aligned_alloc(16, NA * 4), *o1 = aligned_alloc(16, NA * 4), *orr = aligned_alloc(16, NA * 4), *gg = aligned_alloc(16, NG * 4); + uint32_t s = seed; + for (size_t i = 0; i < NA; i++) { a[i] = frand(&s, -2.0f, 2.0f); o1[i] = orr[i] = -999.0f; } + for (size_t i = 0; i < NG; i++) gg[i] = frand(&s, -4.0f, 4.0f); + static uint8_t smem[OMEGA_DEC_SHARED_BYTES]; + long bad = 0; + for (uint32_t h = 0; h <= heads && bad >= 0; h++) { /* h < heads: the one-row program on head h; h == heads: the rows program */ + WsSim sim; memset(&sim, 0, sizeof sim); + const int rows = h == heads; + sim.p = rows ? &pr : &p1; sim.threads = 256; sim.smem = smem; sim.smem_bytes = OMEGA_DEC_SHARED_BYTES; + float *aa = rows ? a : a + (size_t)h * C, *oo = rows ? orr : o1 + (size_t)h * C, *g0 = rows ? gg : gg + (size_t)h * GS; + put64(&sim, OMEGA_DEC_GT_A, aa); put64(&sim, OMEGA_DEC_GT_G, g0 + 5120u); put64(&sim, OMEGA_DEC_GT_OUT, oo); + sim.cbank[OMEGA_DEC_GT_N / 4] = C; + sim.nranges = 3; + sim.ranges[0] = (WsRange){ (uintptr_t)aa, (uintptr_t)aa + (rows ? NA : C) * 4 }; + sim.ranges[1] = (WsRange){ (uintptr_t)gg, (uintptr_t)gg + NG * 4 }; + sim.ranges[2] = (WsRange){ (uintptr_t)oo, (uintptr_t)oo + (rows ? NA : C) * 4 }; + if (ws_run(&sim, C / 256u, rows ? heads : 1) != 0) { snprintf(msg, n, "sim (%s): %.150s (pc %d)", rows ? "rows" : "one row", sim.msg, sim.err_pc); bad = -1; } + } + if (bad == 0) { + for (size_t i = 0; i < NA; i++) bad += memcmp(&o1[i], &orr[i], 4) != 0; + snprintf(msg, n, "%u heads: %ld of %zu gate outputs differ from the one-row program", heads, bad, NA); + } + free(a); free(o1); free(orr); free(gg); + return bad; +} + static double swiglu_point(int mutant, uint32_t seed, char *msg, size_t n) { static BlackwellIRProgram prog; OmegaDecSpec sp = { .kind = OMEGA_DEC_SWIGLU, .mutant = mutant, .width = I }; @@ -250,6 +289,14 @@ int main(void) { printf("COMBINE|NORM rows (L356): %s\n", msg); } { long b = rows_point(3, 8, 49, msg, sizeof msg); CHECK(b > 0, "COMBINE rows mutant 3 must be caught: %s", msg); printf("COMBINE rows mutant 3: %s (%s)\n", b > 0 ? "caught" : "NOT CAUGHT", msg); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_GATE, .mode = 1 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "GATE rows without a g stride refused"); } + { OmegaDecSpec sp = { .kind = OMEGA_DEC_GATE, .mode = 2, .stride = 9216 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "GATE mode 2 refused"); } + for (uint32_t hh = 1; hh <= 8; hh += hh < 3 ? 2 : 5) { + long b = gate_rows_point(0, hh, 60 + hh, msg, sizeof msg); + CHECK(b == 0, "GATE rows: %s", msg); + printf("GATE rows (L312 lever 7): %s\n", msg); + } + for (int m = 1; m <= 2; m++) { long b = gate_rows_point(m, 3, 70 + m, msg, sizeof msg); CHECK(b > 0, "GATE rows mutant %d must be caught: %s", m, msg); printf("GATE rows mutant %d: %s (%s)\n", m, b > 0 ? "caught" : "NOT CAUGHT", msg); } printf("q36_dec_sim_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS"); return g_failed ? 1 : 0; } From fedc1e38238793a81a193bcbc38ada2aec0dfd53 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 31 Oct 2026 09:19:38 -0500 Subject: [PATCH 8/8] q36 lm_head group plan as a pure function (omega_gpu_q36_head_group) with a host test over N 1..8 x G {4,8} (DRA-67, #215) record_final_heads' XBATCH grouping had no host coverage: xb = G instead of min(N - h0, G) survived test-q36-dec-sim and test-q36-codegen-hash (Main's mutant). Extracted unchanged; the test asserts every group is 1..G rows, groups cover heads 0..N-1 exactly once and no row passes N-1. Mutant (return g): 13 FAIL lines, rc 2; restored: 50 checks, 0 failed. Codegen hash 685 lines, base 509 (54cf5c03d685f1ec), 0 base lines changed. --- Makefile | 2 +- src/omega_gpu_q36_graph.c | 6 +++++- src/omega_gpu_q36_graph.h | 4 ++++ tests/q36_dec_sim_test.c | 13 +++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2c7314c3..9d382d9a 100644 --- a/Makefile +++ b/Makefile @@ -349,7 +349,7 @@ test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) # 4bbccf08 (tests/fixtures/q36_codegen_hash/main-4bbccf08.txt) to appear verbatim: levers may add programs, never change one. .PHONY: test-q36-dec-sim test-q36-codegen-hash Q36_DEC_SIM_TEST = $(OUT_DIR)/q36_dec_sim_test -$(Q36_DEC_SIM_TEST): tests/q36_dec_sim_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h $(OUT_DIR)/libomega_gpu.a +$(Q36_DEC_SIM_TEST): tests/q36_dec_sim_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h src/omega_gpu_q36_graph.h $(OUT_DIR)/libomega_gpu.a $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/q36_dec_sim_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm test-q36-dec-sim: $(Q36_DEC_SIM_TEST) $(Q36_DEC_SIM_TEST) diff --git a/src/omega_gpu_q36_graph.c b/src/omega_gpu_q36_graph.c index 45782061..3d5b4484 100644 --- a/src/omega_gpu_q36_graph.c +++ b/src/omega_gpu_q36_graph.c @@ -889,6 +889,10 @@ int omega_gpu_q36_graph_record_head_final(OmegaGpuQ36Graph *g, uint32_t h) { return rc == OMEGA_GPU_DGRAPH_OK ? rc : fail(g, NULL, rc); } +uint32_t omega_gpu_q36_head_group(uint32_t n, uint32_t g, uint32_t h0) { + if (g == 0 || h0 >= n) return 0; + return n - h0 < g ? n - h0 : g; +} /* The batch's final head (v2 lever 1, L312): every head's hidden is ready after the last layer (record_layer_heads), so * the bf16 lm_head runs once per group of up to q36_head_xbatch() heads (4; 8 with lever 6) (the XBATCH form: x rows hidden_of(h0..), * y rows logits_of(h0..), ystride the logits slot; each row bit-identical to its own one-head launch), then the argmax @@ -901,7 +905,7 @@ static int record_final_heads(OmegaGpuQ36Graph *g) { int rc = OMEGA_GPU_DGRAPH_OK; const uint32_t G = q36_head_xbatch(); for (uint32_t h0 = 0; h0 < N && rc == OMEGA_GPU_DGRAPH_OK; h0 += G) { - const uint32_t xb = N - h0 < G ? N - h0 : G; + const uint32_t xb = omega_gpu_q36_head_group(N, G, h0); rc = after_op(g, OMEGA_GPU_Q36_K_LM_HEAD, omega_gpu_bf16_gemv_xbatch_record(g->cl, g->cfg.lm_head, xb, va_of(g, hidden_of(g, h0)), va_of(g, logits_of(g, h0)), g->am_ctas * OMEGA_DEC_ARGMAX_SPAN)); } diff --git a/src/omega_gpu_q36_graph.h b/src/omega_gpu_q36_graph.h index 3059972a..bddc2af3 100644 --- a/src/omega_gpu_q36_graph.h +++ b/src/omega_gpu_q36_graph.h @@ -176,6 +176,10 @@ void omega_q36_perm_table(uint32_t *tab, uint32_t k); int omega_gpu_q36_graph_set_batch(OmegaGpuQ36Graph *g, int on); int omega_gpu_q36_graph_batch(const OmegaGpuQ36Graph *g); int omega_gpu_q36_graph_record_layer_heads(OmegaGpuQ36Graph *g, uint32_t layer, const uint32_t *pos); +/* The lm_head group plan (lever 1/6): the group starting at head h0 of n stroke heads, groups of up to g heads, reads + * omega_gpu_q36_head_group(n, g, h0) rows (0 when h0 >= n or g == 0). Walking h0 = 0, g, 2g, ... covers heads 0..n-1 + * exactly once with no row past n-1. Pure; record_final_heads uses it and q36_dec_sim_test checks it. */ +uint32_t omega_gpu_q36_head_group(uint32_t n, uint32_t g, uint32_t h0); enum { OMEGA_GPU_Q36_K_NORM = 0, OMEGA_GPU_Q36_K_MIX, OMEGA_GPU_Q36_K_AB, OMEGA_GPU_Q36_K_GDN, OMEGA_GPU_Q36_K_GATHER, OMEGA_GPU_Q36_K_ATTN, diff --git a/tests/q36_dec_sim_test.c b/tests/q36_dec_sim_test.c index 166702f3..c94fb037 100644 --- a/tests/q36_dec_sim_test.c +++ b/tests/q36_dec_sim_test.c @@ -15,6 +15,7 @@ */ #include "omega_blackwell_codegen_dec.h" #include "bw_warp_sim_k.h" +#include "omega_gpu_q36_graph.h" #include #include #include @@ -248,6 +249,18 @@ static int group_point(int mutant, uint32_t heads, int all_same, uint32_t seed, int main(void) { char msg[300]; + for (uint32_t gg = 4; gg <= 8; gg += 4) /* lever 1/6 lm_head groups: every N heads covered once, no row past N-1 */ + for (uint32_t n = 1; n <= 8; n++) { + uint32_t cov = 0, bad = 0, ng = 0; + for (uint32_t h0 = 0; h0 < n; h0 += gg) { + const uint32_t xb = omega_gpu_q36_head_group(n, gg, h0); + if (xb == 0 || xb > gg || h0 + xb > n || h0 != cov) bad++; + cov = h0 + xb; ng++; + } + CHECK(!bad && cov == n && ng == (n + gg - 1) / gg && omega_gpu_q36_head_group(n, gg, n) == 0, + "lm_head groups N %u G %u: %u groups cover %u heads, %u bad", n, gg, ng, cov, bad); + } + printf("lm_head group plan: N 1..8 x G {4,8} checked\n"); { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_ADD | OMEGA_DEC_RES_NORM, .groups = 9 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "groups 9 without COMBINE refused"); } { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE, .groups = 7 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "groups 7 refused"); } { OmegaDecSpec sp = { .kind = OMEGA_DEC_RES, .mode = OMEGA_DEC_RES_COMBINE, .mutant = 3 }; CHECK(omega_dec_prog_stats(&sp, NULL, NULL) != 0, "mutant 3 without the shared slot refused"); }