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 / checks / avrope.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/avrope.om: av_attnrope (gpu/nvidia/om/api/attn_math.om, through av_pow, av_log, av_exp, |
| 3 | note av_pow2, av_sinc, av_rrow and vc_rope) against av_ropegen of CUDApp src/omega_attn_tables.h with its pending C |
| 4 | note and the C host math of src/omega_gpu_hostmath.c: the ropegen calls of tests/attn_views_cases.c, the decode |
| 5 | note tables of the attention APIs and probes. attn_math.om carries om2, so it is the head of this check. Rows: |
| 6 | note R pos theta dim width rows h |
| 7 | note theta is the bits of the f64. The f32 array of rows*width elements starts as the bits 0x40490fdb (so an element |
| 8 | note the call does not write is compared too); h is its FNV-1a digest (h = (h xor bits) * 1099511628211 from |
| 9 | note 1469598103934665603). The unit must answer 0. rows*width above 1000003 (the largest local f32 array, 4 MiB) is |
| 10 | note ckbad. The host math the R rows stand on is compared on its own, every value as f64 bits, so an error the f32 |
| 11 | note table rounds away still shows: |
| 12 | note L x log(x) (av_log) E y exp(y) (av_exp) |
| 13 | note P b e pow(b,e) (av_pow) S a sin(a) cos(a) (av_sinc) |
| 14 | text t_name "AVROPE" |
| 15 | text t_r "R" |
| 16 | text t_l "L" |
| 17 | text t_e "E" |
| 18 | text t_p "P" |
| 19 | text t_s "S" |
| 20 | fn cname to void |
| 21 | for i ulong len t_name bound 64 |
| 22 | ckoc ulong get t_name i |
| 23 | end |
| 24 | end |
| 25 | fn ckf i ulong to f64 |
| 26 | ret bitcast f64 cknum i |
| 27 | end |
| 28 | fn arm to bool |
| 29 | if ckis 0 t_l |
| 30 | if ne ckcnt 3 |
| 31 | ckbad |
| 32 | end |
| 33 | ret eq bitcast ulong av_log ckf 1 cknum 2 |
| 34 | end |
| 35 | if ckis 0 t_e |
| 36 | if ne ckcnt 3 |
| 37 | ckbad |
| 38 | end |
| 39 | ret eq bitcast ulong av_exp ckf 1 cknum 2 |
| 40 | end |
| 41 | if ckis 0 t_p |
| 42 | if ne ckcnt 4 |
| 43 | ckbad |
| 44 | end |
| 45 | ret eq bitcast ulong av_pow ckf 1 ckf 2 cknum 3 |
| 46 | end |
| 47 | if or ne ckcnt 4 not ckis 0 t_s |
| 48 | ckbad |
| 49 | end |
| 50 | o = new ulong 2 0 |
| 51 | av_sinc ckf 1 o |
| 52 | ret and eq get o 0 cknum 2 eq get o 1 cknum 3 |
| 53 | end |
| 54 | fn crow to bool |
| 55 | if not ckis 0 t_r |
| 56 | ret arm |
| 57 | end |
| 58 | if ne ckcnt 7 |
| 59 | ckbad |
| 60 | end |
| 61 | w = cknum 4 |
| 62 | rows = cknum 5 |
| 63 | if gt w 0 |
| 64 | if gt rows div 1000003 w |
| 65 | ckbad |
| 66 | end |
| 67 | end |
| 68 | l = mul rows w |
| 69 | d = new f32 1000003 f32 0 |
| 70 | for i ulong l bound 1000003 |
| 71 | put d i bitcast f32 uint 1078530011 |
| 72 | end |
| 73 | q = new ulong 16 0 |
| 74 | put q 0 cknum 1 |
| 75 | put q 1 cknum 2 |
| 76 | put q 2 cknum 3 |
| 77 | put q 3 w |
| 78 | put q 4 rows |
| 79 | rc = av_attnrope d q |
| 80 | if ne rc 0 |
| 81 | ret false |
| 82 | end |
| 83 | h = ulong 1469598103934665603 |
| 84 | for i ulong l bound 1000003 |
| 85 | h = mul xor h ulong bitcast uint get d i 1099511628211 |
| 86 | end |
| 87 | ret eq h cknum 6 |
| 88 | end |