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/dnn-activations/kernel.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 / dnn-activations / kernel.om` 153 lines · 4076 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note One warp per CTA, one component per lane. Tail lanes exit before addressing. 3 note Vregs: 0 tid,1 block,2 input pair,3 output pair,4 input address pair, 4 note 5 output address pair,6 count,7 index,8 original x,9 bounded abs x, 5 note 10 t,11 exp,12 result,13 constant scratch,14 scratch,15 polynomial, 6 note 16 one,17 zero,18 log2e,19 original abs bits. Params input,output,count. 7 fn da_copy x edit ulong 8192 m edit ulong 512 d ulong a ulong to void 8 aa_mad x m d a 1 AN 9 end 10 fn da_mulc x edit ulong 8192 m edit ulong 512 d ulong a ulong v f32 to void 11 aa_mov x m 13 ulong bitcast uint v 12 aa_bin x m 32 d a 13 13 end 14 fn da_addc x edit ulong 8192 m edit ulong 512 d ulong a ulong v f32 to void 15 aa_mov x m 13 ulong bitcast uint v 16 aa_bin x m 30 d a 13 17 end 18 fn da_horner x edit ulong 8192 m edit ulong 512 v f32 to void 19 aa_bin x m 32 15 15 10 20 da_addc x m 15 15 v 21 end 22 fn da_exp x edit ulong 8192 m edit ulong 512 to void 23 note Input 11 is nonpositive and bounded. Tail exp forced to exact zero. 24 aa_bin x m 32 11 11 18 25 aa_i x m 47 aa_rg 11 11 AN AN 0 2 26 end 27 fn da_erf x edit ulong 8192 m edit ulong 512 to void 28 note A&S 7.1.26 erfc polynomial at |x|/sqrt(2), not tanh GELU. 29 da_mulc x m 9 9 0.`707106781f32` 30 da_mulc x m 10 9 0.`3275911f32` 31 aa_bin x m 30 10 10 16 32 aa_i x m 40 aa_rg 10 10 AN AN 0 2 33 aa_bin x m 32 11 9 9 34 da_mulc x m 11 11 -1.0f32 35 da_exp x m 36 aa_mov x m 13 ulong bitcast uint 10.0f32 37 aa_cmp x m 19 13 38 aa_mov x m 11 0 39 aa_pred x m 2 40 aa_mov x m 15 ulong bitcast uint 1.`061405429f32` 41 da_horner x m -1.`453152027f32` 42 da_horner x m 1.`421413741f32` 43 da_horner x m -0.`284496736f32` 44 da_horner x m 0.`254829592f32` 45 aa_bin x m 32 15 15 10 46 aa_bin x m 32 15 15 11 47 da_mulc x m 15 15 0.5f32 48 note Negative tail uses x*erfc/2 directly; no 1-erf cancellation. 49 aa_bin x m 31 14 16 15 50 aa_bin x m 32 12 8 14 51 aa_mov x m 13 `2147483648` 52 aa_cmp x m 8 13 53 aa_bin x m 32 12 8 15 54 aa_pred x m 2 55 end 56 fn da_sig x edit ulong 8192 m edit ulong 512 op ulong to void 57 note SiLU uses exp(-abs x). Tanh GELU uses sigmoid(2*sqrt(2/pi)*(x+.044715*x^3)). 58 if eq op 2 59 aa_bin x m 32 11 9 9 60 da_mulc x m 11 11 0.`044715f32` 61 aa_bin x m 30 11 11 16 62 aa_bin x m 32 11 11 9 63 da_mulc x m 11 11 -1.`595769122f32` 64 else 65 da_mulc x m 11 9 -1.0f32 66 end 67 da_exp x m 68 cut = f32 80.0 69 if eq op 2 70 cut = f32 10.0 71 end 72 aa_mov x m 13 ulong bitcast uint cut 73 aa_cmp x m 19 13 74 aa_mov x m 11 0 75 aa_pred x m 2 76 aa_bin x m 30 10 16 11 77 aa_i x m 40 aa_rg 10 10 AN AN 0 2 78 aa_bin x m 32 12 8 10 79 note Multiply exp before x for negative values. Every intermediate stays finite. 80 aa_bin x m 32 14 11 10 81 aa_mov x m 13 `2147483648` 82 aa_cmp x m 8 13 83 aa_bin x m 32 12 8 14 84 aa_pred x m 2 85 end 86 fn da_start x edit ulong 8192 m edit ulong 512 dtype ulong to void 87 for i ulong 20 88 kind = ulong 1 89 if and ge i 2 le i 5 90 kind = ulong 2 91 end 92 v = aa_v m kind 93 end 94 put m 2 1 95 put m 320 2 96 aa_i x m 7 aa_rg 0 AN AN AN 856 260 97 aa_i x m 3 aa_rg 0 AN AN AN 33 2 98 aa_i x m 3 aa_rg 1 AN AN AN 37 2 99 aa_i x m 5 aa_rg 2 AN AN AN 896 2 100 aa_i x m 5 aa_rg 3 AN AN AN 904 2 101 aa_i x m 4 aa_rg 6 AN AN AN 912 2 102 aa_mad x m 7 1 32 0 103 aa_cmp x m 7 6 104 aa_i x m 45 aa_rg AN AN AN AN 0 5 105 aa_pred x m 2 106 bytes = ulong 4 107 if ne dtype 0 108 bytes = ulong 2 109 end 110 aa_addr x m 4 7 bytes 2 111 aa_addr x m 5 7 4 3 112 aa_load x m 8 4 0 dtype 113 aa_mov x m 16 ulong bitcast uint 1.0f32 114 aa_mov x m 17 0 115 aa_mov x m 18 ulong bitcast uint 1.`442695041f32` 116 aa_i x m 18 aa_rg 19 8 AN AN `2147483647` 0 117 end 118 fn dnn_activations op ulong dtype ulong unused ulong mutant ulong x edit ulong 8192 m edit ulong 512 to ulong 119 for i ulong 512 120 put m i 0 121 end 122 if or or gt op 3 gt dtype 2 or ne unused 0 ne mutant 0 123 ret 1 124 end 125 da_start x m dtype 126 if eq op 0 127 note ReLU copies signed zero; strictly negative values produce positive zero. 128 da_copy x m 12 8 129 aa_mov x m 13 `2147483648` 130 aa_cmp x m 8 13 131 aa_mov x m 12 0 132 aa_pred x m 2 133 aa_mov x m 13 1 134 aa_cmp x m 19 13 135 da_copy x m 12 8 136 aa_pred x m 6 137 else 138 cut = f32 80.0 139 if ne op 3 140 cut = f32 10.0 141 end 142 aa_mov x m 13 ulong bitcast uint cut 143 aa_bin x m 36 9 19 13 144 if eq op 1 145 da_erf x m 146 else 147 da_sig x m op 148 end 149 end 150 aa_i x m 12 aa_rg AN 5 12 AN 0 3 151 aa_i x m 45 aa_rg AN AN AN AN 0 5 152 ret get m 4 153 end