ggml-cpu: add AVX2 vec_dot for Q2_0 x Q8_0 on x86 - #164
Open
nicode1990 wants to merge 1 commit into
Open
nicode1990 wants to merge 1 commit into
nicode1990 wants to merge 1 commit into
Conversation
Q2_0 had no x86 kernel: arch-fallback.h mapped ggml_vec_dot_q2_0_q8_0 to the generic scalar loop (only ARM had a NEON path). On a MoE model with all routed experts in Q2_0 (Qwen3.8-Flash-Next GSQ-RCO) this made CPU-side expert layers the bottleneck: ~4.2 tok/s at -ncmoe 38 on a 6-core box, versus 15-20 tok/s with this kernel. The AVX2 path broadcasts 8 raw Q2_0 bytes into four 64-bit lanes, shifts lane j by 2j, masks to 2 bits and subtracts 1, then permutes the Q8_0 block into the same (8*j + b) order and uses mul_sum_i8_pairs_float. Verified with test-backend-ops against CUDA0: MUL_MAT (type_a=q2_0) all OK, MUL_MAT_ID 75/75. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds an AVX2
ggml_vec_dot_q2_0_q8_0for x86. The x86 build had no kernel for it:arch-fallback.hmapped it to the generic scalar loop (only ARM has NEON; ggml-org#26348 upstream covers VNNI only, not AVX2-only CPUs like Zen 2/3).Q2_0 stores weight
4*b + jin bits[2j, 2j+1]of byteb. The 8 raw bytes are broadcast into four 64-bit lanes, lanejis shifted by2j, which gives order8*j + b; the Q8_0 block is permuted to the same order, then the existingmul_sum_i8_pairs_float+ FMA pattern of the Q4_0 kernel applies.Additional information
Ryzen 5 5600X (AVX2, no VNNI), RTX 3060 12 GB, 32 GB DDR4, gcc 13.3,
-DGGML_CUDA=ON -DGGML_NATIVE=ON. Model:Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00001-of-00002.gguf(ISTA-DASLab, all routed experts Q2_0). Before = the same build without this commit (scalar fallback).tg64: 4.17 -> 10.15 tok/s (64 tokens are warm-up dominated on 32 GB;
-n 256gives 16.03 +/- 4.26, llama-server 15-20 tok/s).Uses FMA like the neighbouring kernels, so not bit-identical to the scalar loop (same as noted in ggml-org#26348).
Requirements