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/gemm-any/host.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 / gemm-any / host.om` 256 lines · 4429 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note x32: type rt ct wm wn stall mutant band M N K layout lda ldb A B AP BP C. 3 note p64: Mp Np Kp KS2 a_bytes b_bytes ap_bytes bp_bytes grid[6] threads[3], spans[2], effective_ld[2]. 4 note p24..53 launch argument words; p54 first launch. Result 0 OK, 1 BAD_ARGS, 2 TOO_LARGE. 5 fn gh_pow v ulong to bool 6 ret or eq v 1 or eq v 2 eq v 4 7 end 8 fn gh_esz t ulong to ulong 9 if eq t 1 10 ret 1 11 end 12 if eq t 3 13 ret 4 14 end 15 ret 2 16 end 17 fn gh_step t ulong to ulong 18 if eq t 1 19 ret 32 20 end 21 ret 16 22 end 23 fn gh_round v ulong m ulong to ulong 24 ret mul div add v sub m 1 m m 25 end 26 fn gemm_host_value op ulong a ulong b ulong c ulong d ulong to ulong 27 if eq op 0 28 ret gh_esz a 29 end 30 if eq op 1 31 ret gh_step a 32 end 33 if eq op 2 34 if le a 3 35 ret 1 36 end 37 ret 0 38 end 39 if eq op 3 40 ret and mul 4 add add mul 4 a mul 2 b mul a b `4294967295` 41 end 42 if eq op 4 43 ret and add a 255 `18446744073709551360` 44 end 45 if eq op 5 46 if and ne a 0 ge b c 47 ret 1 48 end 49 ret 0 50 end 51 if eq op 6 52 if and eq a 1 and eq b 48 eq c 0 53 ret 0 54 end 55 ret 1 56 end 57 ret d 58 end 59 fn gemm_host_cfg x view ulong 32 to ulong 60 if gt get x 0 3 61 ret 0 62 end 63 for i ulong 4 64 if not gh_pow get x add i 1 65 ret 0 66 end 67 end 68 if or lt get x 5 1 gt get x 5 15 69 ret 0 70 end 71 if gt get x 6 3 72 ret 0 73 end 74 b = get x 7 75 if or gt b 32 ne and b sub b 1 0 76 ret 0 77 end 78 ret 1 79 end 80 fn gh_pack groups ulong ks2 ulong frag ulong to ulong 81 ret mul mul add mul groups ks2 2 frag 512 82 end 83 fn gemm_host_plan x view ulong 32 p edit ulong 64 to ulong 84 if eq gemm_host_cfg x 0 85 ret 1 86 end 87 for i ulong 3 88 if eq get x add i 8 0 89 ret 1 90 end 91 end 92 for i ulong 3 93 if gt get x add i 8 16384 94 ret 2 95 end 96 end 97 for i ulong 64 98 put p i 0 99 end 100 ks = gh_step get x 0 101 hga = mul 16 get x 1 102 hgb = mul 8 get x 2 103 put p 0 gh_round get x 8 mul hga get x 3 104 put p 1 gh_round get x 9 mul hgb get x 4 105 put p 2 gh_round get x 10 mul 4 ks 106 put p 3 div get p 2 mul 2 ks 107 put p 4 mul mul get x 8 get x 10 gh_esz get x 0 108 put p 5 mul mul get x 10 get x 9 gh_esz get x 0 109 put p 6 gh_pack div get p 0 hga get p 3 mul 2 get x 1 110 put p 7 gh_pack div get p 1 hgb get p 3 get x 2 111 put p 8 get p 3 112 put p 9 div get p 0 hga 113 put p 10 get p 3 114 put p 11 div get p 1 hgb 115 put p 12 div get p 1 mul hgb get x 4 116 put p 13 div get p 0 mul hga get x 3 117 if gt get x 7 1 118 gx = get p 12 119 gy = get p 13 120 band = get x 7 121 put p 12 mul band gy 122 put p 13 div add gx sub band 1 band 123 end 124 put p 14 128 125 put p 15 128 126 put p 16 mul mul 32 get x 3 get x 4 127 if eq get x 0 3 128 put p 6 0 129 put p 7 0 130 for i ulong 9 131 put p add 8 i 0 132 end 133 put p 12 div add get x 9 127 128 134 put p 13 get x 8 135 put p 16 128 136 end 137 ret 0 138 end 139 note Stored spans use 64-bit arithmetic exactly as C; outer,inner,ld originate from u32. 140 fn gh_span col ulong rows ulong kk ulong ld ulong to ulong 141 ou = rows 142 iu = kk 143 if ne col 0 144 ou = kk 145 iu = rows 146 end 147 if eq ld 0 148 ld = iu 149 end 150 if or lt ld iu gt ld `4294967295` 151 ret 0 152 end 153 sp = add mul sub ou 1 ld iu 154 if gt sp `4294967295` 155 ret 0 156 end 157 ret sp 158 end 159 fn gemm_host_span x view ulong 32 p edit ulong 64 to ulong 160 if gt get x 11 3 161 ret 1 162 end 163 for i ulong 3 164 if eq get x add i 8 0 165 ret 1 166 end 167 end 168 sa = gh_span and get x 11 1 get x 8 get x 10 get x 12 169 sb = gh_span and xor get x 11 2 2 get x 9 get x 10 get x 13 170 if or eq sa 0 eq sb 0 171 ret 1 172 end 173 put p 17 sa 174 put p 18 sb 175 put p 19 get x 12 176 if eq get x 12 0 177 put p 19 get x 10 178 if ne and get x 11 1 0 179 put p 19 get x 8 180 end 181 end 182 put p 20 get x 13 183 if eq get x 13 0 184 put p 20 get x 9 185 if ne and get x 11 2 0 186 put p 20 get x 10 187 end 188 end 189 ret 0 190 end 191 fn gh_put64 p edit ulong 64 w ulong v ulong to void 192 put p w and v `4294967295` 193 put p add w 1 shr v 32 194 end 195 fn gemm_host_drive x view ulong 32 p edit ulong 64 to ulong 196 if gt get x 11 3 197 ret 1 198 end 199 rc = gemm_host_plan x p 200 if ne rc 0 201 ret rc 202 end 203 rc = gemm_host_span x p 204 if ne rc 0 205 ret rc 206 end 207 if eq get x 0 3 208 if ne get x 11 0 209 ret 1 210 end 211 if ne get p 19 get x 10 212 ret 1 213 end 214 if ne get p 20 get x 9 215 ret 1 216 end 217 put p 54 2 218 gh_put64 p 44 get x 14 219 gh_put64 p 46 get x 15 220 gh_put64 p 48 get x 18 221 put p 50 get x 8 222 put p 51 get x 9 223 put p 52 get x 10 224 ret 0 225 end 226 gh_put64 p 24 get x 14 227 gh_put64 p 26 get x 16 228 put p 28 get x 8 229 put p 29 get x 10 230 put p 30 get p 19 231 put p 31 1 232 if ne and get x 11 1 0 233 put p 30 1 234 put p 31 get p 19 235 end 236 put p 32 get p 3 237 gh_put64 p 34 get x 15 238 gh_put64 p 36 get x 17 239 put p 38 get x 9 240 put p 39 get x 10 241 put p 40 1 242 put p 41 get p 20 243 if ne and get x 11 2 0 244 put p 40 get p 20 245 put p 41 1 246 end 247 put p 42 get p 3 248 gh_put64 p 44 get x 16 249 gh_put64 p 46 get x 17 250 gh_put64 p 48 get x 18 251 put p 50 get x 8 252 put p 51 get x 9 253 put p 52 get p 3 254 put p 53 div get p 1 mul mul 8 get x 2 get x 4 255 ret 0 256 end