e29acf74fe
* vulkan (DRAFT): split shader generation by GLSL source file, to improve incremental build times * support dep-files so shaders are recompiled if their included files change * rename shader files which are used as "headers" to use .glsl extension * move glslc extension detection shaders to separate folders * the above is to prevent them from getting glob'd with the actual compute shaders that need to be compiled * vulkan : only write embedded shader .hpp/.cpp when they change * avoid recompiling ggml-vulkan.cpp when editing shaders * pass single --source argument instead of --input-dir & --filter to shader gen * check for source file match earlier * fix hang in vulkan-shaders-gen when there are compilation errors * early out did not decrement compile_count * clean up * fix glslc integer dot product test * unconditionally write the embedded shader cpp output * replace output filepath in generated dep-files to match output in CMakeLists --------- Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
52 lines
2.1 KiB
Plaintext
52 lines
2.1 KiB
Plaintext
#version 450
|
|
|
|
#include "dequant_head.glsl"
|
|
|
|
layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
|
|
|
|
layout (binding = 0) readonly buffer A {block_iq3_xxs data_a[];};
|
|
layout (binding = 1) writeonly buffer D {D_TYPE data_b[];};
|
|
|
|
void main() {
|
|
// Each thread handles 1 scale block (32 values)
|
|
// 8 threads handle 1 superblock
|
|
const uint ib = gl_WorkGroupID.x * 32 + gl_LocalInvocationID.x / 8;
|
|
|
|
init_iq_shmem(gl_WorkGroupSize);
|
|
|
|
if (ib >= p.nel / 256) {
|
|
return;
|
|
}
|
|
|
|
const uint is = gl_LocalInvocationID.x % 8;
|
|
const uint b_idx = 256 * ib + 32 * is;
|
|
const uint s_idx = QUANT_K / 4 + 4 * is;
|
|
|
|
const float d = float(data_a[ib].d);
|
|
uint signscale = pack32(u8vec4(
|
|
data_a[ib].qs[s_idx + 0],
|
|
data_a[ib].qs[s_idx + 1],
|
|
data_a[ib].qs[s_idx + 2],
|
|
data_a[ib].qs[s_idx + 3]
|
|
));
|
|
const float db = d * (0.5 + (signscale >> 28)) * 0.5;
|
|
|
|
[[unroll]] for (uint l = 0; l < 4; ++l) {
|
|
const uint sign7 = bitfieldExtract(signscale, 7 * int(l), 7);
|
|
// Restore parity bit.
|
|
const uint sign8 = sign7 | (bitCount(sign7) << 7);
|
|
const uint qs0 = data_a[ib].qs[8 * is + 2 * l];
|
|
const uint qs1 = data_a[ib].qs[8 * is + 2 * l + 1];
|
|
const u8vec4 grid0 = unpack8(iq3xxs_grid[qs0]);
|
|
const u8vec4 grid1 = unpack8(iq3xxs_grid[qs1]);
|
|
data_b[b_idx + 8 * l + 0] = D_TYPE(db * grid0.x * ((sign8 & 1) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 1] = D_TYPE(db * grid0.y * ((sign8 & 2) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 2] = D_TYPE(db * grid0.z * ((sign8 & 4) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 3] = D_TYPE(db * grid0.w * ((sign8 & 8) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 4] = D_TYPE(db * grid1.x * ((sign8 & 16) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 5] = D_TYPE(db * grid1.y * ((sign8 & 32) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 6] = D_TYPE(db * grid1.z * ((sign8 & 64) != 0 ? -1.0 : 1.0));
|
|
data_b[b_idx + 8 * l + 7] = D_TYPE(db * grid1.w * ((sign8 & 128) != 0 ? -1.0 : 1.0));
|
|
}
|
|
}
|