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 / q38-head / envelope.om

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