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 / src / tensor / test_tensor.om

267 lines · 8038 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note test_tensor.om -- Pure seeded OM-2 M20 OMEGA_TENSOR CPU & GB10-map test suite.
3
4global tt_c ulong 2
5note 0=checks, 1=fails
6
7text msg_pass "M20_OMEGA_TENSOR_TESTS_PASS\n"
8text msg_fail "M20_OMEGA_TENSOR_TESTS_FAIL\n"
9
10fn t_chk cond bool to void
11 put tt_c 0 add get tt_c 0 1
12 if not cond
13 put tt_c 1 add get tt_c 1 1
14 end
15end
16
17fn t_near a f32 b f32 tol f32 to bool
18 ret le fabs sub a b tol
19end
20
21fn test_lifetime_and_views to void
22 t_chk eq ot_ctx_init 64 OT_OK
23 sh = new ulong 8 0
24 put sh 0 2
25 put sh 1 3
26 dat = new f32 6 0.0f32
27 for i ulong 6
28 put dat i f32 add i 1
29 end
30 ha = new ulong 2 0
31 t_chk eq ot_from_f32 2 sh dat ha OT_OK
32 ht = new ulong 2 0
33 t_chk eq ot_transpose get ha 0 get ha 1 ht OT_OK
34 obuf = new f32 6 0.0f32
35 t_chk eq ot_read_f32 get ht 0 get ht 1 obuf OT_OK
36 t_chk eq get obuf 0 1.0f32
37 t_chk eq get obuf 1 4.0f32
38 t_chk eq get obuf 2 2.0f32
39 t_chk eq get obuf 3 5.0f32
40 t_chk eq get obuf 4 3.0f32
41 t_chk eq get obuf 5 6.0f32
42 note Value ID invariance across contiguous copy of transposed view
43 hc = new ulong 2 0
44 t_chk eq ot_contiguous get ht 0 get ht 1 hc OT_OK
45 eq_f = new ulong 1 0
46 t_chk eq ot_value_equal get ht 0 get ht 1 get hc 0 get hc 1 eq_f OT_OK
47 t_chk eq get eq_f 0 1
48 note Releasing parent makes view stale
49 t_chk eq ot_release get ha 0 get ha 1 OT_OK
50 t_chk eq ot_release get ha 0 get ha 1 OT_ERR_STALE
51 t_chk eq ot_read_f32 get ht 0 get ht 1 obuf OT_ERR_STALE
52 t_chk eq ot_release get ht 0 get ht 1 OT_OK
53 t_chk eq ot_release get hc 0 get hc 1 OT_OK
54 lc = new ulong 2 0
55 ot_live_counts lc
56 t_chk and eq get lc 0 0 eq get lc 1 0
57 note Generation retirement at UINT64_MAX
58 t_chk eq ot_set_st_gen_test 0 OT_U64_MAX OT_OK
59 t_chk eq ot_from_f32 2 sh dat ha OT_OK
60 t_chk eq get ot_ts_meta add mul get ha 0 10 7 0
61 t_chk eq ot_release get ha 0 get ha 1 OT_OK
62 t_chk eq ot_from_f32 2 sh dat ha OT_OK
63 t_chk ne get ot_ts_meta add mul get ha 0 10 7 0
64 t_chk eq ot_release get ha 0 get ha 1 OT_OK
65end
66
67fn test_slice_embed_concat to void
68 t_chk eq ot_ctx_init 64 OT_OK
69 sh = new ulong 8 0
70 put sh 0 2
71 put sh 1 4
72 dat = new f32 8 0.0f32
73 for i ulong 8
74 put dat i f32 add i 1
75 end
76 ha = new ulong 2 0
77 t_chk eq ot_from_f32 2 sh dat ha OT_OK
78 st = new ulong 8 0
79 sp = new ulong 8 0
80 stp = new ulong 8 0
81 put st 0 0
82 put st 1 1
83 put sp 0 2
84 put sp 1 4
85 put stp 0 1
86 put stp 1 2
87 hs = new ulong 2 0
88 t_chk eq ot_slice get ha 0 get ha 1 st sp stp hs OT_OK
89 obuf = new f32 4 0.0f32
90 t_chk eq ot_read_f32 get hs 0 get hs 1 obuf OT_OK
91 t_chk eq get obuf 0 2.0f32
92 t_chk eq get obuf 1 4.0f32
93 t_chk eq get obuf 2 6.0f32
94 t_chk eq get obuf 3 8.0f32
95 he = new ulong 2 0
96 t_chk eq ot_embed get hs 0 get hs 1 sh st stp he OT_OK
97 out8 = new f32 8 0.0f32
98 t_chk eq ot_read_f32 get he 0 get he 1 out8 OT_OK
99 t_chk eq get out8 0 0.0f32
100 t_chk eq get out8 1 2.0f32
101 t_chk eq get out8 3 4.0f32
102 t_chk eq get out8 5 6.0f32
103 t_chk eq get out8 7 8.0f32
104 sl = new ulong 16 0
105 gn = new ulong 16 0
106 put sl 0 get hs 0
107 put gn 0 get hs 1
108 put sl 1 get hs 0
109 put gn 1 get hs 1
110 hc = new ulong 2 0
111 t_chk eq ot_concat 2 sl gn 1 hc OT_OK
112 t_chk eq ot_read_f32 get hc 0 get hc 1 out8 OT_OK
113 t_chk eq get out8 0 2.0f32
114 t_chk eq get out8 2 2.0f32
115 t_chk eq get out8 4 6.0f32
116 t_chk eq get out8 7 8.0f32
117end
118
119fn test_ops_and_where to void
120 t_chk eq ot_ctx_init 64 OT_OK
121 sh = new ulong 8 0
122 put sh 0 4
123 da = new f32 4 0.0f32
124 db = new f32 4 0.0f32
125 put da 0 -2.0f32
126 put da 1 0.0f32
127 put da 2 4.0f32
128 put da 3 9.0f32
129 put db 0 1.0f32
130 put db 1 0.0f32
131 put db 2 2.0f32
132 put db 3 10.0f32
133 ha = new ulong 2 0
134 ha2 = new ulong 2 0
135 hb = new ulong 2 0
136 t_chk eq ot_from_f32 1 sh da ha OT_OK
137 put ha2 0 get ha 0
138 put ha2 1 get ha 1
139 t_chk eq ot_from_f32 1 sh db hb OT_OK
140 hr = new ulong 2 0
141 obuf = new f32 4 0.0f32
142 t_chk eq ot_unary OT_TU_RELU get ha 0 get ha 1 hr OT_OK
143 t_chk eq ot_read_f32 get hr 0 get hr 1 obuf OT_OK
144 t_chk eq get obuf 0 0.0f32
145 t_chk eq get obuf 2 4.0f32
146 t_chk eq ot_unary OT_TU_NEG get ha 0 get ha 1 hr OT_OK
147 t_chk eq ot_read_f32 get hr 0 get hr 1 obuf OT_OK
148 t_chk eq get obuf 0 2.0f32
149 t_chk eq bitcast uint get obuf 1 OT_NEG0_BITS
150 hm = new ulong 2 0
151 t_chk eq ot_binary OT_TB_CMP_GT get ha 0 get ha 1 get hb 0 get hb 1 hm OT_OK
152 hw = new ulong 2 0
153 t_chk eq ot_where hm ha hb hw OT_OK
154 t_chk eq ot_read_f32 get hw 0 get hw 1 obuf OT_OK
155 t_chk eq get obuf 0 1.0f32
156 t_chk eq get obuf 2 4.0f32
157 t_chk eq get obuf 3 10.0f32
158 note Bad mask refused
159 t_chk eq ot_where ha2 ha hb hw OT_ERR_MASK
160 note Transcendentals
161 t_chk t_near ot_unary_scalar OT_TU_EXP 0.0f32 1.0f32 0.0001f32
162 t_chk t_near ot_unary_scalar OT_TU_EXP2 3.0f32 8.0f32 0.001f32
163 t_chk t_near ot_unary_scalar OT_TU_LOG 1.0f32 0.0f32 0.0001f32
164 t_chk t_near ot_unary_scalar OT_TU_LOG2 8.0f32 3.0f32 0.001f32
165 t_chk t_near ot_unary_scalar OT_TU_SIGMOID 0.0f32 0.5f32 0.0001f32
166 t_chk t_near ot_unary_scalar OT_TU_TANH 0.0f32 0.0f32 0.0001f32
167 t_chk t_near ot_unary_scalar OT_TU_SIN 0.0f32 0.0f32 0.0001f32
168 t_chk t_near ot_unary_scalar OT_TU_COS 0.0f32 1.0f32 0.0001f32
169 t_chk t_near ot_unary_scalar OT_TU_ERF 0.0f32 0.0f32 0.0001f32
170 t_chk t_near ot_unary_scalar OT_TU_GELU 0.0f32 0.0f32 0.0001f32
171 t_chk t_near ot_unary_scalar OT_TU_RSQRT 4.0f32 0.5f32 0.0001f32
172end
173
174fn test_reduce_matmul_cast to void
175 t_chk eq ot_ctx_init 64 OT_OK
176 sh = new ulong 8 0
177 put sh 0 2
178 put sh 1 3
179 da = new f32 6 0.0f32
180 for i ulong 6
181 put da i f32 add i 1
182 end
183 ha = new ulong 2 0
184 t_chk eq ot_from_f32 2 sh da ha OT_OK
185 hr = new ulong 2 0
186 t_chk eq ot_reduce OT_TR_SUM get ha 0 get ha 1 1 0 hr OT_OK
187 o2 = new f32 2 0.0f32
188 t_chk eq ot_read_f32 get hr 0 get hr 1 o2 OT_OK
189 t_chk eq get o2 0 6.0f32
190 t_chk eq get o2 1 15.0f32
191 note multi-axis reduce and sum_to_shape
192 ax = new ulong 8 0
193 put ax 0 0
194 put ax 1 1
195 ko = new ulong 3 0
196 put ko 2 0
197 t_chk eq ot_reduce_axes OT_TR_SUM get ha 0 get ha 1 2 ax ko OT_OK
198 o1 = new f32 1 0.0f32
199 t_chk eq ot_read_f32 get ko 0 get ko 1 o1 OT_OK
200 t_chk eq get o1 0 21.0f32
201 t_chk eq ot_reduce_axes OT_TR_MEAN get ha 0 get ha 1 2 ax ko OT_ERR_BAD_ARGS
202 tsh = new ulong 8 0
203 put tsh 0 3
204 hs = new ulong 2 0
205 t_chk eq ot_sum_to_shape get ha 0 get ha 1 1 tsh hs OT_OK
206 o3 = new f32 3 0.0f32
207 t_chk eq ot_read_f32 get hs 0 get hs 1 o3 OT_OK
208 t_chk eq get o3 0 5.0f32
209 t_chk eq get o3 1 7.0f32
210 t_chk eq get o3 2 9.0f32
211end
212
213fn test_matmul_cast_gb10 to void
214 t_chk eq ot_ctx_init 64 OT_OK
215 sh = new ulong 8 0
216 put sh 0 2
217 put sh 1 3
218 da = new f32 6 0.0f32
219 for i ulong 6
220 put da i f32 add i 1
221 end
222 ha = new ulong 2 0
223 t_chk eq ot_from_f32 2 sh da ha OT_OK
224 note matmul [2,3] x [3,2]
225 shb = new ulong 8 0
226 put shb 0 3
227 put shb 1 2
228 hb = new ulong 2 0
229 t_chk eq ot_from_f32 2 shb da hb OT_OK
230 hm = new ulong 2 0
231 t_chk eq ot_matmul get ha 0 get ha 1 get hb 0 get hb 1 hm OT_OK
232 o4 = new f32 4 0.0f32
233 t_chk eq ot_read_f32 get hm 0 get hm 1 o4 OT_OK
234 t_chk eq get o4 0 22.0f32
235 t_chk eq get o4 1 28.0f32
236 t_chk eq get o4 2 49.0f32
237 t_chk eq get o4 3 64.0f32
238 note F32 <-> F16 and BF16 cast round-trip
239 hf16 = new ulong 2 0
240 hf32 = new ulong 2 0
241 t_chk eq ot_cast get ha 0 get ha 1 OT_DT_F16 hf16 OT_OK
242 t_chk eq ot_cast get hf16 0 get hf16 1 OT_DT_BF16 hf32 OT_ERR_DTYPE
243 t_chk eq ot_cast get hf16 0 get hf16 1 OT_DT_F32 hf32 OT_OK
244 o6 = new f32 6 0.0f32
245 t_chk eq ot_read_f32 get hf32 0 get hf32 1 o6 OT_OK
246 t_chk eq get o6 5 6.0f32
247 note GB10 mapping checks
248 t_chk ne ot_gb10_simt_op_id OT_TB_ADD 0
249 t_chk eq ot_gb10_simt_op_id OT_TB_CMP_EQ 0
250 t_chk eq ot_gb10_transc_kernel OT_TU_EXP 9
251 t_chk eq ot_gb10_transc_kernel OT_TU_RELU -1
252 t_chk eq ot_gb10_check_reduce OT_TR_SUM 32769 OT_GB10_ERR_OPERANDS
253end
254
255fn main to int
256 test_lifetime_and_views
257 test_slice_embed_concat
258 test_ops_and_where
259 test_reduce_matmul_cast
260 test_matmul_cast_gb10
261 if ne get tt_c 1 0
262 w = write 1 msg_fail 0 len msg_fail
263 ret 1
264 end
265 w = write 1 msg_pass 0 len msg_pass
266 ret 0
267end