omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
GitHub aien-dev/omega-mv#264 (code only)
Apply it
git checkout -b patch-bc8f012b1bb418d1 6b940faa9df2baffa7d38ec3cafdf4a55fd91289 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/bc8f012b1bb418d1.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
264
f8d0aca20e35fdc1ff4cbd769b6f2971c9af942f
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":264,"url":"https://github.com/aien-dev/omega-mv/pull/264","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:01Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/src/omega_gpu_attention_api.c b/src/omega_gpu_attention_api.c index cdba59416..53884ae44 100644 --- a/src/omega_gpu_attention_api.c +++ b/src/omega_gpu_attention_api.c @@ -237,13 +237,22 @@ static void gen_attention(Em *e, const KSpec *k) { int j = V(e), s = V(e), koff = V(e); int bi = V(e), sl = V(e), ta = V64(e), blk = V(e), ka = V64(e), dot = V(e), d = V(e); int x = V(e), lo = V(e), hi = V(e), qa = V(e), qb = V(e), q0 = V(e), q1 = V(e), ka2 = V64(e), j1 = V(e); + int dneg = V(e), over = V(e), ot = V(e), ctxm1 = V(e), cm1 = V(e), cninf = V(e), nb = V(e), ns = V(e); + movi(e, cm1, 0xFFFFFFFFu); iadd3(e, ctxm1, ctx, cm1); movi(e, cninf, F32_NEG_INF); loop_begin(e); int Lout = here(e); + /* No branch here: a warp split by "j >= ctx" stays split (the IR has no reconvergence + * instruction) and the SHFL reductions below then read inactive lanes, which is undefined + * (wrong dims tid >= tail on the chip, 2026-10-04). over = (j >= ctx) as 0/1 from the sign of + * ctx-1-j; out-of-range lanes read token `base` (always < ctx here) and their score + * is forced to -inf after the dot product with s = -max(-s, nb), nb = -inf or +inf. */ iadd3(e, j, base, tid); movi(e, s, F32_NEG_INF); movrz(e, koff); - isetp_ge_u32(e, j, ctx); - int bA = bra_fwd_if_p0(e); + imadi(e, dneg, j, 0xFFFFFFFFu, ctxm1); /* ctx - 1 - j */ + shri(e, over, dneg, 31); + imadr(e, ot, over, tid, NOREG); + imadi(e, j, ot, 0xFFFFFFFFu, j); /* j - over*tid */ /* phase A: token j */ shri(e, bi, j, k->log2bs); lop3andi(e, sl, j, (1u << k->log2bs) - 1u); @@ -289,7 +298,8 @@ static void gen_attention(Em *e, const KSpec *k) { bra_back_if_not_p0(e, Lin); loop_end(e); e_fmul(e, s, dot, scale); - patch_fwd(e, bA); + imadi(e, nb, over, 0x80000000u, cninf); /* over ? +inf : -inf (bits) */ + e_fsub(e, ns, zero, s); e_fmax(e, ns, ns, nb); e_fsub(e, s, zero, ns); sts32(e, sOff, s); sts32(e, oOff, koff); diff --git a/tests/gpu_attention_test.c b/tests/gpu_attention_test.c index bb18b623e..82d7de7e9 100644 --- a/tests/gpu_attention_test.c +++ b/tests/gpu_attention_test.c @@ -257,11 +257,13 @@ static int chip(const char *out_path) { uint32_t seed = 0xfb1c0005u; const uint32_t hd = 64; const struct { uint32_t nqh, nkv; const char *model; } shapes[2] = { { 32, 4, "tinyllama" }, { 32, 8, "llama32_1b" } }; - const uint32_t ctxs[4] = { 1, 17, 256, 2048 }; + /* 65, 129, 300 and 1000 end in a partial 64-token chunk after whole ones: the case that + * caught the diverged-warp shuffle on the chip (2026-10-04); 1, 17, 128, 256, 2048 did not. */ + const uint32_t ctxs[9] = { 1, 17, 256, 2048, 65, 128, 129, 300, 1000 }; const int no_mutants[1] = { 0 }; /* 1. contiguous f32 KV (gqa_attention) */ - for (int sh = 0; sh < 2; sh++) for (int ci = 0; ci < 4; ci++) { + for (int sh = 0; sh < 2; sh++) for (int ci = 0; ci < 9; ci++) { uint32_t nqh = shapes[sh].nqh, nkv = shapes[sh].nkv, seq = ctxs[ci]; size_t n = (size_t)nqh * hd, nkvs = (size_t)seq * nkv * hd; float *q = malloc(n * 4), *kc = malloc(nkvs * 4), *vc = malloc(nkvs * 4), *got = malloc(n * 4), *want = malloc(n * 4), *again = malloc(n * 4); @@ -309,7 +311,7 @@ static int chip(const char *out_path) { record(c, out); free(q); free(kc); free(vc); free(got); free(want); } /* 3. paged bf16 KV, block size 16, 2 layers (layer 1 under test), scattered block ids */ - for (int sh = 0; sh < 2; sh++) for (int ci = 0; ci < 4; ci++) { + for (int sh = 0; sh < 2; sh++) for (int ci = 0; ci < 9; ci++) { uint32_t nqh = shapes[sh].nqh, nkv = shapes[sh].nkv, ctx = ctxs[ci], bs = 16, layers = 2, layer = 1; uint32_t nblk = (ctx + bs - 1) / bs, pool_blocks = nblk + 7; OmegaGpuKvLayout ly = layout_for(pool_blocks, bs, layers, nkv, hd); @@ -391,7 +393,11 @@ static int chip(const char *out_path) { * loop handling is under test too) for every CTA of a launch: 64 threads, 1 KB shared, * host pointers as addresses, SHFL and BAR as lockstep points (all threads of the CTA * must sit at the same instruction). EX2 and RCP are exact here; the chip's are approximate. */ -typedef struct { uint32_t r[256]; int pc; int p0; int done; } SimThr; +/* path: hash of every branch decision so far. The IR has no reconvergence instruction + * (no BSSY/BSYNC/WARPSYNC), so once a warp splits it may stay split on the chip, and a + * SHFL reading an inactive lane is undefined (CUDA guide, warp shuffle functions). Every + * SHFL therefore requires one path across the warp, or the simulator stops with error 7. */ +typedef struct { uint32_t r[256]; int pc; int p0; int done; uint64_t path; } SimThr; static uint32_t sim_cbank[256]; static uint8_t sim_shared[1024]; #define SIM_T 64 @@ -415,6 +421,7 @@ static int sim_step(SimThr *t, const BlackwellIRProgram *p, uint32_t tid, uint32 case BW_IR_EXIT: if (!in->predicate_p0 || t->p0) { t->done = 1; return 0; } break; case BW_IR_BRA: { int take = !in->predicate_p0 || (in->predicate_not ? !t->p0 : t->p0); + t->path = t->path * 1000003u + (((uint64_t)t->pc << 1) | (uint64_t)take); if (take) { if ((int32_t)in->imm == 0) { g_sim_err = 2; t->done = 1; return 0; } t->pc += (int32_t)in->imm; continue; } break; } case BW_IR_MOV_IMM: wr(t, in->dst_vreg, in->imm, p); break; @@ -476,6 +483,8 @@ static int sim_launch(const void *progv, const OmegaGpuAttnLaunch *L, OmegaGpuAt if (g_sim_err) break; const BlackwellIRInsn *in = &p->insns[pc]; if (in->op == BW_IR_SHFL_DOWN) { + for (int i = 0; i < SIM_T; i++) if (!th[i].done && !th[i & ~31].done && th[i].path != th[i & ~31].path) g_sim_err = 7; + if (g_sim_err) break; uint32_t src[SIM_T]; for (int i = 0; i < SIM_T; i++) src[i] = rd(&th[i], in->src1_vreg, p); for (int i = 0; i < SIM_T; i++) { int lane = i & 31, from = lane + (int)(in->imm & 31); wr(&th[i], in->dst_vreg, from < 32 ? src[(i & ~31) + from] : src[i], p); }