interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / chan / complete.om

379 lines · 8323 bytes Raw Blame History
1note chan/complete.om: completion semaphore producer/consumer protocol, command encoding,
2note wrap-safe sequence progress tracking, and bounded drain policy for Blackwell GPFIFO channels.
3note Layout source of record: NVIDIA open-gpu-kernel-modules 580.173.02 (MIT) clc96f.h:75-89,
4note uvm_hopper_host.c:45-52. Library unit, no main. Prefix cm / CM.
5note
6note Blackwell USERD (Nvc96fControl, clc96f.h:29-33) has GPPut at offset 0x8c (140) and NO GPGet;
7note Ignored01 covers bytes 0x90..0x1ff (512 bytes). Completion is tracked exclusively through
8note hardware semaphores released into host-visible memory, never via caller assertion or GPGet.
9note
10note Pure protocol:
11note cmhdr subc count -> uint incMethod header (2<<28 | count<<16 | subc<<13 | 23)
12note cmrel subc va seq -> long encodes 5-method release command into cmwds[0..5]
13note cmacq subc va seq -> long encodes 5-method acquire command into cmwds[0..5]
14note cmprog ret put obs -> long wrap-safe sequence check; returns newly completed entries,
15note 0 for pending, or CMESTALE (-5) for out-of-order/wrapped
16note cmputpb b off subc va seq -> long writes 6-word release command into pushbuffer b at offset off
17note
18note Typed mapped effect adapter:
19note cminit -> long initializes only unused tracker state; refuses retained bindings
20note cmbind c slot off gen -> long verifies mapped host capabilities; never hardware admission
21note cmsub c count -> long accounts only already-submitted channel entries within capacity
22note cmpoll c -> long polls memory via mmrd32, advances retired, calls chretire
23note cmdrain c budget -> long bounded poll loop; quarantines backing on timeout/error
24note cmquar c gen -> long uncertainty latch; quarantines semaphore and window
25note
26note Status codes: 0 CMOK, -1 CMEINVAL, -2 CMEALIGN, -3 CMERANGE, -4 CMESTATE, -5 CMESTALE,
27note -6 CMEFULL, -10 CMEGEN, -11 CMETIME, -12 CMEQUAR. No CPU/GPU ordering or cache flush is implied.
28note Vendor uvm_hopper_host.c:43 requires wfi_membar before release. cmrel is ONLY the release packet.
29note Production use additionally needs a qualified engine/cache fence and ordered mapped effects.
30const CMOK long 0
31const CMEINVAL long -1
32const CMEALIGN long -2
33const CMERANGE long -3
34const CMESTATE long -4
35const CMESTALE long -5
36const CMEFULL long -6
37const CMEGEN long -10
38const CMETIME long -11
39const CMEQUAR long -12
40note NVC96F method byte offsets
41const CMSADDR ulong 92
42const CMSHI ulong 96
43const CMSPLO ulong 100
44const CMSPHI ulong 104
45const CMSEXEC ulong 108
46note Method index in method space: 0x5c / 4 = 23
47const CMSEMM uint 23
48note CHNINC header (2 << 28) = 536870912
49const CMINC uint 536870912
50const CMCWDS ulong 6
51note Channel slots
52const CMSLOTS ulong 4
53note Tracker states
54const CMSNONE ulong 0
55const CMSBIND ulong 1
56const CMSACTV ulong 2
57const CMSDRN ulong 3
58const CMSIDLE ulong 4
59const CMSTOUT ulong 5
60const CMSQST ulong 6
61global cmwds uint 6
62global cmlen ulong 1
63global cmgen ulong 4
64global cmbuf ulong 4
65global cmbgen ulong 4
66global cmpa ulong 4
67global cmva ulong 4
68global cmret uint 4
69global cmput uint 4
70global cmst ulong 4
71fn cmhdr subc uint count uint to uint
72ret or or CMINC shl and count 1023 16 or shl and subc 7 13 CMSEMM
73end
74fn cmrel subc uint va ulong seq uint to long
75if gt subc 7
76ret CMEINVAL
77end
78if ne and va 3 0
79ret CMEALIGN
80end
81if or eq va 0 ge va MMVALIM
82ret CMERANGE
83end
84put cmwds 0 cmhdr subc 5
85put cmwds 1 and uint and va 4294967295 4294967292
86put cmwds 2 and uint shr va 32 33554431
87put cmwds 3 seq
88put cmwds 4 0
89put cmwds 5 1
90put cmlen 0 CMCWDS
91ret long CMCWDS
92end
93fn cmacq subc uint va ulong seq uint to long
94if gt subc 7
95ret CMEINVAL
96end
97if ne and va 3 0
98ret CMEALIGN
99end
100if or eq va 0 ge va MMVALIM
101ret CMERANGE
102end
103put cmwds 0 cmhdr subc 5
104put cmwds 1 and uint and va 4294967295 4294967292
105put cmwds 2 and uint shr va 32 33554431
106put cmwds 3 seq
107put cmwds 4 0
108put cmwds 5 0
109put cmlen 0 CMCWDS
110ret long CMCWDS
111end
112fn cmprog ret_ uint put_ uint obs uint to long
113inflight = sub put_ ret_
114if eq inflight 0
115if eq obs ret_
116ret 0
117end
118ret CMESTALE
119end
120prog = sub obs ret_
121if eq prog 0
122ret 0
123end
124if gt prog inflight
125ret CMESTALE
126end
127ret long prog
128end
129fn cmputpb b ulong off uint subc uint va ulong seq uint to long
130if ge b GMMAXB
131ret CMEINVAL
132end
133if not gmlive b
134ret CMEINVAL
135end
136if ne and off 3 0
137ret CMEALIGN
138end
139sz = get gmbsz b
140span = mul CMCWDS 4
141if or gt ulong off sz gt span sub sz ulong off
142ret CMERANGE
143end
144rc = cmrel subc va seq
145if lt rc 0
146ret rc
147end
148pa = add get gmbpa b ulong off
149for i ulong 6
150mmwr32 add pa mul i 4 ulong get cmwds i
151end
152ret long CMCWDS
153end
154fn cminit to long
155for c ulong CMSLOTS
156st = get cmst c
157if ne st CMSNONE
158ret CMESTATE
159end
160end
161for c ulong CMSLOTS
162put cmgen c 0
163put cmbuf c GMNONE
164put cmbgen c 0
165put cmpa c 0
166put cmva c 0
167put cmret c 0
168put cmput c 0
169put cmst c CMSNONE
170end
171put cmlen 0 0
172ret CMOK
173end
174fn cmbind c ulong slot ulong off uint gen ulong to long
175if ge c CMSLOTS
176ret CMEINVAL
177end
178if ne get mmwkind 0 1
179ret CMESTATE
180end
181if or lt get mmwst 0 MMWDMA ge get mmwst 0 MMWQUAR
182ret CMESTATE
183end
184if ne get mmwgen 0 gen
185ret CMEGEN
186end
187if ge slot GMMAXB
188ret CMEINVAL
189end
190if not gmlive slot
191ret CMEINVAL
192end
193if ne get cmst c CMSNONE
194ret CMESTATE
195end
196if or eq get chopen c 0 ne get chepoch c gen
197ret CMESTATE
198end
199if ne get chret c get chput c
200ret CMESTATE
201end
202if eq and get gmbfl slot GMHPOLL 0
203ret CMESTATE
204end
205if ne get gmbca slot 1
206ret CMESTATE
207end
208if ne and off 3 0
209ret CMEALIGN
210end
211sz = get gmbsz slot
212if gt add ulong off 4 sz
213ret CMERANGE
214end
215pa = add get gmbpa slot ulong off
216va = add get gmbva slot ulong off
217put cmgen c gen
218put cmbuf c slot
219put cmbgen c ulong get gmbgen slot
220put cmpa c pa
221put cmva c va
222put cmret c get chput c
223put cmput c get chput c
224put cmst c CMSBIND
225mmwr32 pa ulong get chput c
226ret CMOK
227end
228fn cmsub c ulong count uint to long
229if ge c CMSLOTS
230ret CMEINVAL
231end
232st = get cmst c
233if and and ne st CMSBIND ne st CMSACTV ne st CMSIDLE
234ret CMESTATE
235end
236if ne get mmwgen 0 get cmgen c
237ret CMEGEN
238end
239if ne get mmwst 0 MMWPUB
240ret CMESTATE
241end
242b = get cmbuf c
243if not gmlive b
244ret CMESTATE
245end
246if ne get cmbgen c ulong get gmbgen b
247ret CMEGEN
248end
249ent = get chent c
250if or eq count 0 eq ent 0
251ret CMEINVAL
252end
253p = get cmput c
254r = get cmret c
255inflight = sub p r
256if ge inflight ent
257ret CMEFULL
258end
259if gt count sub sub ent 1 inflight
260ret CMEFULL
261end
262chp = get chput c
263if ne r get chret c
264ret CMESTALE
265end
266avail = sub chp p
267if or ge avail ent gt count avail
268ret CMERANGE
269end
270put cmput c add p count
271put cmst c CMSACTV
272ret CMOK
273end
274fn cmpoll c ulong to long
275if ge c CMSLOTS
276ret CMEINVAL
277end
278st = get cmst c
279if and and and ne st CMSBIND ne st CMSACTV ne st CMSDRN ne st CMSIDLE
280ret CMESTATE
281end
282if ne get mmwgen 0 get cmgen c
283ret CMEGEN
284end
285if ne get mmwst 0 MMWPUB
286ret CMESTATE
287end
288b = get cmbuf c
289if not gmlive b
290ret CMESTATE
291end
292if ne get cmbgen c ulong get gmbgen b
293ret CMEGEN
294end
295pa = get cmpa c
296obs = uint mmrd32 pa
297r = get cmret c
298p = get cmput c
299diff = cmprog r p obs
300if lt diff 0
301ret diff
302end
303if eq diff 0
304ret 0
305end
306put cmret c obs
307chretire c obs
308if eq obs p
309put cmst c CMSIDLE
310end
311ret diff
312end
313fn cmdrain c ulong budget uint to long
314if ge c CMSLOTS
315ret CMEINVAL
316end
317st = get cmst c
318if and and and ne st CMSBIND ne st CMSACTV ne st CMSDRN ne st CMSIDLE
319ret CMESTATE
320end
321if ne get mmwgen 0 get cmgen c
322ret CMEGEN
323end
324if ne get mmwst 0 MMWPUB
325ret CMESTATE
326end
327b = get cmbuf c
328if not gmlive b
329ret CMESTATE
330end
331if ne get cmbgen c ulong get gmbgen b
332ret CMEGEN
333end
334if or ne get cmput c get chput c ne get cmret c get chret c
335ret CMESTALE
336end
337if eq get cmret c get cmput c
338put cmst c CMSIDLE
339ret CMOK
340end
341put cmst c CMSDRN
342drained = false
343for i uint budget
344r = cmpoll c
345if lt r 0
346break
347end
348if eq get cmret c get cmput c
349drained = true
350break
351end
352end
353if drained
354put cmst c CMSIDLE
355ret CMOK
356end
357put cmst c CMSTOUT
358note b is live under a published owned window: gmquar retires it AND quarantines the window (gmretire).
359r = gmquar b
360put cmst c CMSQST
361ret CMETIME
362end
363fn cmquar c ulong gen ulong to long
364if ge c CMSLOTS
365ret CMEINVAL
366end
367if ne gen get cmgen c
368ret CMEGEN
369end
370b = get cmbuf c
371if ne b GMNONE
372r = gmquar b
373end
374if eq get mmwst 0 MMWPUB
375r = mmwquar gen
376end
377put cmst c CMSQST
378ret CMOK
379end