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 / nvidia / native / blackwell / batch.om

182 lines · 4490 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.
85note Add, never subtract: after a seam the used bytes may exceed 1048476 (n<=65536, no overflow).
86if gt add n get gbst 2 1048476
87ret gbberr idx id -75
88end
89if not gbbcopy
90ret false
91end
92put gbids idx id
93if gt get gbst 0 1
94put gbused 0 0
95va = add mapaddr get gbmem 3 add ulong 32 mul idx 4
96gbrel va 6
97note Full shader invalidation after the WFI release has drained this grid.
98gbmth 1 540 1
99gbemit 4113
100if not gbbcopy
101ret false
102end
103end
104put gbst 1 add idx 1
105ret true
106end
107note Scan seals without waiting. Blame FIRST uncompleted index and the caller's kernel id.
108note Tail timeout with all seals complete is count, not a fabricated kernel failure.
109fn gbbcheck to bool
110n = get gbst 0
111if gt n 1
112for i ulong n
113if ne mapget get gbmem 3 add ulong 32 mul i 4 4 6
114put gbst 4 i
115put gbst 5 get gbids i
116ret false
117end
118end
119else
120if ne mapget get gbmem 2 8192 4 6
121put gbst 4 0
122put gbst 5 get gbids 0
123ret false
124end
125end
126put gbst 4 n
127put gbst 5 0
128ret true
129end
130note Existing nvwait is sleep-polling: never spin or inherit a process spin window.
131note One nvsend and one nvwait. The second marker follows the unchanged C3 L2 flush.
132fn gbbsubmit budget ulong to bool
133if or ne get gbst 3 1 ne get nvfault 0 0
134ret false
135end
136if ne get gbst 1 get gbst 0
137ret gbberr get gbst 1 0 -22
138end
139if or eq budget 0 gt budget 30000000000
140ret gbberr get gbst 1 0 -22
141end
142put gbused 0 0
143gbtail
144if not gbbcopy
145ret false
146end
147r = mapset get gbmem 2 8192 4 0
148r = mapset get gbmem 3 0 4 0
149r = mapset get gbmem 3 16 4 0
150for i ulong get gbst 0
151r = mapset get gbmem 3 add ulong 32 mul i 4 4 0
152end
153n = get gbst 2
154put gbst 3 2
155put nvstage 0 41
156if not nvsend get gbpkt 0 0 uint div n 4
157note Conservative fail-stop even if the driver refused before its doorbell.
158put nvfault 0 1
159put gbst 3 3
160ret false
161end
162put gbst 6 1
163put gbst 7 1
164put nvstage 0 42
165if not nvwait get gbmem 3 16 1179010630 budget
166ok = gbbcheck
167put nvfault 0 1
168put gbst 3 3
169ret false
170end
171ok = gbbcheck
172if or not ok ne mapget get gbmem 3 0 4 1145324612
173put nvfault 0 1
174put gbst 3 3
175put nverr 0 -5
176ret false
177end
178put gbst 3 0
179put gbst 4 18446744073709551615
180put nvstage 0 43
181ret true
182end