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 / om / encoder / guard_pred_test.om

444 lines · 8475 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note guard_pred_test.om: gate for the guard predicate of every sm_121 op in the seeded encoder (DRA-483, C1b).
3note Concatenate after bw_enc_sm121.om; mk/om-encoder.mk test-om-encoder-guard compiles it with the pinned omc.
4note Input word 7 bit 1 (predicate_p0) and bit 2 (predicate_not) ask for @P0 / @!P0; the guard is w0 bits 12..15:
5note 7 always (PT), 0 @P0, 8 @!P0. Every emitting op 0..79 (BW_IR_LAST) is encoded three times with R4 <- R8, R12,
6note R16, UR4 (imm 2 for BRA and BSSY, else 0): unpredicated, @P0 and @!P0. The @P0 / @!P0 words must carry guard
7note 0 / 8 and equal the unpredicated words in every other bit. DSETP (op 72) has no GPR destination, so that row
8note clears the destination-present flag. LDCU and LDCU.64 (ops 6, 7) are uniform-datapath instructions: their
9note guard bits name UP0..UPT, so @P0 cannot be encoded there and both forms must be refused.
10note Program rows: the omega-mv #1044 seed/oscgpu bool and trap shapes (gpuir.om bw_bool, bw_trap; the C twin is
11note src/omega_osc_gpu.c Bool, Trap) go through the program entry bw_enc_sm121 with word 7 as the C packer writes
12note it: MOV R4, 0 / @P0 MOV R4, 1 / @!P0 STG.E desc[UR4][R8.64], R12 / @!P0 MOV R5, 1 / @!P0 MOV R4, 0. Their
13note guards must be 7, 0, 8, 8, 8.
14note No arguments: print one line per failing form (op, form 1 @P0 / 2 @!P0, guard read; 99 refused, 98 accepted
15note but must refuse, 97 another bit changed; program rows as op 100 + row), then the failure count; exit 0 when
16note none, else 1.
17note One argument: write 165 instructions (2640 bytes) on stdout for the ORACLE: the @P0 and @!P0 forms of the 78
18note P-guarded ops in op order, then the unpredicated LDCU and LDCU.64 words with their guard bits set to 0 and 8
19note (an oracle probe, not encoder output), then the five program rows.
20note Two arguments: read the ORACLE's text on stdin; instruction k must start with @P0 / @!P0 (k < 156, even / odd),
21note then @UP0 / @!UP0 (156..159), then no guard, @P0, @!P0, @!P0, @!P0 (160..164). Exit 0, 4 when a guard or the
22note instruction count is wrong, 70 read error, 71 text too long.
23note ORACLE (independent, not first-party, never shipped): NVIDIA nvdisasm 13.0.85 -b SM121 -hex.
24note Constants: 61440 = 0xf000 (guard mask). 78 = 80 - 2 uniform ops. 156 = 78 * 2. 160 = 156 + 4. 165 = 160 + 5.
25note 2640 = 165 * 16.
26text gptok "@P0 @!P0 @UP0 @!UP0 "
27text gpm1 "FAIL op "
28text gpm2 " form "
29text gpm3 " guard "
30text gpm4 "guard predicate failures: "
31text gpm5 "oracle instructions: "
32text gpm6 " guard mismatches: "
33text gpnl "\n"
34global gpbuf uchar 65536
35const GPNONE ulong 18446744073709551615
36
37note uniform-datapath ops: the guard bits name a uniform predicate
38fn gp_uni op ulong to bool
39ret or eq op 6 eq op 7
40end
41
42note encode op with form f (0 none, 1 @P0, 2 @!P0) into w; enc1's result (0 accepted)
43fn gp_enc op ulong f ulong w edit ulong 4 to ulong
44o = new ulong 16 0
45put o 0 op
46put o 1 4
47put o 2 8
48put o 3 12
49put o 4 16
50put o 5 4
51if or eq op 46 eq op 54
52put o 6 2
53end
54put o 12 1
55put o 13 1
56put o 14 1
57put o 15 1
58if eq op 72
59put o 15 0
60end
61if ne f 0
62put o 9 1
63end
64if eq f 2
65put o 10 1
66end
67ret enc1 view o w
68end
69
70fn gp_dec x ulong to void
71b = new uchar 20 0
72i = ulong 20
73v = x
74c = true
75while c bound 20
76i = sub i 1
77put b i uchar add 48 rem v 10
78v = div v 10
79if eq v 0
80c = false
81end
82end
83k = write 1 b i sub 20 i
84end
85
86fn gp_fail op ulong f ulong g ulong to void
87k = write 1 gpm1 0 len gpm1
88gp_dec op
89k = write 1 gpm2 0 len gpm2
90gp_dec f
91k = write 1 gpm3 0 len gpm3
92gp_dec g
93k = write 1 gpnl 0 1
94end
95
96note the guard field of w0
97fn gp_g w view ulong 4 to ulong
98ret and shr get w 0 12 15
99end
100
101note equal outside the guard field
102fn gp_same u view ulong 4 p view ulong 4 to bool
103if ne or get u 0 61440 or get p 0 61440
104ret false
105end
106for k ulong 3
107if ne get u add k 1 get p add k 1
108ret false
109end
110end
111ret true
112end
113
114note the failing forms of op (0..2)
115fn gp_row op ulong to ulong
116u = new ulong 4 0
117p = new ulong 4 0
118if ne gp_enc op 0 edit u 0
119gp_fail op 0 99
120ret 1
121end
122bad = ulong 0
123for f ulong 2
124fm = add f 1
125r = gp_enc op fm edit p
126if gp_uni op
127if eq r 0
128gp_fail op fm 98
129bad = add bad 1
130end
131else
132if ne r 0
133gp_fail op fm 99
134bad = add bad 1
135else
136g = gp_g view p
137if ne g mul f 8
138gp_fail op fm g
139bad = add bad 1
140else
141if not gp_same view u view p
142gp_fail op fm 97
143bad = add bad 1
144end
145end
146end
147end
148end
149ret bad
150end
151
152note program row r: op, dst, src1, src2, imm, word 7 (2 @P0, 6 @!P0), and the guard it must get
153fn gp_pop r ulong to ulong
154if eq r 2
155ret 12
156end
157ret 2
158end
159fn gp_pdst r ulong to ulong
160if eq r 2
161ret GPNONE
162end
163if eq r 3
164ret 5
165end
166ret 4
167end
168fn gp_pimm r ulong to ulong
169if or eq r 1 eq r 3
170ret 1
171end
172ret 0
173end
174fn gp_pfl r ulong to ulong
175if eq r 0
176ret 0
177end
178if eq r 1
179ret 2
180end
181ret 6
182end
183fn gp_pg r ulong to ulong
184if eq r 0
185ret 7
186end
187if eq r 1
188ret 0
189end
190ret 8
191end
192
193note the five #1044 rows through bw_enc_sm121 into code; the byte count (80 when accepted)
194fn gp_penc code edit uchar 16384 to ulong
195ins = new ulong 8192 0
196phys = new ulong 288 0
197for v ulong 256
198put phys v v
199end
200for u ulong 32
201put phys add 256 u u
202end
203for r ulong 5
204b = mul r 8
205put ins b gp_pop r
206put ins add b 1 gp_pdst r
207put ins add b 2 GPNONE
208put ins add b 3 GPNONE
209put ins add b 4 GPNONE
210put ins add b 5 GPNONE
211put ins add b 6 gp_pimm r
212put ins add b 7 gp_pfl r
213if eq r 2
214put ins add b 2 8
215put ins add b 3 12
216put ins add b 5 4
217end
218end
219ret bw_enc_sm121 view ins view phys 5 0 code
220end
221
222fn gp_prog to ulong
223code = new uchar 16384 0
224if ne gp_penc edit code 80
225gp_fail 100 0 99
226ret 1
227end
228bad = ulong 0
229for r ulong 5
230g = and shr get code add mul r 16 1 4 15
231if ne ulong g gp_pg r
232gp_fail add 100 r gp_pfl r ulong g
233bad = add bad 1
234end
235end
236ret bad
237end
238
239fn gp_rows to int
240bad = ulong 0
241for op ulong 80
242bad = add bad gp_row op
243end
244bad = add bad gp_prog
245k = write 1 gpm4 0 len gpm4
246gp_dec bad
247k = write 1 gpnl 0 1
248if ne bad 0
249ret 1
250end
251ret 0
252end
253
254fn gp_bin to int
255w = new ulong 4 0
256code = new uchar 16384 0
257pc = new uchar 16384 0
258i = ulong 0
259for op ulong 80
260if not gp_uni op
261for f ulong 2
262if ne gp_enc op add f 1 edit w 0
263ret int add 10 op
264end
265store edit code i view w
266i = add i 1
267end
268end
269end
270for op ulong 80
271if gp_uni op
272if ne gp_enc op 0 edit w 0
273ret int add 10 op
274end
275x = get w 0
276for f ulong 2
277put w 0 or sub x and x 61440 shl mul f 8 12
278store edit code i view w
279i = add i 1
280end
281end
282end
283if ne gp_penc edit pc 80
284ret 9
285end
286for q ulong 80
287put code add mul i 16 q get pc q
288end
289n = add mul i 16 80
290off = ulong 0
291while lt off n bound 4096
292k = write 1 code off sub n off
293if le k 0
294ret 3
295end
296off = add off ulong k
297end
298ret 0
299end
300
301fn gp_ts t ulong to ulong
302if eq t 0
303ret 0
304end
305if eq t 1
306ret 4
307end
308if eq t 2
309ret 9
310end
311ret 14
312end
313
314note does token t of gptok start at gpbuf[j]? Token 4 is no guard (the mnemonic is not an @ word).
315fn gp_tok j ulong n ulong t ulong to bool
316if eq t 4
317if ge j n
318ret false
319end
320ret ne get gpbuf j 64
321end
322s = gp_ts t
323e = gp_ts add t 1
324if eq t 3
325e = 20
326end
327if gt add j sub e s n
328ret false
329end
330for q ulong sub e s
331if ne get gpbuf add j q get gptok add s q
332ret false
333end
334end
335ret true
336end
337
338note an address marker "/*" then a hex digit at gpbuf[i]; the caller keeps i + 2 below n
339fn gp_mark i ulong to bool
340if ne get gpbuf i 47
341ret false
342end
343if ne get gpbuf add i 1 42
344ret false
345end
346c = get gpbuf add i 2
347if and ge c 48 le c 57
348ret true
349end
350ret and ge c 97 le c 102
351end
352
353note the index after the marker's "*/" and the blanks that follow
354fn gp_after i ulong n ulong to ulong
355j = add i 2
356while lt add j 1 n bound 65536
357if eq get gpbuf j 42
358if eq get gpbuf add j 1 47
359j = add j 2
360break
361end
362end
363j = add j 1
364end
365while lt j n bound 65536
366c = get gpbuf j
367if and ne c 32 ne c 9
368break
369end
370j = add j 1
371end
372ret j
373end
374
375note the token instruction k must carry
376fn gp_want k ulong to ulong
377if lt k 156
378ret rem k 2
379end
380if lt k 160
381ret add 2 rem k 2
382end
383if eq k 160
384ret 4
385end
386if eq k 161
387ret 0
388end
389ret 1
390end
391
392fn gp_check to int
393n = ulong 0
394while lt n 65536 bound 65536
395r = read 0 gpbuf n sub 65536 n
396if lt r 0
397ret 70
398end
399if eq r 0
400break
401end
402n = add n ulong r
403end
404if eq n 65536
405ret 71
406end
407k = ulong 0
408bad = ulong 0
409i = ulong 0
410while lt add i 2 n bound 65536
411if gp_mark i
412j = gp_after i n
413if not gp_tok j n gp_want k
414bad = add bad 1
415end
416k = add k 1
417i = j
418else
419i = add i 1
420end
421end
422w = write 1 gpm5 0 len gpm5
423gp_dec k
424w = write 1 gpm6 0 len gpm6
425gp_dec bad
426w = write 1 gpnl 0 1
427if or ne k 165 ne bad 0
428ret 4
429end
430ret 0
431end
432
433fn main to int
434if gt argcnt 3
435ret 64
436end
437if eq argcnt 3
438ret gp_check
439end
440if eq argcnt 2
441ret gp_bin
442end
443ret gp_rows
444end