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 / om / tools / ampcorp.om

202 lines · 5360 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note ampcorp: the decisions of tools/ampere_corpus.c (SM86 IR corpus capture). The C shell reads
3note OMEGA_AMPERE_CORPUS_DIR, runs the SM86 encoder, opens and writes the files and calls abort; this unit
4note checks the folder, builds the IR metadata, classifies the program (an FP8 marker or a training R5
5note opcode beyond MUFU.LG2 must be refused), checks the encoder outcome and formats the three file paths
6note "<dir>/<pid>-<serial>.<suffix>" and the unexpected-refusal message.
7note facts f (ulong 16): 0 mode (0 folder check, 1 capture); 1 folder length (in d); 2 instruction count;
8note 3 encoder rc (int64 bits); 4 bytes written; 5 SM121 length; 6 pid; 7 serial; the constants of the C
9note headers 8 BW_IR_MUFU_LG2, 9 BW_IR_HMMA_BF16, 10 OMEGA_QMMA_MARK, 11 BW_IR_FMNMX_MAX,
10note 12 OMEGA_QMMA_MARK_F2E4, 13 OMEGA_GPU_ENCODE_UNSUPPORTED (int64 bits). ins (ulong 2048): op, imm of
11note each instruction. code (uchar 16384): the SM86 buffer after the encoder.
12note Mode 0 returns 1 when the folder is safe. Mode 1 writes the metadata (op, imm as little-endian
13note uint32 pairs) at o 0 and returns 1 (save "refused" from the path at o 8192), 2 (save "sm121.bin",
14note "sm86.bin", "ir" from the paths at o 8192, 12288, 16384), 3 (abort: the refusal wrote bytes or
15note did not refuse), 4 + 256 * length (print the message at o 8192, then abort) or 5 (abort: the path
16note does not fit 4096 bytes). Paths end with a zero byte.
17const ACPATH ulong 8192
18const ACMAX ulong 4096
19fn ac_s o edit uchar 20480 p ulong w ulong n ulong to ulong
20i = ulong 0
21while lt i n bound 9
22put o add p i uchar and shr w mul i 8 255
23i = add i 1
24end
25ret add p n
26end
27fn ac_nd v ulong to ulong
28n = ulong 1
29x = div v 10
30while ne x 0 bound 20
31n = add n 1
32x = div x 10
33end
34ret n
35end
36fn ac_u o edit uchar 20480 p ulong v ulong to ulong
37w = ac_nd v
38k = add p w
39x = v
40for i ulong w
41k = sub k 1
42put o k uchar add 48 rem x 10
43x = div x 10
44end
45ret add p w
46end
47note ac_safe: is_safe_corpus_dir: not empty, no backslash, no ".." component.
48fn ac_safe d view uchar 131072 n ulong to ulong
49if eq n 0
50ret ulong 0
51end
52for i ulong n
53if eq get d i uchar 92
54ret ulong 0
55end
56end
57i = ulong 0
58while lt i n bound 131072
59while lt i n bound 131072
60if ne get d i uchar 47
61break
62end
63i = add i 1
64end
65s = i
66while lt i n bound 131072
67if eq get d i uchar 47
68break
69end
70i = add i 1
71end
72if eq sub i s 2
73if eq get d s uchar 46
74if eq get d add s 1 uchar 46
75ret ulong 0
76end
77end
78end
79end
80ret ulong 1
81end
82note ac_path: "<dir>/<pid>-<serial>." at o at; returns the position after it, or 0 when the path with a
83note suffix of sn bytes (without its zero) would not fit 4096 bytes.
84fn ac_path o edit uchar 20480 at ulong f view ulong 16 d view uchar 131072 sn ulong to ulong
85dn = get f 1
86pid = get f 6
87ser = get f 7
88n = add add add dn ac_nd pid ac_nd ser add sn 3
89if ge n ACMAX
90ret ulong 0
91end
92for i ulong dn
93put o add at i get d i
94end
95p = add at dn
96put o p uchar 47
97p = ac_u o add p 1 pid
98put o p uchar 45
99p = ac_u o add p 1 ser
100put o p uchar 46
101ret add p 1
102end
103note ac_msg: "SM86 unexpectedly refused an existing kernel (%zu instructions, rc %d)\n" at o 8192.
104fn ac_msg o edit uchar 20480 cnt ulong rc ulong to ulong
105p = ACPATH
106note s "SM86 unexpectedly refused an existing kernel ("
107p = ac_s o p 7308908026477956435 8
108p = ac_s o p 7810479204325486712 8
109p = ac_s o p 7310315702801539193 8
110p = ac_s o p 7599935561152929892 8
111p = ac_s o p 7307970448944886899 8
112p = ac_s o p 44119722651250 6
113p = ac_u o p cnt
114note s " instructions, rc "
115p = ac_s o p 7166760226508400928 8
116p = ac_s o p 8223621793864182132 8
117p = ac_s o p 8291 2
118v = rc
119if ne shr rc 63 0
120put o p uchar 45
121p = add p 1
122v = sub ulong 0 rc
123end
124p = ac_u o p v
125note s ")\n"
126p = ac_s o p 2601 2
127ret sub p ACPATH
128end
129note ac_meta: the metadata pairs at o 0; returns 1 when the program must be refused.
130fn ac_meta o edit uchar 20480 f view ulong 16 ins view ulong 2048 to ulong
131r = ulong 0
132for i ulong get f 2
133op = get ins mul i 2
134im = get ins add mul i 2 1
135x = ac_s o mul i 8 and op 4294967295 4
136x = ac_s o add mul i 8 4 im 4
137if gt and op 4294967295 get f 8
138r = ulong 1
139end
140if eq and op 4294967295 get f 9
141if eq im get f 10
142r = ulong 1
143end
144end
145if eq and op 4294967295 get f 11
146if eq im get f 12
147r = ulong 1
148end
149end
150end
151ret r
152end
153fn ac_cap f view ulong 16 d view uchar 131072 ins view ulong 2048 code view uchar 16384 o edit uchar 20480 to ulong
154rf = ac_meta o f ins
155rc = get f 3
156nb = get f 4
157if ne rf 0
158if or ne rc get f 13 ne nb 0
159ret ulong 3
160end
161for i ulong 16384
162if ne get code i uchar 165
163ret ulong 3
164end
165end
166p = ac_path o ACPATH f d 7
167if eq p 0
168ret ulong 5
169end
170note s "refused"
171p = ac_s o p 28259044236354930 7
172put o p uchar 0
173ret ulong 1
174end
175if or ne rc 0 ne nb get f 5
176ret add shl ac_msg o get f 2 rc 8 4
177end
178note sm121.bin is the longest suffix, so it alone can exceed 4096 bytes.
179p = ac_path o ACPATH f d 9
180if eq p 0
181ret ulong 5
182end
183note s "sm121.bin"
184p = ac_s o p 7593682710530452851 8
185p = ac_s o p 110 1
186put o p uchar 0
187p = ac_path o 12288 f d 8
188note s "sm86.bin"
189p = ac_s o p 7955998167344377203 8
190put o p uchar 0
191p = ac_path o 16384 f d 2
192note s "ir"
193p = ac_s o p 29289 2
194put o p uchar 0
195ret ulong 2
196end
197fn ampcorp f view ulong 16 d view uchar 131072 ins view ulong 2048 code view uchar 16384 o edit uchar 20480 to ulong
198if eq get f 0 0
199ret ac_safe d get f 1
200end
201ret ac_cap f d ins code o
202end