omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / gpu / nvidia / om / api / attn_oracle.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | fn ar_abs u ulong to ulong |
| 4 | x = bitcast f64 u |
| 5 | if lt x 0.0 |
| 6 | ret bitcast ulong neg x |
| 7 | end |
| 8 | ret u |
| 9 | end |
| 10 | note q = row, column, k, n; preserve double operation order and float maxima. |
| 11 | fn ar_term a view ushort * b view ushort * q view ulong 6 t ulong to ulong |
| 12 | x = f64 bitcast f32 shl uint get a add mul get q 0 get q 2 t 16 |
| 13 | y = f64 bitcast f32 shl uint get b add mul t get q 3 get q 1 16 |
| 14 | ret bitcast ulong mul x y |
| 15 | end |
| 16 | fn ar_seg a view ushort * b view ushort * q view ulong 6 d edit ulong 2 to ulong |
| 17 | for z ulong get q 5 |
| 18 | p = bitcast f64 ar_term a b q add get q 4 z |
| 19 | put d 0 bitcast ulong add bitcast f64 get d 0 p |
| 20 | put d 1 bitcast ulong add bitcast f64 get d 1 bitcast f64 ar_abs bitcast ulong p |
| 21 | end |
| 22 | ret 0 |
| 23 | end |
| 24 | fn ar_dot a view ushort * b view ushort * q view ulong 4 d edit ulong 2 to ulong |
| 25 | qq = new ulong 6 0 |
| 26 | for i ulong 4 |
| 27 | put qq i get q i |
| 28 | end |
| 29 | put d 0 bitcast ulong f64 0.0 |
| 30 | put d 1 bitcast ulong f64 0.0 |
| 31 | for bb ulong add div get q 2 1000000 1 |
| 32 | put qq 4 mul bb 1000000 |
| 33 | cnt = sub get q 2 get qq 4 |
| 34 | if gt cnt 1000000 |
| 35 | cnt = ulong 1000000 |
| 36 | end |
| 37 | put qq 5 cnt |
| 38 | rc = ar_seg a b qq d |
| 39 | if ne rc 0 |
| 40 | ret rc |
| 41 | end |
| 42 | end |
| 43 | ret 0 |
| 44 | end |
| 45 | fn ar_err d view ulong 2 c uint z edit ulong 4 to ulong |
| 46 | diff = bitcast f64 ar_abs bitcast ulong sub bitcast f64 get d 0 f64 bitcast f32 c |
| 47 | scale = bitcast f64 get d 1 |
| 48 | if not gt scale 0.000001 |
| 49 | scale = f64 0.000001 |
| 50 | end |
| 51 | rel = div diff scale |
| 52 | if gt f32 diff bitcast f32 uint get z 0 |
| 53 | put z 0 ulong bitcast uint f32 diff |
| 54 | end |
| 55 | if gt f32 rel bitcast f32 uint get z 1 |
| 56 | put z 1 ulong bitcast uint f32 rel |
| 57 | end |
| 58 | if gt rel 0.00001 |
| 59 | put z 2 add get z 2 1 |
| 60 | end |
| 61 | if eq get z 2 0 |
| 62 | put z 3 1 |
| 63 | else |
| 64 | put z 3 0 |
| 65 | end |
| 66 | ret 0 |
| 67 | end |