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
CUDApp / om / apiviews / gdnex.om
| 1 | om2 |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | note negA = -exp(a_log) over the live view. Same steps as omega_hostmath_exp. |
| 4 | note WolframLanguageEvaluator bits of the C double literals: |
| 5 | note 1.44269504088896338700 -> 4609176140021203710 |
| 6 | note 6.93147180369123816490e-1 -> 4604418534311723008 |
| 7 | note 1.90821492927058770002e-10 -> 4461442080421002358 |
| 8 | note 709.78 -> 4649454506724284170 |
| 9 | note -745.2 -> 13873138101193906586 |
| 10 | note +inf is 9218868437227405312. |
| 11 | fn av_krnd fk f64 to int |
| 12 | if ge fk 0.0f64 |
| 13 | ret int add fk 0.5f64 |
| 14 | end |
| 15 | ret int sub fk 0.5f64 |
| 16 | end |
| 17 | fn av_pow2 k int to f64 |
| 18 | if gt k 1023 |
| 19 | ret bitcast f64 ulong 9218868437227405312 |
| 20 | end |
| 21 | if lt k int -1074 |
| 22 | ret 0.0f64 |
| 23 | end |
| 24 | if ge k int -1022 |
| 25 | ret bitcast f64 shl ulong add k 1023 52 |
| 26 | end |
| 27 | a = bitcast f64 shl ulong 1 52 |
| 28 | b = bitcast f64 shl ulong add add k 1022 1023 52 |
| 29 | ret mul a b |
| 30 | end |
| 31 | fn av_horn r f64 to f64 |
| 32 | p = 1.0f64 |
| 33 | for i ulong 17 |
| 34 | d = sub 17 i |
| 35 | p = add 1.0f64 div mul r p f64 d |
| 36 | end |
| 37 | ret p |
| 38 | end |
| 39 | fn av_exp1 y f64 to f64 |
| 40 | if ne y y |
| 41 | ret y |
| 42 | end |
| 43 | if gt y bitcast f64 ulong 4649454506724284170 |
| 44 | ret bitcast f64 ulong 9218868437227405312 |
| 45 | end |
| 46 | if lt y bitcast f64 ulong 13873138101193906586 |
| 47 | ret 0.0f64 |
| 48 | end |
| 49 | fk = mul y bitcast f64 ulong 4609176140021203710 |
| 50 | k = av_krnd fk |
| 51 | kd = f64 k |
| 52 | hi = bitcast f64 ulong 4604418534311723008 |
| 53 | lo = bitcast f64 ulong 4461442080421002358 |
| 54 | r = sub sub y mul kd hi mul kd lo |
| 55 | p = av_horn r |
| 56 | if lt k int -1020 |
| 57 | ret mul mul p av_pow2 int -1020 av_pow2 add k 1020 |
| 58 | end |
| 59 | ret mul p av_pow2 k |
| 60 | end |
| 61 | fn av_gdnex a view f32 * ng edit f32 * to ulong |
| 62 | if ne len a len ng |
| 63 | ret 1 |
| 64 | end |
| 65 | for i ulong len a |
| 66 | put ng i neg f32 av_exp1 f64 get a i |
| 67 | end |
| 68 | ret 0 |
| 69 | end |