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 / dscalar.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note gpu/nvidia/checks/dscalar.om: the Omega port of the scalars() block of CUDApp tests/api_attn_rest_diff.c. |
| 3 | note Composed after gpu/nvidia/om/api/attn_om2.om (it starts with om2), gpu/nvidia/om/gemmex/num.om, |
| 4 | note gpu/nvidia/om/api/attn_scalar.om (av_drnd, av_perm, av_permf, av_permb), the four roots over it the C entries |
| 5 | note wrap (ds_round.om, ds_slot.om, ds_vecf.om, ds_vecb.om, which the check calls), gpu/nvidia/checks/lib.om and |
| 6 | note gpu/nvidia/checks/lib-om2.om; run with gpu/nvidia/checks/dscalar.tsv. Rows, tab separated, hex: |
| 7 | note r U WANT av_drnd of f32 bits U, and the check's port of the test's raw rounding, are both WANT |
| 8 | note s I R SLOT av_perm of I and R, and the check's port of the test's perm(), are both SLOT |
| 9 | note d av_drnd over the test's whole domain (every sign, exponent and high payload, eight low payloads) |
| 10 | note against the ported rounding |
| 11 | note v R av_permf and av_permb at rotary dimension R move every slot as the ported perm() says |
| 12 | note The r and s rows are the test's own expressions compiled from C; they tie the ported expressions to C. |
| 13 | text t_name "DSCALAR" |
| 14 | fn cname to void |
| 15 | for i ulong len t_name bound 64 |
| 16 | ckoc ulong get t_name i |
| 17 | end |
| 18 | end |
| 19 | fn dsx i ulong to ulong |
| 20 | n = cklen i |
| 21 | if or eq n 0 gt n 16 |
| 22 | ckbad |
| 23 | end |
| 24 | v = ulong 0 |
| 25 | for j ulong n bound 16 |
| 26 | v = or shl v 4 cknib ckch i j |
| 27 | end |
| 28 | ret v |
| 29 | end |
| 30 | note the test's want: (uint16_t)((u + 0x7fff + ((u >> 16) & 1)) >> 16), uint32 arithmetic |
| 31 | fn dsrnd u ulong to ulong |
| 32 | ret and shr and add add u 32767 and shr u 16 1 4294967295 16 65535 |
| 33 | end |
| 34 | note the test's perm(i, r), uint32 arithmetic |
| 35 | fn dsperm i ulong r ulong to ulong |
| 36 | p = div r 2 |
| 37 | if lt i 128 |
| 38 | if lt i p |
| 39 | ret i |
| 40 | end |
| 41 | ret and add r sub i p 4294967295 |
| 42 | end |
| 43 | j = sub i 128 |
| 44 | if lt j p |
| 45 | ret add p j |
| 46 | end |
| 47 | ret i |
| 48 | end |
| 49 | fn dsrow u ulong to bool |
| 50 | ret eq ulong ds_round uint u dsrnd u |
| 51 | end |
| 52 | fn crow to bool |
| 53 | k = ckch 0 0 |
| 54 | s = new f32 256 f32 0 |
| 55 | d = new f32 256 f32 0 |
| 56 | b = new ushort 256 0 |
| 57 | w = new ushort 256 0 |
| 58 | lows = new ulong 8 0 |
| 59 | put lows 1 1 |
| 60 | put lows 2 32766 |
| 61 | put lows 3 32767 |
| 62 | put lows 4 32768 |
| 63 | put lows 5 32769 |
| 64 | put lows 6 65534 |
| 65 | put lows 7 65535 |
| 66 | if or ne cklen 0 1 gt ckcnt 4 |
| 67 | ckbad |
| 68 | end |
| 69 | if eq k 114 |
| 70 | if ne ckcnt 3 |
| 71 | ckbad |
| 72 | end |
| 73 | u = dsx 1 |
| 74 | if gt u 4294967295 |
| 75 | ckbad |
| 76 | end |
| 77 | want = dsx 2 |
| 78 | ret and eq ulong ds_round uint u want eq dsrnd u want |
| 79 | end |
| 80 | if eq k 115 |
| 81 | if ne ckcnt 4 |
| 82 | ckbad |
| 83 | end |
| 84 | i = dsx 1 |
| 85 | r = dsx 2 |
| 86 | if or gt i 4294967295 gt r 4294967295 |
| 87 | ckbad |
| 88 | end |
| 89 | want = dsx 3 |
| 90 | ret and eq ulong ds_slot uint i uint r want eq dsperm i r want |
| 91 | end |
| 92 | if eq k 100 |
| 93 | for sg ulong 2 |
| 94 | for e ulong 256 |
| 95 | for hi ulong 128 |
| 96 | base = or or shl sg 31 shl e 23 shl hi 16 |
| 97 | for j ulong 8 |
| 98 | if not dsrow or base get lows j |
| 99 | ret false |
| 100 | end |
| 101 | end |
| 102 | end |
| 103 | end |
| 104 | end |
| 105 | ret true |
| 106 | end |
| 107 | if eq k 118 |
| 108 | if ne ckcnt 2 |
| 109 | ckbad |
| 110 | end |
| 111 | r = dsx 1 |
| 112 | if gt r 4294967295 |
| 113 | ckbad |
| 114 | end |
| 115 | for i ulong 256 |
| 116 | put s i bitcast f32 uint add 2139095040 i |
| 117 | put b i ushort i |
| 118 | end |
| 119 | for i ulong 256 |
| 120 | if ne ulong ds_slot uint i uint r dsperm i r |
| 121 | ret false |
| 122 | end |
| 123 | end |
| 124 | if ne ds_vecf view s edit d uint r 0 |
| 125 | ret false |
| 126 | end |
| 127 | if ne ds_vecb view b edit w uint r 0 |
| 128 | ret false |
| 129 | end |
| 130 | for i ulong 256 |
| 131 | q = dsperm i r |
| 132 | if ne ulong bitcast uint get d i add 2139095040 q |
| 133 | ret false |
| 134 | end |
| 135 | if ne ulong get w i q |
| 136 | ret false |
| 137 | end |
| 138 | end |
| 139 | ret true |
| 140 | end |
| 141 | ckbad |
| 142 | ret false |
| 143 | end |