interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / src / ufbi_check1_kernels.om

430 lines · 9106 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/ufbi_check1_kernels.om: Pure Seeded-OM-2 SM121 Direct SASS Emitter for Check #1
3note (4D Massive Free Scalar Masked Helmholtz Stencil, CTA Parallel Dot Product, AXPY, Mask-Copy).
4note Composed after om/encoder/bw_enc_sm121.om.
5note Honors all SM121 silicon laws (Antibodies #13-#15: 6-cycle ALU floor, BB leader pinning,
6note disjoint LDS/LDG address registers before qW0/qW1, zero B0 nesting).
7
8const UZ ulong 255
9global uPc ulong 1
10global uGuard ulong 1
11global uCodeBuf ulong 8192
12
13fn ucw st ulong wb ulong rbar ulong wt ulong yld ulong to ulong
14a = or shl st 9 shl yld 13
15b = or shl wb 14 shl rbar 17
16ret or or a b shl wt 20
17end
18
19fn uAlu4 to ulong
20ret ucw 6 7 7 0 0
21end
22fn uCmp to ulong
23ret ucw 14 7 7 0 0
24end
25fn uLd to ulong
26ret ucw 2 0 1 0 1
27end
28fn uSt to ulong
29ret ucw 4 7 1 0 1
30end
31fn uW0 to ulong
32ret ucw 6 7 7 1 0
33end
34fn uW1 to ulong
35ret ucw 6 7 7 2 0
36end
37fn uWall to ulong
38ret ucw 6 7 7 7 0
39end
40fn uShfl to ulong
41ret ucw 4 0 7 0 1
42end
43fn uSafe to ulong
44ret ucw 6 7 7 7 0
45end
46
47fn uEmitRaw o edit ulong 16 atPc ulong to void
48w = new ulong 4 0
49if ne get uGuard 0 0
50put o 9 1
51end
52if eq get uGuard 0 2
53put o 10 1
54end
55put uGuard 0 0
56if ne get o 2 UZ
57put o 12 1
58end
59if ne get o 3 UZ
60put o 13 1
61end
62if ne enc1 o w 0
63exit 3
64end
65base = mul atPc 4
66for i ulong 4
67put uCodeBuf add base i get w i
68end
69end
70
71fn uic op ulong dst ulong a ulong b ulong imm ulong ctrl ulong to void
72o = new ulong 16 0
73put o 0 op
74put o 1 dst
75put o 2 a
76put o 3 b
77put o 4 UZ
78put o 5 4
79put o 6 and imm 0xffffffff
80put o 7 ctrl
81pc = get uPc 0
82uEmitRaw o pc
83put uPc 0 add pc 1
84end
85
86fn uic4 op ulong dst ulong a ulong b ulong c ulong ctrl ulong to void
87o = new ulong 16 0
88put o 0 op
89put o 1 dst
90put o 2 a
91put o 3 b
92put o 4 c
93put o 5 4
94put o 6 0
95put o 7 ctrl
96pc = get uPc 0
97uEmitRaw o pc
98put uPc 0 add pc 1
99end
100
101fn uicImm op ulong dst ulong a ulong c ulong imm ulong ctrl ulong to void
102o = new ulong 16 0
103put o 0 op
104put o 1 dst
105put o 2 a
106put o 3 UZ
107put o 4 c
108put o 5 4
109put o 6 and imm 0xffffffff
110put o 7 ctrl
111pc = get uPc 0
112uEmitRaw o pc
113put uPc 0 add pc 1
114end
115
116fn uBraFwd gd ulong to ulong
117pos = get uPc 0
118put uGuard 0 gd
119uic 46 UZ UZ UZ 0 uAlu4
120ret pos
121end
122
123fn uPatch pos ulong gd ulong to void
124o = new ulong 16 0
125put o 0 46
126put o 1 UZ
127put o 2 UZ
128put o 3 UZ
129put o 4 UZ
130put o 5 4
131put o 6 and sub get uPc 0 pos 0xffffffff
132put o 7 uAlu4
133put uGuard 0 gd
134uEmitRaw o pos
135end
136
137fn uLit d ulong x ulong to void
138uic 2 d UZ UZ x uAlu4
139end
140
141fn uParam d ulong off ulong to void
142uic 4 d UZ UZ add 896 off ucw 4 0 7 0 1
143uic 0 UZ UZ UZ 0 uW0
144end
145
146fn uStart ptrs ulong to void
147uic 7 4 UZ UZ 856 ucw 4 2 7 0 1
148for i ulong ptrs bound 8
149uic 5 mul i 2 UZ UZ add 896 mul i 8 ucw 4 0 7 0 1
150end
151uic 3 14 UZ UZ 33 ucw 4 0 7 0 1
152uic 3 15 UZ UZ 37 ucw 4 0 7 0 1
153uic 0 UZ UZ UZ 0 uWall
154end
155
156fn uBar to void
157uic 0 UZ UZ UZ 0 uWall
158uic 48 UZ UZ UZ 0 uSafe
159end
160
161fn uWarpBflySum acc ulong tmp ulong to void
162d = ulong 16
163while ge d 1 bound 5
164uic 60 tmp acc UZ d uShfl
165uic 30 acc acc tmp 0 uW0
166d = shr d 1
167end
168end
169
170fn uDone to void
171uic 0 UZ UZ UZ 0 uWall
172uic 45 UZ UZ UZ 0 uSafe
173while or lt get uPc 0 32 ne rem get uPc 0 8 0 bound 2048
174uic 0 UZ UZ UZ 0 uSafe
175end
176w = new ulong 4 0
177n = get uPc 0
178for pc ulong n bound 2048
179base = mul pc 4
180for i ulong 4
181put w i get uCodeBuf add base i
182end
183uCodeWrite w
184end
185end
186
187note =========================================================================
188note Kernel 0: k_helm4d (Masked 4D 9-point Helmholtz Stencil)
189note Args:
190note ptr0 (R0:R1) = x (f32[N])
191note ptr1 (R2:R3) = y (f32[N])
192note ptr2 (R4:R5) = mask (f32[N], 0.0 on frozen/boundary, 1.0 on active interior)
193note off 24 = N
194note off 28 = L
195note off 32 = L2
196note off 36 = L3
197note off 40 = negL (0 - L as u32)
198note off 44 = negL2 (0 - L2 as u32)
199note off 48 = negL3 (0 - L3 as u32)
200note off 52 = diag_f32_bits (8.0 + ma^2)
201note =========================================================================
202fn uEmitHelm4d to bool
203uStart 3
204uParam 20 24
205uParam 21 28
206uParam 22 32
207uParam 23 36
208uParam 24 40
209uParam 25 44
210uParam 26 48
211uParam 27 52
212note gidx (R16) = CTAID.X (R15) * 256 + TID.X (R14)
213uicImm 8 16 15 14 256 uAlu4
214uic 28 UZ 16 20 0 uCmp
215bOob = uBraFwd 1
216
217note Load mask[gidx] into R17
218uicImm 9 28 16 4 4 uAlu4
219uic 11 17 28 UZ 0 uLd
220uic 0 UZ UZ UZ 0 uW0
221
222note Check mask != 0 (f32 0.0 is 0u32; 1.0 is 0x3f800000 >= 1)
223uLit 18 1
224uic 28 UZ 17 18 0 uCmp
225bZero = uBraFwd 2
226
227note Active strictly-interior site: load x[gidx] and 8 neighbors
228note Batch 1: x[gidx], x[gidx+1], x[gidx-1], x[gidx+L]
229uLit 19 0xffffffff
230uic 14 30 16 18 0 uAlu4
231uic 14 31 16 19 0 uAlu4
232uic 14 32 16 21 0 uAlu4
233uicImm 9 34 16 0 4 uAlu4
234uicImm 9 36 30 0 4 uAlu4
235uicImm 9 38 31 0 4 uAlu4
236uicImm 9 40 32 0 4 uAlu4
237uic 11 42 34 UZ 0 uLd
238uic 11 43 36 UZ 0 uLd
239uic 11 44 38 UZ 0 uLd
240uic 11 45 40 UZ 0 uLd
241uic 0 UZ UZ UZ 0 uW0
242uic 30 46 43 44 0 uAlu4
243uic 30 46 46 45 0 uAlu4
244
245note Batch 2: x[gidx-L], x[gidx+L2], x[gidx-L2], x[gidx+L3]
246uic 14 30 16 24 0 uAlu4
247uic 14 31 16 22 0 uAlu4
248uic 14 32 16 25 0 uAlu4
249uic 14 33 16 23 0 uAlu4
250uicImm 9 34 30 0 4 uAlu4
251uicImm 9 36 31 0 4 uAlu4
252uicImm 9 38 32 0 4 uAlu4
253uicImm 9 40 33 0 4 uAlu4
254uic 11 43 34 UZ 0 uLd
255uic 11 44 36 UZ 0 uLd
256uic 11 45 38 UZ 0 uLd
257uic 11 47 40 UZ 0 uLd
258uic 0 UZ UZ UZ 0 uW0
259uic 30 46 46 43 0 uAlu4
260uic 30 46 46 44 0 uAlu4
261uic 30 46 46 45 0 uAlu4
262uic 30 46 46 47 0 uAlu4
263
264note Batch 3: x[gidx-L3]
265uic 14 30 16 26 0 uAlu4
266uicImm 9 34 30 0 4 uAlu4
267uic 11 43 34 UZ 0 uLd
268uic 0 UZ UZ UZ 0 uW0
269uic 30 46 46 43 0 uAlu4
270
271note val = diag * x[gidx] - sum_neighbors
272uic 32 48 27 42 0 uAlu4
273uic 31 48 48 46 0 uAlu4
274
275note Store y[gidx] = val
276uicImm 9 34 16 2 4 uAlu4
277uic 12 UZ 34 48 0 uSt
278uic 0 UZ UZ UZ 0 uW1
279bDone = uBraFwd 0
280
281note Zero path: y[gidx] = 0.0
282uPatch bZero 2
283uic 1 48 UZ UZ 0 uAlu4
284uicImm 9 34 16 2 4 uAlu4
285uic 12 UZ 34 48 0 uSt
286uic 0 UZ UZ UZ 0 uW1
287
288uPatch bDone 0
289uPatch bOob 1
290ret true
291end
292
293note =========================================================================
294note Kernel 1: k_dot_cta (256-thread CTA parallel dot product -> part[ctaid])
295note Args:
296note ptr0 (R0:R1) = u (f32[N])
297note ptr1 (R2:R3) = v (f32[N])
298note ptr2 (R4:R5) = part (f32[grid_x])
299note off 24 = N
300note SMEM: 32 bytes (8 warp partial sums)
301note =========================================================================
302fn uEmitDotCta to bool
303uStart 3
304uParam 20 24
305note gidx (R16) = CTAID.X * 256 + TID.X
306uicImm 8 16 15 14 256 uAlu4
307uic 1 22 UZ UZ 0 uAlu4
308uic 28 UZ 16 20 0 uCmp
309bSkip = uBraFwd 1
310
311uicImm 9 24 16 0 4 uAlu4
312uicImm 9 26 16 2 4 uAlu4
313uic 11 28 24 UZ 0 uLd
314uic 11 29 26 UZ 0 uLd
315uic 0 UZ UZ UZ 0 uW0
316uic 32 22 28 29 0 uAlu4
317
318uPatch bSkip 1
319note All 256 threads in CTA participate in warp butterfly sum
320uWarpBflySum 22 23
321
322note lane = tid & 31 (R30), warp = tid >> 5 (R31), smem_off = warp << 2 (R32)
323uic 18 30 14 UZ 31 uAlu4
324uic 17 31 14 UZ 5 uAlu4
325uicImm 8 32 31 UZ 4 uAlu4
326uLit 33 1
327uic 28 UZ 30 33 0 uCmp
328bNotLane0 = uBraFwd 1
329uic 50 UZ 32 22 0 uSt
330uic 0 UZ UZ UZ 0 uW1
331uPatch bNotLane0 1
332
333uBar
334
335note Only tid == 0 sums the 8 warp slots in SMEM and writes part[ctaid]
336uic 28 UZ 14 33 0 uCmp
337bNotT0 = uBraFwd 1
338note Precompute 8 disjoint SMEM byte offsets 0..28 in R34..R41
339uLit 34 0
340uLit 35 4
341uLit 36 8
342uLit 37 12
343uLit 38 16
344uLit 39 20
345uLit 40 24
346uLit 41 28
347uic 49 42 34 UZ 0 uLd
348uic 49 43 35 UZ 0 uLd
349uic 49 44 36 UZ 0 uLd
350uic 49 45 37 UZ 0 uLd
351uic 0 UZ UZ UZ 0 uW0
352uic 30 42 42 43 0 uAlu4
353uic 30 44 44 45 0 uAlu4
354uic 30 42 42 44 0 uAlu4
355uic 49 46 38 UZ 0 uLd
356uic 49 47 39 UZ 0 uLd
357uic 49 48 40 UZ 0 uLd
358uic 49 49 41 UZ 0 uLd
359uic 0 UZ UZ UZ 0 uW0
360uic 30 46 46 47 0 uAlu4
361uic 30 48 48 49 0 uAlu4
362uic 30 46 46 48 0 uAlu4
363uic 30 42 42 46 0 uAlu4
364uicImm 9 50 15 4 4 uAlu4
365uic 12 UZ 50 42 0 uSt
366uic 0 UZ UZ UZ 0 uW1
367uPatch bNotT0 1
368ret true
369end
370
371note =========================================================================
372note Kernel 2: k_axpy (y[i] = a * x[i] + b * y[i])
373note Args:
374note ptr0 (R0:R1) = x (f32[N])
375note ptr1 (R2:R3) = y (f32[N])
376note off 16 = N
377note off 20 = a_f32_bits
378note off 24 = b_f32_bits
379note =========================================================================
380fn uEmitAxpy to bool
381uStart 2
382uParam 20 16
383uParam 21 20
384uParam 22 24
385uicImm 8 16 15 14 256 uAlu4
386uic 28 UZ 16 20 0 uCmp
387bOob = uBraFwd 1
388
389uicImm 9 24 16 0 4 uAlu4
390uicImm 9 26 16 2 4 uAlu4
391uic 11 28 24 UZ 0 uLd
392uic 11 29 26 UZ 0 uLd
393uic 0 UZ UZ UZ 0 uW0
394uic 32 30 22 29 0 uAlu4
395uic4 33 30 21 28 30 uAlu4
396uic 12 UZ 26 30 0 uSt
397uic 0 UZ UZ UZ 0 uW1
398
399uPatch bOob 1
400ret true
401end
402
403note =========================================================================
404note Kernel 3: k_mask_copy (y[i] = mask[i] * x[i])
405note Args:
406note ptr0 (R0:R1) = x (f32[N])
407note ptr1 (R2:R3) = y (f32[N])
408note ptr2 (R4:R5) = mask (f32[N])
409note off 24 = N
410note =========================================================================
411fn uEmitMaskCopy to bool
412uStart 3
413uParam 20 24
414uicImm 8 16 15 14 256 uAlu4
415uic 28 UZ 16 20 0 uCmp
416bOob = uBraFwd 1
417
418uicImm 9 24 16 0 4 uAlu4
419uicImm 9 26 16 2 4 uAlu4
420uicImm 9 28 16 4 4 uAlu4
421uic 11 30 24 UZ 0 uLd
422uic 11 31 28 UZ 0 uLd
423uic 0 UZ UZ UZ 0 uW0
424uic 32 30 30 31 0 uAlu4
425uic 12 UZ 26 30 0 uSt
426uic 0 UZ UZ UZ 0 uW1
427
428uPatch bOob 1
429ret true
430end