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