interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-vulkan / vulkan-shaders / copy_transpose_02.comp

61 lines · 2156 bytes Raw Blame History
1#version 450
2
3#include "types.glsl"
4#include "generic_unary_head.glsl"
5
6// workgroup does 32x32 tile, but uses 32x8 threads
7#define TILE_DIM 32
8layout(local_size_x = 32, local_size_y = 8, local_size_z = 1) in;
9
10// +1 padding avoids shared-memory bank conflicts on the transposed read
11shared uint sh[TILE_DIM][TILE_DIM + 1];
12
13void iter(uvec3 wg_id) {
14 const uint tile_i0 = wg_id.x; // tiles dst ne10 (== src ne00)
15 const uint tile_i2 = wg_id.y; // tiles dst ne12 (== src ne02)
16
17 const uint tid_col = gl_LocalInvocationID.x;
18 const uint tid_row = gl_LocalInvocationID.y;
19
20 const uint i1 = wg_id.z % p.ne11;
21 const uint i3 = wg_id.z / p.ne11;
22 const uint i01 = i1;
23 const uint i03 = i3;
24
25 [[unroll]] for (uint y = 0; y < 4; ++y) {
26 const uint i00 = tile_i0 * TILE_DIM + tid_row + 8 * y;
27 const uint i02 = tile_i2 * TILE_DIM + tid_col;
28 if (i00 < p.ne00 && i01 < p.ne01 && i02 < p.ne02 && i03 < p.ne03) {
29 const uint src_idx = i00 * p.nb00 + i01 * p.nb01 + i02 * p.nb02 + i03 * p.nb03;
30 sh[tid_row + 8 * y][tid_col] = uint(data_a[get_aoffset() + src_idx]);
31 }
32 }
33
34 barrier();
35
36 [[unroll]] for (uint y = 0; y < 4; ++y) {
37 const uint i0 = tile_i0 * TILE_DIM + tid_col;
38 const uint i2 = tile_i2 * TILE_DIM + tid_row + 8 * y;
39 if (i0 < p.ne10 && i1 < p.ne11 && i2 < p.ne12 && i3 < p.ne13) {
40 const uint dst_idx = i0 * p.nb10 + i1 * p.nb11 + i2 * p.nb12 + i3 * p.nb13;
41 data_d[get_doffset() + dst_idx] = D_TYPE(sh[tid_col][tid_row + 8 * y]);
42 }
43 }
44}
45
46#define CEIL_DIV(a, b) (((a) + (b) - 1) / (b))
47
48void main() {
49 bool need_barrier = false;
50 for (uint z = gl_WorkGroupID.z; z < p.ne11 * p.ne13; z += gl_NumWorkGroups.z) {
51 for (uint y = gl_WorkGroupID.y; y < CEIL_DIV(p.ne12, TILE_DIM); y += gl_NumWorkGroups.y) {
52 for (uint x = gl_WorkGroupID.x; x < CEIL_DIV(p.ne10, TILE_DIM); x += gl_NumWorkGroups.x) {
53 if (need_barrier) {
54 barrier();
55 }
56 need_barrier = true;
57 iter(uvec3(x, y, z));
58 }
59 }
60 }
61}