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 / amd / kfd / launch / dispatch.om

287 lines · 7884 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note launch: table,ninputs,repeats,timeoutns,outbytes,groupsX,groupsY,queueid,bell,belloff,ringslots.
3global launch ulong 11
4text timed "OMEGA dispatch_ns="
5text repeatlabel " packets="
6note Diagnostics retain CPU-side inputs only; no additional device writes.
7global queueinput ulong 11
8note diagstate: vadd,full doorbell offset,last packet slot.
9global diagstate ulong 3
10text diagprefix "OMEGA diag "
11text diagspace " "
12text dread "queue_read_pointer"
13text dwrite "queue_write_pointer"
14text dptr64 "queue_properties"
15text dqbase "read_pointer_base_offset"
16text dkind "signal_kind"
17text dvalue "signal_value"
18text dheader "ring_header"
19text dslot "ring_slot_byte_offset"
20text dout "output_word_"
21text dqueue "create_queue_input_qword_"
22text did "queue_id"
23text dbell "doorbell_offset"
24text dentry "kernel_code_entry_byte_offset"
25text drsrc1 "compute_pgm_rsrc1"
26text drsrc2 "compute_pgm_rsrc2"
27text drsrc3 "compute_pgm_rsrc3"
28text dprops "kernel_code_properties"
29text dgroup "group_segment_size"
30text dprivate "private_segment_size"
31text dargsize "kernarg_size"
32text dobject "packet_kernel_object"
33text dargaddr "packet_kernarg_address"
34text dnan "output_first8_nan_fill_count"
35text dsum "output_first8_expected_vadd_sum_count"
36text dtimeout "wait_timeout_ns"
37fn diag name view uchar * value ulong to void
38emit diagprefix
39emit name
40emit diagspace
41printnum value
42emit newline
43end
44fn diagindexed name view uchar * index ulong value ulong to void
45emit diagprefix
46emit name
47printnum index
48emit diagspace
49printnum value
50emit newline
51end
52fn lh i ulong to long
53ret long mapget long get launch 0 mul i 24 8
54end
55fn allocate i ulong n ulong flags ulong to long
56ret gpumem n flags long get launch 0 mul i 24
57end
58fn diagnostics to void
59cpufence
60diag dread mapget lh 5 128 8
61diag dwrite mapget lh 5 56 8
62diag dptr64 mapget lh 5 180 4
63diag dqbase mapget lh 5 136 4
64diag dkind mapget lh 7 0 8
65diag dvalue mapget lh 7 8 8
66diag dslot get diagstate 2
67diag dheader mapget lh 3 get diagstate 2 4
68diag dobject mapget lh 3 add get diagstate 2 32 8
69diag dargaddr mapget lh 3 add get diagstate 2 40 8
70diag did get launch 7
71diag dbell get diagstate 1
72for i ulong 11
73diagindexed dqueue i get queueinput i
74end
75diag dentry mapget lh 0 add get el 6 16 8
76diag drsrc1 mapget lh 0 add get el 6 48 4
77diag drsrc2 mapget lh 0 add get el 6 52 4
78diag drsrc3 mapget lh 0 add get el 6 44 4
79diag dprops and mapget lh 0 add get el 6 56 4 65535
80diag dgroup mapget lh 0 get el 6 4
81diag dprivate mapget lh 0 add get el 6 4 4
82diag dargsize mapget lh 0 add get el 6 8 4
83count = div get launch 4 4
84if gt count 8
85count = ulong 8
86end
87nan = ulong 0
88sum = ulong 0
89for i ulong count
90word = mapget lh 2 mul i 4 4
91diagindexed dout i word
92if eq word 0x7fc00000
93nan = add nan 1
94end
95if eq word 0x40000000
96sum = add sum 1
97end
98end
99diag dnan nan
100if ne get diagstate 0 0
101diag dsum sum
102end
103end
104fn queuehdr to void
105note Allocation 4 holds the inactive USER signal; allocation 5 owns the full queue.
106zeromap lh 4 0 4096
107r = checked mapset lh 4 0 8 1
108zeromap lh 5 0 4096
109note AMD queue v1 prefix: HSA header, write id at 56, read id at 128.
110r = checked mapset lh 5 4 4 1
111r = checked mapset lh 5 8 8 mapaddr lh 3
112r = checked mapset lh 5 24 4 get launch 10
113r = checked mapset lh 5 32 8 18446744073709551615
114r = checked mapset lh 5 64 4 get dev 12
115r = checked mapset lh 5 68 4 get dev 13
116if or eq get dev 4 0 eq get dev 11 0
117exit 66
118end
119cu = div get dev 3 get dev 4
120if gt get dev 11 div ulong 4294967296 get dev 4
121exit 66
122end
123waves = mul get dev 11 get dev 4
124if or eq cu 0 or gt cu 4294967296 gt waves 4294967296
125exit 66
126end
127r = checked mapset lh 5 72 4 sub cu 1
128r = checked mapset lh 5 76 4 sub waves 1
129r = checked mapset lh 5 136 4 128
130note IS_PTR64 at read_dispatch_id + 52, inactive signal at +64.
131r = checked mapset lh 5 180 4 2
132r = checked mapset lh 5 192 8 mapaddr lh 4
133end
134fn queueinit to void
135if eq get launch 10 0
136put launch 10 16
137end
138ctxsizes
139readap
140note The command processor fetches AQL packets through an executable GPU mapping.
141r = allocate 3 mul get launch 10 64 0xe6000002
142r = allocate 4 4096 0xa6000002
143r = allocate 5 4096 0xa6000002
144n = roundup mul add get dev 8 get dev 10 get dev 7 4096
145r = allocate 6 n 0xe4000002
146r = allocate 7 4096 0xa6000002
147zeromap lh 3 0 mul get launch 10 64
148queuehdr
149zeromap lh 6 0 n
150zeromap lh 7 0 64
151note USER signal ABI: kind 1 at 0, value at 8, no interrupt event.
152r = checked mapset lh 7 0 8 1
153r = checked mapset lh 7 8 8 get launch 2
154for i ulong get dev 7 bound 9223372036854775807
155p = mul i get dev 8
156r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8
157r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7
158end
159for i ulong get launch 10 bound 9223372036854775807
160r = checked mapset lh 3 mul i 64 4 1
161end
162stepbegin stqueue get dev 2
163zerohdr
164note Same WP/RP handle selects the compiler-owned AMD queue ABI; address bytes stay zero.
165hput 32 4 mul get launch 10 64
166hput 36 4 get dev 2
167hput 40 4 2
168hput 44 4 100
169hput 48 4 7
170hput 80 4 get dev 8
171hput 84 4 get dev 9
172note gfx942 AQL queues require no EOP allocation (ROCT queues.c).
173note kfdctl supplies these five mapping addresses in its private ioctl block.
174note Reconstruct that input here, before the ioctl returns output fields.
175for i ulong 11
176put queueinput i hget mul i 8 8
177end
178put queueinput 0 mapaddr lh 3
179put queueinput 1 add mapaddr lh 5 56
180put queueinput 2 add mapaddr lh 5 128
181put queueinput 7 0
182put queueinput 9 mapaddr lh 6
183r = checked kfdctl int get dev 0 3227011842 hdr 0 88 lh 3 lh 5 lh 5 long 0 lh 6
184put launch 7 hget 52 4
185r = checked mapset lh 5 32 8 get launch 7
186stepend
187belloff = hget 24 8
188put diagstate 1 belloff
189put launch 9 rem belloff 8192
190stepbegin stbell belloff
191put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192
192stepend
193end
194fn packet id ulong to void
195slot = mul rem id 16 64
196put diagstate 2 slot
197zerohdr
198note First dword kept INVALID until every other field is published.
199hput 0 2 1
200hput 2 2 2
201hput 4 2 64
202hput 6 2 1
203hput 8 2 1
204hput 12 4 mul get launch 5 64
205hput 16 4 get launch 6
206hput 20 4 1
207note HSA packet order differs from descriptor order: private at 24, group at 28.
208hput 24 4 get el 10
209hput 28 4 get el 9
210hput 32 8 add mapaddr lh 0 get el 6
211hput 40 8 mapaddr lh 1
212hput 56 8 mapaddr lh 7
213r = checked mapset lh 3 slot 4 1
214r = checked mapwrite lh 3 add slot 4 hdr 4 60
215cpufence
216note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2.
217r = checked mapset lh 3 slot 4 0x00021502
218cpufence
219r = checked mapset lh 5 56 8 add id 1
220cpufence
221r = checked mapset long get launch 8 get launch 9 8 id
222end
223fn deadline start long to void
224now = monons
225if lt now start
226steprow 110 false
227diagnostics
228exit 75
229end
230slowdispatch ulong sub now start
231if and ne get launch 3 0 gt ulong sub now start get launch 3
232steprow 110 false
233diagnostics
234exit 75
235end
236end
237fn dispatch to void
238stepbegin stdispatch get launch 2
239diag dtimeout get launch 3
240put dispatchalarm 0 0
241start = monons
242if lt start 0
243steprow ulong neg start false
244exit 74
245end
246for i ulong get launch 2 bound 9223372036854775807
247while ge sub i mapget lh 5 128 8 16 bound 9223372036854775807
248deadline start
249cpurelax
250end
251packet i
252end
253stepend
254stepbegin stwait get launch 2
255while ne mapget lh 7 8 8 0 bound 9223372036854775807
256deadline start
257cpurelax
258end
259cpufence
260stepend
261elapsed = sub monons start
262if lt elapsed 0
263exit 74
264end
265slowdispatch ulong elapsed
266emit timed
267printnum ulong elapsed
268emit repeatlabel
269printnum get launch 2
270emit newline
271diagnostics
272end
273fn teardown to void
274stepbegin stcleanup 0
275zerohdr
276hput 0 4 get launch 7
277r = checked kfdctl int get dev 0 3221768963 hdr 0 8
278r = checked mapdrop long get launch 8
279for i ulong add get launch 1 8 bound 9223372036854775807
280gpufree long get launch 0 mul i 24
281end
282r = checked mapdrop long get launch 0
283r = checked fclose int get dev 1
284r = checked fclose int get dev 0
285r = checked fclose int get el 0
286stepend
287end