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
CUDApp / om / api / attn_art.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | fn ar_rd b view uchar * o ulong n ulong to ulong |
| 4 | v = ulong 0 |
| 5 | for i ulong n |
| 6 | v = or v shl ulong get b add o i mul i 8 |
| 7 | end |
| 8 | ret v |
| 9 | end |
| 10 | fn ar_eq b view uchar * off ulong s view uchar * to bool |
| 11 | if gt off len b |
| 12 | ret false |
| 13 | end |
| 14 | if gt len s sub len b off |
| 15 | ret false |
| 16 | end |
| 17 | for i ulong len s |
| 18 | if ne get b add off i get s i |
| 19 | ret false |
| 20 | end |
| 21 | end |
| 22 | ret true |
| 23 | end |
| 24 | fn ar_sect b view uchar * sh ulong str view ulong 2 fnm view uchar * to bool |
| 25 | name = ar_rd b sh 4 |
| 26 | if ge name get str 1 |
| 27 | ret false |
| 28 | end |
| 29 | off = add get str 0 name |
| 30 | left = sub get str 1 name |
| 31 | if le left add len fnm 6 |
| 32 | ret false |
| 33 | end |
| 34 | if ne get b off 46 |
| 35 | ret false |
| 36 | end |
| 37 | if ne get b add off 1 116 |
| 38 | ret false |
| 39 | end |
| 40 | if ne get b add off 2 101 |
| 41 | ret false |
| 42 | end |
| 43 | if ne get b add off 3 120 |
| 44 | ret false |
| 45 | end |
| 46 | if ne get b add off 4 116 |
| 47 | ret false |
| 48 | end |
| 49 | if ne get b add off 5 46 |
| 50 | ret false |
| 51 | end |
| 52 | if not ar_eq b add off 6 fnm |
| 53 | ret false |
| 54 | end |
| 55 | ret eq get b add add off 6 len fnm 0 |
| 56 | end |
| 57 | fn ar_data b view uchar * sh ulong txt view uchar * to bool |
| 58 | off = ar_rd b add sh 24 8 |
| 59 | sz = ar_rd b add sh 32 8 |
| 60 | if or gt off len b ne sz len txt |
| 61 | ret false |
| 62 | end |
| 63 | ret ar_eq b off txt |
| 64 | end |
| 65 | fn ar_cubin b view uchar * fnm view uchar * txt view uchar * to bool |
| 66 | if lt len b 64 |
| 67 | ret false |
| 68 | end |
| 69 | if ne ar_rd b 0 4 1179403647 |
| 70 | ret false |
| 71 | end |
| 72 | if ne ar_rd b 18 2 190 |
| 73 | ret false |
| 74 | end |
| 75 | shoff = ar_rd b 40 8 |
| 76 | num = ar_rd b 60 2 |
| 77 | idx = ar_rd b 62 2 |
| 78 | if or ne ar_rd b 58 2 64 or eq num 0 ge idx num |
| 79 | ret false |
| 80 | end |
| 81 | if gt shoff len b |
| 82 | ret false |
| 83 | end |
| 84 | if gt mul num 64 sub len b shoff |
| 85 | ret false |
| 86 | end |
| 87 | str = new ulong 2 0 |
| 88 | put str 0 ar_rd b add add shoff mul idx 64 24 8 |
| 89 | put str 1 ar_rd b add add shoff mul idx 64 32 8 |
| 90 | if gt get str 0 len b |
| 91 | ret false |
| 92 | end |
| 93 | if gt get str 1 sub len b get str 0 |
| 94 | ret false |
| 95 | end |
| 96 | note snprintf want[128] requires 6-byte prefix plus fn plus terminator to fit. |
| 97 | if ge add len fnm 6 128 |
| 98 | ret false |
| 99 | end |
| 100 | for i ulong num |
| 101 | sh = add shoff mul i 64 |
| 102 | if ar_sect b sh str fnm |
| 103 | ret ar_data b sh txt |
| 104 | end |
| 105 | end |
| 106 | ret false |
| 107 | end |
| 108 | fn ar_layout b view uchar * keys view uchar * cap ulong to bool |
| 109 | if ge len b cap |
| 110 | ret false |
| 111 | end |
| 112 | for i ulong len b |
| 113 | if or eq get b i 0 eq get b i 13 |
| 114 | ret false |
| 115 | end |
| 116 | end |
| 117 | pos = ulong 0 |
| 118 | idx = ulong 0 |
| 119 | first = true |
| 120 | while lt idx len keys |
| 121 | if eq get keys idx 0 |
| 122 | idx = add idx 1 |
| 123 | continue |
| 124 | end |
| 125 | while ne get keys idx 0 |
| 126 | if ge pos len b |
| 127 | ret false |
| 128 | end |
| 129 | if ne get keys idx get b pos |
| 130 | ret false |
| 131 | end |
| 132 | idx = add idx 1 |
| 133 | pos = add pos 1 |
| 134 | end |
| 135 | idx = add idx 1 |
| 136 | if first |
| 137 | first = false |
| 138 | else |
| 139 | while lt pos len b |
| 140 | c = get b pos |
| 141 | pos = add pos 1 |
| 142 | if eq c 10 |
| 143 | break |
| 144 | end |
| 145 | end |
| 146 | if eq pos 0 |
| 147 | ret false |
| 148 | end |
| 149 | if ne get b sub pos 1 10 |
| 150 | ret false |
| 151 | end |
| 152 | end |
| 153 | end |
| 154 | ret eq pos len b |
| 155 | end |
| 156 | fn ar_version h view uint 3 n view uint 3 to bool |
| 157 | for i ulong 3 |
| 158 | if ne get h i get n i |
| 159 | ret gt get h i get n i |
| 160 | end |
| 161 | end |
| 162 | ret true |
| 163 | end |
| 164 | fn ar_json c uchar d edit uchar 6 to ulong |
| 165 | if or eq c 34 eq c 92 |
| 166 | put d 0 92 |
| 167 | put d 1 c |
| 168 | ret 2 |
| 169 | end |
| 170 | if or lt c 32 eq c 127 |
| 171 | put d 0 92 |
| 172 | put d 1 117 |
| 173 | put d 2 48 |
| 174 | put d 3 48 |
| 175 | v = shr c 4 |
| 176 | if gt v 9 |
| 177 | v = add v 87 |
| 178 | else |
| 179 | v = add v 48 |
| 180 | end |
| 181 | put d 4 v |
| 182 | v = and c 15 |
| 183 | if gt v 9 |
| 184 | v = add v 87 |
| 185 | else |
| 186 | v = add v 48 |
| 187 | end |
| 188 | put d 5 v |
| 189 | ret 6 |
| 190 | end |
| 191 | put d 0 c |
| 192 | ret 1 |
| 193 | end |