Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/patches/beb17a010791f5c9 # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/omega-mv#509 (code only) closed derived `beb17a010791f5c9` #509 Imported from GitHub aien-dev/omega-mv#509 (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 `62d1d0d668f897386a0e311374f8dbcc5c32dde8` · Head `c21fd0156d0a82965b876ada69be4f3dcb7dfd00` drakestapleton reviewed (COMMENTED) on 2026-10-30 11:34 UTC MUFU FTZ host simulators plus test-mufu-ftz wired into the numeric-cpu gate (tests/gates/run.sh L126, omega-numeric-cpu.gate inputs L15-22). bw_hmma_model.h and bw_qmma_model.h exist on main. Checks are green. No chip runs, which is acceptable for a host-sim change, but please say so in the gate header comment. tests/.crumb overlaps #567. — Grokbot ### Fetch it A git bundle of the pull request's head, 30253 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/beb17a010791f5c9.bundle -o beb17a010791f5c9.bundle git fetch beb17a010791f5c9.bundle refs/pull/509/head ``` Raw bundle · 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/omega-mv 509 c21fd0156d0a82965b876ada69be4f3dcb7dfd00 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":509,"url":"https://github.com/aien-dev/omega-mv/pull/509","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:07Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index f3e51fe46..7f2ff3b27 100644 --- a/.crumb +++ b/.crumb @@ -59,8 +59,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "8f0e5cb325040247440527f6b54b65cf72c47ff5adca75b4f32a1ddf2b2d6ade", - "last_commit": "1f320caad", + "digest": "b3962e76064f21cffac99f4ccf6152ab08e20971c86e764c96ac6e9cd741df82", + "last_commit": "5e01f7b9a", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -72,38 +72,38 @@ }, { "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { "digest": "aaf5acb82fd4c720cd60c85fd6087f636c72a98e2f3740c9295dcfa525dc64d7", - "last_commit": "bf54b19fa", + "last_commit": "089e5b053", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "digest": "ebabbd0f3de9b36d5712de87ddd0fd8448275eb1521f808a8309517ad336445b", + "last_commit": "c2be51d02", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "62d1d0d66", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:c76e247793af5da32a6c25f60d60161fd261cf763537474f3860d4a0db6980c3", + "compiled_at": "2026-10-30T14:43:13Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", + "digest": "sha256:3eb044aba985969701d6e30219ead3f8de9c91a57305a361a9ac2811758be448", "evidence_files": 12622, "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "files": 17852, + "generated_at_commit": "c2be51d02bf84ceb45269dd8d51ce63c2954c346", + "source_tree": "sha256:dbe69f8d9bbfc162f9da16f3ec8d1b839476a35451468279013451c19ec0d029" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index dda6d20b5..50a9fe99b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -49,3 +49,5 @@ Update this table in the same commit as the work it credits. | Codex | Integrated FR-9 with compiler batch 3 and the latest quantity/diagnostic audit; preserved empty text and integer-bitcast behavior on x86 and kept seed bootstrap within its function budget by removing unused helpers and inlining one single-use helper. | | Codex | Fixed x86 quantity unary refusals and empty-text emission; added explicit per-target acceptance contracts, preserved historical failed experiments, and exercised missing diagnostic callers and stale-binding controls. | | Grok 4.7 | Merged current main (b3dca0f1) into #514. The only conflict was the generated root `.crumb`; regenerated crumbs with the crumb.lock tool (d0f0b95d). | +| Grok 4.7 | Merged current main (089e5b05) into #509. Conflicts were the generated root `.crumb` and `tests/.crumb`. Took main's copies and regenerated crumbs with the crumb.lock tool (d0f0b95d). | +| Grok 4.7 | Merged current main (62d1d0d) into #509. Conflicts were the generated root `.crumb` and `tests/.crumb`. Took main's copies and regenerated crumbs with the crumb.lock tool (d0f0b95d). | diff --git a/mk/.crumb b/mk/.crumb index e38efa48f..e20192f79 100644 --- a/mk/.crumb +++ b/mk/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-28T03:06:12Z", + "compiled_at": "2026-10-30T14:43:13Z", "compiler": "crumb-compile/1", - "digest": "sha256:8f0e5cb325040247440527f6b54b65cf72c47ff5adca75b4f32a1ddf2b2d6ade", + "digest": "sha256:b3962e76064f21cffac99f4ccf6152ab08e20971c86e764c96ac6e9cd741df82", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 75, - "generated_at_commit": "79b8c1f9c24195c53ac8dad111d35175a4431506", - "source_tree": "sha256:b8302c1e15664dfe98c550a03830f5d4cf75c5451a6c75eed5042e623dea5d10" + "files": 76, + "generated_at_commit": "c2be51d02bf84ceb45269dd8d51ce63c2954c346", + "source_tree": "sha256:8139c03987a06dc2524e83db3e384789b6bcb7c2de8bd0a349cfe498a03ebe10" }, "owner_lane": "", "provenance": { diff --git a/mk/omega-mufu-ftz.mk b/mk/omega-mufu-ftz.mk new file mode 100644 index 000000000..00ebb48d3 --- /dev/null +++ b/mk/omega-mufu-ftz.mk @@ -0,0 +1,19 @@ +# MUFU flush rule (omega #462): the GB10 MUFU unit (EX2 / RCP / RSQ) flushes a subnormal input or result to a +# sign-preserving zero. tests/bw_mufu_ftz.h is the one host model of it; every warp simulator and SwiGLU host reference +# routes through it. test-mufu-ftz runs the helper unit test, then one MUFU instruction through each simulator's +# ws_lane_exec (bw_warp_sim.h, _k, _pa, _tc). Picked up by `-include mk/*.mk`. Host only: opens no device, needs no +# physics headers, takes no chip lock. The attention test's own per-thread simulator is checked by +# `gpu_attention_test --host-only` (test-gpu-attention). +MUFU_FTZ_SIMS := bw_warp_sim bw_warp_sim_k bw_warp_sim_pa bw_warp_sim_tc +MUFU_FTZ_CFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Itests +.PHONY: test-mufu-ftz +$(OUT_DIR)/test_mufu_ftz_helper: tests/bw_mufu_ftz_test.c tests/bw_mufu_ftz.h + @mkdir -p $(OUT_DIR) + gcc $(MUFU_FTZ_CFLAGS) -o $@ tests/bw_mufu_ftz_test.c -lm +$(OUT_DIR)/test_mufu_ftz_%: tests/bw_mufu_ftz_test.c tests/bw_mufu_ftz.h tests/%.h tests/bw_hmma_model.h tests/bw_qmma_model.h src/omega_blackwell_codegen.h + @mkdir -p $(OUT_DIR) + gcc $(MUFU_FTZ_CFLAGS) -DWS_SIM_HDR='"$*.h"' -o $@ tests/bw_mufu_ftz_test.c -lm +test-mufu-ftz: $(OUT_DIR)/test_mufu_ftz_helper $(addprefix $(OUT_DIR)/test_mufu_ftz_,$(MUFU_FTZ_SIMS)) + $(OUT_DIR)/test_mufu_ftz_helper + @for s in $(MUFU_FTZ_SIMS); do $(OUT_DIR)/test_mufu_ftz_$$s || exit 1; done + @echo "test-mufu-ftz: PASS (helper + $(words $(MUFU_FTZ_SIMS)) simulators)" diff --git a/tests/.crumb b/tests/.crumb index 5fbfcb29c..a8547de40 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -302,14 +302,14 @@ } ], "children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902", - "compiled_at": "2026-10-30T12:31:50Z", + "compiled_at": "2026-10-30T14:43:13Z", "compiler": "crumb-compile/1", - "digest": "sha256:5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", + "digest": "sha256:ebabbd0f3de9b36d5712de87ddd0fd8448275eb1521f808a8309517ad336445b", "evidence_files": 16, "evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a", - "files": 1386, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:a3b853bb9c0edfc5f1413ccaa2698cc6ea920f2e8795756121667cc9d37f6679" + "files": 1388, + "generated_at_commit": "c2be51d02bf84ceb45269dd8d51ce63c2954c346", + "source_tree": "sha256:3be260219819f83eaedb8def965c42b6056baa04debadc0ee13a0b391588b2b9" }, "owner_lane": "", "provenance": { diff --git a/tests/bw_mufu_ftz.h b/tests/bw_mufu_ftz.h new file mode 100644 index 000000000..e1263c4c6 --- /dev/null +++ b/tests/bw_mufu_ftz.h @@ -0,0 +1,34 @@ +/* bw_mufu_ftz.h: the GB10 MUFU unit's flush-to-zero rule, shared by every host model of it (omega #462). + * + * MUFU (the SASS EX2 / RCP / RSQ unit) flushes a subnormal result to a sign-preserving zero. Chip-observed on GB10: the + * SwiGLU reciprocal 1 / (2^t + 1) for t in (126, 128) came back as +-0 on all 101 of 101 differing elements (evidence + * OWN30B-L1G-PFGEMM-SWIGLU-FTZ-df9bd9c4, gpu_pfgemm_test host red test). Doc-inferred, not separately chip-observed: the + * input flush and the EX2 / RSQ cases follow the same rule, PTX ISA 9.7.3.13 (rcp) and 9.7.3.21 (ex2) "flushes subnormal + * inputs and results to sign-preserving zero" for the .ftz form, which is what the bare MUFU we emit is (the non-ftz PTX + * variants are ptxas sequences around MUFU; NVIDIA publishes no SASS semantics). Limit: the chip's MUFU is approximate + * (RCP 1 ulp, EX2 2 ulp), the model flushes a correctly rounded IEEE result, so right at the subnormal boundary the two + * can disagree 0 versus nonzero. + * + * Users: tests/bw_warp_sim.h, bw_warp_sim_k.h, bw_warp_sim_pa.h, bw_warp_sim_tc.h (MUFU cases), the attention test's own + * per-thread simulator (gpu_attention_test.c) and the pfgemm / qgemm SwiGLU host references. omega_numeric.c has its own + * ftz() on the library side. Self-contained (no simulator state) so any of them can include it, in any order. */ +#ifndef BW_MUFU_FTZ_H +#define BW_MUFU_FTZ_H + +#include +#include +#include + +/* A subnormal (exponent field 0, mantissa nonzero) becomes a zero of the same sign; zeros, normals, inf and NaN pass. */ +static inline float ws_mufu_ftz(float f) { + uint32_t u; memcpy(&u, &f, 4); + if ((u & 0x7f800000u) == 0u) u &= 0x80000000u; + memcpy(&f, &u, 4); + return f; +} +/* The three MUFU functions the codegen emits: input flushed, IEEE f32 function, result flushed. */ +static inline float ws_mufu_ex2(float x) { return ws_mufu_ftz(exp2f(ws_mufu_ftz(x))); } +static inline float ws_mufu_rcp(float x) { return ws_mufu_ftz(1.0f / ws_mufu_ftz(x)); } +static inline float ws_mufu_rsq(float x) { return ws_mufu_ftz(1.0f / sqrtf(ws_mufu_ftz(x))); } + +#endif diff --git a/tests/bw_mufu_ftz_test.c b/tests/bw_mufu_ftz_test.c new file mode 100644 index 000000000..573ce0732 --- /dev/null +++ b/tests/bw_mufu_ftz_test.c @@ -0,0 +1,96 @@ +/* bw_mufu_ftz_test.c: the MUFU flush rule (tests/bw_mufu_ftz.h, omega #462) and every warp simulator's MUFU cases. + * + * Built once per model (Makefile test-mufu-ftz): + * no WS_SIM_HDR the helper itself: subnormal -> sign-preserving zero; zeros, normals, inf, NaN pass + * -DWS_SIM_HDR='"bw_warp_sim.h"' (and _k, _pa, _tc) one MUFU instruction through that simulator's ws_lane_exec + * The simulator cases expect the chip rule: a subnormal input or result is a zero of the same sign. Before #462 the + * first three simulators returned the IEEE subnormal (RCP of 1.5 * 2^127, EX2 of -130) and the IEEE finite value for a + * subnormal input (RCP / RSQ of 2^-127, 2^-140), and fail here. Unreachable: an RSQ result can never be subnormal + * (1 / sqrt(x) >= 2^-64 for every finite f32 x), so RSQ only exercises the input flush. */ +#ifdef WS_SIM_HDR +#include WS_SIM_HDR /* the simulator under test; it must get its MUFU rule from bw_mufu_ftz.h */ +#else +#include "bw_mufu_ftz.h" +#endif +#include +#include +#include +#include + +static int g_checks, g_failed; +__attribute__((unused)) 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; } +/* expect bits exactly, or any NaN when want is a NaN */ +static void expect(const char *what, uint32_t in, uint32_t got, uint32_t want) { + int nan = (want & 0x7fffffffu) > 0x7f800000u, ok = nan ? (got & 0x7fffffffu) > 0x7f800000u : got == want; + g_checks++; + if (!ok) { g_failed++; printf("FAIL: %s(0x%08x) = 0x%08x (%g), want 0x%08x (%g)\n", what, in, got, u2f(got), want, u2f(want)); } +} + +#ifndef WS_SIM_HDR +#define MODEL "helper" +static void run_model(void) { + /* every subnormal of both signs, sampled across the whole mantissa range, plus its extremes */ + for (uint32_t m = 1; m < 0x800000u; m += (m < 64 || m > 0x7fffc0u) ? 1u : 4093u) { + expect("ftz", m, f2u(ws_mufu_ftz(u2f(m))), 0x00000000u); + expect("ftz", 0x80000000u | m, f2u(ws_mufu_ftz(u2f(0x80000000u | m))), 0x80000000u); + } + static const uint32_t pass[] = { 0x00000000u, 0x80000000u, 0x00800000u, 0x80800000u, 0x3f800000u, 0xbf800000u, + 0x7f7fffffu, 0xff7fffffu, 0x7f800000u, 0xff800000u, 0x7fc00000u, 0xffc00000u, 0x7f800001u, 0x00ffffffu }; + for (size_t i = 0; i < sizeof pass / sizeof pass[0]; i++) expect("ftz", pass[i], f2u(ws_mufu_ftz(u2f(pass[i]))), pass[i]); + /* the three functions, same table the simulators use below */ + expect("ex2", f2u(-130.0f), f2u(ws_mufu_ex2(-130.0f)), 0x00000000u); + expect("rcp", 0xff400000u, f2u(ws_mufu_rcp(u2f(0xff400000u))), 0x80000000u); + expect("rsq", 0x00000200u, f2u(ws_mufu_rsq(u2f(0x00000200u))), 0x7f800000u); +} +#else +#define MODEL WS_SIM_HDR +static BlackwellIRProgram g_prog; +static uint32_t sim_mufu(BlackwellIROpcode op, uint32_t x) { + static WsSim s; static WsLane l; + memset(&s, 0, sizeof s); memset(&l, 0, sizeof l); + BlackwellIRInsn in; memset(&in, 0, sizeof in); + in.op = op; in.dst_vreg = 0; in.src1_vreg = 1; in.src2_vreg = -1; in.src3_vreg = -1; in.ureg = -1; + s.p = &g_prog; l.r[1] = x; l.r[0] = 0xdeadbeefu; + ws_lane_exec(&s, &l, &in, 0, 0, 0, 0); + return l.r[0]; +} +static void run_model(void) { + (void)ws_run; /* the warp scheduler is not under test here */ + g_prog.regalloc.vreg_to_phys[0] = 0; g_prog.regalloc.vreg_to_phys[1] = 1; + static const struct { BlackwellIROpcode op; const char *name; uint32_t in, want; } c[] = { + /* subnormal result -> sign-preserving zero (IEEE: 0x00080000, 0x00155555 / 0x80155555) */ + { BW_IR_MUFU_EX2, "EX2", 0xc3020000u /* -130 */, 0x00000000u }, + { BW_IR_MUFU_EX2, "EX2", 0xc2fe0000u /* -127 */, 0x00000000u }, + { BW_IR_MUFU_RCP, "RCP", 0x7f400000u /* 1.5 * 2^127 */, 0x00000000u }, + { BW_IR_MUFU_RCP, "RCP", 0xff400000u /* -1.5 * 2^127 */, 0x80000000u }, + /* subnormal input -> treated as a zero of the same sign (IEEE: 2^127, -2^127, 2^70) */ + { BW_IR_MUFU_RCP, "RCP", 0x00400000u /* 2^-127 */, 0x7f800000u }, + { BW_IR_MUFU_RCP, "RCP", 0x80400000u /* -2^-127 */, 0xff800000u }, + { BW_IR_MUFU_RSQ, "RSQ", 0x00000200u /* 2^-140 */, 0x7f800000u }, + { BW_IR_MUFU_EX2, "EX2", 0x80000200u /* -2^-140 */, 0x3f800000u }, + /* controls: unchanged by the flush */ + { BW_IR_MUFU_EX2, "EX2", 0xc2fc0000u /* -126 -> smallest normal */, 0x00800000u }, + { BW_IR_MUFU_EX2, "EX2", 0x40400000u /* 3 */, 0x41000000u }, + { BW_IR_MUFU_EX2, "EX2", 0xff800000u /* -inf */, 0x00000000u }, + { BW_IR_MUFU_EX2, "EX2", 0x7f800000u /* +inf */, 0x7f800000u }, + { BW_IR_MUFU_EX2, "EX2", 0x7fc00000u /* NaN */, 0x7fc00000u }, + { BW_IR_MUFU_RCP, "RCP", 0x7e800000u /* 2^126 -> smallest normal */, 0x00800000u }, + { BW_IR_MUFU_RCP, "RCP", 0x40000000u /* 2 */, 0x3f000000u }, + { BW_IR_MUFU_RCP, "RCP", 0x80000000u /* -0 */, 0xff800000u }, + { BW_IR_MUFU_RCP, "RCP", 0xff800000u /* -inf */, 0x80000000u }, + { BW_IR_MUFU_RCP, "RCP", 0x7fc00000u /* NaN */, 0x7fc00000u }, + { BW_IR_MUFU_RSQ, "RSQ", 0x40800000u /* 4 */, 0x3f000000u }, + { BW_IR_MUFU_RSQ, "RSQ", 0x00800000u /* 2^-126 */, 0x5f000000u }, + { BW_IR_MUFU_RSQ, "RSQ", 0x7f800000u /* +inf */, 0x00000000u }, + { BW_IR_MUFU_RSQ, "RSQ", 0x80000000u /* -0 */, 0xff800000u }, + }; + for (size_t i = 0; i < sizeof c / sizeof c[0]; i++) expect(c[i].name, c[i].in, sim_mufu(c[i].op, c[i].in), c[i].want); +} +#endif + +int main(void) { + run_model(); + printf("%s: mufu-ftz %s: %d checks, %d failed\n", g_failed ? "FAIL" : "PASS", MODEL, g_checks, g_failed); + return g_failed ? 1 : 0; +} diff --git a/tests/bw_warp_sim.h b/tests/bw_warp_sim.h index 6d93828f3..3ad56d3ab 100644 --- a/tests/bw_warp_sim.h +++ b/tests/bw_warp_sim.h @@ -51,12 +51,13 @@ * nobody wrote shows up in the oracle comparison. * * Per-lane ALU semantics are those of the two earlier simulators (tests/gpu_attention_test.c, - * bench/prime_race/tests/gb10_sieve_host_test.c). EX2 and RCP are exact here; the chip's - * are approximate. LDCU64 (memory descriptor) is not modelled. */ + * bench/prime_race/tests/gb10_sieve_host_test.c). MUFU EX2 / RCP / RSQ are the correctly + * rounded IEEE value with the chip's subnormal flush (bw_mufu_ftz.h); the chip's are approximate. LDCU64 (memory descriptor) is not modelled. */ #ifndef BW_WARP_SIM_H #define BW_WARP_SIM_H #include "omega_blackwell_codegen.h" +#include "bw_mufu_ftz.h" /* MUFU EX2 / RCP / RSQ: the chip's flush of subnormal inputs and results (omega #462) */ #include #include #include @@ -182,9 +183,9 @@ static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, case BW_IR_FFMA: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaf(ws_u2f(a), ws_u2f(b), ws_u2f(c))), p); break; case BW_IR_FMNMX_MAX: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; case BW_IR_FMNMX_MIN: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(exp2f(ws_u2f(a))), p); break; - case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / ws_u2f(a)), p); break; - case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; + case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ex2(ws_u2f(a))), p); break; + case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rcp(ws_u2f(a))), p); break; + case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rsq(ws_u2f(a))), p); break; default: ws_fail(s, WS_E_OP, pc, "opcode not modelled"); return; } } diff --git a/tests/bw_warp_sim_k.h b/tests/bw_warp_sim_k.h index 993875647..138a4b146 100644 --- a/tests/bw_warp_sim_k.h +++ b/tests/bw_warp_sim_k.h @@ -51,8 +51,8 @@ * nobody wrote shows up in the oracle comparison. * * Per-lane ALU semantics are those of the two earlier simulators (tests/gpu_attention_test.c, - * bench/prime_race/tests/gb10_sieve_host_test.c). EX2 and RCP are exact here; the chip's - * are approximate. LDCU64 (memory descriptor) is not modelled. */ + * bench/prime_race/tests/gb10_sieve_host_test.c). MUFU EX2 / RCP / RSQ are the correctly + * rounded IEEE value with the chip's subnormal flush (bw_mufu_ftz.h); the chip's are approximate. LDCU64 (memory descriptor) is not modelled. */ #ifndef BW_WARP_SIM_K_H #define BW_WARP_SIM_K_H /* bw_warp_sim_k.h (OWN-30B cut 8, 2026-10-13): tests/bw_warp_sim.h plus the system-scope opcodes the decode attention @@ -60,6 +60,7 @@ * The simulator runs CTAs one after another, so an atomic counter sees every earlier CTA's add. */ #include "omega_blackwell_codegen.h" +#include "bw_mufu_ftz.h" /* MUFU EX2 / RCP / RSQ: the chip's flush of subnormal inputs and results (omega #462) */ #include "omega_blackwell_codegen_tc.h" #include #include @@ -193,9 +194,9 @@ static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, if (in->imm == OMEGA_TC_MARK_F2FP) { ws_wrs(l, in->dst_vreg, in->dst_subreg, (ws_k_bf16_rn(a) << 16) | ws_k_bf16_rn(b), p); break; } /* F2FP.BF16.F32.PACK_AB placeholder (L313 bf16 state) */ ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; case BW_IR_FMNMX_MIN: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(exp2f(ws_u2f(a))), p); break; - case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / ws_u2f(a)), p); break; - case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; + case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ex2(ws_u2f(a))), p); break; + case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rcp(ws_u2f(a))), p); break; + case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rsq(ws_u2f(a))), p); break; case BW_IR_MUFU_LG2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(log2f(ws_u2f(a))), p); break; case BW_IR_LDG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; memcpy((void *)(uintptr_t)ad, &b, 4); break; } diff --git a/tests/bw_warp_sim_pa.h b/tests/bw_warp_sim_pa.h index 157e396cd..3239ca0b4 100644 --- a/tests/bw_warp_sim_pa.h +++ b/tests/bw_warp_sim_pa.h @@ -51,8 +51,8 @@ * nobody wrote shows up in the oracle comparison. * * Per-lane ALU semantics are those of the two earlier simulators (tests/gpu_attention_test.c, - * bench/prime_race/tests/gb10_sieve_host_test.c). EX2 and RCP are exact here; the chip's - * are approximate. LDCU64 (memory descriptor) is not modelled. */ + * bench/prime_race/tests/gb10_sieve_host_test.c). MUFU EX2 / RCP / RSQ are the correctly + * rounded IEEE value with the chip's subnormal flush (bw_mufu_ftz.h); the chip's are approximate. LDCU64 (memory descriptor) is not modelled. */ #ifndef BW_WARP_SIM_PA_H /* bw_warp_sim_pa.h (OWN-30B L1 attention, 2026-10-13): bw_warp_sim_tc.h with the HMMA operands read at their sub-register * offsets (src1/src2/src3_subreg; the encoder adds them to the physical register, bw_warp_sim_tc.h ignored them). The @@ -67,6 +67,7 @@ * encoder emits and bw_warp_sim_k.h ignored. Timing (stall counts, scoreboards) is not modelled. */ #include "omega_blackwell_codegen.h" +#include "bw_mufu_ftz.h" /* MUFU EX2 / RCP / RSQ: the chip's flush of subnormal inputs and results (omega #462) */ #include "bw_hmma_model.h" #include "omega_blackwell_codegen_tc.h" #include @@ -200,9 +201,9 @@ static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, if (in->imm == OMEGA_TC_MARK_F2FP) { ws_wrs(l, in->dst_vreg, in->dst_subreg, (ws_bf16_rn(a) << 16) | ws_bf16_rn(b), p); break; } /* F2FP.BF16.F32.PACK_AB placeholder */ ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; case BW_IR_FMNMX_MIN: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(exp2f(ws_u2f(a))), p); break; - case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / ws_u2f(a)), p); break; - case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(1.0f / sqrtf(ws_u2f(a))), p); break; + case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ex2(ws_u2f(a))), p); break; + case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rcp(ws_u2f(a))), p); break; + case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rsq(ws_u2f(a))), p); break; case BW_IR_LDG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; memcpy((void *)(uintptr_t)ad, &b, 4); break; } case BW_IR_ATOMG_ADD_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t old; memcpy(&old, (const void *)(uintptr_t)ad, 4); uint32_t nw = old + b; memcpy((void *)(uintptr_t)ad, &nw, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, old, p); break; } diff --git a/tests/bw_warp_sim_tc.h b/tests/bw_warp_sim_tc.h index a08e38b6a..3169b0ef9 100644 --- a/tests/bw_warp_sim_tc.h +++ b/tests/bw_warp_sim_tc.h @@ -51,8 +51,8 @@ * nobody wrote shows up in the oracle comparison. * * Per-lane ALU semantics are those of the two earlier simulators (tests/gpu_attention_test.c, - * bench/prime_race/tests/gb10_sieve_host_test.c). EX2 and RCP are exact here; the chip's - * are approximate. LDCU64 (memory descriptor) is not modelled. */ + * bench/prime_race/tests/gb10_sieve_host_test.c). MUFU EX2 / RCP / RSQ are the correctly + * rounded IEEE value with the chip's subnormal flush (bw_mufu_ftz.h); the chip's are approximate. LDCU64 (memory descriptor) is not modelled. */ #ifndef BW_WARP_SIM_TC_H #define BW_WARP_SIM_TC_H /* bw_warp_sim_k.h (OWN-30B cut 8, 2026-10-13): tests/bw_warp_sim.h plus the system-scope opcodes the decode attention @@ -64,6 +64,7 @@ * encoder emits and bw_warp_sim_k.h ignored. Timing (stall counts, scoreboards) is not modelled. */ #include "omega_blackwell_codegen.h" +#include "bw_mufu_ftz.h" /* MUFU EX2 / RCP / RSQ: the chip's flush of subnormal inputs and results (omega #462) */ #include "bw_hmma_model.h" #include "omega_blackwell_codegen_tc.h" #include "omega_blackwell_codegen_qmma.h" @@ -143,16 +144,7 @@ static void ws_wrs(WsLane *l, int v, unsigned sub, uint32_t x, const BlackwellIR static float ws_u2f(uint32_t u) { float f; memcpy(&f, &u, 4); return f; } static uint32_t ws_f2u(float f) { uint32_t u; memcpy(&u, &f, 4); return u; } static uint32_t ws_bf16_rn(uint32_t u) { if ((u & 0x7fffffffu) > 0x7f800000u) return 0x7fc0u; return (u + 0x7fffu + ((u >> 16) & 1u)) >> 16; } /* f32 bits -> bf16 bits, round to nearest even */ -/* MUFU (the SASS EX2 / RCP / RSQ unit) flushes a subnormal result to a sign-preserving zero. Chip-observed on GB10: the SwiGLU - * reciprocal 1 / (2^t + 1) for t in (126, 128) came back as +-0 on all 101 of 101 differing elements (evidence - * OWN30B-L1G-PFGEMM-SWIGLU-FTZ-df9bd9c4, gpu_pfgemm_test host red test). Doc-inferred, not separately chip-observed: the input flush - * and the EX2 / RSQ cases follow the same rule, PTX ISA 9.7.3.13 (rcp) and 9.7.3.21 (ex2) "flushes subnormal inputs and results to - * sign-preserving zero" for the .ftz form, which is what the bare MUFU we emit is (the non-ftz PTX variants are ptxas sequences around - * MUFU; NVIDIA publishes no SASS semantics). Limit: the chip's MUFU is approximate (RCP 1 ulp, EX2 2 ulp), the model flushes a correctly - * rounded IEEE result, so right at the subnormal boundary the two can disagree 0 versus nonzero. This simulator and the pfgemm reference - * go through this helper; bw_warp_sim.h, bw_warp_sim_k.h, bw_warp_sim_pa.h and gpu_attention_test.c still model MUFU as IEEE (issue filed - * with PR #461). omega_numeric.c has its own ftz() on the library side. */ -static float ws_mufu_ftz(float f) { uint32_t u = ws_f2u(f); if ((u & 0x7f800000u) == 0u) u &= 0x80000000u; return ws_u2f(u); } +/* MUFU EX2 / RCP / RSQ: the flush rule and its evidence live in bw_mufu_ftz.h (shared by every simulator, omega #462). */ static uint32_t ws_lut3(uint32_t lut, uint32_t a, uint32_t b, uint32_t c) { uint32_t r = 0; for (int i = 0; i < 8; i++) if (lut >> i & 1) r |= ((i & 4) ? a : ~a) & ((i & 2) ? b : ~b) & ((i & 1) ? c : ~c); @@ -210,9 +202,9 @@ static void ws_lane_exec(WsSim *s, WsLane *l, const BlackwellIRInsn *in, int pc, if (in->imm == OMEGA_QMMA_MARK_F2E4) { ws_wrs(l, in->dst_vreg, in->dst_subreg, (uint32_t)qm_e4m3_rne_sat(ws_u2f(a)) << 8 | qm_e4m3_rne_sat(ws_u2f(b)), p); break; } /* F2FP.SATFINITE.E4M3 placeholder (NaN not modelled) */ ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fmaxf(ws_u2f(a), ws_u2f(b))), p); break; case BW_IR_FMNMX_MIN: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(fminf(ws_u2f(a), ws_u2f(b))), p); break; - case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ftz(exp2f(ws_mufu_ftz(ws_u2f(a))))), p); break; - case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ftz(1.0f / ws_mufu_ftz(ws_u2f(a)))), p); break; - case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ftz(1.0f / sqrtf(ws_mufu_ftz(ws_u2f(a))))), p); break; + case BW_IR_MUFU_EX2: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_ex2(ws_u2f(a))), p); break; + case BW_IR_MUFU_RCP: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rcp(ws_u2f(a))), p); break; + case BW_IR_MUFU_RSQ: ws_wrs(l, in->dst_vreg, in->dst_subreg, ws_f2u(ws_mufu_rsq(ws_u2f(a))), p); break; case BW_IR_LDG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t x; memcpy(&x, (const void *)(uintptr_t)ad, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, x, p); break; } case BW_IR_STG_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; memcpy((void *)(uintptr_t)ad, &b, 4); break; } case BW_IR_ATOMG_ADD_STRONG_SYS: { uint64_t ad = ws_rd64(l, in->src1_vreg, p); if (!ws_mem_ok(s, ad, 4, pc)) return; uint32_t old; memcpy(&old, (const void *)(uintptr_t)ad, 4); uint32_t nw = old + b; memcpy((void *)(uintptr_t)ad, &nw, 4); ws_wrs(l, in->dst_vreg, in->dst_subreg, old, p); break; } diff --git a/tests/gates/omega-numeric-cpu.gate b/tests/gates/omega-numeric-cpu.gate index 5d1ea7294..c79198dc6 100644 --- a/tests/gates/omega-numeric-cpu.gate +++ b/tests/gates/omega-numeric-cpu.gate @@ -1,5 +1,6 @@ # tests/gates/omega-numeric-cpu.gate -# Mirrors hosted: host-suites.yml numeric-cpu: test-numeric-cpu test-numeric-qualify test-e1-combine test-chipwait-campaign test-gpu-wait test-gpu-wait-mutants test-gpu-code-alloc (hosted 63 s) +# Mirrors hosted: host-suites.yml numeric-cpu: test-numeric-cpu test-numeric-qualify test-e1-combine test-chipwait-campaign test-gpu-wait test-gpu-wait-mutants test-gpu-code-alloc test-mufu-ftz (hosted 63 s before test-mufu-ftz) +# test-mufu-ftz (omega #462) is host-only: the MUFU flush helper and the four warp simulators; no chip runs gate: OMEGA-NUMERIC-CPU manifest_version: 2 owner: omega @@ -12,6 +13,14 @@ inputs: - tests/test_omega_numeric.c - tests/numeric_oracle.h - tests/run_numeric_gates.sh + - tests/bw_mufu_ftz.h + - tests/bw_mufu_ftz_test.c + - tests/bw_warp_sim.h + - tests/bw_warp_sim_k.h + - tests/bw_warp_sim_pa.h + - tests/bw_warp_sim_tc.h + - tests/bw_hmma_model.h + - tests/bw_qmma_model.h - tools/ - tests/gates/ run: diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 66da8e1a9..3fc2bd44f 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -123,7 +123,7 @@ case "$step" in searchtrace) make $NOPHYS test-searchtrace ;; estimation) for t in test-estimation test-est-tools test-estimation-v3 test-est3c-tools; do make $NOPHYS $t; done ;; ans) make $NOPHYS test-inertial-alignment ;; - numeric-cpu) for t in test-numeric-cpu test-numeric-qualify test-e1-combine test-chipwait-campaign test-gpu-wait test-gpu-wait-mutants test-gpu-code-alloc; do make $NOPHYS $t; done ;; + numeric-cpu) for t in test-numeric-cpu test-numeric-qualify test-e1-combine test-chipwait-campaign test-gpu-wait test-gpu-wait-mutants test-gpu-code-alloc test-mufu-ftz; do make $NOPHYS $t; done ;; train) make $NOPHYS test-train ;; compiler) make $NOPHYS test-compiler-quick; make $NOPHYS test-compiler-full ;; one-layer-acceptance) make $NOPHYS test-one-layer-acceptance ;; diff --git a/tests/gpu_attention_test.c b/tests/gpu_attention_test.c index b42cd14dc..8ba96c81c 100644 --- a/tests/gpu_attention_test.c +++ b/tests/gpu_attention_test.c @@ -769,8 +769,8 @@ static int sim_step(SimThr *t, const BlackwellIRProgram *p, uint32_t tid, uint32 case BW_IR_FMUL: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(u2f(a) * u2f(b)), p); break; case BW_IR_FFMA: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(fmaf(u2f(a), u2f(b), u2f(c))), p); break; case BW_IR_FMNMX_MAX: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(fmaxf(u2f(a), u2f(b))), p); break; - case BW_IR_MUFU_EX2: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(exp2f(u2f(a))), p); break; - case BW_IR_MUFU_RCP: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(1.0f / u2f(a)), p); break; + case BW_IR_MUFU_EX2: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(ws_mufu_ex2(u2f(a))), p); break; /* bw_mufu_ftz.h (#462) */ + case BW_IR_MUFU_RCP: wrs(t, in->dst_vreg, in->dst_subreg, f2u_(ws_mufu_rcp(u2f(a))), p); break; default: g_sim_err = 100 + (int)in->op; t->done = 1; return 0; } if (g_trace && tid == 0 && cx == g_trace_cx && cy == 0 && g_trace_launch == 1) { uint32_t dv = rd(t, in->dst_vreg, p); printf("T pc=%d op=%d dst=v%d(r%d)=%08x f=%g p0=%d a=%08x b=%08x c=%08x\n", t->pc, (int)in->op, in->dst_vreg, in->dst_vreg >= 0 ? p->regalloc.vreg_to_phys[in->dst_vreg] : -1, dv, u2f(dv), t->p0, a, b, c); } @@ -778,6 +778,30 @@ static int sim_step(SimThr *t, const BlackwellIRProgram *p, uint32_t tid, uint32 } g_sim_err = 4; t->done = 1; return 0; } +/* omega #462: this per-thread simulator's MUFU cases follow the chip's flush rule (tests/bw_mufu_ftz.h). One MUFU then + * EXIT through sim_step: a subnormal EX2 / RCP result is a zero of the same sign, a subnormal RCP input is a zero (so the + * result is an infinity), normals unchanged. Reachable in the kernel: softmax EX2 of a score more than 126 below the + * running max (log2 units) is subnormal in IEEE and 0 on the chip. */ +static void mufu_ftz_sim_check(void) { + static BlackwellIRProgram p; + static const struct { BlackwellIROpcode op; uint32_t in, want; } c[] = { + { BW_IR_MUFU_EX2, 0xc3020000u /* -130 */, 0x00000000u }, { BW_IR_MUFU_EX2, 0xc2fc0000u /* -126 */, 0x00800000u }, + { BW_IR_MUFU_RCP, 0x7f400000u /* 1.5 * 2^127 */, 0x00000000u }, { BW_IR_MUFU_RCP, 0xff400000u, 0x80000000u }, + { BW_IR_MUFU_RCP, 0x00400000u /* 2^-127 */, 0x7f800000u }, { BW_IR_MUFU_RCP, 0x7e800000u /* 2^126 */, 0x00800000u }, + }; + memset(&p, 0, sizeof p); + p.count = 2; p.regalloc.vreg_to_phys[0] = 0; p.regalloc.vreg_to_phys[1] = 1; + for (int i = 0; i < 2; i++) { p.insns[i].dst_vreg = p.insns[i].src1_vreg = p.insns[i].src2_vreg = p.insns[i].src3_vreg = p.insns[i].ureg = -1; } + p.insns[1].op = BW_IR_EXIT; + for (size_t i = 0; i < sizeof c / sizeof c[0]; i++) { + SimThr t; memset(&t, 0, sizeof t); + p.insns[0].op = c[i].op; p.insns[0].dst_vreg = 0; p.insns[0].src1_vreg = 1; + t.r[1] = c[i].in; t.r[0] = 0xdeadbeefu; g_sim_err = 0; + sim_step(&t, &p, 0, 0, 0); + CHECK(g_sim_err == 0 && t.r[0] == c[i].want, "attention sim MUFU %s(0x%08x) = 0x%08x, chip rule 0x%08x (omega #462)", + c[i].op == BW_IR_MUFU_EX2 ? "EX2" : "RCP", c[i].in, t.r[0], c[i].want); + } +} static int sim_launch(const void *progv, const OmegaGpuAttnLaunch *L, OmegaGpuAttnInfo *info) { const BlackwellIRProgram *p = progv; memset(sim_cbank, 0, sizeof sim_cbank); @@ -1207,7 +1231,7 @@ int main(int argc, char **argv) { if (g_divergent) omega_gpu_attention_test_set_divergent(1); if (sim) { g_sim_mode = 1; omega_gpu_attention_test_set_simulator(g_divergent ? ws_attn_launch : sim_launch); } if (sim && g_divergent && !host) divergent_negative_control(); - if (host) { host_only(); hd_codegen_checks(); } + if (host) { host_only(); hd_codegen_checks(); mufu_ftz_sim_check(); } else if (split_timing_mode) { if (split_timing(out_path) != 0) return 2; } else if (timing_mode) { if (timing(out_path) != 0) return 2; } else if (sweep_mode) { if (sweep(out_path) != 0) return 2; } diff --git a/tests/gpu_pfgemm_test.c b/tests/gpu_pfgemm_test.c index 56bf974f5..900878f59 100644 --- a/tests/gpu_pfgemm_test.c +++ b/tests/gpu_pfgemm_test.c @@ -95,11 +95,11 @@ static float emu_phys(const Prob *p, uint32_t i, uint32_t c) { return acc * R(KB); #undef R } -/* the kernel's epilogue arithmetic: MUFU.EX2, FADD, MUFU.RCP, FMUL x 3, F2FP. The two MUFU results pass through ws_mufu_ftz - * (bw_warp_sim_tc.h): the chip's MUFU flushes a subnormal result to a sign-preserving zero, so for t = -g log2 e in (126, 128) +/* the kernel's epilogue arithmetic: MUFU.EX2, FADD, MUFU.RCP, FMUL x 3, F2FP. The two MUFU ops go through ws_mufu_ex2 / ws_mufu_rcp + * (bw_mufu_ftz.h, omega #462): the chip's MUFU flushes a subnormal result to a sign-preserving zero, so for t = -g log2 e in (126, 128) * (g in (-88.72, -87.34)) the reciprocal is +-0 and the activation is +-0, not the 2^-56-ish product an IEEE 1/d would give. */ static uint16_t swiglu_bits(float g, float u) { - float t = g * u2f(0xbfb8aa3bu), ex = ws_mufu_ftz(exp2f(ws_mufu_ftz(t))), d = ex + 1.0f, r = ws_mufu_ftz(1.0f / ws_mufu_ftz(d)), o = g * r; + float t = g * u2f(0xbfb8aa3bu), ex = ws_mufu_ex2(t), d = ex + 1.0f, r = ws_mufu_rcp(d), o = g * r; o = o * u; o = o * u2f(0x5f800000u); return bf16_rn(o); } diff --git a/tests/gpu_prefill_attn_test.c b/tests/gpu_prefill_attn_test.c index a17362ae7..5a20ae554 100644 --- a/tests/gpu_prefill_attn_test.c +++ b/tests/gpu_prefill_attn_test.c @@ -94,7 +94,7 @@ static void emu_rows(const float *qkv_row, const float *kn, float eps, uint32_t for (unsigned i = 0; i < 128; i++) x[i] = qkv_row[4096 + gk * 128 + i]; for (unsigned L = 0; L < 32; L++) { float a = x[4 * L] * x[4 * L]; for (unsigned i = 1; i < 4; i++) a = fmaf(x[4 * L + i], x[4 * L + i], a); sq[L] = a; } for (unsigned o = 16; o >= 1; o /= 2) { float nx[32]; for (unsigned L = 0; L < 32; L++) nx[L] = sq[L] + (L + o < 32 ? sq[L + o] : sq[L]); memcpy(sq, nx, sizeof sq); } - float rs = 1.0f / sqrtf(fmaf(sq[0], u2f(0x3c000000u), eps)); + float rs = ws_mufu_rsq(fmaf(sq[0], u2f(0x3c000000u), eps)); /* MUFU.RSQ, bw_mufu_ftz.h (#462); eps > 0 keeps it normal */ for (unsigned i = 0; i < 128; i++) { x[i] = x[i] * rs; x[i] = x[i] * kn[i]; } float y[128]; for (unsigned i = 0; i < 128; i++) { diff --git a/tests/gpu_qgemm_test.c b/tests/gpu_qgemm_test.c index 3c33dc3c8..15dd5cb87 100644 --- a/tests/gpu_qgemm_test.c +++ b/tests/gpu_qgemm_test.c @@ -229,8 +229,12 @@ static float qemu_phys(const QProb *p, uint32_t i, uint32_t c) { } return acc; } +/* the kernel's SwiGLU epilogue (omega_blackwell_codegen_qg.c: FMNMX t-cap, MUFU.EX2, MUFU.RCP). Both MUFU results go + * through the chip's flush rule (tests/bw_mufu_ftz.h, omega #462). Not observable with the t-cap: t <= 125 keeps + * 1 / (2^t + 1) >= 2^-125 normal, and an EX2 result below 2^-126 (t < -126) rounds to the same d = 1.0 after the +1 as + * its flushed zero; qg_host checks this bit for bit. Removing the cap (issue #462) is a separate chip-gated change. */ static uint16_t qswiglu_bits(float g, float u) { - float t = fminf(g * u2f(0xbfb8aa3bu), 125.0f), ex = exp2f(t), d = ex + 1.0f, r = 1.0f / d, o = g * r; + float t = fminf(g * u2f(0xbfb8aa3bu), 125.0f), ex = ws_mufu_ex2(t), d = ex + 1.0f, r = ws_mufu_rcp(d), o = g * r; o = o * u; return bf16_rn(o); } @@ -271,8 +275,26 @@ static size_t qcompare(const QProb *p, const void *y, const uint32_t *rows, uint return bad; } +/* omega #462: with the t-cap the MUFU flush never changes a SwiGLU output bit. Compare qswiglu_bits against the IEEE + * form over every g in [80, 110] and [-110, -80] (the EX2-subnormal window t in (-150, -126] and the cap t = 125, both + * signs) plus a stride-65537 sample of all f32. Not a red test: there is no input for which the two differ. */ +static int qg_mufu_ftz_unobservable(void) { + uint64_t n = 0, diff = 0; + const float us[2] = { 1.0f, -3.0f }; + for (int pass = 0; pass < 3; pass++) { + uint64_t lo = pass == 0 ? f2u(80.0f) : pass == 1 ? f2u(-80.0f) : 0, hi = pass == 0 ? f2u(110.0f) : pass == 1 ? f2u(-110.0f) : 0xffffffffull, step = pass == 2 ? 65537 : 1; + for (uint64_t b = lo; b <= hi; b += step) { + float g = u2f((uint32_t)b); + if (isnan(g)) continue; + float t = fminf(g * u2f(0xbfb8aa3bu), 125.0f), r = 1.0f / (exp2f(t) + 1.0f); + for (int k = 0; k < 2; k++) { n++; if (bf16_rn((g * r) * us[k]) != qswiglu_bits(g, us[k])) diff++; } + } + } + printf("%s qgemm SwiGLU: MUFU flush vs IEEE, %llu inputs, %llu differ (t-cap keeps it unobservable, #462)\n", diff ? "FAIL" : "PASS", (unsigned long long)n, (unsigned long long)diff); + return diff ? 1 : 0; +} static int qg_host(void) { - int fail = 0; + int fail = qg_mufu_ftz_unobservable(); for (uint32_t layout = 0; layout < 3; layout += 2) { QProb p; qprob_make(&p, 3, 256, 384, 40, 17, layout, 0, 0); double worst = 0; ```