Optimize multibit sign-bit unpacking in RaBitQ FastScan handlers#5097
Open
alibeklfc wants to merge 2 commits intofacebookresearch:mainfrom
Open
Optimize multibit sign-bit unpacking in RaBitQ FastScan handlers#5097alibeklfc wants to merge 2 commits intofacebookresearch:mainfrom
alibeklfc wants to merge 2 commits intofacebookresearch:mainfrom
Conversation
…cebookresearch#5095) Summary: D100399519 added IVFRaBitQSearchParameters support to the FastScan scanner but only patched the distance_to_code fallback path. The main search path (LUT construction and SIMD distance correction in handle()) still read qb/centered from the index, ignoring the search params override. This diff completes the fix by: 1. Adding qb/centered fields to FastScanDistancePostProcessing context 2. Threading them through compute_LUT → compute_residual_LUT 3. Reading them from context in the handler's handle() method 4. Extracting them from IVFRaBitQSearchParameters in search_preassigned Differential Revision: D100674751
Summary: Replace `CodePackerRaBitQ::unpack_1()` with `rabitq_utils::unpack_sign_bits_from_packed()` in both `RaBitQHeapHandler` and `IVFRaBitQHeapHandler` multibit refinement paths. The old path called `pq4_get_packed_element` twice per output byte, each call recomputing the vector's in-block position from scratch (division, modulo, branches). The new function precomputes the PQ4 address once and iterates with simple strided byte loads. It also skips the unnecessary auxiliary data copy that `unpack_1` performed. Micro-benchmark results (unpack-only, median ns/call): | d | Old (ns) | New (ns) | Speedup | |------|----------|----------|---------| | 64 | 627 | 166 | 3.8x | | 128 | 1204 | 279 | 4.3x | | 256 | 2329 | 525 | 4.4x | | 512 | 4583 | 996 | 4.6x | | 768 | 6731 | 1376 | 4.9x | | 1024 | 9344 | 1819 | 5.1x | End-to-end (unpack + SIMD distance) speedup is 1.4-1.6x. Additional cleanup: removed `CodePacker` heap allocation and virtual dispatch from both handlers. Differential Revision: D100718832
Contributor
|
@alibeklfc has exported this pull request. If you are a Meta employee, you can view the originating Diff in D100718832. |
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:
Replace
CodePackerRaBitQ::unpack_1()withrabitq_utils::unpack_sign_bits_from_packed()in bothRaBitQHeapHandlerandIVFRaBitQHeapHandlermultibit refinement paths.The old path called
pq4_get_packed_elementtwice per output byte, each call recomputing the vector's in-block position from scratch (division, modulo, branches). The new function precomputes the PQ4 address once and iterates with simple strided byte loads. It also skips the unnecessary auxiliary data copy thatunpack_1performed.Micro-benchmark results (unpack-only, median ns/call):
End-to-end (unpack + SIMD distance) speedup is 1.4-1.6x.
Additional cleanup: removed
CodePackerheap allocation and virtual dispatch from both handlers.Differential Revision: D100718832