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
CUDApp / om / dnn-activations / README.md
| 1 | # Seeded elementwise activations |
| 2 | |
| 3 | IMPLEMENTED seeded Omega admission and Blackwell IR for contiguous ReLU, |
| 4 | erf-form GELU, tanh-form GELU and SiLU. GPU execution is NOT_RUN. This is not |
| 5 | a replacement for the existing model-tuned activation kernels. |
| 6 | |
| 7 | ## API |
| 8 | |
| 9 | `src/omega_gpu_dnn_activations_api.h` exports: |
| 10 | |
| 11 | ```c |
| 12 | typedef struct { |
| 13 | uint64_t elements; |
| 14 | uint32_t operation, dtype; |
| 15 | } OmegaGpuDnnActivationsShape; |
| 16 | int omega_gpu_dnn_activations_codegen(const OmegaGpuDnnActivationsShape *shape, |
| 17 | BlackwellIRProgram *program, uint8_t *code, size_t capacity, |
| 18 | OmegaBlackwellKernel *kernel); |
| 19 | int omega_gpu_dnn_activations(const OmegaGpuDnnActivationsShape *shape, |
| 20 | const void *input, float *output); |
| 21 | ``` |
| 22 | |
| 23 | Operation 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 |
| 25 | from `omega_gpu_dnn_types.h`: f32=0, bf16=1, f16=2. Input is contiguous and |
| 26 | has `elements` scalars. Output has `elements` f32 scalars. Accumulation and |
| 27 | arithmetic use f32, including widening bf16/f16 inputs before evaluation. |
| 28 | |
| 29 | The finite-input precondition excludes NaN and infinity; values are not scanned |
| 30 | on the host. Callers provide enough readable/writable storage. Input/output |
| 31 | may overlap because the execution shell uploads input before downloading output. |
| 32 | Nonempty counts through `UINT32_MAX` are admitted. No alignment or warp-multiple |
| 33 | restriction applies to the element count. Maximum-count admission is exercised |
| 34 | without allocating that tensor. Physical allocation failure remains a chip error. |
| 35 | |
| 36 | Return codes: 0 OK, 1 BAD_ARGS (null required argument), 2 REFUSED (zero count, |
| 37 | count above `UINT32_MAX`, unknown operation or storage type), 3 CODEGEN (bridge, |
| 38 | allocation, replay or encoding failure), 4 CHIP (session, buffer, transfer or |
| 39 | launch failure). Shape/type refusal happens before session/device access; the |
| 40 | host and mutant links wrap session open/lock/unlock/free and allocation. In |
| 41 | `--sim`/`--quick`, every such call aborts without forwarding to the device. |
| 42 | Refused execution shapes must cause zero attempts. A separately compiled |
| 43 | direct-open mutant must abort under `--sim`, proving the linked guard. The |
| 44 | separate explicit `--shell-contract` fake-backend mode checks pointer semantics: |
| 45 | NULL open causes zero allocations; non-NULL open reaches one deliberately failed |
| 46 | allocation. No fake-mode exception exists under `--sim`. |
| 47 | |
| 48 | `*_codegen` is host-only. The execution API opens the GPU and requires an |
| 49 | operator-authorized exclusive window. Its C implementation is a memory/session |
| 50 | shell 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. |
| 52 | It 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 |
| 54 | math library is introduced. Host libm is verification-only. |
| 55 | |
| 56 | Each 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 |
| 58 | independent simulator checks exact input/output ranges and an output sentinel. |
| 59 | Parameter 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 | |
| 64 | ReLU is `x < 0 ? 0 : x`. Signed zero is preserved for every operation, including |
| 65 | ReLU at negative zero. Strictly negative ReLU values produce positive zero. |
| 66 | |
| 67 | Erf GELU is `x*(1+erf(x/sqrt(2)))/2`. The device evaluates the A&S 7.1.26 |
| 68 | complementary-error-function polynomial at `z=abs(x)/sqrt(2)`: |
| 69 | |
| 70 | ``` |
| 71 | t = 1/(1 + 0.3275911*z) |
| 72 | q = t*(0.254829592 + t*(-0.284496736 + t*(1.421413741 |
| 73 | + t*(-1.453152027 + t*1.061405429)))) * exp(-z*z) |
| 74 | y = x*(1-q/2) for nonnegative x; x*q/2 for negative x |
| 75 | ``` |
| 76 | |
| 77 | Tanh GELU is `x*(1+tanh(sqrt(2/pi)*(x+0.044715*x^3)))/2`. It is evaluated |
| 78 | using the equivalent sigmoid identity and the absolute value of its argument. |
| 79 | SiLU is `x/(1+exp(-x))`. Both use `e=exp(-abs(argument))`, then the stable |
| 80 | positive multiplier `1/(1+e)` or negative multiplier `e/(1+e)`. The negative |
| 81 | multiplier is formed before multiplying by x. This prevents positive-exp |
| 82 | overflow and negative-tail cancellation. |
| 83 | |
| 84 | Before square/cube evaluation, GELU absolute inputs are clamped to 10; their |
| 85 | exp terms are forced to exactly zero when the original magnitude is at least |
| 86 | 10. SiLU uses magnitude 80 similarly. Hence saturation returns x on the |
| 87 | positive side and negative zero on the negative side, including largest finite |
| 88 | f32/bf16 values. No finite tail is multiplied by an overflowing cube or exp. |
| 89 | MUFU.EX2 receives a nonpositive argument, scaled by log2(e); MUFU.RCP handles |
| 90 | the positive denominators. The polynomial, f32 rounding, and MUFU approximation |
| 91 | mean results are not bitwise libm results. |
| 92 | |
| 93 | The tested envelope is `abs(got-reference) <= 3e-6 + 3e-6*abs(reference)` for |
| 94 | all formats after decoding storage. This is a deliberately conservative test |
| 95 | envelope, not a proven universal error bound or chip guarantee. MODELED grid |
| 96 | errors below use ideal real/double evaluation, not the device instruction path. |
| 97 | MEASURED simulator results are reported separately in the acceptance receipt. |
| 98 | |
| 99 | ### Wolfram query/result record (MODELED) |
| 100 | |
| 101 | All constants and modeled calculations were checked with the mounted Wolfram |
| 102 | Language 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 | |
| 136 | Use the compiler/bridge environment required by `om/units.sh`. Seed compiler: |
| 137 | Omega source `e5b32567`, omc SHA256 |
| 138 | `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`. |
| 139 | The checked C and declarations are generated only by that script. |
| 140 | |
| 141 | ```sh |
| 142 | export OMEGA_OMC=/home/drakestapleton/work/cudastack/omega-mv/seed/out/omc |
| 143 | export OMEGA_BRIDGE=/home/drakestapleton/work/cudastack/omega-bridge |
| 144 | bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh |
| 145 | bwrap --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 | |
| 148 | The 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 |
| 150 | both signs, both zeros, small values and saturation even at count one. Larger |
| 151 | cases include largest finite f32/bf16 inputs. It compares the complete emitted |
| 152 | path with independent double erf/erfc, tanh and exp references. Deliberately |
| 153 | perturbed computed output must fail. Seven seeded source mutants must first compile with seeded |
| 154 | omc and generate checked C, then fail behavior: ReLU selection, erf coefficient, |
| 155 | tanh cubic coefficient, SiLU sign, block indexing, storage load and admission. |
| 156 | The admission mutant is killed by an expected session-lock guard abort; an |
| 157 | unrelated signal or compile failure never counts. A separate compiled C |
| 158 | direct-open guard control must die with the session-open abort marker. |
| 159 | Mutation evidence is retained under the printed ignored build directory. |
| 160 | No full suite or GPU run is part of these targets. See `CHIP.md` for the |
| 161 | operator-only hardware acceptance procedure. |
| 162 | |
| 163 | ### Private host receipt (MEASURED; no chip qualification) |
| 164 | |
| 165 | First registration was committed separately as `8d491f2`. The implementation |
| 166 | and reference-first work-in-progress checkpoint was pushed as `9c9f00b`. |
| 167 | The final device-isolated focused command was: |
| 168 | |
| 169 | ```sh |
| 170 | bwrap --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 | |
| 176 | Exit status: **0**. Local evidence: `build/dnn-activations-bwrap-final.log`; |
| 177 | mutation artifacts: `build/dnn-activations-mutants.A5n2G3/`. The private `/dev` |
| 178 | contains no GPU, CUSE or VFIO device nodes. Session-abort guards remain in |
| 179 | addition to this device namespace isolation. These build artifacts are ignored, |
| 180 | not historical committed chip receipts. Final lines: |
| 181 | |
| 182 | ``` |
| 183 | dnn-activations host+warp-sim: PASS (4 operators, 3 types, tails, independent double references, refusal-before-open, wrong-result control) |
| 184 | dnn-activations shell-contract: PASS (NULL open: 0 allocs; non-NULL open: 1 failed alloc; isolated fake backend) |
| 185 | dnn-activations isolation control: PASS (compiled direct-open mutant aborts under --sim) |
| 186 | dnn-activations source mutants: PASS (7 compiled, 7 behaviorally killed) |
| 187 | ``` |
| 188 | |
| 189 | The deliberate C direct-open control aborts with the session-open marker. |
| 190 | The widened seeded admission mutant aborts with the session-lock marker; |
| 191 | the remaining six seeded mutants return the expected behavioral-failure status. |
| 192 | The host test binary's five `__wrap_omega_gpu_session_*` symbols were also |
| 193 | observed with `nm -g --defined-only` before the guarded acceptance run. |
| 194 | The separately gated chip runner was built, not executed, in the prior focused |
| 195 | build recorded in `build/dnn-activations-final.log` (exit 0). |
| 196 | |
| 197 | Generation by `om/units.sh`: PASS. Independent host references and warp |
| 198 | simulation: PASS for the enumerated corpus and counts, not an exhaustive input |
| 199 | proof. Seeded behavioral mutation gate: PASS. Hardware correctness/performance: |
| 200 | **NOT_RUN**. Full host suite: **NOT_RUN**, integration-owner-only. |
| 201 | No merge or deployment was performed. |