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 / seed / ng / gpu / encrun.om

159 lines · 3769 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/gpu/encrun.om: conformance harness for the sm_121 encoder ng consumes (Hive NG lane ng-gpu, D10).
3note Not an encoder: it composes AFTER gpu/nvidia/om/encoder/bw_enc_sm121.om (the sha in seed/ng/cudapp.lock):
4note cat gpu/nvidia/om/encoder/bw_enc_sm121.om seed/ng/gpu/encrun.om | seed/out/omc > encrun
5note Program mode, AArch64 Linux. stdin is a stream of NGBWENC1 frames, stdout one result frame per input frame.
6note Input frame (every word a 64-bit little-endian unsigned):
7note 8 bytes "NGBWENC1" | n | pad | 288 words phys | n*8 words ins (none when n > 1024)
8note phys and ins are exactly the arrays bw_enc_sm121 takes (see its header): 8 words per solved BlackwellIR
9note instruction, vreg 0..255 then uvreg 256..287 physical registers. ins words past n*8 are zero, as the
10note CUDApp C caller zeroes them. pad 1: NOP-pad to a multiple of 8, at least 32 instructions.
11note Output frame: one word r (the bytes encoded; 0 = refused) then the r code bytes.
12note Exit: 0 after a whole number of frames; 2 bad magic; 3 truncated frame; 4 read error; 5 write error,
13note each with one stderr line. Output written before an error stays written.
14
15text g_emag "NGBWENC1"
16text g_em2 "encrun: bad frame magic\n"
17text g_em3 "encrun: truncated frame\n"
18text g_em4 "encrun: read error\n"
19text g_em5 "encrun: write error\n"
20
21fn gp_efail c ulong to int
22if eq c 2
23k = write 2 g_em2 0 len g_em2
24end
25if eq c 3
26k = write 2 g_em3 0 len g_em3
27end
28if eq c 4
29k = write 2 g_em4 0 len g_em4
30end
31if eq c 5
32k = write 2 g_em5 0 len g_em5
33end
34ret int c
35end
36
37note exactly n bytes of stdin into b from 0: n, fewer only at the end of input, -1 on a read error
38fn gp_eread b edit uchar 65536 n ulong to long
39got = ulong 0
40note every pass consumes at least one byte of at most 65536
41while lt got n bound 65537
42k = read 0 b got sub n got
43if lt k 0
44ret -1
45end
46if eq k 0
47ret long got
48end
49got = add got ulong k
50end
51ret long got
52end
53
54note all n bytes of b to stdout: 0, or 1 on a write error or a zero-length write
55fn gp_ewrite b view uchar 16392 n ulong to ulong
56wr = ulong 0
57while lt wr n bound 16393
58k = write 1 b wr sub n wr
59if le k 0
60ret 1
61end
62wr = add wr ulong k
63end
64ret 0
65end
66
67fn gp_ele b view uchar 65536 off ulong to ulong
68w = ulong 0
69for i ulong 8
70w = or w shl ulong get b add off i mul i 8
71end
72ret w
73end
74
75note one frame body after the 24 header bytes into phys and ins; gives 0, or the exit code
76fn gp_eframe ib edit uchar 65536 n ulong ins edit ulong 8192 phys edit ulong 288 to ulong
77k = gp_eread ib 2304
78if lt k 0
79ret 4
80end
81if ne k 2304
82ret 3
83end
84for i ulong 288
85put phys i gp_ele ib mul i 8
86end
87for i ulong 8192
88put ins i 0
89end
90rows = n
91if gt n 1024
92rows = 0
93end
94if gt rows 0
95nb = mul rows 64
96k = gp_eread ib nb
97if lt k 0
98ret 4
99end
100if ne ulong k nb
101ret 3
102end
103for i ulong mul rows 8
104put ins i gp_ele ib mul i 8
105end
106end
107ret 0
108end
109
110note encode one frame and write its result frame; gives 0, or the exit code
111fn gp_eout ins view ulong 8192 phys view ulong 288 n ulong pad ulong ob edit uchar 16392 to ulong
112code = new uchar 16384 0
113r = bw_enc_sm121 ins phys n pad code
114for i ulong 8
115put ob i uchar and shr r mul i 8 255
116end
117for i ulong r
118put ob add i 8 get code i
119end
120if ne gp_ewrite ob add r 8 0
121ret 5
122end
123ret 0
124end
125
126fn main to int
127ib = new uchar 65536 0
128ins = new ulong 8192 0
129phys = new ulong 288 0
130ob = new uchar 16392 0
131note at most 1000000 frames: each frame is at least 2328 bytes
132while true bound 1000000
133k = gp_eread ib 24
134if lt k 0
135ret gp_efail 4
136end
137if eq k 0
138ret 0
139end
140if ne k 24
141ret gp_efail 3
142end
143for i ulong 8
144if ne get ib i get g_emag i
145ret gp_efail 2
146end
147end
148n = gp_ele ib 8
149pad = gp_ele ib 16
150c = gp_eframe ib n ins phys
151if eq c 0
152c = gp_eout ins phys n pad ob
153end
154if ne c 0
155ret gp_efail c
156end
157end
158ret 0
159end