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 / intel / xe / batch.om

328 lines · 6372 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note batch.om: pure seeded-Omega Intel Xe3 (Panther Lake / Xe3Core) CCS batch buffer builder & checker.
3note Bitfields verified against Intel compute-runtime shared/source/generated/xe3_core/hw_cmds_generated_xe3_core.inl:
4note PIPELINE_SELECT (1 dw): 0x69040302 (PipelineSelection=GPGPU/Compute, Mask=0x3)
5note STATE_BASE_ADDRESS (22 dw): 0x61010014 (InstructionBaseAddress DW10..11, InstructionBufferSize DW15)
6note STATE_COMPUTE_MODE (3 dw): 0x61050001 (LargeGrfMode=0, UavCoherencyMode=1)
7note CFE_STATE (6 dw): 0x72000004 (Pipeline=COMPUTE(2), Opcode=2, SubOp=0, MaxThreads DW3[31:16])
8note COMPUTE_WALKER (40 dw): 0x72080026 (Pipeline=COMPUTE(2), Opcode=2, SubOp=2, IDD DW19..26, PostSync DW27..31, InlineData DW32..39)
9note PIPE_CONTROL (6 dw): 0x7a000a04 (UnTypedDataPortCacheFlush + DataportFlush + CS Stall + DC Flush + QWORD Write Immediate)
10note MI_BATCH_BUFFER_END (1 dw): 0x05000000
11note
12note Usage:
13note batch emit KERNEL_VA INLINE_VA FENCE_VA FENCE_VAL GX GY GZ SIMD
14note batch fence FENCE_VA FENCE_VAL
15note batch check FILE.bin
16note Exit: 0 ok; 1 invalid batch; 2 usage; 3 I/O error.
17om2
18
19text tuse "usage: batch emit KVA IVA FVA FVAL GX GY GZ SIMD | fence FVA FVAL | check FILE.bin\n"
20text temit "emit"
21text tfence "fence"
22text tchk "check"
23text tbad "batch: invalid Xe3 CCS batch buffer\n"
24text tio "batch: I/O error\n"
25
26const OP_PIPE_SEL uint 0x69040302
27const OP_SBA uint 0x61010014
28const OP_SCM uint 0x61050001
29const OP_CFE uint 0x72000004
30const OP_WALKER uint 0x72080026
31const OP_PIPE_CTL uint 0x7a000a04
32const OP_BB_END uint 0x05000000
33
34global gdw uint 256
35global gbuf uchar 1024
36global gpath uchar 4096
37global garg uchar 64
38global gst ulong 4
39
40fn fail code int msg view uchar * to void
41n = write 2 msg 0 len msg
42exit code
43end
44
45fn argis i ulong t view uchar * to bool
46n = argread i garg 0 len garg
47if ne n long len t
48ret false
49end
50for k ulong len t
51if ne get garg k get t k
52ret false
53end
54end
55ret true
56end
57
58fn parseu ai ulong to ulong
59n = argread ai garg 0 len garg
60if or le n 0 gt n 20
61fail 2 tuse
62end
63v = ulong 0
64for i ulong ulong n
65c = get garg i
66if or lt c 48 gt c 57
67fail 2 tuse
68end
69v = add mul v 10 ulong sub c 48
70end
71ret v
72end
73
74fn dw v uint to void
75n = get gst 0
76put gdw n v
77put gst 0 add n 1
78end
79
80fn dw64 v ulong to void
81dw uint and v 4294967295
82dw uint shr v 32
83end
84
85fn emit_sba kva ulong to void
86note Xe3 STATE_BASE_ADDRESS (22 dwords): DW10..11 InstructionBaseAddress, DW15 InstructionBufferSize
87dw OP_SBA
88for i ulong 9
89dw 0
90end
91dw64 or and kva 18446744073709547520 1
92for i ulong 3
93dw 0
94end
95dw 0xfffff001
96for i ulong 6
97dw 0
98end
99end
100
101fn emit_scm to void
102note Xe3 STATE_COMPUTE_MODE (3 dwords): LargeGrfMode=0 (mask bit 31), UavCoherencyMode=1 (mask bit 22 + bit 6)
103dw OP_SCM
104dw 0x80000000
105dw 0x00400040
106end
107
108fn emit_cfe to void
109note Xe3 CFE_STATE (6 dwords): MaximumNumberOfThreads = 1024 in DW3[31:16]
110dw OP_CFE
111dw 0
112dw 0
113dw 0x04000000
114dw 0
115dw 0
116end
117
118fn emit_walker kva ulong iva ulong gx uint gy uint gz uint simd uint to void
119note Xe3 COMPUTE_WALKER (40 dwords, hw_cmds_generated_xe3_core.inl)
120dw OP_WALKER
121dw 0
122note DW2: IndirectDataLength = 64
123dw 64
124note DW3: IndirectDataStartAddress[31:6] (64B aligned)
125dw uint and iva 4294967232
126note DW4: SimdSize[31:30] (1=SIMT16, 2=SIMT32) | GenerateLocalId(29) | EmitInlineParameter(25)
127sbits = uint 0x62000000
128if eq simd 32
129sbits = 0xa2000000
130end
131dw sbits
132note DW5: ExecutionMask
133dw 0xffffffff
134note DW6: LocalXMaximum=63 (64 work-items/group)
135dw 63
136note DW7..9: ThreadGroupId X, Y, Z dimensions
137dw gx
138dw gy
139dw gz
140note DW10..18: Starting X/Y/Z, PartitionId, PartitionSize, Preempt X/Y/Z, Reserved
141for i ulong 9
142dw 0
143end
144note DW19..26: INTERFACE_DESCRIPTOR_DATA (8 dwords)
145note IDD DW0: KernelStartPointer[31:6] (64B aligned offset from InstructionBaseAddress)
146dw uint and kva 4032
147dw 0
148dw 0
149dw 0
150dw 0
151note IDD DW5: NumberOfThreadsInGpgpuThreadGroup=4 (4*SIMD16=64), RoundingMode=0 (RTNE)
152dw 4
153dw 0
154dw 0
155note DW27..31: POSTSYNC_DATA (5 dwords, no walker post-sync; PIPE_CONTROL signals fence)
156for i ulong 5
157dw 0
158end
159note DW32..39: InlineData[8] (32 bytes; inline_va in DW32..33)
160dw64 iva
161for i ulong 6
162dw 0
163end
164end
165
166fn emit_pipe_ctl fva ulong fval ulong to void
167note Xe3 PIPE_CONTROL (6 dwords): CS stall(20) | PostSync=WriteImmediate(14) | DcFlush(5)
168dw OP_PIPE_CTL
169dw 0x00104020
170dw64 fva
171dw64 fval
172end
173
174fn flush_dw to void
175while ne rem get gst 0 16 0 bound 16
176dw 0
177end
178ndw = get gst 0
179for i ulong ndw
180v = get gdw i
181o = mul i 4
182for k ulong 4
183put gbuf add o k uchar and shr v mul uint k 8 255
184end
185end
186nb = mul ndw 4
187r = write 1 gbuf 0 nb
188if ne r long nb
189fail 3 tio
190end
191end
192
193fn do_emit to void
194if ne argcnt 10
195fail 2 tuse
196end
197kva = parseu 2
198iva = parseu 3
199fva = parseu 4
200fval = parseu 5
201gx = uint parseu 6
202gy = uint parseu 7
203gz = uint parseu 8
204simd = uint parseu 9
205if and ne simd 16 ne simd 32
206fail 2 tuse
207end
208dw OP_PIPE_SEL
209emit_sba kva
210emit_scm
211emit_cfe
212emit_walker kva iva gx gy gz simd
213emit_pipe_ctl fva fval
214dw OP_BB_END
215flush_dw
216end
217
218fn do_fence to void
219if ne argcnt 4
220fail 2 tuse
221end
222fva = parseu 2
223fval = parseu 3
224emit_pipe_ctl fva fval
225dw OP_BB_END
226flush_dw
227end
228
229fn gbu32 i ulong to uint
230o = mul i 4
231v = uint 0
232for k ulong 4
233v = or v shl uint get gbuf add o k mul uint k 8
234end
235ret v
236end
237
238fn do_check to void
239if ne argcnt 3
240fail 2 tuse
241end
242pn = argread 2 gpath 0 len gpath
243if le pn 0
244fail 2 tuse
245end
246fd = fopen gpath 0 ulong pn 0 0
247if lt fd 0
248fail 3 tio
249end
250sz = fseek int fd 0 2
251if or lt sz 64 gt sz 1024
252c = fclose int fd
253fail 1 tbad
254end
255if ne rem ulong sz 64 0
256c = fclose int fd
257fail 1 tbad
258end
259r = pread int fd gbuf 0 ulong sz 0
260c = fclose int fd
261if ne r sz
262fail 3 tio
263end
264ndw = div ulong sz 4
265p = ulong 0
266seen_ctl = false
267seen_end = false
268while lt p ndw bound 256
269h = gbu32 p
270if eq h 0
271p = add p 1
272continue
273end
274if eq h OP_BB_END
275seen_end = true
276break
277end
278if eq h OP_PIPE_SEL
279p = add p 1
280continue
281end
282if eq h OP_SBA
283p = add p 22
284continue
285end
286if eq h OP_SCM
287p = add p 3
288continue
289end
290if eq h OP_CFE
291p = add p 6
292continue
293end
294if eq h OP_WALKER
295p = add p 40
296continue
297end
298if eq h OP_PIPE_CTL
299seen_ctl = true
300p = add p 6
301continue
302end
303fail 1 tbad
304end
305if or not seen_ctl not seen_end
306fail 1 tbad
307end
308end
309
310fn main to int
311if lt argcnt 3
312fail 2 tuse
313end
314if argis 1 temit
315do_emit
316ret 0
317end
318if argis 1 tfence
319do_fence
320ret 0
321end
322if argis 1 tchk
323do_check
324ret 0
325end
326fail 2 tuse
327ret 2
328end