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 / api / apish_blk.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note One 128-wide FP8 e4m3 block product. w is the weight row, x is f32 bits, sc is bf16 bits. |
| 3 | note The sum is left-associative f64, one rounding per mul and add. Returns the f64 bits. |
| 4 | |
| 5 | fn refb b uint to f32 |
| 6 | s = and b 128 |
| 7 | e = and shr b 3 15 |
| 8 | m = and b 7 |
| 9 | if and eq e 15 eq m 7 |
| 10 | ret bitcast f32 uint 2143289344 |
| 11 | end |
| 12 | if eq e 0 |
| 13 | z = mul f32 m bitcast f32 shl sub uint 127 9 23 |
| 14 | if ne s 0 |
| 15 | ret bitcast f32 xor bitcast uint z shl uint 1 31 |
| 16 | end |
| 17 | ret z |
| 18 | end |
| 19 | base = add bitcast f32 shl uint 127 23 div f32 m 8.0f32 |
| 20 | val = mul base bitcast f32 shl add uint 120 e 23 |
| 21 | if ne s 0 |
| 22 | ret bitcast f32 xor bitcast uint val shl uint 1 31 |
| 23 | end |
| 24 | ret val |
| 25 | end |
| 26 | |
| 27 | fn u32le x view uchar 512 i ulong to uint |
| 28 | o = mul i 4 |
| 29 | b0 = uint get x o |
| 30 | b1 = uint get x add o 1 |
| 31 | b2 = uint get x add o 2 |
| 32 | b3 = uint get x add o 3 |
| 33 | ret or or or b0 shl b1 8 shl b2 16 shl b3 24 |
| 34 | end |
| 35 | |
| 36 | fn apishb w view uchar 128 x view uchar 512 sc uint to ulong |
| 37 | sf = bitcast f32 shl and sc 65535 16 |
| 38 | sd = f64 sf |
| 39 | acc = 0.0f64 |
| 40 | for i ulong 128 |
| 41 | rd = f64 refb uint get w i |
| 42 | xd = f64 bitcast f32 u32le x i |
| 43 | acc = add acc mul mul rd xd sd |
| 44 | end |
| 45 | ret bitcast ulong acc |
| 46 | end |