interplane.Get Omega
Read in your language

openaccel-lab

aien-dev/openaccel-lab

Brought by drakestapleton

branch main Branches Tags History

openaccel-lab / workloads / gemv / kernel.cu

31 lines · 1006 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2#include <cuda_runtime.h>
3
4#define TS 64
5
6// One thread per row; x is staged through static shared memory in chunks of 64 shared by the block.
7// Every thread reaches every __syncthreads().
8__global__ void gemv(const float *A, const float *x, float *y, int M, int N)
9{
10 __shared__ float xs[TS];
11 int i = blockIdx.x * TS + threadIdx.x, lid = threadIdx.x;
12 float acc = 0.0f;
13 for (int j0 = 0; j0 < N; j0 += TS) {
14 xs[lid] = (j0 + lid < N) ? x[j0 + lid] : 0.0f;
15 __syncthreads();
16 if (i < M) {
17 int jn = N - j0 < TS ? N - j0 : TS;
18 for (int j = 0; j < jn; ++j)
19 acc += A[(long long)i * N + j0 + j] * xs[j];
20 }
21 __syncthreads();
22 }
23 if (i < M)
24 y[i] = acc;
25}
26
27void oal_launch(const long long *p, void *const *buf)
28{
29 int M = (int)p[0], N = (int)p[1];
30 gemv<<<(unsigned)((M + TS - 1) / TS), TS>>>((const float *)buf[0], (const float *)buf[1], (float *)buf[2], M, N);
31}