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#222 (code only)

closed derived 25b68b0af6d89366 #222

Imported from GitHub aien-dev/CUDApp#222 (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 b4c414d01233a27893009ddfe069a44f4013ad21

Apply it

git checkout -b patch-25b68b0af6d89366 4bbccf084b7309ae89e126c890324e377478b3be
curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/25b68b0af6d89366.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
222
b4c414d01233a27893009ddfe069a44f4013ad21
{"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":222,"url":"https://github.com/aien-dev/CUDApp/pull/222","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:55Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/src/omega_blackwell_codegen_gdn.c b/src/omega_blackwell_codegen_gdn.c
index c1abd4c6..63350f10 100644
--- a/src/omega_blackwell_codegen_gdn.c
+++ b/src/omega_blackwell_codegen_gdn.c
@@ -118,6 +118,15 @@ static void bf16x4_pack(Em *e, int w, int q) {
     f2fp(e, S(w, 0), S(q, 1), S(q, 0));
     f2fp(e, S(w, 1), S(q, 3), S(q, 2));
 }
+/* Four f32 (q) to bf16 at addr64 + imm (two STG.E). Mutant OMEGA_GDN_MUT_BF16_TRUNC (DRA-76, test only) clears the low 4
+ * of each bf16's 7 mantissa bits after the rounding: the stored state keeps 3 bits, rounded toward zero. */
+static void bf16x4_store(Em *e, int w, int q, int addr64, uint32_t imm, int udesc, int mut) {
+    bf16x4_pack(e, w, q);
+    for (unsigned k = 0; k < 2; k++) {
+        if (mut == OMEGA_GDN_MUT_BF16_TRUNC) andi(e, S(w, k), S(w, k), 0xfff0fff0u);
+        stg(e, addr64, imm + k * 4u, S(w, k), udesc);
+    }
+}
 static void lds128(Em *e, int d128, int addr, uint32_t imm, int first) { BlackwellIRInsn i = I0(BW_IR_LDS128); i.dst_vreg = d128; i.src1_vreg = addr; i.imm = imm; emit(e, i, first ? K_VAR : K_VAR_MORE); }
 static void lds32(Em *e, Op d, int addr, int first) { BlackwellIRInsn i = I0(BW_IR_LDS32); i.dst_vreg = d.v; i.dst_subreg = (uint8_t)d.s; i.src1_vreg = addr; emit(e, i, first ? K_VAR : K_VAR_MORE); }
 static void sts32(Em *e, int addr, Op val) { BlackwellIRInsn i = I0(BW_IR_STS32); i.src1_vreg = addr; i.src2_vreg = val.v; i.src2_subreg = (uint8_t)val.s; emit(e, i, K_STORE); }
@@ -216,8 +225,14 @@ int omega_gdn_shape(const OmegaGdnSpec *spec, OmegaGdnShape *s) {
     return 0;
 }
 
+/* The mutants a GDN program accepts: 0..4 everywhere, OMEGA_GDN_MUT_BF16_TRUNC only with the bf16 state (the programs
+ * that do not store the state ignore it). */
+static int mutant_ok(const OmegaGdnSpec *spec) {
+    return spec->mutant >= 0 && (spec->mutant <= 4 || (spec->mutant == OMEGA_GDN_MUT_BF16_TRUNC && spec->state_bf16));
+}
+
 int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) {
-    if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1;
+    if (!spec || !prog || spec->copy || !mutant_ok(spec)) return -1;
     OmegaGdnShape G;
     if (omega_gdn_shape(spec, &G)) return -1;
     const uint32_t RR = G.r, NC = 2u + G.r;
@@ -381,10 +396,7 @@ int omega_blackwell_codegen_gdn_prog(const OmegaGdnSpec *spec, BlackwellIRProgra
         int pk[16];
         for (unsigned r = 0; r < 16; r++) pk[r] = V64(e);
         if (e->err) return -1;
-        for (unsigned r = 0; r < 16; r++) {
-            bf16x4_pack(e, pk[r], sq[r]);
-            for (unsigned w = 0; w < 2; w++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 2u + w * 4u, S(pk[r], w), udesc);
-        }
+        for (unsigned r = 0; r < 16; r++) bf16x4_store(e, pk[r], sq[r], sa, r * OMEGA_GDN_HEAD_DIM * 2u, udesc, MUT);
     } else {
         for (unsigned r = 0; r < 16; r++) for (unsigned j = 0; j < 4; j++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 4u + j * 4u, S(sq[r], j), udesc);
     }
@@ -499,7 +511,7 @@ static void gdn_scalars(Em *e, int MUT, int abq, int scq, int dec, int beta, int
 }
 
 int omega_blackwell_codegen_gdn_prep_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) {
-    if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1;
+    if (!spec || !prog || spec->copy || !mutant_ok(spec)) return -1;
     OmegaGdnShape G;
     if (omega_gdn_shape(spec, &G)) return -1;
     const uint32_t RR = G.r, NC = 2u + G.r;
@@ -662,7 +674,7 @@ int omega_blackwell_codegen_gdn_prep_prog(const OmegaGdnSpec *spec, BlackwellIRP
 }
 
 int omega_blackwell_codegen_gdn_scan_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) {
-    if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1;
+    if (!spec || !prog || spec->copy || !mutant_ok(spec)) return -1;
     OmegaGdnShape G;
     if (omega_gdn_shape(spec, &G)) return -1;
     const uint32_t RR = G.r, NC = 2u + G.r;
@@ -791,10 +803,7 @@ int omega_blackwell_codegen_gdn_scan_prog(const OmegaGdnSpec *spec, BlackwellIRP
         int pk[16];
         for (unsigned r = 0; r < 16; r++) pk[r] = V64(e);
         if (e->err) return -1;
-        for (unsigned r = 0; r < 16; r++) {
-            bf16x4_pack(e, pk[r], sq[r]);
-            for (unsigned w = 0; w < 2; w++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 2u + w * 4u, S(pk[r], w), udesc);
-        }
+        for (unsigned r = 0; r < 16; r++) bf16x4_store(e, pk[r], sq[r], sa, r * OMEGA_GDN_HEAD_DIM * 2u, udesc, MUT);
     } else {
         for (unsigned r = 0; r < 16; r++) for (unsigned j = 0; j < 4; j++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 4u + j * 4u, S(sq[r], j), udesc);
     }
@@ -827,7 +836,7 @@ int omega_blackwell_codegen_gdn_scan_prog(const OmegaGdnSpec *spec, BlackwellIRP
 }
 
 int omega_blackwell_codegen_gdn_post_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) {
-    if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1;
+    if (!spec || !prog || spec->copy || !mutant_ok(spec)) return -1;
     OmegaGdnShape G;
     if (omega_gdn_shape(spec, &G)) return -1;
     const uint32_t RR = G.r, NC = 2u + G.r;
@@ -904,7 +913,7 @@ int omega_gdn_pf_prog_stats(unsigned kind, const OmegaGdnSpec *spec, uint32_t *i
  * it), the conv tails are shifted in registers (one load, one store), and the loop-invariant loads (conv taps, negA and
  * dt_bias, the norm weight) are issued once. */
 int omega_blackwell_codegen_gdn_multi_prog(const OmegaGdnSpec *spec, BlackwellIRProgram *prog) {
-    if (!spec || !prog || spec->copy || spec->mutant < 0 || spec->mutant > 4) return -1;
+    if (!spec || !prog || spec->copy || !mutant_ok(spec)) return -1;
     OmegaGdnShape G;
     if (omega_gdn_shape(spec, &G)) return -1;
     const uint32_t RR = G.r;
@@ -930,9 +939,12 @@ int omega_blackwell_codegen_gdn_multi_prog(const OmegaGdnSpec *spec, BlackwellIR
     imadi(e, R(h), R(cy), RR, cx);
     shr(e, warp, tid, 5);
     andi(e, R(lane), R(tid), 31u);
-    imadi(e, R(toff), R(h), OMEGA_GDN_STATE_HEAD_BYTES, NOREG);
-    imadi(e, R(toff), R(warp), 16u * OMEGA_GDN_HEAD_DIM * 4u, toff);
-    imadi(e, R(toff), R(lane), 16u, toff);
+    /* the state element size: 4 (f32) or 2 (bf16, L313), as the decode program; this thread holds rows 16 warp .. +15,
+     * columns 4 lane .. +3 */
+    const unsigned sel = spec->state_bf16 ? 2u : 4u;
+    imadi(e, R(toff), R(h), OMEGA_GDN_HEAD_DIM * OMEGA_GDN_HEAD_DIM * sel, NOREG);
+    imadi(e, R(toff), R(warp), 16u * OMEGA_GDN_HEAD_DIM * sel, toff);
+    imadi(e, R(toff), R(lane), 4u * sel, toff);
     imadw(e, sa, toff, 1u, ps);
     ldc32(e, T, OMEGA_GDN_MULTI_ARG_T); ldc32(e, xs, OMEGA_GDN_MULTI_ARG_XSTRIDE);
     ldc32(e, abs_, OMEGA_GDN_MULTI_ARG_ABSTRIDE); ldc32(e, os, OMEGA_GDN_MULTI_ARG_OSTRIDE);
@@ -975,9 +987,17 @@ int omega_blackwell_codegen_gdn_multi_prog(const OmegaGdnSpec *spec, BlackwellIR
     ldg_wide(e, BW_IR_LDG_E_128, tV, atV, 0, udesc, 0);
     ldg_wide(e, BW_IR_LDG_E_64, scq, asc, G.par_scal, udesc, 0);
     ldg_wide(e, BW_IR_LDG_E_128, nq, an, G.par_norm, udesc, 0);
-    for (unsigned r = 0; r < 16; r++) ldg_pf(e, sq[r], sa, r * OMEGA_GDN_HEAD_DIM * 4u, udesc, SB_STATE);
+    int sw[16];
+    if (spec->state_bf16) {
+        for (unsigned r = 0; r < 16; r++) sw[r] = V64(e);
+        if (e->err) return -1;
+        for (unsigned r = 0; r < 16; r++) ldg_pf64(e, sw[r], sa, r * OMEGA_GDN_HEAD_DIM * 2u, udesc, SB_STATE);
+    } else {
+        for (unsigned r = 0; r < 16; r++) ldg_pf(e, sq[r], sa, r * OMEGA_GDN_HEAD_DIM * 4u, udesc, SB_STATE);
+    }
     movi(e, cnl2e, C_NLOG2E); movi(e, fone, C_ONE); movi(e, cl2e, C_LOG2E);
     consume(e, SB_STATE);
+    if (spec->state_bf16) for (unsigned r = 0; r < 16; r++) bf16x4_widen(e, sq[r], sw[r]); /* exact; S stays f32 in the loop */
     movrz(e, R(t)); /* waits for every load above: the loop is entered with nothing pending */
 
     const int L = here(e);
@@ -1110,8 +1130,15 @@ int omega_blackwell_codegen_gdn_multi_prog(const OmegaGdnSpec *spec, BlackwellIR
     }
     loop_end(e);
 
-    /* ---- the state and the tails back to memory, once ---- */
-    for (unsigned r = 0; r < 16; r++) for (unsigned j = 0; j < 4; j++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 4u + j * 4u, S(sq[r], j), udesc);
+    /* ---- the state and the tails back to memory, once (bf16: one round to nearest even for the T tokens, as the scan) ---- */
+    if (spec->state_bf16) {
+        int pk[16];
+        for (unsigned r = 0; r < 16; r++) pk[r] = V64(e);
+        if (e->err) return -1;
+        for (unsigned r = 0; r < 16; r++) bf16x4_store(e, pk[r], sq[r], sa, r * OMEGA_GDN_HEAD_DIM * 2u, udesc, MUT);
+    } else {
+        for (unsigned r = 0; r < 16; r++) for (unsigned j = 0; j < 4; j++) stg(e, sa, r * OMEGA_GDN_HEAD_DIM * 4u + j * 4u, S(sq[r], j), udesc);
+    }
     if (MUT != 4) {
         stg(e, atA, 0, S(tA, 0), udesc); stg(e, atA, 4, S(tA, 1), udesc); stg(e, atA, 8, S(tA, 2), udesc);
         stg(e, atV, 0, S(tV, 0), udesc); stg(e, atV, 4, S(tV, 1), udesc); stg(e, atV, 8, S(tV, 2), udesc);
diff --git a/src/omega_blackwell_codegen_gdn.h b/src/omega_blackwell_codegen_gdn.h
index d82e7c97..5cc4b9b5 100644
--- a/src/omega_blackwell_codegen_gdn.h
+++ b/src/omega_blackwell_codegen_gdn.h
@@ -79,15 +79,21 @@
 #define OMEGA_GDN_THREADS 256u
 #define OMEGA_GDN_GRID_X 3u
 #define OMEGA_GDN_GRID_Y 16u
+/* DRA-76 test mutant: the bf16 state store keeps 3 of the 7 mantissa bits (the low 4 cleared after the rounding). Only
+ * with state_bf16 = 1; the programs that store the state (decode, scan, multi) apply it, prep and post ignore it. */
+#define OMEGA_GDN_MUT_BF16_TRUNC 5
 
 typedef struct {
     int mutant; /* TEST ONLY. 0 none; 1 no decay (decay = 1); 2 beta = 1; 3 the output gate is z, not silu(z);
-                 * 4 the conv tail is not shifted (the next step convolves stale history). */
+                 * 4 the conv tail is not shifted (the next step convolves stale history); OMEGA_GDN_MUT_BF16_TRUNC (5). */
     int copy;   /* 0: the GDN kernels. OMEGA_GDN_COPY / OMEGA_GDN_ZERO: omega_blackwell_codegen_gdn_copy_prog */
     uint32_t ratio; /* value heads per key head (16 key heads): 0 = 3 (Qwen3.8-27B, 48 value heads, the program before
                      * this field existed); 2 = Qwen3.6-35B-A3B (32 value heads, conv 8192). Appended last. */
     uint32_t state_bf16; /* L313: 1 = the state is stored bf16 (round to nearest even on store, exact widen on load), half the
-                          * bytes; compute stays f32. 0 = f32 (the program before this field existed). Appended last. */
+                          * bytes; compute stays f32. 0 = f32 (the program before this field existed). Appended last. The
+                          * decode program rounds after every token; scan and multi widen once, run their T tokens in f32
+                          * registers and round once at the end (multi: DRA-76; before it the multi program read and wrote
+                          * the bf16 state as f32). */
 } OmegaGdnSpec;
 
 /* The shape a spec selects (Q36, sc L306). The 27B constants above are the ratio-3 values. */
@@ -109,7 +115,9 @@ int omega_gdn_prog_stats(const OmegaGdnSpec *spec, uint32_t *insns, uint32_t *gp
  * T times (omega_blackwell_codegen_gdn.c). Same grid, threads, shared memory and argument block as the decode step plus
  * the four words below; token t reads qkv + t * xstride, z + t * xstride, ab + t * abstride and writes out + t * ostride
  * (bytes). Per CTA the state S stays in the 64 registers and the conv tails in registers for the whole loop (one load
- * before it, one store after it); the per-token arithmetic is the decode step's, instruction for instruction. T >= 1. */
+ * before it, one store after it); the per-token arithmetic is the decode step's, instruction for instruction. T >= 1.
+ * With state_bf16 the state is widened once and rounded once (DRA-76), so a bf16 multi launch equals the f32 multi launch
+ * from the widened state with the final state rounded, not T bf16 decode steps (those round after every token). */
 #define OMEGA_GDN_MULTI_ARG_T 0x3c8u        /* u32 tokens */
 #define OMEGA_GDN_MULTI_ARG_XSTRIDE 0x3ccu  /* u32 bytes between the qkv rows (and the z rows) of consecutive tokens */
 #define OMEGA_GDN_MULTI_ARG_ABSTRIDE 0x3d0u /* u32 bytes between the ab rows */
diff --git a/src/omega_gpu_gdn_api.c b/src/omega_gpu_gdn_api.c
index c8fd2be4..65f69bff 100644
--- a/src/omega_gpu_gdn_api.c
+++ b/src/omega_gpu_gdn_api.c
@@ -36,6 +36,8 @@ struct OmegaGpuGdn {
     OmegaGpuMem lb;    /* launch buffer */
     int cached;        /* tail and state GPU-cached: the host reaches them only through the chip (reset, stage) */
     int bf16;          /* L313: the state is stored bf16 (AIEN_OMEGA_GDN_STATE_BF16=1 at alloc); set/get_state keep the f32 layout */
+    int state_mutant;  /* DRA-76, TEST ONLY: AIEN_OMEGA_GDN_STATE_MUTANT at alloc (0 off; 1 no decay; 5 OMEGA_GDN_MUT_BF16_TRUNC),
+                        * bf16 state only; a process-wide omega_gpu_gdn_test_set_mutant takes precedence */
     OmegaGpuMem stage; /* cached: uncached staging for set_state / get_state, [state of one layer][tail of one layer] */
     OmegaGpuScratch pf; /* prefill scratch (see pf_layout) */
 };
@@ -146,17 +148,35 @@ static int zero_ts_locked(OmegaGpuGdn *g);
 static int move_locked(unsigned kind, uint64_t src, uint64_t dst, size_t bytes);
 int omega_gpu_gdn_alloc(uint32_t layers, OmegaGpuGdn **out) { return omega_gpu_gdn_alloc_ratio(layers, 0, out); }
 
+/* The state mode alloc takes from the environment (no device): see the header. */
+int omega_gpu_gdn_state_env(int *bf16, int *state_mutant) {
+    if (!bf16 || !state_mutant) return OMEGA_GPU_GDN_BAD_ARGS;
+    /* L313: AIEN_OMEGA_GDN_STATE_BF16=1 stores the state bf16 (half the bytes per conversation; compute stays f32) */
+    const char *pb = getenv("AIEN_OMEGA_GDN_STATE_BF16");
+    *bf16 = pb && pb[0] == '1' && pb[1] == 0;
+    /* DRA-76: AIEN_OMEGA_GDN_STATE_MUTANT=1 (no decay) or 5 (bf16 store keeps 3 mantissa bits), the negative controls of
+     * the bf16-state agreement gate. Unset or empty = off. Any other value, or a mutant without the bf16 state, refuses. */
+    const char *pm = getenv("AIEN_OMEGA_GDN_STATE_MUTANT");
+    *state_mutant = 0;
+    if (!pm || !pm[0] || (pm[0] == '0' && pm[1] == 0)) return OMEGA_GPU_GDN_OK;
+    if (pm[1] == 0 && pm[0] == '1') *state_mutant = 1;
+    else if (pm[1] == 0 && pm[0] == '5') *state_mutant = OMEGA_GDN_MUT_BF16_TRUNC;
+    else { omega_gpu_session_set_error("gdn: AIEN_OMEGA_GDN_STATE_MUTANT must be 1 or 5"); return OMEGA_GPU_GDN_BAD_ARGS; }
+    if (!*bf16) { *state_mutant = 0; omega_gpu_session_set_error("gdn: AIEN_OMEGA_GDN_STATE_MUTANT needs AIEN_OMEGA_GDN_STATE_BF16=1"); return OMEGA_GPU_GDN_BAD_ARGS; }
+    return OMEGA_GPU_GDN_OK;
+}
+
 int omega_gpu_gdn_alloc_ratio(uint32_t layers, uint32_t ratio, OmegaGpuGdn **out) {
     OmegaGdnShape S;
     if (!out || layers == 0 || layers > OMEGA_GPU_GDN_MAX_LAYERS || shape_of(ratio, &S)) return OMEGA_GPU_GDN_BAD_ARGS;
-    /* L313: AIEN_OMEGA_GDN_STATE_BF16=1 stores the state bf16 (half the bytes per conversation; compute stays f32) */
-    const char *pb = getenv("AIEN_OMEGA_GDN_STATE_BF16");
-    const int bf16 = pb && pb[0] == '1' && pb[1] == 0;
+    int bf16 = 0, state_mutant = 0;
+    if (omega_gpu_gdn_state_env(&bf16, &state_mutant) != OMEGA_GPU_GDN_OK) return OMEGA_GPU_GDN_BAD_ARGS;
     if (bf16) { OmegaGdnSpec sp; memset(&sp, 0, sizeof sp); sp.ratio = ratio; sp.state_bf16 = 1; if (omega_gdn_shape(&sp, &S)) return OMEGA_GPU_GDN_BAD_ARGS; }
     *out = NULL;
     OmegaGpuGdn *g = omega_gpu_host_calloc(1, sizeof *g);
     if (!g) return OMEGA_GPU_GDN_BAD_ARGS;
     g->bf16 = bf16;
+    g->state_mutant = state_mutant;
     g->layers = layers;
     g->ratio = ratio;
     g->sh = S;
@@ -360,6 +380,8 @@ static int zero_ts_locked(OmegaGpuGdn *g) {
     int rc = move_locked(KK_ZERO, 0, g->tail.va, tb);
     return rc == OMEGA_GPU_GDN_OK ? move_locked(KK_ZERO, 0, g->state.va, sb) : rc;
 }
+/* The spec's mutant: the process-wide test mutant, else this allocation's AIEN_OMEGA_GDN_STATE_MUTANT (DRA-76). */
+static int spec_mutant(const OmegaGpuGdn *g) { return g_k.mutant ? g_k.mutant : g->state_mutant; }
 /* rec non-NULL (record path, caller holds the session lock): the inputs are the device rows dev_*, the launch is
  * appended to rec instead of submitted, nothing is staged, poisoned or read back. */
 static int gdn_core(OmegaGpuGdn *g, uint32_t layer, const float *qkv, const float *z, const float *ab, float eps_l2,
@@ -370,7 +392,7 @@ static int gdn_core(OmegaGpuGdn *g, uint32_t layer, const float *qkv, const floa
     if (!g || layer >= g->layers || (rec ? (!dev_qkv || !dev_z || !dev_ab) : (!qkv || !z || !ab || !out))) return OMEGA_GPU_GDN_BAD_ARGS;
     if (!isfinite(eps_l2) || !isfinite(eps_norm) || !isfinite(in_scale) || !isfinite(out_scale)) return OMEGA_GPU_GDN_BAD_ARGS;
     OmegaGdnSpec spec; memset(&spec, 0, sizeof spec);
-    spec.mutant = g_k.mutant;
+    spec.mutant = spec_mutant(g);
     spec.ratio = g->ratio;
     spec.state_bf16 = (uint32_t)g->bf16;
 
@@ -449,7 +471,7 @@ int omega_gpu_gdn_record(OmegaGpuCmdList *cl, OmegaGpuGdn *g, uint32_t layer, ui
 int omega_gpu_gdn_multi_prepare(OmegaGpuGdn *g) {
     if (!g) return OMEGA_GPU_GDN_BAD_ARGS;
     OmegaGdnSpec spec; memset(&spec, 0, sizeof spec);
-    spec.mutant = g_k.mutant; spec.ratio = g->ratio;
+    spec.mutant = spec_mutant(g); spec.ratio = g->ratio; spec.state_bf16 = (uint32_t)g->bf16;
     omega_gpu_session_lock();
     int rc = dev_open_locked() ? OMEGA_GPU_GDN_OK : OMEGA_GPU_GDN_CHIP_FAIL;
     Slot *ks = NULL; bool hit = false;
@@ -465,7 +487,7 @@ int omega_gpu_gdn_multi_record(OmegaGpuCmdList *cl, OmegaGpuGdn *g, uint32_t lay
     if (!isfinite(eps_l2) || !isfinite(eps_norm) || !isfinite(in_scale) || !isfinite(out_scale)) return OMEGA_GPU_GDN_BAD_ARGS;
     if (((qkv_va | z_va | out_va | xstride | ostride) & 15u) || ((ab_va | abstride) & 7u)) return OMEGA_GPU_GDN_BAD_ARGS;
     OmegaGdnSpec spec; memset(&spec, 0, sizeof spec);
-    spec.mutant = g_k.mutant; spec.ratio = g->ratio;
+    spec.mutant = spec_mutant(g); spec.ratio = g->ratio; spec.state_bf16 = (uint32_t)g->bf16;
     /* caller holds the session lock */
     if (!dev_open_locked()) return OMEGA_GPU_GDN_CHIP_FAIL;
     Slot *ks = NULL; bool hit = false;
@@ -540,7 +562,7 @@ static int pf_core(OmegaGpuGdn *g, uint32_t layer, uint32_t T, const float *qkv,
     if (rec ? (!dev_qkv || !dev_z || !dev_ab) : (!qkv || !z || !ab || !out)) return OMEGA_GPU_GDN_BAD_ARGS;
     if (!isfinite(eps_l2) || !isfinite(eps_norm) || !isfinite(in_scale) || !isfinite(out_scale)) return OMEGA_GPU_GDN_BAD_ARGS;
     OmegaGdnSpec spec; memset(&spec, 0, sizeof spec);
-    spec.mutant = g_k.mutant;
+    spec.mutant = spec_mutant(g);
     spec.ratio = g->ratio;
     spec.state_bf16 = (uint32_t)g->bf16;
     size_t off[PF_N];
diff --git a/src/omega_gpu_gdn_api.h b/src/omega_gpu_gdn_api.h
index a2300ebc..12306160 100644
--- a/src/omega_gpu_gdn_api.h
+++ b/src/omega_gpu_gdn_api.h
@@ -10,6 +10,11 @@
  *        The tails and states are GPU-cached (2026-10-19; AIEN_OMEGA_GDN_STATE_CACHED=0 keeps them uncached): the host
  *        never touches them directly, reset zeroes them with a chip launch and set_state / get_state copy one layer through
  *        an uncached staging buffer with chip launches (omega_blackwell_codegen_gdn.h, state copy / zero).
+ *        AIEN_OMEGA_GDN_STATE_BF16=1 (read here, L313) stores the states bf16 (half the bytes; compute stays f32; set/get_state
+ *        keep the f32 layout) for every kernel: decode, prefill scan and multi-token decode (the last since DRA-76).
+ *        AIEN_OMEGA_GDN_STATE_MUTANT (read here, DRA-76, TEST ONLY, needs the bf16 state; unset, empty or 0 = off) corrupts it on
+ *        purpose for the agreement gate's negative control: 1 drops the decay, 5 keeps 3 mantissa bits at every state
+ *        store (OMEGA_GDN_MUT_BF16_TRUNC). Another value, or a mutant without the bf16 state, is BAD_ARGS.
  *   int  omega_gpu_gdn_set_layer(OmegaGpuGdn *g, uint32_t layer, const float *conv_w, const float *a_log,
  *                                const float *dt_bias, const float *norm_w);
  *        conv_w: linear_attn.conv1d.weight [10240][1][4] widened to f32 ([10240][4]); a_log, dt_bias: [48];
@@ -134,5 +139,8 @@ int omega_gdn_pack_tail_r(uint32_t ratio, const float *tail, float *dev);
 int omega_gdn_unpack_tail_r(uint32_t ratio, const float *dev, float *tail);
 
 void omega_gpu_gdn_test_set_mutant(int mutant); /* TEST ONLY: OmegaGdnSpec.mutant; clears the kernel cache */
+/* DRA-76: the state mode omega_gpu_gdn_alloc_ratio takes from AIEN_OMEGA_GDN_STATE_BF16 / AIEN_OMEGA_GDN_STATE_MUTANT
+ * (see the alloc notes above), without the device. OK, or BAD_ARGS (with the session error) on a refused mutant. */
+int omega_gpu_gdn_state_env(int *bf16, int *state_mutant);
 
 #endif
diff --git a/tests/gpu_gdn_multi_test.c b/tests/gpu_gdn_multi_test.c
index ea643723..1d6aa768 100644
--- a/tests/gpu_gdn_multi_test.c
+++ b/tests/gpu_gdn_multi_test.c
@@ -3,15 +3,28 @@
  * gpu_gdn_multi_test: the multi-token Gated DeltaNet decode (L369, omega_gpu_gdn_api.h) must be the decode step T times,
  * bit for bit: every output row, the conv tail and the state after the last token.
  *   --sim         warp simulator over the whole grid: T decode launches against one multi launch (both fragment orders),
- *                 T 1, 2, 5; controls: a zero row stride and mutant 4 (tail not shifted) must differ
+ *                 T 1, 2, 5; controls: a zero row stride and mutant 4 (tail not shifted) must differ. Then the bf16 state
+ *                 (DRA-76): one bf16-state multi launch == the f32 multi launch from the widened state, the final state
+ *                 rounded to nearest even (outputs and tails bit for bit, T 1, 2, 5, both orders); controls: mutant 1 with
+ *                 the bf16 state changes the outputs, mutant 5 (OMEGA_GDN_MUT_BF16_TRUNC) stores rn & 0xfff0 from the
+ *                 multi and the decode launch. Then the host checks below.
+ *   --host-only   (DRA-76) codegen: the bf16-state multi program builds, fits and encodes with every placeholder patched;
+ *                 mutant 5 accepted with the bf16 state by all five GDN programs and refused without it;
+ *                 omega_gpu_gdn_state_env parses AIEN_OMEGA_GDN_STATE_BF16 / _MUTANT as alloc does. No device.
+ *   --bf16        the chip, bf16 state through the API (DRA-76): gdns allocated under AIEN_OMEGA_GDN_STATE_BF16=1 (and
+ *                 AIEN_OMEGA_GDN_STATE_MUTANT 1 / 5, set here) against an f32 gdn from the widened state, T 2, 37, 128:
+ *                 the multi launch's outputs and tail bit for bit, its state == the rounded f32 state; mutant 1 differs,
+ *                 mutant 5 stores the truncated state. Run it with both variables unset in the environment.
  *   (default)     the chip: T decode steps (omega_gpu_gdn_step) against one recorded multi launch from the same nonzero
- *                 state, T 1, 2, 37, 128, two input scales; the same controls must differ
+ *                 state, T 1, 2, 37, 128, two input scales; the same controls must differ. f32 state only: under
+ *                 AIEN_OMEGA_GDN_STATE_BF16=1 the decode rounds the state every token and the multi once, so they differ.
  * Rows as the 35B graph lays them out: token t's qkv | z in one row (stride (conv + vdim) * 4 bytes), ab rows of vh * 8
  * bytes, out rows of vdim * 4 bytes. Verdict line last: "gpu_gdn_multi_test: N checks, F failed: PASS|FAIL".
  */
 #include "omega_gpu_gdn_api.h"
 #include "omega_gpu_session.h"
 #include "omega_gpu_cmdlist.h"
+#include "omega_blackwell_codegen_tc.h"
 #include "bw_warp_sim_k.h"
 #include <math.h>
 #include <stdio.h>
@@ -94,18 +107,28 @@ static int sim_run(const BlackwellIRProgram *prog, int order, const SimBuf *b, i
     if (err) snprintf(msg, n, "%.150s (pc %d)", s.msg, s.err_pc);
     return err;
 }
-/* T decode launches (decode = 1) or one multi launch over the case; out [T][VD], tail and state device layouts */
-static int sim_path(const Case *c, uint32_t T, int multi, int mutant, uint32_t xstride, float in_scale, int order, float *out,
-                    uint8_t *tail, uint8_t *state, char *msg, size_t n) {
+/* bf16 state helpers: round to nearest even (the F2FP the bf16 store emits) and the exact widen */
+static uint16_t t_bf16_rn(float f) {
+    uint32_t u; memcpy(&u, &f, 4);
+    if ((u & 0x7fffffffu) > 0x7f800000u) return (uint16_t)((u >> 16) | 0x40u);
+    return (uint16_t)((u + 0x7fffu + ((u >> 16) & 1u)) >> 16);
+}
+static float t_bf16_f(uint16_t b) { const uint32_t u = (uint32_t)b << 16; float f; memcpy(&f, &u, 4); return f; }
+/* T decode launches (multi = 0) or one multi launch over the case; out [T][VD], tail and state device layouts. The state
+ * starts at init (NULL: the case's state0), rounded to bf16 when bf16 (state then holds NS uint16 in the same order). */
+static int sim_path(const Case *c, uint32_t T, int multi, int mutant, int bf16, const float *init, uint32_t xstride, float in_scale,
+                    int order, float *out, uint8_t *tail, uint8_t *state, char *msg, size_t n) {
     static BlackwellIRProgram prog;
-    OmegaGdnSpec spec = { .mutant = mutant, .ratio = GDN_TEST_RATIO };
+    OmegaGdnSpec spec = { .mutant = mutant, .ratio = GDN_TEST_RATIO, .state_bf16 = (uint32_t)bf16 };
     if ((multi ? omega_blackwell_codegen_gdn_multi_prog(&spec, &prog) : omega_blackwell_codegen_gdn_prog(&spec, &prog)) != 0) {
         snprintf(msg, n, "codegen refused"); return -1;
     }
     uint8_t *par = aligned_alloc(256, (P_BYTES + 255) & ~255u);
     omega_gdn_pack_params_r(GDN_TEST_RATIO, c->conv_w, c->a_log, c->dtb, c->nw, par);
     omega_gdn_pack_tail_r(GDN_TEST_RATIO, c->tail0, (float *)tail);
-    memcpy(state, c->state0, STATE_BYTES);
+    const float *s0 = init ? init : c->state0;
+    if (bf16) for (size_t i = 0; i < NS; i++) ((uint16_t *)state)[i] = t_bf16_rn(s0[i]);
+    else memcpy(state, s0, STATE_BYTES);
     const float one = 1.0f;
     uint32_t w[10];
     memcpy(&w[0], &EPS_L2, 4); memcpy(&w[1], &EPS_N, 4); memcpy(&w[2], &in_scale, 4); memcpy(&w[3], &one, 4);
@@ -115,7 +138,7 @@ static int sim_path(const Case *c, uint32_t T, int multi, int mutant, uint32_t x
         SimBuf b[7] = {
             { OMEGA_GDN_ARG_QKV, (void *)row, (size_t)(multi ? T : 1) * ROW }, { OMEGA_GDN_ARG_Z, (void *)(row + CD * 4u), (size_t)(multi ? T : 1) * ROW - CD * 4u },
             { OMEGA_GDN_ARG_AB, (uint8_t *)c->ab + (size_t)t * ABROW, (size_t)(multi ? T : 1) * ABROW }, { OMEGA_GDN_ARG_PAR, par, P_BYTES },
-            { OMEGA_GDN_ARG_TAIL, tail, TAIL_BYTES }, { OMEGA_GDN_ARG_STATE, state, STATE_BYTES },
+            { OMEGA_GDN_ARG_TAIL, tail, TAIL_BYTES }, { OMEGA_GDN_ARG_STATE, state, bf16 ? STATE_BYTES / 2u : STATE_BYTES },
             { OMEGA_GDN_ARG_OUT, (uint8_t *)out + (size_t)t * OROW, (size_t)(multi ? T : 1) * OROW },
         };
         w[4] = T; w[5] = xstride; w[6] = ABROW; w[7] = OROW; /* the multi words follow OUT_SCALE (0x3c4): 0x3c8.. */
@@ -132,25 +155,135 @@ static void sim_battery(void) {
     for (unsigned i = 0; i < 3; i++) {
         const uint32_t T = Ts[i];
         Case c; case_make(&c, T, 77 + T, 1.0f);
-        int e1 = sim_path(&c, T, 0, 0, ROW, 1.0f, 0, oa, ta, sa, msg, sizeof msg);
+        int e1 = sim_path(&c, T, 0, 0, 0, NULL, ROW, 1.0f, 0, oa, ta, sa, msg, sizeof msg);
         CHECK(e1 == 0, "sim decode x %u ran (%s)", T, msg);
         for (int order = 0; order < 2 && e1 == 0; order++) {
-            int e2 = sim_path(&c, T, 1, 0, ROW, 1.0f, order, ob, tb, sb, msg, sizeof msg);
+            int e2 = sim_path(&c, T, 1, 0, 0, NULL, ROW, 1.0f, order, ob, tb, sb, msg, sizeof msg);
             const size_t dO = first_diff(oa, ob, (size_t)T * VD), dT = first_diff(ta, tb, TAIL_BYTES / 4), dS = first_diff(sa, sb, STATE_BYTES / 4);
             printf("sim T %u order %d: multi %s | out %s tail %s state %s\n", T, order, e2 ? msg : "ran", dO == (size_t)-1 ? "identical" : "DIFFER",
                    dT == (size_t)-1 ? "identical" : "DIFFER", dS == (size_t)-1 ? "identical" : "DIFFER");
             CHECK(e2 == 0 && dO == (size_t)-1 && dT == (size_t)-1 && dS == (size_t)-1, "sim T %u order %d: multi == %u decode steps bit for bit", T, order, T);
         }
         if (T >= 2 && e1 == 0) {
-            int e3 = sim_path(&c, T, 1, 0, 0, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+            int e3 = sim_path(&c, T, 1, 0, 0, NULL, 0, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
             CHECK(e3 == 0 && first_diff(oa, ob, (size_t)T * VD) != (size_t)-1, "sim T %u control: row stride 0 differs", T);
-            int e4 = sim_path(&c, T, 1, 4, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+            int e4 = sim_path(&c, T, 1, 4, 0, NULL, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
             CHECK(e4 == 0 && first_diff(oa, ob, (size_t)T * VD) != (size_t)-1, "sim T %u control: mutant 4 (tail not shifted) differs", T);
         }
         case_free(&c);
     }
     free(oa); free(ob); free(ta); free(tb); free(sa); free(sb);
 }
+/* DRA-76: the bf16 state. The multi launch widens the state once, runs the f32 recurrence over the T tokens and rounds once,
+ * so it must be the f32 multi launch from the widened state, its final state rounded to nearest even. */
+static size_t state_off(const float *f32, const uint16_t *b16, int trunc, size_t *moved) {
+    size_t bad = 0, mv = 0;
+    for (size_t k = 0; k < NS; k++) {
+        const uint16_t r = t_bf16_rn(f32[k]), want = trunc ? (uint16_t)(r & 0xfff0u) : r;
+        bad += b16[k] != want; mv += b16[k] != r;
+    }
+    if (moved) *moved = mv;
+    return bad;
+}
+static void sim_bf16_battery(void) {
+    const uint32_t Ts[] = { 1, 2, 5 };
+    float *oa = malloc((size_t)5 * OROW), *ob = malloc((size_t)5 * OROW), *wide = malloc((size_t)NS * 4);
+    uint8_t *ta = malloc(TAIL_BYTES), *tb = malloc(TAIL_BYTES), *sa = malloc(STATE_BYTES), *sb = malloc(STATE_BYTES);
+    const float *fa = (const float *)sa; const uint16_t *hb = (const uint16_t *)sb;
+    char msg[256] = "";
+    for (unsigned i = 0; i < 3; i++) {
+        const uint32_t T = Ts[i];
+        Case c; case_make(&c, T, 177 + T, 1.0f);
+        for (size_t k = 0; k < NS; k++) wide[k] = t_bf16_f(t_bf16_rn(c.state0[k]));
+        const int e1 = sim_path(&c, T, 1, 0, 0, wide, ROW, 1.0f, 0, oa, ta, sa, msg, sizeof msg);
+        CHECK(e1 == 0, "sim bf16 T %u: the f32 multi launch from the widened state ran (%s)", T, msg);
+        if (e1) { case_free(&c); continue; }
+        for (int order = 0; order < 2; order++) {
+            const int e2 = sim_path(&c, T, 1, 0, 1, NULL, ROW, 1.0f, order, ob, tb, sb, msg, sizeof msg);
+            const size_t dO = first_diff(oa, ob, (size_t)T * VD), dT = first_diff(ta, tb, TAIL_BYTES / 4), bad = e2 ? NS : state_off(fa, hb, 0, NULL);
+            printf("sim bf16 T %u order %d: multi %s | out %s tail %s state %zu of %u off rn(f32)\n", T, order, e2 ? msg : "ran",
+                   dO == (size_t)-1 ? "identical" : "DIFFER", dT == (size_t)-1 ? "identical" : "DIFFER", bad, (unsigned)NS);
+            CHECK(e2 == 0 && dO == (size_t)-1 && dT == (size_t)-1 && bad == 0,
+                  "sim bf16 T %u order %d: bf16 multi == f32 multi from the widened state, state rounded to nearest even", T, order);
+        }
+        size_t moved = 0;
+        const int e5 = sim_path(&c, T, 1, OMEGA_GDN_MUT_BF16_TRUNC, 1, NULL, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+        const size_t bad5 = e5 ? NS : state_off(fa, hb, 1, &moved);
+        CHECK(e5 == 0 && first_diff(oa, ob, (size_t)T * VD) == (size_t)-1 && bad5 == 0 && moved > 0,
+              "sim bf16 T %u control: multi mutant 5 keeps the outputs and stores rn & 0xfff0 (%zu of %u words moved)", T, moved, (unsigned)NS);
+        const int e6 = sim_path(&c, T, 1, 1, 1, NULL, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+        CHECK(e6 == 0 && first_diff(oa, ob, (size_t)T * VD) != (size_t)-1, "sim bf16 T %u control: multi mutant 1 (no decay) differs", T);
+        /* the decode launch rounds the state every token: one launch is the multi launch with T 1, more drift */
+        const int e7 = sim_path(&c, T, 0, 0, 1, NULL, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+        float dmax = 0.0f;
+        for (size_t k = 0; k < (size_t)T * VD && e7 == 0; k++) dmax = fmaxf(dmax, fabsf(oa[k] - ob[k]));
+        printf("sim bf16 T %u: %u bf16 decode launches vs the bf16 multi launch: max |out diff| %g\n", T, T, (double)dmax);
+        if (T == 1) {
+            const size_t bad = e7 ? NS : state_off(fa, hb, 0, NULL);
+            CHECK(e7 == 0 && first_diff(oa, ob, VD) == (size_t)-1 && first_diff(ta, tb, TAIL_BYTES / 4) == (size_t)-1 && bad == 0,
+                  "sim bf16 T 1: the bf16 decode launch == the bf16 multi launch (out, tail, state)");
+            const int e8 = sim_path(&c, 1, 0, OMEGA_GDN_MUT_BF16_TRUNC, 1, NULL, ROW, 1.0f, 0, ob, tb, sb, msg, sizeof msg);
+            const size_t bad8 = e8 ? NS : state_off(fa, hb, 1, &moved);
+            CHECK(e8 == 0 && first_diff(oa, ob, VD) == (size_t)-1 && bad8 == 0 && moved > 0,
+                  "sim bf16 T 1 control: decode mutant 5 keeps the output and stores rn & 0xfff0 (%zu words moved)", moved);
+        } else {
+            CHECK(e7 == 0, "sim bf16 T %u: the bf16 decode launches ran (%s)", T, msg);
+        }
+        case_free(&c);
+    }
+    free(oa); free(ob); free(wide); free(ta); free(tb); free(sa); free(sb);
+}
+
+/* ---- DRA-76 host checks: codegen and the environment parse, no device ---- */
+typedef int (*GdnGen)(const OmegaGdnSpec *, BlackwellIRProgram *);
+static void host_checks(void) {
+    static BlackwellIRProgram p, q;
+    const GdnGen gen[5] = { omega_blackwell_codegen_gdn_prog, omega_blackwell_codegen_gdn_prep_prog, omega_blackwell_codegen_gdn_scan_prog,
+                            omega_blackwell_codegen_gdn_post_prog, omega_blackwell_codegen_gdn_multi_prog };
+    static const char *const name[5] = { "decode", "prep", "scan", "post", "multi" };
+    for (unsigned k = 0; k < 5; k++) {
+        const OmegaGdnSpec t5 = { .mutant = OMEGA_GDN_MUT_BF16_TRUNC, .ratio = GDN_TEST_RATIO, .state_bf16 = 1 };
+        const OmegaGdnSpec f5 = { .mutant = OMEGA_GDN_MUT_BF16_TRUNC, .ratio = GDN_TEST_RATIO };
+        const OmegaGdnSpec t6 = { .mutant = OMEGA_GDN_MUT_BF16_TRUNC + 1, .ratio = GDN_TEST_RATIO, .state_bf16 = 1 };
+        const int a = gen[k](&t5, &p), b = gen[k](&f5, &p), d = gen[k](&t6, &p);
+        CHECK(a == 0 && b != 0 && d != 0, "%s codegen: mutant 5 accepted with the bf16 state (%d), refused without it (%d), mutant 6 refused (%d)",
+              name[k], a, b, d);
+    }
+    const OmegaGdnSpec m32 = { .ratio = GDN_TEST_RATIO }, m16 = { .ratio = GDN_TEST_RATIO, .state_bf16 = 1 };
+    uint32_t i32 = 0, g32 = 0, i16 = 0, g16 = 0;
+    CHECK(omega_gdn_multi_prog_stats(&m32, &i32, &g32) == 0 && omega_gdn_multi_prog_stats(&m16, &i16, &g16) == 0 && g16 > 0 &&
+          OMEGA_GDN_THREADS * (g16 + 2u) <= 65536u,
+          "bf16 multi program fits the register file (%u insns, %u registers; f32 %u insns, %u registers)", i16, g16, i32, g32);
+    const int rq = omega_blackwell_codegen_gdn_multi_prog(&m32, &q), rc = omega_blackwell_codegen_gdn_multi_prog(&m16, &p);
+    const size_t need = rc == 0 ? omega_bw_program_code_bytes(&p) : 0;
+    uint8_t *code = need ? malloc(need) : NULL;
+    OmegaBlackwellKernel kern;
+    const int enc = code ? omega_blackwell_kernel_encode_into(&p, code, need, &kern) : -1;
+    const int np = enc == 0 ? omega_tc_patch_code(&p, code, need) : -1;
+    const uint32_t want = rc == 0 ? omega_gdn_bfly_count(&p) : 0, base = rq == 0 ? omega_gdn_bfly_count(&q) : 0;
+    CHECK(rq == 0 && rc == 0 && enc == 0 && np >= 0 && (uint32_t)np == want && want == base + 32u,
+          "bf16 multi encodes: %d of %u placeholders patched (f32 %u + 32 F2FP)", np, want, base);
+    free(code);
+    /* omega_gpu_gdn_state_env: what alloc takes from the environment */
+    static const char *const var[2] = { "AIEN_OMEGA_GDN_STATE_BF16", "AIEN_OMEGA_GDN_STATE_MUTANT" };
+    static const struct { const char *bf, *mu; int ok, bf16, mut; } ev[] = {
+        { NULL, NULL, 1, 0, 0 }, { "1", NULL, 1, 1, 0 }, { "0", "", 1, 0, 0 }, { "10", NULL, 1, 0, 0 }, { "1", "0", 1, 1, 0 },
+        { "1", "1", 1, 1, 1 }, { "1", "5", 1, 1, OMEGA_GDN_MUT_BF16_TRUNC }, { "1", "4", 0, 1, 0 }, { "1", "15", 0, 1, 0 },
+        { NULL, "1", 0, 0, 0 }, { "true", "5", 0, 0, 0 },
+    };
+    char *saved[2];
+    for (int j = 0; j < 2; j++) { const char *v = getenv(var[j]); saved[j] = v ? strdup(v) : NULL; }
+    for (size_t k = 0; k < sizeof ev / sizeof ev[0]; k++) {
+        const char *val[2] = { ev[k].bf, ev[k].mu };
+        for (int j = 0; j < 2; j++) { if (val[j]) setenv(var[j], val[j], 1); else unsetenv(var[j]); }
+        int bf16 = -1, mut = -1;
+        const int rc_env = omega_gpu_gdn_state_env(&bf16, &mut);
+        CHECK(ev[k].ok ? rc_env == OMEGA_GPU_GDN_OK && bf16 == ev[k].bf16 && mut == ev[k].mut : rc_env == OMEGA_GPU_GDN_BAD_ARGS && mut == 0,
+              "state env BF16=%s MUTANT=%s: %s (rc %d, bf16 %d, mutant %d)", val[0] ? val[0] : "(unset)", val[1] ? val[1] : "(unset)",
+              ev[k].ok ? "accepted" : "refused", rc_env, bf16, mut);
+    }
+    for (int j = 0; j < 2; j++) { if (saved[j]) setenv(var[j], saved[j], 1); else unsetenv(var[j]); free(saved[j]); }
+}
 
 /* ---- chip ---- */
 /* the decode path: T omega_gpu_gdn_step calls; out [T][VD], tail (reference layout) and state after the last */
@@ -222,14 +355,77 @@ static void chip_battery(void) {
     free(oa); free(ob); free(ta); free(tb); free(sa); free(sb);
     omega_gpu_gdn_free(g);
 }
+/* DRA-76: the bf16 state on the chip, selected through the environment exactly as the 35B selects it */
+static int env_alloc(const char *bf, const char *mu, OmegaGpuGdn **g) {
+    if (bf) setenv("AIEN_OMEGA_GDN_STATE_BF16", bf, 1); else unsetenv("AIEN_OMEGA_GDN_STATE_BF16");
+    if (mu) setenv("AIEN_OMEGA_GDN_STATE_MUTANT", mu, 1); else unsetenv("AIEN_OMEGA_GDN_STATE_MUTANT");
+    const int rc = omega_gpu_gdn_alloc_ratio(1, GDN_TEST_RATIO, g);
+    unsetenv("AIEN_OMEGA_GDN_STATE_BF16"); unsetenv("AIEN_OMEGA_GDN_STATE_MUTANT");
+    return rc;
+}
+static size_t chip_state_off(const float *f32, const float *wid, int trunc, size_t *moved) {
+    size_t bad = 0, mv = 0;
+    for (size_t k = 0; k < NS; k++) {
+        const uint16_t r = t_bf16_rn(f32[k]);
+        const float want = t_bf16_f(trunc ? (uint16_t)(r & 0xfff0u) : r), rn = t_bf16_f(r);
+        bad += memcmp(&wid[k], &want, 4) != 0; mv += memcmp(&wid[k], &rn, 4) != 0;
+    }
+    if (moved) *moved = mv;
+    return bad;
+}
+static void chip_bf16_battery(void) {
+    OmegaGpuGdn *gf = NULL, *gb = NULL, *g1 = NULL, *g5 = NULL, *gx = NULL;
+    CHECK(env_alloc(NULL, NULL, &gf) == 0 && env_alloc("1", NULL, &gb) == 0 && env_alloc("1", "1", &g1) == 0 && env_alloc("1", "5", &g5) == 0,
+          "alloc f32, bf16, bf16 mutant 1, bf16 mutant 5 (%s)", omega_gpu_gdn_last_error());
+    CHECK(env_alloc(NULL, "1", &gx) != 0 && gx == NULL, "alloc refuses AIEN_OMEGA_GDN_STATE_MUTANT without the bf16 state");
+    const uint32_t Ts[] = { 2, 37, 128 };
+    float *oa = malloc((size_t)128 * OROW), *ob = malloc((size_t)128 * OROW), *wide = malloc((size_t)NS * 4);
+    float *ta = malloc((size_t)NT * 4), *tb = malloc((size_t)NT * 4), *sa = malloc(STATE_BYTES), *sb = malloc(STATE_BYTES);
+    for (unsigned i = 0; i < 3 && gf && gb && g1 && g5; i++) {
+        const uint32_t T = Ts[i];
+        Case c; case_make(&c, T, 1300 + T, 1.0f);
+        for (size_t k = 0; k < NS; k++) wide[k] = t_bf16_f(t_bf16_rn(c.state0[k]));
+        Case cw = c; cw.state0 = wide;
+        OmegaGpuGdn *all[4] = { gf, gb, g1, g5 };
+        for (int j = 0; j < 4; j++) CHECK(omega_gpu_gdn_set_layer(all[j], 0, c.conv_w, c.a_log, c.dtb, c.nw) == 0, "set layer");
+        const int ra = chip_multi(gf, &cw, T, 1.0f, ROW, oa, ta, sa), rb = chip_multi(gb, &c, T, 1.0f, ROW, ob, tb, sb);
+        const size_t dO = first_diff(oa, ob, (size_t)T * VD), dT = first_diff(ta, tb, NT), bad = ra || rb ? NS : chip_state_off(sa, sb, 0, NULL);
+        printf("chip bf16 T %3u: f32 multi %s bf16 multi %s | out %s tail %s state %zu of %u off rn(f32)\n", T, ra ? "FAILED" : "ran", rb ? "FAILED" : "ran",
+               dO == (size_t)-1 ? "identical" : "DIFFER", dT == (size_t)-1 ? "identical" : "DIFFER", bad, (unsigned)NS);
+        CHECK(ra == 0 && rb == 0 && dO == (size_t)-1 && dT == (size_t)-1 && bad == 0,
+              "chip bf16 T %u: bf16 multi == f32 multi from the widened state, state rounded to nearest even (%s)", T, omega_gpu_gdn_last_error());
+        size_t moved = 0;
+        const int r5 = chip_multi(g5, &c, T, 1.0f, ROW, ob, tb, sb);
+        const size_t bad5 = r5 || ra ? NS : chip_state_off(sa, sb, 1, &moved);
+        CHECK(r5 == 0 && first_diff(oa, ob, (size_t)T * VD) == (size_t)-1 && bad5 == 0 && moved > 0,
+              "chip bf16 T %u control: env mutant 5 keeps the outputs and stores rn & 0xfff0 (%zu words moved)", T, moved);
+        const int r1 = chip_multi(g1, &c, T, 1.0f, ROW, ob, tb, sb);
+        CHECK(r1 == 0 && first_diff(oa, ob, (size_t)T * VD) != (size_t)-1, "chip bf16 T %u control: env mutant 1 (no decay) differs", T);
+        const int rd = chip_decode(gb, &c, T, 1.0f, ob, tb, sb);
+        float dmax = 0.0f;
+        for (size_t k = 0; k < (size_t)T * VD && rd == 0; k++) dmax = fmaxf(dmax, fabsf(oa[k] - ob[k]));
+        printf("chip bf16 T %3u: %u bf16 decode steps vs the bf16 multi launch: max |out diff| %g\n", T, T, (double)dmax);
+        CHECK(rd == 0, "chip bf16 T %u: the bf16 decode steps ran", T);
+        case_free(&c);
+    }
+    free(oa); free(ob); free(wide); free(ta); free(tb); free(sa); free(sb);
+    if (gf) omega_gpu_gdn_free(gf);
+    if (gb) omega_gpu_gdn_free(gb);
+    if (g1) omega_gpu_gdn_free(g1);
+    if (g5) omega_gpu_gdn_free(g5);
+}
 
 int main(int argc, char **argv) {
-    int sim = argc > 1 && strcmp(argv[1], "--sim") == 0;
+    const char *mode = argc > 1 ? argv[1] : "";
+    const int sim = strcmp(mode, "--sim") == 0, host = strcmp(mode, "--host-only") == 0, bf = strcmp(mode, "--bf16") == 0;
+    if (mode[0] && !sim && !host && !bf) { fprintf(stderr, "usage: gpu_gdn_multi_test [--sim | --host-only | --bf16]\n"); return 2; }
     uint32_t insns = 0, gprs = 0;
     OmegaGdnSpec spec = { .ratio = GDN_TEST_RATIO };
     CHECK(omega_gdn_multi_prog_stats(&spec, &insns, &gprs) == 0 && gprs > 0 && OMEGA_GDN_THREADS * (gprs + 2u) <= 65536u,
           "multi program builds and fits the register file (%u insns, %u registers)", insns, gprs);
-    if (sim) sim_battery();
+    if (sim) { sim_battery(); sim_bf16_battery(); host_checks(); }
+    else if (host) host_checks();
+    else if (bf) chip_bf16_battery();
     else chip_battery();
     printf("gpu_gdn_multi_test: %d checks, %d failed: %s\n", g_checks, g_failed, g_failed ? "FAIL" : "PASS");
     return g_failed ? 1 : 0;