interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / attn_scores / kernel.cu

27 lines · 776 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2#include <cuda_runtime.h>
3
4__global__ void attn_scores(const float *q, const float *k, float *s, int T, int D)
5{
6 int j = blockIdx.x * blockDim.x + threadIdx.x;
7 int i = blockIdx.y * blockDim.y + threadIdx.y;
8 if (i >= T || j >= T)
9 return;
10 if (j > i) {
11 s[i * T + j] = -1e30f;
12 return;
13 }
14 float acc = 0.0f;
15 for (int c = 0; c < D; c++)
16 acc += q[i * D + c] * k[j * D + c];
17 s[i * T + j] = acc * 0.125f;
18}
19
20void oal_launch(const long long *p, void *const *buf)
21{
22 int T = (int)p[0];
23 int D = (int)p[1];
24 dim3 block(16, 16);
25 dim3 grid((T + 15) / 16, (T + 15) / 16);
26 attn_scores<<<grid, block>>>((const float *)buf[0], (const float *)buf[1], (float *)buf[2], T, D);
27}