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 / apiviews / bf16.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note f32 to bf16 over the live view. md 0 is round-to-nearest-even (payload-quiet NaN). |
| 4 | note md 1 is the gdn state_put rule: any NaN becomes 0x7fc0, sign cleared. |
| 5 | note 0x7fffffff 2147483647, 0x7f800000 2139095040, 0x7fff 32767, 0x7fc0 32704. |
| 6 | fn av_rne u uint to uint |
| 7 | a = and u 2139095040 |
| 8 | if eq a 2139095040 |
| 9 | if ne and u 8388607 0 |
| 10 | ret or shr u 16 64 |
| 11 | end |
| 12 | ret shr u 16 |
| 13 | end |
| 14 | ret shr add add u 32767 and shr u 16 1 16 |
| 15 | end |
| 16 | fn av_stbf u uint to uint |
| 17 | if gt and u 2147483647 2139095040 |
| 18 | ret 32704 |
| 19 | end |
| 20 | ret shr add add u 32767 and shr u 16 1 16 |
| 21 | end |
| 22 | fn av_bf16 md ulong x view f32 * y edit ushort * to ulong |
| 23 | if ne len x len y |
| 24 | ret 1 |
| 25 | end |
| 26 | for i ulong len x |
| 27 | u = bitcast uint get x i |
| 28 | if eq md 0 |
| 29 | put y i ushort and av_rne u 65535 |
| 30 | else |
| 31 | put y i ushort and av_stbf u 65535 |
| 32 | end |
| 33 | end |
| 34 | ret 0 |
| 35 | end |