ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-vulkan / vulkan-shaders / dequant_iq1_m.comp
| 1 | #version 450 |
| 2 | |
| 3 | #extension GL_EXT_shader_explicit_arithmetic_types_int16 : require |
| 4 | |
| 5 | #include "dequant_head.glsl" |
| 6 | |
| 7 | layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; |
| 8 | |
| 9 | layout (binding = 0) readonly buffer A {block_iq1_m data_a[];}; |
| 10 | layout (binding = 1) writeonly buffer D {D_TYPE data_b[];}; |
| 11 | |
| 12 | void main() { |
| 13 | // Each thread handles 1 subblock (32 values with 2 scales) |
| 14 | const uint ib = gl_WorkGroupID.x * 32 + gl_LocalInvocationID.x / 8; |
| 15 | |
| 16 | init_iq_shmem(gl_WorkGroupSize); |
| 17 | |
| 18 | if (ib >= p.nel / 256) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | const uint ib32 = gl_LocalInvocationID.x % 8; |
| 23 | const uint ib64 = ib32 / 2; |
| 24 | const uint b_idx = 256 * ib + 32 * ib32; |
| 25 | |
| 26 | const uint16_t[4] scales = data_a[ib].scales; |
| 27 | const u16vec4 s = u16vec4(scales[0], scales[1], scales[2], scales[3]) >> 12; |
| 28 | const float d = float(unpackHalf2x16(s.x | (s.y << 4) | (s.z << 8) | (s.w << 12)).x); |
| 29 | |
| 30 | const uint sc = data_a[ib].scales[ib64]; |
| 31 | [[unroll]] for (int l = 0; l < 4; ++l) { |
| 32 | const uint ib16 = 2 * ib32 + l / 2; |
| 33 | const float dl = d * (2 * bitfieldExtract(sc, 3 * int(ib16 & 3), 3) + 1); |
| 34 | const uint qh = data_a[ib].qh[ib16] >> (4 * (l & 1)); |
| 35 | const uint qs = data_a[ib].qs[4 * ib32 + l]; |
| 36 | const float delta = ((qh & 8) != 0) ? -IQ1M_DELTA : IQ1M_DELTA; |
| 37 | const int16_t grid = int16_t(iq1s_grid[qs | ((qh & 7) << 8)]); |
| 38 | [[unroll]] for (int j = 0; j < 8; ++j) { |
| 39 | data_b[b_idx + 8 * l + j] = D_TYPE(dl * (bitfieldExtract(grid, 2*j, 2) + delta)); |
| 40 | } |
| 41 | } |
| 42 | } |