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
omega-mv / docs / numeric / E1_DIVSQRT_GB10.md
| 1 | # E1 row 7: correctly rounded FP32 DIV and SQRT on the GB10 |
| 2 | |
| 3 | Status: see "Result" at the end. This page covers gap-table row 7 in |
| 4 | `E1_GAP_TABLE.md`. |
| 5 | |
| 6 | ## What this closes |
| 7 | |
| 8 | The GB10 (Blackwell, sm_121) now has its own FP32 divide and square root kernels. |
| 9 | Each one gives the same bits as the CPU semantic `omega_math_div` / |
| 10 | `omega_math_sqrt`, which is the IEEE 754 result: round to nearest even, |
| 11 | subnormal inputs and outputs kept (no flush to zero), and every NaN result |
| 12 | returned as the canonical quiet NaN `0x7fc00000`. The comparison on the chip |
| 13 | is against the AArch64 `FDIV` / `FSQRT` instructions and against |
| 14 | `omega_math_*`. Both must match, with zero mismatches. |
| 15 | |
| 16 | ## How the kernels work |
| 17 | |
| 18 | Neither kernel uses the hardware's approximate reciprocal or square root |
| 19 | units (MUFU), and neither uses floating-point multiply-add. Each one does the |
| 20 | whole operation with exact integer arithmetic, the same way the CPU semantic |
| 21 | does, so the rounding is exact by construction: |
| 22 | |
| 23 | * **Unpack.** `|x| = m * 2^e` with `m` in `[2^23, 2^24)`. For subnormal inputs, |
| 24 | the leading bit comes from `I2FP.F32.S32` (exact for values below 2^24), and |
| 25 | `m` is the input shifted left by `23 - msb`. |
| 26 | * **DIV.** Restoring long division gives 27 quotient bits |
| 27 | (6 instructions per bit). The remainder is the sticky bit. |
| 28 | * **SQRT.** If the exponent is odd, it is first made even by shifting `m`. |
| 29 | Then digit-by-digit square root over 27 bit pairs (8 to 10 instructions per |
| 30 | bit). The remainder is the sticky bit. |
| 31 | * **Round and pack.** One shared sequence, the same as `omega_round_pack`. |
| 32 | It handles the normal and subnormal result ranges, round to nearest even |
| 33 | from the guard bit, the bits below it and the sticky bit, overflow to |
| 34 | infinity, and underflow to zero. |
| 35 | * **Special operands.** These are applied last, in the priority order of |
| 36 | `omega_math_div` / `omega_math_sqrt`: zero, infinity, 0/0, inf/inf, NaN, and |
| 37 | negative inputs to SQRT. |
| 38 | |
| 39 | Every shift amount on a path that affects the result stays inside `[0, 31]`. |
| 40 | |
| 41 | ## Kernel layout |
| 42 | |
| 43 | | Part | Words | |
| 44 | |---|---| |
| 45 | | Prologue | the 17 vecadd words, unchanged: thread index, bounds check, addresses, `LDG a` into R2, `LDG b` into R5 | |
| 46 | | Body | 13 instruction forms, all `PT`-guarded, control word `0x010fde00` | |
| 47 | | Epilogue | vecadd `STG [R6.64], R9`, `EXIT`, `BRA` | |
| 48 | | Padding | NOPs up to a multiple of 8 | |
| 49 | |
| 50 | About the body control word `0x010fde00`: it means stall 15, no barrier set, |
| 51 | and wait on scoreboard SB4. SB4 is the write barrier both vecadd `LDG`s set. |
| 52 | Every body instruction is fixed-latency, so stall 15 is the conservative |
| 53 | ptxas `-O0` pattern for this class. |
| 54 | |
| 55 | The QMD allocates 48 registers. The hardware reserves the top two of the |
| 56 | allocation: a 32-register QMD faulted (Xid 13, "Out Of Range Register") on |
| 57 | the LOG2, SIGMOID and TANH bodies, which use R30 and R31 (receipt |
| 58 | `1dc85ef2`, kept as NOT_RUN). DIV and SQRT write R8 through R27 and R9; the |
| 59 | transcendental bodies use up to R31. No body touches R1, R6, R7 or the |
| 60 | uniform registers. |
| 61 | |
| 62 | ## Provenance (no invented encodings) |
| 63 | |
| 64 | * Every body word comes from `omega_ds_encode` in |
| 65 | `src/omega_numeric_divsqrt_gb10.c`. |
| 66 | * The form templates (opcode, fixed bits and field positions) come from two |
| 67 | sources, both decoded offline by nvdisasm: |
| 68 | * ptxas 13.0.88 `-O0` oracle output for each instruction class; |
| 69 | * single-word probes. |
| 70 | * No ptxas kernel is copied. |
| 71 | * `tools/divsqrt_nvdisasm_check.sh` dumps both kernels and disassembles every |
| 72 | word with `nvdisasm -b SM121` (version 13.0.85 on this machine). It then |
| 73 | requires the text to equal, line by line, the listing the encoder produces |
| 74 | for itself (`omega_ds_listing`). |
| 75 | * The kernel SHA-256 values recorded in `OMEGA_DS_KERNEL_SHA256` were taken |
| 76 | after that check passed. The executor refuses any kernel with a different |
| 77 | digest. |
| 78 | |
| 79 | ## Pre-submission checks |
| 80 | |
| 81 | Each check in `src/omega_numeric_divsqrt_gb10.c` is one line that ends in a |
| 82 | `CHECK:` marker. `tools/divsqrt_check_sweep.sh` deletes each check in turn and |
| 83 | shows that the host tier then fails. |
| 84 | |
| 85 | | Check | What it guards | |
| 86 | |---|---| |
| 87 | | `ds_op` | the op is known | |
| 88 | | `ds_len` | the kernel length is valid | |
| 89 | | `ds_prologue` | the prologue is identical to the vecadd prologue | |
| 90 | | `ds_epilogue` | the kernel ends with `STG`, `EXIT`, `BRA` | |
| 91 | | `ds_pad` | the padding is NOPs only | |
| 92 | | `ds_body` | the body is not empty and not oversize | |
| 93 | | `ds_guard` | no body instruction is predicated | |
| 94 | | `ds_ctrl` | every body control word is the fixed control word | |
| 95 | | `ds_forms` | every body word decodes and re-encodes to the same bits (a recorded form) | |
| 96 | | `ds_def_use` | no register is read before it is written | |
| 97 | | `ds_pred_def_use` | no predicate is read before it is written | |
| 98 | | `ds_reserved` | the body never writes R1, R6 or R7 | |
| 99 | | `ds_gpr` | every register fits inside the QMD allocation, below the two registers the hardware reserves at its top | |
| 100 | | `ds_result` | the last body instruction writes R9 | |
| 101 | | `ds_digest` | the kernel digest equals the recorded nvdisasm-verified digest | |
| 102 | | `ds_args_op`, `ds_buffers`, `ds_count` | arguments | |
| 103 | | `ds_qmd`, `ds_qmd_gpr`, `ds_qmd_code` | the QMD | |
| 104 | |
| 105 | ## Verification |
| 106 | |
| 107 | | Tier | Coverage | |
| 108 | |---|---| |
| 109 | | Host (`make test-divsqrt-host`) | encoder round trips; one refusal per check; a host model of the exact body (register-level interpreter) against FDIV/FSQRT and `omega_math_*` on the hard corpus from `tests/test_omega_numeric.c`, the edge set and 200k random samples | |
| 110 | | Host, long | `--host-sqrt-all` runs all 2^32 SQRT inputs through the host model; `--host-div N` runs N random DIV pairs | |
| 111 | | Chip (`tools/run_divsqrt_gate.sh`) | SQRT: all 2^32 inputs. DIV: 7 batches of 2^24 pairs (117,440,512), with batch 0 starting with the corpus and the edge set | |
| 112 | |
| 113 | The DIV edge set covers: |
| 114 | |
| 115 | * every pair of 35 edge magnitudes with both signs: 0, subnormals, the minimum |
| 116 | and maximum normal, values near 1, the maximum finite value, infinity and |
| 117 | NaNs; |
| 118 | * neighbours of 2^±126. |
| 119 | |
| 120 | The DIV random pairs are stratified across five shapes: |
| 121 | |
| 122 | * uniform bits; |
| 123 | * both operands near 1; |
| 124 | * quotients from 2^-118 to 2^-155 (the subnormal result range); |
| 125 | * quotients from 2^124 to 2^130 (the overflow boundary); |
| 126 | * subnormal operands. |
| 127 | |
| 128 | The receipt is `~/workspace/evidence-out/E1-DIVSQRT/<sha256>.json` (mode 0444). It |
| 129 | records: |
| 130 | |
| 131 | * the omega commit and the physics commit (the `physics.lock` pin); |
| 132 | * whether each tree was clean before and after the run; |
| 133 | * the binary digest and the kernel digests; |
| 134 | * the counts and the verdict. |
| 135 | |
| 136 | The script refuses to run on a dirty tree. |
| 137 | |
| 138 | ## Result |
| 139 | |
| 140 | Three chip runs, all receipts kept (none overwritten), all under |
| 141 | `~/workspace/evidence-out/E1-DIVSQRT/`, physics pinned at e95e3ed: |
| 142 | |
| 143 | | Run | Omega commit | Verdict | Receipt (sha256) | What it showed | |
| 144 | |-----|--------------|---------|------------------|----------------| |
| 145 | | 1 | f2a6a19 | FAIL | 88930d2f03f98ba50e09a3a3e53ae17278e0f6b0c72a1b535e20ae74857e55c2 | DIV correct. 49,359,680 SQRT outputs still held the 0x55555555 fill: the host read results after the completion marker but before the stores were visible. Fix: wait for the QMD release semaphore (value 6) and a barrier before reading. | |
| 146 | | 2 | 9bd4de2 | PASS | daa1d6235373f2e7cae97c410094d4d0aeb43dbe680baafe5aa2ffd70227fed5 | Same numbers as run 3 below. | |
| 147 | | 3 | 9b5756e | PASS | de7b2dd6a930ae94529773cf4e31aa08aac7065602b1d771e13e6ed2784a9074 | Rerun after the Codex review fixes (gate exit status, commit binding, sweep crash handling, QMD high address bits, thread checks). Kernel words unchanged. This is the receipt of record. | |
| 148 | |
| 149 | Run 3 numbers: |
| 150 | |
| 151 | - DIV: 117,440,512 pairs (7 batches of 2^24; batch 0 opens with the 5,033 |
| 152 | edge and corpus pairs, the rest are random from seed 0x9e3779b97f4a7c15). 0 mismatches against AArch64 FDIV, 0 against |
| 153 | `omega_math_div`, 0 unwritten outputs. |
| 154 | - SQRT: all 4,294,967,296 inputs (exhaustive). 0 mismatches against AArch64 |
| 155 | FSQRT, 0 against `omega_math_sqrt`, 0 unwritten outputs. |
| 156 | - Host tier 53/53; nvdisasm 13.0.85 decodes all 264 + 336 words to the |
| 157 | encoder's text; mutation sweep 21/21 checks killed, 0 survived, 0 broken. |
| 158 | - Chip binary sha256 730b42a9767c163a52f311105a6140a9899ef9131007e54659a5928f341b8b9c, |
| 159 | no libm math or CUDA symbols. Run 07:16:05Z to 07:23:31Z. |
| 160 | |
| 161 | Review: Codex (gpt-6-astra, read-only sandbox) found no arithmetic blocker and |
| 162 | four MAJOR plus one MINOR integrity issues in the gate tooling; all five were |
| 163 | fixed in 9b5756e before run 3. |
| 164 | |
| 165 | Not done here: the kernels are not yet called from `omega_numeric_gb10.c` |
| 166 | (owned by another lane), so `omega_numeric` still refuses DIV/SQRT on GB10 |
| 167 | until that wiring lands. |
| 168 | |
| 169 | ## Row 10: natural EXP and LOG |
| 170 | |
| 171 | The same frame and encoder carry two more whole-program kernels: the E1 |
| 172 | `OP_TABLE` ops EXP and LOG, bit-identical to `omega_math_exp` / |
| 173 | `omega_math_log` of `src/omega_numeric.c` (built with `-ffp-contract=off`, so |
| 174 | every C operator is one unfused binary32 operation). The bodies are |
| 175 | `body_exp` / `body_log` in `src/omega_numeric_divsqrt_gb10.c`. |
| 176 | |
| 177 | | Op | Words | Kernel sha256 | Float ops (all unfused, in C order) | |
| 178 | |----|-------|---------------|-------------------------------------| |
| 179 | | EXP | 88 | b0214f4b0c8416411fdd897d640b45b27da16b92e117f57b02c6abb2f1350cb6 | 13 FMUL, 9 FADD (FSUB as FADD with a negated operand), 1 I2FP | |
| 180 | | LOG | 312 | be4f782381c34169670e45e500fd1f0afa0cc7bcfcec9f8e6aca8a41b0029a9e | 9 FMUL, 6 FADD, 3 I2FP; z = (m-1)/(m+1) is the row 7 DIV sequence (integer, correctly rounded) | |
| 181 | |
| 182 | Neither kernel contains MUFU or FFMA. EXP truncates `prod +/- 0.5` toward |
| 183 | zero from the float bits (integer shift, exact for every input that reaches |
| 184 | it), converts k with I2FP (exact for |k| <= 150), and builds 2^k, 2^127, |
| 185 | 2^(k+100) and 2^-100 by writing exponent fields, then selects the branch the C |
| 186 | takes. LOG splits exponent and mantissa as the C does (subnormals scaled by |
| 187 | 2^23 first) and calls the DIV core for z. |
| 188 | |
| 189 | Host evidence (not hardware): the host model of the emitted bodies against |
| 190 | `omega_math_exp` / `omega_math_log` over all 2^32 inputs, 0 mismatches each |
| 191 | (`build/test_omega_numeric_transc_gb10_cpu --host-all EXP` / `LOG`). |
| 192 | Full-domain output digests (tree of `tests/test_omega_transc.c`): |
| 193 | EXP 413c342928951fb078a3f6ecdc56221f26a2a6b19a1b7e099227bf38c1c2829c, |
| 194 | LOG 05e94f63d078b9d460bc94305389a874216c6cb50d2d462b8d4bd0943c86f51e. |
| 195 | `make test-numeric-transc-gb10-mutants` builds EXP with c2 one ulp up and LOG |
| 196 | with c1 one ulp up; each must fail a host-model check. nvdisasm 13.0.85 and |
| 197 | sm121dis decode all 88 + 312 words to the encoder's text |
| 198 | (`tools/divsqrt_nvdisasm_check.sh`). Chip run: `tools/run_numeric_transc_gate.sh` |
| 199 | (default op list includes EXP and LOG). Chip PASS on the GB10, 2026-10-27, |
| 200 | omega `cb6d201`, physics `048e5f5`: EXP and LOG each over all 2^32 inputs, |
| 201 | 0 mismatches, 0 unwritten, output digests equal to the host-model digests above |
| 202 | (receipt `evidence/E1-TRANSC-GB10/b2f4afe91148931db0f10f40edec9b8cce4533db99ec8e7d9733492794fa2b0e.json`, |
| 203 | chip log `blobs/ea7a32198c71b30b6682f53a556bf01d02d1a765e32c632e970f51330d6c92ef.log`). |