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 / components / api_mm_plan.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | fn mm_dims a edit ulong 16 to ulong |
| 3 | m = get a 0 |
| 4 | k = get a 1 |
| 5 | n = get a 2 |
| 6 | if or eq m 0 or eq k 0 eq n 0 |
| 7 | ret 1 |
| 8 | end |
| 9 | if or gt m 8192 or gt k 16384 gt n 262144 |
| 10 | ret 2 |
| 11 | end |
| 12 | if or gt get a 3 262144 gt get a 4 128 |
| 13 | ret 2 |
| 14 | end |
| 15 | m = mul div add m 15 16 16 |
| 16 | k = mul div add k 15 16 16 |
| 17 | n = mul div add n 7 8 8 |
| 18 | put a 8 m |
| 19 | put a 9 k |
| 20 | put a 10 n |
| 21 | put a 11 mul mul m k 2 |
| 22 | put a 13 mul mul k n 2 |
| 23 | k = mul mul m n 4 |
| 24 | n = get a 3 |
| 25 | n = mul div add n 7 8 8 |
| 26 | n = mul n 64 |
| 27 | if gt n k |
| 28 | k = n |
| 29 | end |
| 30 | put a 12 k |
| 31 | put a 14 mul get a 1 get a 2 |
| 32 | ret 0 |
| 33 | end |
| 34 | fn mm_tiles a edit ulong 16 to void |
| 35 | mt = div get a 0 16 |
| 36 | nt = div get a 1 8 |
| 37 | r = ulong 1 |
| 38 | c = ulong 1 |
| 39 | if eq rem mt 2 0 |
| 40 | r = 2 |
| 41 | end |
| 42 | if eq rem mt 4 0 |
| 43 | r = 4 |
| 44 | end |
| 45 | while gt r 1 bound 2 |
| 46 | c = 1 |
| 47 | if eq rem nt 2 0 |
| 48 | c = 2 |
| 49 | end |
| 50 | if eq rem nt 4 0 |
| 51 | c = 4 |
| 52 | end |
| 53 | fit = mul sub r 1 64 |
| 54 | fit = mul fit get a 1 |
| 55 | fit = add fit mul sub c 1 32 |
| 56 | if lt add fit 4 8388608 |
| 57 | break |
| 58 | end |
| 59 | r = div r 2 |
| 60 | end |
| 61 | if eq r 1 |
| 62 | c = 1 |
| 63 | end |
| 64 | put a 10 r |
| 65 | put a 11 c |
| 66 | end |
| 67 | fn mm_grid a edit ulong 16 to ulong |
| 68 | mm_tiles a |
| 69 | budget = get a 2 |
| 70 | if eq budget 0 |
| 71 | budget = 1024 |
| 72 | end |
| 73 | rows = get a 0 |
| 74 | r = get a 10 |
| 75 | rb = div div rows 16 r |
| 76 | if gt rb budget |
| 77 | rows = mul mul budget 16 r |
| 78 | end |
| 79 | gx = div budget div div rows 16 r |
| 80 | if eq gx 0 |
| 81 | gx = 1 |
| 82 | end |
| 83 | rb = div div get a 1 8 get a 11 |
| 84 | if gt gx rb |
| 85 | gx = rb |
| 86 | end |
| 87 | put a 8 rows |
| 88 | put a 9 gx |
| 89 | put a 12 div div rows 16 r |
| 90 | ret 0 |
| 91 | end |
| 92 | fn api_mm_plan mode ulong a edit ulong 16 to ulong |
| 93 | if eq mode 0 |
| 94 | ret mm_dims a |
| 95 | end |
| 96 | if eq mode 3 |
| 97 | v = and add get a 0 sub get a 1 1 4294967295 |
| 98 | put a 8 mul div v get a 1 get a 1 |
| 99 | ret 0 |
| 100 | end |
| 101 | if eq mode 1 |
| 102 | ret mm_grid a |
| 103 | end |
| 104 | if eq mode 2 |
| 105 | chunk = ulong 64 |
| 106 | if ne get a 3 0 |
| 107 | fit = div 262144 mul get a 0 8 |
| 108 | if lt fit chunk |
| 109 | chunk = fit |
| 110 | end |
| 111 | end |
| 112 | last = add get a 2 chunk |
| 113 | if lt sub get a 1 get a 2 chunk |
| 114 | last = get a 1 |
| 115 | end |
| 116 | put a 8 chunk |
| 117 | put a 9 last |
| 118 | ret 0 |
| 119 | end |
| 120 | if eq mode 4 |
| 121 | if or ne get a 0 get a 2 ne get a 1 get a 3 |
| 122 | ret 1 |
| 123 | end |
| 124 | ret 0 |
| 125 | end |
| 126 | if eq mode 5 |
| 127 | ks = div get a 0 16 |
| 128 | blk = or gt get a 1 1 gt get a 2 1 |
| 129 | u = ulong 1 |
| 130 | if blk |
| 131 | if eq rem ks 2 0 |
| 132 | sum = add get a 1 get a 2 |
| 133 | if le mul sum 2 8 |
| 134 | u = 2 |
| 135 | end |
| 136 | end |
| 137 | else |
| 138 | u = get a 3 |
| 139 | if eq u 0 |
| 140 | u = 1 |
| 141 | if eq rem ks 2 0 |
| 142 | u = 2 |
| 143 | end |
| 144 | if eq rem ks 4 0 |
| 145 | u = 4 |
| 146 | end |
| 147 | end |
| 148 | end |
| 149 | if and ne get a 4 0 or blk eq get a 3 0 |
| 150 | while and gt u 1 lt div ks u 2 |
| 151 | u = div u 2 |
| 152 | end |
| 153 | end |
| 154 | put a 8 ulong 0 |
| 155 | if blk |
| 156 | put a 8 ulong 1 |
| 157 | end |
| 158 | put a 9 u |
| 159 | ret 0 |
| 160 | end |
| 161 | if eq mode 6 |
| 162 | c = mul get a 0 8 |
| 163 | w = mul get a 1 8 |
| 164 | if gt w get a 2 |
| 165 | w = get a 2 |
| 166 | end |
| 167 | put a 8 c |
| 168 | put a 9 sub w c |
| 169 | ret 0 |
| 170 | end |
| 171 | if eq mode 7 |
| 172 | rows = get a 0 |
| 173 | if gt rows get a 1 |
| 174 | rows = get a 1 |
| 175 | end |
| 176 | put a 8 rows |
| 177 | put a 9 div div rows 16 get a 2 |
| 178 | ret 0 |
| 179 | end |
| 180 | if eq mode 8 |
| 181 | rows = get a 0 |
| 182 | if eq rows 0 |
| 183 | rows = 1024 |
| 184 | end |
| 185 | put a 8 rows |
| 186 | ret 0 |
| 187 | end |
| 188 | ret 1 |
| 189 | end |