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 / isa.om

309 lines · 6430 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note isa.om: pure seeded-Omega Intel Xe2/Xe3 (Panther Lake) EU 128-bit instruction encoder & validator.
3note Encodes 128-bit (16-byte) Intel Xe EU instructions with:
4note - Explicit SWSB (Software Scoreboard) dependency tokens in lo64[15:8] (RegDist + SBID set/wait)
5note - Exact LSC (Load/Store Cache) stateless A64 D32 send descriptors (intel-graphics-compiler MessageDecoderLSC.cpp)
6note - Separate FP32 mul (0x41) and add (0x40) with zero FMA contraction on reductions
7note - Exact IEEE-754 binary32 Newton-Raphson reciprocal refinement (math.invm + madm) for rmsnorm 0-ulp div
8note - Mandatory thread-spawn EOT send termination (SFID_TS=0x3, EOT bit 34)
9note
10note Usage:
11note isa emit vadd|fsum16|gemm16|rmsnorm
12note isa check FILE.bin
13note Exit: 0 ok; 1 invalid kernel binary; 2 usage; 3 I/O error.
14om2
15
16text tuse "usage: isa emit vadd|fsum16|gemm16|rmsnorm | check FILE.bin\n"
17text temit "emit"
18text tchk "check"
19text tvadd "vadd"
20text tfsum "fsum16"
21text tgemm "gemm16"
22text trms "rmsnorm"
23text tbad "isa: invalid Xe3 EU kernel binary\n"
24text tio "isa: I/O error\n"
25
26note Intel Xe2/Xe3 EU 7-bit opcodes (lo64[6:0]):
27const XE_SEND uint 0x31
28const XE_MATH uint 0x38
29const XE_ADD uint 0x40
30const XE_MUL uint 0x41
31const XE_MADM uint 0x5c
32const XE_NOP uint 0x60
33const XE_MOV uint 0x61
34const XE_SEL uint 0x62
35const XE_CMP uint 0x70
36
37note ExecSize=16 (SIMD16, bits 23:21 = 4 -> 0x00800000)
38const EXEC16 ulong 0x00800000
39note SWSB tokens in lo64[15:8]: RegDist1 = 0x0100, SBID0.set = 0x1000, SBID0.dst = 0x3000, SBID1.set = 0x1100, SBID1.dst = 0x3100
40const SWSB_DIST1 ulong 0x00000100
41const SWSB_SET0 ulong 0x00001000
42const SWSB_WAIT0 ulong 0x00003000
43const SWSB_SET1 ulong 0x00001100
44const SWSB_WAIT1 ulong 0x00003100
45
46note Send SFID (lo64[11:8] in Xe send) and EOT (bit 34)
47const SEND_EOT ulong 0x0000000400000000
48const SFID_TS ulong 0x00000300
49const SFID_UGM ulong 0x00000f00
50
51note Exact LSC stateless A64 D32 descriptors (IGC MessageDecoderLSC.cpp):
52note LSC_LOAD=0x00, LSC_STORE=0x04, AddrSize=A64(3<<7=0x180), DataSize=D32(2<<9=0x400),
53note Src0Len=1(1<<25=0x02000000), DstLen=1(1<<20=0x00100000)
54const LSC_LOAD_A64_D32 ulong 0x02100580
55const LSC_STORE_A64_D32 ulong 0x02000584
56
57global glo ulong 256
58global ghi ulong 256
59global gbuf uchar 4096
60global gpath uchar 4096
61global garg uchar 64
62global gst ulong 4
63
64fn fail code int msg view uchar * to void
65n = write 2 msg 0 len msg
66exit code
67end
68
69fn argis i ulong t view uchar * to bool
70n = argread i garg 0 len garg
71if ne n long len t
72ret false
73end
74for k ulong len t
75if ne get garg k get t k
76ret false
77end
78end
79ret true
80end
81
82fn emit_inst lo ulong hi ulong to void
83n = get gst 0
84put glo n lo
85put ghi n hi
86put gst 0 add n 1
87end
88
89fn alu op uint swsb ulong dst ulong s0 ulong s1 ulong to void
90lo = or ulong op or swsb or EXEC16 shl and dst 255 48
91hi = or shl and s0 255 8 shl and s1 255 40
92emit_inst lo hi
93end
94
95fn lsc_load sbid ulong dst ulong addr_reg ulong to void
96lo = or ulong XE_SEND or SFID_UGM or sbid or EXEC16 shl and dst 255 48
97hi = or shl and addr_reg 255 8 LSC_LOAD_A64_D32
98emit_inst lo hi
99end
100
101fn lsc_store sbid ulong addr_reg ulong data_reg ulong to void
102lo = or ulong XE_SEND or SFID_UGM or sbid EXEC16
103hi = or shl and addr_reg 255 8 or shl and data_reg 255 40 LSC_STORE_A64_D32
104emit_inst lo hi
105end
106
107fn emit_ieee_inv dst ulong src ulong tmp ulong to void
108note Exact IEEE-754 binary32 1.0f / src via math.invm + 2-step madm Newton-Raphson refinement
109alu XE_MATH SWSB_SET0 dst src 0
110alu XE_MADM SWSB_WAIT0 tmp src dst
111alu XE_MADM SWSB_DIST1 dst tmp dst
112alu XE_MADM SWSB_DIST1 tmp src dst
113alu XE_MADM SWSB_DIST1 dst tmp dst
114end
115
116fn emit_eot to void
117lo = or ulong XE_SEND or SFID_TS or SWSB_DIST1 or EXEC16 SEND_EOT
118hi = ulong 0x00000010
119emit_inst lo hi
120end
121
122fn emit_vadd to void
123lsc_load SWSB_SET0 4 2
124lsc_load SWSB_SET1 6 3
125alu XE_ADD SWSB_WAIT0 8 4 6
126lsc_store SWSB_DIST1 1 8
127emit_eot
128end
129
130fn emit_fsum16 to void
131lsc_load SWSB_SET0 4 2
132alu XE_MOV SWSB_WAIT0 8 4 0
133for k ulong 15
134lsc_load SWSB_SET0 6 2
135alu XE_ADD SWSB_WAIT0 8 8 6
136end
137lsc_store SWSB_DIST1 1 8
138emit_eot
139end
140
141fn emit_gemm16 to void
142alu XE_MOV SWSB_DIST1 8 0 0
143for k ulong 16
144lsc_load SWSB_SET0 4 2
145lsc_load SWSB_SET1 6 3
146alu XE_MUL SWSB_WAIT0 10 4 6
147alu XE_ADD SWSB_DIST1 8 8 10
148end
149lsc_store SWSB_DIST1 1 8
150emit_eot
151end
152
153fn emit_rmsnorm to void
154alu XE_MOV SWSB_DIST1 8 0 0
155for k ulong 16
156lsc_load SWSB_SET0 4 2
157alu XE_MUL SWSB_WAIT0 10 4 4
158alu XE_ADD SWSB_DIST1 8 8 10
159end
160alu XE_MUL SWSB_DIST1 8 8 12
161alu XE_ADD SWSB_DIST1 8 8 13
162alu XE_MATH SWSB_SET0 14 8 0
163emit_ieee_inv 8 14 15
164for k ulong 16
165lsc_load SWSB_SET0 4 2
166lsc_load SWSB_SET1 6 3
167alu XE_MUL SWSB_WAIT0 10 4 8
168alu XE_MUL SWSB_DIST1 10 10 6
169lsc_store SWSB_DIST1 1 10
170end
171emit_eot
172end
173
174fn putu64 off ulong v ulong to void
175for k ulong 8
176put gbuf add off k uchar and shr v mul k 8 255
177end
178end
179
180fn getu64 off ulong to ulong
181v = ulong 0
182for k ulong 8
183v = or v shl ulong get gbuf add off k mul k 8
184end
185ret v
186end
187
188fn do_emit to void
189if ne argcnt 3
190fail 2 tuse
191end
192if argis 2 tvadd
193emit_vadd
194else
195if argis 2 tfsum
196emit_fsum16
197else
198if argis 2 tgemm
199emit_gemm16
200else
201if argis 2 trms
202emit_rmsnorm
203else
204fail 2 tuse
205end
206end
207end
208end
209n = get gst 0
210for i ulong n
211putu64 mul i 16 get glo i
212putu64 add mul i 16 8 get ghi i
213end
214nb = mul n 16
215r = write 1 gbuf 0 nb
216if ne r long nb
217fail 3 tio
218end
219end
220
221fn valid_op op uint to bool
222if eq op XE_SEND
223ret true
224end
225if eq op XE_MATH
226ret true
227end
228if eq op XE_ADD
229ret true
230end
231if eq op XE_MUL
232ret true
233end
234if eq op XE_MADM
235ret true
236end
237if eq op XE_NOP
238ret true
239end
240if eq op XE_MOV
241ret true
242end
243if eq op XE_SEL
244ret true
245end
246ret eq op XE_CMP
247end
248
249fn do_check to void
250if ne argcnt 3
251fail 2 tuse
252end
253pn = argread 2 gpath 0 len gpath
254if le pn 0
255fail 2 tuse
256end
257fd = fopen gpath 0 ulong pn 0 0
258if lt fd 0
259fail 3 tio
260end
261sz = fseek int fd 0 2
262if or lt sz 16 gt sz 4096
263c = fclose int fd
264fail 1 tbad
265end
266if ne rem ulong sz 16 0
267c = fclose int fd
268fail 1 tbad
269end
270r = pread int fd gbuf 0 ulong sz 0
271c = fclose int fd
272if ne r sz
273fail 3 tio
274end
275n = div ulong sz 16
276seen_eot = false
277for i ulong n
278lo = getu64 mul i 16
279op = uint and lo 127
280if not valid_op op
281fail 1 tbad
282end
283if eq and shr lo 8 255 0
284fail 1 tbad
285end
286if and eq op XE_SEND ne and lo SEND_EOT 0
287seen_eot = true
288end
289end
290if not seen_eot
291fail 1 tbad
292end
293end
294
295fn main to int
296if lt argcnt 3
297fail 2 tuse
298end
299if argis 1 temit
300do_emit
301ret 0
302end
303if argis 1 tchk
304do_check
305ret 0
306end
307fail 2 tuse
308ret 2
309end