Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/openaccel-lab/blob/main/workloads/gemm_nt/kernel.cu # openaccel-lab aien-dev/openaccel-lab Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `openaccel-lab / workloads / gemm_nt / kernel.cu` 34 lines ยท 1350 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 #include 3 4 #define TS 16 5 6 // C = A B^T. 16x16 tiles of A and of B^T staged in static shared memory; out-of-range tile elements 7 // load as 0.0f, which adds exact zeros to the accumulator. 8 __global__ void gemm_nt(const float *A, const float *B, float *C, int M, int N, int K) 9 { 10 __shared__ float As[TS][TS]; 11 __shared__ float Bs[TS][TS]; // Bs[k][n] = B[n][k] 12 int tx = threadIdx.x, ty = threadIdx.y; 13 int row = blockIdx.y * TS + ty, col = blockIdx.x * TS + tx; 14 int bn = blockIdx.x * TS + ty; // B row this thread stages 15 float acc = 0.0f; 16 for (int k0 = 0; k0 < K; k0 += TS) { 17 As[ty][tx] = (row < M && k0 + tx < K) ? A[(long long)row * K + k0 + tx] : 0.0f; 18 Bs[tx][ty] = (bn < N && k0 + tx < K) ? B[(long long)bn * K + k0 + tx] : 0.0f; 19 __syncthreads(); 20 for (int k = 0; k < TS; ++k) 21 acc += As[ty][k] * Bs[k][tx]; 22 __syncthreads(); 23 } 24 if (row < M && col < N) 25 C[(long long)row * N + col] = acc; 26 } 27 28 void oal_launch(const long long *p, void *const *buf) 29 { 30 int M = (int)p[0], N = (int)p[1], K = (int)p[2]; 31 dim3 grid((unsigned)((N + TS - 1) / TS), (unsigned)((M + TS - 1) / TS)); 32 dim3 block(TS, TS); 33 gemm_nt<<>>((const float *)buf[0], (const float *)buf[1], (float *)buf[2], M, N, K); 34 }