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/ggml/blob/master/src/ggml-vulkan/vulkan-shaders/pool2d.comp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-vulkan / vulkan-shaders / pool2d.comp` 94 lines ยท 2470 bytes Raw Blame History 1 #version 450 2 3 #if defined(USE_SUBGROUP) 4 #extension GL_KHR_shader_subgroup_basic : require 5 #extension GL_KHR_shader_subgroup_arithmetic : require 6 #endif 7 8 #include "types.glsl" 9 10 #extension GL_EXT_shader_16bit_storage : require 11 12 layout(push_constant) uniform parameter { 13 uint IW; uint IH; 14 uint OW; uint OH; 15 uint OC; 16 uint pelements; 17 uint op; 18 int k0; int k1; 19 int s0; int s1; 20 int p0; int p1; 21 } p; 22 23 layout(constant_id = 0) const uint BLOCK_SIZE = 512; 24 #define FLT_MAX 3.`402823466e`+38F 25 #define OP_POOL_MAX 0u 26 #define OP_POOL_AVG 1u 27 28 layout (local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in; 29 30 layout(binding = 0) readonly buffer X {A_TYPE data_a[];}; 31 layout(binding = 1) writeonly buffer D {D_TYPE data_d[];}; 32 33 void main() { 34 const uint workgroup = gl_WorkGroupID.y * gl_NumWorkGroups.x + gl_WorkGroupID.x; 35 #if defined(USE_SUBGROUP) 36 const uint idx = workgroup * gl_NumSubgroups + gl_SubgroupID; 37 const int lane = int(gl_SubgroupInvocationID); 38 const int step = int(gl_SubgroupSize); 39 #else 40 const uint idx = workgroup * BLOCK_SIZE + gl_LocalInvocationID.x; 41 const int lane = 0; 42 const int step = 1; 43 #endif 44 if (idx >= p.pelements) { 45 return; 46 } 47 48 const uint O_HW = p.OW * p.OH; 49 50 const uint nc = idx / O_HW; 51 const uint cur_oh = (idx % O_HW) / p.OW; 52 const uint cur_ow = (idx % O_HW) % p.OW; 53 54 const int start_h = int(cur_oh) * p.s0 - p.p0; 55 const int bh = max(start_h, 0); 56 const int eh = min(start_h + p.k0, int(p.IH)); 57 58 const int start_w = int(cur_ow) * p.s1 - p.p1; 59 const int bw = max(start_w, 0); 60 const int ew = min(start_w + p.k1, int(p.IW)); 61 62 const float scale = 1.0 / float(p.k0 * p.k1); 63 float res; 64 65 if (p.op == OP_POOL_AVG) { 66 res = 0.0; 67 } else if (p.op == OP_POOL_MAX) { 68 res = -FLT_MAX; 69 } else { 70 return; 71 } 72 73 #pragma unroll 74 for (int i = bh; i < eh; i++) { 75 #pragma unroll 76 for (int j = bw + lane; j < ew; j += step) { 77 const float cur = D_TYPE(data_a[nc * p.IH * p.IW + i * p.IW + j]); 78 79 if (p.op == OP_POOL_AVG) { 80 res += cur; 81 } else if (p.op == OP_POOL_MAX) { 82 res = max(res, cur); 83 } 84 } 85 } 86 87 #if defined(USE_SUBGROUP) 88 res = p.op == OP_POOL_AVG ? subgroupAdd(res) : subgroupMax(res); 89 if (!subgroupElect()) { 90 return; 91 } 92 #endif 93 data_d[idx] = p.op == OP_POOL_AVG ? res * scale : res; 94 }