openaccel-lab
aien-dev/openaccel-lab
Brought by drakestapleton
openaccel-lab / workloads / transpose / kernel.cl
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // 16x16 tile through __local memory (one padding column against bank conflicts); global is the |
| 3 | // tile-rounded (C, R) grid, local (16, 16). |
| 4 | #define TS 16 |
| 5 | __kernel void transpose(__global const float *a, __global float *b, const int R, const int C) |
| 6 | { |
| 7 | __local float tile[TS][TS + 1]; |
| 8 | int tx = get_local_id(0), ty = get_local_id(1); |
| 9 | int c0 = get_group_id(0) * TS, r0 = get_group_id(1) * TS; |
| 10 | int r = r0 + ty, c = c0 + tx; |
| 11 | if (r < R && c < C) |
| 12 | tile[ty][tx] = a[r * C + c]; |
| 13 | barrier(CLK_LOCAL_MEM_FENCE); |
| 14 | int orow = c0 + ty, ocol = r0 + tx; // output b is C x R |
| 15 | if (orow < C && ocol < R) |
| 16 | b[orow * R + ocol] = tile[tx][ty]; |
| 17 | } |