char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
7a333e724
char/aliceai-t5-moe
1#version 450 2 3#extension GL_EXT_control_flow_attributes : require 4 5// Collapse the hc residual streams of a token into one, weighted per stream: 6// 7// dst[i0, it] = sum_ih x[i0, ih, it] * weights[ih, it] 8 9layout(constant_id = 0) const uint BLOCK_SIZE = 256; 10 11layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in; 12 13layout(push_constant) uniform parameter 14{ 15 uint n_embd; 16 uint n_tokens; 17 18 uint nbx0; uint nbx1; uint nbx2; // x 19 uint nbw0; uint nbw1; // weights 20 uint nbd0; uint nbd1; // dst 21 22 uint x_offset; 23 uint w_offset; 24 uint d_offset; 25}; 26 27layout(binding = 0, std430) readonly buffer X { float data_x[]; }; 28layout(binding = 1, std430) readonly buffer W { float data_w[]; }; 29layout(binding = 2, std430) writeonly buffer D { float data_d[]; }; 30 31const uint hc = 4; 32 33shared float w[hc]; 34 35void main() { 36 const uint tid = gl_LocalInvocationID.x; 37 const uint it = gl_WorkGroupID.y; 38 39 if (tid < hc) { 40 w[tid] = data_w[w_offset + tid * nbw0 + it * nbw1]; 41 } 42 barrier(); 43 44 // After the barrier, so every invocation reaches it. 45 const uint i0 = gl_WorkGroupID.x * BLOCK_SIZE + tid; 46 if (i0 >= n_embd) { 47 return; 48 } 49 50 const uint xb = x_offset + i0 * nbx0 + it * nbx2; 51 52 float result = 0.0f; 53 [[unroll]] 54 for (uint ih = 0; ih < hc; ++ih) { 55 result = fma(data_x[xb + ih * nbx1], w[ih], result); 56 } 57 58 data_d[d_offset + i0 * nbd0 + it * nbd1] = result; 59}