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.cl # 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.cl` 24 lines ยท 1132 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // C = A B^T. 16x16 tiles of A and of B^T staged in __local memory; out-of-range tile elements load as 3 // 0.0f, which adds exact zeros to the accumulator. global is the tile-rounded (N, M) grid, local (16, 16). 4 #define TS 16 5 __kernel void gemm_nt(__global const float *A, __global const float *B, __global float *C, 6 const int M, const int N, const int K) 7 { 8 __local float As[TS][TS]; 9 __local float Bs[TS][TS]; // Bs[k][n] = B[n][k] 10 int tx = get_local_id(0), ty = get_local_id(1); 11 int row = get_group_id(1) * TS + ty, col = get_group_id(0) * TS + tx; 12 int bn = get_group_id(0) * TS + ty; // B row this thread stages 13 float acc = 0.0f; 14 for (int k0 = 0; k0 < K; k0 += TS) { 15 As[ty][tx] = (row < M && k0 + tx < K) ? A[row * K + k0 + tx] : 0.0f; 16 Bs[tx][ty] = (bn < N && k0 + tx < K) ? B[bn * K + k0 + tx] : 0.0f; 17 barrier(CLK_LOCAL_MEM_FENCE); 18 for (int k = 0; k < TS; ++k) 19 acc += As[ty][k] * Bs[k][tx]; 20 barrier(CLK_LOCAL_MEM_FENCE); 21 } 22 if (row < M && col < N) 23 C[row * N + col] = acc; 24 }