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 / session / admit.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Session admission and bookkeeping decisions from src/omega_gpu_session.c. |
| 3 | note Pure computation: no host words, no platform calls. The C shell keeps the |
| 4 | note lock, the atomic stores and every dma, queue and sync call. decide is the |
| 5 | note only export; op selects the decision and a carries the inputs. |
| 6 | const WMASK ulong 4294967295 |
| 7 | const PAGEMSK ulong 18446744073709547520 |
| 8 | const PAGE ulong 4096 |
| 9 | const EPOCHX ulong 18446744073709551615 |
| 10 | const SIGN ulong 2147483648 |
| 11 | const REFUSED ulong 18446744073709551615 |
| 12 | const HOOKMAX ulong 8 |
| 13 | |
| 14 | fn roundup v ulong q ulong to ulong |
| 15 | a = and v WMASK |
| 16 | b = and q WMASK |
| 17 | if eq b 0 |
| 18 | ret 0 |
| 19 | end |
| 20 | ret and mul div add a sub b 1 b b WMASK |
| 21 | end |
| 22 | |
| 23 | fn pageup b ulong to ulong |
| 24 | r = and add b sub PAGE 1 PAGEMSK |
| 25 | if lt r PAGE |
| 26 | ret PAGE |
| 27 | end |
| 28 | ret r |
| 29 | end |
| 30 | |
| 31 | fn spinok us ulong mx ulong to ulong |
| 32 | if gt and us WMASK and mx WMASK |
| 33 | ret 1 |
| 34 | end |
| 35 | ret 0 |
| 36 | end |
| 37 | |
| 38 | fn gprcount c ulong to ulong |
| 39 | a = and c WMASK |
| 40 | if gt a 64 |
| 41 | ret roundup a 8 |
| 42 | end |
| 43 | ret 64 |
| 44 | end |
| 45 | |
| 46 | fn argsoff amp ulong to ulong |
| 47 | if ne and amp WMASK 0 |
| 48 | ret 352 |
| 49 | end |
| 50 | ret 896 |
| 51 | end |
| 52 | |
| 53 | fn semva amp ulong marker ulong qmd ulong to ulong |
| 54 | if ne and amp WMASK 0 |
| 55 | ret add marker 32 |
| 56 | end |
| 57 | ret add qmd 8192 |
| 58 | end |
| 59 | |
| 60 | fn scratch o edit ulong 4 bytes ulong cap ulong reserved ulong cpu ulong high ulong to ulong |
| 61 | b = bytes |
| 62 | c = cap |
| 63 | if ne and reserved WMASK 0 |
| 64 | if gt b c |
| 65 | put o 0 high |
| 66 | ret 2 |
| 67 | end |
| 68 | if eq and cpu WMASK 0 |
| 69 | put o 0 high |
| 70 | ret 2 |
| 71 | end |
| 72 | end |
| 73 | if gt b high |
| 74 | high = b |
| 75 | end |
| 76 | put o 0 high |
| 77 | if ge c b |
| 78 | if ne and cpu WMASK 0 |
| 79 | ret 0 |
| 80 | end |
| 81 | end |
| 82 | ret 1 |
| 83 | end |
| 84 | |
| 85 | fn freedec blocked ulong opened ulong plat ulong to ulong |
| 86 | if ne and blocked WMASK 0 |
| 87 | ret 0 |
| 88 | end |
| 89 | if eq and opened WMASK 0 |
| 90 | ret 3 |
| 91 | end |
| 92 | if eq and plat WMASK 0 |
| 93 | ret 3 |
| 94 | end |
| 95 | ret 2 |
| 96 | end |
| 97 | |
| 98 | fn opendec blocked ulong epoch ulong plat ulong opened ulong to ulong |
| 99 | if ne and blocked WMASK 0 |
| 100 | ret 1 |
| 101 | end |
| 102 | if ne and opened WMASK 0 |
| 103 | ret 2 |
| 104 | end |
| 105 | if eq epoch EPOCHX |
| 106 | ret 3 |
| 107 | end |
| 108 | if eq and plat WMASK 0 |
| 109 | ret 4 |
| 110 | end |
| 111 | ret 0 |
| 112 | end |
| 113 | |
| 114 | fn platdec opened ulong locked ulong blocked ulong to ulong |
| 115 | if ne and opened WMASK 0 |
| 116 | ret 1 |
| 117 | end |
| 118 | if ne and locked WMASK 0 |
| 119 | ret 1 |
| 120 | end |
| 121 | if ne and blocked WMASK 0 |
| 122 | ret 1 |
| 123 | end |
| 124 | ret 0 |
| 125 | end |
| 126 | |
| 127 | fn recovdec latched ulong opened ulong plat ulong to ulong |
| 128 | if eq and latched WMASK 0 |
| 129 | ret 2 |
| 130 | end |
| 131 | if eq and opened WMASK 0 |
| 132 | ret 1 |
| 133 | end |
| 134 | if eq and plat WMASK 0 |
| 135 | ret 1 |
| 136 | end |
| 137 | ret 0 |
| 138 | end |
| 139 | |
| 140 | fn hookdec nhooks ulong present ulong to ulong |
| 141 | if ge and nhooks WMASK HOOKMAX |
| 142 | ret 1 |
| 143 | end |
| 144 | if eq and present WMASK 0 |
| 145 | ret 1 |
| 146 | end |
| 147 | ret 0 |
| 148 | end |
| 149 | |
| 150 | fn slice left ulong to ulong |
| 151 | a = and left WMASK |
| 152 | if lt a 1 |
| 153 | ret a |
| 154 | end |
| 155 | ret 1 |
| 156 | end |
| 157 | |
| 158 | fn mdone seen ulong want ulong to ulong |
| 159 | d = and sub seen want WMASK |
| 160 | if lt d SIGN |
| 161 | ret 0 |
| 162 | end |
| 163 | ret 1 |
| 164 | end |
| 165 | |
| 166 | fn decide op ulong a view ulong 16 o edit ulong 4 to ulong |
| 167 | if eq op 0 |
| 168 | ret roundup get a 0 get a 1 |
| 169 | end |
| 170 | if eq op 1 |
| 171 | ret pageup get a 0 |
| 172 | end |
| 173 | if eq op 2 |
| 174 | ret spinok get a 0 get a 1 |
| 175 | end |
| 176 | if eq op 3 |
| 177 | ret gprcount get a 0 |
| 178 | end |
| 179 | if eq op 4 |
| 180 | ret argsoff get a 0 |
| 181 | end |
| 182 | if eq op 5 |
| 183 | ret semva get a 0 get a 1 get a 2 |
| 184 | end |
| 185 | if eq op 6 |
| 186 | ret scratch o get a 0 get a 1 get a 2 get a 3 get a 4 |
| 187 | end |
| 188 | if eq op 7 |
| 189 | ret freedec get a 0 get a 1 get a 2 |
| 190 | end |
| 191 | if eq op 8 |
| 192 | ret opendec get a 0 get a 1 get a 2 get a 3 |
| 193 | end |
| 194 | if eq op 9 |
| 195 | ret platdec get a 0 get a 1 get a 2 |
| 196 | end |
| 197 | if eq op 10 |
| 198 | ret recovdec get a 0 get a 1 get a 2 |
| 199 | end |
| 200 | if eq op 11 |
| 201 | ret hookdec get a 0 get a 1 |
| 202 | end |
| 203 | if eq op 12 |
| 204 | ret slice get a 0 |
| 205 | end |
| 206 | if eq op 13 |
| 207 | ret mdone get a 0 get a 1 |
| 208 | end |
| 209 | ret REFUSED |
| 210 | end |