Repository navigation
perf(ggml-hip): SWAR __vsub4 and __vcmpne4 for the IQ2/IQ3 decoders - #766
Merged
Merged
Conversation
Backport of ggml-org/llama.cpp#27962. The HIP fallbacks for these CUDA byte-SIMD intrinsics compiled to per-byte loops (__vcmpne4) and a saturating subtract (__vsub4). Replace them with SWAR bit arithmetic. Every caller (the IQ2_XXS/XS/S and IQ3_XXS/S MMVQ and MMQ paths) applies signs as (g ^ s) - s with s in {0x00, 0xff} per byte and grid bytes at most 62, so the wrapping subtract never differs from the saturating one: the decoded weights are bit-identical. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
Summary
Backport of ggml-org/llama.cpp#27962. On HIP, the fallbacks for the CUDA byte-SIMD intrinsics
__vcmpne4and__vsub4compiled to a per-byte loop and a saturating subtract. This replaces them with SWAR bit arithmetic inggml-cuda/vendors/hip.h.The only callers are the IQ2_XXS/XS/S and IQ3_XXS/S decoders in the MMVQ and MMQ paths (20 call sites). All of them apply signs as
(g ^ s) - s, withsin {0x00, 0xff} per byte and grid bytes of at most 62, so the wrapping subtract never differs from the saturating one. The decoded weights are bit-identical.This matters for the published Qwen3.8 file: UD-IQ4_XS keeps 2.4 GB of its tensors in IQ3_S/IQ3_XXS/IQ2_S/IQ2_XS. At the 16-row verify shape those ran at 117-240 GB/s, vs 444 GB/s for IQ4_XS (rocprofv3 on an R9700).
Results
R9700 (gfx1201), Qwen3.8-27B UD-IQ4_XS + DFlash2 q8_0, published profile (
--draft-block-size 16 --max-ctx 131072 --cache-type-k q8_0 --cache-type-v q8_0). Both sides include #765:Upstream measured +21.6% tg128 on a Qwen3.8-27B UD-IQ3_S file on gfx1201.
Test plan
__vsub4caller audited for saturation (none reachable)🤖 Generated with Claude Code