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/native/aiengpu/context.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 / native / aiengpu / context.om` 228 lines · 5465 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note aien-gpu compute ABI 1 client decisions and request bytes (CUDApp#128). Successor of the logic in 3 note src/omega_gpu_platform_aien.c; that C stays behind CUDAPP_MIGRATION_PENDING_C_PLATFORM_AIEN as the oracle. 4 note Layouts: third_party/aien-gpu-abi1/aien_gpu_uapi.h, little endian, reserved bytes zero. The open, ioctl, 5 note mmap and doorbell/USERD stores stay in the C host binding until devctl accepts the AGPU requests. 6 note m[0] operation, m[1..] arguments; b is one 128-byte request or reply block (the largest struct is 112). 7 note 1 info check: b=agpu_info; 0 usable, 1 abi is not 1, 2 state is not RM_READY (4). 8 note 2 mem size: m1 bytes; page-rounded size, or 0 when bytes is 0 or above 2^37. 9 note 3 VA start: m1 cursor; the cursor, or the window base when it lies outside [2^36, 2^40). 10 note 4 VA align: m1 x, m2 align; x rounded up to max(align, 4096). 11 note 5 VA try: m1 at, m2 size, m3 wrapped, m4 start; 0 reserve at, 1 give up, 2 wrap to the base. 12 note 6 VA base, 7 VA top. 8 VA step: m1 at, m2 size, m3 align; next candidate after a taken range. 13 note 9 MEM_ALLOC request: m1 size, m2 va, m3 flags; writes b, returns 48 (bytes of the request). 14 note 10 rm ok: m1 offset of agpu_rm_status in b; 1 when its verdict is AGPU_RM_OK (1). 15 note 11 MEM_FREE request: m1 handle; returns 24. 12 CHAN_CREATE request: m1 ring/USERD handle, m2 notifier 16 note handle; 1024 entries, ring at 0, USERD at 8192; returns 72. 13 CHAN_DESTROY request: m1 channel; 24. 17 note 14 cache policy: m1 kind, m2 rights, m3 cache; 1 GPU-uncached flag, 0 GPU-cached, 2 refused. 18 note 15 range: m1 size, m2 off, m3 len; 1 inside. 16 poll check: m1 rights, m2 off, m3 size; 19 note 0 ok, 1 not HOST_POLLED, 2 misaligned, 3 out of range. 17 serial compare: m1 observed, m2 target; 20 note 1 when (int32)(observed - target) >= 0. 21 note 18 submit plan: m1 nwords, m2 words present, m3 L2 invalidate pending, m4 pushbuffer bytes, m5 put, 22 note m6 retired, m7 pushbuffer VA. 0 accepted, 1 bad args, 2 bad length, 3 ring full. Accepted writes 23 note b[0..20) prefix words, b[24..32) GP entry, b[32..36) ring slot, b[36..40) new GPPut, b[40..44) 24 note prefix words, b[44..48) total words. 25 note 19 GP entry: m1 va, m2 words. Any other operation returns 0 and writes nothing. 26 const AGBASE ulong `68719476736` 27 const AGTOP ulong `1099511627776` 28 const AGMAXB ulong `137438953472` 29 const AGPAGE ulong 4096 30 const AGGPMAX ulong `2097151` 31 const AGRING ulong 1024 32 const AGUSERD ulong 8192 33 const AGUNC ulong 1 34 fn ag_put b edit uchar 128 off ulong v ulong n ulong to void 35 for i ulong 8 36 if ge i n 37 break 38 end 39 put b add off i uchar and shr v mul i 8 255 40 end 41 end 42 fn ag_load b edit uchar 128 off ulong n ulong to ulong 43 v = ulong 0 44 for i ulong 8 45 if ge i n 46 break 47 end 48 v = or v shl ulong get b add off i mul i 8 49 end 50 ret v 51 end 52 fn ag_clear b edit uchar 128 to void 53 for i ulong 128 54 put b i uchar 0 55 end 56 end 57 fn ag_align x ulong a ulong to ulong 58 al = a 59 if lt al AGPAGE 60 al = AGPAGE 61 end 62 y = sub add x al 1 63 ret sub y and y sub al 1 64 end 65 fn ag_gp va ulong n ulong to ulong 66 ret or or sub va and va 3 shl and n AGGPMAX 42 shl ulong 1 41 67 end 68 fn ag_submit m view ulong 16 b edit uchar 128 to ulong 69 if or eq get m 2 0 eq get m 1 0 70 ret 1 71 end 72 pre = ulong 0 73 if ne get m 3 0 74 pre = ulong 5 75 end 76 total = add get m 1 pre 77 if or gt mul total 4 get m 4 gt total AGGPMAX 78 ret 2 79 end 80 if ge and sub get m 5 get m 6 `4294967295` sub AGRING 1 81 ret 3 82 end 83 ag_clear b 84 if ne pre 0 85 ag_put b 0 `537133066` 4 86 ag_put b 16 `2281701376` 4 87 end 88 ag_put b 24 ag_gp get m 7 total 8 89 ag_put b 32 rem and get m 5 `4294967295` AGRING 4 90 ag_put b 36 rem and add get m 5 1 `4294967295` AGRING 4 91 ag_put b 40 pre 4 92 ag_put b 44 total 4 93 ret 0 94 end 95 fn ag_range sz ulong off ulong ln ulong to ulong 96 if or eq ln 0 gt off sz 97 ret 0 98 end 99 if gt ln sub sz off 100 ret 0 101 end 102 ret 1 103 end 104 fn ag_chk m view ulong 16 b edit uchar 128 to ulong 105 op = get m 0 106 if eq op 14 107 if eq get m 3 1 108 note GPU-cached only for device-private DATA (kind 2): no CPU_READ (1), no HOST_POLLED (32). 109 if or ne get m 1 2 ne and get m 2 33 0 110 ret 2 111 end 112 ret 0 113 end 114 ret AGUNC 115 end 116 if eq op 15 117 ret ag_range get m 1 get m 2 get m 3 118 end 119 if eq op 16 120 if eq and get m 1 32 0 121 ret 1 122 end 123 if ne and get m 2 3 0 124 ret 2 125 end 126 if eq ag_range get m 3 get m 2 4 0 127 ret 3 128 end 129 ret 0 130 end 131 if eq op 17 132 if lt and sub get m 1 get m 2 `4294967295` `2147483648` 133 ret 1 134 end 135 ret 0 136 end 137 if eq op 18 138 ret ag_submit m b 139 end 140 if eq op 19 141 ret ag_gp get m 1 get m 2 142 end 143 ret 0 144 end 145 fn aiengpu m view ulong 16 b edit uchar 128 to ulong 146 op = get m 0 147 if eq op 1 148 if ne ag_load b 0 4 1 149 ret 1 150 end 151 if ne ag_load b 4 4 4 152 ret 2 153 end 154 ret 0 155 end 156 if eq op 2 157 if or eq get m 1 0 gt get m 1 AGMAXB 158 ret 0 159 end 160 ret ag_align get m 1 AGPAGE 161 end 162 if eq op 3 163 if or lt get m 1 AGBASE ge get m 1 AGTOP 164 ret AGBASE 165 end 166 ret get m 1 167 end 168 if eq op 4 169 ret ag_align get m 1 get m 2 170 end 171 if eq op 5 172 if gt add get m 1 get m 2 AGTOP 173 if ne get m 3 0 174 ret 1 175 end 176 ret 2 177 end 178 if and ne get m 3 0 ge get m 1 get m 4 179 ret 1 180 end 181 ret 0 182 end 183 if eq op 6 184 ret AGBASE 185 end 186 if eq op 7 187 ret AGTOP 188 end 189 if eq op 8 190 ret ag_align add get m 1 get m 2 get m 3 191 end 192 if eq op 9 193 ag_clear b 194 ag_put b 0 get m 1 8 195 ag_put b 8 get m 2 8 196 ag_put b 16 get m 3 4 197 ret 48 198 end 199 if eq op 10 200 if eq ag_load b get m 1 4 1 201 ret 1 202 end 203 ret 0 204 end 205 if eq op 11 206 ag_clear b 207 ag_put b 0 get m 1 4 208 ret 24 209 end 210 if eq op 12 211 ag_clear b 212 ag_put b 0 get m 1 4 213 ag_put b 4 AGRING 4 214 ag_put b 16 get m 1 4 215 ag_put b 20 get m 2 4 216 ag_put b 24 AGUSERD 8 217 ret 72 218 end 219 if eq op 13 220 ag_clear b 221 ag_put b 0 get m 1 4 222 ret 24 223 end 224 if ge op 14 225 ret ag_chk m b 226 end 227 ret 0 228 end