interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tests / api_shells_diff.c

499 lines · 22150 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2/* Omega API decisions against the pending C oracle. Same header, flag off here. */
3#include "omega_api_shells.h"
4#include "omega_fp8_slot_table.h"
5#include "omega_gpu_fp8_api.h"
6#include <stdio.h>
7#include <stdint.h>
8#include <string.h>
9#include <stdlib.h>
10
11uint32_t c_lane(uint32_t k);
12void c_fp8def(uint32_t mt, uint32_t wp, uint32_t *m, uint32_t *w);
13uint32_t c_fp8mt(uint32_t mt, uint32_t segs);
14uint32_t c_ctabud(uint32_t segs, uint32_t ov);
15int c_regfit(uint32_t w, uint32_t d);
16uint32_t c_tgbm(uint32_t rt, uint32_t w, uint32_t n);
17void c_tgspec(uint32_t rt, uint32_t w, uint32_t n, uint32_t *r, uint32_t *ww);
18uint32_t c_tgsz(uint32_t m, uint32_t n, uint32_t bm);
19void c_ternd(uint32_t k, uint32_t lay, uint32_t R, uint32_t gr, uint32_t gd, uint32_t *rows, uint32_t *depth);
20void c_ternwc(uint32_t w, uint32_t ct, uint32_t *ww, uint32_t *cc);
21uint32_t c_pad8(uint32_t n);
22uint32_t c_segb(uint32_t i, uint32_t cnt, uint32_t n, uint32_t en, uint32_t mu);
23int c_segend(uint32_t i, uint32_t cnt, uint32_t n, uint32_t en, uint32_t pv);
24int c_finite(uint32_t bits);
25uint64_t c_pkbytes(uint32_t e, uint32_t k);
26int c_alignok(uint32_t lo, uint32_t mask);
27int c_tile8(uint32_t c0);
28uint32_t c_perm4(uint32_t q);
29uint32_t c_pfbm(uint32_t rt);
30uint32_t c_swsrc(uint32_t p, uint32_t n);
31int c_maxmnk(uint32_t m, uint32_t k, uint32_t n);
32int c_dcache(uint32_t layers, uint32_t mx, uint32_t rot);
33int c_dreg(uint32_t decl);
34int c_tpack(uint32_t n, uint32_t k, uint32_t lay, uint32_t R, uint32_t np);
35uint32_t c_rrows(uint32_t s);
36uint32_t c_rtdst(uint32_t g, uint32_t ex, uint32_t q, uint32_t e);
37uint32_t c_rtsrc(uint32_t ex, uint32_t k, uint32_t g, uint32_t q);
38void c_dsplit(uint32_t pos, uint32_t per, uint32_t mx, uint32_t *code, uint32_t *splits);
39int c_vy2(uint32_t v);
40int c_thok(uint32_t lo, uint32_t hi);
41void c_tcsp(uint32_t rt, uint32_t ct, uint32_t n, uint32_t *r, uint32_t *c);
42uint32_t c_tcw(uint32_t w);
43uint32_t c_rup(uint32_t v, uint32_t q);
44uint64_t c_woff(uint32_t kp, uint32_t col0);
45int c_wok(uint32_t c0, uint32_t cols, uint32_t n);
46uint32_t c_qgrp(uint32_t kb);
47uint32_t c_refb(uint8_t b);
48uint32_t c_kbits(uint8_t b);
49int c_isnanb(uint8_t b);
50int c_scalef(uint16_t bf16, int mutant, uint32_t *out);
51uint32_t c_xfold(uint32_t bits);
52uint32_t c_xfold16(uint16_t bf16);
53int32_t c_slot(uint64_t op, uint64_t aux, uint64_t rec[16]);
54uint64_t c_trit(const uint8_t v[16]);
55uint64_t c_block(const uint8_t w[128], const uint8_t x[512], uint32_t sc);
56uint32_t c_qrt(uint32_t rt);
57uint32_t c_qwait(uint32_t set, uint32_t w);
58float omega_bf16_to_fp32(uint16_t b) {
59 uint32_t val = (uint32_t)b << 16;
60 float f;
61 memcpy(&f, &val, 4);
62 return f;
63}
64
65int c_le128(uint32_t decl);
66int c_roomok(uint32_t n, uint32_t pos, uint32_t mx);
67int c_pa256b(uint32_t m, uint32_t pos, uint32_t mx);
68int c_qydiv(uint32_t qh, uint32_t pc, uint32_t *q);
69uint64_t c_qfbyt(uint32_t rows, uint32_t qh);
70uint32_t c_gxatt(uint32_t m);
71uint32_t c_kvsb(uint32_t mx);
72uint64_t c_hostb(uint32_t n, uint32_t w);
73int c_vy16(uint32_t v);
74uint32_t c_splt(uint32_t mx);
75uint64_t c_plane(uint32_t kvh, uint32_t mx);
76int c_persok(uint32_t p);
77int c_stride(uint32_t need, uint32_t got, uint32_t mask);
78uint64_t c_mtgrp(uint32_t left, uint32_t p0, uint32_t t0, uint32_t vy);
79int c_mtbig(uint32_t n, uint32_t vy, uint32_t sm);
80uint32_t c_smaxp(uint32_t pos, uint32_t n);
81uint64_t c_mtps(uint32_t vy, uint32_t sm);
82int c_p2bad(uint32_t v);
83uint32_t c_nkbad(uint32_t n, uint32_t k);
84int c_layok(uint32_t lay, uint32_t R);
85int c_tritok(uint32_t v);
86uint32_t c_qset(uint32_t k);
87int c_pfargs(uint32_t n, uint32_t k, uint32_t lay);
88
89static int fails;
90static uint64_t checks;
91
92static void bad(const char *what, uint64_t a, uint64_t b) {
93 if (fails < 12) fprintf(stderr, "MISMATCH %s omega=%llu c=%llu\n", what,
94 (unsigned long long)a, (unsigned long long)b);
95 fails++;
96}
97static void eq_u32(const char *what, uint32_t o, uint32_t c) {
98 checks++;
99 if (o != c) bad(what, o, c);
100}
101static void eq_i(const char *what, int o, int c) {
102 checks++;
103 if (o != c) bad(what, (uint64_t)(int64_t)o, (uint64_t)(int64_t)c);
104}
105static void eq_u64(const char *what, uint64_t o, uint64_t c) {
106 checks++;
107 if (o != c) bad(what, o, c);
108}
109
110static const uint32_t B[] = {
111 0, 1, 2, 3, 4, 7, 8, 15, 16, 31, 32, 45, 63, 64, 127, 128, 129, 255, 256,
112 511, 512, 1023, 1024, 2048, 4095, 4096, 8191, 8192, 16384, 32768, 65535, 65536,
113 131072, 262144, 1048576, 16777215, 0x7fffffffu, 0xffffffffu
114};
115enum { NB = sizeof B / sizeof B[0] };
116
117static uint32_t xs = 0xA11E5001u;
118static uint32_t rnd(void) {
119 xs ^= xs << 13;
120 xs ^= xs >> 17;
121 xs ^= xs << 5;
122 return xs;
123}
124static uint32_t pick(void) {
125 uint32_t r = rnd();
126 if ((r & 7u) == 0) return B[r % NB];
127 return r;
128}
129
130static void check_pack_bytes(void) {
131 uint8_t w[256], xraw[512], v[16];
132 float out_o[8], out_c[8], xf[32], yo[32], yc[32];
133 uint16_t sc[8];
134 for (int i = 0; i < 256; i++) w[i] = (uint8_t)i;
135 for (int i = 0; i < 512; i++) xraw[i] = (uint8_t)(i * 17);
136 for (int i = 0; i < 16; i++) v[i] = (uint8_t)(i * 3 + 1);
137 eq_u64("trit", omega_api_trit(v), c_trit(v));
138 eq_u64("block", omega_api_block(w, xraw, 0x3f80), c_block(w, xraw, 0x3f80));
139 eq_u64("block0", omega_api_block(w, xraw, 0), c_block(w, xraw, 0));
140 for (int b = 0; b < 256; b++) {
141 eq_u32("refb", omega_api_refb((uint8_t)b), c_refb((uint8_t)b));
142 eq_u32("kbits", omega_api_kbits((uint8_t)b), c_kbits((uint8_t)b));
143 eq_i("isnan", omega_api_isnanb((uint8_t)b), c_isnanb((uint8_t)b));
144 eq_u32("e4ref", omega_fp8_e4m3_kernel_bits((uint8_t)b), c_kbits((uint8_t)b));
145 eq_i("e4nan", omega_fp8_e4m3_is_nan((uint8_t)b), c_isnanb((uint8_t)b));
146 }
147 size_t first = 99;
148 size_t n = omega_fp8_pack_scan_nan(w, 256, &first);
149 checks++;
150 if (n != 2 || first != 127) bad("scan", n, first);
151 for (uint32_t bf = 0; bf < 65536u; bf++) {
152 uint32_t ob = 1, cb = 2;
153 int oc = omega_api_scalef((uint16_t)bf, 0, &ob);
154 int cc = c_scalef((uint16_t)bf, 0, &cb);
155 eq_i("scalef", oc, cc);
156 if (oc == 0) eq_u32("scalebits", ob, cb);
157 ob = 1; cb = 2;
158 oc = omega_api_scalef((uint16_t)bf, 1, &ob);
159 cc = c_scalef((uint16_t)bf, 1, &cb);
160 eq_i("scalefm", oc, cc);
161 if (oc == 0) eq_u32("scalebitsm", ob, cb);
162 eq_u32("x16", omega_api_xfold16((uint16_t)bf), c_xfold16((uint16_t)bf));
163 }
164 sc[0] = 0x3f80; sc[1] = 0x4000; sc[2] = 0x7f80; sc[3] = 0;
165 int pr = omega_fp8_pack_scales(sc, 4, out_o, 0);
166 checks++;
167 if (pr != -1) bad("packscale-refuse", (uint64_t)pr, 1);
168 sc[2] = 0x3f00;
169 pr = omega_fp8_pack_scales(sc, 4, out_o, 0);
170 eq_i("packscale", pr, 0);
171 for (int i = 0; i < 4; i++) {
172 uint32_t bits = 0, cb = 0;
173 c_scalef(sc[i], 0, &cb);
174 memcpy(&bits, &out_o[i], 4);
175 eq_u32("packscale-byte", bits, cb);
176 }
177 for (uint32_t i = 0; i < 32; i++) xf[i] = (float)(i + 1);
178 omega_fp8_pack_x_f32(xf, 32, yo);
179 for (uint32_t i = 0; i < 32; i++) {
180 uint32_t bits, inb, cb;
181 memcpy(&inb, &xf[i], 4);
182 cb = c_xfold(inb);
183 memcpy(&bits, &yo[i], 4);
184 eq_u32("xf32", bits, cb);
185 }
186 uint16_t xb[32];
187 for (uint32_t i = 0; i < 32; i++) xb[i] = (uint16_t)(0x3f80 + i);
188 omega_fp8_pack_x_bf16(xb, 32, yc);
189 for (uint32_t i = 0; i < 32; i++) {
190 uint32_t bits;
191 memcpy(&bits, &yc[i], 4);
192 eq_u32("xbf16", bits, c_xfold16(xb[i]));
193 }
194 /* bit patterns around the subnormal fold and the NaN boundary */
195 uint32_t edge[] = {0, 1, 0x7f, 0x80, 0xff, 0x100, 0x7fffff, 0x800000, 0xffffff,
196 0x7f7fffff, 0x7f800000, 0x80000000u, 0xff800000u, 0xffffffffu};
197 for (unsigned i = 0; i < sizeof edge / sizeof edge[0]; i++)
198 eq_u32("xfold-e", omega_api_xfold(edge[i]), c_xfold(edge[i]));
199}
200
201static void check_shapes(void) {
202 for (unsigned i = 0; i < NB; i++) {
203 uint32_t a = B[i];
204 eq_u32("lane", omega_api_lane(a), c_lane(a));
205 eq_u32("pad8", omega_api_pad8(a), c_pad8(a));
206 eq_u32("perm4", omega_api_perm4(a), c_perm4(a));
207 eq_u32("pfbm", omega_api_pfbm(a), c_pfbm(a));
208 eq_i("finite", omega_api_finite(a), c_finite(a));
209 eq_i("tile8", omega_api_tile8(a), c_tile8(a));
210 eq_i("dreg", omega_api_dreg(a), c_dreg(a));
211 eq_u32("rrows", omega_api_rrows(a), c_rrows(a));
212 eq_i("vy2", omega_api_vy2(a), c_vy2(a));
213 eq_u32("tcw", omega_api_tcw(a), c_tcw(a));
214 eq_u32("qrt", omega_api_qrt(a), c_qrt(a));
215 eq_i("le128", omega_api_le128(a), c_le128(a));
216 eq_u32("qgrp", omega_api_qgrp(a), c_qgrp(a));
217 for (unsigned j = 0; j < NB; j++) {
218 uint32_t b = B[j];
219 uint32_t om = 0, ow = 0, cm = 0, cw = 0;
220 omega_api_fp8_defaults(a, b, &om, &ow);
221 c_fp8def(a, b, &cm, &cw);
222 eq_u32("fp8m", om, cm);
223 eq_u32("fp8w", ow, cw);
224 eq_u32("fp8mt", omega_api_fp8mt(a, b), c_fp8mt(a, b));
225 eq_u32("ctabud", omega_api_ctabud(a, b), c_ctabud(a, b));
226 eq_i("regfit", omega_api_regfit(a, b), c_regfit(a, b));
227 eq_i("align", omega_api_alignok(a, b), c_alignok(a, b));
228 eq_u64("pk", omega_api_pkbytes(a, b), c_pkbytes(a, b));
229 eq_u32("swsrc", omega_api_swsrc(a, b), c_swsrc(a, b));
230 eq_i("thok", omega_api_thok(a, b), c_thok(a, b));
231 eq_u32("rup", omega_api_rup(a, b), c_rup(a, b));
232 eq_u64("woff", omega_api_woff(a, b), c_woff(a, b));
233 eq_u32("qwait", omega_api_qwait(a, b), c_qwait(a, b));
234 uint32_t orows = 9, oc = 9, crows = 8, cc = 8;
235 omega_api_ternwc(a, b, &orows, &oc);
236 c_ternwc(a, b, &crows, &cc);
237 eq_u32("ternw", orows, crows);
238 eq_u32("ternc", oc, cc);
239 }
240 }
241 /* exhaustive small domains */
242 for (uint32_t k = 0; k <= 256; k++) eq_u32("lane-x", omega_api_lane(k), c_lane(k));
243 for (uint32_t q = 0; q < 16; q++) eq_u32("perm-x", omega_api_perm4(q), c_perm4(q));
244 for (uint32_t n = 0; n <= 64; n++) eq_u32("pad-x", omega_api_pad8(n), c_pad8(n));
245 for (uint32_t g = 1; g <= 32; g++) eq_u32("qgrp-x", omega_api_qgrp(g * 3), c_qgrp(g * 3));
246 eq_u32("qgrp0", omega_api_qgrp(0), c_qgrp(0));
247 eq_u32("qgrp1", omega_api_qgrp(1), c_qgrp(1));
248 eq_u32("qgrp32", omega_api_qgrp(32), c_qgrp(32));
249}
250
251static void check_multi(void) {
252 for (unsigned i = 0; i < NB; i++) {
253 for (unsigned j = 0; j < 16; j++) {
254 uint32_t a = B[i], b = B[j % NB], c = B[(i + j) % NB];
255 uint32_t d = B[(i * 3 + j) % NB], e = B[(j * 5) % NB];
256 eq_u32("tgbm", omega_api_tgbm(a, b, c), c_tgbm(a, b, c));
257 uint32_t or = 1, ow = 1, cr = 2, cw = 2;
258 omega_api_tgspec(a, b, c, &or, &ow);
259 c_tgspec(a, b, c, &cr, &cw);
260 eq_u32("tgspecr", or, cr);
261 eq_u32("tgspecw", ow, cw);
262 eq_u32("tgsz", omega_api_tgsz(a, b, c), c_tgsz(a, b, c));
263 uint32_t od = 3, orows = 3, cd = 4, crows = 4;
264 omega_api_ternd(a, b & 1u, c & 7u, d & 15u, e & 31u, &orows, &od);
265 c_ternd(a, b & 1u, c & 7u, d & 15u, e & 31u, &crows, &cd);
266 eq_u32("terndr", orows, crows);
267 eq_u32("terndd", od, cd);
268 eq_u32("segb", omega_api_segb(a, b, c, d, e), c_segb(a, b, c, d, e));
269 eq_i("segend", omega_api_segend(a, b, c, d, e), c_segend(a, b, c, d, e));
270 eq_i("maxmnk", omega_api_maxmnk(a, b, c), c_maxmnk(a, b, c));
271 eq_i("dcache", omega_api_dcache(a, b, c), c_dcache(a, b, c));
272 eq_i("tpack", omega_api_tpack(a, b, c & 1u, d, e), c_tpack(a, b, c & 1u, d, e));
273 eq_u32("rtdst", omega_api_rtdst(a, b, c, d), c_rtdst(a, b, c, d));
274 eq_u32("rtsrc", omega_api_rtsrc(a, b, c, d), c_rtsrc(a, b, c, d));
275 uint32_t ocode = 9, ospl = 9, ccode = 8, cspl = 9;
276 omega_api_dsplit(a, b, c, &ocode, &ospl);
277 c_dsplit(a, b, c, &ccode, &cspl);
278 eq_u32("dsplitc", ocode, ccode);
279 eq_u32("dsplits", ospl, cspl);
280 uint32_t otr = 1, otc = 1, ctr = 2, ctc = 2;
281 omega_api_tcsp(a, b, c, &otr, &otc);
282 c_tcsp(a, b, c, &ctr, &ctc);
283 eq_u32("tcspr", otr, ctr);
284 eq_u32("tcspc", otc, ctc);
285 eq_i("wok", omega_api_wok(a, b, c), c_wok(a, b, c));
286 }
287 }
288}
289
290static void check_random(void) {
291 for (int n = 0; n < 10000; n++) {
292 uint32_t a = pick(), b = pick(), c = pick(), d = pick(), e = pick();
293 eq_u32("r-lane", omega_api_lane(a), c_lane(a));
294 eq_u32("r-tgbm", omega_api_tgbm(a, b, c), c_tgbm(a, b, c));
295 eq_u32("r-segb", omega_api_segb(a % 8u, (b % 5u) + 1u, c ? c : 1u, d, e),
296 c_segb(a % 8u, (b % 5u) + 1u, c ? c : 1u, d, e));
297 eq_i("r-segend", omega_api_segend(a % 8u, (b % 5u) + 1u, c ? c : 1u, d, e & 1u),
298 c_segend(a % 8u, (b % 5u) + 1u, c ? c : 1u, d, e & 1u));
299 eq_i("r-align", omega_api_alignok(a, b | 1u), c_alignok(a, b | 1u));
300 eq_u64("r-pk", omega_api_pkbytes(a % 64u, b), c_pkbytes(a % 64u, b));
301 eq_i("r-max", omega_api_maxmnk(a, b, c), c_maxmnk(a, b, c));
302 eq_i("r-tpack", omega_api_tpack(a, b, c & 1u, d % 8u, e), c_tpack(a, b, c & 1u, d % 8u, e));
303 eq_u32("r-rtdst", omega_api_rtdst(a % 16u, b, c % 8u, d % 8u), c_rtdst(a % 16u, b, c % 8u, d % 8u));
304 eq_u32("r-rtsrc", omega_api_rtsrc(a, b, c % 16u, d % 8u), c_rtsrc(a, b, c % 16u, d % 8u));
305 uint32_t oc = 1, os = 1, cc = 2, cs = 1;
306 omega_api_dsplit(a, b % 64u, c % 128u, &oc, &os);
307 c_dsplit(a, b % 64u, c % 128u, &cc, &cs);
308 eq_u32("r-dsc", oc, cc);
309 eq_u32("r-dss", os, cs);
310 eq_u64("r-woff", omega_api_woff(a % 4096u, b), c_woff(a % 4096u, b));
311 eq_i("r-wok", omega_api_wok(a, b, c ? c : 1u), c_wok(a, b, c ? c : 1u));
312 eq_u32("r-rup", omega_api_rup(a, b % 64u), c_rup(a, b % 64u));
313 eq_i("r-finite", omega_api_finite(a), c_finite(a));
314 eq_u32("r-xfold", omega_api_xfold(a), c_xfold(a));
315 uint32_t ob = 0, cb = 1;
316 int so = omega_api_scalef((uint16_t)(a & 65535u), (int)(b & 1u), &ob);
317 int sc = c_scalef((uint16_t)(a & 65535u), (int)(b & 1u), &cb);
318 eq_i("r-sc", so, sc);
319 if (so == 0) eq_u32("r-scb", ob, cb);
320 }
321}
322
323static void shadow_step(uint64_t rec[16], uint64_t op, uint64_t aux, int32_t *rc) {
324 *rc = c_slot(op, aux, rec);
325}
326
327static void check_slots(void) {
328 uint64_t rec[16];
329 memset(rec, 0, sizeof rec);
330 int32_t cr, orc;
331 /* direct opcode differential over the legal transitions */
332 struct { uint64_t op, aux; } seq[] = {
333 {1, 0}, {1, 0}, {2, 0}, {1, 0}, {3, 0x11}, {4, 0}, {4, 0}, {5, 0}, {5, 0},
334 {7, 0}, {6, 0}, {3, 1}, {8, 0}
335 };
336 for (unsigned i = 0; i < sizeof seq / sizeof seq[0]; i++) {
337 uint64_t copy[16];
338 memcpy(copy, rec, sizeof rec);
339 orc = omega_api_slot(seq[i].op, seq[i].aux, rec);
340 cr = c_slot(seq[i].op, seq[i].aux, copy);
341 eq_i("slot-rc", orc, cr);
342 for (int k = 0; k < 16; k++) eq_u64("slot-rec", rec[k], copy[k]);
343 }
344 /* bad op and short record are refusals; a null record must not be passed */
345 uint64_t junk[16];
346 memset(junk, 0, sizeof junk);
347 eq_i("slot-badop", omega_api_slot(9, 0, junk), c_slot(9, 0, junk));
348 eq_i("slot-stale-gate", omega_api_slot(7, 0, junk), -7);
349
350 OmegaFp8SlotTable table;
351 if (omega_fp8_slot_table_init(&table, 2) != 0) {
352 bad("slot-init", 1, 0);
353 return;
354 }
355 uint64_t ver = 0;
356 int tr = omega_fp8_slot_begin_load(&table, 0);
357 eq_i("tbl-begin", tr, 0);
358 tr = omega_fp8_slot_begin_load(&table, 0);
359 eq_i("tbl-busy", tr, OMEGA_FP8_SLOT_BUSY);
360 tr = omega_fp8_slot_finish_load(&table, 0, 42, 1, &ver);
361 eq_i("tbl-fin", tr, 0);
362 checks++;
363 if (ver == 0) bad("tbl-ver", ver, 1);
364 tr = omega_fp8_slot_pin(&table, 0, ver);
365 eq_i("tbl-pin", tr, 0);
366 tr = omega_fp8_slot_pin(&table, 0, ver + 1);
367 eq_i("tbl-pin-stale", tr, OMEGA_FP8_SLOT_STALE);
368 tr = omega_fp8_slot_evict(&table, 0);
369 eq_i("tbl-evict-busy", tr, OMEGA_FP8_SLOT_BUSY);
370 tr = omega_fp8_slot_unpin(&table, 0, ver);
371 eq_i("tbl-unpin", tr, 0);
372 tr = omega_fp8_slot_unpin(&table, 0, ver);
373 eq_i("tbl-unpin-bad", tr, OMEGA_FP8_SLOT_BAD_ARGS);
374 tr = omega_fp8_slot_evict(&table, 0);
375 eq_i("tbl-evict", tr, 0);
376 tr = omega_fp8_slot_evict(&table, 0);
377 eq_i("tbl-evict-stale", tr, 0);
378 eq_i("tbl-idle", omega_fp8_slot_table_idle(&table), 1);
379 omega_fp8_slot_table_set_mutant(&table, 1);
380 tr = omega_fp8_slot_begin_load(&table, 1);
381 eq_i("tbl-mbegin", tr, 0);
382 tr = omega_fp8_slot_pin(&table, 1, 0);
383 eq_i("tbl-mpin", tr, OMEGA_FP8_SLOT_STALE);
384 omega_fp8_slot_table_fini(&table);
385}
386
387static void check_negative(void) {
388 uint32_t o = omega_api_lane(256);
389 uint32_t flipped = o ^ 8u;
390 checks++;
391 if (flipped == c_lane(256)) bad("neg-control", flipped, c_lane(256));
392 uint64_t rec[16];
393 memset(rec, 0, sizeof rec);
394 rec[0] = 2; rec[1] = 1; rec[3] = 1;
395 int32_t rc = omega_api_slot(7, 0, rec);
396 checks++;
397 if (rc != -7) bad("neg-slot", (uint64_t)(int64_t)rc, 7);
398 rec[1] ^= 1u;
399 int32_t rc2 = omega_api_slot(7, 0, rec);
400 checks++;
401 if (rc2 == rc && rec[1] == 1) bad("neg-flip", rc2, rc);
402}
403
404static void check_attn(void) {
405 uint32_t bounds[] = {0, 1, 2, 7, 8, 15, 16, 17, 127, 128, 255, 256, 257, 32767, 32768, 32769, 65535, 65536, 131072};
406 unsigned nb = sizeof bounds / sizeof bounds[0];
407 for (unsigned i = 0; i < nb; i++) {
408 uint32_t a = bounds[i];
409 eq_u32("gxatt", omega_api_gxatt(a), c_gxatt(a));
410 eq_u32("kvsb", omega_api_kvsb(a), c_kvsb(a));
411 eq_i("vy16", omega_api_vy16(a), c_vy16(a));
412 eq_u32("splt", omega_api_splt(a), c_splt(a));
413 eq_i("persok", omega_api_persok(a), c_persok(a));
414 eq_i("p2bad", omega_api_p2bad(a), c_p2bad(a));
415 for (unsigned j = 0; j < nb; j++) {
416 uint32_t b = bounds[j];
417 uint32_t oq = 9, cq = 8;
418 eq_i("qydiv", omega_api_qydiv(a, b, &oq), c_qydiv(a, b, &cq));
419 if (b) eq_u32("qydivq", oq, cq);
420 eq_u64("qfbyt", omega_api_qfbyt(a, b), c_qfbyt(a, b));
421 eq_u64("hostb", omega_api_hostb(a, b), c_hostb(a, b));
422 eq_u64("plane", omega_api_plane(a, b), c_plane(a, b));
423 eq_u32("smaxp", omega_api_smaxp(a, b), c_smaxp(a, b));
424 eq_u64("mtps", omega_api_mtps(a, b), c_mtps(a, b));
425 for (unsigned k = 0; k < nb; k++) {
426 uint32_t c = bounds[k];
427 eq_i("roomok", omega_api_roomok(a, b, c), c_roomok(a, b, c));
428 eq_i("pa256b", omega_api_pa256b(a, b, c), c_pa256b(a, b, c));
429 eq_i("stride", omega_api_stride(a, b, c), c_stride(a, b, c));
430 eq_i("mtbig", omega_api_mtbig(a, b, c), c_mtbig(a, b, c));
431 eq_u64("mtgrp", omega_api_mtgrp(a, b, c, bounds[k % 8]), c_mtgrp(a, b, c, bounds[k % 8]));
432 }
433 }
434 }
435 for (uint32_t n = 0; n < 10000u; n++) {
436 uint32_t a = pick(), b = pick(), c = pick(), d = pick() & 31u;
437 uint32_t oq = 1, cq = 2;
438 eq_i("room-r", omega_api_roomok(a, b, c), c_roomok(a, b, c));
439 eq_i("pa-r", omega_api_pa256b(a & 65535u, b, c), c_pa256b(a & 65535u, b, c));
440 eq_i("qy-r", omega_api_qydiv(a, b, &oq), c_qydiv(a, b, &cq));
441 if (b) eq_u32("qyq-r", oq, cq);
442 eq_u64("qf-r", omega_api_qfbyt(a, b), c_qfbyt(a, b));
443 eq_u32("gx-r", omega_api_gxatt(a), c_gxatt(a));
444 eq_u64("host-r", omega_api_hostb(a, b), c_hostb(a, b));
445 eq_i("vy-r", omega_api_vy16(a), c_vy16(a));
446 eq_u64("plane-r", omega_api_plane(a & 63u, b), c_plane(a & 63u, b));
447 eq_i("p2-r", omega_api_p2bad(a), c_p2bad(a));
448 eq_i("st-r", omega_api_stride(a, b, c), c_stride(a, b, c));
449 eq_u64("grp-r", omega_api_mtgrp(a & 255u, b, c, d), c_mtgrp(a & 255u, b, c, d));
450 eq_i("big-r", omega_api_mtbig(a & 255u, d, b), c_mtbig(a & 255u, d, b));
451 }
452}
453
454static void check_upload(void) {
455 uint32_t ns[] = {0, 1, 255, 256, 512, 8192, 8193, 16384, 16385, 1073741824u, 1073741825u};
456 uint32_t ks[] = {0, 1, 255, 256, 512, 768, 8192, 8448, 8704, 16384, 16640};
457 uint32_t lays[] = {0, 1, 2, 3};
458 uint32_t rs[] = {0, 1, 2, 3, 4, 5};
459 unsigned nn = sizeof ns / sizeof ns[0], nk = sizeof ks / sizeof ks[0];
460 for (unsigned i = 0; i < nn; i++) {
461 for (unsigned j = 0; j < nk; j++) {
462 eq_u32("nkbad", omega_api_nkbad(ns[i], ks[j]), c_nkbad(ns[i], ks[j]));
463 eq_u32("qset", omega_api_qset(ks[j]), c_qset(ks[j]));
464 for (unsigned L = 0; L < 4; L++)
465 eq_i("pfargs", omega_api_pfargs(ns[i], ks[j], lays[L]), c_pfargs(ns[i], ks[j], lays[L]));
466 }
467 }
468 for (unsigned L = 0; L < 4; L++)
469 for (unsigned r = 0; r < 6; r++)
470 eq_i("layok", omega_api_layok(lays[L], rs[r]), c_layok(lays[L], rs[r]));
471 for (uint32_t v = 0; v < 256u; v++)
472 eq_i("tritok", omega_api_tritok(v), c_tritok(v));
473 for (uint32_t n = 0; n < 10000u; n++) {
474 uint32_t a = pick(), b = pick(), c = pick() & 3u, d = pick() & 7u;
475 eq_u32("nk-r", omega_api_nkbad(a, b), c_nkbad(a, b));
476 eq_i("lay-r", omega_api_layok(c, d), c_layok(c, d));
477 eq_i("trit-r", omega_api_tritok(a & 255u), c_tritok(a & 255u));
478 eq_u32("qset-r", omega_api_qset(a), c_qset(a));
479 eq_i("pf-r", omega_api_pfargs(a, b, c), c_pfargs(a, b, c));
480 }
481}
482
483int main(void) {
484 check_upload();
485 check_pack_bytes();
486 check_shapes();
487 check_attn();
488 check_multi();
489 check_random();
490 check_slots();
491 check_negative();
492 if (fails) {
493 fprintf(stderr, "FAIL api-shells checks=%llu fails=%d\n",
494 (unsigned long long)checks, fails);
495 return 1;
496 }
497 printf("PASS api-shells checks=%llu\n", (unsigned long long)checks);
498 return 0;
499}