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 / om / gpu / dsv41 / decoder / index.om

212 lines · 4732 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note Offline tensor index. Each 160-byte record names a shard, a dtype,
3note dimensions and an absolute file extent. Source header pinning precedes
4note every descriptor. No lookup treats a file offset as a virtual address.
5text dsOffsets "data_offsets"
6text dsShape "shape"
7text dsType "dtype"
8
9fn diString src view uchar 261440 tape view uint 200000 key ulong outrec edit uchar 160 off ulong to bool
10 limit = ulong 15
11 if eq off 56
12 limit = 103
13 end
14 width = js_span tape key
15 if or lt width 3 gt sub width 2 limit
16 ret false
17 end
18 ret diCopy src add 1 js_off tape key sub width 2 outrec off
19end
20
21fn diCopy src view uchar 261440 pos ulong width ulong outrec edit uchar 160 off ulong to bool
22 for i ulong width
23 c = get src add pos i
24 if or lt c 32 or gt c 126 eq c 92
25 ret false
26 end
27 put outrec add off i c
28 end
29 ret true
30end
31
32fn diField src view uchar 261440 tape view uint 200000 obj ulong name view uchar * to ulong
33 k = js_first tape obj
34 while ne k jsnone
35 if js_streq src js_off tape k name
36 ret add k 1
37 end
38 k = js_mnext tape k
39 end
40 ret jsnone
41end
42
43fn diValue src view uchar 261440 tape view uint 200000 t ulong to ulong
44 if ne js_type tape t jsnum
45 ret 18446744073709551615
46 end
47 off = js_off tape t
48 if not js_isu src off
49 ret 18446744073709551615
50 end
51 ret js_imag src off
52end
53
54fn diShape src view uchar 261440 tape view uint 200000 obj ulong outrec edit uchar 160 to bool
55 t = diField src tape obj dsShape
56 if ne js_type tape t jsarr
57 ret false
58 end
59 rank = js_nkids tape t
60 if gt rank 4
61 ret false
62 end
63 put outrec 2 uchar rank
64 item = js_first tape t
65 for i ulong rank bound 4
66 v = diValue src tape item
67 if gt v 0xffffffff
68 ret false
69 end
70 diPut outrec add 24 mul i 4 4 v
71 item = js_enext tape item
72 end
73 t = diField src tape obj dsType
74 if ne js_type tape t jsstr
75 ret false
76 end
77 ret diString src tape t outrec 40
78end
79
80fn diExtent src view uchar 261440 tape view uint 200000 obj ulong bounds view ulong 3 outrec edit uchar 160 to bool
81 t = diField src tape obj dsOffsets
82 if or ne js_type tape t jsarr ne js_nkids tape t 2
83 ret false
84 end
85 item = js_first tape t
86 lo = diValue src tape item
87 hi = diValue src tape js_enext tape item
88 if or gt lo hi gt hi sub get bounds 1 get bounds 0
89 ret false
90 end
91 diPut outrec 8 8 add get bounds 0 lo
92 diPut outrec 16 8 sub hi lo
93 ret true
94end
95
96fn diEmit src view uchar 261440 tape view uint 200000 key ulong bounds view ulong 3 to bool
97 outrec = new uchar 160 0
98 put outrec 0 uchar get bounds 2
99 if not diString src tape key outrec 56
100 ret false
101 end
102 obj = add key 1
103 if ne js_type tape obj jsobj
104 ret false
105 end
106 if not diShape src tape obj outrec
107 ret false
108 end
109 if not diExtent src tape obj bounds outrec
110 ret false
111 end
112 used = ulong 0
113 while lt used 160
114 n = write 1 outrec used sub 160 used
115 if eq n -4
116 continue
117 end
118 if le n 0
119 ret false
120 end
121 used = add used ulong n
122 end
123 ret true
124end
125
126fn diCheckHeader src view uchar * shard ulong count ulong to bool
127 for i ulong count
128 put sh_dat i get src i
129 end
130 sh_all count
131 pos = mul sub shard 1 64
132 for i ulong 32
133 v = uint get sh_dig i
134 if ne get dsHeaderPins add pos mul i 2 sh_hexd shr v 4
135 ret false
136 end
137 if ne get dsHeaderPins add pos add mul i 2 1 sh_hexd and v 15
138 ret false
139 end
140 end
141 ret true
142end
143
144fn diShard fd int shard ulong to bool
145 size = fseek fd 0 2
146 if ne size long dsFileBytes shard
147 ret false
148 end
149 prefix = new uchar 8 0
150 if not diRead fd prefix 0 8
151 ret false
152 end
153 count = ulong 0
154 for i ulong 8
155 count = or count shl ulong get prefix i mul i 8
156 end
157 src = new uchar 261440 0
158 tape = new uint 200000 0
159 if or eq count 0 gt count len src
160 ret false
161 end
162 if not diRead fd src 8 count
163 ret false
164 end
165 if not diCheckHeader src shard count
166 ret false
167 end
168 if ne js_init tape count 64 0
169 ret false
170 end
171 if lt js_parse src tape count 0
172 ret false
173 end
174 bounds = new ulong 3 0
175 put bounds 0 add count 8
176 put bounds 1 ulong size
177 put bounds 2 shard
178 key = js_first tape 0
179 while ne key jsnone
180 if not diEmit src tape key bounds
181 ret false
182 end
183 key = js_mnext tape key
184 end
185 ret true
186end
187
188fn main to int
189 if ne argcnt 49
190 ret 64
191 end
192 path = new uchar 4096 0
193 for i ulong 48
194 shard = add i 1
195 n = argread shard path 0 4096
196 if le n 0
197 ret 64
198 end
199 fd = fopen path 0 ulong n 524288 0
200 if lt fd 0
201 ret 66
202 end
203 ok = diShard int fd shard
204 if ne fclose int fd 0
205 ret 74
206 end
207 if not ok
208 ret 65
209 end
210 end
211 ret 0
212end