interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

GitHub aien-dev/CUDApp#225 (code only)

closed derived eed4a82cc67a0345 #225

Imported from GitHub aien-dev/CUDApp#225 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 4bbccf084b7309ae89e126c890324e377478b3be · Head db8fc080196084efbdd69f76bbee209fb0f4f0bd

Apply it

git checkout -b patch-eed4a82cc67a0345 4bbccf084b7309ae89e126c890324e377478b3be
curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/eed4a82cc67a0345.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/CUDApp
225
db8fc080196084efbdd69f76bbee209fb0f4f0bd
{"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":225,"url":"https://github.com/aien-dev/CUDApp/pull/225","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:56Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/Makefile b/Makefile
index 0a8a8b80..4ee615e9 100644
--- a/Makefile
+++ b/Makefile
@@ -330,11 +330,18 @@ $(OUT_DIR)/gpu_lmhead_fp8_study: tests/gpu_lmhead_fp8_study.c src/omega_gpu_bf16
 # permutation, budgets) plus the warp simulator (512 threads); the chip gate is tools/run_gpu_fp8gemm_chip.sh under the GB10 lock.
 .PHONY: test-gpu-fp8gemm
 GPU_FP8GEMM_TEST = $(OUT_DIR)/gpu_fp8gemm_test
-$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a
+$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_gpu_fp8gemm_internal.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a
 	$(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_fp8gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm
+# P-DRA-4 DRA-67: the decode levers are env-gated and OFF by default; --spec-of checks the spec the stroke path resolves.
+FP8GEMM_STROKE_GU = --spec-of 2048,16,4,1
 test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST)
 	$(GPU_FP8GEMM_TEST) --host-only
 	$(GPU_FP8GEMM_TEST) --sim
+	env -u AIEN_OMEGA_FP8GEMM_X_AHEAD $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=0"
+	env AIEN_OMEGA_FP8GEMM_X_AHEAD=0 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0"
+	env AIEN_OMEGA_FP8GEMM_X_AHEAD=yes $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "x_ahead=0"
+	env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) $(FP8GEMM_STROKE_GU) --expect "rowmap=1 mt=4 x_ahead=1"
+	env AIEN_OMEGA_FP8GEMM_X_AHEAD=1 $(GPU_FP8GEMM_TEST) --spec-of 2048,16,8,0 --warps 4 --expect "x_ahead=0"
 
 # OWN-30B (2026-10-13): host-only audit that every launcher declares peak + 2 registers (the chip hung at peak + 1).
 .PHONY: test-gpu-gpr-boundary
diff --git a/src/omega_blackwell_codegen_gemm.c b/src/omega_blackwell_codegen_gemm.c
index 10bf71b4..d0ee0987 100644
--- a/src/omega_blackwell_codegen_gemm.c
+++ b/src/omega_blackwell_codegen_gemm.c
@@ -2,7 +2,8 @@
 /* omega_blackwell_codegen_gemm.c: FP8 e4m3 block-scaled grouped GEMM for prefill (OWN-30B builder F item 26). See the
  * header for the contract. The emitter helpers are copies of omega_blackwell_codegen_moe.c's (same chip-learned
  * scheduling rules) plus one addition: weight and scale prefetch loads use scoreboards 3 (buffer A) and 4 (buffer B)
- * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes. */
+ * and are waited for only by the step that decodes them, so the next step's weights stream while this step computes; the
+ * staging words of x' are loaded one step ahead the same way on scoreboard 5 (L312 lever 3, 2026-10-21). */
 #include "omega_blackwell_codegen_gemm.h"
 #ifndef OMEGA_GPU_NO_POSIX
 #include <stdlib.h>
@@ -128,6 +129,22 @@ static void ldw_pf(Em *e, BlackwellIROpcode op, int d, int addr64, uint32_t imm,
 }
 static void consume(Em *e, unsigned sb) { e->pending |= e->held & (1u << sb); e->held &= ~(1u << sb); }
 
+/* The staging words of one K step (NJ per thread) into xv[], loaded one step AHEAD on scoreboard 5 (L312 lever 3): the
+ * STS of the step that reads them waits for them (consume(5)), so the x' latency hides behind the previous step's
+ * compute instead of sitting between its barriers. Addresses in rounds of 4 so the temporaries stay few; every load
+ * sets SB_RD and the next waits on it (the address read), as every load batch of this file does. xs (plain) or xso (rowmap)
+ * already point at the step to load. */
+static void x_prefetch(Em *e, uint32_t NJ, uint32_t T, uint32_t ROWW, uint32_t K, int RM, int one, int xs, int xso, const int *xb, const int *xv, int udesc) {
+    for (uint32_t j0 = 0; j0 < NJ; j0 += 4) {
+        const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4;
+        int xa[4];
+        for (uint32_t q = 0; q < nj; q++) xa[q] = V64(e);
+        if (e->err) return;
+        for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); }
+        for (uint32_t q = 0; q < nj; q++) ldw_pf(e, BW_IR_LDG_E, xv[j0 + q], xa[q], 0, udesc, 5);
+    }
+}
+
 static int log2u(uint32_t v) { int l = 0; while ((1u << l) < v) l++; return (1u << l) == v ? l : -1; }
 
 static int spec_ok(const OmegaFp8GemmSpec *s) {
@@ -140,6 +157,7 @@ static int spec_ok(const OmegaFp8GemmSpec *s) {
     if (ks % 2u && ks > 3u) return 0; /* odd step counts are fully unrolled: at most 3 */
     if (s->mutant < 0 || s->mutant > 4) return 0;
     if (s->rowmap > 1u || (s->rowmap && s->mt > 4u)) return 0; /* the mapped form keeps NJ row bases and MT y rows in registers: mt 8 needs 135 at 16 warps, past the file */
+    if (s->x_ahead > 1u || (s->x_ahead && s->mt * s->lane_bytes / s->warps > 16u)) return 0; /* lever 3 holds NJ staging words in registers: NJ > 16 (under 8 warps at mt * lane_bytes 128) is not a served shape */
     return 1;
 }
 uint32_t omega_fp8gemm_steps(const OmegaFp8GemmSpec *spec) { return spec_ok(spec) ? spec->k / (32u * spec->lane_bytes) : 0; }
@@ -220,6 +238,11 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
     for (int q = 0; q < 4; q++) xq[q] = V128(e);
     for (int b = 0; b < 2; b++) { wq[b] = LB == 16 ? V128(e) : V64(e); sc[b] = V(e); }
     for (int i = 0; i < 4; i++) fr[i] = V(e);
+    /* x_ahead (L312 lever 3): the next K step's staging words, loaded one step ahead (x_prefetch) into NJ registers held
+     * across the step; x_ahead 0 keeps the incumbent program byte for byte (the staging words loaded inside the step) */
+    const int XA = spec->x_ahead != 0;
+    int xv[16];
+    if (XA) for (uint32_t j = 0; j < NJ; j++) xv[j] = V(e);
     if (e->err) return -1;
 
     /* ---- weight-row loop (uniform per CTA) ---- */
@@ -259,6 +282,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
     for (uint32_t m = 0; m < MT; m++) movrz(e, acc[m]);
     ldw_pf(e, ldw, wq[0], pwc, 0, udesc, 3);
     ldw_pf(e, BW_IR_LDG_E, sc[0], psc, 0, udesc, 3);
+    if (XA) x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc); /* step 0's x' words */
     movi(e, cntk, KS / U);
 
     /* ---- K loop: U steps per iteration ---- */
@@ -267,17 +291,18 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
     for (uint32_t us = 0; us < U; us++) {
         const int cur = (int)(us & 1u), nxt = 1 - cur;
         const unsigned sbc = cur ? 4u : 3u, sbn = nxt ? 4u : 3u;
-        /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back; the
-         * staging words go in rounds of 4 so the temporaries stay few */
+        /* addresses first (fixed-latency ops would otherwise wait for the loads below), then loads back to back */
         const int last = us + 1 == U, prefetch = !last || KS > U;
-        int pwn = -1, psn = -1;
+        int pwn = -1, psn = -1, nf = -1;
         if (prefetch) { pwn = V64(e); psn = V64(e); }
         int sa = V(e);
         if (e->err) return -1;
         if (prefetch && !last) {
             imadw(e, pwn, one, (us + 1) * 32u * LB, pwc); imadw(e, psn, one, spec->mutant == 2 ? 0u : (us + 1) * BPS * 4u, psc);
         } else if (prefetch) { /* the next iteration's step 0; the last iteration re-reads its own step (harmless, drained after the loop) */
-            int nf = V(e), inc = V(e), inc2 = V(e);
+            int inc, inc2;
+            if (XA) { inc = V(e); inc2 = V(e); nf = V(e); }
+            else { nf = V(e); inc = V(e); inc2 = V(e); }
             if (e->err) return -1;
             imadi(e, nf, one, 0, 0xfffffffeu, cntk);     /* cntk - 2 */
             shr(e, nf, nf, 0, 31);                       /* 1 iff cntk == 1 (the last iteration) */
@@ -285,18 +310,34 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
             imadi(e, inc, nf, 0, U * 32u * LB, NOREG); imadi(e, inc2, nf, 0, spec->mutant == 2 ? 0u : U * BPS * 4u, NOREG);
             imadw(e, pwn, inc, 1, pwc); imadw(e, psn, inc2, 1, psc);
         }
-        for (uint32_t j0 = 0; j0 < NJ; j0 += 4) {
-            const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4;
-            int xv[4], xa[4];
-            for (uint32_t q = 0; q < nj; q++) { xv[q] = V(e); xa[q] = V64(e); }
-            if (e->err) return -1;
-            for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); }
-            for (uint32_t q = 0; q < nj; q++) ldg32(e, xv[q], xa[q], udesc, q == 0);
-            if (prefetch && j0 == 0) {
+        if (XA) {
+            /* stage this step's x' words: they were loaded one step ago (the pass prologue for step 0), scoreboard 5 */
+            consume(e, 5);
+            for (uint32_t j = 0; j < NJ; j++) { imadi(e, sa, one, 0, j * T * 4u, sa0); sts32(e, sa, xv[j]); }
+            if (prefetch) {
                 ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn);
                 ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn);
+                /* the next step's x' words, into the registers the STS above has read (its SB_RD wait orders the two); the
+                 * last step of the last iteration re-reads its own step (nf 0), never past the rows */
+                if (!last) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); }
+                else { if (RM) imadi(e, xso, nf, 0, ROWW * 4u, xso); else imadw(e, xs, nf, ROWW * 4u, xs); }
+                x_prefetch(e, NJ, T, ROWW, K, RM, one, xs, xso, xb, xv, udesc);
+            }
+        } else {
+            /* the incumbent: this step's staging words loaded and stored inside the step, in rounds of 4 */
+            for (uint32_t j0 = 0; j0 < NJ; j0 += 4) {
+                const uint32_t nj = NJ - j0 < 4 ? NJ - j0 : 4;
+                int xw[4], xa[4];
+                for (uint32_t q = 0; q < nj; q++) { xw[q] = V(e); xa[q] = V64(e); }
+                if (e->err) return -1;
+                for (uint32_t q = 0; q < nj; q++) { const uint32_t pos = (j0 + q) * T; if (RM) imadw(e, xa[q], xso, 1u, xb[j0 + q]); else imadw(e, xa[q], one, ((pos / ROWW) * K + pos % ROWW) * 4u, xs); }
+                for (uint32_t q = 0; q < nj; q++) ldg32(e, xw[q], xa[q], udesc, q == 0);
+                if (prefetch && j0 == 0) {
+                    ldw_pf(e, ldw, wq[nxt], pwn, 0, udesc, sbn);
+                    ldw_pf(e, BW_IR_LDG_E, sc[nxt], psn, 0, udesc, sbn);
+                }
+                for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xw[q]); }
             }
-            for (uint32_t q = 0; q < nj; q++) { imadi(e, sa, one, 0, (j0 + q) * T * 4u, sa0); sts32(e, sa, xv[q]); }
         }
         bar_sync(e);
         consume(e, sbc);
@@ -319,7 +360,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
             else ffma(e, acc[m], dot[m], sc[cur], 0, acc[m]);
         }
         bar_sync(e);
-        if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs);
+        if (!XA) { if (RM) imadi(e, xso, one, 0, ROWW * 4u, xso); else imadw(e, xs, one, ROWW * 4u, xs); }
     }
     imadw(e, pwc, one, U * 32u * LB, pwc);
     imadw(e, psc, one, spec->mutant == 2 ? 0u : U * BPS * 4u, psc);
@@ -328,6 +369,7 @@ int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, Blackwell
     bra_if_p0(e, L_k);
     loop_end(e);
     consume(e, 3); consume(e, 4);
+    if (XA) consume(e, 5); /* the last step's re-read x' words land before their registers go out of scope */
 
     /* ---- reduce and store, per row of the pass ---- */
     for (uint32_t m = 0; m < MT; m++)
diff --git a/src/omega_blackwell_codegen_gemm.h b/src/omega_blackwell_codegen_gemm.h
index 74abbcfa..8e5220f4 100644
--- a/src/omega_blackwell_codegen_gemm.h
+++ b/src/omega_blackwell_codegen_gemm.h
@@ -18,7 +18,8 @@
  * stages one K step of MT rows (MT*32*LB*4 <= 16384 bytes: the QMD shared-memory limit of omega_blackwell_qmd.h) in
  * shared memory, so every lane reads its 4 columns of every row with one conflict-free LDS.128. Per step: stage,
  * BAR.SYNC, compute, BAR.SYNC. The weights and scales of step s+1 are loaded before step s computes (two register
- * sets, scoreboards 3 and 4 held until the step that uses them).
+ * sets, scoreboards 3 and 4 held until the step that uses them); with x_ahead 1 (L312 lever 3) so are the staging words
+ * of x' for step s+1 (scoreboard 5, stored at the start of the step that reads them): neither latency sits between the barriers.
  *
  * Segment table (device, 32 bytes per segment, ctaid.y = segment): { w_va u64, s_va u64, row0 u32, cnt u32, pad[8] }.
  * Constant bank 0 argument words (cbank + 0x380):
@@ -66,6 +67,9 @@ typedef struct {
                           * expert on the chip; the x' buffer holds one permuted row per head, the outputs land in head order). 0: the
                           * prefill form, x' row i and y row i are sorted row i. mt <= 4 (registers); the dense trunk of a stroke (one
                           * segment, the heads' rows in head order) needs no map and runs at mt 8. */
+    uint32_t x_ahead;    /* 1 (L312 lever 3): the staging words of x' for step s+1 are loaded during step s on scoreboard 5 and
+                          * stored at the start of the step that reads them; NJ = mt * lane_bytes / warps <= 16 (registers). 0: the
+                          * incumbent program, byte for byte (the staging words loaded inside the step that stores them). */
 } OmegaFp8GemmSpec;
 
 int omega_blackwell_codegen_fp8gemm_prog(const OmegaFp8GemmSpec *spec, BlackwellIRProgram *prog);
diff --git a/src/omega_gpu_fp8gemm_api.c b/src/omega_gpu_fp8gemm_api.c
index 6487abba..150a99d1 100644
--- a/src/omega_gpu_fp8gemm_api.c
+++ b/src/omega_gpu_fp8gemm_api.c
@@ -3,6 +3,7 @@
  * See the header. Submission path and buffer policy are the FP8 GEMV API's: every buffer both sides touch is
  * GPU-uncached (nvos.h NVOS32_ATTR2_GPU_CACHEABLE), one launch = omega_gpu_session_launch. */
 #include "omega_gpu_fp8gemm_api.h"
+#include "omega_gpu_fp8gemm_internal.h"
 #include "omega_gpu_session.h"
 #include "omega_gpu_cmdlist.h"
 #include "omega_gpu_fmt.h"
@@ -96,6 +97,14 @@ void omega_gpu_fp8gemm_shape_for(uint32_t k, uint32_t *mt, uint32_t *warps, uint
     if (mt) *mt = g.mt ? g.mt : 4u;
     if (warps) *warps = g.warps ? g.warps : 16u;
 }
+/* L312 lever 3: x' staging words one K step ahead, OFF unless AIEN_OMEGA_FP8GEMM_X_AHEAD=1 (read once; P-DRA-4 DRA-67:
+ * decode changes are env-gated, default off, until the stroke gate passes), and only where the NJ = mt * lane_bytes /
+ * warps staging words fit the registers the program holds for them (NJ <= 16); call after mt is final */
+static void x_ahead_for(OmegaFp8GemmSpec *spec) {
+    static int on = -1;
+    if (on < 0) { const char *e = getenv("AIEN_OMEGA_FP8GEMM_X_AHEAD"); on = (e && e[0] == '1' && e[1] == 0) ? 1 : 0; }
+    spec->x_ahead = on && spec->mt * spec->lane_bytes / spec->warps <= 16u ? 1u : 0u;
+}
 /* dense = a few distinct experts with many rows each (qkv, o): 8 rows per pass measured best there */
 static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) {
     memset(spec, 0, sizeof *spec);
@@ -103,6 +112,7 @@ static void spec_for(uint32_t k, uint32_t segs, OmegaFp8GemmSpec *spec) {
     omega_gpu_fp8gemm_shape_for(k, &spec->mt, &spec->warps, &spec->lane_bytes);
     if (!g.mt && segs < 8u) spec->mt = 8u;
     spec->mutant = g.mutant;
+    x_ahead_for(spec);
 }
 
 static int g_rec; /* 1 while a record call runs (lock held): kernel_for must not evict */
@@ -210,6 +220,10 @@ static void spec_for_stroke(uint32_t k, uint32_t segs, uint32_t mt, int rowmap,
     spec_for(k, segs, spec);
     if (mt) spec->mt = mt;
     spec->rowmap = rowmap ? 1u : 0u;
+    x_ahead_for(spec);
+}
+void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec) {
+    spec_for_stroke(k, segs, mt, rowmap, spec);
 }
 int omega_gpu_fp8gemm_prepare_shape(uint32_t k, uint32_t segs, uint32_t mt, int rowmap) {
     OmegaFp8GemmSpec spec; spec_for_stroke(k, segs, mt, rowmap, &spec);
diff --git a/src/omega_gpu_fp8gemm_internal.h b/src/omega_gpu_fp8gemm_internal.h
new file mode 100644
index 00000000..31b7f1ea
--- /dev/null
+++ b/src/omega_gpu_fp8gemm_internal.h
@@ -0,0 +1,9 @@
+#ifndef OMEGA_GPU_FP8GEMM_INTERNAL_H
+#define OMEGA_GPU_FP8GEMM_INTERNAL_H
+/* Library-internal view of omega_gpu_fp8gemm_api.c for the host tests. Not part of the public ABI (no manifest entry). */
+#include "omega_blackwell_codegen_gemm.h"
+#include <stdint.h>
+/* The program spec omega_gpu_fp8gemm_prepare_shape / _record would build for (k, segs, mt, rowmap) under the process's
+ * environment and setters (AIEN_OMEGA_FP8GEMM_X_AHEAD, omega_gpu_fp8gemm_set_shape, ...). Host only: opens no device. */
+void omega_gpu_fp8gemm_stroke_spec(uint32_t k, uint32_t segs, uint32_t mt, int rowmap, OmegaFp8GemmSpec *spec);
+#endif
diff --git a/tests/bw_hazard_test.c b/tests/bw_hazard_test.c
index e052b090..eb54a7e4 100644
--- a/tests/bw_hazard_test.c
+++ b/tests/bw_hazard_test.c
@@ -416,11 +416,12 @@ static void sweep(void) {
           snprintf(v, sizeof v, "k%u rows%u warps%u depth%u", ks[a], rows, w, dp);
           if (BUILD(omega_blackwell_codegen_bf16_gemv_prog(&s, &g_prog))) sweep_prog("bf16_gemv", v, P_NONE);
       } }
-    /* fp8 grouped GEMM */
-    { unsigned ks[] = { 768, 2048, 4096 };
-      for (unsigned a = 0; a < 3; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2) {
-          OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w };
-          snprintf(v, sizeof v, "k%u lane%u mt%u warps%u", ks[a], lb, mt, w);
+    /* fp8 grouped GEMM: the incumbent, rowmap (the stroke's expert form) and x_ahead (L312 lever 3, scoreboard 5) */
+    { unsigned ks[] = { 512, 768, 2048, 4096 };
+      for (unsigned a = 0; a < 4; a++) for (unsigned lb = 8; lb <= 16; lb += 8) for (unsigned mt = 1; mt <= 16; mt *= 2) for (unsigned w = 1; w <= 32; w *= 2)
+      for (unsigned rm = 0; rm <= 1; rm++) for (unsigned xa = 0; xa <= 1; xa++) {
+          OmegaFp8GemmSpec s = { .k = ks[a], .lane_bytes = lb, .mt = mt, .warps = w, .rowmap = rm, .x_ahead = xa };
+          snprintf(v, sizeof v, "k%u lane%u mt%u warps%u%s%s", ks[a], lb, mt, w, rm ? " rowmap" : "", xa ? " x_ahead" : "");
           if (BUILD(omega_blackwell_codegen_fp8gemm_prog(&s, &g_prog))) sweep_prog("fp8gemm", v, P_NONE);
       } }
     /* ternary GEMV */
diff --git a/tests/gpu_fp8gemm_test.c b/tests/gpu_fp8gemm_test.c
index 988d8a24..6ca2302a 100644
--- a/tests/gpu_fp8gemm_test.c
+++ b/tests/gpu_fp8gemm_test.c
@@ -12,6 +12,7 @@
  * Verdict line last: "gpu_fp8gemm_test: N checks, F failed: PASS|FAIL".
  */
 #include "omega_gpu_fp8gemm_api.h"
+#include "omega_gpu_fp8gemm_internal.h"
 #include "omega_gpu_fp8_api.h"
 #include "omega_gpu_session.h"
 #include "bw_warp_sim_k.h"
@@ -118,19 +119,35 @@ static void host_only(void) {
       CHECK(p[(1 * 32 + 5) * 4 + 2] / 18446744073709551616.0f == x[86], "column 86 sits at lane 5 word 1 element 2"); }
     struct { uint32_t k, lb, mt, w; } shp[] = { { 2048, 16, 8, 16 }, { 4096, 16, 8, 16 }, { 1024, 16, 8, 16 }, { 768, 8, 8, 16 }, { 768, 8, 8, 8 }, { 2048, 8, 8, 16 }, { 2048, 16, 4, 16 }, { 2048, 16, 8, 32 }, { 2048, 16, 8, 8 }, { 2048, 16, 4, 8 }, { 4096, 16, 4, 8 } };
     for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) for (int m = 0; m <= 3; m++) {
-        OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0 }; uint32_t n = 0, gp = 0;
+        OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, m, 0, 0 }; uint32_t n = 0, gp = 0;
         int rc = omega_fp8gemm_prog_stats(&s, &n, &gp);
         uint32_t decl = ((gp + 1 + 7) / 8) * 8;
         CHECK(rc == 0 && n <= 1024, "codegen k %u lb %u mt %u warps %u mutant %d: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, m, rc, n, gp);
         if (m == 0 && rc == 0) printf("codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u, register file %u of 65536)%s, shared %u B\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT", omega_fp8gemm_shared_bytes(&s));
     }
-    { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); }
-    { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); }
-    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 5, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 5 refused"); }
-    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); }
-    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 16, 16, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 16 at lane 16 refused (32 KB of shared memory)"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 6, 16, 0, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mt 6 refused"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 5, 0, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "mutant 5 refused"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 2, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap 2 refused"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 1, 0 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "rowmap at mt 8 refused (registers)"); }
+    /* L312 lever 3 (x_ahead): every shape above and the rowmap form at mt 4 build with the NJ prefetch registers (fit is
+     * printed as above: warps 32 does not fit either way); NJ > 16 and x_ahead 2 are refused */
+    for (unsigned i = 0; i < sizeof shp / sizeof shp[0]; i++) {
+        OmegaFp8GemmSpec s = { shp[i].k, shp[i].lb, shp[i].mt, shp[i].w, 0, 0, 1 }; uint32_t n = 0, gp = 0;
+        int rc = omega_fp8gemm_prog_stats(&s, &n, &gp);
+        uint32_t decl = ((gp + 1 + 7) / 8) * 8;
+        CHECK(rc == 0 && n <= 1024, "x_ahead codegen k %u lb %u mt %u warps %u: rc %d insns %u gprs %u", s.k, s.lane_bytes, s.mt, s.warps, rc, n, gp);
+        if (rc == 0) printf("x_ahead codegen k %4u lane %2u mt %2u warps %2u: %u instructions, %u registers (declared %u)%s\n", s.k, s.lane_bytes, s.mt, s.warps, n, gp, decl, 32u * s.warps * decl <= 65536u ? "" : " DOES NOT FIT");
+    }
+    { OmegaFp8GemmSpec s = { 2048, 16, 4, 16, 0, 1, 1 }; uint32_t n = 0, gp = 0; int rc = omega_fp8gemm_prog_stats(&s, &n, &gp);
+      uint32_t decl = ((gp + 1 + 7) / 8) * 8;
+      CHECK(rc == 0 && 32u * s.warps * decl <= 65536u, "x_ahead rowmap mt 4: rc %d gprs %u", rc, gp);
+      printf("x_ahead codegen k 2048 lane 16 mt  4 warps 16 rowmap: %u instructions, %u registers (declared %u)\n", n, gp, decl); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 8, 4, 0, 0, 1 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead at NJ 32 refused (registers)");
+      s.x_ahead = 0; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) == 0, "the same shape without x_ahead is accepted"); }
+    { OmegaFp8GemmSpec s = { 2048, 16, 8, 16, 0, 0, 2 }; CHECK(omega_fp8gemm_prog_stats(&s, NULL, NULL) != 0, "x_ahead 2 refused"); }
     { uint32_t ks[] = { 2048, 4096, 512, 768 }; for (unsigned i = 0; i < 4; i++) {
-        OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1 }; uint32_t n = 0, gp = 0;
+        OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, 4, 16, 0, 1, 0 }; uint32_t n = 0, gp = 0;
         int rc = omega_fp8gemm_prog_stats(&s, &n, &gp);
         uint32_t decl = ((gp + 1 + 7) / 8) * 8;
         CHECK(rc == 0 && n <= 1024 && 32u * s.warps * decl <= 65536u, "codegen k %u mt 4 rowmap: rc %d insns %u gprs %u", ks[i], rc, n, gp);
@@ -143,10 +160,11 @@ static void host_only(void) {
 
 /* ------------------------------------------------------------- simulator */
 static uint64_t g_sim_issues;
+static uint32_t g_xa; /* the battery runs once with x_ahead 0 (the incumbent) and once with x_ahead 1 (L312 lever 3) */
 typedef struct { uint32_t k, n, lb, mt, w, grid; uint32_t counts[4]; uint32_t nseg; } SimPt;
 static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_t msgn, size_t *bad) {
     static BlackwellIRProgram prog;
-    OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0 };
+    OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, 0, g_xa };
     if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; }
     uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g];
     Weights W; weights_make(&W, p->nseg, p->n, p->k, seed);
@@ -198,7 +216,7 @@ static int sim_point(const SimPt *p, int mutant, uint32_t seed, char *msg, size_
  * result must equal the emulation moved through YMAP and differ from the unmoved one. budget: the simulator's step budget. */
 static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int empty_at, uint64_t budget, char *msg, size_t msgn, size_t *bad, int *moved) {
     static BlackwellIRProgram prog;
-    OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap };
+    OmegaFp8GemmSpec spec = { p->k, p->lb, p->mt, p->w, mutant, (uint32_t)rowmap, g_xa };
     if (omega_blackwell_codegen_fp8gemm_prog(&spec, &prog) != 0) { snprintf(msg, msgn, "codegen refused"); return -1; }
     uint32_t M = 0; for (uint32_t g = 0; g < p->nseg; g++) M += p->counts[g];
     Weights W; weights_make(&W, p->nseg, p->n, p->k, seed);
@@ -268,7 +286,8 @@ static int sim_point2(const SimPt *p, int mutant, uint32_t seed, int rowmap, int
     return err;
 }
 
-static void sim_battery(void) {
+static void sim_battery_one(void) {
+    printf("sim battery, x_ahead %u\n", g_xa);
     SimPt pts[] = {
         { 2048, 40, 16, 8, 16, 2, { 1, 5, 9 }, 3 },           /* lane 16, KS 4 (2 iterations), 2 passes in segment 3, row clamping (n 40 < 2 x 32 x 1) */
         { 4096, 20, 16, 8, 16, 1, { 3, 8 }, 2 },              /* KS 8: 4 iterations */
@@ -325,6 +344,7 @@ static void sim_battery(void) {
     }
     printf("sim: %" PRIu64 " warp issues in total\n", g_sim_issues);
 }
+static void sim_battery(void) { for (g_xa = 0; g_xa <= 1; g_xa++) sim_battery_one(); }
 
 /* ------------------------------------------------------------- chip */
 static int g_evict = 1;
@@ -394,6 +414,7 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) {
             if (rc != 0) printf("chip mutant %d: call returned %s: %s\n", m, omega_gpu_fp8gemm_rc_name(rc), omega_gpu_fp8gemm_last_error());
             int caught = rc == 0 && b != 0;
             if (m == 2 && info.k / (32u * info.lane_bytes) < 2) caught = 1; /* single-step k: mutant 2 has no effect by construction */
+            if (m == 3 && info.mt < 2) caught = 1;                           /* one row per pass (--mt 1): mutant 3 has no neighbour row */
             CHECK(caught, "%s: chip mutant %d must be caught", S->name, m);
             printf("chip mutant %d: %s (%zu of %zu outputs differ)\n", m, caught ? "caught" : "NOT CAUGHT", b, (size_t)M * S->n);
             if (g_out) fprintf(g_out, "%s{\"point\":\"%s mutant %d\",\"caught\":%d}", g_first ? "" : ",", S->name, m, caught), g_first = 0;
@@ -436,8 +457,27 @@ static void run_shape(const Shape *S, uint32_t reps, uint32_t seed) {
     free(ids); free(trow); free(picks); free(x); free(y); free(yref); free(y2); weights_free(&W);
 }
 
+/* --spec-of K,SEGS,MT,ROWMAP: the spec the stroke path resolves under this process's environment, printed as one line;
+ * with --expect "f=v ...", every listed field must hold (the env-gate checks of the decode levers: default off). */
+static int spec_of(const char *arg, const char *expect) {
+    unsigned k = 0, segs = 0, mt = 0, rowmap = 0;
+    if (sscanf(arg, "%u,%u,%u,%u", &k, &segs, &mt, &rowmap) != 4) { printf("spec-of: bad argument %s\n", arg); return 2; }
+    OmegaFp8GemmSpec s; omega_gpu_fp8gemm_stroke_spec(k, segs, mt, (int)rowmap, &s);
+    char line[256];
+    snprintf(line, sizeof line, " k=%u lane_bytes=%u mt=%u warps=%u mutant=%d rowmap=%u x_ahead=%u ", s.k, s.lane_bytes, s.mt, s.warps, s.mutant, s.rowmap, s.x_ahead);
+    printf("spec-of %s:%s\n", arg, line);
+    if (!expect) return 0;
+    char want[64]; const char *p = expect; int n = 0, bad = 0;
+    while (sscanf(p, " %62s%n", want + 1, &n) == 1) {
+        want[0] = ' '; size_t w = strlen(want); want[w] = ' '; want[w + 1] = 0;
+        g_checks++; if (!strstr(line, want)) { g_failed++; bad = 1; printf("spec-of %s: FAIL expected%s\n", arg, want); }
+        p += n;
+    }
+    return bad;
+}
+
 int main(int argc, char **argv) {
-    int host = 0, sim = 0; const char *out_path = NULL, *shape = "all"; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64;
+    int host = 0, sim = 0; const char *out_path = NULL, *shape = "all", *spec_arg = NULL, *expect = NULL; uint32_t reps = 0, mt = 0, warps = 0, ctas = 0, spin = 2000, tokens = 64;
     for (int i = 1; i < argc; i++) {
         if (strcmp(argv[i], "--host-only") == 0) host = 1;
         else if (strcmp(argv[i], "--sim") == 0) sim = 1;
@@ -450,11 +490,20 @@ int main(int argc, char **argv) {
         else if (strcmp(argv[i], "--tokens") == 0 && i + 1 < argc) tokens = (uint32_t)atoi(argv[++i]);
         else if (strcmp(argv[i], "--spin-us") == 0 && i + 1 < argc) spin = (uint32_t)atoi(argv[++i]);
         else if (strcmp(argv[i], "--no-evict") == 0) g_evict = 0;
+        else if (strcmp(argv[i], "--spec-of") == 0 && i + 1 < argc) spec_arg = argv[++i];
+        else if (strcmp(argv[i], "--expect") == 0 && i + 1 < argc) expect = argv[++i];
         else { printf("unknown argument %s\n", argv[i]); return 2; }
     }
-    Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 } };
+    if (spec_arg) {
+        if (mt || warps) omega_gpu_fp8gemm_set_shape(mt, warps);
+        int rc = spec_of(spec_arg, expect);
+        if (rc == 2 || !expect) return rc;
+        printf("gpu_fp8gemm_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS");
+        return g_failed ? 1 : 0;
+    }
+    Shape shapes[] = { { "gateup", 128, 1536, 2048, tokens, 8 }, { "down", 128, 2048, 768, tokens, 8 }, { "qkv", 1, 5120, 2048, tokens, 1 }, { "o", 1, 2048, 4096, tokens, 1 }, { "d768", 1, 2048, 768, tokens, 1 }, { "mix", 1, 12288, 2048, tokens, 1 } };
     unsigned selected = 0;
-    for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++;
+    for (unsigned i = 0; i < 6; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) selected++;
     if (!selected) { fprintf(stderr, "gpu_fp8gemm_test: INVALID shape '%s'\n", shape); return 2; }
     if (host) host_only();
     if (sim) sim_battery();
@@ -463,7 +512,7 @@ int main(int argc, char **argv) {
         if (ctas) omega_gpu_fp8gemm_set_cta_budget(ctas);
         (void)omega_gpu_session_set_spin_us(spin);
         if (out_path) { g_out = test_out_open(out_path); if (g_out) fprintf(g_out, "{\"receipt\":\"OMEGA_GPU_FP8GEMM_V1\",\"reps\":%u,\"evict\":%d,\"tokens\":%u,\"spin_us\":%u,\"points\":[", reps ? reps : 1, g_evict, tokens, omega_gpu_session_spin_us()); }
-        for (unsigned i = 0; i < 5; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i);
+        for (unsigned i = 0; i < 6; i++) if ((!strcmp(shape, "all") && i < 4) || !strcmp(shape, shapes[i].name)) run_shape(&shapes[i], reps ? reps : 1, 1000 + i);
         if (g_out) { fprintf(g_out, "],\"checks\":%d,\"failed\":%d,\"verdict\":\"%s\"}\n", g_checks, g_failed, !g_checks ? "NOT_RUN" : g_failed ? "FAIL" : "PASS"); fclose(g_out); }
         omega_gpu_session_close();
     }
diff --git a/tests/gpu_gpr_boundary_test.c b/tests/gpu_gpr_boundary_test.c
index 21046454..34428ec9 100644
--- a/tests/gpu_gpr_boundary_test.c
+++ b/tests/gpu_gpr_boundary_test.c
@@ -56,11 +56,11 @@ int main(void) {
     { unsigned ks[] = { 2048, 4096 }; for (unsigned i = 0; i < 2; i++) { OmegaBf16GemvSpec s; memset(&s, 0, sizeof s); s.k = ks[i]; uint32_t c; omega_gpu_bf16_shape_for(s.k, &s.rows, &s.warps, &s.depth, &c);
         uint32_t peak = 0, decl = 0; CHECK(omega_bf16_gemv_prog_stats(&s, NULL, &peak) == 0, "bf16 k%u builds", ks[i]); (void)omega_gpu_bf16_kernel_fits(&s, &decl);
         CHECK(omega_bw_gpr_declared_ok(decl, peak), "bf16 gemv k%u: peak %u declared %u", ks[i], peak, decl); } }
-    /* fp8 grouped GEMM (all shapes we launch) */
-    { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) {
-        OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0 }; uint32_t peak = 0, decl = 0;
-        CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u builds", ks[i], mts[j]); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl);
-        CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u: peak %u declared %u", ks[i], mts[j], peak, decl); } }
+    /* fp8 grouped GEMM (all shapes we launch, with and without the L312 lever 3 x' prefetch) */
+    { unsigned ks[] = { 2048, 768, 4096 }, mts[] = { 4, 8 }; for (unsigned xa = 0; xa < 2; xa++) for (unsigned i = 0; i < 3; i++) for (unsigned j = 0; j < 2; j++) {
+        OmegaFp8GemmSpec s = { ks[i], ks[i] % 512 ? 8u : 16u, mts[j], 16, 0, 0, xa }; uint32_t peak = 0, decl = 0;
+        CHECK(omega_fp8gemm_prog_stats(&s, NULL, &peak) == 0, "gemm k%u mt%u x_ahead %u builds", ks[i], mts[j], xa); (void)omega_gpu_fp8gemm_kernel_fits(&s, &decl);
+        CHECK(omega_bw_gpr_declared_ok(decl, peak), "gemm k%u mt%u x_ahead %u: peak %u declared %u", ks[i], mts[j], xa, peak, decl); } }
     /* router and decode attention: the launcher uses omega_bw_gpr_declared(peak) (static), so check the helper on the real peak */
     { OmegaRouterSpec s = { .warps = OMEGA_GPU_ROUTER_WARPS, .depth = OMEGA_GPU_ROUTER_DEPTH }; uint32_t peak = 0;
       CHECK(omega_router_prog_stats(&s, NULL, &peak) == 0 && omega_bw_gpr_declared_ok(omega_bw_gpr_declared(peak), peak), "router peak %u", peak); printf("router peak %u -> declared %u\n", peak, omega_bw_gpr_declared(peak)); }