From 36637feac9c84ec2b67a340a04856aafc6af065d Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 21:07:37 -0500 Subject: [PATCH 01/10] C3: reductions (sum, max, min) and prefix sums of any length 1..2^28 on Omega's own codegen, frozen order; host and simulator tiers PASS, three mutants caught Co-Authored-By: Claude Opus 5.5 --- Makefile | 11 + evidence/C3-SCAN/01-host-only.log | 8 + evidence/C3-SCAN/02-sim.log | 10 + evidence/C3-SCAN/README.md | 14 ++ src/omega_gpu_scan.c | 320 +++++++++++++++++++++++++ src/omega_gpu_scan.h | 110 +++++++++ src/omega_gpu_scan_ref.c | 75 ++++++ tests/gpu_scan_test.c | 377 ++++++++++++++++++++++++++++++ 8 files changed, 925 insertions(+) create mode 100644 evidence/C3-SCAN/01-host-only.log create mode 100644 evidence/C3-SCAN/02-sim.log create mode 100644 evidence/C3-SCAN/README.md create mode 100644 src/omega_gpu_scan.c create mode 100644 src/omega_gpu_scan.h create mode 100644 src/omega_gpu_scan_ref.c create mode 100644 tests/gpu_scan_test.c diff --git a/Makefile b/Makefile index aa4e7428f..a80ea0062 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,8 @@ SRCS += src/omega_blackwell_codegen_router.c src/omega_gpu_router_api.c SRCS += src/omega_blackwell_codegen_gdn.c src/omega_gpu_gdn_api.c # OWN-30B W-L2 (2026-10-13): decode launch collapse, new files only: command list (N launches, one submit) + glue kernels SRCS += src/omega_gpu_cmdlist.c src/omega_blackwell_codegen_dec.c +# C3 (docs/OMEGA.md): reductions and prefix sums of any length, bit-exact against the frozen-order host reference. +SRCS += src/omega_gpu_scan.c src/omega_gpu_scan_ref.c SRCS += src/omega_gpu_mem_cached.c SRCS += src/omega_gpu_decode_graph.c # sc #642 (2026-10-18): one Qwen3.8-27B decode token as one command list (GDN + hd256 attention layers, dense MLP) @@ -2687,3 +2689,12 @@ test-gpu-q38-graph-host: $(GPU_Q38_GRAPH_TEST) GPU_EXACT_HEAD_TEST = $(OUT_DIR)/gpu_exact_head_test $(GPU_EXACT_HEAD_TEST): tests/gpu_exact_head_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h src/omega_gpu_bf16_gemv_api.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_exact_head_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +# C3 (docs/OMEGA.md): sum, max, min and prefix sum of any length 1..2^28, bit-exact against the frozen order. +# test-gpu-scan: host refusals, codegen, references vs exact sums and vs the E1 reference, then the warp simulator +# (both orders, mutants caught). The chip tier is "$(GPU_SCAN_TEST)" with no flag, under the GB10 lock. +GPU_SCAN_TEST = $(OUT_DIR)/gpu_scan_test +$(GPU_SCAN_TEST): tests/gpu_scan_test.c tests/bw_warp_sim.h src/omega_gpu_scan.h src/omega_numeric_reduce.c src/omega_numeric.c $(OUT_DIR)/libomega_gpu.a + $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_scan_test.c src/omega_numeric_reduce.c src/omega_numeric.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +.PHONY: test-gpu-scan +test-gpu-scan: $(GPU_SCAN_TEST) + ./$(GPU_SCAN_TEST) --sim diff --git a/evidence/C3-SCAN/01-host-only.log b/evidence/C3-SCAN/01-host-only.log new file mode 100644 index 000000000..8f46aaf04 --- /dev/null +++ b/evidence/C3-SCAN/01-host-only.log @@ -0,0 +1,8 @@ +$ ./build/gpu_scan_test --host-only (omega c3/reduce-scan, 2026-10-22T02:07Z) +kernel 0: 45 insns, 768 bytes, 18 gprs +kernel 1: 45 insns, 768 bytes, 18 gprs +kernel 2: 45 insns, 768 bytes, 18 gprs +kernel 3: 79 insns, 1280 bytes, 26 gprs +kernel 4: 33 insns, 640 bytes, 18 gprs +C3 scan host: PASS (133 checks) +exit=0 diff --git a/evidence/C3-SCAN/02-sim.log b/evidence/C3-SCAN/02-sim.log new file mode 100644 index 000000000..25921f3cf --- /dev/null +++ b/evidence/C3-SCAN/02-sim.log @@ -0,0 +1,10 @@ +$ ./build/gpu_scan_test --sim (omega c3/reduce-scan, 2026-10-22T02:07Z) +kernel 0: 45 insns, 768 bytes, 18 gprs +kernel 1: 45 insns, 768 bytes, 18 gprs +kernel 2: 45 insns, 768 bytes, 18 gprs +kernel 3: 79 insns, 1280 bytes, 26 gprs +kernel 4: 33 insns, 640 bytes, 18 gprs +simulator order 0: 340 runs, reductions wrong 0, prefix sums wrong 0 +simulator order 1: 336 runs, reductions wrong 0, prefix sums wrong 0 +C3 scan sim: PASS (139 checks) +exit=0 diff --git a/evidence/C3-SCAN/README.md b/evidence/C3-SCAN/README.md new file mode 100644 index 000000000..b932ba866 --- /dev/null +++ b/evidence/C3-SCAN/README.md @@ -0,0 +1,14 @@ +# C3 receipt, part 1: sums, maximum, minimum and running totals of any length + +Row C3 of `docs/OMEGA.md` asks for reductions and prefix sums (running totals) over every length from 1 to 2^28, +bit-exact against a host reference whose order of additions is frozen. The kernels come from Omega's own code +generator (`src/omega_gpu_scan.c`), with no CUDA. The order is written down in `src/omega_gpu_scan.h`; the reduction +order is the E1 contract (`docs/numeric/E1_REDUCTION_CONTRACT.md`). + +| Log | What it checks | Result | +|---|---|---| +| 01-host-only | bad calls refused; all five kernels (and each planted fault) go through our code generator and encoder; the host reference gives exact answers on integer inputs and equals the E1 reduction reference bit for bit on mixed, signed-zero, NaN and infinite inputs; the frozen tree differs from a left-to-right sum | PASS, 133 checks | +| 02-sim | the real kernels in the warp simulator, both scheduling orders, every length 1 to 70 and the tile, block and grid-stride edges up to 270,000; three planted faults (a skipped tree step, a skipped scan step, a carry from the wrong tile) each caught | PASS, 139 checks | +| (next) chip | every n from 1 to 2048, 2^k - 1, 2^k, 2^k + 1 up to 2^28, 64 random lengths, the three faults caught on the GB10 | waiting for a chip window | + +Command: `make test-gpu-scan` (host and simulator). The chip run is `build/gpu_scan_test` with no flag, under the GB10 lock. diff --git a/src/omega_gpu_scan.c b/src/omega_gpu_scan.c new file mode 100644 index 000000000..3f999eb35 --- /dev/null +++ b/src/omega_gpu_scan.c @@ -0,0 +1,320 @@ +/* omega_gpu_scan.c -- see omega_gpu_scan.h. Kernels from Omega's IR (emitter helpers of omega_bw_em.h, the + * chip-proven scheduling rules of the tensor-core generators), host references, the level driver, the chip calls. */ +#include "omega_gpu_scan.h" +#include "omega_bw_em.h" +#include "omega_gpu_session.h" + +#include +#include + +#define PAD_SUM 0x80000000u /* -0.0: x + -0.0 == x for every x */ +#define PAD_MINMAX 0x7fc00000u /* quiet NaN: max(NaN, x) == min(NaN, x) == x */ +#define POISON 0x7fa00badu /* a signalling NaN: no FADD or FMNMX writes it, so a word still holding it was never written */ +#define TIMEOUT_MS 20000ull + +/* ------------------------------------------------------------------ IR */ + +static void fmnmx(Em *e, BlackwellIROpcode op, int d, int a, int b) { + BlackwellIRInsn i = I0(op); i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; emit(e, i, K_FIXED); +} +typedef struct { int bssy, bra; } Region; +/* the lanes with P0 set skip to the region's end; the warp joins again there */ +static Region skip_if_p0(Em *e) { Region r; r.bssy = bssy_fwd(e); r.bra = bra_if_p0_fwd(e); return r; } +static void region_end(Em *e, Region r) { int at = here(e); bsync(e); patch_bra(e, r.bra, at); patch_bra(e, r.bssy, at + 1); } + +static int gen(Em *e, const OmegaScanSpec *sp) { + const OmegaScanKind k = sp->kind; + const int red = k <= OMEGA_SCAN_K_RED_MIN; + int udesc = UV64(e), pin = V64(e), pout = V64(e), ptot = V64(e), len = V(e), tiles = V(e), warps = V(e); + int tid = V(e), cta = V(e), lane = V(e), gw = V(e), one = V(e), tile = V(e), el = V(e), v = V(e), t = V(e); + int a64 = V64(e), b64 = V64(e), rl = V(e), nz = V(e), c31 = V(e), m1 = V(e), off = V(e), tm1 = V(e); + int mask[5]; + for (unsigned s = 0; s < 5; s++) mask[s] = k == OMEGA_SCAN_K_TILE ? V(e) : NOREG; + if (e->err) return -1; + ldcu64(e, udesc, 0x358); + ldc64(e, pin, OMEGA_GPU_SCAN_A_IN); ldc64(e, pout, OMEGA_GPU_SCAN_A_OUT); + if (k == OMEGA_SCAN_K_TILE) ldc64(e, ptot, OMEGA_GPU_SCAN_A_TOT); + ldc32(e, len, OMEGA_GPU_SCAN_A_LEN); ldc32(e, tiles, OMEGA_GPU_SCAN_A_TILES); ldc32(e, warps, OMEGA_GPU_SCAN_A_WARPS); + s2r(e, tid, BW_SR_TID_X); s2r(e, cta, BW_SR_CTAID_X); + movi(e, one, 1); movi(e, m1, 0xffffffffu); movi(e, nz, PAD_SUM); + andi(e, lane, tid, 0, 31u); + shr(e, t, tid, 0, 5); + imadi(e, gw, cta, 0, OMEGA_GPU_SCAN_THREADS / 32u, t); /* global warp = cta * 8 + warp */ + if (k == OMEGA_SCAN_K_ADD) imadi(e, tile, gw, 0, 1u, one); /* the carry starts at tile 1 */ + else imadi(e, tile, gw, 0, 1u, NOREG); + if (k == OMEGA_SCAN_K_TILE) { + /* reversed lanes: lane L holds tile position 31 - L, so SHFL.DOWN by d reads position - d */ + movi(e, c31, 31u); + lop3(e, rl, lane, c31, NOREG, 0x3cu); /* 31 - L == L ^ 31 for L < 32 */ + /* mask[s] = all ones when position - d exists (L + d <= 31), else 0: ((L + d) >> 5) - 1 */ + for (unsigned s = 0; s < 5; s++) { + movi(e, t, 1u << s); + iadd(e, mask[s], lane, t); + shr(e, mask[s], mask[s], 0, 5); + imadi(e, mask[s], mask[s], 0, 1u, m1); + } + } + + const int top = here(e); + loop_begin(e); + isetp_ge_u32(e, tile, tiles); + const int done = bra_if_p0_fwd(e); + if (red) { + const BlackwellIROpcode op = k == OMEGA_SCAN_K_RED_MAX ? BW_IR_FMNMX_MAX : BW_IR_FMNMX_MIN; + imadi(e, el, tile, 0, 32u, lane); + movi(e, v, k == OMEGA_SCAN_K_RED_SUM ? PAD_SUM : PAD_MINMAX); + isetp_ge_u32(e, el, len); + { Region r = skip_if_p0(e); imadw(e, a64, el, 4u, pin); ldg32(e, v, a64, udesc, 1); region_end(e, r); } + for (uint32_t d = 16; d >= 1; d /= 2) { + if (sp->mutant == 1 && d == 1) break; + shfl_down(e, t, v, d); + if (k == OMEGA_SCAN_K_RED_SUM) fadd(e, v, v, t); else fmnmx(e, op, v, v, t); + } + isetp_ge_u32(e, lane, one); + { Region r = skip_if_p0(e); imadw(e, a64, tile, 4u, pout); stg(e, a64, 0, v, udesc); region_end(e, r); } + } else if (k == OMEGA_SCAN_K_TILE) { + imadi(e, el, tile, 0, 32u, rl); + movi(e, v, PAD_SUM); + isetp_ge_u32(e, el, len); + { Region r = skip_if_p0(e); imadw(e, a64, el, 4u, pin); ldg32(e, v, a64, udesc, 1); region_end(e, r); } + for (unsigned s = 0; s < 5; s++) { + if (sp->mutant == 2 && s == 4) break; + shfl_down(e, t, v, 1u << s); + lop3(e, t, t, mask[s], nz, 0xe2u); /* (t & mask) | (-0.0 & ~mask) */ + fadd(e, v, t, v); /* lower position on the left */ + } + isetp_ge_u32(e, el, len); + { Region r = skip_if_p0(e); imadw(e, a64, el, 4u, pout); stg(e, a64, 0, v, udesc); region_end(e, r); } + isetp_ge_u32(e, lane, one); /* lane 0 holds position 31: the tile total */ + { Region r = skip_if_p0(e); imadw(e, a64, tile, 4u, ptot); stg(e, a64, 0, v, udesc); region_end(e, r); } + } else { + imadi(e, el, tile, 0, 32u, lane); + isetp_ge_u32(e, el, len); + { + Region r = skip_if_p0(e); + if (sp->mutant == 3) imadi(e, tm1, tile, 0, 1u, NOREG); else imadi(e, tm1, tile, 0, 1u, m1); + imadw(e, b64, tm1, 4u, pout); imadw(e, a64, el, 4u, pin); + ldg32(e, off, b64, udesc, 1); ldg32(e, v, a64, udesc, 0); + fadd(e, v, off, v); + stg(e, a64, 0, v, udesc); + region_end(e, r); + } + } + iadd(e, tile, tile, warps); + bra(e, top); + loop_end(e); + patch_bra(e, done, here(e)); + tail(e); + return e->err; +} + +int omega_gpu_scan_codegen(const OmegaScanSpec *spec, BlackwellIRProgram *prog) { + if (!spec || !prog || (unsigned)spec->kind >= OMEGA_SCAN_K_COUNT) return -1; + omega_bw_ir_init(prog); + Em em; memset(&em, 0, sizeof em); em.p = prog; + if (gen(&em, spec) != 0 || em.err || em.depth != 0) return -1; + return omega_bw_regalloc_solve(prog); +} + +/* ------------------------------------------------------------------ the level driver */ + +uint32_t omega_gpu_scan_grid(size_t len) { + size_t tiles = (len + 31) / 32, ctas = (tiles + OMEGA_GPU_SCAN_THREADS / 32u - 1) / (OMEGA_GPU_SCAN_THREADS / 32u); + return ctas > OMEGA_GPU_SCAN_MAX_CTAS ? OMEGA_GPU_SCAN_MAX_CTAS : (uint32_t)(ctas ? ctas : 1); +} + +static void args_for(uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS], uint64_t in, uint64_t out, uint64_t tot, size_t len) { + memset(a, 0, OMEGA_GPU_SCAN_ARGS_WORDS * 4u); + a[0] = (uint32_t)in; a[1] = (uint32_t)(in >> 32); a[2] = (uint32_t)out; a[3] = (uint32_t)(out >> 32); + a[4] = (uint32_t)tot; a[5] = (uint32_t)(tot >> 32); + a[6] = (uint32_t)len; a[7] = (uint32_t)((len + 31) / 32); a[8] = omega_gpu_scan_grid(len) * (OMEGA_GPU_SCAN_THREADS / 32u); +} + +size_t omega_gpu_scan_reduce_scratch_words(size_t n) { + size_t w = 0; + do { n = (n + 31) / 32; w += n; } while (n > 1); + return w; +} + +size_t omega_gpu_scan_prefix_scratch_words(size_t n) { + size_t w = 0; + while (n > 32) { n = (n + 31) / 32; w += n; } + return w + 1; /* the last level's single total */ +} + +int omega_gpu_scan_drive_reduce(OmegaGpuRedOp op, size_t n, uint64_t in_va, uint64_t scratch_va, uint64_t *out_va, + OmegaScanLaunchFn launch, void *ctx, uint32_t *launches) { + if ((unsigned)op > OMEGA_GPU_RED_MIN || n == 0 || !launch || !out_va) return OMEGA_GPU_SCAN_BAD_ARGS; + if (n > OMEGA_GPU_SCAN_MAX_N) return OMEGA_GPU_SCAN_TOO_LARGE; + const OmegaScanKind k = (OmegaScanKind)(OMEGA_SCAN_K_RED_SUM + (int)op); + uint64_t in = in_va, out = scratch_va; + size_t len = n; + uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS]; + do { + args_for(a, in, out, 0, len); + if (launch(ctx, k, a, omega_gpu_scan_grid(len)) != 0) return OMEGA_GPU_SCAN_CHIP_FAIL; + if (launches) (*launches)++; + len = (len + 31) / 32; + in = out; out += len * 4u; + } while (len > 1); + *out_va = in; + return OMEGA_GPU_SCAN_OK; +} + +int omega_gpu_scan_drive_prefix(size_t n, uint64_t in_va, uint64_t out_va, uint64_t scratch_va, + OmegaScanLaunchFn launch, void *ctx, uint32_t *launches) { + if (n == 0 || !launch) return OMEGA_GPU_SCAN_BAD_ARGS; + if (n > OMEGA_GPU_SCAN_MAX_N) return OMEGA_GPU_SCAN_TOO_LARGE; + enum { MAXL = 8 }; /* 32^6 >= 2^28 */ + uint64_t buf[MAXL], tot[MAXL]; + size_t len[MAXL]; + unsigned L = 0; + uint64_t in = in_va, sp = scratch_va; + buf[0] = out_va; len[0] = n; + uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS]; + for (;;) { /* forward: scan every level, its totals become the next level (scanned in place) */ + size_t nt = (len[L] + 31) / 32; + tot[L] = sp; sp += nt * 4u; + args_for(a, in, buf[L], tot[L], len[L]); + if (launch(ctx, OMEGA_SCAN_K_TILE, a, omega_gpu_scan_grid(len[L])) != 0) return OMEGA_GPU_SCAN_CHIP_FAIL; + if (launches) (*launches)++; + if (nt == 1) break; + if (L + 1 >= MAXL) return OMEGA_GPU_SCAN_TOO_LARGE; + buf[L + 1] = tot[L]; len[L + 1] = nt; in = tot[L]; + L++; + } + while (L-- > 0) { /* back down: carry the scanned totals of level L + 1 into level L */ + args_for(a, buf[L], buf[L + 1], 0, len[L]); + if (launch(ctx, OMEGA_SCAN_K_ADD, a, omega_gpu_scan_grid(len[L])) != 0) return OMEGA_GPU_SCAN_CHIP_FAIL; + if (launches) (*launches)++; + } + return OMEGA_GPU_SCAN_OK; +} + +/* ------------------------------------------------------------------ the chip */ + +static struct { + int mutant; + OmegaGpuMem code[OMEGA_SCAN_K_COUNT]; + uint32_t gpr[OMEGA_SCAN_K_COUNT]; +} g; + +void omega_gpu_scan_test_set_mutant(int mutant) { + omega_gpu_session_lock(); + for (unsigned k = 0; k < OMEGA_SCAN_K_COUNT; k++) if (g.code[k].cpu) omega_gpu_session_free(&g.code[k]); + memset(g.code, 0, sizeof g.code); + g.mutant = mutant; + omega_gpu_session_unlock(); +} + +const char *omega_gpu_scan_rc_name(int rc) { + switch (rc) { + case OMEGA_GPU_SCAN_OK: return "OK"; + case OMEGA_GPU_SCAN_BAD_ARGS: return "BAD_ARGS"; + case OMEGA_GPU_SCAN_TOO_LARGE: return "TOO_LARGE"; + case OMEGA_GPU_SCAN_CODEGEN_FAIL: return "CODEGEN_FAIL"; + case OMEGA_GPU_SCAN_CHIP_FAIL: return "CHIP_FAIL"; + default: return "?"; + } +} + +/* lock held */ +static int kernel_locked(OmegaScanKind k) { + if (g.code[k].cpu) return OMEGA_GPU_SCAN_OK; + BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); + if (!prog) return OMEGA_GPU_SCAN_CODEGEN_FAIL; + OmegaScanSpec s = { k, g.mutant }; + int rc = OMEGA_GPU_SCAN_OK; + size_t need = 0; + if (omega_gpu_scan_codegen(&s, prog) != 0 || (need = omega_bw_program_code_bytes(prog)) == 0) rc = OMEGA_GPU_SCAN_CODEGEN_FAIL; + else if (omega_gpu_session_alloc_code(need, &g.code[k]) != 0) rc = OMEGA_GPU_SCAN_CHIP_FAIL; + else { + OmegaBlackwellKernel kk; + if (omega_blackwell_kernel_encode_into(prog, g.code[k].cpu, need, &kk) != 0 || kk.code_size != need) rc = OMEGA_GPU_SCAN_CODEGEN_FAIL; + else if (omega_gpu_session_sync_to_gpu(&g.code[k]) != 0) rc = OMEGA_GPU_SCAN_CHIP_FAIL; + else { g.gpr[k] = omega_bw_gpr_declared(kk.gpr_count); if (g.gpr[k] < 64u) g.gpr[k] = 64u; } + if (rc != OMEGA_GPU_SCAN_OK) { omega_gpu_session_free(&g.code[k]); memset(&g.code[k], 0, sizeof g.code[k]); } + } + omega_gpu_host_free(prog); + return rc; +} + +typedef struct { uint64_t elapsed_ns; } ChipCtx; + +/* lock held */ +static int chip_launch(void *ctx, OmegaScanKind k, const uint32_t args[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t grid_x) { + if (kernel_locked(k) != OMEGA_GPU_SCAN_OK) return -1; + OmegaGpuLaunch L = { + .code_va = g.code[k].va, .gpr_count = g.gpr[k], .threads_x = OMEGA_GPU_SCAN_THREADS, .threads_y = 1, + .grid_x = grid_x, .grid_y = 1, .num_elements = (size_t)grid_x * OMEGA_GPU_SCAN_THREADS, + .args = args, .n_args = OMEGA_GPU_SCAN_ARGS_WORDS, .timeout_ms = TIMEOUT_MS, + }; + uint64_t ns = 0; + if (omega_gpu_session_launch(&L, &ns, NULL) != 0) return -1; + ((ChipCtx *)ctx)->elapsed_ns += ns; + return 0; +} + +/* lock held: one data buffer [in n | out n | scratch], the input copied in, outputs poisoned */ +static int stage_locked(const float *x, size_t n, size_t out_words, size_t scratch_words, OmegaGpuMem *m) { + if (!omega_gpu_session_open()) return OMEGA_GPU_SCAN_CHIP_FAIL; + if (omega_gpu_session_alloc((n + out_words + scratch_words) * 4u, m) != 0) return OMEGA_GPU_SCAN_CHIP_FAIL; + uint32_t *w = m->cpu; + memcpy(w, x, n * 4u); + for (size_t i = n; i < n + out_words + scratch_words; i++) w[i] = POISON; + if (omega_gpu_session_sync_to_gpu(m) != 0) { omega_gpu_session_free(m); return OMEGA_GPU_SCAN_CHIP_FAIL; } + return OMEGA_GPU_SCAN_OK; +} + +int omega_gpu_reduce(OmegaGpuRedOp op, const float *x, size_t n, float *out, OmegaGpuScanInfo *info) { + uint64_t t0 = omega_gpu_session_now_ns(); + if (info) memset(info, 0, sizeof *info); + if ((unsigned)op > OMEGA_GPU_RED_MIN || !x || !out || n == 0) return OMEGA_GPU_SCAN_BAD_ARGS; + if (n > OMEGA_GPU_SCAN_MAX_N) return OMEGA_GPU_SCAN_TOO_LARGE; + omega_gpu_session_lock(); + OmegaGpuMem m; + const size_t sw = omega_gpu_scan_reduce_scratch_words(n); + int rc = stage_locked(x, n, 0, sw, &m); + if (rc == OMEGA_GPU_SCAN_OK) { + ChipCtx c = { 0 }; uint64_t res = 0; uint32_t nl = 0; + rc = omega_gpu_scan_drive_reduce(op, n, m.va, m.va + n * 4u, &res, chip_launch, &c, &nl); + if (rc == OMEGA_GPU_SCAN_OK && omega_gpu_session_sync_to_cpu(&m) != 0) rc = OMEGA_GPU_SCAN_CHIP_FAIL; + if (rc == OMEGA_GPU_SCAN_OK) { + uint32_t r; memcpy(&r, (const uint8_t *)m.cpu + (res - m.va), 4); + if (r == POISON) { omega_gpu_session_set_error("reduce: the result word was never written"); rc = OMEGA_GPU_SCAN_CHIP_FAIL; } + else memcpy(out, &r, 4); + } + if (info) { info->launches = nl; info->elapsed_ns = c.elapsed_ns; } + omega_gpu_session_free(&m); + } + omega_gpu_session_unlock(); + if (info) info->call_ns = omega_gpu_session_now_ns() - t0; + return rc; +} + +int omega_gpu_prefix_sum(const float *x, size_t n, float *y, OmegaGpuScanInfo *info) { + uint64_t t0 = omega_gpu_session_now_ns(); + if (info) memset(info, 0, sizeof *info); + if (!x || !y || n == 0) return OMEGA_GPU_SCAN_BAD_ARGS; + if (n > OMEGA_GPU_SCAN_MAX_N) return OMEGA_GPU_SCAN_TOO_LARGE; + omega_gpu_session_lock(); + OmegaGpuMem m; + int rc = stage_locked(x, n, n, omega_gpu_scan_prefix_scratch_words(n), &m); + if (rc == OMEGA_GPU_SCAN_OK) { + ChipCtx c = { 0 }; uint32_t nl = 0; + rc = omega_gpu_scan_drive_prefix(n, m.va, m.va + n * 4u, m.va + 2 * n * 4u, chip_launch, &c, &nl); + if (rc == OMEGA_GPU_SCAN_OK && omega_gpu_session_sync_to_cpu(&m) != 0) rc = OMEGA_GPU_SCAN_CHIP_FAIL; + if (rc == OMEGA_GPU_SCAN_OK) { + const uint32_t *w = (const uint32_t *)m.cpu + n; + size_t unwritten = 0; + for (size_t i = 0; i < n; i++) unwritten += w[i] == POISON; + if (unwritten) { omega_gpu_session_set_error("prefix sum: output words never written"); rc = OMEGA_GPU_SCAN_CHIP_FAIL; } + else memcpy(y, w, n * 4u); + } + if (info) { info->launches = nl; info->elapsed_ns = c.elapsed_ns; } + omega_gpu_session_free(&m); + } + omega_gpu_session_unlock(); + if (info) info->call_ns = omega_gpu_session_now_ns() - t0; + return rc; +} diff --git a/src/omega_gpu_scan.h b/src/omega_gpu_scan.h new file mode 100644 index 000000000..3c775cf6a --- /dev/null +++ b/src/omega_gpu_scan.h @@ -0,0 +1,110 @@ +/* omega_gpu_scan.h -- reductions and prefix sums of any length on the GB10 (row C3 of docs/OMEGA.md). + * + * The sum, the maximum and the minimum of n float values, and the inclusive prefix sum (the running total + * y[i] = x[0] + ... + x[i]), for every n from 1 to 2^28. The order of the additions is frozen: it depends only on n + * and the element index, never on the grid, the scheduling or the chip, so the chip result equals the host + * reference below bit for bit. + * + * Reductions (the order of docs/numeric/E1_REDUCTION_CONTRACT.md, omega_numeric_reduce.h): one level turns len values + * into ceil(len / 32) values; value j is the 32-lane tree over values [32j, 32j + 32) with lane i combining lane i + d + * for d = 16, 8, 4, 2, 1 (lower lane on the left), positions past len filled with the identity (-0.0 for the sum, a + * quiet NaN for the maximum and minimum, which those operations ignore). Levels repeat until one value is left; at + * least one level runs. + * + * Prefix sum, same tile structure: + * level scan inside each tile of 32 (positions past len filled with -0.0), for d = 1, 2, 4, 8, 16 in that order, + * every position i >= d takes v[i - d] + v[i] (both from before the step); the tile total T[j] is the + * value at position 31. + * carry when there is more than one tile, the totals T are prefix-summed by the same definition (recursively) + * into S, and every element of tile j >= 1 becomes S[j - 1] + (its tile value). + * Inputs are any float values. Results with no NaN are bit-exact; a NaN result is a NaN (the chip writes one canonical + * NaN, the host may keep another payload). + * + * On the chip each level is one launch of a kernel from Omega's own codegen (no CUDA): the reduction tree and the + * tile scan are warp shuffles (SHFL.DOWN; the scan holds each tile in reversed lane order so a shuffle down reads the + * lower element), the carry is a separate pass. omega_gpu_scan_drive_* run the levels through a launch callback, so + * the same driver runs on the chip (omega_gpu_reduce, omega_gpu_prefix_sum) and in the warp simulator + * (tests/gpu_scan_test.c). */ +#ifndef OMEGA_GPU_SCAN_H +#define OMEGA_GPU_SCAN_H + +#include +#include +#include "omega_blackwell_codegen.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OMEGA_GPU_SCAN_MAX_N ((size_t)1 << 28) +#define OMEGA_GPU_SCAN_THREADS 256u /* 8 warps per CTA; each warp walks tiles gw, gw + warps, ... */ +#define OMEGA_GPU_SCAN_MAX_CTAS 1024u + +enum { + OMEGA_GPU_SCAN_OK = 0, + OMEGA_GPU_SCAN_BAD_ARGS = -1, /* NULL pointer, n == 0, unknown op */ + OMEGA_GPU_SCAN_TOO_LARGE = -2, /* n > OMEGA_GPU_SCAN_MAX_N */ + OMEGA_GPU_SCAN_CODEGEN_FAIL = -3, /* our codegen refused a kernel */ + OMEGA_GPU_SCAN_CHIP_FAIL = -4 /* device, allocation, launch, or an output word the chip never wrote */ +}; + +typedef enum { OMEGA_GPU_RED_SUM = 0, OMEGA_GPU_RED_MAX = 1, OMEGA_GPU_RED_MIN = 2 } OmegaGpuRedOp; + +/* The kernels. Argument words at constant bank 0x380 (OMEGA_GPU_SCAN_A_*). */ +typedef enum { + OMEGA_SCAN_K_RED_SUM = 0, OMEGA_SCAN_K_RED_MAX, OMEGA_SCAN_K_RED_MIN, /* one reduction level: in -> out[tile] */ + OMEGA_SCAN_K_TILE, /* one scan level: in -> out (may alias), tot[tile] */ + OMEGA_SCAN_K_ADD, /* carry: out[e] = S[tile - 1] + out[e], tiles >= 1 */ + OMEGA_SCAN_K_COUNT +} OmegaScanKind; +#define OMEGA_GPU_SCAN_A_IN 0x380u /* u64: level input (K_ADD: the level being carried into) */ +#define OMEGA_GPU_SCAN_A_OUT 0x388u /* u64: level output (K_ADD: S, the scanned totals) */ +#define OMEGA_GPU_SCAN_A_TOT 0x390u /* u64: tile totals (K_TILE only) */ +#define OMEGA_GPU_SCAN_A_LEN 0x398u /* u32: values in this level */ +#define OMEGA_GPU_SCAN_A_TILES 0x39cu /* u32: ceil(len / 32) */ +#define OMEGA_GPU_SCAN_A_WARPS 0x3a0u /* u32: warps in the grid (the tile stride) */ +#define OMEGA_GPU_SCAN_ARGS_WORDS 9u + +/* Mutants for the red checks (each must change some result): 1 the reduction tree skips d = 1, 2 the tile scan skips + * d = 16, 3 the carry adds S[tile] instead of S[tile - 1]. 0 = the real kernels. */ +typedef struct { OmegaScanKind kind; int mutant; } OmegaScanSpec; + +/* Builds the IR program of one kernel and allocates its registers; 0 or -1. */ +int omega_gpu_scan_codegen(const OmegaScanSpec *spec, BlackwellIRProgram *prog); + +/* Host references, the frozen order above. 0, or -1 for bad arguments or out of memory. */ +int omega_gpu_reduce_reference(OmegaGpuRedOp op, const float *x, size_t n, float *out); +int omega_gpu_prefix_sum_reference(const float *x, size_t n, float *y); + +/* The level driver. Device addresses are plain numbers (host pointers in the simulator). launch runs one kernel over + * grid_x CTAs of OMEGA_GPU_SCAN_THREADS threads with the given argument words and returns 0 when it completed. */ +typedef int (*OmegaScanLaunchFn)(void *ctx, OmegaScanKind kind, const uint32_t args[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t grid_x); +/* Scratch words a call needs beyond its input and output. */ +size_t omega_gpu_scan_reduce_scratch_words(size_t n); +size_t omega_gpu_scan_prefix_scratch_words(size_t n); +/* Reduction: the result lands in the scratch word the function returns through *out_va. */ +int omega_gpu_scan_drive_reduce(OmegaGpuRedOp op, size_t n, uint64_t in_va, uint64_t scratch_va, uint64_t *out_va, + OmegaScanLaunchFn launch, void *ctx, uint32_t *launches); +/* Prefix sum of in into out (out may equal in). */ +int omega_gpu_scan_drive_prefix(size_t n, uint64_t in_va, uint64_t out_va, uint64_t scratch_va, + OmegaScanLaunchFn launch, void *ctx, uint32_t *launches); +/* CTAs for a level of len values. */ +uint32_t omega_gpu_scan_grid(size_t len); + +typedef struct { + uint32_t launches; /* kernels run */ + uint64_t elapsed_ns; /* sum of launch-to-completion over the launches */ + uint64_t call_ns; /* the whole call, uploads and readback included */ +} OmegaGpuScanInfo; + +/* On the chip. x is read, out / y written; nothing else is kept between calls except the kernels. */ +int omega_gpu_reduce(OmegaGpuRedOp op, const float *x, size_t n, float *out, OmegaGpuScanInfo *info); +int omega_gpu_prefix_sum(const float *x, size_t n, float *y, OmegaGpuScanInfo *info); +/* Red checks: every later call builds its kernels with this mutant (clears the kernel cache). */ +void omega_gpu_scan_test_set_mutant(int mutant); +const char *omega_gpu_scan_rc_name(int rc); + +#ifdef __cplusplus +} +#endif +#endif /* OMEGA_GPU_SCAN_H */ diff --git a/src/omega_gpu_scan_ref.c b/src/omega_gpu_scan_ref.c new file mode 100644 index 000000000..ab5ee16a5 --- /dev/null +++ b/src/omega_gpu_scan_ref.c @@ -0,0 +1,75 @@ +/* omega_gpu_scan_ref.c -- the host references of omega_gpu_scan.h: the frozen order, in plain C on the CPU. + * Separate from the chip code so a CPU-only program can check them against the E1 reduction reference + * (tests/gpu_scan_ref_check.c). Additions only, so no fused multiply-add can change a bit. */ +#include "omega_gpu_scan.h" + +#include +#include + +#define PAD_SUM 0x80000000u /* -0.0 */ +#define PAD_MINMAX 0x7fc00000u /* quiet NaN */ + + +static float u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } + +static float combine(OmegaGpuRedOp op, float a, float b) { + if (op == OMEGA_GPU_RED_SUM) return a + b; + return op == OMEGA_GPU_RED_MAX ? __builtin_fmaxf(a, b) : __builtin_fminf(a, b); /* AArch64 FMAXNM / FMINNM: NaN ignored */ +} + +int omega_gpu_reduce_reference(OmegaGpuRedOp op, const float *x, size_t n, float *out) { + if ((unsigned)op > OMEGA_GPU_RED_MIN || !x || !out || n == 0) return -1; + const float pad = u2f(op == OMEGA_GPU_RED_SUM ? PAD_SUM : PAD_MINMAX); + float *cur = NULL; + size_t len = n; + const float *in = x; + do { + size_t nt = (len + 31) / 32; + float *next = malloc(nt * sizeof *next); + if (!next) { free(cur); return -1; } + for (size_t j = 0; j < nt; j++) { + float v[32]; + for (size_t i = 0; i < 32; i++) v[i] = j * 32 + i < len ? in[j * 32 + i] : pad; + for (size_t d = 16; d >= 1; d /= 2) + for (size_t i = 0; i + d < 32; i++) v[i] = combine(op, v[i], v[i + d]); /* ascending: v[i + d] is still old */ + next[j] = v[0]; + } + free(cur); + cur = next; in = next; len = nt; + } while (len > 1); + *out = cur[0]; + free(cur); + return 0; +} + +/* one scan level of len values: out (may alias in) and the tile totals */ +static void ref_scan_level(const float *in, float *out, float *tot, size_t len) { + for (size_t j = 0; j * 32 < len; j++) { + float v[32]; + for (size_t i = 0; i < 32; i++) v[i] = j * 32 + i < len ? in[j * 32 + i] : u2f(PAD_SUM); + for (size_t d = 1; d <= 16; d *= 2) + for (size_t i = 31; i >= d; i--) v[i] = v[i - d] + v[i]; /* descending: v[i - d] is still old */ + for (size_t i = 0; i < 32 && j * 32 + i < len; i++) out[j * 32 + i] = v[i]; + tot[j] = v[31]; + } +} + +static int ref_prefix(const float *in, float *out, size_t len) { + size_t nt = (len + 31) / 32; + float *tot = malloc(nt * sizeof *tot); + if (!tot) return -1; + ref_scan_level(in, out, tot, len); + int rc = 0; + if (nt > 1) { + rc = ref_prefix(tot, tot, nt); + for (size_t e = 32; rc == 0 && e < len; e++) out[e] = tot[e / 32 - 1] + out[e]; + } + free(tot); + return rc; +} + +int omega_gpu_prefix_sum_reference(const float *x, size_t n, float *y) { + if (!x || !y || n == 0) return -1; + return ref_prefix(x, y, n); +} + diff --git a/tests/gpu_scan_test.c b/tests/gpu_scan_test.c new file mode 100644 index 000000000..a648b5dc0 --- /dev/null +++ b/tests/gpu_scan_test.c @@ -0,0 +1,377 @@ +/* gpu_scan_test.c -- row C3 of docs/OMEGA.md: reductions and prefix sums of any length, bit-exact against the + * frozen-order host reference (src/omega_gpu_scan.h). + * + * --host-only no device: refusals, every kernel through our codegen and encoder, the references checked against + * exact integer sums and against the E1 reduction reference (omega_reduce_reference) + * --sim the real kernels through the warp simulator (tests/bw_warp_sim.h), both scheduling orders, lengths + * that cross every tile, CTA and grid-stride edge; the three mutants must be caught + * (no flag) the GB10: every n from 1 to 2048, then 2^k - 1, 2^k, 2^k + 1 up to 2^28, then random lengths; + * bit-exact (a NaN result must be a NaN); the three mutants must be caught. + * --max-log2 K stops the power-of-two ladder at 2^K (default 28). + * Last line: "C3 scan : PASS ( checks)" or "... FAIL ( of )". */ +#include "omega_gpu_scan.h" +#include "omega_gpu_session.h" +#include "omega_numeric_reduce.h" +#include "bw_warp_sim.h" + +#include +#include +#include +#include + +static int g_checks, g_failed; +static void check(int ok, const char *what) { + g_checks++; + if (!ok) { g_failed++; printf("FAIL: %s\n", what); } +} + +static uint32_t f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } +static float u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } +static int is_nan(uint32_t u) { return (u & 0x7f800000u) == 0x7f800000u && (u & 0x007fffffu); } +static int same(float a, float b) { uint32_t x = f2u(a), y = f2u(b); return x == y || (is_nan(x) && is_nan(y)); } + +static uint64_t g_rng = 0x9e3779b97f4a7c15ull; +static uint32_t rnd(void) { g_rng = g_rng * 6364136223846793005ull + 1442695040888963407ull; return (uint32_t)(g_rng >> 33); } + +/* inputs: 0 small integers (every sum exact), 1 mixed magnitudes and signed zeros, 2 mixed plus NaN and infinities */ +static void fill(float *x, size_t n, int kind, uint64_t seed) { + g_rng = seed * 0x2545f4914f6cdd1dull + 1; + for (size_t i = 0; i < n; i++) { + if (kind == 0) { x[i] = (float)((int)(rnd() % 2001u) - 1000); continue; } + float m = (float)((rnd() & 0x7fffffu) | 1u) * (rnd() & 1 ? -1.0f : 1.0f); + int e = (int)(rnd() % 41u) - 20 - 23; + x[i] = m * u2f((uint32_t)(127 + e) << 23); + if (i % 97u == 5u) x[i] = 0.0f; + if (i % 131u == 7u) x[i] = -0.0f; + if (kind == 2 && i % 53u == 11u) x[i] = u2f(0x7fc00000u | (rnd() & 0xffffu)); + if (kind == 2 && i == n / 3) x[i] = u2f(0x7f800000u); + if (kind == 2 && i == n / 2 && n > 4) x[i] = u2f(0xff800000u); + } +} + +static const char *op_name(OmegaGpuRedOp op) { return op == OMEGA_GPU_RED_SUM ? "sum" : op == OMEGA_GPU_RED_MAX ? "max" : "min"; } + +/* ------------------------------------------------------------------ host only */ + +static int fake_fail(void *ctx, OmegaScanKind k, const uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t g) { + (void)ctx; (void)k; (void)a; (void)g; return -1; +} + +static void host_only(void) { + char w[200]; + float x[4] = { 1, 2, 3, 4 }, o; + check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, x, 0, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce n = 0 refused"); + check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, NULL, 4, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce NULL input refused"); + check(omega_gpu_reduce((OmegaGpuRedOp)7, x, 4, &o, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "reduce unknown op refused"); + check(omega_gpu_reduce(OMEGA_GPU_RED_SUM, x, OMEGA_GPU_SCAN_MAX_N + 1, &o, NULL) == OMEGA_GPU_SCAN_TOO_LARGE, "reduce 2^28 + 1 refused"); + check(omega_gpu_prefix_sum(x, 0, x, NULL) == OMEGA_GPU_SCAN_BAD_ARGS, "prefix n = 0 refused"); + check(omega_gpu_prefix_sum(x, OMEGA_GPU_SCAN_MAX_N + 1, x, NULL) == OMEGA_GPU_SCAN_TOO_LARGE, "prefix 2^28 + 1 refused"); + uint64_t r; + check(omega_gpu_scan_drive_reduce(OMEGA_GPU_RED_SUM, 100, 0, 0, &r, fake_fail, NULL, NULL) == OMEGA_GPU_SCAN_CHIP_FAIL, "a failed launch is reported (reduce)"); + check(omega_gpu_scan_drive_prefix(100, 0, 0, 0, fake_fail, NULL, NULL) == OMEGA_GPU_SCAN_CHIP_FAIL, "a failed launch is reported (prefix)"); + + for (int mut = 0; mut <= 3; mut++) + for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) { + BlackwellIRProgram *p = calloc(1, sizeof *p); + OmegaScanSpec s = { (OmegaScanKind)k, mut }; + int rc = omega_gpu_scan_codegen(&s, p); + size_t bytes = rc == 0 ? omega_bw_program_code_bytes(p) : 0; + uint8_t *code = bytes ? malloc(bytes) : NULL; + OmegaBlackwellKernel kk; memset(&kk, 0, sizeof kk); + int enc = code ? omega_blackwell_kernel_encode_into(p, code, bytes, &kk) : -1; + snprintf(w, sizeof w, "kernel %d mutant %d through codegen and encoder (%zu bytes, %u gprs)", k, mut, bytes, (unsigned)kk.gpr_count); + check(rc == 0 && enc == 0 && kk.code_size == bytes, w); + if (mut == 0 && rc == 0) printf("kernel %d: %u insns, %zu bytes, %u gprs\n", k, (unsigned)p->count, bytes, (unsigned)kk.gpr_count); + free(code); free(p); + } + + /* the references against exact sums: integers in [-1000, 1000], n <= 16384, every partial sum below 2^24 */ + static float a[16384], y[16384]; + const size_t ns[] = { 1, 2, 31, 32, 33, 63, 64, 65, 1023, 1024, 1025, 1057, 16384 }; + for (size_t t = 0; t < sizeof ns / sizeof ns[0]; t++) { + size_t n = ns[t]; + fill(a, n, 0, n); + double s = 0, mx = -1e9, mn = 1e9; + for (size_t i = 0; i < n; i++) { s += a[i]; if (a[i] > mx) mx = a[i]; if (a[i] < mn) mn = a[i]; } + float rs, rmx, rmn; + int ok = omega_gpu_reduce_reference(OMEGA_GPU_RED_SUM, a, n, &rs) == 0 && omega_gpu_reduce_reference(OMEGA_GPU_RED_MAX, a, n, &rmx) == 0 && + omega_gpu_reduce_reference(OMEGA_GPU_RED_MIN, a, n, &rmn) == 0; + snprintf(w, sizeof w, "reference sum/max/min exact at n = %zu", n); + check(ok && rs == (float)s && rmx == (float)mx && rmn == (float)mn, w); + ok = omega_gpu_prefix_sum_reference(a, n, y) == 0; + double run = 0; size_t bad = 0; + for (size_t i = 0; i < n; i++) { run += a[i]; bad += y[i] != (float)run; } + snprintf(w, sizeof w, "reference prefix sum exact at n = %zu (%zu wrong)", n, bad); + check(ok && bad == 0, w); + } + + /* the reduction reference is the E1 order: equal bit for bit to omega_reduce_reference on any input */ + static float b[300000]; + const size_t ms[] = { 1, 2, 17, 32, 33, 100, 1000, 1024, 1025, 4097, 32768, 32769, 299999 }; + for (int kind = 1; kind <= 2; kind++) + for (size_t t = 0; t < sizeof ms / sizeof ms[0]; t++) + for (int op = 0; op < 3; op++) { + size_t n = ms[t]; + fill(b, n, kind, n * 3 + (size_t)op); + float mine, e1; + int ok = omega_gpu_reduce_reference((OmegaGpuRedOp)op, b, n, &mine) == 0 && omega_reduce_reference((OmegaReduceOp)op, b, n, &e1) == 0; + snprintf(w, sizeof w, "reference %s equals the E1 reference, inputs %d, n = %zu (%08x vs %08x)", op_name(op), kind, n, f2u(mine), f2u(e1)); + check(ok && same(mine, e1), w); + } + + /* the frozen order is a real order: summing left to right gives a different answer on mixed inputs */ + fill(b, 4097, 1, 99); + float tree, seq = -0.0f; + for (size_t i = 0; i < 4097; i++) seq += b[i]; + omega_gpu_reduce_reference(OMEGA_GPU_RED_SUM, b, 4097, &tree); + check(f2u(tree) != f2u(seq), "the frozen tree differs from a left-to-right sum (the order is pinned, not luck)"); +} + +/* ------------------------------------------------------------------ the simulator */ + +typedef struct { + BlackwellIRProgram *prog[OMEGA_SCAN_K_COUNT]; + int order; + WsRange ranges[3]; + char err[260]; +} SimCtx; + +static int sim_launch(void *ctx, OmegaScanKind k, const uint32_t a[OMEGA_GPU_SCAN_ARGS_WORDS], uint32_t grid_x) { + SimCtx *c = ctx; + static WsSim s; + memset(&s, 0, sizeof s); + s.p = c->prog[k]; s.threads = OMEGA_GPU_SCAN_THREADS; s.order = c->order; + for (unsigned i = 0; i < OMEGA_GPU_SCAN_ARGS_WORDS; i++) s.cbank[0x380 / 4 + i] = a[i]; + memcpy(s.ranges, c->ranges, sizeof c->ranges); s.nranges = 3; + if (ws_run(&s, grid_x, 1) != 0) { snprintf(c->err, sizeof c->err, "kernel %d: %s at pc %d", (int)k, s.msg, s.err_pc); return -1; } + return 0; +} + +static int sim_build(SimCtx *c, int mutant) { + for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) { + c->prog[k] = calloc(1, sizeof *c->prog[k]); + OmegaScanSpec s = { (OmegaScanKind)k, mutant }; + if (!c->prog[k] || omega_gpu_scan_codegen(&s, c->prog[k]) != 0) return -1; + } + return 0; +} +static void sim_free(SimCtx *c) { for (int k = 0; k < OMEGA_SCAN_K_COUNT; k++) free(c->prog[k]); } + +#define POISON 0x7fa00badu +static void poison(float *p, size_t n) { for (size_t i = 0; i < n; i++) memcpy(&p[i], &(uint32_t){ POISON }, 4); } + +/* one reduction through the simulator; 0 when it ran, the result in *out */ +static int sim_reduce(SimCtx *c, OmegaGpuRedOp op, const float *x, size_t n, float *out) { + size_t sw = omega_gpu_scan_reduce_scratch_words(n); + float *scr = malloc(sw * 4u); + poison(scr, sw); + c->ranges[0] = (WsRange){ (uintptr_t)x, (uintptr_t)(x + n) }; + c->ranges[1] = (WsRange){ (uintptr_t)scr, (uintptr_t)(scr + sw) }; + c->ranges[2] = c->ranges[1]; + uint64_t res = 0; + int rc = omega_gpu_scan_drive_reduce(op, n, (uintptr_t)x, (uintptr_t)scr, &res, sim_launch, c, NULL); + if (rc == 0) { memcpy(out, (const void *)(uintptr_t)res, 4); if (f2u(*out) == POISON) rc = -9; } + free(scr); + return rc; +} + +static int sim_prefix(SimCtx *c, const float *x, size_t n, float *y) { + size_t sw = omega_gpu_scan_prefix_scratch_words(n); + float *scr = malloc(sw * 4u); + poison(scr, sw); poison(y, n); + c->ranges[0] = (WsRange){ (uintptr_t)x, (uintptr_t)(x + n) }; + c->ranges[1] = (WsRange){ (uintptr_t)y, (uintptr_t)(y + n) }; + c->ranges[2] = (WsRange){ (uintptr_t)scr, (uintptr_t)(scr + sw) }; + int rc = omega_gpu_scan_drive_prefix(n, (uintptr_t)x, (uintptr_t)y, (uintptr_t)scr, sim_launch, c, NULL); + for (size_t i = 0; rc == 0 && i < n; i++) if (f2u(y[i]) == POISON) rc = -9; + free(scr); + return rc; +} + +static size_t diff(const float *a, const float *b, size_t n, size_t *first) { + size_t d = 0; + for (size_t i = 0; i < n; i++) if (!same(a[i], b[i])) { if (!d) *first = i; d++; } + return d; +} + +static void sim_tier(void) { + char w[600]; + static size_t ns[200]; size_t nn = 0; + for (size_t n = 1; n <= 70; n++) ns[nn++] = n; + const size_t more[] = { 255, 256, 257, 1000, 1023, 1024, 1025, 2047, 2048, 2049, 32767, 32768, 32769, 40000, 270000 }; + for (size_t i = 0; i < sizeof more / sizeof more[0]; i++) ns[nn++] = more[i]; + float *x = malloc(270000 * 4u), *y = malloc(270000 * 4u), *ref = malloc(270000 * 4u); + SimCtx c; memset(&c, 0, sizeof c); + check(sim_build(&c, 0) == 0, "simulator: all kernels built"); + for (int order = 0; order <= 1; order++) { + c.order = order; + size_t bad_red = 0, bad_pre = 0, runs = 0; + for (size_t t = 0; t < nn; t++) { + size_t n = ns[t]; + if (order == 1 && n > 40000) continue; + int kind = (int)(t % 3); + fill(x, n, kind, n * 7 + (size_t)order); + for (int op = 0; op < 3; op++) { + float got, want; + omega_gpu_reduce_reference((OmegaGpuRedOp)op, x, n, &want); + int rc = sim_reduce(&c, (OmegaGpuRedOp)op, x, n, &got); + runs++; + if (rc != 0 || !same(got, want)) { + bad_red++; + snprintf(w, sizeof w, "sim order %d %s n = %zu: rc %d got %08x want %08x %s", order, op_name(op), n, rc, f2u(got), f2u(want), c.err); + check(0, w); + } + } + omega_gpu_prefix_sum_reference(x, n, ref); + int rc = sim_prefix(&c, x, n, y); + size_t first = 0, d = rc == 0 ? diff(y, ref, n, &first) : n; + runs++; + if (rc != 0 || d) { + bad_pre++; + snprintf(w, sizeof w, "sim order %d prefix n = %zu: rc %d, %zu wrong, first at %zu (%08x vs %08x) %s", order, n, rc, d, first, + f2u(y[first]), f2u(ref[first]), c.err); + check(0, w); + } + } + snprintf(w, sizeof w, "simulator order %d: %zu runs, reductions wrong %zu, prefix sums wrong %zu", order, runs, bad_red, bad_pre); + check(bad_red == 0 && bad_pre == 0, w); + printf("%s\n", w); + } + sim_free(&c); + + /* red checks: each mutant must change a result the real kernels get right */ + for (int mut = 1; mut <= 3; mut++) { + SimCtx m; memset(&m, 0, sizeof m); + int built = sim_build(&m, mut) == 0, caught = 0; + const size_t n = 1000; + fill(x, n, 1, 4242); + if (built && mut == 1) { + for (int op = 0; op < 3 && !caught; op++) { + float got = 0, want; omega_gpu_reduce_reference((OmegaGpuRedOp)op, x, n, &want); + caught = sim_reduce(&m, (OmegaGpuRedOp)op, x, n, &got) != 0 || !same(got, want); + } + } else if (built) { + omega_gpu_prefix_sum_reference(x, n, ref); + size_t first; + caught = sim_prefix(&m, x, n, y) != 0 || diff(y, ref, n, &first) != 0; + } + snprintf(w, sizeof w, "simulator red check: mutant %d is caught", mut); + check(built && caught, w); + sim_free(&m); + } + free(x); free(y); free(ref); +} + +/* ------------------------------------------------------------------ the chip */ + +static size_t mem_available(void) { + FILE *f = fopen("/proc/meminfo", "r"); + char line[256]; size_t kb = 0; + while (f && fgets(line, sizeof line, f)) if (sscanf(line, "MemAvailable: %zu kB", &kb) == 1) break; + if (f) fclose(f); + return kb * 1024u; +} + +static float *g_x, *g_y, *g_ref; + +static void chip_one(size_t n, int kind, int verbose) { + char w[600]; + fill(g_x, n, kind, n * 11 + (size_t)kind); + for (int op = 0; op < 3; op++) { + float got = 0, want; OmegaGpuScanInfo info; + omega_gpu_reduce_reference((OmegaGpuRedOp)op, g_x, n, &want); + int rc = omega_gpu_reduce((OmegaGpuRedOp)op, g_x, n, &got, &info); + int ok = rc == 0 && same(got, want); + if (!ok || verbose) { + snprintf(w, sizeof w, "chip %s n = %zu inputs %d: %s, got %08x want %08x, %u launches, kernels %.3f ms%s%s", op_name(op), n, kind, + omega_gpu_scan_rc_name(rc), f2u(got), f2u(want), info.launches, info.elapsed_ns / 1e6, rc ? ": " : "", + rc ? omega_gpu_session_last_error() : ""); + if (ok) { g_checks++; printf("ok: %s\n", w); } else check(0, w); + } else g_checks++; + } + OmegaGpuScanInfo info; + omega_gpu_prefix_sum_reference(g_x, n, g_ref); + int rc = omega_gpu_prefix_sum(g_x, n, g_y, &info); + size_t first = 0, d = rc == 0 ? diff(g_y, g_ref, n, &first) : n; + if (rc || d || verbose) { + snprintf(w, sizeof w, "chip prefix n = %zu inputs %d: %s, %zu wrong (first at %zu), %u launches, kernels %.3f ms%s%s", n, kind, + omega_gpu_scan_rc_name(rc), d, first, info.launches, info.elapsed_ns / 1e6, rc ? ": " : "", rc ? omega_gpu_session_last_error() : ""); + if (!rc && !d) { g_checks++; printf("ok: %s\n", w); } else check(0, w); + } else g_checks++; +} + +static void chip_tier(unsigned max_log2) { + char w[200]; + size_t cap = (size_t)1 << max_log2; + if (cap > OMEGA_GPU_SCAN_MAX_N) cap = OMEGA_GPU_SCAN_MAX_N; + /* host: input, output, reference (3 x 4n); device buffer: in + out + scratch (~ 8n); plus 8 GiB for everyone else */ + size_t need = cap * 4u * 5u + ((size_t)8 << 30), have = mem_available(); + if (have < need) { + printf("NOT_RUN: MemAvailable %zu MiB < %zu MiB needed for n up to %zu\n", have >> 20, need >> 20, cap); + exit(2); + } + g_x = malloc(cap * 4u); g_y = malloc(cap * 4u); g_ref = malloc(cap * 4u); + if (!g_x || !g_y || !g_ref) { printf("NOT_RUN: host allocation\n"); exit(2); } + + int before = g_failed; + for (size_t n = 1; n <= 2048; n++) chip_one(n, (int)(n % 3), 0); + printf("every n from 1 to 2048 (sum, max, min, prefix): %s\n", g_failed == before ? "PASS" : "FAIL"); + before = g_failed; + for (unsigned k = 11; k <= max_log2 && k <= 28; k++) { + size_t p = (size_t)1 << k; + chip_one(p - 1, 1, 0); + chip_one(p, 2, k >= 20); + if (p + 1 <= cap) chip_one(p + 1, 1, 0); + } + printf("2^k - 1, 2^k, 2^k + 1 up to 2^%u: %s\n", max_log2, g_failed == before ? "PASS" : "FAIL"); + before = g_failed; + g_rng = 0xc3c3c3c3ull; + for (int i = 0; i < 64; i++) { + size_t n = 2049 + (((size_t)rnd() << 16) ^ rnd()) % (cap > (1u << 24) ? (1u << 24) : cap - 2048); + chip_one(n, i % 3, 0); + } + printf("64 random lengths: %s\n", g_failed == before ? "PASS" : "FAIL"); + + for (int mut = 1; mut <= 3; mut++) { + omega_gpu_scan_test_set_mutant(mut); + const size_t n = 1000; + fill(g_x, n, 1, 4242); + int caught = 0; + if (mut == 1) { + for (int op = 0; op < 3 && !caught; op++) { + float got = 0, want; omega_gpu_reduce_reference((OmegaGpuRedOp)op, g_x, n, &want); + caught = omega_gpu_reduce((OmegaGpuRedOp)op, g_x, n, &got, NULL) != 0 || !same(got, want); + } + } else { + size_t first; + omega_gpu_prefix_sum_reference(g_x, n, g_ref); + caught = omega_gpu_prefix_sum(g_x, n, g_y, NULL) != 0 || diff(g_y, g_ref, n, &first) != 0; + } + snprintf(w, sizeof w, "chip red check: mutant %d is caught", mut); + check(caught, w); + } + omega_gpu_scan_test_set_mutant(0); + fill(g_x, 1000, 1, 4242); + omega_gpu_prefix_sum_reference(g_x, 1000, g_ref); + size_t first; + check(omega_gpu_prefix_sum(g_x, 1000, g_y, NULL) == 0 && diff(g_y, g_ref, 1000, &first) == 0, "the real kernels are right again after the red checks"); + free(g_x); free(g_y); free(g_ref); +} + +int main(int argc, char **argv) { + const char *tier = "chip"; + unsigned max_log2 = 28; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--host-only")) tier = "host"; + else if (!strcmp(argv[i], "--sim")) tier = "sim"; + else if (!strcmp(argv[i], "--max-log2") && i + 1 < argc) max_log2 = (unsigned)atoi(argv[++i]); + else { fprintf(stderr, "usage: %s [--host-only | --sim] [--max-log2 K]\n", argv[0]); return 2; } + } + if (max_log2 < 11 || max_log2 > 28) { fprintf(stderr, "--max-log2 must be 11..28\n"); return 2; } + if (!strcmp(tier, "host")) host_only(); + else if (!strcmp(tier, "sim")) { host_only(); sim_tier(); } + else chip_tier(max_log2); + if (g_failed) printf("C3 scan %s: FAIL (%d of %d)\n", tier, g_failed, g_checks); + else printf("C3 scan %s: PASS (%d checks)\n", tier, g_checks); + return g_failed ? 1 : 0; +} From 6e177ce137bc75cdc77c315469e2ae3df3a58818 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 21:53:37 -0500 Subject: [PATCH 02/10] C3 scan: close hook drops the kernel cache with the device; chip check after close and reopen Without it a session close (or C5 recover) left the cached kernels pointing at the old device. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 0bd79b15306a830ab95a24688ddbe5ecb7d2b57a) --- src/omega_gpu_scan.c | 12 ++++++++++++ tests/gpu_scan_test.c | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/omega_gpu_scan.c b/src/omega_gpu_scan.c index 3f999eb35..0094072e3 100644 --- a/src/omega_gpu_scan.c +++ b/src/omega_gpu_scan.c @@ -197,8 +197,16 @@ static struct { int mutant; OmegaGpuMem code[OMEGA_SCAN_K_COUNT]; uint32_t gpr[OMEGA_SCAN_K_COUNT]; + int hooked; } g; +/* lock held; the session calls it right before it closes the device (also in omega_gpu_session_recover): the kernels go + * with the device, the next call builds them again on the new one */ +static void on_session_close(void) { + for (unsigned k = 0; k < OMEGA_SCAN_K_COUNT; k++) if (g.code[k].cpu) omega_gpu_session_free(&g.code[k]); + memset(g.code, 0, sizeof g.code); +} + void omega_gpu_scan_test_set_mutant(int mutant) { omega_gpu_session_lock(); for (unsigned k = 0; k < OMEGA_SCAN_K_COUNT; k++) if (g.code[k].cpu) omega_gpu_session_free(&g.code[k]); @@ -221,6 +229,10 @@ const char *omega_gpu_scan_rc_name(int rc) { /* lock held */ static int kernel_locked(OmegaScanKind k) { if (g.code[k].cpu) return OMEGA_GPU_SCAN_OK; + if (!g.hooked) { /* without the hook a kernel would outlive its device */ + if (omega_gpu_session_on_close(on_session_close) != 0) return OMEGA_GPU_SCAN_CHIP_FAIL; + g.hooked = 1; + } BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); if (!prog) return OMEGA_GPU_SCAN_CODEGEN_FAIL; OmegaScanSpec s = { k, g.mutant }; diff --git a/tests/gpu_scan_test.c b/tests/gpu_scan_test.c index a648b5dc0..1e1b608fc 100644 --- a/tests/gpu_scan_test.c +++ b/tests/gpu_scan_test.c @@ -355,6 +355,8 @@ static void chip_tier(unsigned max_log2) { omega_gpu_prefix_sum_reference(g_x, 1000, g_ref); size_t first; check(omega_gpu_prefix_sum(g_x, 1000, g_y, NULL) == 0 && diff(g_y, g_ref, 1000, &first) == 0, "the real kernels are right again after the red checks"); + omega_gpu_session_close(); /* the kernels go with the device (close hook); the next call builds them on a new one */ + check(omega_gpu_prefix_sum(g_x, 1000, g_y, NULL) == 0 && diff(g_y, g_ref, 1000, &first) == 0, "after the device closed and opened again the kernels are rebuilt and right"); free(g_x); free(g_y); free(g_ref); } From db0af940651b86bba876e5eaf1ec9ba950394e61 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 18:14:38 -0500 Subject: [PATCH 03/10] C3 scan evidence: carry the 2026-10-22 chip receipt (PASS 8,665 checks on a7d6463b) and today's host/sim logs on the rebased tip The chip log was recovered unpushed from the dead worker's worktree (durable copy ~/handoffs/evidence-L386-chip-20261022/). The scan kernel generator, order contract and test are byte-identical between that head and this tip; the two numeric files differ only by main's licence header, bw_warp_sim.h by main's warp visit-order knob (simulator only). 01/02 logs re-run 2026-10-24 23:10Z on c5cf3495b: host 133 checks, simulator 139 checks, PASS. A chip re-run on the train tip is still owed. Co-Authored-By: Claude Fable 5.1 --- evidence/C3-SCAN/01-host-only.log | 2 - evidence/C3-SCAN/02-sim.log | 2 - .../C3-SCAN/03-chip-20261022-a7d6463b.log | 45 +++++++++++++++++++ evidence/C3-SCAN/README.md | 4 +- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 evidence/C3-SCAN/03-chip-20261022-a7d6463b.log diff --git a/evidence/C3-SCAN/01-host-only.log b/evidence/C3-SCAN/01-host-only.log index 8f46aaf04..a48ef0ff5 100644 --- a/evidence/C3-SCAN/01-host-only.log +++ b/evidence/C3-SCAN/01-host-only.log @@ -1,8 +1,6 @@ -$ ./build/gpu_scan_test --host-only (omega c3/reduce-scan, 2026-10-22T02:07Z) kernel 0: 45 insns, 768 bytes, 18 gprs kernel 1: 45 insns, 768 bytes, 18 gprs kernel 2: 45 insns, 768 bytes, 18 gprs kernel 3: 79 insns, 1280 bytes, 26 gprs kernel 4: 33 insns, 640 bytes, 18 gprs C3 scan host: PASS (133 checks) -exit=0 diff --git a/evidence/C3-SCAN/02-sim.log b/evidence/C3-SCAN/02-sim.log index 25921f3cf..940bdee3e 100644 --- a/evidence/C3-SCAN/02-sim.log +++ b/evidence/C3-SCAN/02-sim.log @@ -1,4 +1,3 @@ -$ ./build/gpu_scan_test --sim (omega c3/reduce-scan, 2026-10-22T02:07Z) kernel 0: 45 insns, 768 bytes, 18 gprs kernel 1: 45 insns, 768 bytes, 18 gprs kernel 2: 45 insns, 768 bytes, 18 gprs @@ -7,4 +6,3 @@ kernel 4: 33 insns, 640 bytes, 18 gprs simulator order 0: 340 runs, reductions wrong 0, prefix sums wrong 0 simulator order 1: 336 runs, reductions wrong 0, prefix sums wrong 0 C3 scan sim: PASS (139 checks) -exit=0 diff --git a/evidence/C3-SCAN/03-chip-20261022-a7d6463b.log b/evidence/C3-SCAN/03-chip-20261022-a7d6463b.log new file mode 100644 index 000000000..4af451bae --- /dev/null +++ b/evidence/C3-SCAN/03-chip-20261022-a7d6463b.log @@ -0,0 +1,45 @@ +Thu Oct 22 07:03:33 UTC 2026 +a7d6463b9df4485484e207f11fb7802d09aed627 +c417f88728d2ee771d0af1369aa1a46791b48c11d4c8d685eb9eef393e082719 build/gpu_scan_test +COMMAND: spark-window run timeout 3600 stdbuf -oL -eL build/gpu_scan_test +every n from 1 to 2048 (sum, max, min, prefix): PASS +ok: chip sum n = 1048576 inputs 2: OK, got 7fffffff want 7fc0105f, 4 launches, kernels 0.530 ms +ok: chip max n = 1048576 inputs 2: OK, got 7f800000 want 7f800000, 4 launches, kernels 0.617 ms +ok: chip min n = 1048576 inputs 2: OK, got ff800000 want ff800000, 4 launches, kernels 0.621 ms +ok: chip prefix n = 1048576 inputs 2: OK, 0 wrong (first at 0), 7 launches, kernels 1.020 ms +ok: chip sum n = 2097152 inputs 2: OK, got 7fffffff want 7fc01b96, 5 launches, kernels 0.981 ms +ok: chip max n = 2097152 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 0.823 ms +ok: chip min n = 2097152 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 1.631 ms +ok: chip prefix n = 2097152 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 1.417 ms +ok: chip sum n = 4194304 inputs 2: OK, got 7fffffff want 7fc03205, 5 launches, kernels 1.052 ms +ok: chip max n = 4194304 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 2.124 ms +ok: chip min n = 4194304 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 1.010 ms +ok: chip prefix n = 4194304 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 3.284 ms +ok: chip sum n = 8388608 inputs 2: OK, got 7fffffff want 7fc05ee2, 5 launches, kernels 1.579 ms +ok: chip max n = 8388608 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 1.412 ms +ok: chip min n = 8388608 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 2.365 ms +ok: chip prefix n = 8388608 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 4.076 ms +ok: chip sum n = 16777216 inputs 2: OK, got 7fffffff want 7fc0b89e, 5 launches, kernels 2.558 ms +ok: chip max n = 16777216 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 2.362 ms +ok: chip min n = 16777216 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 2.660 ms +ok: chip prefix n = 16777216 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 3.808 ms +ok: chip sum n = 33554432 inputs 2: OK, got 7fffffff want 7fc06c14, 5 launches, kernels 5.531 ms +ok: chip max n = 33554432 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 5.973 ms +ok: chip min n = 33554432 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 5.058 ms +ok: chip prefix n = 33554432 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 6.689 ms +ok: chip sum n = 67108864 inputs 2: OK, got 7fffffff want 7fc0d301, 6 launches, kernels 10.649 ms +ok: chip max n = 67108864 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 9.341 ms +ok: chip min n = 67108864 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 9.005 ms +ok: chip prefix n = 67108864 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 13.186 ms +ok: chip sum n = 134217728 inputs 2: OK, got 7fffffff want 7fc0a0da, 6 launches, kernels 17.443 ms +ok: chip max n = 134217728 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 17.061 ms +ok: chip min n = 134217728 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 18.621 ms +ok: chip prefix n = 134217728 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 24.440 ms +ok: chip sum n = 268435456 inputs 2: OK, got 7fffffff want 7fc03c8d, 6 launches, kernels 36.363 ms +ok: chip max n = 268435456 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 35.326 ms +ok: chip min n = 268435456 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 35.078 ms +ok: chip prefix n = 268435456 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 46.719 ms +2^k - 1, 2^k, 2^k + 1 up to 2^28: PASS +64 random lengths: PASS +C3 scan chip: PASS (8665 checks) +EXIT_CODE=0 diff --git a/evidence/C3-SCAN/README.md b/evidence/C3-SCAN/README.md index b932ba866..ad11023e8 100644 --- a/evidence/C3-SCAN/README.md +++ b/evidence/C3-SCAN/README.md @@ -9,6 +9,6 @@ order is the E1 contract (`docs/numeric/E1_REDUCTION_CONTRACT.md`). |---|---|---| | 01-host-only | bad calls refused; all five kernels (and each planted fault) go through our code generator and encoder; the host reference gives exact answers on integer inputs and equals the E1 reduction reference bit for bit on mixed, signed-zero, NaN and infinite inputs; the frozen tree differs from a left-to-right sum | PASS, 133 checks | | 02-sim | the real kernels in the warp simulator, both scheduling orders, every length 1 to 70 and the tile, block and grid-stride edges up to 270,000; three planted faults (a skipped tree step, a skipped scan step, a carry from the wrong tile) each caught | PASS, 139 checks | -| (next) chip | every n from 1 to 2048, 2^k - 1, 2^k, 2^k + 1 up to 2^28, 64 random lengths, the three faults caught on the GB10 | waiting for a chip window | +| 03-chip-20261022-a7d6463b | every n from 1 to 2048, 2^k - 1, 2^k, 2^k + 1 up to 2^28, 64 random lengths, the three faults caught on the GB10 | PASS (8,665 checks), run 2026-10-22 07:03Z on `c3/gemm` a7d6463b (an older head, before this branch was rebased onto main 0d72560a); the kernel generator, its order contract and the test (`src/omega_gpu_scan.c`, `src/omega_gpu_scan.h`, `tests/gpu_scan_test.c`) are byte-identical between that head and this tip; `src/omega_numeric.c` and `src/omega_numeric_reduce.c` differ only by the licence header main added; `tests/bw_warp_sim.h` gained main's warp visit-order knob (simulator only, no chip code); binary sha256 c417f887 28d2ee77...; log recovered unpushed from the dead worker's worktree `omega-c5`-era sibling `omega-c3-scan` (durable copy `~/handoffs/evidence-L386-chip-20261022/`). A re-run on this tip is owed before the row is final. | -Command: `make test-gpu-scan` (host and simulator). The chip run is `build/gpu_scan_test` with no flag, under the GB10 lock. +Command: `make test-gpu-scan` (host and simulator; `PHYSICS_DIR` must point at the physics checkout pinned in `physics.lock`). The chip run is `build/gpu_scan_test` with no flag, under the GB10 lock. 01 and 02 logs: 2026-10-24 23:10Z on this tip (c5cf3495b, binary sha256 3400c91e 5d91d1a1...), host 133 checks, simulator 139 checks. From 961bde0e1306142feaff6e77f2a150653c4dfd0a Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 18:29:05 -0500 Subject: [PATCH 04/10] C3 scan evidence: chip tier PASS (8,665 checks) on the train tip f16b56a58, 2026-10-24 23:26Z Shared value-check window 20261024T232617Z-b940cf, 39 s wall, binary byte-identical to this branch's build (sha256 3400c91e...). Row 03 (2026-10-22, older head) stays as history; row 04 is the receipt for this tip. Co-Authored-By: Claude Fable 5.1 --- .../C3-SCAN/04-chip-20261024-f16b56a58.log | 52 +++++++++++++++++++ evidence/C3-SCAN/README.md | 3 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 evidence/C3-SCAN/04-chip-20261024-f16b56a58.log diff --git a/evidence/C3-SCAN/04-chip-20261024-f16b56a58.log b/evidence/C3-SCAN/04-chip-20261024-f16b56a58.log new file mode 100644 index 000000000..a3a0b7d00 --- /dev/null +++ b/evidence/C3-SCAN/04-chip-20261024-f16b56a58.log @@ -0,0 +1,52 @@ +Sat Oct 24 11:26:17 PM UTC 2026 +f16b56a58383e6d635b9bda97be0be207c67f2e3 +physics pin 6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf (PHYSICS_DIR=/home/drakestapleton/workspace/l386-physics) +3400c91e5d91d1a17369a96c2b4642609518ae955beb579404ff20d6ebb2a9a0 build/gpu_scan_test +CAMERA /dev/nvidia0 holders before: ,873959,2935091,3489680 +CAMERA 18091: {"object":"list","data":[{"id":"qwen3.6-35b-a3b-fp8","object":"model","created": +WINDOW: 20261024T232617Z-b940cf +COMMAND: spark-window run ./build/gpu_scan_test +every n from 1 to 2048 (sum, max, min, prefix): PASS +ok: chip sum n = 1048576 inputs 2: OK, got 7fffffff want 7fc0105f, 4 launches, kernels 0.516 ms +ok: chip max n = 1048576 inputs 2: OK, got 7f800000 want 7f800000, 4 launches, kernels 0.497 ms +ok: chip min n = 1048576 inputs 2: OK, got ff800000 want ff800000, 4 launches, kernels 0.513 ms +ok: chip prefix n = 1048576 inputs 2: OK, 0 wrong (first at 0), 7 launches, kernels 1.019 ms +ok: chip sum n = 2097152 inputs 2: OK, got 7fffffff want 7fc01b96, 5 launches, kernels 0.826 ms +ok: chip max n = 2097152 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 0.723 ms +ok: chip min n = 2097152 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 0.826 ms +ok: chip prefix n = 2097152 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 1.229 ms +ok: chip sum n = 4194304 inputs 2: OK, got 7fffffff want 7fc03205, 5 launches, kernels 1.034 ms +ok: chip max n = 4194304 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 0.996 ms +ok: chip min n = 4194304 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 1.029 ms +ok: chip prefix n = 4194304 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 1.610 ms +ok: chip sum n = 8388608 inputs 2: OK, got 7fffffff want 7fc05ee2, 5 launches, kernels 1.439 ms +ok: chip max n = 8388608 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 1.442 ms +ok: chip min n = 8388608 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 1.439 ms +ok: chip prefix n = 8388608 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 2.358 ms +ok: chip sum n = 16777216 inputs 2: OK, got 7fffffff want 7fc0b89e, 5 launches, kernels 2.252 ms +ok: chip max n = 16777216 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 2.152 ms +ok: chip min n = 16777216 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 2.252 ms +ok: chip prefix n = 16777216 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 3.480 ms +ok: chip sum n = 33554432 inputs 2: OK, got 7fffffff want 7fc06c14, 5 launches, kernels 3.579 ms +ok: chip max n = 33554432 inputs 2: OK, got 7f800000 want 7f800000, 5 launches, kernels 3.475 ms +ok: chip min n = 33554432 inputs 2: OK, got ff800000 want ff800000, 5 launches, kernels 3.688 ms +ok: chip prefix n = 33554432 inputs 2: OK, 0 wrong (first at 0), 9 launches, kernels 5.833 ms +ok: chip sum n = 67108864 inputs 2: OK, got 7fffffff want 7fc0d301, 6 launches, kernels 6.533 ms +ok: chip max n = 67108864 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 6.504 ms +ok: chip min n = 67108864 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 6.442 ms +ok: chip prefix n = 67108864 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 10.330 ms +ok: chip sum n = 134217728 inputs 2: OK, got 7fffffff want 7fc0a0da, 6 launches, kernels 12.133 ms +ok: chip max n = 134217728 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 12.534 ms +ok: chip min n = 134217728 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 12.128 ms +ok: chip prefix n = 134217728 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 19.979 ms +ok: chip sum n = 268435456 inputs 2: OK, got 7fffffff want 7fc03c8d, 6 launches, kernels 23.837 ms +ok: chip max n = 268435456 inputs 2: OK, got 7f800000 want 7f800000, 6 launches, kernels 24.345 ms +ok: chip min n = 268435456 inputs 2: OK, got ff800000 want ff800000, 6 launches, kernels 24.327 ms +ok: chip prefix n = 268435456 inputs 2: OK, 0 wrong (first at 0), 11 launches, kernels 38.488 ms +2^k - 1, 2^k, 2^k + 1 up to 2^28: PASS +64 random lengths: PASS +C3 scan chip: PASS (8665 checks) +EXIT_CODE=0 + close.json + open.json +Sat Oct 24 11:26:56 PM UTC 2026 diff --git a/evidence/C3-SCAN/README.md b/evidence/C3-SCAN/README.md index ad11023e8..78bc955bf 100644 --- a/evidence/C3-SCAN/README.md +++ b/evidence/C3-SCAN/README.md @@ -9,6 +9,7 @@ order is the E1 contract (`docs/numeric/E1_REDUCTION_CONTRACT.md`). |---|---|---| | 01-host-only | bad calls refused; all five kernels (and each planted fault) go through our code generator and encoder; the host reference gives exact answers on integer inputs and equals the E1 reduction reference bit for bit on mixed, signed-zero, NaN and infinite inputs; the frozen tree differs from a left-to-right sum | PASS, 133 checks | | 02-sim | the real kernels in the warp simulator, both scheduling orders, every length 1 to 70 and the tile, block and grid-stride edges up to 270,000; three planted faults (a skipped tree step, a skipped scan step, a carry from the wrong tile) each caught | PASS, 139 checks | -| 03-chip-20261022-a7d6463b | every n from 1 to 2048, 2^k - 1, 2^k, 2^k + 1 up to 2^28, 64 random lengths, the three faults caught on the GB10 | PASS (8,665 checks), run 2026-10-22 07:03Z on `c3/gemm` a7d6463b (an older head, before this branch was rebased onto main 0d72560a); the kernel generator, its order contract and the test (`src/omega_gpu_scan.c`, `src/omega_gpu_scan.h`, `tests/gpu_scan_test.c`) are byte-identical between that head and this tip; `src/omega_numeric.c` and `src/omega_numeric_reduce.c` differ only by the licence header main added; `tests/bw_warp_sim.h` gained main's warp visit-order knob (simulator only, no chip code); binary sha256 c417f887 28d2ee77...; log recovered unpushed from the dead worker's worktree `omega-c5`-era sibling `omega-c3-scan` (durable copy `~/handoffs/evidence-L386-chip-20261022/`). A re-run on this tip is owed before the row is final. | +| 03-chip-20261022-a7d6463b | every n from 1 to 2048, 2^k - 1, 2^k, 2^k + 1 up to 2^28, 64 random lengths, the three faults caught on the GB10 | PASS (8,665 checks), run 2026-10-22 07:03Z on `c3/gemm` a7d6463b (an older head, before this branch was rebased onto main 0d72560a); the kernel generator, its order contract and the test (`src/omega_gpu_scan.c`, `src/omega_gpu_scan.h`, `tests/gpu_scan_test.c`) are byte-identical between that head and this tip; `src/omega_numeric.c` and `src/omega_numeric_reduce.c` differ only by the licence header main added; `tests/bw_warp_sim.h` gained main's warp visit-order knob (simulator only, no chip code); binary sha256 c417f887 28d2ee77...; log recovered unpushed from the dead worker's worktree `omega-c5`-era sibling `omega-c3-scan` (durable copy `~/handoffs/evidence-L386-chip-20261022/`). Re-run on the train tip: row 04. | +| 04-chip-20261024-f16b56a58 | the same chip battery (every n to 2048, 2^k - 1 / 2^k / 2^k + 1 to 2^28, 64 random lengths, three faults caught) on the GB10 | PASS (8,665 checks), 2026-10-24 23:26Z on the L386 train tip f16b56a58 (c3/gemm over this branch over main 0d72560a), binary sha256 3400c91e 5d91d1a1... (byte-identical to this branch's own build), 39 s wall, spark-window 20261024T232617Z-b940cf (gb10 shared, value check), chip shared with the live 35B server on 18091 and two other /dev/nvidia0 holders. | Command: `make test-gpu-scan` (host and simulator; `PHYSICS_DIR` must point at the physics checkout pinned in `physics.lock`). The chip run is `build/gpu_scan_test` with no flag, under the GB10 lock. 01 and 02 logs: 2026-10-24 23:10Z on this tip (c5cf3495b, binary sha256 3400c91e 5d91d1a1...), host 133 checks, simulator 139 checks. From 002b4c08e151fbf79929b534f1040c9ad71ab660 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 18:54:34 -0500 Subject: [PATCH 05/10] crumb: recompile after the re-stack on main 697539a57 (L386 train) Co-Authored-By: Claude Fable 5.1 --- .crumb | 38 +++++++++++++-------------- src/.crumb | 52 ++++++++++++++++++------------------ tests/.crumb | 74 ++++++++++++++++++++++++++-------------------------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/.crumb b/.crumb index bff65f4b0..c7d214e62 100644 --- a/.crumb +++ b/.crumb @@ -42,68 +42,68 @@ "children": [ { "digest": "9f19f11674ca5dfc3c9c3ae35fe6106557aee9583210da13d257e1b9d88e052c", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "calibration", "purpose": "Directory calibration. Purpose not yet described by a human." }, { "digest": "c92de7796549ecf47bb28700d4b82e8ba3e4dd260cdb4caa61a3337c44e063d3", - "last_commit": "843424ce", + "last_commit": "843424cea", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, { "digest": "536f7b8db9a92a1f586bad4379d47544a30d1b8e83c2d799c18e66cf8660c9ae", - "last_commit": "30bb116c", + "last_commit": "30bb116cc", "name": "doctrine", "purpose": "Directory doctrine. Purpose not yet described by a human." }, { "digest": "28ca50efe4c6219607f80199b70e50807127d121c66550511606dede047a6200", - "last_commit": "f9602043", + "last_commit": "f96020434", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, { "digest": "590f1f3a26a12dfd9df281ec944b882b85fd4ac2ae07a88a03bb8bd0d7d62536", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "research", "purpose": "Directory research. Purpose not yet described by a human." }, { "digest": "6327473d41e10acbf43be0918d3557509322bfd7d6e075e114c79c2600a47305", - "last_commit": "43d8d20d", + "last_commit": "43d8d20da", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "4718c14bd4052ff822a315892aebc3c2229900b338191d98c95945b109be4e91", - "last_commit": "1719bc69", + "digest": "ba3fa7cfe0a7e2df29583c0450bf5f7b5789349b5bbe735d1448a50295a87ec8", + "last_commit": "6e177ce13", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "8fa4874233c906929082e779408ae009b381ade4590b930a2faf68c60fd7e48f", - "last_commit": "79b2b632", + "digest": "87757530a28d4408bc4410fd8f922088f3e3f1cbc8987c5879e92ca59fe8728a", + "last_commit": "6e177ce13", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "e519c1f13dc5134c5b6ab17f669745776880cb6e78c6efd2f716283760466c66", - "last_commit": "1a12d5d0", + "last_commit": "1a12d5d0b", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:e53d60955af1d03b4ada9e70e1c969877d2ccf7d74cd47d38cda6a65b37858e3", - "compiled_at": "2026-10-24T23:32:51Z", + "children_root": "sha256:25bb98707e3701d95854342be7572172b8e9151d409fbcaea73ddc1690591607", + "compiled_at": "2026-10-24T23:54:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:fd24682c44204b438ba61e45410f87473e10352ca7dc4755eb4a04175326bd75", - "evidence_files": 11614, - "evidence_root": "sha256:e8361cf08ea15248d8a6e60b7e9c801908c7bb76d44196e72b06ce852ddf5bd6", - "files": 14914, - "generated_at_commit": "79b2b6329d552350efc62eecce2b298afa53fc10", - "source_tree": "sha256:e7e0d299c68fcd99850bc4678c27fcb03e0f43e7dadf050166aa54b84b6cd466" + "digest": "sha256:2aca06720f7a98be3c84475dcbf35c466d4bae33d6e93a2e07c0abb9e8d21f1e", + "evidence_files": 11619, + "evidence_root": "sha256:2a8475f2e1c377d2a0715da7b2b9de849865303f80c1776f351177440492ec9e", + "files": 14923, + "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", + "source_tree": "sha256:98bef521239fcbbae90d313839be15e5882adfbce6cc99f3045fe0c863cb6e52" }, "owner_lane": "", "provenance": { diff --git a/src/.crumb b/src/.crumb index 492b0dd03..5bd5f0ee5 100644 --- a/src/.crumb +++ b/src/.crumb @@ -62,140 +62,140 @@ "children": [ { "digest": "728ab6985dea994eb78a7eb2521384a911492d1c36819c17970a5dc3a8a0c5e2", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "algebra", "purpose": "Directory src/algebra. Purpose not yet described by a human." }, { "digest": "1881ed1d139a405a777d24d4b26f97bc8405dee0552d6ce21841ce4833560ce2", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "ans", "purpose": "ANS (Alignment Navigation System), Inertial Alignment v1: frozen reference atoms, drift filter o" }, { "digest": "92c3e2481f7457afd6c7717e6c1a75ebab950ec9114b48025dd137a6edb2975c", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "autodiff", "purpose": "M21 OMEGA_AUTODIFF: reverse-mode tape over M20 tensor CPU ops, caller-owned nodes and scratch, p" }, { "digest": "3bd51397fcd28cd54db65c1df72c320883798bc8550779b2b79c8498b28ffb0d", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "compiler", "purpose": "Directory src/compiler. Purpose not yet described by a human." }, { "digest": "36a66980895553ae73884798bc09a92141e1aeba5e5068a7d9d62a99bad02548", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "crumbline", "purpose": "Directory src/crumbline. Purpose not yet described by a human." }, { "digest": "c75df77ddb2bae35ac5e1225a0ae9dcef77b24608775c7b8d02dce1af0ec3ca4", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "dual_experiment", "purpose": "DUAL applicability experiment library (ARCH-0031 offline evidence lane): deterministic discrete " }, { "digest": "8856d5162c55cb33997201cd580638f80ea933b46e11c61e1913185d419731d7", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "estimation", "purpose": "Directory src/estimation. Purpose not yet described by a human." }, { "digest": "391e337c60cb8b2ae549595394482c23717c1757d83747a7446e81cd780750c1", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "fabric", "purpose": "Directory src/fabric. Purpose not yet described by a human." }, { "digest": "2d33eb528dafb5954bb027cdd9a7c7923594c177f17181194311155b4e1f40b3", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "language", "purpose": "Directory src/language. Purpose not yet described by a human." }, { "digest": "cd0551dbfb6fc354741efe9a3ad1808ffaaf6a8d7e9e7345851333d7a721cee0", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "osh", "purpose": "osh (Omega-native shell, arch#158) lexer unit: layout list, generator, osh_lex.osc, C reference " }, { "digest": "2b5dd2c64d4bbba8c41471dc1af5a0b00bfc1361a2c680d78b99fb30b5b547fe", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "path", "purpose": "Directory src/path. Purpose not yet described by a human." }, { "digest": "e0b91129cc9c188fc0e47b7f3189a3a9a09f9c55eecd018786794571ffc39aad", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "physics0", "purpose": "PD-0 hidden-equation benchmark (Physics-0 Discovery Engine cut 1): world, oracle, scorer, ladder" }, { "digest": "8b923fb5dc1de3b04afae043a4770f7b1fb27d959a8f597191ae2556d822a1cf", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "polyglot", "purpose": "Directory src/polyglot. Purpose not yet described by a human." }, { "digest": "076f486fdf51e12a26160e7f0bf7686fea611db54216f7fef81367620e7a6bdb", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "reservoir", "purpose": "Ionic-droplet reservoir simulator (omega#440): binary32 fixed-step RK4 of the authors' droplet m" }, { "digest": "c6af24b823d6a18a8ad1593003a214fcd577955d1d134bc4304a5c097a71cd35", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "runtime", "purpose": "Directory src/runtime. Purpose not yet described by a human." }, { "digest": "af5fcc64fe83dc35f782724372854febde5461f5eab8b327f3c3ed75f8572053", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "searchtrace", "purpose": "Directory src/searchtrace. Purpose not yet described by a human." }, { "digest": "b82288db7e732d10f954e921ac98c60e19579a3e58118cc12c49230587929ea2", - "last_commit": "ed8de573", + "last_commit": "ed8de5736", "name": "synapse", "purpose": "Synapse ADR 0003 J1 binary codec port: layout list, generator, syn_codec.osc (A1 WAL records + c" }, { "digest": "9723dd7c18d4e2c22db631680974e1025bccb9c309619424e2f4dfcc43cc7068", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "tensor", "purpose": "M20 OMEGA_TENSOR: immutable tensor semantic layer, views, generation-checked storage, CPU realiz" }, { "digest": "06d9fb18dddf7ab0f8ad02fffd15ce8b80808c77d0904609b6baae83c2b05ce5", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "train", "purpose": "Directory src/train. Purpose not yet described by a human." }, { "digest": "812a7faed07b21e066b732ed596eb0aea609379a2b2af0e8b61dd1ea05bef602", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "turing", "purpose": "Directory src/turing. Purpose not yet described by a human." }, { "digest": "b2e34b2ea0392059ac30d17e27289b1146e523db60a02ef825edef96036817ab", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "visor", "purpose": "Directory src/visor. Purpose not yet described by a human." } ], "children_root": "sha256:4460b4a6d5ed4054d462af660a6a02691350a35a8f44197e60ce605e243f698e", - "compiled_at": "2026-10-24T23:28:54Z", + "compiled_at": "2026-10-24T23:54:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:4718c14bd4052ff822a315892aebc3c2229900b338191d98c95945b109be4e91", + "digest": "sha256:ba3fa7cfe0a7e2df29583c0450bf5f7b5789349b5bbe735d1448a50295a87ec8", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 558, - "generated_at_commit": "0d72560ad82c657b9b51b62119781b36484e2bdc", - "source_tree": "sha256:2c08e2cc72d20b23284775f67a56a7c759fe03ad159060f06ad765e7b76d1526" + "files": 561, + "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", + "source_tree": "sha256:286ee3dab8eced7c5c94e6383d494fd218b10140043352907a3eb7ab3f49e413" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index c816853a1..a24ca6ab6 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -110,206 +110,206 @@ "children": [ { "digest": "2c1deaaa1bae6257789749edde641df61413250fe91ce6aa61a99dfb3b271306", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "algebra", "purpose": "Directory tests/algebra. Purpose not yet described by a human." }, { "digest": "63f086b68bb9ffc032cbd74931309ab34df3c8c341b57935e5db43d8bf475800", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "ans", "purpose": "Tests 1-10 for ANS (docs/ans/INERTIAL_ALIGNMENT_SPEC_V1.md): freeze/digest, hostile reference mu" }, { "digest": "45c5f4fd157769cf0dcc4b8acbd76b0953580bc328714bab8e1d65e9264a5664", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "brownian", "purpose": "Directory tests/brownian. Purpose not yet described by a human." }, { "digest": "1cd97575b2b10d9313ca0df4997391612056754778bb2851bf052c146144f15e", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "canonicalization", "purpose": "Directory tests/canonicalization. Purpose not yet described by a human." }, { "digest": "646c083a94914e5726634c33cc1e694349cfcd4f43817864ffec83e506a52d4e", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "compiler", "purpose": "Directory tests/compiler. Purpose not yet described by a human." }, { "digest": "9e372cfc9747befacdcf31bc8643356aaff861e81ee6640b4866170be67b5e6c", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "constraints", "purpose": "Directory tests/constraints. Purpose not yet described by a human." }, { "digest": "87a3efa5cd0aefa7821046f9a31594bfa0a109e95005a1e12f40c99a1bc6cd3d", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "crumbline", "purpose": "Directory tests/crumbline. Purpose not yet described by a human." }, { "digest": "10aa3424eded7768fee0bae0eedd062b9deac3279d2e5721439fd024493bc42b", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "dual_experiment", "purpose": "Tests for the DUAL applicability experiment: determinism (same seed, byte-identical results dige" }, { "digest": "758dde696afa847d9347fad76b0c4935e968f8af4551f0f9810ec2a37ad9847a", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "effect", "purpose": "Directory tests/effect. Purpose not yet described by a human." }, { "digest": "23e559d13ff664995baca31dc157a8cf5a860615f3ecb07a9a40fe4626b57ae3", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "estimation", "purpose": "Directory tests/estimation. Purpose not yet described by a human." }, { "digest": "b7b6391caf653c76707a21f9969126abcbc730d1243259219225fdb9bc0084e0", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "fabric", "purpose": "Directory tests/fabric. Purpose not yet described by a human." }, { "digest": "defc52a44ea0f65ba5de3468de786148ba58d292ffa217fb95629a28a569a977", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "identity", "purpose": "Directory tests/identity. Purpose not yet described by a human." }, { "digest": "6ba43d622b712a4215767cab29425016f29cce4b28eb9e4961fc67fd20e9d765", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "language", "purpose": "Directory tests/language. Purpose not yet described by a human." }, { "digest": "54f43a3416595ff5d4e64bd12afe013359e706651c39c78e2896a5799638d263", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "malformed", "purpose": "Directory tests/malformed. Purpose not yet described by a human." }, { "digest": "a03a4dd9a72f7b449342e562f6d9df1a3348fb03fb640b662956caf163dcd7e9", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "numeric_native", "purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity" }, { "digest": "d958af5413726ddc48a47721800d9766939129f480b26492332ba094577837cb", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "osh", "purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292)" }, { "digest": "12b31dc2cd4f6a6c27983db11b4140c597025c9124da5ddcbe6a9230ab4f8410", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "path", "purpose": "Directory tests/path. Purpose not yet described by a human." }, { "digest": "51f14936b27d3d21379cf05ea1b6b532cf3175a40844dac85f023a61e7a0912c", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "physics0", "purpose": "PD-0 gates: world self-test, oracle calibration, learner L0/L1/NULL, mutations, OSC differential" }, { "digest": "c8524317c751fa8f464cabc31b760cef262abba822f1843482a02e239daa81b3", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "polyglot", "purpose": "Directory tests/polyglot. Purpose not yet described by a human." }, { "digest": "6569e2cd6dbf6f792edb5d83bf0715df9dece42ca7bd9b3a291535de0492d3aa", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "program", "purpose": "Directory tests/program. Purpose not yet described by a human." }, { "digest": "c549b5b82fd026d664b35e4b1a5d7fd2aaafa13b60b541cfbba87d7522517b1d", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "r16_inventory", "purpose": "Directory tests/r16_inventory. Purpose not yet described by a human." }, { "digest": "855bd23e4c526fb49eeb430c4ea5967d3f2f9da3a5b3aa3ec9dae5b814b11a21", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "r16_negative", "purpose": "Directory tests/r16_negative. Purpose not yet described by a human." }, { "digest": "f21be04969cbf51de17118c4f81b103f712db56fd517a1f12dd0d3ac4ff3afe4", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "r16_surface", "purpose": "Directory tests/r16_surface. Purpose not yet described by a human." }, { "digest": "b0ba3448394d5f27958c38b7233ae389e5e437e327f0859749a774fb252d6b02", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "realize", "purpose": "Directory tests/realize. Purpose not yet described by a human." }, { "digest": "157018d66de5bfd149015654cf0bda1346a9cfcefe5fd552c1d54859cd9ece81", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "relations", "purpose": "Directory tests/relations. Purpose not yet described by a human." }, { "digest": "e5f68362c083510e34c41f65de3ba2d553eac8a52fbc3e4cc1f69314eac9cc32", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "reservoir", "purpose": "Reservoir tests (omega#440): Gate 1 simulator and readout checks against an independent binary64" }, { "digest": "39bb8b5bc5bb91af7db77cc15bcd326cdb083060f27077e9f60670cad9086a11", - "last_commit": "843424ce", + "last_commit": "843424cea", "name": "runtime", "purpose": "Directory tests/runtime. Purpose not yet described by a human." }, { "digest": "467652c09505ecbd82d96a5e0e7ea24b19d9216cfd1dad7c60fa8258e47594c0", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "searchtrace", "purpose": "Directory tests/searchtrace. Purpose not yet described by a human." }, { "digest": "e69616ad471704066a86bf2796776301179eada5c0aa36a7166b9aca788619f4", - "last_commit": "ed8de573", + "last_commit": "ed8de5736", "name": "synapse", "purpose": "J1 parity driver for syn_codec.osc against the sealed Rust A1 corpus (aien-dev/synapse j1-codec-" }, { "digest": "5c97916fbf20310eff2e502c526337cb093e912cb48f18d44b0345ed8a3c3240", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "train", "purpose": "Directory tests/train. Purpose not yet described by a human." }, { "digest": "7679bd1c49c7e89d8c26ccf8dfb91478f4e6e2f584745806fa8d26061dbdbb9c", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "turing", "purpose": "Directory tests/turing. Purpose not yet described by a human." }, { "digest": "003966bc697c6f85cfffbae00fae992a634bc386f4a44340daaa8ddcb5618ef6", - "last_commit": "d863780e", + "last_commit": "d863780eb", "name": "visor", "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], "children_root": "sha256:21fc25ed991f4066326a9270e13961ed8a45edc12064ce9e7846ab6782d5b72b", - "compiled_at": "2026-10-24T23:32:51Z", + "compiled_at": "2026-10-24T23:54:33Z", "compiler": "crumb-compile/1", - "digest": "sha256:8fa4874233c906929082e779408ae009b381ade4590b930a2faf68c60fd7e48f", + "digest": "sha256:87757530a28d4408bc4410fd8f922088f3e3f1cbc8987c5879e92ca59fe8728a", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1287, - "generated_at_commit": "79b2b6329d552350efc62eecce2b298afa53fc10", - "source_tree": "sha256:66aa30eb539fb8432bd7571a91659a1ae9a174746c98fb2eeda085a373778a65" + "files": 1288, + "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", + "source_tree": "sha256:cbf44d3eac6439851672ffdcf5046d84b972b1dbf2e29ca2fbfd420cbca74b83" }, "owner_lane": "", "provenance": { From 3a3d6b47be7159f1e82362d68186852e114ed8ea Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 21:19:16 -0500 Subject: [PATCH 06/10] C3: matrix multiply of any shape, BF16 (HMMA) and FP8 (QMMA), row/column-major A and B, on Omega's own codegen; bit-exact vs the chip tensor-core model in the simulator, three mutants caught The simulator's HMMA now honours operand subregisters (the encoder already adds them). Co-Authored-By: Claude Opus 5.5 --- Makefile | 12 + evidence/C3-GEMM/01-host-only.log | 41 ++++ evidence/C3-GEMM/02-sim.log | 53 +++++ evidence/C3-GEMM/README.md | 19 ++ src/omega_gpu_gemm.c | 368 ++++++++++++++++++++++++++++++ src/omega_gpu_gemm.h | 96 ++++++++ tests/bw_warp_sim_tc.h | 4 +- tests/gpu_gemm_test.c | 334 +++++++++++++++++++++++++++ 8 files changed, 925 insertions(+), 2 deletions(-) create mode 100644 evidence/C3-GEMM/01-host-only.log create mode 100644 evidence/C3-GEMM/02-sim.log create mode 100644 evidence/C3-GEMM/README.md create mode 100644 src/omega_gpu_gemm.c create mode 100644 src/omega_gpu_gemm.h create mode 100644 tests/gpu_gemm_test.c diff --git a/Makefile b/Makefile index a80ea0062..82593c8ec 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,8 @@ SRCS += src/omega_blackwell_codegen_gdn.c src/omega_gpu_gdn_api.c SRCS += src/omega_gpu_cmdlist.c src/omega_blackwell_codegen_dec.c # C3 (docs/OMEGA.md): reductions and prefix sums of any length, bit-exact against the frozen-order host reference. SRCS += src/omega_gpu_scan.c src/omega_gpu_scan_ref.c +# C3: matrix multiply of any shape, BF16 and FP8, both layouts, on the tensor cores (pack kernels + one multiply kernel). +SRCS += src/omega_gpu_gemm.c SRCS += src/omega_gpu_mem_cached.c SRCS += src/omega_gpu_decode_graph.c # sc #642 (2026-10-18): one Qwen3.8-27B decode token as one command list (GDN + hd256 attention layers, dense MLP) @@ -2698,3 +2700,13 @@ $(GPU_SCAN_TEST): tests/gpu_scan_test.c tests/bw_warp_sim.h src/omega_gpu_scan.h .PHONY: test-gpu-scan test-gpu-scan: $(GPU_SCAN_TEST) ./$(GPU_SCAN_TEST) --sim + +# C3 (docs/OMEGA.md): matrix multiply of any shape, BF16 and FP8 (e4m3), both layouts, on the tensor cores; bit-exact +# against the chip-measured tensor-core model. test-gpu-gemm: host refusals and codegen, then the warp simulator. +# The chip tier is "$(GPU_GEMM_TEST)" with no flag (>= 200 shapes up to 8192, speed vs the measured ceiling), under the GB10 lock. +GPU_GEMM_TEST = $(OUT_DIR)/gpu_gemm_test +$(GPU_GEMM_TEST): tests/gpu_gemm_test.c tests/bw_warp_sim_tc.h tests/bw_hmma_model.h tests/bw_qmma_model.h src/omega_gpu_gemm.h $(OUT_DIR)/libomega_gpu.a + $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +.PHONY: test-gpu-gemm +test-gpu-gemm: $(GPU_GEMM_TEST) + ./$(GPU_GEMM_TEST) --sim diff --git a/evidence/C3-GEMM/01-host-only.log b/evidence/C3-GEMM/01-host-only.log new file mode 100644 index 000000000..88aa39993 --- /dev/null +++ b/evidence/C3-GEMM/01-host-only.log @@ -0,0 +1,41 @@ +$ ./build/gpu_gemm_test --host-only (omega c3/gemm, 2026-10-22T02:19Z) +the bf16 model is a multiply (A row B row): worst error 3.81e-07 of the magnitude sum +the bf16 model is a multiply (A col B row): worst error 5.42e-07 of the magnitude sum +the bf16 model is a multiply (A row B col): worst error 5.77e-07 of the magnitude sum +the bf16 model is a multiply (A col B col): worst error 4.26e-07 of the magnitude sum +the e4m3 model is a multiply (A row B row): worst error 3.16e-07 of the magnitude sum +the e4m3 model is a multiply (A col B row): worst error 3.17e-07 of the magnitude sum +the e4m3 model is a multiply (A row B col): worst error 2.44e-07 of the magnitude sum +the e4m3 model is a multiply (A col B col): worst error 2.58e-07 of the magnitude sum +bf16 rt 2 ct 4 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 4 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 4 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 116 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 20 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 48 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 20 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 108 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 84 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 84 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 32, 116 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 4, 48 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 108 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 84 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 84 gprs +C3 gemm host: PASS (136 checks) +exit=0 diff --git a/evidence/C3-GEMM/02-sim.log b/evidence/C3-GEMM/02-sim.log new file mode 100644 index 000000000..a0045c8ce --- /dev/null +++ b/evidence/C3-GEMM/02-sim.log @@ -0,0 +1,53 @@ +$ ./build/gpu_gemm_test --sim (omega c3/gemm, 2026-10-22T02:19Z) +the bf16 model is a multiply (A row B row): worst error 3.81e-07 of the magnitude sum +the bf16 model is a multiply (A col B row): worst error 5.42e-07 of the magnitude sum +the bf16 model is a multiply (A row B col): worst error 5.77e-07 of the magnitude sum +the bf16 model is a multiply (A col B col): worst error 4.26e-07 of the magnitude sum +the e4m3 model is a multiply (A row B row): worst error 3.16e-07 of the magnitude sum +the e4m3 model is a multiply (A col B row): worst error 3.17e-07 of the magnitude sum +the e4m3 model is a multiply (A row B col): worst error 2.44e-07 of the magnitude sum +the e4m3 model is a multiply (A col B col): worst error 2.58e-07 of the magnitude sum +bf16 rt 2 ct 4 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 4 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 4 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 116 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 20 gprs +bf16 rt 1 ct 1 wm 1 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 48 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 20 gprs +bf16 rt 4 ct 1 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 108 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 1 ct 4 wm 4 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 84 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +bf16 rt 2 ct 2 wm 1 wn 4 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 0, 84 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 4 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 32, 116 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +e4m3 rt 1 ct 1 wm 1 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 4, 48 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 28 gprs +e4m3 rt 4 ct 1 wm 2 wn 2 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 108 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 1 ct 4 wm 4 wn 1 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 84 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs +e4m3 rt 2 ct 2 wm 1 wn 4 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 84 gprs +simulator bf16 rt 2 ct 4 wm 2 wn 2: 40 multiplies, 0 wrong +simulator bf16 rt 1 ct 1 wm 1 wn 1: 10 multiplies, 0 wrong +simulator bf16 rt 4 ct 1 wm 1 wn 4: 10 multiplies, 0 wrong +simulator e4m3 rt 2 ct 4 wm 2 wn 2: 40 multiplies, 0 wrong +simulator e4m3 rt 1 ct 1 wm 1 wn 1: 10 multiplies, 0 wrong +simulator e4m3 rt 4 ct 1 wm 1 wn 4: 10 multiplies, 0 wrong +simulator red check: bf16 mutant 1 is caught (4095 wrong) +simulator red check: bf16 mutant 2 is caught (4095 wrong) +simulator red check: bf16 mutant 3 is caught (4095 wrong) +simulator red check: e4m3 mutant 1 is caught (4095 wrong) +simulator red check: e4m3 mutant 2 is caught (4095 wrong) +simulator red check: e4m3 mutant 3 is caught (4095 wrong) +C3 gemm sim: PASS (154 checks) +exit=0 diff --git a/evidence/C3-GEMM/README.md b/evidence/C3-GEMM/README.md new file mode 100644 index 000000000..914362fa9 --- /dev/null +++ b/evidence/C3-GEMM/README.md @@ -0,0 +1,19 @@ +# C3 receipt, part 2: matrix multiply of any shape on the tensor cores + +Row C3 of `docs/OMEGA.md` asks for matrix multiply (GEMM) of any shape in BF16 and FP8, both layouts, at least 200 shapes +from 1 to 8192, correct, with speed as a fraction of the measured tensor-core ceiling. The kernels come from Omega's own +code generator (`src/omega_gpu_gemm.c`), no CUDA: two pack kernels put A and B (row- or column-major) into the tensor +cores' order with zeros past the edges, one multiply kernel runs the tensor cores (HMMA for BF16, QMMA for FP8). + +"Correct" here is bit for bit: the reference is a host model of the same tensor-core steps whose rounding was measured +on this chip (`tests/bw_hmma_model.h`, `tests/bw_qmma_model.h`, both exact on 262,144 of 262,144 chip outputs), and a +separate check shows that model stays within one part in a million of the exact product. + +| Log | What it checks | Result | +|---|---|---| +| 01-host-only | bad calls refused, tile shapes past the register budget refused; every kernel (both types, five tile shapes, each planted fault) through our code generator and encoder; the model against exact double-precision sums | PASS, 136 checks | +| 02-sim | the real kernels in the warp simulator (tensor-core ops computed with the chip models): ten shapes over every edge, all four layouts, three tile shapes, both types, every output compared; three planted faults (a dropped k step, no zeros past the edges, swapped columns) each caught on all 4,095 outputs | PASS, 146 checks | +| (next) chip | 208 shapes up to 8192, both types, all four layouts; speed against 115.36 TFLOPS (BF16) and 237.52 TFLOPS (FP8) | waiting for a chip window | + +Command: `make test-gpu-gemm` (host and simulator). The chip run is `build/gpu_gemm_test` with no flag, under the GB10 lock. +This is the general kernel; the prefill-roof lane (L403) tunes it toward the ceiling. diff --git a/src/omega_gpu_gemm.c b/src/omega_gpu_gemm.c new file mode 100644 index 000000000..5bb4d186d --- /dev/null +++ b/src/omega_gpu_gemm.c @@ -0,0 +1,368 @@ +/* omega_gpu_gemm.c -- matrix multiply of any shape on the GB10 tensor cores (C3). See the header. */ +#include "omega_gpu_gemm.h" +#include "omega_bw_em.h" +#include "omega_bw_em_q.h" +#include "omega_gpu_session.h" + +#include +#include + +#define POISON 0x7fa00badu /* a signalling NaN no tensor-core op writes: a word still holding it was never stored */ +#define TIMEOUT_MS 60000ull +#define FRAG 512u /* bytes of one warp fragment: 32 lanes x 16 */ + +static uint32_t esz(OmegaGpuGemmType t) { return t == OMEGA_GPU_GEMM_BF16 ? 2u : 1u; } +static uint32_t kstep(OmegaGpuGemmType t) { return t == OMEGA_GPU_GEMM_BF16 ? 16u : 32u; } +static int pow124(uint32_t v) { return v == 1u || v == 2u || v == 4u; } + +void omega_gpu_gemm_default_cfg(OmegaGpuGemmType type, OmegaGemmCfg *cfg) { + memset(cfg, 0, sizeof *cfg); + cfg->type = type; cfg->rt = 2; cfg->ct = 4; cfg->wm = 2; cfg->wn = 2; cfg->stall = type == OMEGA_GPU_GEMM_BF16 ? 4u : 2u; +} + +int omega_gpu_gemm_cfg_ok(const OmegaGemmCfg *c) { + return c && (c->type == OMEGA_GPU_GEMM_BF16 || c->type == OMEGA_GPU_GEMM_E4M3) && pow124(c->rt) && pow124(c->ct) && + pow124(c->wm) && pow124(c->wn) && c->stall >= 1u && c->stall <= 15u && c->mutant >= 0 && c->mutant <= 3 && + 4u * (4u * c->rt + 2u * c->ct + c->rt * c->ct) <= 100u; /* registers: two operand sets + accumulators, R2..R127 in all */ +} + +/* ------------------------------------------------------------------ IR helpers */ + +typedef struct { int bssy, bra; } Region; +static Region skip_if_p0(Em *e) { Region r; r.bssy = bssy_fwd(e); r.bra = bra_if_p0_fwd(e); return r; } +static void region_end(Em *e, Region r) { int at = here(e); bsync(e); patch_bra(e, r.bra, at); patch_bra(e, r.bssy, at + 1); } +/* d = a - b */ +static void isub(Em *e, int d, int a, int b) { imadi(e, d, b, 0, 0xffffffffu, a); } +/* d = 1 when a < b (both below 2^31), else 0 */ +static void lt_bit(Em *e, int d, int a, int b) { isub(e, d, a, b); shr(e, d, d, 0, 31); } +static void and_r(Em *e, int d, int a, int b) { lop3(e, d, a, b, NOREG, 0xc0u); } +/* tensor-core op d = a * b[bsub..bsub+1] + c */ +static void mma(Em *e, int fp8, int d, int a, int b, unsigned bsub, int c, uint32_t stall) { + BlackwellIRInsn i = I0(BW_IR_HMMA_BF16); + i.dst_vreg = d; i.src1_vreg = a; i.src2_vreg = b; i.src2_subreg = (uint8_t)bsub; i.src3_vreg = c; + if (fp8) i.imm = OMEGA_QMMA_MARK; + i.control = CW(stall, SB_NONE, SB_NONE, e->pending); e->pending = 0; + if (omega_bw_ir_append(e->p, &i) < 0) e->err = -1; +} + +/* ------------------------------------------------------------------ PACK_A / PACK_B + * CTA (pair cx, row group cy), 128 threads; thread tid writes word tid of each of the F fragments of the block: + * lane L = tid / 4, register q = tid % 4, g = L / 4, t = L % 4, r = elements per register (2 bf16, 4 e4m3). + * A fragment f = u * rt + i: row 16 (rt cy + i) + g + 8 (q & 1), k = 2 step cx + step u + r t + 4 r (q >> 1) + * B fragment f = j: row 8 (ct cy + j) + g, k = 2 step cx + step (q >> 1) + r t + 4 r (q & 1) + * Element (row, k) of the source is at (row * row_stride + k * k_stride) * esz; past rows or kdim it is 0. */ +static int gen_pack(Em *e, const OmegaGemmCfg *c, int isb) { + const int fp8 = c->type == OMEGA_GPU_GEMM_E4M3; + const uint32_t ks = kstep(c->type), r = 4u / esz(c->type), F = isb ? c->ct : 2u * c->rt; + int udesc = UV64(e), psrc = V64(e), pdst = V64(e), R = V(e), Kd = V(e), sr = V(e), sk = V(e), ks2 = V(e); + int tid = V(e), cx = V(e), cy = V(e), one = V(e), g = V(e), t = V(e), qa = V(e), qb = V(e), row0 = V(e), k0 = V(e); + int tmp = V(e), pd = V64(e), row = V(e), vrow = V(e), rowoff = V(e), kx = V(e), v = V(e), off = V(e), word = V(e); + int addr[4], val[4], mask[4], odd[4]; + for (unsigned x = 0; x < 4; x++) { addr[x] = V64(e); val[x] = V(e); mask[x] = V(e); odd[x] = V(e); } + if (e->err) return -1; + ldcu64(e, udesc, 0x358); + ldc64(e, psrc, 0x380); ldc64(e, pdst, 0x388); + ldc32(e, R, 0x390); ldc32(e, Kd, 0x394); ldc32(e, sr, 0x398); ldc32(e, sk, 0x39c); ldc32(e, ks2, 0x3a0); + 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); + shr(e, g, tid, 0, 4); + shr(e, t, tid, 0, 2); andi(e, t, t, 0, 3); + andi(e, qa, tid, 0, 1); + shr(e, qb, tid, 0, 1); andi(e, qb, qb, 0, 1); + if (!isb) { + imadi(e, row0, cy, 0, 16u * c->rt, g); imadi(e, row0, qa, 0, 8u, row0); + imadi(e, k0, cx, 0, 2u * ks, NOREG); imadi(e, k0, t, 0, r, k0); imadi(e, k0, qb, 0, 4u * r, k0); + } else { + imadi(e, row0, cy, 0, 8u * c->ct, g); + imadi(e, k0, cx, 0, 2u * ks, NOREG); imadi(e, k0, t, 0, r, k0); imadi(e, k0, qb, 0, ks, k0); imadi(e, k0, qa, 0, 4u * r, k0); + } + /* this thread's word of fragment 0: ((cy * KS2 + cx) * F * 128 + tid) words */ + imadr(e, tmp, cy, ks2, cx); imadi(e, tmp, tmp, 0, F * 128u, tid); imadw(e, pd, tmp, 4u, pdst); + for (uint32_t f = 0; f < F; f++) { + const uint32_t drow = isb ? 8u * f : 16u * (f % c->rt), dk = isb ? 0u : ks * (f / c->rt); + imadi(e, row, one, 0, drow, row0); + lt_bit(e, vrow, row, R); + imadr(e, rowoff, row, sr, NOREG); + for (uint32_t x = 0; x < r; x++) { + imadi(e, kx, one, 0, dk + x, k0); + lt_bit(e, v, kx, Kd); + and_r(e, v, v, vrow); + imadr(e, off, kx, sk, rowoff); + imadr(e, off, off, v, NOREG); /* outside: element 0, always readable, then masked */ + if (c->mutant == 2) movi(e, mask[x], 0xffffffffu); /* the red check: element 0 leaks in past the edges */ + else imadi(e, mask[x], v, 0, 0xffffffffu, NOREG); + if (fp8) { andi(e, odd[x], off, 0, 1u); andi(e, off, off, 0, 0xfffffffeu); imadw(e, addr[x], off, 1u, psrc); } + else imadw(e, addr[x], off, 2u, psrc); + } + for (uint32_t x = 0; x < r; x++) ldg_wide(e, BW_IR_LDG_E_U16, val[x], addr[x], 0, udesc, x == 0); + for (uint32_t x = 0; x < r; x++) { + if (fp8) { /* the byte at off: low or high half of the u16 */ + andi(e, kx, val[x], 0, 0xffu); + shr(e, v, val[x], 0, 8); andi(e, v, v, 0, 0xffu); + isub(e, v, v, kx); + imadr(e, val[x], v, odd[x], kx); + } + and_r(e, val[x], val[x], mask[x]); + } + imadi(e, word, val[0], 0, 1u, NOREG); + for (uint32_t x = 1; x < r; x++) imadi(e, word, val[x], 0, 1u << (x * (32u / r)), word); + stg(e, pd, f * FRAG, word, udesc); + } + tail(e); + return e->err; +} + +/* ------------------------------------------------------------------ MAIN */ +static int gen_main(Em *e, const OmegaGemmCfg *c) { + const int fp8 = c->type == OMEGA_GPU_GEMM_E4M3; + const uint32_t RT = c->rt, CT = c->ct, FA = 2u * RT, FB = CT; + int udesc = UV64(e), pa = V64(e), pb = V64(e), pc = V64(e), M = V(e), N = V(e), ks2 = V(e); + int tid = V(e), cx = V(e), cy = V(e), warp = V(e), lane = V(e), g = V(e), t = V(e), one = V(e), zr = V(e); + int rga = V(e), rgb = V(e), tmp = V(e), cnt = V(e); + int acc[16], as[2][8], bs[2][4]; + for (uint32_t x = 0; x < RT * CT; x++) acc[x] = V128(e); + for (unsigned s = 0; s < 2; s++) { for (uint32_t f = 0; f < FA; f++) as[s][f] = V128(e); for (uint32_t j = 0; j < FB; j++) bs[s][j] = V128(e); } + if (e->err) return -1; + ldcu64(e, udesc, 0x358); + ldc64(e, pa, 0x380); ldc64(e, pb, 0x388); ldc64(e, pc, 0x390); + ldc32(e, M, 0x398); ldc32(e, N, 0x39c); ldc32(e, ks2, 0x3a0); + 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); movrz(e, zr); + shr(e, warp, tid, 0, 5); andi(e, lane, tid, 0, 31u); + /* warp (wm, wn) = (warp / WN, warp % WN); row groups rga = cy WM + wm, rgb = cx WN + wn */ + shr(e, tmp, warp, 0, (uint32_t)log2u(c->wn)); imadi(e, rga, cy, 0, c->wm, tmp); + andi(e, tmp, warp, 0, c->wn - 1u); imadi(e, rgb, cx, 0, c->wn, tmp); + imadr(e, tmp, rga, ks2, NOREG); imadw(e, pa, tmp, FA * FRAG, pa); + imadr(e, tmp, rgb, ks2, NOREG); imadw(e, pb, tmp, FB * FRAG, pb); + imadi(e, tmp, lane, 0, 16u, NOREG); imadw(e, pa, tmp, 1u, pa); imadw(e, pb, tmp, 1u, pb); + for (uint32_t x = 0; x < RT * CT; x++) for (unsigned q = 0; q < 4; q++) { BlackwellIRInsn mz = I0(BW_IR_MOV_RZ); mz.dst_vreg = acc[x]; mz.dst_subreg = (uint8_t)q; emit(e, mz, K_FIXED); } + shr(e, cnt, ks2, 0, 1); /* loop iterations: two k pairs each */ + + #define ISSUE(s, sb) do { \ + for (uint32_t f = 0; f < FA; f++) ldw_pf(e, BW_IR_LDG_E_128, as[s][f], pa, f * FRAG, udesc, (sb)); \ + for (uint32_t j = 0; j < FB; j++) ldw_pf(e, BW_IR_LDG_E_128, bs[s][j], pb, j * FRAG, udesc, (sb)); \ + imadw(e, pa, one, FA * FRAG, pa); imadw(e, pb, one, FB * FRAG, pb); } while (0) + #define COMPUTE(s) do { \ + for (uint32_t u = 0; u < 2; u++) { \ + if (c->mutant == 1 && u == 1) break; \ + for (uint32_t i = 0; i < RT; i++) for (uint32_t j = 0; j < CT; j++) \ + mma(e, fp8, acc[i * CT + j], as[s][u * RT + i], bs[s][j], 2u * u, acc[i * CT + j], c->stall); } } while (0) + + ISSUE(0, 3u); + const int top = here(e); + loop_begin(e); + ISSUE(1, 4u); + consume(e, 3); + COMPUTE(0); + nop(e, 15); /* the tensor ops have read set 0 before it is reloaded */ + ISSUE(0, 3u); /* the last iteration reads one pair past the end: slack */ + consume(e, 4); + COMPUTE(1); + nop(e, 15); + imadi(e, cnt, one, 0, 0xffffffffu, cnt); + isetp_ge_u32(e, cnt, one); + bra_if_p0(e, top); + loop_end(e); + #undef ISSUE + #undef COMPUTE + consume(e, 3); + nop(e, 15); nop(e, 15); nop(e, 15); nop(e, 15); /* the last results settle before the stores read them */ + + /* stores: C[m][n] for m = 16 (RT rga + i) + 8 h + g, n = 8 (CT rgb + j) + 2 t + cc, when m < M and n < N */ + int mb = V(e), nb = V(e), m = V(e), n = V(e), vm = V(e), vn = V(e), rowoff = V(e), ca = V64(e); + if (e->err) return -1; + shr(e, g, lane, 0, 2); andi(e, t, lane, 0, 3u); + imadi(e, mb, rga, 0, 16u * RT, g); + imadi(e, tmp, t, 0, 2u, NOREG); imadi(e, nb, rgb, 0, 8u * CT, tmp); + for (uint32_t i = 0; i < RT; i++) for (uint32_t h = 0; h < 2; h++) { + imadi(e, m, one, 0, 16u * i + 8u * h, mb); + lt_bit(e, vm, m, M); + imadr(e, rowoff, m, N, NOREG); + for (uint32_t j = 0; j < CT; j++) for (uint32_t cc = 0; cc < 2; cc++) { + imadi(e, n, one, 0, 8u * j + cc, nb); + lt_bit(e, vn, n, N); + and_r(e, vn, vn, vm); + isetp_ge_u32(e, zr, vn); /* P0: 0 >= ok, i.e. outside: skip */ + Region rg = skip_if_p0(e); + iadd(e, tmp, rowoff, n); imadw(e, ca, tmp, 4u, pc); + BlackwellIRInsn st = I0(BW_IR_STG_E); st.src1_vreg = ca; st.src2_vreg = acc[i * CT + j]; + st.src2_subreg = (uint8_t)(2u * h + (c->mutant == 3 ? 1u - cc : cc)); st.ureg = udesc; emit(e, st, K_STORE); + region_end(e, rg); + } + } + tail(e); + return e->err; +} + +int omega_gpu_gemm_codegen(const OmegaGemmCfg *cfg, OmegaGemmKind kind, BlackwellIRProgram *prog) { + if (!omega_gpu_gemm_cfg_ok(cfg) || !prog || (unsigned)kind >= OMEGA_GEMM_K_COUNT) return -1; + omega_bw_ir_init(prog); + Em em; memset(&em, 0, sizeof em); em.p = prog; + int rc = kind == OMEGA_GEMM_K_MAIN ? gen_main(&em, cfg) : gen_pack(&em, cfg, kind == OMEGA_GEMM_K_PACK_B); + if (rc != 0 || em.err || em.depth != 0) return -1; + return omega_bw_regalloc_solve(prog); +} + +/* ------------------------------------------------------------------ plan and driver */ + +static uint32_t roundup(uint32_t v, uint32_t m) { return (v + m - 1u) / m * m; } + +int omega_gpu_gemm_plan(const OmegaGemmCfg *c, uint32_t M, uint32_t N, uint32_t K, OmegaGemmPlan *p) { + if (!omega_gpu_gemm_cfg_ok(c) || !p || !M || !N || !K) return OMEGA_GPU_GEMM_BAD_ARGS; + if (M > OMEGA_GPU_GEMM_MAX_DIM || N > OMEGA_GPU_GEMM_MAX_DIM || K > OMEGA_GPU_GEMM_MAX_DIM) return OMEGA_GPU_GEMM_TOO_LARGE; + memset(p, 0, sizeof *p); + const uint32_t ks = kstep(c->type), ga = 16u * c->rt, gb = 8u * c->ct, FA = 2u * c->rt, FB = c->ct; + p->Mp = roundup(M, ga * c->wm); p->Np = roundup(N, gb * c->wn); p->Kp = roundup(K, 4u * ks); + p->KS2 = p->Kp / (2u * ks); + p->a_bytes = (uint64_t)M * K * esz(c->type); p->b_bytes = (uint64_t)K * N * esz(c->type); + p->ap_bytes = (uint64_t)(p->Mp / ga) * p->KS2 * FA * FRAG + 2u * FA * FRAG; + p->bp_bytes = (uint64_t)(p->Np / gb) * p->KS2 * FB * FRAG + 2u * FB * FRAG; + p->grid[OMEGA_GEMM_K_PACK_A][0] = p->KS2; p->grid[OMEGA_GEMM_K_PACK_A][1] = p->Mp / ga; + p->grid[OMEGA_GEMM_K_PACK_B][0] = p->KS2; p->grid[OMEGA_GEMM_K_PACK_B][1] = p->Np / gb; + p->grid[OMEGA_GEMM_K_MAIN][0] = p->Np / (gb * c->wn); p->grid[OMEGA_GEMM_K_MAIN][1] = p->Mp / (ga * c->wm); + p->threads[OMEGA_GEMM_K_PACK_A] = p->threads[OMEGA_GEMM_K_PACK_B] = 128u; + p->threads[OMEGA_GEMM_K_MAIN] = 32u * c->wm * c->wn; + return OMEGA_GPU_GEMM_OK; +} + +static void put64(uint32_t *a, unsigned w, uint64_t v) { a[w] = (uint32_t)v; a[w + 1] = (uint32_t)(v >> 32); } + +int omega_gpu_gemm_drive(const OmegaGemmCfg *c, unsigned layout, uint32_t M, uint32_t N, uint32_t K, uint64_t a_va, + uint64_t b_va, uint64_t ap_va, uint64_t bp_va, uint64_t c_va, OmegaGemmLaunchFn launch, void *ctx) { + if (!launch || (layout & ~3u)) return OMEGA_GPU_GEMM_BAD_ARGS; + OmegaGemmPlan p; + int rc = omega_gpu_gemm_plan(c, M, N, K, &p); + if (rc != OMEGA_GPU_GEMM_OK) return rc; + uint32_t a[OMEGA_GPU_GEMM_ARGS_WORDS]; + /* A element (m, k): row-major m K + k, column-major k M + m */ + memset(a, 0, sizeof a); + put64(a, 0, a_va); put64(a, 2, ap_va); a[4] = M; a[5] = K; + a[6] = layout & OMEGA_GPU_GEMM_A_COL ? 1u : K; a[7] = layout & OMEGA_GPU_GEMM_A_COL ? M : 1u; a[8] = p.KS2; + if (launch(ctx, OMEGA_GEMM_K_PACK_A, a, p.grid[0][0], p.grid[0][1], p.threads[0]) != 0) return OMEGA_GPU_GEMM_CHIP_FAIL; + /* B element (k, n) as packed row n: row-major k N + n, column-major n K + k */ + memset(a, 0, sizeof a); + put64(a, 0, b_va); put64(a, 2, bp_va); a[4] = N; a[5] = K; + a[6] = layout & OMEGA_GPU_GEMM_B_COL ? K : 1u; a[7] = layout & OMEGA_GPU_GEMM_B_COL ? 1u : N; a[8] = p.KS2; + if (launch(ctx, OMEGA_GEMM_K_PACK_B, a, p.grid[1][0], p.grid[1][1], p.threads[1]) != 0) return OMEGA_GPU_GEMM_CHIP_FAIL; + memset(a, 0, sizeof a); + put64(a, 0, ap_va); put64(a, 2, bp_va); put64(a, 4, c_va); a[6] = M; a[7] = N; a[8] = p.KS2; + if (launch(ctx, OMEGA_GEMM_K_MAIN, a, p.grid[2][0], p.grid[2][1], p.threads[2]) != 0) return OMEGA_GPU_GEMM_CHIP_FAIL; + return OMEGA_GPU_GEMM_OK; +} + +/* ------------------------------------------------------------------ the chip */ + +static struct { + int set[2]; + OmegaGemmCfg cfg[2]; + OmegaGpuMem code[2][OMEGA_GEMM_K_COUNT]; + uint32_t gpr[2][OMEGA_GEMM_K_COUNT]; +} g; + +static const OmegaGemmCfg *cfg_of(OmegaGpuGemmType t) { + if (!g.set[t]) { omega_gpu_gemm_default_cfg(t, &g.cfg[t]); g.set[t] = 1; } + return &g.cfg[t]; +} + +int omega_gpu_gemm_test_set_cfg(OmegaGpuGemmType type, const OmegaGemmCfg *cfg) { + if ((unsigned)type > OMEGA_GPU_GEMM_E4M3 || (cfg && (!omega_gpu_gemm_cfg_ok(cfg) || cfg->type != type))) return OMEGA_GPU_GEMM_BAD_ARGS; + omega_gpu_session_lock(); + for (unsigned k = 0; k < OMEGA_GEMM_K_COUNT; k++) if (g.code[type][k].cpu) omega_gpu_session_free(&g.code[type][k]); + memset(g.code[type], 0, sizeof g.code[type]); + if (cfg) g.cfg[type] = *cfg; else omega_gpu_gemm_default_cfg(type, &g.cfg[type]); + g.set[type] = 1; + omega_gpu_session_unlock(); + return OMEGA_GPU_GEMM_OK; +} + +const char *omega_gpu_gemm_rc_name(int rc) { + switch (rc) { + case OMEGA_GPU_GEMM_OK: return "OK"; + case OMEGA_GPU_GEMM_BAD_ARGS: return "BAD_ARGS"; + case OMEGA_GPU_GEMM_TOO_LARGE: return "TOO_LARGE"; + case OMEGA_GPU_GEMM_CODEGEN_FAIL: return "CODEGEN_FAIL"; + case OMEGA_GPU_GEMM_CHIP_FAIL: return "CHIP_FAIL"; + default: return "?"; + } +} + +/* lock held */ +static int kernel_locked(OmegaGpuGemmType t, OmegaGemmKind k) { + if (g.code[t][k].cpu) return OMEGA_GPU_GEMM_OK; + BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); + if (!prog) return OMEGA_GPU_GEMM_CODEGEN_FAIL; + int rc = OMEGA_GPU_GEMM_OK; + size_t need = 0; + if (omega_gpu_gemm_codegen(cfg_of(t), k, prog) != 0 || (need = omega_bw_program_code_bytes(prog)) == 0) rc = OMEGA_GPU_GEMM_CODEGEN_FAIL; + else if (omega_gpu_session_alloc_code(need, &g.code[t][k]) != 0) rc = OMEGA_GPU_GEMM_CHIP_FAIL; + else { + OmegaBlackwellKernel kk; + if (omega_blackwell_kernel_encode_into(prog, g.code[t][k].cpu, need, &kk) != 0 || kk.code_size != need || + omega_qmma_patch_code(prog, g.code[t][k].cpu, need) < 0) rc = OMEGA_GPU_GEMM_CODEGEN_FAIL; + else if ((g.gpr[t][k] = omega_bw_gpr_declared(kk.gpr_count)) > 255u) rc = OMEGA_GPU_GEMM_CODEGEN_FAIL; + else if (omega_gpu_session_sync_to_gpu(&g.code[t][k]) != 0) rc = OMEGA_GPU_GEMM_CHIP_FAIL; + if (g.gpr[t][k] < 64u) g.gpr[t][k] = 64u; + if (rc != OMEGA_GPU_GEMM_OK) { omega_gpu_session_free(&g.code[t][k]); memset(&g.code[t][k], 0, sizeof g.code[t][k]); } + } + if (rc == OMEGA_GPU_GEMM_CODEGEN_FAIL) omega_gpu_session_set_error("gemm: our codegen refused a kernel"); + omega_gpu_host_free(prog); + return rc; +} + +typedef struct { OmegaGpuGemmType t; uint64_t pack_ns, main_ns; } ChipCtx; + +/* lock held */ +static int chip_launch(void *ctx, OmegaGemmKind k, const uint32_t args[OMEGA_GPU_GEMM_ARGS_WORDS], uint32_t gx, uint32_t gy, uint32_t threads) { + ChipCtx *c = ctx; + if (kernel_locked(c->t, k) != OMEGA_GPU_GEMM_OK) return -1; + OmegaGpuLaunch L = { + .code_va = g.code[c->t][k].va, .gpr_count = g.gpr[c->t][k], .threads_x = threads, .threads_y = 1, + .grid_x = gx, .grid_y = gy, .num_elements = (size_t)gx * gy * threads, + .args = args, .n_args = OMEGA_GPU_GEMM_ARGS_WORDS, .timeout_ms = TIMEOUT_MS, + }; + uint64_t ns = 0; + if (omega_gpu_session_launch(&L, &ns, NULL) != 0) return -1; + if (k == OMEGA_GEMM_K_MAIN) c->main_ns += ns; else c->pack_ns += ns; + return 0; +} + +static uint64_t up16(uint64_t v) { return (v + 255u) & ~(uint64_t)255u; } + +int omega_gpu_gemm(OmegaGpuGemmType type, unsigned layout, uint32_t M, uint32_t N, uint32_t K, const void *A, const void *B, + float *C, OmegaGpuGemmInfo *info) { + uint64_t t0 = omega_gpu_session_now_ns(); + if (info) memset(info, 0, sizeof *info); + if ((unsigned)type > OMEGA_GPU_GEMM_E4M3 || (layout & ~3u) || !A || !B || !C) return OMEGA_GPU_GEMM_BAD_ARGS; + omega_gpu_session_lock(); + const OmegaGemmCfg *cfg = cfg_of(type); + OmegaGemmPlan p; + int rc = omega_gpu_gemm_plan(cfg, M, N, K, &p); + if (rc != OMEGA_GPU_GEMM_OK) { omega_gpu_session_unlock(); return rc; } + /* one buffer: A | B | packed A | packed B | C (each 256-byte aligned; A and B carry 16 bytes of readable slack) */ + const uint64_t oa = 0, ob = up16(p.a_bytes + 16u), oap = ob + up16(p.b_bytes + 16u), obp = oap + up16(p.ap_bytes), + oc = obp + up16(p.bp_bytes), total = oc + (uint64_t)M * N * 4u; + OmegaGpuMem m; + if (!omega_gpu_session_open() || omega_gpu_session_alloc(total, &m) != 0) { omega_gpu_session_unlock(); return OMEGA_GPU_GEMM_CHIP_FAIL; } + uint8_t *base = m.cpu; + memcpy(base + oa, A, p.a_bytes); memcpy(base + ob, B, p.b_bytes); + uint32_t *cw = (uint32_t *)(base + oc); + for (uint64_t i = 0; i < (uint64_t)M * N; i++) cw[i] = POISON; + ChipCtx cc = { type, 0, 0 }; + if (omega_gpu_session_sync_to_gpu(&m) != 0) rc = OMEGA_GPU_GEMM_CHIP_FAIL; + else rc = omega_gpu_gemm_drive(cfg, layout, M, N, K, m.va + oa, m.va + ob, m.va + oap, m.va + obp, m.va + oc, chip_launch, &cc); + if (rc == OMEGA_GPU_GEMM_OK && omega_gpu_session_sync_to_cpu(&m) != 0) rc = OMEGA_GPU_GEMM_CHIP_FAIL; + if (rc == OMEGA_GPU_GEMM_OK) { + uint64_t unwritten = 0; + for (uint64_t i = 0; i < (uint64_t)M * N; i++) unwritten += cw[i] == POISON; + if (unwritten) { omega_gpu_session_set_error("gemm: output words never written"); rc = OMEGA_GPU_GEMM_CHIP_FAIL; } + else memcpy(C, cw, (size_t)M * N * 4u); + } + if (info) { + info->pack_ns = cc.pack_ns; info->main_ns = cc.main_ns; + for (unsigned k = 0; k < OMEGA_GEMM_K_COUNT; k++) info->gpr[k] = g.gpr[type][k]; + } + omega_gpu_session_free(&m); + omega_gpu_session_unlock(); + if (info) info->call_ns = omega_gpu_session_now_ns() - t0; + return rc; +} diff --git a/src/omega_gpu_gemm.h b/src/omega_gpu_gemm.h new file mode 100644 index 000000000..66a6b0485 --- /dev/null +++ b/src/omega_gpu_gemm.h @@ -0,0 +1,96 @@ +/* omega_gpu_gemm.h -- matrix multiply of any shape on the GB10 tensor cores (row C3 of docs/OMEGA.md). + * + * C = A * B A is M x K, B is K x N, C is M x N f32 (row-major), every M, N, K from 1 to OMEGA_GPU_GEMM_MAX_DIM + * BF16: A and B hold bf16 values, the product runs on HMMA.16816.F32.BF16 + * E4M3: A and B hold FP8 e4m3 bytes, the product runs on QMMA.16832.F32.E4M3.E4M3 + * Layouts: A row-major (M rows of K) or column-major (K rows of M); B row-major (K rows of N) or column-major (N rows of K). + * + * The arithmetic is fixed by the shape alone: every C[m][n] starts at +0 and takes one tensor-core step per 16 (BF16) or + * 32 (E4M3) values of k, in increasing k, k past K counting as zero. The rounding of one step is the chip-measured model + * (tests/bw_hmma_model.h { 16, 2, RZ, 2, 0 }, tests/bw_qmma_model.h { 32, 26, RZ, 2, 0 }), so a host model of the same + * steps reproduces the chip bit for bit (tests/gpu_gemm_test.c). + * + * Kernels, all from Omega's own code generator (no CUDA): + * PACK_A, PACK_B copy A and B, whatever their layout, into the tensor cores' fragment order (each lane's operand + * registers are 16 contiguous bytes; a warp's fragment is 512 contiguous bytes), zero past the edges. + * MAIN each warp computes a 16 rt x 8 ct block of C from the packed operands (LDG.128 straight into the + * operand registers, two register sets so the next loads fly while the tensor cores work), a CTA holds + * wm x wn warps; edge elements past M or N are not stored. + * Packed operand layout (bytes): block (row group, k pair) at ((group * KS2 + pair) * F + f) * 512, lane L at + 16 L, where + * a k pair is two tensor-core steps, KS2 = Kp / (2 * step), F = 2 rt (A: f = u * rt + i, step u of the pair, row tile i) + * or ct (B: f = column tile j; registers 0, 1 step 0 and 2, 3 step 1). */ +#ifndef OMEGA_GPU_GEMM_H +#define OMEGA_GPU_GEMM_H + +#include +#include +#include "omega_blackwell_codegen.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OMEGA_GPU_GEMM_MAX_DIM 16384u + +enum { + OMEGA_GPU_GEMM_OK = 0, + OMEGA_GPU_GEMM_BAD_ARGS = -1, /* NULL pointer, a zero dimension, unknown type or layout bits, a bad configuration */ + OMEGA_GPU_GEMM_TOO_LARGE = -2, /* a dimension past OMEGA_GPU_GEMM_MAX_DIM */ + OMEGA_GPU_GEMM_CODEGEN_FAIL = -3, /* our codegen refused a kernel */ + OMEGA_GPU_GEMM_CHIP_FAIL = -4 /* device, allocation, launch, or an output word the chip never wrote */ +}; + +typedef enum { OMEGA_GPU_GEMM_BF16 = 0, OMEGA_GPU_GEMM_E4M3 = 1 } OmegaGpuGemmType; +#define OMEGA_GPU_GEMM_A_COL 1u /* A is column-major: K rows of M */ +#define OMEGA_GPU_GEMM_B_COL 2u /* B is column-major: N rows of K */ + +typedef enum { OMEGA_GEMM_K_PACK_A = 0, OMEGA_GEMM_K_PACK_B, OMEGA_GEMM_K_MAIN, OMEGA_GEMM_K_COUNT } OmegaGemmKind; + +/* rt row tiles of 16 and ct column tiles of 8 per warp (1, 2 or 4 each), wm x wn warps per CTA (1, 2 or 4 each), + * with 4 (4 rt + 2 ct + rt ct) <= 100 (the registers of two operand sets and the accumulators; rt 2 ct 4 is the largest), + * stall: issue cycles after each tensor-core op (1 .. 15). + * mutant (red checks): 1 MAIN drops the second step of every k pair, 2 the packs let element 0 in past the edges (instead of zero), + * 3 MAIN stores each column pair swapped. */ +typedef struct { OmegaGpuGemmType type; uint32_t rt, ct, wm, wn, stall; int mutant; } OmegaGemmCfg; +void omega_gpu_gemm_default_cfg(OmegaGpuGemmType type, OmegaGemmCfg *cfg); +int omega_gpu_gemm_cfg_ok(const OmegaGemmCfg *cfg); + +/* Argument words (constant bank 0x380). Packs: src u64, dst u64, rows, kdim, row stride, k stride (elements), KS2. + * MAIN: packed A u64, packed B u64, C u64, M, N, KS2. */ +#define OMEGA_GPU_GEMM_ARGS_WORDS 9u +int omega_gpu_gemm_codegen(const OmegaGemmCfg *cfg, OmegaGemmKind kind, BlackwellIRProgram *prog); + +typedef struct { + uint32_t Mp, Np, Kp, KS2; /* padded sizes; KS2 k pairs (even) */ + uint64_t a_bytes, b_bytes; /* the inputs as given */ + uint64_t ap_bytes, bp_bytes; /* the packed operands, slack for the last prefetch included */ + uint32_t grid[OMEGA_GEMM_K_COUNT][2]; + uint32_t threads[OMEGA_GEMM_K_COUNT]; +} OmegaGemmPlan; +int omega_gpu_gemm_plan(const OmegaGemmCfg *cfg, uint32_t M, uint32_t N, uint32_t K, OmegaGemmPlan *plan); + +/* Runs the three kernels through a launch callback (the chip, or the warp simulator in the test). Device addresses + * are plain numbers. */ +typedef int (*OmegaGemmLaunchFn)(void *ctx, OmegaGemmKind kind, const uint32_t args[OMEGA_GPU_GEMM_ARGS_WORDS], + uint32_t grid_x, uint32_t grid_y, uint32_t threads); +int omega_gpu_gemm_drive(const OmegaGemmCfg *cfg, unsigned layout, uint32_t M, uint32_t N, uint32_t K, uint64_t a_va, + uint64_t b_va, uint64_t ap_va, uint64_t bp_va, uint64_t c_va, OmegaGemmLaunchFn launch, void *ctx); + +typedef struct { + uint64_t pack_ns; /* the two pack kernels, launch to completion */ + uint64_t main_ns; /* the multiply kernel */ + uint64_t call_ns; /* the whole call, uploads and readback included */ + uint32_t gpr[OMEGA_GEMM_K_COUNT]; +} OmegaGpuGemmInfo; + +/* On the chip, with the configuration set by omega_gpu_gemm_test_set_cfg (default: omega_gpu_gemm_default_cfg). */ +int omega_gpu_gemm(OmegaGpuGemmType type, unsigned layout, uint32_t M, uint32_t N, uint32_t K, const void *A, const void *B, + float *C, OmegaGpuGemmInfo *info); +/* Tests and tuning: later calls of that type use cfg (NULL: back to the default); clears the kernel cache. */ +int omega_gpu_gemm_test_set_cfg(OmegaGpuGemmType type, const OmegaGemmCfg *cfg); +const char *omega_gpu_gemm_rc_name(int rc); + +#ifdef __cplusplus +} +#endif +#endif /* OMEGA_GPU_GEMM_H */ diff --git a/tests/bw_warp_sim_tc.h b/tests/bw_warp_sim_tc.h index 3f779e3f7..bf662ea6b 100644 --- a/tests/bw_warp_sim_tc.h +++ b/tests/bw_warp_sim_tc.h @@ -348,8 +348,8 @@ static int ws_run_warp(WsSim *s, WsWarp *w, uint32_t warp, uint32_t cx, uint32_t int gg = L / 4, tt = L % 4; const WsLane *ln = &w->lane[L]; uint32_t a4[4], b2[2], c4[4]; - for (unsigned q = 0; q < 4; q++) { a4[q] = ws_rds(ln, in->src1_vreg, q, p); c4[q] = in->src3_vreg >= 0 ? ws_rds(ln, in->src3_vreg, q, p) : 0u; } - for (unsigned q = 0; q < 2; q++) b2[q] = ws_rds(ln, in->src2_vreg, q, p); + for (unsigned q = 0; q < 4; q++) { a4[q] = ws_rds(ln, in->src1_vreg, in->src1_subreg + q, p); c4[q] = in->src3_vreg >= 0 ? ws_rds(ln, in->src3_vreg, in->src3_subreg + q, p) : 0u; } + for (unsigned q = 0; q < 2; q++) b2[q] = ws_rds(ln, in->src2_vreg, in->src2_subreg + q, p); /* operands may start at a subregister (the encoder adds it) */ const int ar[4] = { gg, gg + 8, gg, gg + 8 }, ac[4] = { 2 * tt, 2 * tt, 2 * tt + 8, 2 * tt + 8 }; for (unsigned q = 0; q < 4; q++) { A[ar[q]][ac[q]] = ws_u2f(a4[q] << 16); A[ar[q]][ac[q] + 1] = ws_u2f(a4[q] & 0xffff0000u); } for (unsigned q = 0; q < 2; q++) { B[2 * tt + 8 * q][gg] = ws_u2f(b2[q] << 16); B[2 * tt + 8 * q + 1][gg] = ws_u2f(b2[q] & 0xffff0000u); } diff --git a/tests/gpu_gemm_test.c b/tests/gpu_gemm_test.c new file mode 100644 index 000000000..04f5e81f8 --- /dev/null +++ b/tests/gpu_gemm_test.c @@ -0,0 +1,334 @@ +/* gpu_gemm_test.c -- row C3 of docs/OMEGA.md: matrix multiply of any shape, BF16 and FP8 (e4m3), both layouts of A and B, + * on the GB10 tensor cores, checked bit for bit against a host model of the same tensor-core steps (src/omega_gpu_gemm.h). + * + * --host-only no device: refusals, every kernel (both types, several shapes of tile, the red-check mutants) through our + * code generator and encoder, register counts + * --sim the real kernels in the warp simulator (tensor-core ops computed with the chip-exact models), small shapes + * over every edge case, all four layouts, three tile configurations; the three mutants must be caught + * (no flag) the GB10: at least 200 shapes with M, N, K from 1 to 8192, both types, all four layouts. Every output word + * must be written; shapes up to 2^27 multiply-adds are compared in full, larger ones on 4096 sampled + * elements plus the last row and column. Speed: 2 M N K / kernel time, as a fraction of the measured + * tensor-core ceiling (BF16 HMMA 115.36 TFLOPS, evidence OWN30B-T3-TC-PEAK-BW-5faa0f70-20261013T2236Z; + * FP8 QMMA 237.52 TFLOPS, L151 as quoted in evidence/L403-roof-20261022). The mutants must be caught. + * --quick: 24 shapes, for a first look. + * Last line: "C3 gemm : PASS ( checks)" or "... FAIL ( of )". */ +#include "omega_gpu_gemm.h" +#include "omega_gpu_session.h" +#include "bw_warp_sim_tc.h" + +#include + +static int g_checks, g_failed; +static void check(int ok, const char *what) { + g_checks++; + if (!ok) { g_failed++; printf("FAIL: %s\n", what); } +} + +static const HmmaModel HM = { 16, 2, 0, 2, 0 }; /* chip-exact, evidence OWN30B-T3-HMMA-MODEL */ +static const QmmaModel QM = { 32, 26, 0, 2, 0 }; /* chip-exact, evidence OWN30B-L1G-QMMA-PFGEMM-c742aa13 */ +static const char *tname(OmegaGpuGemmType t) { return t == OMEGA_GPU_GEMM_BF16 ? "bf16" : "e4m3"; } +static const char *lname(unsigned l) { static const char *n[4] = { "A row B row", "A col B row", "A row B col", "A col B col" }; return n[l & 3u]; } + +static uint64_t g_rng = 1; +static uint32_t rnd(void) { g_rng = g_rng * 6364136223846793005ull + 1442695040888963407ull; return (uint32_t)(g_rng >> 33); } + +/* inputs: bf16 values 0 or +-(1 + m/128) 2^e, e in -8..8; e4m3 any code except the two NaNs */ +static void fill(OmegaGpuGemmType t, void *p, uint64_t n, uint64_t seed) { + g_rng = seed * 0x2545f4914f6cdd1dull + 7; + if (t == OMEGA_GPU_GEMM_BF16) { + uint16_t *h = p; + for (uint64_t i = 0; i < n; i++) { + uint32_t r = rnd(); + h[i] = r % 61u == 0 ? 0 : (uint16_t)(((r >> 8) & 1u) << 15 | (uint32_t)(127 + (int)((r >> 9) % 17u) - 8) << 7 | (r >> 16 & 0x7fu)); + } + } else { + uint8_t *b = p; + for (uint64_t i = 0; i < n; i++) { uint8_t c = (uint8_t)rnd(); b[i] = (c & 0x7fu) == 0x7fu ? (uint8_t)(c ^ 1u) : c; } + } +} + +static float val(OmegaGpuGemmType t, const void *p, uint64_t i) { + if (t == OMEGA_GPU_GEMM_BF16) { uint32_t u = (uint32_t)((const uint16_t *)p)[i] << 16; float f; memcpy(&f, &u, 4); return f; } + return qm_e4m3(((const uint8_t *)p)[i]); +} + +/* the host model: one tensor-core step per 16 (bf16) or 32 (e4m3) values of k, in increasing k, from +0 */ +static float ref_elem(OmegaGpuGemmType t, unsigned lay, uint32_t M, uint32_t N, uint32_t K, const void *A, const void *B, uint32_t m, uint32_t n) { + const uint32_t ks = t == OMEGA_GPU_GEMM_BF16 ? 16u : 32u; + float acc = 0.0f; + for (uint32_t k0 = 0; k0 < K; k0 += ks) { + float av[32], bv[32]; + for (uint32_t k = 0; k < ks; k++) { + uint32_t kk = k0 + k; + if (kk >= K) { av[k] = bv[k] = 0.0f; continue; } + av[k] = val(t, A, lay & OMEGA_GPU_GEMM_A_COL ? (uint64_t)kk * M + m : (uint64_t)m * K + kk); + bv[k] = val(t, B, lay & OMEGA_GPU_GEMM_B_COL ? (uint64_t)n * K + kk : (uint64_t)kk * N + n); + } + acc = t == OMEGA_GPU_GEMM_BF16 ? hm_dot16(&HM, av, bv, acc) : qm_dot32(&QM, av, bv, acc); + } + return acc; +} + +static uint32_t f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } + +/* compare: every element when M N K <= 2^27, else 4096 samples + the last row and column; returns the mismatches */ +static uint64_t compare(OmegaGpuGemmType t, unsigned lay, uint32_t M, uint32_t N, uint32_t K, const void *A, const void *B, const float *C, + uint64_t *checked, char *first, size_t firstn) { + uint64_t bad = 0; *checked = 0; first[0] = 0; + #define ONE(mm, nn) do { uint32_t m_ = (mm), n_ = (nn); float w_ = ref_elem(t, lay, M, N, K, A, B, m_, n_), g_ = C[(uint64_t)m_ * N + n_]; (*checked)++; \ + if (f2u(w_) != f2u(g_)) { if (!bad) snprintf(first, firstn, "C[%u][%u] = %08x, model %08x", m_, n_, f2u(g_), f2u(w_)); bad++; } } while (0) + if ((uint64_t)M * N * K <= (1ull << 27)) { + for (uint32_t m = 0; m < M; m++) for (uint32_t n = 0; n < N; n++) ONE(m, n); + } else { + g_rng = (uint64_t)M * 31 + N * 7 + K; + for (int i = 0; i < 4096; i++) ONE(rnd() % M, rnd() % N); + for (uint32_t n = 0; n < N; n += N > 512 ? N / 512 : 1) ONE(M - 1, n); + for (uint32_t m = 0; m < M; m += M > 512 ? M / 512 : 1) ONE(m, N - 1); + ONE(M - 1, N - 1); + } + #undef ONE + return bad; +} + +/* ------------------------------------------------------------------ host only */ + +static void host_only(void) { + char w[200]; + uint16_t a[4] = { 0 }, b[4] = { 0 }; float c[4]; + check(omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, 0, 1, 1, a, b, c, NULL) == OMEGA_GPU_GEMM_BAD_ARGS, "M = 0 refused"); + check(omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, 1, 1, 0, a, b, c, NULL) == OMEGA_GPU_GEMM_BAD_ARGS, "K = 0 refused"); + check(omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, OMEGA_GPU_GEMM_MAX_DIM + 1, 1, 1, a, b, c, NULL) == OMEGA_GPU_GEMM_TOO_LARGE, "M past the maximum refused"); + check(omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 4, 1, 1, 1, a, b, c, NULL) == OMEGA_GPU_GEMM_BAD_ARGS, "unknown layout bits refused"); + check(omega_gpu_gemm((OmegaGpuGemmType)2, 0, 1, 1, 1, a, b, c, NULL) == OMEGA_GPU_GEMM_BAD_ARGS, "unknown type refused"); + check(omega_gpu_gemm(OMEGA_GPU_GEMM_E4M3, 0, 1, 1, 1, NULL, b, c, NULL) == OMEGA_GPU_GEMM_BAD_ARGS, "NULL A refused"); + OmegaGemmCfg bad; omega_gpu_gemm_default_cfg(OMEGA_GPU_GEMM_BF16, &bad); bad.rt = 3; + check(!omega_gpu_gemm_cfg_ok(&bad), "a tile of 3 row tiles refused"); + + /* the model itself is a multiply: within 2^-20 of the exact sum, relative to the sum of the magnitudes */ + for (int t = 0; t < 2; t++) for (unsigned lay = 0; lay < 4; lay++) { + enum { MM = 23, NN = 19, KK = 300 }; + static uint16_t A[MM * KK], B[KK * NN]; + fill((OmegaGpuGemmType)t, A, MM * KK, 5 + lay); fill((OmegaGpuGemmType)t, B, KK * NN, 9 + lay); + double worst = 0; + for (uint32_t m = 0; m < MM; m++) for (uint32_t n = 0; n < NN; n++) { + double ex = 0, mag = 0; + for (uint32_t k = 0; k < KK; k++) { + double p = (double)val((OmegaGpuGemmType)t, A, lay & OMEGA_GPU_GEMM_A_COL ? (uint64_t)k * MM + m : (uint64_t)m * KK + k) * + (double)val((OmegaGpuGemmType)t, B, lay & OMEGA_GPU_GEMM_B_COL ? (uint64_t)n * KK + k : (uint64_t)k * NN + n); + ex += p; mag += fabs(p); + } + double d = fabs((double)ref_elem((OmegaGpuGemmType)t, lay, MM, NN, KK, A, B, m, n) - ex) / (mag > 0 ? mag : 1); + if (d > worst) worst = d; + } + snprintf(w, sizeof w, "the %s model is a multiply (%s): worst error %.3g of the magnitude sum", tname((OmegaGpuGemmType)t), lname(lay), worst); + check(worst < ldexp(1.0, -20), w); + printf("%s\n", w); + } + + const OmegaGemmCfg shapes[] = { { 0, 2, 4, 2, 2, 4, 0 }, { 0, 1, 1, 1, 1, 4, 0 }, { 0, 4, 1, 2, 2, 2, 0 }, { 0, 1, 4, 4, 1, 2, 0 }, { 0, 2, 2, 1, 4, 8, 0 } }; + OmegaGemmCfg big; omega_gpu_gemm_default_cfg(OMEGA_GPU_GEMM_BF16, &big); big.rt = 4; big.ct = 2; + check(!omega_gpu_gemm_cfg_ok(&big), "a tile past the register budget (rt 4 ct 2) refused"); + for (int t = 0; t < 2; t++) + for (size_t s = 0; s < sizeof shapes / sizeof shapes[0]; s++) + for (int mut = 0; mut <= 3; mut++) + for (int k = 0; k < OMEGA_GEMM_K_COUNT; k++) { + OmegaGemmCfg c = shapes[s]; c.type = (OmegaGpuGemmType)t; c.mutant = mut; + BlackwellIRProgram *p = calloc(1, sizeof *p); + int rc = omega_gpu_gemm_codegen(&c, (OmegaGemmKind)k, p); + size_t bytes = rc == 0 ? omega_bw_program_code_bytes(p) : 0; + uint8_t *code = bytes ? malloc(bytes) : NULL; + OmegaBlackwellKernel kk; memset(&kk, 0, sizeof kk); + int enc = code ? omega_blackwell_kernel_encode_into(p, code, bytes, &kk) : -1; + int np = enc == 0 ? omega_qmma_patch_code(p, code, bytes) : -1; + snprintf(w, sizeof w, "%s rt %u ct %u wm %u wn %u kernel %d mutant %d: codegen %d, encode %d, qmma patches %d, %u gprs", tname(c.type), + c.rt, c.ct, c.wm, c.wn, k, mut, rc, enc, np, (unsigned)kk.gpr_count); + check(rc == 0 && enc == 0 && kk.code_size == bytes && np >= 0 && (t == 1 || np == 0) && omega_bw_gpr_declared(kk.gpr_count) <= 255u, w); + if (mut == 0) printf("%s\n", w); + free(code); free(p); + } +} + +/* ------------------------------------------------------------------ the simulator */ + +typedef struct { + BlackwellIRProgram *prog[OMEGA_GEMM_K_COUNT]; + WsRange ranges[5]; + int order; + char err[300]; +} SimCtx; + +static int sim_launch(void *ctx, OmegaGemmKind k, const uint32_t a[OMEGA_GPU_GEMM_ARGS_WORDS], uint32_t gx, uint32_t gy, uint32_t threads) { + SimCtx *c = ctx; + static WsSim s; + memset(&s, 0, sizeof s); + s.p = c->prog[k]; s.threads = threads; s.order = c->order; + for (unsigned i = 0; i < OMEGA_GPU_GEMM_ARGS_WORDS; i++) s.cbank[0x380 / 4 + i] = a[i]; + memcpy(s.ranges, c->ranges, sizeof c->ranges); s.nranges = 5; + if (ws_run(&s, gx, gy) != 0) { snprintf(c->err, sizeof c->err, "kernel %d: %s at pc %d", (int)k, s.msg, s.err_pc); return -1; } + return 0; +} + +static int sim_build(SimCtx *c, const OmegaGemmCfg *cfg) { + for (int k = 0; k < OMEGA_GEMM_K_COUNT; k++) { + c->prog[k] = calloc(1, sizeof *c->prog[k]); + if (!c->prog[k] || omega_gpu_gemm_codegen(cfg, (OmegaGemmKind)k, c->prog[k]) != 0) return -1; + } + return 0; +} +static void sim_free(SimCtx *c) { for (int k = 0; k < OMEGA_GEMM_K_COUNT; k++) { free(c->prog[k]); c->prog[k] = NULL; } } + +/* one multiply through the simulator; 0 when it ran and every output word was written */ +static int sim_gemm(SimCtx *c, const OmegaGemmCfg *cfg, unsigned lay, uint32_t M, uint32_t N, uint32_t K, const void *A, const void *B, float *C) { + OmegaGemmPlan p; + if (omega_gpu_gemm_plan(cfg, M, N, K, &p) != 0) return -2; + uint8_t *ap = malloc(p.ap_bytes), *bp = malloc(p.bp_bytes); + memset(ap, 0xa5, p.ap_bytes); memset(bp, 0x5a, p.bp_bytes); + for (uint64_t i = 0; i < (uint64_t)M * N; i++) { uint32_t u = 0x7fa00badu; memcpy(&C[i], &u, 4); } + c->ranges[0] = (WsRange){ (uintptr_t)A, (uintptr_t)A + p.a_bytes + 1 }; /* the e4m3 pack reads a u16 around the last byte */ + c->ranges[1] = (WsRange){ (uintptr_t)B, (uintptr_t)B + p.b_bytes + 1 }; + c->ranges[2] = (WsRange){ (uintptr_t)ap, (uintptr_t)ap + p.ap_bytes }; + c->ranges[3] = (WsRange){ (uintptr_t)bp, (uintptr_t)bp + p.bp_bytes }; + c->ranges[4] = (WsRange){ (uintptr_t)C, (uintptr_t)(C + (uint64_t)M * N) }; + int rc = omega_gpu_gemm_drive(cfg, lay, M, N, K, (uintptr_t)A, (uintptr_t)B, (uintptr_t)ap, (uintptr_t)bp, (uintptr_t)C, sim_launch, c); + for (uint64_t i = 0; rc == 0 && i < (uint64_t)M * N; i++) if (f2u(C[i]) == 0x7fa00badu) rc = -9; + free(ap); free(bp); + return rc; +} + +static void sim_tier(void) { + char w[600], first[200]; + static const uint32_t sh[][3] = { { 1, 1, 1 }, { 1, 1, 17 }, { 16, 8, 16 }, { 17, 9, 33 }, { 64, 64, 64 }, { 65, 63, 100 }, + { 3, 130, 70 }, { 100, 3, 257 }, { 129, 65, 31 }, { 31, 200, 129 } }; + const size_t nsh = sizeof sh / sizeof sh[0]; + const OmegaGemmCfg cfgs[] = { { 0, 2, 4, 2, 2, 4, 0 }, { 0, 1, 1, 1, 1, 4, 0 }, { 0, 4, 1, 1, 4, 2, 0 } }; + void *A = malloc(300 * 300 * 2), *B = malloc(300 * 300 * 2); + float *C = malloc(300 * 300 * 4); + for (int t = 0; t < 2; t++) + for (size_t ci = 0; ci < sizeof cfgs / sizeof cfgs[0]; ci++) { + OmegaGemmCfg cfg = cfgs[ci]; cfg.type = (OmegaGpuGemmType)t; + SimCtx c; memset(&c, 0, sizeof c); + check(sim_build(&c, &cfg) == 0, "simulator: kernels built"); + uint64_t runs = 0, wrong = 0; + for (size_t s = 0; s < nsh; s++) + for (unsigned lay = 0; lay < 4; lay++) { + if (ci > 0 && lay != (unsigned)(s % 4)) continue; /* the other tile shapes: one layout per shape */ + const uint32_t M = sh[s][0], N = sh[s][1], K = sh[s][2]; + fill(cfg.type, A, (uint64_t)M * K, s * 4 + lay); fill(cfg.type, B, (uint64_t)K * N, s * 4 + lay + 1000); + c.order = (int)(s & 1u); + int rc = sim_gemm(&c, &cfg, lay, M, N, K, A, B, C); + uint64_t checked = 0, bad = rc == 0 ? compare(cfg.type, lay, M, N, K, A, B, C, &checked, first, sizeof first) : 1; + runs++; + if (rc != 0 || bad) { + wrong++; + snprintf(w, sizeof w, "sim %s rt %u ct %u wm %u wn %u, %ux%ux%u %s: rc %d, %" PRIu64 " wrong of %" PRIu64 " %s %s", tname(cfg.type), cfg.rt, + cfg.ct, cfg.wm, cfg.wn, M, N, K, lname(lay), rc, bad, checked, first, c.err); + check(0, w); + } + } + snprintf(w, sizeof w, "simulator %s rt %u ct %u wm %u wn %u: %" PRIu64 " multiplies, %" PRIu64 " wrong", tname(cfg.type), cfg.rt, cfg.ct, cfg.wm, cfg.wn, runs, wrong); + check(wrong == 0, w); + printf("%s\n", w); + sim_free(&c); + } + /* red checks: each mutant must change a result the real kernels get right */ + for (int t = 0; t < 2; t++) + for (int mut = 1; mut <= 3; mut++) { + OmegaGemmCfg cfg; omega_gpu_gemm_default_cfg((OmegaGpuGemmType)t, &cfg); cfg.mutant = mut; + SimCtx c; memset(&c, 0, sizeof c); + const uint32_t M = 65, N = 63, K = 100; + fill(cfg.type, A, M * K, 77); fill(cfg.type, B, K * N, 78); + int built = sim_build(&c, &cfg) == 0, rc = built ? sim_gemm(&c, &cfg, 0, M, N, K, A, B, C) : -1; + uint64_t checked = 0, bad = rc == 0 ? compare(cfg.type, 0, M, N, K, A, B, C, &checked, first, sizeof first) : 1; + snprintf(w, sizeof w, "simulator red check: %s mutant %d is caught (%" PRIu64 " wrong)", tname(cfg.type), mut, bad); + check(built && bad > 0, w); + printf("%s\n", w); + sim_free(&c); + } + free(A); free(B); free(C); +} + +/* ------------------------------------------------------------------ the chip */ + +static size_t mem_available(void) { + FILE *f = fopen("/proc/meminfo", "r"); + char line[256]; size_t kb = 0; + while (f && fgets(line, sizeof line, f)) if (sscanf(line, "MemAvailable: %zu kB", &kb) == 1) break; + if (f) fclose(f); + return kb * 1024u; +} + +static const double CEIL_TFLOPS[2] = { 115.36, 237.52 }; + +static void chip_one(OmegaGpuGemmType t, unsigned lay, uint32_t M, uint32_t N, uint32_t K, void *A, void *B, float *C) { + char w[600], first[200]; + fill(t, A, (uint64_t)M * K, (uint64_t)M * 3 + N * 5 + K * 7 + lay); + fill(t, B, (uint64_t)K * N, (uint64_t)M * 11 + N * 13 + K * 17 + lay); + OmegaGpuGemmInfo info; + int rc = omega_gpu_gemm(t, lay, M, N, K, A, B, C, &info); + uint64_t checked = 0, bad = rc == 0 ? compare(t, lay, M, N, K, A, B, C, &checked, first, sizeof first) : 1; + double flop = 2.0 * M * N * K, tf = info.main_ns ? flop / (double)info.main_ns / 1e3 : 0, tfp = info.main_ns ? flop / (double)(info.main_ns + info.pack_ns) / 1e3 : 0; + snprintf(w, sizeof w, "%s %ux%ux%u %s: %s, %" PRIu64 " checked, %" PRIu64 " wrong%s%s; kernel %.3f ms %.2f TFLOPS = %.4f of ceiling, with packs %.2f TFLOPS = %.4f%s%s", + tname(t), M, N, K, lname(lay), omega_gpu_gemm_rc_name(rc), checked, bad, bad && rc == 0 ? ", first " : "", bad && rc == 0 ? first : "", + info.main_ns / 1e6, tf, tf / CEIL_TFLOPS[t], tfp, tfp / CEIL_TFLOPS[t], rc ? ": " : "", rc ? omega_gpu_session_last_error() : ""); + check(rc == 0 && bad == 0, w); + if (rc == 0 && bad == 0) printf("ok: %s\n", w); +} + +static void chip_tier(int quick) { + char w[200]; + const size_t need = (size_t)8192 * 8192 * 2 * 2 + (size_t)8192 * 8192 * 4 + ((size_t)8 << 30); + if (!quick && mem_available() < need * 2) { printf("NOT_RUN: MemAvailable %zu MiB < %zu MiB\n", mem_available() >> 20, need * 2 >> 20); exit(2); } + const uint32_t big = quick ? 1024u : 8192u; + void *A = malloc((size_t)big * big * 2), *B = malloc((size_t)big * big * 2); + float *C = malloc((size_t)big * big * 4); + if (!A || !B || !C) { printf("NOT_RUN: host allocation\n"); exit(2); } + /* the shapes: per type and layout, the same list (26 each, 208 in all): edges, odd sizes, skinny, square up to 8192 */ + static const uint32_t sh[][3] = { + { 1, 1, 1 }, { 1, 8192, 1 }, { 8192, 1, 1 }, { 1, 1, 8192 }, { 7, 13, 29 }, { 16, 8, 16 }, { 33, 65, 127 }, { 100, 100, 100 }, + { 128, 64, 64 }, { 255, 257, 511 }, { 1000, 999, 1001 }, { 1, 4096, 4096 }, { 4096, 1, 4096 }, { 4096, 4096, 1 }, + { 17, 8192, 3000 }, { 8192, 17, 3000 }, { 1024, 1024, 1024 }, { 2048, 2048, 2048 }, { 4096, 4096, 4096 }, { 3000, 5000, 700 }, + { 8192, 8192, 64 }, { 64, 8192, 8192 }, { 8192, 64, 8192 }, { 6000, 7000, 8000 }, { 8191, 8191, 8191 }, { 8192, 8192, 8192 } }; + const size_t nsh = quick ? 12 : sizeof sh / sizeof sh[0]; + int before = g_failed, shapes = 0; + for (int t = 0; t < 2; t++) + for (unsigned lay = 0; lay < 4; lay++) + for (size_t s = 0; s < nsh; s++) { + if (quick && lay != (unsigned)(s % 4)) continue; + uint32_t M = sh[s][0] > big ? big : sh[s][0], N = sh[s][1] > big ? big : sh[s][1], K = sh[s][2] > big ? big : sh[s][2]; + chip_one((OmegaGpuGemmType)t, lay, M, N, K, A, B, C); + shapes++; + } + printf("%d shapes, both types, all four layouts: %s\n", shapes, g_failed == before ? "PASS" : "FAIL"); + for (int t = 0; t < 2; t++) + for (int mut = 1; mut <= 3; mut++) { + OmegaGemmCfg cfg; omega_gpu_gemm_default_cfg((OmegaGpuGemmType)t, &cfg); cfg.mutant = mut; + omega_gpu_gemm_test_set_cfg((OmegaGpuGemmType)t, &cfg); + const uint32_t M = 65, N = 63, K = 100; + fill((OmegaGpuGemmType)t, A, M * K, 77); fill((OmegaGpuGemmType)t, B, K * N, 78); + int rc = omega_gpu_gemm((OmegaGpuGemmType)t, 0, M, N, K, A, B, C, NULL); + char first[200]; uint64_t checked = 0, bad = rc == 0 ? compare((OmegaGpuGemmType)t, 0, M, N, K, A, B, C, &checked, first, sizeof first) : 1; + snprintf(w, sizeof w, "chip red check: %s mutant %d is caught (%s, %" PRIu64 " wrong)", tname((OmegaGpuGemmType)t), mut, omega_gpu_gemm_rc_name(rc), bad); + check(bad > 0, w); + printf("%s\n", w); + omega_gpu_gemm_test_set_cfg((OmegaGpuGemmType)t, NULL); + } + for (int t = 0; t < 2; t++) chip_one((OmegaGpuGemmType)t, 3, 65, 63, 100, A, B, C); /* right again after the red checks */ + free(A); free(B); free(C); +} + +int main(int argc, char **argv) { + const char *tier = "chip"; + int quick = 0; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--host-only")) tier = "host"; + else if (!strcmp(argv[i], "--sim")) tier = "sim"; + else if (!strcmp(argv[i], "--quick")) quick = 1; + else { fprintf(stderr, "usage: %s [--host-only | --sim | --quick]\n", argv[0]); return 2; } + } + if (!strcmp(tier, "host")) host_only(); + else if (!strcmp(tier, "sim")) { host_only(); sim_tier(); } + else chip_tier(quick); + if (g_failed) printf("C3 gemm %s: FAIL (%d of %d)\n", tier, g_failed, g_checks); + else printf("C3 gemm %s: PASS (%d checks)\n", tier, g_checks); + return g_failed ? 1 : 0; +} From ac1e3cba8be25afc32c48bc7363dcceb5ed92252 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 21:19:25 -0500 Subject: [PATCH 07/10] C3 gemm evidence: sim check count Co-Authored-By: Claude Opus 5.5 --- evidence/C3-GEMM/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evidence/C3-GEMM/README.md b/evidence/C3-GEMM/README.md index 914362fa9..83165307f 100644 --- a/evidence/C3-GEMM/README.md +++ b/evidence/C3-GEMM/README.md @@ -12,7 +12,7 @@ separate check shows that model stays within one part in a million of the exact | Log | What it checks | Result | |---|---|---| | 01-host-only | bad calls refused, tile shapes past the register budget refused; every kernel (both types, five tile shapes, each planted fault) through our code generator and encoder; the model against exact double-precision sums | PASS, 136 checks | -| 02-sim | the real kernels in the warp simulator (tensor-core ops computed with the chip models): ten shapes over every edge, all four layouts, three tile shapes, both types, every output compared; three planted faults (a dropped k step, no zeros past the edges, swapped columns) each caught on all 4,095 outputs | PASS, 146 checks | +| 02-sim | the real kernels in the warp simulator (tensor-core ops computed with the chip models): ten shapes over every edge, all four layouts, three tile shapes, both types, every output compared; three planted faults (a dropped k step, no zeros past the edges, swapped columns) each caught on all 4,095 outputs | PASS, 154 checks | | (next) chip | 208 shapes up to 8192, both types, all four layouts; speed against 115.36 TFLOPS (BF16) and 237.52 TFLOPS (FP8) | waiting for a chip window | Command: `make test-gpu-gemm` (host and simulator). The chip run is `build/gpu_gemm_test` with no flag, under the GB10 lock. From c11a491a81607b6bb8e487f56c89803123799d03 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 21:53:37 -0500 Subject: [PATCH 08/10] C3 gemm: close hook drops the kernel cache with the device; chip check after close and reopen Co-Authored-By: Claude Opus 5.5 --- src/omega_gpu_gemm.c | 13 +++++++++++++ tests/gpu_gemm_test.c | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/omega_gpu_gemm.c b/src/omega_gpu_gemm.c index 5bb4d186d..42b47a7d6 100644 --- a/src/omega_gpu_gemm.c +++ b/src/omega_gpu_gemm.c @@ -257,8 +257,17 @@ static struct { OmegaGemmCfg cfg[2]; OmegaGpuMem code[2][OMEGA_GEMM_K_COUNT]; uint32_t gpr[2][OMEGA_GEMM_K_COUNT]; + int hooked; } g; +/* lock held; the session calls it right before it closes the device (also in omega_gpu_session_recover): the kernels go + * with the device, the next call builds them again on the new one */ +static void on_session_close(void) { + for (unsigned t = 0; t < 2; t++) + for (unsigned k = 0; k < OMEGA_GEMM_K_COUNT; k++) if (g.code[t][k].cpu) omega_gpu_session_free(&g.code[t][k]); + memset(g.code, 0, sizeof g.code); +} + static const OmegaGemmCfg *cfg_of(OmegaGpuGemmType t) { if (!g.set[t]) { omega_gpu_gemm_default_cfg(t, &g.cfg[t]); g.set[t] = 1; } return &g.cfg[t]; @@ -289,6 +298,10 @@ const char *omega_gpu_gemm_rc_name(int rc) { /* lock held */ static int kernel_locked(OmegaGpuGemmType t, OmegaGemmKind k) { if (g.code[t][k].cpu) return OMEGA_GPU_GEMM_OK; + if (!g.hooked) { /* without the hook a kernel would outlive its device */ + if (omega_gpu_session_on_close(on_session_close) != 0) return OMEGA_GPU_GEMM_CHIP_FAIL; + g.hooked = 1; + } BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); if (!prog) return OMEGA_GPU_GEMM_CODEGEN_FAIL; int rc = OMEGA_GPU_GEMM_OK; diff --git a/tests/gpu_gemm_test.c b/tests/gpu_gemm_test.c index 04f5e81f8..b60f70964 100644 --- a/tests/gpu_gemm_test.c +++ b/tests/gpu_gemm_test.c @@ -313,6 +313,9 @@ static void chip_tier(int quick) { omega_gpu_gemm_test_set_cfg((OmegaGpuGemmType)t, NULL); } for (int t = 0; t < 2; t++) chip_one((OmegaGpuGemmType)t, 3, 65, 63, 100, A, B, C); /* right again after the red checks */ + omega_gpu_session_close(); /* the kernels go with the device (close hook); the next call builds them on a new one */ + printf("after the device closed and opened again:\n"); + for (int t = 0; t < 2; t++) chip_one((OmegaGpuGemmType)t, 0, 70, 33, 129, A, B, C); free(A); free(B); free(C); } From ec02c7991f8132d25ba8bd3d18e896082fe70a54 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 18:15:31 -0500 Subject: [PATCH 09/10] C3 gemm: stack on the scan layer over main 0d72560a; today's host/sim logs; crumbs recompiled Layer 2 of the L386 train (#616 scan -> #615 gemm -> #617 isolation -> #614 disasm). The two scan commits this branch shared with c3/reduce-scan are dropped (the scan layer carries them); the Makefile keeps both blocks. Host 136 checks and simulator 154 checks PASS on 2026-10-24 23:11Z; the scan simulator tier on this tip PASS 139 checks. The 208-shape chip run is owed on the train tip. Co-Authored-By: Claude Fable 5.1 --- evidence/C3-GEMM/01-host-only.log | 2 -- evidence/C3-GEMM/02-sim.log | 2 -- evidence/C3-GEMM/README.md | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/evidence/C3-GEMM/01-host-only.log b/evidence/C3-GEMM/01-host-only.log index 88aa39993..c581c5126 100644 --- a/evidence/C3-GEMM/01-host-only.log +++ b/evidence/C3-GEMM/01-host-only.log @@ -1,4 +1,3 @@ -$ ./build/gpu_gemm_test --host-only (omega c3/gemm, 2026-10-22T02:19Z) the bf16 model is a multiply (A row B row): worst error 3.81e-07 of the magnitude sum the bf16 model is a multiply (A col B row): worst error 5.42e-07 of the magnitude sum the bf16 model is a multiply (A row B col): worst error 5.77e-07 of the magnitude sum @@ -38,4 +37,3 @@ e4m3 rt 2 ct 2 wm 1 wn 4 kernel 0 mutant 0: codegen 0, encode 0, qmma patches 0, e4m3 rt 2 ct 2 wm 1 wn 4 kernel 1 mutant 0: codegen 0, encode 0, qmma patches 0, 40 gprs e4m3 rt 2 ct 2 wm 1 wn 4 kernel 2 mutant 0: codegen 0, encode 0, qmma patches 16, 84 gprs C3 gemm host: PASS (136 checks) -exit=0 diff --git a/evidence/C3-GEMM/02-sim.log b/evidence/C3-GEMM/02-sim.log index a0045c8ce..fd97da9f2 100644 --- a/evidence/C3-GEMM/02-sim.log +++ b/evidence/C3-GEMM/02-sim.log @@ -1,4 +1,3 @@ -$ ./build/gpu_gemm_test --sim (omega c3/gemm, 2026-10-22T02:19Z) the bf16 model is a multiply (A row B row): worst error 3.81e-07 of the magnitude sum the bf16 model is a multiply (A col B row): worst error 5.42e-07 of the magnitude sum the bf16 model is a multiply (A row B col): worst error 5.77e-07 of the magnitude sum @@ -50,4 +49,3 @@ simulator red check: e4m3 mutant 1 is caught (4095 wrong) simulator red check: e4m3 mutant 2 is caught (4095 wrong) simulator red check: e4m3 mutant 3 is caught (4095 wrong) C3 gemm sim: PASS (154 checks) -exit=0 diff --git a/evidence/C3-GEMM/README.md b/evidence/C3-GEMM/README.md index 83165307f..0e730a9bf 100644 --- a/evidence/C3-GEMM/README.md +++ b/evidence/C3-GEMM/README.md @@ -15,5 +15,5 @@ separate check shows that model stays within one part in a million of the exact | 02-sim | the real kernels in the warp simulator (tensor-core ops computed with the chip models): ten shapes over every edge, all four layouts, three tile shapes, both types, every output compared; three planted faults (a dropped k step, no zeros past the edges, swapped columns) each caught on all 4,095 outputs | PASS, 154 checks | | (next) chip | 208 shapes up to 8192, both types, all four layouts; speed against 115.36 TFLOPS (BF16) and 237.52 TFLOPS (FP8) | waiting for a chip window | -Command: `make test-gpu-gemm` (host and simulator). The chip run is `build/gpu_gemm_test` with no flag, under the GB10 lock. +Command: `make test-gpu-gemm` (host and simulator). The chip run is `build/gpu_gemm_test` with no flag, under the GB10 lock. 01 and 02 logs: 2026-10-24 23:11Z on the stacked tip (gemm layer over the scan layer over main 0d72560a; binary sha256 0a624c25 a68cef88...; `PHYSICS_DIR` must point at the checkout pinned in `physics.lock`), host 136 checks, simulator 154 checks. This is the general kernel; the prefill-roof lane (L403) tunes it toward the ceiling. From 2ed498dbeb92c11489f1064fb003f087ac44cb03 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 18:54:43 -0500 Subject: [PATCH 10/10] crumb: recompile after the re-stack on main 697539a57 (L386 train) Co-Authored-By: Claude Fable 5.1 --- .crumb | 24 ++++++++++++------------ src/.crumb | 10 +++++----- tests/.crumb | 10 +++++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.crumb b/.crumb index c7d214e62..48ab8a601 100644 --- a/.crumb +++ b/.crumb @@ -77,14 +77,14 @@ "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "ba3fa7cfe0a7e2df29583c0450bf5f7b5789349b5bbe735d1448a50295a87ec8", - "last_commit": "6e177ce13", + "digest": "cd13512f11d66b682bae747318c42f34791f05ad5786ab633b942cc93739ef10", + "last_commit": "c11a491a8", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "87757530a28d4408bc4410fd8f922088f3e3f1cbc8987c5879e92ca59fe8728a", - "last_commit": "6e177ce13", + "digest": "af7858c0be60397973120c43c0324c298c65e18b87340c53cc61895a9deb07be", + "last_commit": "c11a491a8", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, @@ -95,15 +95,15 @@ "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:25bb98707e3701d95854342be7572172b8e9151d409fbcaea73ddc1690591607", - "compiled_at": "2026-10-24T23:54:33Z", + "children_root": "sha256:a8c3ef3ac73dceba22f14a3477f74abb4ebc1cfdd4cda49b878487b703e548fe", + "compiled_at": "2026-10-24T23:54:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:2aca06720f7a98be3c84475dcbf35c466d4bae33d6e93a2e07c0abb9e8d21f1e", - "evidence_files": 11619, - "evidence_root": "sha256:2a8475f2e1c377d2a0715da7b2b9de849865303f80c1776f351177440492ec9e", - "files": 14923, - "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", - "source_tree": "sha256:98bef521239fcbbae90d313839be15e5882adfbce6cc99f3045fe0c863cb6e52" + "digest": "sha256:3d81f369c8d2a0cf75282d3567ec5c23ef1eac33434d7a59f07a2b4da283e5aa", + "evidence_files": 11622, + "evidence_root": "sha256:04c535be89b49b673354da436a25c6a6708e8a2ca0ccb3ef0619d7782f9150b9", + "files": 14929, + "generated_at_commit": "ec02c7991f8132d25ba8bd3d18e896082fe70a54", + "source_tree": "sha256:d1de2a9c9d8e8c4c32b444cb08f91f7b437445c25a9d2cb0528d6719e5b98a7f" }, "owner_lane": "", "provenance": { diff --git a/src/.crumb b/src/.crumb index 5bd5f0ee5..67a66decc 100644 --- a/src/.crumb +++ b/src/.crumb @@ -188,14 +188,14 @@ } ], "children_root": "sha256:4460b4a6d5ed4054d462af660a6a02691350a35a8f44197e60ce605e243f698e", - "compiled_at": "2026-10-24T23:54:33Z", + "compiled_at": "2026-10-24T23:54:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:ba3fa7cfe0a7e2df29583c0450bf5f7b5789349b5bbe735d1448a50295a87ec8", + "digest": "sha256:cd13512f11d66b682bae747318c42f34791f05ad5786ab633b942cc93739ef10", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 561, - "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", - "source_tree": "sha256:286ee3dab8eced7c5c94e6383d494fd218b10140043352907a3eb7ab3f49e413" + "files": 563, + "generated_at_commit": "ec02c7991f8132d25ba8bd3d18e896082fe70a54", + "source_tree": "sha256:ec55fb86fd6713625cbd41588e00a53593e79d5d3df9b20cc3ea75e14cf03b71" }, "owner_lane": "", "provenance": { diff --git a/tests/.crumb b/tests/.crumb index a24ca6ab6..6d93d2f2b 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -302,14 +302,14 @@ } ], "children_root": "sha256:21fc25ed991f4066326a9270e13961ed8a45edc12064ce9e7846ab6782d5b72b", - "compiled_at": "2026-10-24T23:54:33Z", + "compiled_at": "2026-10-24T23:54:42Z", "compiler": "crumb-compile/1", - "digest": "sha256:87757530a28d4408bc4410fd8f922088f3e3f1cbc8987c5879e92ca59fe8728a", + "digest": "sha256:af7858c0be60397973120c43c0324c298c65e18b87340c53cc61895a9deb07be", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1288, - "generated_at_commit": "961bde0e1306142feaff6e77f2a150653c4dfd0a", - "source_tree": "sha256:cbf44d3eac6439851672ffdcf5046d84b972b1dbf2e29ca2fbfd420cbca74b83" + "files": 1289, + "generated_at_commit": "ec02c7991f8132d25ba8bd3d18e896082fe70a54", + "source_tree": "sha256:26f761c46141dd1cec7ec4b97c862ce8a3671352575b0525f5e3d70fd2f59624" }, "owner_lane": "", "provenance": {