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/backend/amd/kfd/launch/common.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 / backend / amd / kfd / launch / common.om` 240 lines · 5022 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Concatenate common, elf, device, dispatch, main, then existing cli.om under om2. 3 note Fixed arrays below are Linux pathname or ABI records, not input-size limits. 4 global pathbuf uchar 4096 5 global chunk uchar 4096 6 global hdr uchar 88 7 global ids uchar 4 8 global one uchar 1 9 text newline "\n" 10 text failed "OMEGA error=" 11 text kfdpath "/dev/kfd" 12 global stepname uchar 64 13 note This internal label buffer holds only the literal step names below, never caller input. 14 global stepstate ulong 2 15 text stepprefix "OMEGA step " 16 text stepok " ok errno=0" 17 text stepfail " fail errno=" 18 text stepbefore " phase=before detail=" 19 text stepafter " phase=after detail=" 20 text stopen "open_kfd" 21 text stversion "version" 22 text sttop "topology" 23 text stnode "topology_node" 24 text strender "render_open" 25 text stvm "acquire_vm" 26 text stap "memory_apertures" 27 text streserve "memory_reserve" 28 text stalloc "memory_alloc" 29 text stmap "memory_map" 30 text stbind "memory_cpu_map" 31 text stqueue "queue_create" 32 text stbell "doorbell_map" 33 text stload "code_object_load" 34 text stdispatch "dispatch" 35 text stwait "signal_wait" 36 text streadback "readback" 37 text stcleanup "cleanup" 38 text objectrefusallabel "OMEGA refuse object field=" 39 fn objectrefuse reason ulong to void 40 b = new uchar 20 0 41 p = ulong 20 42 while gt reason 9 bound 20 43 p = sub p 1 44 put b p uchar add rem reason 10 48 45 reason = div reason 10 46 end 47 p = sub p 1 48 put b p uchar add reason 48 49 emitfd 2 objectrefusallabel 50 emitfd 2 part b p sub 20 p 51 emitfd 2 newline 52 exit 65 53 end 54 fn steprow err ulong before bool to void 55 r = write 1 stepprefix 0 len stepprefix 56 r = write 1 stepname 0 get stepstate 0 57 if eq err 0 58 r = write 1 stepok 0 len stepok 59 else 60 r = write 1 stepfail 0 len stepfail 61 printnum err 62 end 63 if before 64 r = write 1 stepbefore 0 len stepbefore 65 else 66 r = write 1 stepafter 0 len stepafter 67 end 68 printnum get stepstate 1 69 r = write 1 newline 0 len newline 70 end 71 fn stepbegin name view uchar * detail ulong to void 72 for i ulong len name bound 64 73 put stepname i get name i 74 end 75 put stepstate 0 len name 76 put stepstate 1 detail 77 steprow 0 true 78 end 79 fn stepend to void 80 steprow 0 false 81 end 82 fn stepresult r long to long 83 if lt r 0 84 steprow ulong neg r false 85 else 86 stepend 87 end 88 ret r 89 end 90 fn checked r long to long 91 if lt r 0 92 steprow ulong neg r false 93 emit failed 94 if eq r -`9223372036854775808` 95 exit 74 96 end 97 printnum ulong neg r 98 emit newline 99 exit 74 100 end 101 ret r 102 end 103 fn printnum v ulong to void 104 b = new uchar 20 0 105 p = ulong 20 106 while gt v 9 bound 20 107 p = sub p 1 108 put b p uchar add rem v 10 48 109 v = div v 10 110 end 111 p = sub p 1 112 put b p uchar add v 48 113 emit part b p sub 20 p 114 end 115 fn roundup n ulong a ulong to ulong 116 if gt n sub `9223372036854775807` sub a 1 117 objectrefuse 0 118 end 119 ret mul div add n sub a 1 a a 120 end 121 fn patharg i ulong to ulong 122 n = argread i pathbuf 0 len pathbuf 123 if lt n 1 124 exit 64 125 end 126 ret ulong n 127 end 128 fn argfile i ulong flags int to int 129 n = patharg i 130 ret int checked fopen pathbuf 0 n flags 384 131 end 132 fn filesize fd int to ulong 133 n = checked fseek fd 0 2 134 r = checked fseek fd 0 0 135 ret ulong n 136 end 137 fn zerohdr to void 138 for i ulong 88 139 put hdr i 0 140 end 141 end 142 fn hput off ulong width ulong v ulong to void 143 for i ulong width 144 put hdr add off i uchar and shr v mul i 8 255 145 end 146 end 147 fn hget off ulong width ulong to ulong 148 v = ulong 0 149 for i ulong width 150 v = or v shl ulong get hdr add off i mul i 8 151 end 152 ret v 153 end 154 fn fword fd int off ulong width ulong to ulong 155 b = new uchar 8 0 156 r = pread fd b 0 width long off 157 if ne r long width 158 objectrefuse 1 159 end 160 v = ulong 0 161 for i ulong width 162 v = or v shl ulong get b i mul i 8 163 end 164 ret v 165 end 166 fn byteat fd int off ulong to uchar 167 r = pread fd one 0 1 long off 168 if ne r 1 169 objectrefuse 2 170 end 171 ret get one 0 172 end 173 fn filecopy fd int src ulong dst long off ulong n ulong to void 174 p = ulong 0 175 while lt p n bound `9223372036854775807` 176 k = sub n p 177 if gt k len chunk 178 k = len chunk 179 end 180 r = checked pread fd chunk 0 k long add src p 181 if eq r 0 182 objectrefuse 3 183 end 184 r = checked mapwrite dst add off p chunk 0 ulong r 185 p = add p ulong r 186 end 187 end 188 fn zeromap dst long off ulong n ulong to void 189 for i ulong len chunk bound 4096 190 put chunk i 0 191 end 192 p = ulong 0 193 while lt p n bound `9223372036854775807` 194 k = sub n p 195 if gt k len chunk 196 k = len chunk 197 end 198 r = checked mapwrite dst add off p chunk 0 k 199 p = add p k 200 end 201 end 202 fn savefile fd int src long n ulong to void 203 p = ulong 0 204 while lt p n bound `9223372036854775807` 205 k = sub n p 206 if gt k len chunk 207 k = len chunk 208 end 209 r = checked mapread src p chunk 0 k 210 q = ulong 0 211 while lt q k bound `9223372036854775807` 212 r = checked write fd chunk q sub k q 213 if eq r 0 214 exit 74 215 end 216 q = add q ulong r 217 end 218 p = add p k 219 end 220 end 221 fn span off ulong n ulong total ulong to void 222 if gt off total 223 objectrefuse 4 224 end 225 if gt n sub total off 226 objectrefuse 5 227 end 228 end 229 230 global dispatchalarm ulong 1 231 text slowdispatchlabel "OMEGA alarm slow_dispatch_ns=" 232 text slowdispatchthreshold " threshold_ns=`10000000000`\n" 233 fn slowdispatch elapsed ulong to void 234 if and eq get dispatchalarm 0 0 gt elapsed `10000000000` 235 put dispatchalarm 0 1 236 emit slowdispatchlabel 237 printnum elapsed 238 emit slowdispatchthreshold 239 end 240 end