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/om/scan/scan_plan.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 / om / scan / scan_plan.om` 167 lines · 4288 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note scan_plan.om: the launch plans of the CUDA++ scans and the radix sort (row C3 of docs/OMEGA.md). Ops 0..4 3 note reproduce the C level drivers of src/omega_gpu_scan.c launch for launch (the C stays as the migration-pending 4 note differential oracle, CUDAPP_MIGRATION_PENDING_C_SCAN). Each launch runs a kernel of om/scan/scan_ir.om. 5 note op 0/1/2 reduce (sum/max/min) n f32 at inva, levels in scratch; 3 inclusive f32 prefix sum inva -> outva; 6 note 4 the same over u32; 5 stable LSD radix sort of n u32 keys at inva (in place); 6 the same for key-value pairs 7 note ([keys n | values n] at inva). 4-bit digits, 8 passes between inva and the scratch copy, ending in inva. 8 note Plan words: 0 launches, 1 scratch words (u32) the plan uses from scrva, 2 the reduce result VA, 3 the shift of 9 note the launch being written, 4 overflow; launch i at 16 + 12 i: kind, grid, then the 10 argument words 10 note (in lo, in hi, out lo, out hi, tot lo, tot hi, len, tiles, warps, shift). 11 note Returns 0 ok, 1 bad arguments, 2 n above 2^28 (or a plan overflow). 12 13 const LO32 ulong `4294967295` 14 const MAXN ulong `268435456` 15 const MAXL ulong 169 16 17 note ceil(len / 32): the 32-element tiles of len 18 fn tiles nw ulong to ulong 19 ret shr add nw 31 5 20 end 21 22 note CTAs of 256 threads (8 warps, one tile each per step), at most 1024 23 fn grid nw ulong to ulong 24 t = shr add tiles nw 7 3 25 if eq t 0 26 ret 1 27 end 28 if gt t 1024 29 ret 1024 30 end 31 ret t 32 end 33 34 fn lau plan edit ulong 2048 k ulong in ulong ov ulong tot ulong nw ulong to void 35 i = get plan 0 36 if ge i MAXL 37 put plan 4 1 38 ret 39 end 40 b = add 16 mul i 12 41 g = grid nw 42 put plan b k 43 put plan add b 1 g 44 put plan add b 2 and in LO32 45 put plan add b 3 shr in 32 46 put plan add b 4 and ov LO32 47 put plan add b 5 shr ov 32 48 put plan add b 6 and tot LO32 49 put plan add b 7 shr tot 32 50 put plan add b 8 nw 51 put plan add b 9 tiles nw 52 put plan add b 10 mul g 8 53 put plan add b 11 get plan 3 54 put plan 0 add i 1 55 end 56 57 note one reduction level per launch, each writing its tile results after the last; plan 2 = the result VA 58 fn pred plan edit ulong 2048 k ulong n ulong in ulong scr ulong to void 59 ov = scr 60 go = ulong 1 61 w = ulong 0 62 for i ulong 8 63 if ne go 0 64 lau plan k in ov 0 n 65 n = tiles n 66 in = ov 67 ov = add ov mul n 4 68 w = add w n 69 if le n 1 70 go = ulong 0 71 end 72 end 73 end 74 put plan 1 w 75 put plan 2 in 76 end 77 78 note an inclusive scan of n words in -> out with the tile kernel tk and the carry kernel tk + 1; level totals from 79 note sp; returns the scratch words used 80 fn ppre plan edit ulong 2048 tk ulong n ulong in ulong ov ulong sp ulong to ulong 81 buf = new ulong 9 0 82 ln = new ulong 9 0 83 put buf 0 ov 84 put ln 0 n 85 s0 = sp 86 l = ulong 0 87 for i ulong 8 88 if eq get ln 8 0 89 n = tiles get ln l 90 lau plan tk in get buf l sp get ln l 91 put buf add l 1 sp 92 in = sp 93 sp = add sp mul n 4 94 if eq n 1 95 put ln 8 1 96 else 97 put ln add l 1 n 98 l = add l 1 99 end 100 end 101 end 102 for i ulong 8 103 if gt l 0 104 l = sub l 1 105 lau plan add tk 1 get buf l get buf add l 1 0 get ln l 106 end 107 end 108 ret shr sub sp s0 2 109 end 110 111 note radix sort: per pass the digit histogram (cnt[0] = 0, cnt[1 + dig * tiles + tile]), the in-place u32 112 note scan of the 16 * tiles counts, then the stable scatter 113 note one pass: ks = scatter kind | shift << 8; plan 1 = the sort's scratch words (the copy, cnt, the counts' scan) 114 fn pas plan edit ulong 2048 ks ulong src ulong dst ulong cnt ulong n ulong to void 115 t16 = mul tiles n 16 116 put plan 3 shr ks 8 117 lau plan 7 src 0 cnt n 118 put plan 3 0 119 w = ppre plan 5 t16 add cnt 4 add cnt 4 add cnt mul add t16 1 4 120 put plan 3 shr ks 8 121 lau plan and ks 255 src dst cnt n 122 put plan 3 0 123 w = add w add t16 1 124 put plan 1 add w mul n sub and ks 255 7 125 end 126 127 fn psort plan edit ulong 2048 kv ulong n ulong a ulong scr ulong to void 128 cnt = add scr mul mul n add kv 1 4 129 for p ulong 8 130 src = a 131 dst = scr 132 if ne and p 1 0 133 src = scr 134 dst = a 135 end 136 k = shl sub 28 mul p 4 8 137 k = or k add 8 kv 138 pas plan k src dst cnt n 139 end 140 end 141 142 note ---- entry 143 fn scan_plan op ulong n ulong inva ulong outva ulong scrva ulong plan edit ulong 2048 to ulong 144 for i ulong 2048 145 put plan i 0 146 end 147 if or gt op 6 eq n 0 148 ret 1 149 end 150 if gt n MAXN 151 ret 2 152 end 153 if le op 2 154 pred plan op n inva scrva 155 end 156 if or eq op 3 eq op 4 157 w = ppre plan add 3 mul sub op 3 2 n inva outva scrva 158 put plan 1 w 159 end 160 if ge op 5 161 psort plan sub op 5 n inva scrva 162 end 163 if ne get plan 4 0 164 ret 2 165 end 166 ret 0 167 end