openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / tmatmul16 / kernel.cu
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | #include <cuda_runtime.h> |
| 3 | |
| 4 | // One 16x16 block per tile; A and B are staged in shared memory, C[i][j] = sum_k A[i][k] B[k][j]. |
| 5 | __global__ void tmatmul16(const float *a, const float *b, float *c) |
| 6 | { |
| 7 | __shared__ float la[256]; |
| 8 | __shared__ float lb[256]; |
| 9 | long long t = blockIdx.x; |
| 10 | int i = threadIdx.y, j = threadIdx.x, l = i * 16 + j; |
| 11 | la[l] = a[t * 256 + l]; |
| 12 | lb[l] = b[t * 256 + l]; |
| 13 | __syncthreads(); |
| 14 | float s = 0.0f; |
| 15 | for (int k = 0; k < 16; k++) |
| 16 | s += la[i * 16 + k] * lb[k * 16 + j]; |
| 17 | c[t * 256 + l] = s; |
| 18 | } |
| 19 | |
| 20 | void oal_launch(const long long *p, void *const *buf) |
| 21 | { |
| 22 | long long tiles = p[0]; |
| 23 | tmatmul16<<<(unsigned)tiles, dim3(16, 16)>>>((const float *)buf[0], (const float *)buf[1], (float *)buf[2]); |
| 24 | } |