interplane.Get Omega
Read in your language

omega-helix

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

omega-helix / native / gpu / batch.om

198 lines · 4842 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Compose context.om, vector.om, launch.om, batch.om. No alternate driver or queue.
3note Bodies are produced by gbbody, or an equivalent INLINE/DMA body WITHOUT gbtail.
4note Every body has a WFI release and full shader invalidation before the next body.
5note QMD/bank updates are inline DMA, never CPU overwrites while the GPU reads them.
6note Source: class/clc96f.h:75-87 RELEASE_WFI_EN; om/streams/streams.om INVALL.
7note All gbmem allocations and code/data operands stay live and immutable until completion.
8note No reset, append, free or retry after uncertain completion: nvfault remains latched.
9global gbst ulong 8
10note gbst: expected, recorded, bytes, phase(0 idle,1 recording,2 in-flight,3 poison),
11note bad index(count means final tail), bad caller id, kicks, waits.
12global gbids ulong 512
13global gbpkt long 1
14fn gbberr idx ulong id ulong err long to bool
15put gbst 4 idx
16put gbst 5 id
17put gbst 3 3
18put nverr 0 err
19ret false
20end
21note Allocate once after opening the context. GPU-uncached packet storage.
22fn gbbopen to bool
23if ne get nvfault 0 0
24ret false
25end
26if gt get gbpkt 0 0
27ret true
28end
29m = nvalloc 1048576 false
30if le m 0
31ret false
32end
33put gbpkt 0 m
34ret true
35end
36note Count admission precedes body recording or any send. A bad append poisons the whole batch.
37fn gbbegin count ulong to bool
38if or ne get nvfault 0 0 eq get gbst 3 2
39ret false
40end
41if or eq count 0 gt count 512
42ret gbberr 0 0 -75
43end
44if le get gbpkt 0 0
45ret gbberr 0 0 -22
46end
47put gbst 0 count
48put gbst 1 0
49put gbst 2 0
50put gbst 3 1
51put gbst 4 18446744073709551615
52put gbst 5 0
53put gbst 6 0
54put gbst 7 0
55ret true
56end
57note Copy directly into the persistent submit mapping, not through a second megabyte buffer.
58fn gbbcopy to bool
59n = get gbused 0
60base = get gbst 2
61r = mapwrite get gbpkt 0 base gbcmd 0 n
62if ne r long n
63ret gbberr get gbst 1 0 -5
64end
65put gbst 2 add base n
66ret true
67end
68note dep = zero for none, or producer index+1. Only already-recorded producers are admissible.
69fn gbappend id ulong dep ulong to bool
70idx = get gbst 1
71if or ne get gbst 3 1 ne get nvfault 0 0
72ret false
73end
74if ge idx get gbst 0
75ret gbberr idx id -75
76end
77if gt dep idx
78ret gbberr idx id -22
79end
80n = get gbused 0
81if or or eq n 0 gt n 65536 ne rem n 4 0
82ret gbberr idx id -22
83end
84note Reserve seam release/invalidate (32 bytes) and unchanged tail (68 bytes) before copying.
85if gt n sub ulong 1048476 get gbst 2
86ret gbberr idx id -75
87end
88if not gbbcopy
89ret false
90end
91put gbids idx id
92if gt get gbst 0 1
93put gbused 0 0
94va = add mapaddr get gbmem 3 add ulong 32 mul idx 4
95gbrel va 6
96note Full shader invalidation after the WFI release has drained this grid.
97gbmth 1 540 1
98gbemit 4113
99if not gbbcopy
100ret false
101end
102end
103put gbst 1 add idx 1
104ret true
105end
106note Scan seals without waiting. Blame FIRST uncompleted index and the caller's kernel id.
107note Tail timeout with all seals complete is count, not a fabricated kernel failure.
108fn gbbcheck to bool
109n = get gbst 0
110if gt n 1
111for i ulong n
112if ne mapget get gbmem 3 add ulong 32 mul i 4 4 6
113put gbst 4 i
114put gbst 5 get gbids i
115ret false
116end
117end
118else
119if ne mapget get gbmem 2 8192 4 6
120put gbst 4 0
121put gbst 5 get gbids 0
122ret false
123end
124end
125put gbst 4 n
126put gbst 5 0
127ret true
128end
129note Split gbbsubmit into async gbbkick (send pushbuffer without waiting) + gbbjoin (wait + seal check)
130note so Grace CPU can prepare the next batch/CSR/loss while Blackwell executes the active batch.
131fn gbbkick to bool
132if or ne get gbst 3 1 ne get nvfault 0 0
133ret false
134end
135if ne get gbst 1 get gbst 0
136ret gbberr get gbst 1 0 -22
137end
138put gbused 0 0
139gbtail
140if not gbbcopy
141ret false
142end
143r = mapset get gbmem 2 8192 4 0
144r = mapset get gbmem 3 0 4 0
145r = mapset get gbmem 3 16 4 0
146for i ulong get gbst 0
147r = mapset get gbmem 3 add ulong 32 mul i 4 4 0
148end
149n = get gbst 2
150put gbst 3 2
151put nvstage 0 41
152if not nvsend get gbpkt 0 0 uint div n 4
153note Conservative fail-stop even if the driver refused before its doorbell.
154put nvfault 0 1
155put gbst 3 3
156ret false
157end
158put gbst 6 1
159ret true
160end
161fn gbbjoin budget ulong to bool
162if or ne get gbst 3 2 ne get nvfault 0 0
163ret false
164end
165if or eq budget 0 gt budget 30000000000
166ret gbberr get gbst 1 0 -22
167end
168put gbst 7 1
169put nvstage 0 42
170if not nvwait get gbmem 3 16 1179010630 budget
171ok = gbbcheck
172put nvfault 0 1
173put gbst 3 3
174ret false
175end
176ok = gbbcheck
177if or not ok ne mapget get gbmem 3 0 4 1145324612
178put nvfault 0 1
179put gbst 3 3
180put nverr 0 -5
181ret false
182end
183put gbst 3 0
184put gbst 4 18446744073709551615
185put nvstage 0 43
186ret true
187end
188note Existing nvwait is sleep-polling: never spin or inherit a process spin window.
189note One nvsend and one nvwait. The second marker follows the unchanged C3 L2 flush.
190fn gbbsubmit budget ulong to bool
191if or eq budget 0 gt budget 30000000000
192ret gbberr get gbst 1 0 -22
193end
194if not gbbkick
195ret false
196end
197ret gbbjoin budget
198end