Download build/webgpu/gather-block-quantized-packed-byte.wgsl.jinja from webgpu-kernels/com.microsoft.GatherBlockQuantized: direct link, hf CLI and curl.
- Browser
- Download file 1.93 kB
-
https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatherBlockQuantized/resolve/v1/build/webgpu/gather-block-quantized-packed-byte.wgsl.jinja
- Command line
-
hf download hf://webgpu-kernels/com.microsoft.GatherBlockQuantized@v1/build/webgpu/gather-block-quantized-packed-byte.wgsl.jinja
-
curl -L -o gather-block-quantized-packed-byte.wgsl.jinja https://huggingface.co/kernels/webgpu-kernels/com.microsoft.GatherBlockQuantized/resolve/v1/build/webgpu/gather-block-quantized-packed-byte.wgsl.jinja
1.93 kB
| {% macro flat_index_2d(workgroupSize, name="i", bound="params.count") %} | |
| {% set wgTerm = workgroupSize ~ "u" if workgroupSize is number else workgroupSize %} | |
| // 2D-folded flat index: gid.y carries the high bits past the dispatch's | |
| // per-axis workgroup fold width. | |
| let {{ name }} = gid.x + gid.y * {{ DISPATCH_FOLD_WIDTH }}u * {{ wgTerm }}; | |
| {% endmacro %} | |
| {{ env.wgsl.resourceDeclarations }} | |
| const WG: u32 = {{ workgroupSize }}u; | |
| @compute @workgroup_size(WG, 1, 1) | |
| fn main(@builtin(global_invocation_id) gid: vec3<u32>) { | |
| {{ flat_index_2d("WG", "pair_index", "") }} | |
| let total = params.indexCount * params.packedCols; | |
| if (pair_index >= total) { | |
| return; | |
| } | |
| let out_row = pair_index / params.packedCols; | |
| let packed_col = pair_index % params.packedCols; | |
| let data_row = indices[out_row]; | |
| if (data_row >= params.rows) { | |
| return; | |
| } | |
| let packed = data[data_row * params.packedCols + packed_col]; | |
| let col0 = packed_col * {{ 8 // bits }}u; | |
| let block = col0 / params.blockSize; | |
| let scale = scales[data_row * params.blocks + block]; | |
| {% if hasZero %} | |
| let packed_zero = zero_points[data_row * params.zeroPointCols + block / {{ 8 // bits }}u]; | |
| let zero = f32((packed_zero >> ((block % {{ 8 // bits }}u) * {{ bits }}u)) & {{ 2 ** bits - 1 }}u); | |
| {% else %} | |
| {% if bits == 2 %} | |
| // uint8 data with bits=2 defaults to zero point 2^(bits-1) = 2. | |
| let zero = 2.0; | |
| {% else %} | |
| // uint8 data with bits=4 defaults to zero point 2^(bits-1) = 8. | |
| let zero = 8.0; | |
| {% endif %} | |
| {% endif %} | |
| let q0 = f32(packed & {{ 2 ** bits - 1 }}u); | |
| let q1 = f32((packed >> {{ bits }}u) & {{ 2 ** bits - 1 }}u); | |
| {% if bits == 2 %} | |
| let q2 = f32((packed >> 4u) & 3u); | |
| let q3 = f32((packed >> 6u) & 3u); | |
| output[pair_index] = vec4<f32>((q0 - zero) * scale, (q1 - zero) * scale, (q2 - zero) * scale, (q3 - zero) * scale); | |
| {% else %} | |
| output[pair_index] = vec2<f32>((q0 - zero) * scale, (q1 - zero) * scale); | |
| {% endif %} | |
| } | |