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 / arboris / arena.om

229 lines · 5410 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note One arena per serialized native context. A trusted producer supplies six
3note distinct, exact-size RM share records and relinquishes mutable input aliases
4note before step admission. The first three imports are read-only on CPU and GPU.
5note This module owns five PROT_NONE CPU reservations at VAs left out of both
6note the RM DMA map and UVM external mappings. The native ABI uses 4096 B pages.
7global ar_maps long 6
8global ar_guards long 5
9global ar_import_index ulong 1
10note Nonzero from completed code installation until all launch buffers retire.
11global ar_code_model ulong 1
12
13fn ar_share_word records view uchar 144 pos ulong to ulong
14 word = ulong 0
15 for i ulong 4
16 word = or word shl ulong get records add pos i mul i 8
17 end
18 ret word
19end
20
21fn ar_region_bytes m view ulong 16 starts view ulong 6 i ulong to ulong
22 if eq i 5
23 ret sub get m 12 get starts i
24 end
25 ret sub sub get starts add i 1 get starts i 4096
26end
27
28fn ar_shares_valid records view uchar 144 m view ulong 16 starts view ulong 6 to bool
29 owner = ar_share_word records 8
30 if or eq owner 0 eq owner ulong get nvobj 0
31 ret false
32 end
33 for i ulong 6
34 off = mul i 24
35 if or ne ar_share_word records off 1129991503 ne ar_share_word records add off 4 1
36 ret false
37 end
38 if ne ar_share_word records add off 8 owner
39 ret false
40 end
41 obj = ar_share_word records add off 12
42 if eq obj 0
43 ret false
44 end
45 for j ulong i bound 6
46 if eq obj ar_share_word records add mul j 24 12
47 ret false
48 end
49 end
50 size = or ar_share_word records add off 16 shl ar_share_word records add off 20 32
51 if ne size ar_region_bytes m starts i
52 ret false
53 end
54 end
55 ret true
56end
57
58fn ar_mapper_idle to bool
59 for i ulong 6
60 if ne get ar_maps i 0
61 ret false
62 end
63 end
64 for i ulong 5
65 if ne get ar_guards i 0
66 ret false
67 end
68 end
69 ret true
70end
71
72fn ar_unmap to bool
73 note A failed or outstanding submission retains its mappings until retirement.
74 if or ne get ar_code_model 0 0 ne get nvput 0 get nvret 0
75 ret false
76 end
77 for j ulong 6
78 i = sub ulong 5 j
79 tok = get ar_maps i
80 if gt tok 0
81 if eq get nvstate 0 1
82 if not nvdrop tok
83 ret false
84 end
85 else
86 note A successful nvstop has already retired all imported mappings.
87 if ne get nvstate 0 0
88 ret false
89 end
90 end
91 put ar_maps i 0
92 end
93 end
94 for j ulong 5
95 tok = get ar_guards j
96 if gt tok 0
97 if ne mapdrop tok 0
98 ret false
99 end
100 put ar_guards j 0
101 end
102 end
103 ret true
104end
105
106fn ar_guard i ulong to bool
107 va = get nvnext 0
108 g = maphold va 4096
109 if le g 0
110 ret false
111 end
112 put ar_guards i g
113 put nvnext 0 add va 4096
114 ret eq mapaddr g va
115end
116
117fn ar_import_range records view uchar 144 i ulong size ulong va ulong to bool
118 if ne get nvnext 0 va
119 ret false
120 end
121 for j ulong 24
122 put nvshrec j get records add mul i 24 j
123 end
124 tok = nvimport size lt i 3
125 if le tok 0
126 ret false
127 end
128 put ar_maps i tok
129 if ne mapaddr tok va
130 ret false
131 end
132 if lt i 5
133 ret ar_guard i
134 end
135 ret true
136end
137
138fn ar_map_arena records view uchar 144 meta view ulong 16 budget ulong to bool
139 if or not ar_mapper_idle ne get nvstate 0 1
140 ret false
141 end
142 if or eq get nvreg 1 0 ne get nvfault 0 0
143 ret false
144 end
145 checked = new ulong 16 0
146 offsets = new ulong 6 0
147 for i ulong 16
148 put checked i get meta i
149 end
150 reason = ulong 1
151 if eq get checked 0 arboris_sparse_magic
152 reason = arboris_plan_sparse checked budget 4096 offsets
153 else
154 reason = arboris_plan_arena checked budget 4096 offsets
155 end
156 if ne reason 0
157 ret false
158 end
159 for i ulong 16
160 if ne get checked i get meta i
161 ret false
162 end
163 end
164 base = get nvnext 0
165 if or lt base 65536 ne and base 4095 0
166 ret false
167 end
168 if or ge base 0x10000000000 gt get meta 12 sub 0x10000000000 base
169 ret false
170 end
171 if not ar_shares_valid records meta offsets
172 ret false
173 end
174 for i ulong 6
175 put ar_import_index 0 i
176 size = ar_region_bytes meta offsets i
177 if not ar_import_range records i size add base get offsets i
178 unused = ar_unmap
179 ret false
180 end
181 if eq i 0
182 for j ulong 16
183 if ne mapget get ar_maps 0 mul j 8 8 get meta j
184 unused = ar_unmap
185 ret false
186 end
187 end
188 end
189 end
190 ret true
191end
192
193note GraphMeta is the immutable plan-lock snapshot. Word 4 of WorkReceipt is
194note the single committed epoch cursor. Its parity selects the active bank
195note relative to that snapshot, so readers never observe a torn epoch/bank.
196note The authority serializes readers/writers and owns the new epoch grant.
197fn ar_snapshot_matches m view ulong 16 to bool
198 base = get ar_maps 0
199 receipt = get ar_maps 5
200 if or le base 0 le receipt 0
201 ret false
202 end
203 origin = mapget base 56 8
204 epoch = mapget receipt 32 8
205 if eq epoch 0
206 epoch = origin
207 end
208 if or eq origin 0 lt epoch origin
209 ret false
210 end
211 if ne epoch get m 7
212 ret false
213 end
214 bank = xor mapget base 48 8 and sub epoch origin 1
215 if ne bank get m 6
216 ret false
217 end
218 for i ulong 16
219 if or lt i 6 gt i 8
220 if ne mapget base mul i 8 8 get m i
221 ret false
222 end
223 end
224 end
225 if eq epoch origin
226 ret eq get m 8 mapget base 64 8
227 end
228 ret ne get m 8 0
229end