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

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