x86: implement AVX2 kernel for ggml_vec_dot_q1_0_g128_q8_0#11
Open
SimesD61 wants to merge 1 commit intoPrismML-Eng:prismfrom
Open
x86: implement AVX2 kernel for ggml_vec_dot_q1_0_g128_q8_0#11SimesD61 wants to merge 1 commit intoPrismML-Eng:prismfrom
SimesD61 wants to merge 1 commit intoPrismML-Eng:prismfrom
Conversation
The x86 implementation was a stub that called the scalar generic fallback. The ARM NEON kernel was already fully vectorized. This implements the same algorithm using AVX2 intrinsics. Key techniques: - vpshufb (mm_shuffle_epi8) to broadcast each 4-byte sub-block to 32 lanes - AND+cmpeq to decode 1-bit weights to sign bytes (+1/-1) - maddubs_epi16 + madd_epi16 for INT8 dot product reduction - 4 independent FMA accumulators to hide the 5-cycle FMA latency Performance on Intel i7-8700B (no AVX-512): - Before: ~0.04 tok/s (scalar fallback, 67x slower than ARM CPU) - After: ~8 tok/s (AVX2, matches compute-bound ceiling for Q1_0_g128) - ~200x speedup over the stub Falls back to generic implementation on non-AVX2 targets.
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.
Problem
The x86 implementation of
ggml_vec_dot_q1_0_g128_q8_0inggml/src/ggml-cpu/arch/x86/quants.cwas a stub that immediately fell through to the scalar generic fallback:The ARM NEON implementation was already fully vectorized. On x86 this meant Bonsai 8B ran at ~0.04 tok/s — 67× slower than the ARM CPU path.
Solution
Full AVX2 implementation using the same algorithm as the NEON kernel:
vpshufbbit expansion: Each 32-bit sub-block is broadcast to 32 bytes via_mm_shuffle_epi8, then AND+cmpeq decodes 1-bit weights to sign bytes (+1/-1)maddubs_epi16+madd_epi16for efficient 8-bit multiply-accumulateblock_q1_0_g128layout)Performance (Intel i7-8700B, AVX2, no AVX-512)
The 8 tok/s result is at the compute-bound ceiling for Q1_0_g128 on this CPU — Q1_0_g128 is ~4x more compute-intensive per byte than Q4_0, so further gains would require AVX-512 or a fundamentally different algorithm.