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-rows / README.md
| 1 | # Seeded row softmax and normalization |
| 2 | |
| 3 | Experimental API; host/simulator exercise is not chip qualification. Chip qualification: **NOT_RUN**. |
| 4 | |
| 5 | Source base: CUDApp native-half seam 9be13fb2595f1b3668288b36c4d17ef976bcb3a7. |
| 6 | Compiler: omega-mv e5b32567, SHA-256 |
| 7 | |
| 8 | 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f. |
| 9 | The generated C and identities come from ${OMEGA_OMC} and ${OMEGA_BRIDGE} via om/units.sh; no handwritten generated implementation. |
| 10 | |
| 11 | ## API contract |
| 12 | |
| 13 | Include src/omega_gpu_dnn_rows_api.h. OmegaGpuDnnRowsShape fields are rows, |
| 14 | length, dtype, op, epsilon. Input is contiguous [rows][length]. Output is f32 |
| 15 | of the same shape, including for bf16/f16 input. Types use shared DNN constants: |
| 16 | 0 f32, 1 bf16, 2 IEEE binary16. Operations: 0 stable softmax, 1 layernorm, |
| 17 | 2 rmsnorm. The norms are pure normalization, with no affine or fusion parameters. |
| 18 | |
| 19 | - softmax: exp(x - row_max) / sum(exp(x - row_max)). |
| 20 | - layernorm: (x - row_mean) / sqrt(mean((x - row_mean)^2) + epsilon). |
| 21 | - rmsnorm: x / sqrt(mean(x^2) + epsilon). |
| 22 | |
| 23 | Rows and length are independently positive and at most 65535. At most |
| 24 | 1073741824 elements are admitted. Size decisions and all byte addresses are |
| 25 | seeded Omega. Epsilon for norms must be positive finite **normal** f32, with |
| 26 | unsigned encoding in [8388608,2139095040). Zero, negative values, subnormals, |
| 27 | infinity and NaN are refused. Softmax ignores epsilon. Epsilon is loaded at |
| 28 | runtime, not embedded in generated instructions. |
| 29 | |
| 30 | Finite input and finite f32 intermediate arithmetic are caller preconditions: |
| 31 | sums, differences, squares, variance plus epsilon, and output must remain |
| 32 | finite. The variance-plus-epsilon must remain normal and positive. Softmax |
| 33 | uses a maximum pass before exponentiation; subtracting two finite extremes |
| 34 | must still be finite. Input contents are not host-scanned. MUFU flush-to-zero |
| 35 | and approximate hardware operations are not represented by a universal |
| 36 | accuracy guarantee. bf16 and f16 widen to f32 through the shared emitter; |
| 37 | f16 is not reinterpreted as bf16. |
| 38 | |
| 39 | omega_gpu_dnn_rows_codegen is CPU-only; caller supplies BlackwellIRProgram, |
| 40 | code buffer (64 KiB recommended), and OmegaBlackwellKernel. It performs |
| 41 | Omega admission, emits Omega IR, uses the one shared generic replay, then |
| 42 | encodes. omega_gpu_dnn_rows copies input, allocates output/code, launches one |
| 43 | 32-thread warp per row, and copies output back. A valid GPU call requires an |
| 44 | operator-authorized exclusive window. Refusals occur before device/session |
| 45 | access. Null pointers return BAD_ARGS before admission. |
| 46 | |
| 47 | Return values: OK=0, REFUSED=1 (shape/type/size/epsilon), BAD_ARGS=2, |
| 48 | CODEGEN=3 (allocation, bridge/replay/encoding or code capacity), CHIP=4 |
| 49 | (session/allocation/synchronization/launch failure). The memory shell preserves |
| 50 | the session's uncertain-completion buffer ownership policy. |
| 51 | |
| 52 | ## Algorithm and independent tests |
| 53 | |
| 54 | A warp traverses each row in uniform ceil(length/32) loops. Every lane loads |
| 55 | only valid elements, with native f16/bf16 widening and appropriate identity |
| 56 | values on tails. Butterfly warp reductions combine the lane accumulators. |
| 57 | Softmax uses maximum, exponential sum, and output passes. Layernorm uses mean, |
| 58 | centered variance, and output passes. RMS norm uses mean-square and output |
| 59 | passes. The allocation/lifetime metadata names every generated loop. |
| 60 | |
| 61 | The independent C test oracle decodes input with host _Float16 and accumulates |
| 62 | naive double references using libm exp/sqrt; it does not call the production |
| 63 | unit to obtain answers. The warp simulator runs the entire emitted IR path, |
| 64 | with strict input/output memory ranges. The complete sweep covers lengths |
| 65 | 1,2,7,31,32,33,64,65,513,65535, all three dtypes and operations, multiple rows, |
| 66 | constant and varied rows, and epsilon values 0.0009765625,0.03125,1. Refused |
| 67 | geometry/type/size/epsilon are also sent to the public execution API to show |
| 68 | that they return before opening the session. A deliberately wrong reference |
| 69 | must be rejected. Six Omega source mutants must generate and compile successfully: |
| 70 | maximum, normalization, load tail, epsilon, epsilon refusal, and native-half mode. |
| 71 | Five fail numerical/address behavioral assertions. The epsilon-admission mutant |
| 72 | aborts at the host device guard before session access. A separate compiled C |
| 73 | test-source mutant directly calls session_open under --sim and must abort at |
| 74 | that entry guard. Baseline and every mutant binary link the same guard wrappers |
| 75 | for session open/allocate/lock/unlock/free. Under --sim and --quick every wrapped |
| 76 | entry aborts, rather than returning a recoverable error. A separate explicit |
| 77 | --shell-contract mode uses only fake open/failed-allocation responses to check |
| 78 | the session pointer contract: NULL opens allocate nothing, non-NULL opens attempt |
| 79 | exactly one blocked allocation. Only --chip forwards calls to real session APIs. |
| 80 | |
| 81 | ## MODELED numerical envelope (not chip accuracy) |
| 82 | |
| 83 | WolframLanguageEvaluator query: |
| 84 | |
| 85 | u=2^-24; k=Ceiling[65535/32]+5; g=k*u/(1-k*u); |
| 86 | {k,g,N[g,12],N[16*g,12],N[2^-5],N[2^-10], |
| 87 | Simplify[(x-m)/Sqrt[v+e]], |
| 88 | FullSimplify[Sum[Exp[a[i]-m],{i,1,n}]/Sum[Exp[a[i]-m],{i,1,n}],Assumptions->n>0]} |
| 89 | |
| 90 | Result: {2053,2053/16775163,0.000122383311566, |
| 91 | 0.00195813298506,0.03125,0.0009765625,(-m+x)/Sqrt[e+v],1}. |
| 92 | Units: dimensionless relative roundoff and normalization output. |
| 93 | |
| 94 | The test uses abs(error) <= 16 gamma_2053 (1+abs(reference)). This is a |
| 95 | conservative **MODELED test envelope** based on the maximum per-lane serial |
| 96 | length and butterfly depth, with headroom for transformations. It is not a |
| 97 | proof for ill-conditioned inputs, not a bound on MUFU approximation, and not |
| 98 | universal or measured chip accuracy. The independent sweep, not the formula, |
| 99 | provides the host numerical evidence for its stated finite test domain. |
| 100 | Tool availability checks: Integrate[x^2,{x,0,1}] -> 1/3; WolframAlpha |
| 101 | sqrt(27)/2 -> (3 sqrt(3))/2. |
| 102 | |
| 103 | ## Focused acceptance |
| 104 | |
| 105 | Set OMEGA_OMC to the pinned seeded compiler and OMEGA_BRIDGE to the pinned |
| 106 | companion checkout. Regenerate with: |
| 107 | |
| 108 | bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 sh om/units.sh |
| 109 | bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make -j3 test-gpu-dnn-rows test-gpu-dnn-rows-mutants |
| 110 | |
| 111 | Do not run the full suite from this slice. The integrator owns its single |
| 112 | attempt. Mutation evidence is kept under build/dnn-rows-evidence/mutants. |
| 113 | See CHIP.md for the separate operator-only NOT_RUN gate. |
| 114 | |
| 115 | Final focused command (with the two pinned OMEGA_* environment variables): |
| 116 | |
| 117 | taskset -c 10-14 nice -n 10 make -j3 test-gpu-dnn-rows test-gpu-dnn-rows-mutants |
| 118 | |
| 119 | Observed exit status: **0**. Final lines: |
| 120 | |
| 121 | dnn-rows host+warp-sim: PASS (all lengths/types/epsilon, constant+varied rows, tail ranges, refusals, wrong-result control) |
| 122 | dnn-rows shell contract: PASS (NULL open zero allocs; non-NULL open one blocked alloc; fake backend only) |
| 123 | dnn-rows direct-open guard mutant: PASS (compiled; killed by abort under --sim) |
| 124 | dnn-rows source mutants: PASS (5 behavioral failures, refusal guard abort, direct-open guard abort; all compiled) |
| 125 | |
| 126 | Persistent full output and exit status: |
| 127 | build/dnn-rows-evidence/focused-abort-guard.log and |
| 128 | build/dnn-rows-evidence/focused-abort-guard.rc. Each mutation retains its generated |
| 129 | source/C, generation log, test log and exact behavior_rc in the mutants subtree. |
| 130 | The five numerical/address mutants each returned 1; the refusal and direct-open |
| 131 | controls each returned 134 with the expected named HOST DEVICE GUARD diagnostic. |
| 132 | The generated units were compiled through om/units.sh with exit 0 before these |
| 133 | focused targets. Their checked .ident files pin source, compiler, converter and |
| 134 | frontend digests. No full suite was run from this lane. |
| 135 | |
| 136 | ### Initial host-test isolation correction |
| 137 | |
| 138 | The initial focused attempt's epsilon-admission mutant could reach real |
| 139 | session_open through the refusal fixture. The original host test did not yet |
| 140 | interpose session entry points. Source-only tracing established reachability |
| 141 | through the default Linux platform to nvrm_open, whose potential opens are |
| 142 | /dev/nvidiactl, /dev/nvidia-uvm (twice), and /dev/nvidia%u with a driver-reported |
| 143 | minor. This is not evidence of a successful open or launch; the initial artifact |
| 144 | cannot support a no-device-access claim. No GPU, dmesg, or lock probing was used |
| 145 | to investigate it. Initial output: artifact://3953 (focused make exit 2 due to |
| 146 | a later test-wrapper link mismatch). Return-error wrappers subsequently passed |
| 147 | the focused gates (artifact://4047), but were superseded by abort-on-entry |
| 148 | wrappers and an explicit direct-open abort control. A later in-flight run |
| 149 | (bg_770) was cancelled when the stronger isolation requirement arrived. |
| 150 | The chip gate remains NOT_RUN; no chip accuracy or operational-safety claim |
| 151 | is inferred from host evidence. |
| 152 | |
| 153 | ## Integration records (AttentionC owns shared files) |
| 154 | |
| 155 | Public declarations: |
| 156 | |
| 157 | int omega_gpu_dnn_rows_codegen(const OmegaGpuDnnRowsShape *shape, BlackwellIRProgram *program, uint8_t *code, size_t capacity, OmegaBlackwellKernel *kernel); |
| 158 | int omega_gpu_dnn_rows(const OmegaGpuDnnRowsShape *shape, const void *input, float *output); |
| 159 | |
| 160 | Proposed manifest records below use the existing format; the integrator owns |
| 161 | the shared manifest, its compiled layout blessing, API.md, version and ROADMAP. |
| 162 | |
| 163 | header src/omega_gpu_dnn_rows_api.h |
| 164 | struct OmegaGpuDnnRowsShape 20 4 # EXPERIMENTAL |
| 165 | field OmegaGpuDnnRowsShape rows 0 4 u32 1 |
| 166 | field OmegaGpuDnnRowsShape length 4 4 u32 1 |
| 167 | field OmegaGpuDnnRowsShape dtype 8 4 u32 1 |
| 168 | field OmegaGpuDnnRowsShape op 12 4 u32 1 |
| 169 | field OmegaGpuDnnRowsShape epsilon 16 4 f32 1 |
| 170 | const OMEGA_GPU_DNN_SOFTMAX 0 |
| 171 | const OMEGA_GPU_DNN_LAYERNORM 1 |
| 172 | const OMEGA_GPU_DNN_RMSNORM 2 |
| 173 | const OMEGA_GPU_DNN_ROWS_OK 0 |
| 174 | const OMEGA_GPU_DNN_ROWS_REFUSED 1 |
| 175 | const OMEGA_GPU_DNN_ROWS_BAD_ARGS 2 |
| 176 | const OMEGA_GPU_DNN_ROWS_CODEGEN 3 |
| 177 | const OMEGA_GPU_DNN_ROWS_CHIP 4 |
| 178 | fn omega_gpu_dnn_rows_codegen fn(*const OmegaGpuDnnRowsShape, *mut BlackwellIRProgram, *mut u8, usize, *mut OmegaBlackwellKernel) -> i32 # EXPERIMENTAL |
| 179 | fn omega_gpu_dnn_rows fn(*const OmegaGpuDnnRowsShape, *const c_void, *mut f32) -> i32 # EXPERIMENTAL |