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 / dnn-activations / README.md

201 lines · 11221 bytes Raw Blame History Rendered
1# Seeded elementwise activations
2
3IMPLEMENTED seeded Omega admission and Blackwell IR for contiguous ReLU,
4erf-form GELU, tanh-form GELU and SiLU. GPU execution is NOT_RUN. This is not
5a replacement for the existing model-tuned activation kernels.
6
7## API
8
9`src/omega_gpu_dnn_activations_api.h` exports:
10
11```c
12typedef struct {
13 uint64_t elements;
14 uint32_t operation, dtype;
15} OmegaGpuDnnActivationsShape;
16int omega_gpu_dnn_activations_codegen(const OmegaGpuDnnActivationsShape *shape,
17 BlackwellIRProgram *program, uint8_t *code, size_t capacity,
18 OmegaBlackwellKernel *kernel);
19int omega_gpu_dnn_activations(const OmegaGpuDnnActivationsShape *shape,
20 const void *input, float *output);
21```
22
23Operation constants: `OMEGA_GPU_DNN_RELU=0`, `OMEGA_GPU_DNN_GELU_ERF=1`,
24`OMEGA_GPU_DNN_GELU_TANH=2`, `OMEGA_GPU_DNN_SILU=3`. Storage constants come
25from `omega_gpu_dnn_types.h`: f32=0, bf16=1, f16=2. Input is contiguous and
26has `elements` scalars. Output has `elements` f32 scalars. Accumulation and
27arithmetic use f32, including widening bf16/f16 inputs before evaluation.
28
29The finite-input precondition excludes NaN and infinity; values are not scanned
30on the host. Callers provide enough readable/writable storage. Input/output
31may overlap because the execution shell uploads input before downloading output.
32Nonempty counts through `UINT32_MAX` are admitted. No alignment or warp-multiple
33restriction applies to the element count. Maximum-count admission is exercised
34without allocating that tensor. Physical allocation failure remains a chip error.
35
36Return codes: 0 OK, 1 BAD_ARGS (null required argument), 2 REFUSED (zero count,
37count above `UINT32_MAX`, unknown operation or storage type), 3 CODEGEN (bridge,
38allocation, replay or encoding failure), 4 CHIP (session, buffer, transfer or
39launch failure). Shape/type refusal happens before session/device access; the
40host and mutant links wrap session open/lock/unlock/free and allocation. In
41`--sim`/`--quick`, every such call aborts without forwarding to the device.
42Refused execution shapes must cause zero attempts. A separately compiled
43direct-open mutant must abort under `--sim`, proving the linked guard. The
44separate explicit `--shell-contract` fake-backend mode checks pointer semantics:
45NULL open causes zero allocations; non-NULL open reaches one deliberately failed
46allocation. No fake-mode exception exists under `--sim`.
47
48`*_codegen` is host-only. The execution API opens the GPU and requires an
49operator-authorized exclusive window. Its C implementation is a memory/session
50shell only. `plan.om` owns count/type validation, byte sizes and grid geometry.
51`kernel.om` owns loads, addressing, tail exits, format widening and all arithmetic.
52It composes the read-only common `attn-any/emit.om` and uses the single generic
53`omega_gpu_om_ir_replay`. No host libm production kernel or external production
54math library is introduced. Host libm is verification-only.
55
56Each CTA has one warp. Each active lane processes one component at
57`block*32+lane`. Out-of-range lanes exit before loading or storing; the
58independent simulator checks exact input/output ranges and an output sentinel.
59Parameter words are input pointer (two u32 words), output pointer (two), count
60(one), starting at c0 byte offset 896.
61
62## Mathematical and approximation contract
63
64ReLU is `x < 0 ? 0 : x`. Signed zero is preserved for every operation, including
65ReLU at negative zero. Strictly negative ReLU values produce positive zero.
66
67Erf GELU is `x*(1+erf(x/sqrt(2)))/2`. The device evaluates the A&S 7.1.26
68complementary-error-function polynomial at `z=abs(x)/sqrt(2)`:
69
70```
71t = 1/(1 + 0.3275911*z)
72q = t*(0.254829592 + t*(-0.284496736 + t*(1.421413741
73 + t*(-1.453152027 + t*1.061405429)))) * exp(-z*z)
74y = x*(1-q/2) for nonnegative x; x*q/2 for negative x
75```
76
77Tanh GELU is `x*(1+tanh(sqrt(2/pi)*(x+0.044715*x^3)))/2`. It is evaluated
78using the equivalent sigmoid identity and the absolute value of its argument.
79SiLU is `x/(1+exp(-x))`. Both use `e=exp(-abs(argument))`, then the stable
80positive multiplier `1/(1+e)` or negative multiplier `e/(1+e)`. The negative
81multiplier is formed before multiplying by x. This prevents positive-exp
82overflow and negative-tail cancellation.
83
84Before square/cube evaluation, GELU absolute inputs are clamped to 10; their
85exp terms are forced to exactly zero when the original magnitude is at least
8610. SiLU uses magnitude 80 similarly. Hence saturation returns x on the
87positive side and negative zero on the negative side, including largest finite
88f32/bf16 values. No finite tail is multiplied by an overflowing cube or exp.
89MUFU.EX2 receives a nonpositive argument, scaled by log2(e); MUFU.RCP handles
90the positive denominators. The polynomial, f32 rounding, and MUFU approximation
91mean results are not bitwise libm results.
92
93The tested envelope is `abs(got-reference) <= 3e-6 + 3e-6*abs(reference)` for
94all formats after decoding storage. This is a deliberately conservative test
95envelope, not a proven universal error bound or chip guarantee. MODELED grid
96errors below use ideal real/double evaluation, not the device instruction path.
97MEASURED simulator results are reported separately in the acceptance receipt.
98
99### Wolfram query/result record (MODELED)
100
101All constants and modeled calculations were checked with the mounted Wolfram
102Language evaluator. Queries and results:
103
104* `Integrate[x^2,{x,0,1}] -> 1/3` and WolframAlpha `sqrt(27)/2 -> (3 sqrt(3))/2`
105 verified tool access.
106* `N[{Sqrt[2/Pi],1/Sqrt[2],Log[2,E]},16]` returned
107 `{0.7978845608028654,0.7071067811865475,1.4426950408889634}`.
108* `Round[10^9*{1/Sqrt[2],2*Sqrt[2/Pi],Log[2,E]}]` (the actual call spelled
109 these as three separate `Round` expressions) returned
110 `{707106781,1595769122,1442695041}`. The decimal literals used by the seeded
111 compiler are therefore `0.707106781`, `1.595769122`, `1.442695041`, each
112 rounded once to f32. The long exact decimal literal exceeded the pinned
113 compiler's signed-significand limit; no compiler pin was changed.
114* Defining `p=0.3275911; a={0.254829592,-0.284496736,1.421413741,-1.453152027,1.061405429};
115 q[z_]:=With[{t=1/(1+p z)},t (a[[1]]+t (a[[2]]+t (a[[3]]+t (a[[4]]+t a[[5]])))) Exp[-z^2]];`
116 then `Max[Table[Abs[q[z]-Erfc[z]],{z,0,10,0.0005}]]` returned
117 `1.3937450349388314e-7`.
118* With the same q, `Max[Table[Abs[(x/2) q[Abs[x]/Sqrt[2]]-(x/2) Erfc[Abs[x]/Sqrt[2]]],{x,-10,10,0.001}]]`
119 returned `2.1112399716622862e-7`. This is a sampled approximation error, not
120 an interval proof.
121* `FullSimplify[(1+Tanh[t])/2-1/(1+Exp[-2 t]),Assumptions->Element[t,Reals]] -> 0`.
122* `N[{80 Exp[-80],10 Erfc[10/Sqrt[2]]/2},12]` returned
123 `{1.4438811102763321e-33,7.6198530241605261e-23}`. These are the ideal
124 omitted SiLU and erf-GELU negative-tail magnitudes at the cutoffs.
125* `N[Exp[-2 Sqrt[2/Pi](10+0.044715*10^3)]*10,12] -> 1.2040923482098023e-37`
126 gives the ideal tanh-GELU omitted tail at its cutoff.
127* `N[0.000003/2.1112399716622862*^-7,12] -> 14.209658969453615` records the
128 absolute-envelope margin over the sampled ideal polynomial error. It is not
129 a floating-point or MUFU error proof.
130* `N[{1/2^23,2^-22.5},12] -> {1.1920928955078125e-7,1.6858739404357614e-7}`
131 is modeled f32 epsilon and the existing EX2-relative-bound constant quoted
132 in the IR header; it does not qualify this kernel on hardware.
133
134## Focused acceptance
135
136Use the compiler/bridge environment required by `om/units.sh`. Seed compiler:
137Omega source `e5b32567`, omc SHA256
138`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`.
139The checked C and declarations are generated only by that script.
140
141```sh
142export OMEGA_OMC=/home/drakestapleton/work/cudastack/omega-mv/seed/out/omc
143export OMEGA_BRIDGE=/home/drakestapleton/work/cudastack/omega-bridge
144bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh
145bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-gpu-dnn-activations test-gpu-dnn-activations-mutants
146```
147
148The host gate exercises every operator/type over counts
149`1,2,7,31,32,33,64,65,513,65535`. Small counts rotate the value corpus to cover
150both signs, both zeros, small values and saturation even at count one. Larger
151cases include largest finite f32/bf16 inputs. It compares the complete emitted
152path with independent double erf/erfc, tanh and exp references. Deliberately
153perturbed computed output must fail. Seven seeded source mutants must first compile with seeded
154omc and generate checked C, then fail behavior: ReLU selection, erf coefficient,
155tanh cubic coefficient, SiLU sign, block indexing, storage load and admission.
156The admission mutant is killed by an expected session-lock guard abort; an
157unrelated signal or compile failure never counts. A separate compiled C
158direct-open guard control must die with the session-open abort marker.
159Mutation evidence is retained under the printed ignored build directory.
160No full suite or GPU run is part of these targets. See `CHIP.md` for the
161operator-only hardware acceptance procedure.
162
163### Private host receipt (MEASURED; no chip qualification)
164
165First registration was committed separately as `8d491f2`. The implementation
166and reference-first work-in-progress checkpoint was pushed as `9c9f00b`.
167The final device-isolated focused command was:
168
169```sh
170bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 env \
171 OMEGA_OMC=/home/drakestapleton/work/cudastack/omega-mv/seed/out/omc \
172 OMEGA_BRIDGE=/home/drakestapleton/work/cudastack/omega-bridge \
173 make -j3 test-gpu-dnn-activations test-gpu-dnn-activations-mutants
174```
175
176Exit status: **0**. Local evidence: `build/dnn-activations-bwrap-final.log`;
177mutation artifacts: `build/dnn-activations-mutants.A5n2G3/`. The private `/dev`
178contains no GPU, CUSE or VFIO device nodes. Session-abort guards remain in
179addition to this device namespace isolation. These build artifacts are ignored,
180not historical committed chip receipts. Final lines:
181
182```
183dnn-activations host+warp-sim: PASS (4 operators, 3 types, tails, independent double references, refusal-before-open, wrong-result control)
184dnn-activations shell-contract: PASS (NULL open: 0 allocs; non-NULL open: 1 failed alloc; isolated fake backend)
185dnn-activations isolation control: PASS (compiled direct-open mutant aborts under --sim)
186dnn-activations source mutants: PASS (7 compiled, 7 behaviorally killed)
187```
188
189The deliberate C direct-open control aborts with the session-open marker.
190The widened seeded admission mutant aborts with the session-lock marker;
191the remaining six seeded mutants return the expected behavioral-failure status.
192The host test binary's five `__wrap_omega_gpu_session_*` symbols were also
193observed with `nm -g --defined-only` before the guarded acceptance run.
194The separately gated chip runner was built, not executed, in the prior focused
195build recorded in `build/dnn-activations-final.log` (exit 0).
196
197Generation by `om/units.sh`: PASS. Independent host references and warp
198simulation: PASS for the enumerated corpus and counts, not an exhaustive input
199proof. Seeded behavioral mutation gate: PASS. Hardware correctness/performance:
200**NOT_RUN**. Full host suite: **NOT_RUN**, integration-owner-only.
201No merge or deployment was performed.