openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / softmax / workload.json
| 1 | { |
| 2 | "name": "softmax", |
| 3 | "family": "row-reduction-transcendental", |
| 4 | "summary": "row softmax of x[R][D]: y = exp(x - max) / sum(exp(x - max))", |
| 5 | "provenance": "authored for OpenAccel Lab (Apache-2.0)", |
| 6 | "params": { |
| 7 | "R": 24, |
| 8 | "D": 200 |
| 9 | }, |
| 10 | "cases": [ |
| 11 | {}, |
| 12 | { |
| 13 | "R": 3, |
| 14 | "D": 1 |
| 15 | }, |
| 16 | { |
| 17 | "R": 5, |
| 18 | "D": 1023 |
| 19 | } |
| 20 | ], |
| 21 | "shrink": { |
| 22 | "R": { |
| 23 | "min": 1 |
| 24 | }, |
| 25 | "D": { |
| 26 | "min": 1 |
| 27 | } |
| 28 | }, |
| 29 | "inputs": [ |
| 30 | { |
| 31 | "name": "x", |
| 32 | "dtype": "f32", |
| 33 | "shape": [ |
| 34 | "R", |
| 35 | "D" |
| 36 | ], |
| 37 | "gen": { |
| 38 | "kind": "uniform", |
| 39 | "lo": -30.0, |
| 40 | "hi": 30.0 |
| 41 | } |
| 42 | } |
| 43 | ], |
| 44 | "outputs": [ |
| 45 | { |
| 46 | "name": "y", |
| 47 | "dtype": "f32", |
| 48 | "shape": [ |
| 49 | "R", |
| 50 | "D" |
| 51 | ] |
| 52 | } |
| 53 | ], |
| 54 | "tolerance": { |
| 55 | "y": { |
| 56 | "kind": "bound", |
| 57 | "rtol": 1.0, |
| 58 | "atol": 0.0, |
| 59 | "why": "reference.py returns an absolute per-element bound y_j R_j as the scale (rtol 1), in float64 from the exact inputs. a_k = x_k - m (m the row max, exact). The f32 subtraction rounds once: d_k = a_k(1+delta), so exp(d_k) = exp(a_k) exp(a_k delta) with |exp(a_k delta) - 1| <= exp(u|a_k|) - 1 (|a_k| <= 60 here: WolframLanguageEvaluator: (Exp[60 u]-1)/u, u=2^-24 -> 60.0001). exp budget 3 ulp (OpenCL C 3.0 s7.4; CUDA expf 2 ulp; Omega rounds a binary64 exp once) = 6u relative (WolframLanguageEvaluator: 3*2^-23/2^-24 -> 6), so e_k^ = e_k(1+eta_k), |eta_k| <= eps_k = (1+6u)exp(u|a_k|) - 1, E = max_k eps_k. The sum of D positive terms in any order: S^ = S(1+theta), |theta| <= (1+E)(1+gamma(D-1)) - 1. The normalisation (divide, or reciprocal then multiply) costs gamma(2). R_j = max((1+eps_j)(1+gamma(2)) / ((1-E)(1-gamma(D-1))) - 1, 1 - (1-eps_j)(1-gamma(2)) / ((1+E)(1+gamma(D-1)))). Inputs are uniform in [-30,30], so every e_k >= exp(-60) is a normal f32 (WolframLanguageEvaluator: Exp[-60] -> 8.7565e-27 > 2^-126 = 1.1755e-38). A kernel without max subtraction is wrong on the softmax_unstable control (inputs in [80,100])." |
| 60 | } |
| 61 | }, |
| 62 | "timing": { |
| 63 | "warmup": 1, |
| 64 | "repeats": 5 |
| 65 | }, |
| 66 | "backends": { |
| 67 | "omega": { |
| 68 | "src": "omega.om" |
| 69 | }, |
| 70 | "opencl": { |
| 71 | "src": "kernel.cl", |
| 72 | "launches": [ |
| 73 | { |
| 74 | "kernel": "softmax", |
| 75 | "global": [ |
| 76 | "R*64" |
| 77 | ], |
| 78 | "local": [ |
| 79 | "64" |
| 80 | ], |
| 81 | "args": [ |
| 82 | "x", |
| 83 | "y", |
| 84 | "D", |
| 85 | "local:f32:64" |
| 86 | ] |
| 87 | } |
| 88 | ] |
| 89 | }, |
| 90 | "triton": { |
| 91 | "src": "triton_kernel.py" |
| 92 | }, |
| 93 | "cuda": { |
| 94 | "src": "kernel.cu" |
| 95 | } |
| 96 | } |
| 97 | } |