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 / q38-head / envelope.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Folded final RMSNorm weight bits. Return positive upper-norm f32 bits, or zero to refuse. |
| 3 | fn q38_envelope bits view uint 5120 to ulong |
| 4 | mx = ulong 0 |
| 5 | for i ulong 5120 |
| 6 | v = and ulong get bits i 2147483647 |
| 7 | if ge v 2139095040 |
| 8 | ret 0 |
| 9 | end |
| 10 | if gt v mx |
| 11 | mx = v |
| 12 | end |
| 13 | end |
| 14 | note Tiny or zero weights use the conservative constant 1.0. |
| 15 | if lt mx 8388608 |
| 16 | ret 1065353216 |
| 17 | end |
| 18 | note 72 bounds sqrt(5120). 1025/1024 provides normalization rounding slack. |
| 19 | ex = and shr mx 23 255 |
| 20 | sig = or and mx 8388607 8388608 |
| 21 | sig = mul sig 73800 |
| 22 | shift = ulong 0 |
| 23 | while gt sig 16777215 bound 64 |
| 24 | sig = div add sig 1 2 |
| 25 | shift = add shift 1 |
| 26 | end |
| 27 | ex = sub add ex shift 10 |
| 28 | if ge ex 255 |
| 29 | ret 0 |
| 30 | end |
| 31 | ret or shl ex 23 sub sig 8388608 |
| 32 | end |