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

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