openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / attn_scores / kernel.cl
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | __kernel void attn_scores(__global const float *q, __global const float *k, __global float *s, |
| 3 | const int T, const int D) |
| 4 | { |
| 5 | int i = get_global_id(0); |
| 6 | int j = get_global_id(1); |
| 7 | if (i >= T || j >= T) |
| 8 | return; |
| 9 | if (j > i) { |
| 10 | s[i * T + j] = -1e30f; |
| 11 | return; |
| 12 | } |
| 13 | float acc = 0.0f; |
| 14 | for (int c = 0; c < D; c++) |
| 15 | acc += q[i * D + c] * k[j * D + c]; |
| 16 | s[i * T + j] = acc * 0.125f; |
| 17 | } |