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 / apiviews / bf16.om

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