interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / nvidia / checks / dscalar.om

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