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 / nmm.om

194 lines · 4845 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/nvidia/checks/nmm.om: the matmul() block of CUDApp tests/api_attn_rest_diff.c. The units mm_init, mm_dot,
3note mm_err and mm_next (gpu/nvidia/om/api/, over ar_dot and ar_err of attn_oracle.om) are the host matmul oracle
4note of src/omega_gpu_matmul_api.c; the check drives them with that file's loop (ported in nmrun) and compares the
5note result with the pending C oracle (CUDAPP_MIGRATION_PENDING_C_MATMUL_ORACLE_GUARD) the table holds. Here
6note mm_init and mm_next are the stand-ins nmm-init.om and nmm-next.om (see there); the units themselves are
7note proven by nmmq.om. Rows:
8note M m k n A B C ABS REL MISM PAR
9note A (m x k) and B (k x n) bfloat16 as 4 hex digits each and C (m x n) float bits as 8 hex
10note digits each, - when empty; the C oracle answered max_abs_err and max_rel_err (float bits,
11note 8 hex digits), mismatch_count and parity_verified. The units must give the same bits.
12note Z K ABS REL MISM PAR
13note 1 x K x 1 with A all 1.0 and B alternating -1.0, 1.0: a dot product of K terms, past the
14note 1000000-term segment of ar_dot when K is larger; built here, not read from the table.
15note The kept operands live in arrays of 4096 values (A, B and C each); a larger row is refused as malformed
16note (ckbad, exit 2), never cut. Z rows hold at most 1000003 terms, two arrays of that many bfloat16 in nmz.
17text t_name "NMM"
18fn cname to void
19for i ulong len t_name bound 64
20ckoc ulong get t_name i
21end
22end
23note value j of hex field i, w bytes wide, as printed (most significant first)
24fn nmh i ulong j ulong w ulong to ulong
25v = ulong 0
26for x ulong w bound 8
27v = or shl v 8 ckhex i add mul j w x
28end
29ret v
30end
31note one dot product of the loop; true when mm_dot answered 0, as the C loop requires. p is q[0..4) (the C passes
32note q with length 4).
33fn nmdot a view ushort * b view ushort * q view ulong 8 d edit ulong 2 to bool
34p = new ulong 4 0
35for i ulong 4
36put p i get q i
37end
38ret eq mm_dot part a 0 get q 6 part b 0 get q 7 p d 0
39end
40note the oracle loop of src/omega_gpu_matmul_api.c, q = {0, 0, k, n, m, 0, 0, 0}, z = {0, 0, 0, 1}. w holds m, k, n
41note in slots 0 to 2 (one array: a function has six parameter slots and an unsized view takes two); z, the
42note answer (max_abs_err, max_rel_err, mismatch_count, parity_verified), is copied to slots 4 to 7; slot 3 holds r,
43note the loop's go-on flag.
44fn nmerr d view ulong 2 c view uint 4096 q view ulong 8 z edit ulong 4 to bool
45ret eq mm_err d get c get q 5 z 0
46end
47fn nmrun a view ushort * b view ushort * c view uint 4096 w edit ulong 8 to bool
48q = new ulong 8 0
49d = new ulong 2 0
50z = new ulong 4 0
51put q 2 get w 1
52put q 3 get w 2
53put q 4 get w 0
54put z 3 1
55put w 3 0
56if mm_init q
57put w 3 1
58end
59for it ulong mul get w 0 get w 2 bound 4096
60if eq get w 3 0
61ret false
62end
63if not nmdot a b q d
64ret false
65end
66if not nmerr d c q z
67ret false
68end
69put w 3 0
70if mm_next q
71put w 3 1
72end
73end
74for i ulong 4
75put w add i 4 get z i
76end
77ret eq get w 3 0
78end
79fn nmfill i ulong w ulong cnt ulong o edit ushort 4096 to void
80if eq cnt 0
81if ne ckhexn i 0
82ckbad
83end
84ret
85end
86if ne ckhexn i mul cnt w
87ckbad
88end
89for j ulong cnt bound 4096
90put o j ushort nmh i j w
91end
92end
93fn nmfillc cnt ulong o edit uint 4096 to void
94if eq cnt 0
95if ne ckhexn 6 0
96ckbad
97end
98ret
99end
100if ne ckhexn 6 mul cnt 4
101ckbad
102end
103for j ulong cnt bound 4096
104put o j uint nmh 6 j 4
105end
106end
107fn nmok w view ulong 8 ia ulong to bool
108if ne get w 4 nmh ia 0 4
109ret false
110end
111if ne get w 5 nmh add ia 1 0 4
112ret false
113end
114if ne get w 6 cknum add ia 2
115ret false
116end
117ret eq get w 7 cknum add ia 3
118end
119fn nmz to bool
120la = new ushort 1000003 0
121lb = new ushort 1000003 0
122lc = new uint 4096 0
123w = new ulong 8 1
124if ne ckcnt 6
125ckbad
126end
127kk = cknum 1
128if or eq kk 0 gt kk 1000003
129ckbad
130end
131if or ne ckhexn 2 4 ne ckhexn 3 4
132ckbad
133end
134for i ulong kk bound 1000003
135put la i ushort 16256
136if eq and i 1 0
137put lb i ushort 49024
138else
139put lb i ushort 16256
140end
141end
142put lc 0 uint 1065353216
143put w 1 kk
144if not nmrun part la 0 kk part lb 0 kk lc w
145ret false
146end
147ret nmok w 2
148end
149note the shape m, k, n of an M row into w slots 0 to 2; a shape whose operands pass 4096 values is refused
150fn nmshape w edit ulong 8 to void
151for i ulong 3
152v = cknum add i 1
153if gt v 4096
154ckbad
155end
156put w i v
157end
158if gt mul get w 0 get w 1 4096
159ckbad
160end
161if gt mul get w 1 get w 2 4096
162ckbad
163end
164if gt mul get w 0 get w 2 4096
165ckbad
166end
167if or ne ckhexn 7 4 ne ckhexn 8 4
168ckbad
169end
170end
171fn crow to bool
172a = new ushort 4096 0
173b = new ushort 4096 0
174c = new uint 4096 0
175w = new ulong 8 0
176if ne cklen 0 1
177ckbad
178end
179k0 = ckch 0 0
180if eq k0 90
181ret nmz
182end
183if or ne k0 77 ne ckcnt 11
184ckbad
185end
186nmshape w
187nmfill 4 2 mul get w 0 get w 1 a
188nmfill 5 2 mul get w 1 get w 2 b
189nmfillc mul get w 0 get w 2 c
190if not nmrun a b c w
191ret false
192end
193ret nmok w 7
194end