openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / tsoftmax16 / kernel.cl
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // One work-item per 32-column row: max, exp(x - max) with its sum, then divide. |
| 3 | __kernel void tsoftmax16(__global const float *x, __global float *y, const int tiles) |
| 4 | { |
| 5 | int r = get_global_id(0); |
| 6 | if (r >= tiles * 16) |
| 7 | return; |
| 8 | __global const float *xr = x + r * 32; |
| 9 | __global float *yr = y + r * 32; |
| 10 | float m = xr[0]; |
| 11 | for (int j = 1; j < 32; j++) |
| 12 | m = fmax(m, xr[j]); |
| 13 | float s = 0.0f; |
| 14 | for (int j = 0; j < 32; j++) { |
| 15 | float e = exp(xr[j] - m); |
| 16 | yr[j] = e; |
| 17 | s += e; |
| 18 | } |
| 19 | for (int j = 0; j < 32; j++) |
| 20 | yr[j] = yr[j] / s; |
| 21 | } |