char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e29acf74f
char/aliceai-t5-moe
1#version 450 2 3#include "generic_head.glsl" 4#include "types.glsl" 5 6#extension GL_EXT_control_flow_attributes : enable 7 8#define FLT_MAX 3.402823466e+38F 9 10layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in; 11 12layout (binding = 0) readonly buffer A {A_TYPE data_a[];}; 13layout (binding = 1) writeonly buffer D {D_TYPE data_d[];}; 14 15layout (constant_id = 0) const uint BLOCK_SIZE = 32; 16 17shared FLOAT_TYPE tmpmax[BLOCK_SIZE]; 18shared uint tmp[BLOCK_SIZE]; 19 20void main() { 21 const uint row = gl_WorkGroupID.z * 262144 + gl_WorkGroupID.y * 512 + gl_WorkGroupID.x; 22 const uint col = gl_LocalInvocationID.x; 23 24 if (row >= p.KY) { 25 return; 26 } 27 28 A_TYPE amax = -FLT_MAX; 29 uint acol = col; 30 31 if (col < p.KX) { 32 amax = data_a[row*p.KX + col]; 33 } 34 35 for (uint i = col + BLOCK_SIZE; i < p.KX; i += BLOCK_SIZE) { 36 A_TYPE val = data_a[row*p.KX + i]; 37 if (val > amax) { 38 amax = val; 39 acol = i; 40 } 41 } 42 43 tmp[col] = acol; 44 tmpmax[col] = amax; 45 46 barrier(); 47 [[unroll]] for (int s = int(BLOCK_SIZE) / 2; s > 0; s >>= 1) { 48 if (col < s && col + s < p.KX) { 49 if (tmpmax[col] < tmpmax[col + s]) { 50 tmpmax[col] = tmpmax[col + s]; 51 tmp[col] = tmp[col + s]; 52 } 53 } 54 barrier(); 55 } 56 57 if (col == 0) { 58 data_d[row] = D_TYPE(tmp[0]); 59 } 60}