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_bias_relu/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_bias_relu / kernel.cl` 24 lines ยท 1121 bytes Raw Blame History 1 // SPDX-License-Identifier: Apache-2.0 2 // C = relu(A B + bias). 16x16 tiles of A and B staged in __local memory; out-of-range tile elements 3 // load as 0.0f, which adds exact zeros to the accumulator. global is the tile-rounded (N, M) grid, 4 // local (16, 16). 5 #define TS 16 6 __kernel void gemm_bias_relu(__global const float *A, __global const float *B, __global const float *bias, 7 __global float *C, const int M, const int N, const int K) 8 { 9 __local float As[TS][TS]; 10 __local float Bs[TS][TS]; 11 int tx = get_local_id(0), ty = get_local_id(1); 12 int row = get_group_id(1) * TS + ty, col = get_group_id(0) * TS + tx; 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[ty][tx] = (k0 + ty < K && col < N) ? B[(k0 + ty) * N + col] : 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] = fmax(acc + bias[col], 0.0f); 24 }