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/openaccel-lab/blob/main/controls/softmax_unstable/kernel.cl # openaccel-lab aien-dev/openaccel-lab 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 `openaccel-lab / controls / softmax_unstable / kernel.cl` 25 lines ยท 847 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // one work-group per row; get_local_size(0) must be a power of two 3 // CONTROL: the max subtraction is deliberately omitted 4 __kernel void softmax(__global const float *x, __global float *y, const int D, __local float *red) 5 { 6 int t = get_local_id(0), nt = get_local_size(0); 7 __global const float *xr = x + (long)get_group_id(0) * D; 8 __global float *yr = y + (long)get_group_id(0) * D; 9 float acc = 0.0f; 10 for (int k = t; k < D; k += nt) { 11 float e = exp(xr[k]); 12 yr[k] = e; 13 acc += e; 14 } 15 red[t] = acc; 16 barrier(CLK_LOCAL_MEM_FENCE); 17 for (int h = nt / 2; h > 0; h >>= 1) { 18 if (t < h) 19 red[t] += red[t + h]; 20 barrier(CLK_LOCAL_MEM_FENCE); 21 } 22 float s = red[0]; 23 for (int k = t; k < D; k += nt) 24 yr[k] = yr[k] / s; 25 }