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 / tests / runtime / HOST_POLICY.md

378 lines · 21767 bytes Raw Blame History Rendered
1# Runtime host policy migration
2
3## Scope and status
4
5IMPLEMENTED, host-only; not merged, deployed or chip-qualified. This is a pending
6migration, not completion of the original all-host-logic assignment.
7
8The generated defaults come from these first-party Omega units:
9
10- `artifact_policy.om`: QMD template/launch admission, including the original
11 uint32 shared-memory rounding wraparound. Byte views do not require aligned QMDs.
12- `artifact_parse.om`: printable fields, lowercase SHA text, decimal/list and
13 semantic-version parsing, and hexadecimal byte formatting.
14- `api_policy.om`: shared matmul, RMSNorm, RoPE, attention-head, cache-range,
15 bf16-weight and router-expert shape predicates. Allocation, device transport,
16 pointer admission and error strings remain in the existing C adapters.
17- `cm_features.om`, `cm_stats.om`, `cm_fit.om`, `cm_quantile.om`,
18 `cm_prediction.om`, `cm_decision.om`, `cm_calibration.om`: cost-model basis,
19 cells/defaults, statistics, Cholesky/prediction, quantiles, ranking/exploration,
20 calibration and ledger arithmetic. Floating values cross the ABI as binary64
21 bits, not as silently narrowed integers.
22- `cm_sort.om`: 256-element sorted runs and bounded two-window merges. C retains
23 allocation, copying and pointer advancement; ordering runs in Omega. The C
24 comparator is total: numerical order, then unsigned bits for ties, NaNs last.
25 This removes qsort's unspecified ordering of equal values, signed zeros and
26 distinct NaNs. Tests compare the complete byte order against glibc qsort using
27 that same total comparator, including ties and run-boundary sizes.
28- `cm_math.om`, `cm_math_extra.om`, `cm_math_erfc.om`: first-party binary64
29 log/log2/ceil/exp/exp2/sqrt/erfc/fabs. Integer bit manipulation, fma-free
30 double-double arithmetic and an integer restoring square root are used. No
31 production libm call substitutes for these implementations.
32- `cm_blob.om`, `cm_digest.om`: blob header construction/validation, scale and
33 length admission, SHA-256 and digest comparison. SHA-256 reuses the existing
34 `om/cache/digest.om` rounds, constants and padding. C streams bounded blocks;
35 the existing native blob layout, including ignored reserved bits, is retained.
36 Little- and big-endian header packing are compared against a C reference.
37
38Retained C oracles are selected by `CUDAPP_MIGRATION_PENDING_C_ARTIFACT`,
39`CUDAPP_MIGRATION_PENDING_C_API_POLICY`, and `CUDAPP_MIGRATION_PENDING_C_CM_`
40with suffix `SORT`, `MATH`, `FIT`, `STATS`, `FEATURES`, `QUANTILE`, `PREDICTION`,
41`DECISION`, `CALIBRATION`, `BLOB`, or `DIGEST`. Every switch defaults to zero.
42No exported signature or ABI manifest entry changed. Generate with
43`sh om/units.sh` using the existing pinned compiler and bridge; explicit
44`OMEGA_UNITS` overrides are honored.
45
46### Binary64 contract — semantic change for review
47
48The canonical successor uses non-contracting IEEE binary64, round-to-nearest,
49with each arithmetic operation rounded separately. Legacy C translation-unit
50builds, including the PENDING oracle and mutation copies, use
51`-ffp-contract=off`; this is a per-object rule, not a global compiler-flag change.
52The algorithm differential binds C's math calls to the canonical Omega routines.
53Its exact-equality exemption list is empty: every captured floating bit pattern,
54including signed zero, is compared without a tolerance. Independent glibc
55comparisons remain in the math sweep and in the C oracle's actual-input report.
56
57This changes legacy AArch64 `-O2` results that previously benefited from implicit
58FMA contraction. The historical measured maximum below describes one exercised
59corpus, not a bound on all inputs. No software FMA or approximate threshold
60comparison is introduced. A contraction-on oracle must be rejected by the same
61floating gate, after which its captured state is replayed with an EI threshold
62at the computed boundary using the canonical, contraction-off oracle.
63The pinned Bridge emits volatile binary64 intermediates in `o_fp`, preserving
64these operation boundaries even when its generated C is optimized.
65
66## Exercised evidence
67
68`make test-host-policy` covers shape Cartesian boundaries and deterministic
69random triples, QMD bit perturbations and launch inputs, decimal/list/text
70parsing, total-order sorting, binary64 functions, blob headers and SHA-256.
71Source mutants of API envelopes, QMD relocation words, decimal digit limits and
72sort order must compile and then fail the differential executable.
73
74Before the final integration run, `make -j3 test-costmodel test-dagsim` passed:
75`checks 127 failures 0`, `dagsim_unit: 203 checks, 0 failed`, pinned CLI fixtures,
76unsupported/refused prediction mutants, inverted-lifetime mutant and the retained
77C operation-clamp mutant. This exercises the default Omega model arithmetic,
78prediction, calibration and ranking on the existing tests. The additional
79direct differential below checks same-state decisions rather than assuming
80parity from those standalone passes.
81
82`cm_blob_unit` passed after blob/digest cutover. It compares initialization,
83serialization bytes, digest bytes and deserialization against the retained C
84oracle, checks digest tampering, all header-bit perturbations, both header byte
85orders, SHA block/padding boundaries, lengths 0 through 255 and larger inputs.
86
87`test-cm-decision-differential` links the unchanged direct model unit through
88decision/prediction interceptors and the retained C implementation. It compares
89actions, selected arms, measurement pairs, reasons, refusal/known/borrowed flags
90and sample counts exactly, and requires zero ULP for every floating output.
91Additional deterministic inputs cover unsupported operations, saturated
92core/pressure classes, empty/partial eligibility, budgets and fallback indices.
93Poisoned-output invalid-argument probes check the cleared prediction contract.
94Assertion-disabled verifier builds are refused, not reported as passing.
95
96Before the canonical contract was fixed, the exercised corpus reported 21,058
97decisions and 8,617 predictions with ordinary policy thresholds agreeing, but
98different floating values under the legacy contraction-on compiler behavior.
99An explicit EI-threshold edge then reproduced a discrete disagreement:
100Omega EI `0x1.8e1b4f17b2c3cp+4`, legacy C `0x1.8e1b4f17b2c2cp+4`.
101The largest historical floating distance was 5,611,147 ULP in `mean_log2_ps`:
102candidate `0x1.c1fea4ee44ep-6`, C `0x1.c1fea4e8eaf75p-6`.
103These are measured differences, not acceptable tolerances. The harness records
104the exact model/features/policy in ignored `build/cm_decision_max.case`; its
105contraction-on negative control regenerates that native-ABI replay fixture.
106The fixture is created with mode `0600`. Replay receives the already-open input
107on descriptor 3 (`CM_DIFF_REPLAY_FD=3`); the verifier never opens an
108environment-supplied path.
109
110WolframLanguageEvaluator:
111`a=FromDigits["1c1fea4ee44e",16]2^(-6-4 StringLength["c1fea4ee44e"]);`
112`b=FromDigits["1c1fea4e8eaf75",16]2^(-6-4 StringLength["c1fea4e8eaf75"]);`
113`N[{a,b,a-b,Abs[(a-b)/b]},30]`
114returned absolute difference `1.9467576856113666 * 10^-11` and relative
115difference `7.0880118476913915 * 10^-10`. These describe that measured case;
116they are not a global model-error bound. Replaying the original captured case
117with **only** `cm_oracle.c` rebuilt using `-ffp-contract=off` reported zero ULP
118difference across the complete decision output, isolating contraction in that
119case. The permanent exact gate uses the canonical contract and first-party math,
120not the legacy contracting/glibc combination. Predictions and decisions compare
121the same input state; the additional mutation gate below checks the independently
122computed state transitions rather than assuming training parity.
123
124The canonical gate passed: `checks 127 failures 0`,
125`decisions=21058 predictions=8617 max_numeric_ulp=0`. Its contraction-on
126negative control was rejected at `p_runner_up_better`: Omega
127`0x1.599f4787b55bep-2`, C `0x1.599f4787b52bap-2`, a measured 772 ULP.
128Replaying that state at the EI threshold passed with both EIs exactly
129`0x1.e347c758fe6aap+4` and every captured output at zero ULP.
130
131The mutation interceptors compare independent C and Omega initialization and
132post-call model bytes for every intercepted init/observe/calibrate/charge call
133in the unchanged direct unit and deterministic corpus. Calibration return bits
134and observation status codes must also match exactly. The exercised run passed
13521 initializations, 4,083 observations, 3 calibrations and 4 charges. Each C
136transition starts from a copy of the pre-call state, not from Omega's updated
137state. Equal initialization plus equal transitions establishes state identity
138over these exercised API sequences; it is not an all-input proof.
139
140The C oracle also compared glibc on its actual model math inputs:
141
142| Function | Calls | Maximum glibc distance (ULP) | Worst input bits | Omega bits | glibc bits |
143| --- | ---: | ---: | --- | --- | --- |
144| log2 | 332606 | 1 | 3ff0fbf55f8bbeaf | 3fb60c1ef82f0909 | 3fb60c1ef82f0908 |
145| ceil | 1 | 0 | — | — | — |
146| exp | 14025 | 1 | bfa53cdaf881f386 | 3feeb325c9a99db2 | 3feeb325c9a99db3 |
147| exp2 | 20931 | 1 | 4042815aaf6527ba | 42401e25fcdb3a52 | 42401e25fcdb3a51 |
148| sqrt | 411586 | 0 | — | — | — |
149| erfc | 28050 | 2 | 3fea66d1c80fe481 | 3fcf242eccf286be | 3fcf242eccf286c0 |
150| fabs | 300 | 0 | — | — | — |
151
152These differences are not algorithm-gate exemptions: that gate uses the
153canonical Omega math on both sides. The following separate high-precision
154WolframLanguageEvaluator query selected the Omega bit pattern in all four
155nonzero-distance rows (not a universal rounding proof):
156
157```wl
158fromBits[h_]:=Module[{u=FromDigits[h,16],e,t},
159 e=BitAnd[BitShiftRight[u,52],2047];t=BitAnd[u,2^52-1];
160 (-1)^BitGet[u,63] If[e==0,t 2^-1074,(2^52+t)2^(e-1023-52)]];
161roundedBits[v_]:=Module[{k=Floor[Log[2,v]],s},
162 s=Round[v 2^(52-k)];If[s==2^53,s=s/2;k++];
163 IntegerString[(k+1023)2^52+s-2^52,16,16]];
164rows={{"log2","3ff0fbf55f8bbeaf","3fb60c1ef82f0909","3fb60c1ef82f0908",Log[2,#]&},
165 {"exp","bfa53cdaf881f386","3feeb325c9a99db2","3feeb325c9a99db3",Exp},
166 {"exp2","4042815aaf6527ba","42401e25fcdb3a52","42401e25fcdb3a51",2^#&},
167 {"erfc","3fea66d1c80fe481","3fcf242eccf286be","3fcf242eccf286c0",Erfc}};
168Table[With[{v=N[r[[5]][fromBits[r[[2]]]],200]},
169 {r[[1]],r[[2]],roundedBits[v],N[v,40],r[[3]],r[[4]]}],{r,rows}]
170```
171
172The rounded reference bit patterns returned were respectively
173`3fb60c1ef82f0909`, `3feeb325c9a99db2`, `42401e25fcdb3a52`,
174and `3fcf242eccf286be`.
175
176`test-cm-source-mutants` passed ten attributed source controls: unsupported-op
177aliasing, doubled sample counts, incorrect variance division, reversed quantile,
178incorrect spread scaling, changed measurement action, inverted calibration
179clamp, changed blob magic, lost digest bits and the wrong logarithm base.
180Every mutant compiled and failed a named numerical/decision/blob assertion.
181The decision interceptor independently caught the action mutant, and its
182assertion-disabled build was refused.
183
184The binary64 sweep uses 65,536 deterministic random bit patterns per tested
185function, signed special values, subnormal/binary-exponent boundaries and
186neighboring values; exp/exp2/erfc also have targeted dyadic grids. Measured maximum
187ULP distance from this host's glibc was respectively `0,0,0,1,0,0,2,0` for
188`log,log2,ceil,exp,exp2,sqrt,erfc,fabs`. `fabs` additionally requires exact
189sign-bit clearing, including NaN payloads. This finite sweep is not a proof of
190correct rounding for all binary64 inputs. Floating exception flags and errno
191compatibility are not claimed.
192
193Wolfram's high-precision checks disagree with glibc at the measured worst exp and
194erfc samples and select the Omega result in both cases:
195
196- `Exp[2^-26]` at 150 digits begins
197 `1.000000014901161304869959263969`; rounded bits `3ff0000004000001`.
198 glibc returned `3ff0000004000000`.
199- For bits `402570dc08794a6a`, `Erfc[x]` at 150 digits begins
200 `6.41098283195702340057758 * 10^-52`; rounded bits `354eb3d792b02a8a`.
201 glibc returned `354eb3d792b02a8c`.
202
203The final `make test` result is recorded in the draft PR, not inferred from the
204focused runs above. Chip remains NOT_RUN.
205
206## Wolfram derivations
207
208The mounted WolframLanguageEvaluator supplied constants and reference values.
209For positive/negative normal values, the bit conversion query used:
210
211```wolfram
212bits[v_] := Module[{e=Floor[Log[2,Abs[v]]],sig},
213 sig=Round[N[Abs[v] 2^(52-e),150]];
214 If[v<0,2^63,0]+(e+1023)2^52+sig-2^52]
215```
216
217`{bits[Log[2]],bits[1/Log[2]],bits[1/Sqrt[Pi]]}` returned
218`{4604418534313441775,4609176140021203710,4603256987541740397}`.
219Splitting each high-precision value at its rounded binary64 high part supplied
220low parts with bits `{4358002977218854975,4357082904033627428,4350950281585880448}`.
221`bits[Sqrt[2]]` returned `4609047870845172685`.
222
223The Acklam coefficients are the exact decimal rationals of the retained C
224`a,b,c,d` arrays, not newly fitted approximations. Applying `Map[bits,{a,b,c,d},{2}]`
225to those rationals returned:
226
227```text
228a: 13854155686354486565 4641977866302784411 13866933838737128345
229 4639072047187312667 13852696627858410445 4612826843888178297
230b: 13856235683484533956 4639889312772538999 13863054224260258002
231 4634401141363829182 13847038013971134502
232c: 13798997430714945504 13822851435045880248 13835960482696009560
233 13836295942911834650 4616611452376731079 4613798575908835234
234d: 4575625165243457492 4599480671287182180 4612688371394471446
235 4615636595525398809
236```
237
238`2^16` returned `65536`, the deterministic random-sweep size. With
239`t=(Sqrt[2]-1)/(Sqrt[2]+1)`,
240`N[2 t^67/(67 (1-t^2)),30]` returned approximately
241`1.5703257028259 * 10^-53` for the log series truncation bound.
242`N[Erfc[6],30]` returned approximately `2.1519736712498913 * 10^-17`, below
243`2^-53`, used only for rounding the reflected negative erfc tail to 2.
244These are analytic bounds, not measured accuracy claims.
245
246QMD: `{BitShiftRight[16^^300,6],16^^7ffff,16^^ffff,16^^1ff,16^^7ff}`
247returned `{12,524287,65535,511,2047}`; `2^32-1` returned `4294967295`.
248Blob packing queries and results are also quoted directly in `cm_blob.om`.
249
250## Remaining acceptance work
251
252Artifact manifest/admission/JSON and remaining owned API plans are being
253completed on disjoint stacked branches before integration. The direct model
254input corpus and dedicated arithmetic/ranking source mutants are exercised
255above. A universal correct-rounding or arbitrary-threshold identity proof is
256not claimed by the finite sweeps. Do not describe this draft as hardware
257qualified or as a completed CUDA-stack replacement. No ROADMAP status has been
258upgraded.
259
260## Chip runbook — NOT_RUN
261
262Do not execute these commands outside a newly authorized exclusive Drake window.
263The current authorization/runbook must establish service shutdown, GPU ownership,
264watchdog and lock handling first; an apparently free lock is not authorization.
265This lane has opened no GPU device and has not touched any live service.
266
267After authorization, from the exact reviewed checkout, build the existing test
268binaries through the host-only targets, then run the actual chip batteries:
269
270```sh
271mkdir -p build/runtime-host-chip
272taskset -c 10-14 nice -n 10 build/gpu_matmul_api_test --out build/runtime-host-chip/matmul.json
273taskset -c 10-14 nice -n 10 build/gpu_elementwise_test --out build/runtime-host-chip/elementwise.json
274taskset -c 10-14 nice -n 10 build/gpu_attention_test --out build/runtime-host-chip/attention.json
275taskset -c 10-14 nice -n 10 build/gpu_router_test --out build/runtime-host-chip/router.json
276taskset -c 10-14 nice -n 10 build/gpu_bf16_gemv_test --out build/runtime-host-chip/bf16.json
277taskset -c 10-14 nice -n 10 build/gpu_decode_attn_test --out build/runtime-host-chip/decode.json
278```
279
280Require each battery's green parity checks and deliberately wrong kernel checks,
281record exact SHA/toolchain and exit statuses, and compare with C-oracle builds
282using the same shapes. Host references and simulators are not chip qualification.
283Pure cost-model/blob tests themselves require no GPU window.
284
285## Artifact format and admission
286
287The artifact public API is unchanged. The admitted input remains the canonical
288`.manifest`, not JSON. The `.json` file is an output-only mirror; no JSON admission
289endpoint or parser has been invented. Adversarial JSON-looking bytes are tested
290as malformed manifest input. Python's independent JSON parser checks emitted
291mirrors, rejects duplicate keys and invalid escapes, and distinguishes legacy
292raw invalid UTF-8 from valid JSON rather than changing its encoding contract.
293
294`artifact_format.om` owns ordered manifest layout, identity/export record
295construction, JSON quoting and key order, numeric spelling, and checksum-list
296emission. `artifact_admit.om` owns hash syntax and equality, field limits, launch,
297contract, constant-bank and driver refusals and the admission sequence.
298`artifact_elf.om` owns ELF section selection, bounds and exact text matching.
299The default C shell owns pointers, retained allocations, file reads/writes and
300SHA-256 calls. `CUDAPP_MIGRATION_PENDING_C_ARTIFACT=1` selects the original C
301oracle. No public declaration or runtime API manifest entry changes.
302
303The format wire has a 65,536-byte buffer (input below 20,000, QMD snapshots at
30424,576 and 24,832, driver at 25,088, digest text at 26,000, output at 32,768)
305and 128 scalar slots. Field offsets/lengths are at `8+k`/`48+k`; slots 88–98
306hold export numeric values; slots 100–105 hold retained-file sizes. Admission
307stages request an identity digest, five file digests, then ELF/text comparison.
308The ELF pull protocol uses 512 bytes and 32 scalar slots; return 2 requests a
309bounded byte copy, 1 accepts, and 0 refuses. Policy is never inferred from a
310host-side pointer or a re-opened file. Existing read-once snapshot tests remain
311the acceptance path.
312
313Regenerate with the existing pinned `om/units.sh` tools. The ELF magic literal
314comes from `WolframLanguageEvaluator:
315FromDigits[Reverse[{127,69,76,70}],256] -> 1179403647`; this is a byte encoding,
316not measured hardware evidence.
317
318Focused host checks (no full suite or GPU):
319
320```sh
321taskset -c 10-14 nice -n 10 make -j3 test-artifact-format
322taskset -c 10-14 nice -n 10 make -j3 test-artifact-format-pending
323taskset -c 10-14 nice -n 10 env OMEGA_OMC=/path/to/pinned/omc \
324 OMEGA_BRIDGE=/path/to/omega-bridge make -j3 test-artifact-format-mutants
325```
326
327The fixed-seed corpus is `0xA17FAC7`: 6,000 admission cases plus export/escape
328cases, comparing exact refusal codes, artifact identities and all eight export
329files. It includes duplicate/reordered records, malformed JSON-looking bytes,
330oversize fields, invalid hashes, strict driver strings, and escape cases.
331The differential's flipped expected byte must fail; source mutants must compile
332and then be rejected, never count a compiler failure as a kill.
333
334### ArtifactOm host receipt
335
336IMPLEMENTED and EXERCISED on `feat/omega-artifact-format`, stacked on
337RuntimeHost `16da758961c165dac9aef585137172175651c372` (#291). This receipt
338supersedes the artifact-only host work listed under Remaining acceptance work;
339it does not upgrade the cost-model, full-stack, or hardware claims.
340
341The checked generator used omega-mv
342`e5b32567a7aff3ce594e3254a622a846a6cd190b` and omc SHA-256
343`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
344`om/units.sh` completed with rc 0. The focused commands above ran serially,
345under cores 10–14 and nice 10, with these observed results:
346
347| Tier | rc | Observed verdict |
348| --- | --- | --- |
349| Default existing manifest fixtures | 0 | `native_artifact_manifest: 70 checks, 0 failed` |
350| Default existing export fixtures | 0 | `test_gpu_artifact_export: 47 checks, 0 failed` |
351| Existing CLI shape fixtures | 0 | `ARTIFACT EXPORT SHAPES PASS` |
352| C/Omega differential of all three existing fixture sets | 0 | Same three verdicts; exact return codes, retained bytes, IDs and export files |
353| Fixed-seed generated corpus | 0 | `ARTIFACT-FORMAT PASS export=256 admission=6000 seed=0xa17fac7 byte-exact strict-json` |
354| Independent JSON codec/parser | 0 | `ARTIFACT-FORMAT codec PASS byte-domain=256 valid-utf8 strict-escapes duplicate-keys invalid-utf8-classified` |
355| Flipped expected manifest byte | 0 | `ARTIFACT-FORMAT negative-control PASS expected-byte-flip rc=1` |
356| PENDING C existing fixtures | 0 | 70 manifest checks and 47 export checks, zero failed; CLI shapes PASS |
357| Compiled Omega source mutants | 0 | `ARTIFACT-FORMAT mutants PASS killed=5 compiled=5` |
358
359The five compiled mutants remove backslash escaping, invert identity-digest
360acceptance, change the ELF machine constant, reject equality at the current-driver
361admission boundary, and swap the cubin/text hashes in the checksum list.
362Each is rejected by a runtime differential assertion, not a compile failure.
363The expanded focused mutant command above completed rc 0. The driver-boundary
364mutant is caught at admission case 48 (Omega rc 8 versus C rc 0); the checksum
365ordering mutant is caught at export case 0's `.sha256` byte comparison.
366Logs remain in `build/artifact-format/mutant-artifact_{format,admit,elf}.log`,
367`build/artifact-format/mutant-artifact_admit-driver-boundary.log`,
368`build/artifact-format/mutant-artifact_format-checksum-order.log`, and
369`build/artifact-format/negative-control.log`.
370
371The differential target clears only its generated export/shape fixture
372directories before each run, preserving EXCL refusal behavior while making the
373host gate repeatable. The direct existing test recipes also track the new C
374shell include, so changing it cannot silently reuse an old test binary.
375
376PASS applies to the focused host tiers only. Full `make test` and chip/device
377qualification are NOT_RUN. No service, GPU device, driver, gate, or compiler pin
378was changed. This work is not MERGED or DEPLOYED.