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/dispatch.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 / dispatch.om` 287 lines · 7884 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note launch: table,ninputs,repeats,timeoutns,outbytes,groupsX,groupsY,queueid,bell,belloff,ringslots. 3 global launch ulong 11 4 text timed "OMEGA dispatch_ns=" 5 text repeatlabel " packets=" 6 note Diagnostics retain CPU-side inputs only; no additional device writes. 7 global queueinput ulong 11 8 note diagstate: vadd,full doorbell offset,last packet slot. 9 global diagstate ulong 3 10 text diagprefix "OMEGA diag " 11 text diagspace " " 12 text dread "queue_read_pointer" 13 text dwrite "queue_write_pointer" 14 text dptr64 "queue_properties" 15 text dqbase "read_pointer_base_offset" 16 text dkind "signal_kind" 17 text dvalue "signal_value" 18 text dheader "ring_header" 19 text dslot "ring_slot_byte_offset" 20 text dout "output_word_" 21 text dqueue "create_queue_input_qword_" 22 text did "queue_id" 23 text dbell "doorbell_offset" 24 text dentry "kernel_code_entry_byte_offset" 25 text drsrc1 "compute_pgm_rsrc1" 26 text drsrc2 "compute_pgm_rsrc2" 27 text drsrc3 "compute_pgm_rsrc3" 28 text dprops "kernel_code_properties" 29 text dgroup "group_segment_size" 30 text dprivate "private_segment_size" 31 text dargsize "kernarg_size" 32 text dobject "packet_kernel_object" 33 text dargaddr "packet_kernarg_address" 34 text dnan "output_first8_nan_fill_count" 35 text dsum "output_first8_expected_vadd_sum_count" 36 text dtimeout "wait_timeout_ns" 37 fn diag name view uchar * value ulong to void 38 emit diagprefix 39 emit name 40 emit diagspace 41 printnum value 42 emit newline 43 end 44 fn diagindexed name view uchar * index ulong value ulong to void 45 emit diagprefix 46 emit name 47 printnum index 48 emit diagspace 49 printnum value 50 emit newline 51 end 52 fn lh i ulong to long 53 ret long mapget long get launch 0 mul i 24 8 54 end 55 fn allocate i ulong n ulong flags ulong to long 56 ret gpumem n flags long get launch 0 mul i 24 57 end 58 fn diagnostics to void 59 cpufence 60 diag dread mapget lh 5 128 8 61 diag dwrite mapget lh 5 56 8 62 diag dptr64 mapget lh 5 180 4 63 diag dqbase mapget lh 5 136 4 64 diag dkind mapget lh 7 0 8 65 diag dvalue mapget lh 7 8 8 66 diag dslot get diagstate 2 67 diag dheader mapget lh 3 get diagstate 2 4 68 diag dobject mapget lh 3 add get diagstate 2 32 8 69 diag dargaddr mapget lh 3 add get diagstate 2 40 8 70 diag did get launch 7 71 diag dbell get diagstate 1 72 for i ulong 11 73 diagindexed dqueue i get queueinput i 74 end 75 diag dentry mapget lh 0 add get el 6 16 8 76 diag drsrc1 mapget lh 0 add get el 6 48 4 77 diag drsrc2 mapget lh 0 add get el 6 52 4 78 diag drsrc3 mapget lh 0 add get el 6 44 4 79 diag dprops and mapget lh 0 add get el 6 56 4 65535 80 diag dgroup mapget lh 0 get el 6 4 81 diag dprivate mapget lh 0 add get el 6 4 4 82 diag dargsize mapget lh 0 add get el 6 8 4 83 count = div get launch 4 4 84 if gt count 8 85 count = ulong 8 86 end 87 nan = ulong 0 88 sum = ulong 0 89 for i ulong count 90 word = mapget lh 2 mul i 4 4 91 diagindexed dout i word 92 if eq word 0x7fc00000 93 nan = add nan 1 94 end 95 if eq word 0x40000000 96 sum = add sum 1 97 end 98 end 99 diag dnan nan 100 if ne get diagstate 0 0 101 diag dsum sum 102 end 103 end 104 fn queuehdr to void 105 note Allocation 4 holds the inactive USER signal; allocation 5 owns the full queue. 106 zeromap lh 4 0 4096 107 r = checked mapset lh 4 0 8 1 108 zeromap lh 5 0 4096 109 note AMD queue v1 prefix: HSA header, write id at 56, read id at 128. 110 r = checked mapset lh 5 4 4 1 111 r = checked mapset lh 5 8 8 mapaddr lh 3 112 r = checked mapset lh 5 24 4 get launch 10 113 r = checked mapset lh 5 32 8 `18446744073709551615` 114 r = checked mapset lh 5 64 4 get dev 12 115 r = checked mapset lh 5 68 4 get dev 13 116 if or eq get dev 4 0 eq get dev 11 0 117 exit 66 118 end 119 cu = div get dev 3 get dev 4 120 if gt get dev 11 div ulong `4294967296` get dev 4 121 exit 66 122 end 123 waves = mul get dev 11 get dev 4 124 if or eq cu 0 or gt cu `4294967296` gt waves `4294967296` 125 exit 66 126 end 127 r = checked mapset lh 5 72 4 sub cu 1 128 r = checked mapset lh 5 76 4 sub waves 1 129 r = checked mapset lh 5 136 4 128 130 note IS_PTR64 at read_dispatch_id + 52, inactive signal at +64. 131 r = checked mapset lh 5 180 4 2 132 r = checked mapset lh 5 192 8 mapaddr lh 4 133 end 134 fn queueinit to void 135 if eq get launch 10 0 136 put launch 10 16 137 end 138 ctxsizes 139 readap 140 note The command processor fetches AQL packets through an executable GPU mapping. 141 r = allocate 3 mul get launch 10 64 0xe6000002 142 r = allocate 4 4096 0xa6000002 143 r = allocate 5 4096 0xa6000002 144 n = roundup mul add get dev 8 get dev 10 get dev 7 4096 145 r = allocate 6 n 0xe4000002 146 r = allocate 7 4096 0xa6000002 147 zeromap lh 3 0 mul get launch 10 64 148 queuehdr 149 zeromap lh 6 0 n 150 zeromap lh 7 0 64 151 note USER signal ABI: kind 1 at 0, value at 8, no interrupt event. 152 r = checked mapset lh 7 0 8 1 153 r = checked mapset lh 7 8 8 get launch 2 154 for i ulong get dev 7 bound `9223372036854775807` 155 p = mul i get dev 8 156 r = checked mapset lh 6 add p 16 4 mul sub get dev 7 i get dev 8 157 r = checked mapset lh 6 add p 20 4 mul get dev 10 get dev 7 158 end 159 for i ulong get launch 10 bound `9223372036854775807` 160 r = checked mapset lh 3 mul i 64 4 1 161 end 162 stepbegin stqueue get dev 2 163 zerohdr 164 note Same WP/RP handle selects the compiler-owned AMD queue ABI; address bytes stay zero. 165 hput 32 4 mul get launch 10 64 166 hput 36 4 get dev 2 167 hput 40 4 2 168 hput 44 4 100 169 hput 48 4 7 170 hput 80 4 get dev 8 171 hput 84 4 get dev 9 172 note gfx942 AQL queues require no EOP allocation (ROCT queues.c). 173 note kfdctl supplies these five mapping addresses in its private ioctl block. 174 note Reconstruct that input here, before the ioctl returns output fields. 175 for i ulong 11 176 put queueinput i hget mul i 8 8 177 end 178 put queueinput 0 mapaddr lh 3 179 put queueinput 1 add mapaddr lh 5 56 180 put queueinput 2 add mapaddr lh 5 128 181 put queueinput 7 0 182 put queueinput 9 mapaddr lh 6 183 r = checked kfdctl int get dev 0 `3227011842` hdr 0 88 lh 3 lh 5 lh 5 long 0 lh 6 184 put launch 7 hget 52 4 185 r = checked mapset lh 5 32 8 get launch 7 186 stepend 187 belloff = hget 24 8 188 put diagstate 1 belloff 189 put launch 9 rem belloff 8192 190 stepbegin stbell belloff 191 put launch 8 ulong checked kfdmap int get dev 0 sub belloff rem belloff 8192 8192 192 stepend 193 end 194 fn packet id ulong to void 195 slot = mul rem id 16 64 196 put diagstate 2 slot 197 zerohdr 198 note First dword kept INVALID until every other field is published. 199 hput 0 2 1 200 hput 2 2 2 201 hput 4 2 64 202 hput 6 2 1 203 hput 8 2 1 204 hput 12 4 mul get launch 5 64 205 hput 16 4 get launch 6 206 hput 20 4 1 207 note HSA packet order differs from descriptor order: private at 24, group at 28. 208 hput 24 4 get el 10 209 hput 28 4 get el 9 210 hput 32 8 add mapaddr lh 0 get el 6 211 hput 40 8 mapaddr lh 1 212 hput 56 8 mapaddr lh 7 213 r = checked mapset lh 3 slot 4 1 214 r = checked mapwrite lh 3 add slot 4 hdr 4 60 215 cpufence 216 note type KERNEL_DISPATCH=2, barrier=1, acquire/release SYSTEM=2, dimensions=2. 217 r = checked mapset lh 3 slot 4 0x00021502 218 cpufence 219 r = checked mapset lh 5 56 8 add id 1 220 cpufence 221 r = checked mapset long get launch 8 get launch 9 8 id 222 end 223 fn deadline start long to void 224 now = monons 225 if lt now start 226 steprow 110 false 227 diagnostics 228 exit 75 229 end 230 slowdispatch ulong sub now start 231 if and ne get launch 3 0 gt ulong sub now start get launch 3 232 steprow 110 false 233 diagnostics 234 exit 75 235 end 236 end 237 fn dispatch to void 238 stepbegin stdispatch get launch 2 239 diag dtimeout get launch 3 240 put dispatchalarm 0 0 241 start = monons 242 if lt start 0 243 steprow ulong neg start false 244 exit 74 245 end 246 for i ulong get launch 2 bound `9223372036854775807` 247 while ge sub i mapget lh 5 128 8 16 bound `9223372036854775807` 248 deadline start 249 cpurelax 250 end 251 packet i 252 end 253 stepend 254 stepbegin stwait get launch 2 255 while ne mapget lh 7 8 8 0 bound `9223372036854775807` 256 deadline start 257 cpurelax 258 end 259 cpufence 260 stepend 261 elapsed = sub monons start 262 if lt elapsed 0 263 exit 74 264 end 265 slowdispatch ulong elapsed 266 emit timed 267 printnum ulong elapsed 268 emit repeatlabel 269 printnum get launch 2 270 emit newline 271 diagnostics 272 end 273 fn teardown to void 274 stepbegin stcleanup 0 275 zerohdr 276 hput 0 4 get launch 7 277 r = checked kfdctl int get dev 0 `3221768963` hdr 0 8 278 r = checked mapdrop long get launch 8 279 for i ulong add get launch 1 8 bound `9223372036854775807` 280 gpufree long get launch 0 mul i 24 281 end 282 r = checked mapdrop long get launch 0 283 r = checked fclose int get dev 1 284 r = checked fclose int get dev 0 285 r = checked fclose int get el 0 286 stepend 287 end