diff options
author | 0cc4m <picard12@live.de> | 2024-06-16 07:17:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-16 07:17:31 +0200 |
commit | 7c7836d9d4062d6858e3fb337b135c417ccee6ce (patch) | |
tree | c896967a106e2985763bf1c7bfd7bfb8cbe4f0fd /vulkan-shaders/mul_mat_vec.comp | |
parent | 0c7b3595b9e5ad2355818e259f06b0dc3f0065b3 (diff) |
Vulkan Shader Refactor, Memory Debugging Option (#7947)
* Refactor shaders, extract GLSL code from ggml_vk_generate_shaders.py into vulkan-shaders directory
* Improve debug log code
* Add memory debug output option
* Fix flake8
* Fix unnecessary high llama-3 VRAM use
Diffstat (limited to 'vulkan-shaders/mul_mat_vec.comp')
-rw-r--r-- | vulkan-shaders/mul_mat_vec.comp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/vulkan-shaders/mul_mat_vec.comp b/vulkan-shaders/mul_mat_vec.comp new file mode 100644 index 00000000..292ccfd7 --- /dev/null +++ b/vulkan-shaders/mul_mat_vec.comp @@ -0,0 +1,50 @@ +#version 450 + +#ifdef FLOAT16 +#extension GL_EXT_shader_explicit_arithmetic_types_float16 : require +#endif + +#include "mul_mat_vec_base.comp" + +layout(local_size_x_id = 0, local_size_y = 1, local_size_z = 1) in; + +layout (constant_id = 0) const uint BLOCK_SIZE = 32; + +shared FLOAT_TYPE tmp[BLOCK_SIZE]; + +void main() { + const uint row = gl_WorkGroupID.x; + const uint tid = gl_LocalInvocationID.x; + + uint a_offset, b_offset, d_offset; + get_offsets(a_offset, b_offset, d_offset); + + const uint y_offset = QUANT_R == 1 ? 1 : QUANT_K/2; + + tmp[tid] = FLOAT_TYPE(0.0f); + + [[unroll]] for (uint i = 0; i < p.ncols/BLOCK_SIZE; i += 2) { + const uint col = i*BLOCK_SIZE + 2*tid; + const uint ib = (row*p.ncols + col)/QUANT_K; // block index + const uint iqs = (col%QUANT_K)/QUANT_R; // quant index + const uint iybs = col - col%QUANT_K; // y block start index + + vec2 v = dequantize(ib, iqs, a_offset / QUANT_K); + + // matrix multiplication + tmp[tid] += FLOAT_TYPE(v.x) * FLOAT_TYPE(data_b[b_offset + iybs + iqs]) + + FLOAT_TYPE(v.y) * FLOAT_TYPE(data_b[b_offset + iybs + iqs + y_offset]); + } + + // sum up partial sums and write back result + barrier(); + [[unroll]] for (uint s = BLOCK_SIZE/2; s > 0; s >>= 1) { + if (tid < s) { + tmp[tid] += tmp[tid + s]; + } + barrier(); + } + if (tid == 0) { + data_d[d_offset + row] = D_TYPE(tmp[0]); + } +} |