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/CUDApp/blob/main/om/q38-head/README.md # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / om / q38-head / README.md` 168 lines · 9136 bytes Raw Blame History Rendered 1 # Conservative output-head screening 2 3 Experimental Omega-generated GPU primitive for Core issue 710 and Core PR 895. 4 This is one step toward an exact two-pass output head for the 27B model. 5 It is not connected to serving. No end-to-end speed or first-token improvement 6 is established by this primitive. 7 8 The compact head produces approximate scores. This kernel turns them into 9 conservative intervals. A later maximum reduction can discard a row only when 10 its upper bound is below the largest lower bound. The full-precision head must 11 still recompute every surviving row and choose the final token. 12 13 ## Contract 14 15 Trusted caller requirements: 16 17 - `1 <= count <= 248320`, 256 threads per block, grid `(count + 255) / 256`. 18 - Four separate arrays of at least `count` binary32 values: score, coefficient, 19 lower output, upper output. Inputs are finite; coefficients are nonnegative. 20 - `hn` is finite, positive, and at least the Euclidean norm of the exact hidden 21 vector used by both heads. An unrepresentable norm requires a full-head fallback. 22 - The coefficient was rounded upward and proves 23 `abs(full_score - compact_score) <= coefficient * hn` for the actual compact 24 and full GPU reductions. This kernel does not establish that upstream premise. 25 - Binary32 round-to-nearest-even arithmetic, with subnormals retained. 26 - The caller validates input values before launching. This primitive does not 27 admit untrusted buffers or detect invalid coefficients on the device. 28 29 Argument words start at constant-bank byte 896: score address, coefficient 30 address, lower address, upper address (four 64-bit addresses), `hn` (binary32), 31 then `count` (u32). No shared memory. The generated frame records register use; 32 the verification launch declares 64 registers, as the existing runtime requires. 33 34 For `e = 2^-20` and `tiny = 2^-100`, operations are separately rounded except 35 for the explicit fused multiply-add: 36 37 ``` 38 r = coefficient * hn 39 r = r * (1 + e) 40 r = fma(abs(score), e, r) 41 r = r + tiny 42 lower = score - r 43 upper = score + r 44 ``` 45 46 The relative margin is sixteen binary32 unit roundoffs. It covers rounding in 47 the two products, fused sum, addition and final endpoints. The score term 48 covers endpoint rounding when the radius is small. The positive normal `tiny` 49 covers absolute subnormal rounding errors. Overflow of the nonnegative radius 50 produces `[-infinity, +infinity]`, retaining the row. These intervals are wider 51 than the binary64 next-up reference in Core PR 895. Equal endpoints are retained. 52 53 For a finite intermediate result, let `u=2^-24`, `eta=2^-150`, `R=c*hn` 54 and `S=abs(score)`. The standard RN error bound gives 55 `r >= A*R + B*S + (1-u)*tiny - D*eta`, with 56 `A=(1-u)^4*(1+e)`, `B=e*(1-u)^2`, and 57 `D=(1+e)*(1-u)^3+(1-u)^2+(1-u)+1`. 58 All three exact inequalities hold: `A*(1-u)>1`, `B*(1-u)>u`, and 59 `((1-u)*tiny-D*eta)*(1-u)>eta`. Thus `r*(1-u)>R+u*S+eta`, 60 which covers the final endpoint error `u*(S+r)+eta`. Nonnegative intermediate 61 overflow takes the infinite-interval case above. This argument depends on 62 the stated RN/subnormal contract, not approximate reciprocal instructions. 63 64 Numerical reference: NVIDIA PTX ISA 9.4, physical page 108, section 6.5.2 65 (round-to-nearest-even). Machine instructions are emitted by the existing 66 checked Omega encoder, not copied from a vendor binary or listing. 67 68 ## Verification 69 70 Build the existing runtime with `make -j1 build/libomega_gpu.a`. Set 71 `OMEGA_OMC` to the compiler pinned in the repository AGENTS.md and set 72 `Q38_GPU_OUT` to an external artifact directory. From the repository root: 73 74 ``` 75 sh om/q38-head/run.sh 76 ``` 77 78 `make test-q38-head-bounds` runs the same host check and is included in 79 `make test` when the pinned compiler can run on the host. On other hosts the 80 explicit target reports NOT_RUN and exits 2. Neither command opens the GPU. 81 82 The external C instrument runs the generated IR in the existing warp simulator 83 against a long-double reference. Cases include tails, zero coefficients, 84 subnormals, cancellation, extreme exponents, overflow and both fragment orders. 85 It then damages a fused arithmetic instruction and requires a numerical failure. 86 The initial generator stub refused with exit 66 before implementation. 87 88 With an authorized, idle chip window, `run.sh --chip` loads the exact machine 89 code from the Omega frame through the existing runtime and repeats the numerical 90 battery. The optional two directory arguments after `--chip` add eight captured 91 27B-state replays: compact-score/coefficient files, then hidden/full-score files. 92 Those current replay scores came from the external host compact-head reference; 93 they do not yet qualify a complete GPU compact-head/recheck pipeline. 94 95 The shell and C files are external verification instruments only. They are not 96 first-party runtime implementations or new production dependencies. 97 98 ## Runtime regression found during qualification 99 100 The unmodified runtime refused this Spark before launching: the driver returned 101 raw RM SM version `10.04`, while class admission compared it only with `12.01`. 102 The existing diagnostic chip table already identifies PCI vendor/device 103 `10de:2e12` as GB10 with execution target SM121. The repaired Omega policy accepts 104 the observed raw version only for that exact PCI identity and the complete 105 Blackwell class set. Other devices, vendor IDs, raw versions and missing classes 106 remain refused. `nvrm.c` forwards identity fields from its existing CARD_INFO 107 result; it adds no driver query and changes no qualified-chip table. 108 109 The new regression assertion fails before the Omega policy fix and passes after 110 regenerating its binding with the pinned Bridge. Physical qualification uses the 111 patched runtime itself, including its normal class admission. No bypass or 112 environment override selects the target. 113 114 ## Isolated two-pass head experiment 115 116 `pipeline.patch` derives an external verification instrument from the existing 117 `tests/gpu_exact_head_test.c`. It uses width 5120, this Omega-generated bound 118 kernel, and conservatively computes the hidden norm on the host. The existing 119 GPU kernels perform compact screening, threshold reduction, masked full-precision 120 recheck and final selection. Apply it outside the source tree: 121 122 ``` 123 patch -o /tmp/pipeline.c tests/gpu_exact_head_test.c om/q38-head/pipeline.patch 124 ``` 125 126 `pipeline-validation.json` records the source fingerprints and results. All eight 127 saved states reproduce the original full GPU logits bit for bit; every compact 128 interval contains the full score, every rechecked score matches, and every final 129 token matches. Zeroing the coefficients loses the true winner at position 97, 130 reproducing the earlier compact-head error. The recorded timing is provisional: 131 host suites were active in the shared correctness window. It is neither an 132 accepted speed result nor a whole-model/first-token measurement. Serving 133 integration and its complete exact-token gate remain untested. 134 135 ## Fixed envelope and experimental graph integration 136 137 `envelope.om` calculates an upward-rounded binary32 bound from the folded final 138 RMSNorm weights: `72 * max(abs(weight)) * 1025/1024`. It uses integer arithmetic 139 on the weight encodings, refuses nonfinite weights and overflow, and conservatively 140 returns 1 for an all-subnormal or zero weight vector. `envelope-check.py` checks 141 all exponent ranges against exact rational arithmetic; five compiled source 142 mutants exercise tail scanning, upward rounding, nonfinite refusal, sign masking and slack. 143 144 The ideal normalized vector has norm at most `sqrt(5120) * max(abs(weight))`. 145 The fixed envelope adds room for the existing GPU normalization's rounding. 146 Its scope is finite input, folded finite weights, epsilon `1e-6f`, width 5120, 147 and output scale 1. The graph adapter refuses a different epsilon. The actual 148 normalizer is in `omega_blackwell_codegen_dec.c`: 20 products per lane, five 149 warp sums, seven CTA sums, the mean plus epsilon, reciprocal square root and 150 two output products. NVIDIA PTX ISA 9.4, physical page 211 (printed 199), gives 151 the reciprocal-square-root relative error as at most `2^-22.9`; this is a 152 numerical reference, not independent proof of every native instruction. 153 `norm-check.c` tests the actual emitted normalizer on the chip, including 154 underflow and overflow magnitudes, dense and sparse input, and adversarial 155 weights. The replay and stress receipts do not prove all possible model states. 156 157 `plan.om` owns the scratch layout and six operations: scale, compact screen, 158 intervals, two threshold reductions, and full-precision masked recheck. 159 `emit.om` produces the checked native bounds kernel. Both are compiled through 160 the pinned Omega Bridge. The C graph adapter only supplies resources and 161 dispatches those operations. The feature is opt-in through 162 `omega_gpu_q38_graph_set_exact_head`; the original head remains available. 163 Disable the feature for sampling, which requires all logits. Full serving 164 qualification is pending; the default path is unchanged. 165 166 The Omega plan also supplies an additional 2 GiB admission reserve for the 167 resident screen, coefficients and scratch. The Core opt-in adds that reserve 168 before loading. It is a conservative budget, not a measured allocation size.