reorganize the scalar quantizer code for dynamic dispatch#4849
Open
mdouze wants to merge 2 commits into
Open
Conversation
…spatch Summary: Split the SIMD-gated template specializations out of ScalarQuantizer.cpp into per-SIMD compilation units and wire up the Dynamic Dispatch (DD) infrastructure (`COMPILE_SIMD_*`, `with_simd_level`, `DISPATCH_SIMDLevel`). This follows the established pattern from `pq_code_distance/` and `distances/`. **New files:** - `sq_impl.h` — declares `sq_select_quantizer<SL>`, `sq_select_distance_computer<SL>`, `sq_select_InvertedListScanner<SL>` - `sq-inl.h` — private implementation header with shared template bodies (`select_quantizer_1_body`, `select_distance_computer_body`, `select_InvertedListScanner_body`) and scanner class templates (`IVFSQScannerIP`, `IVFSQScannerL2`) - `sq-generic.cpp` — `SIMDLevel::NONE` specializations (always compiled) - `sq-avx2.cpp` — `SIMDLevel::AVX2` specializations (`d%8` alignment) - `sq-avx512.cpp` — `SIMDLevel::AVX512` + `AVX512_SPR` forwarding - `sq-neon.cpp` — `SIMDLevel::ARM_NEON` specializations (`d%8` alignment) **Modified files:** - `ScalarQuantizer.cpp` — rewritten to use `with_simd_level` dispatch with nullptr-fallback to NONE - `quantizers.h`, `distance_computers.h` — lint formatting only - `xplat.bzl`, `CMakeLists.txt` — register new SIMD files and headers Each per-SIMD factory returns `nullptr` when the dimension doesn't align, and the caller falls back to NONE. This avoids ODR issues from instantiating `<NONE>` templates in multiple TUs. The sub-headers (codecs.h, quantizers.h, similarities.h, distance_computers.h) keep their original compiler-defined guards (`__AVX512F__`, `__AVX2__`, `USE_NEON`, etc.) because `COMPILE_SIMD_*` macros are globally visible in DD mode but the SIMD intrinsics are only available in per-SIMD TUs. The `USE_*` macros are now defined in `sq-inl.h`. Differential Revision: D94375408
Contributor
mdouze
added a commit
to mdouze/faiss
that referenced
this pull request
Feb 27, 2026
…search#4849) Summary: Pull Request resolved: facebookresearch#4849 This version introduces a cleaner separation between the SIMD templatized code. It also avoids multiple levels of indirection that existed in the original diff. The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate. ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels. Differential Revision: D94588394
f913d63 to
dfecf79
Compare
mdouze
added a commit
to mdouze/faiss
that referenced
this pull request
Mar 2, 2026
…search#4849) Summary: Pull Request resolved: facebookresearch#4849 This version introduces a cleaner separation between the SIMD templatized code. It also avoids multiple levels of indirection that existed in the original diff. The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate. ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels. Differential Revision: D94588394
mdouze
added a commit
to mdouze/faiss
that referenced
this pull request
Mar 2, 2026
…search#4849) Summary: Pull Request resolved: facebookresearch#4849 This version introduces a cleaner separation between the SIMD templatized code. It also avoids multiple levels of indirection that existed in the original diff. The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate. ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels. Differential Revision: D94588394
mdouze
added a commit
to mdouze/faiss
that referenced
this pull request
Mar 2, 2026
…search#4849) Summary: Pull Request resolved: facebookresearch#4849 This version introduces a cleaner separation between the SIMD templatized code. It also avoids multiple levels of indirection that existed in the original diff. The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate. ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels. Differential Revision: D94588394
…search#4849) Summary: Pull Request resolved: facebookresearch#4849 This version introduces a cleaner separation between the SIMD templatized code. It also avoids multiple levels of indirection that existed in the original diff. The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate. ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels. Differential Revision: D94588394
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:
This version introduces a cleaner separation between the SIMD templatized code.
It also avoids multiple levels of indirection that existed in the original diff.
The dispatching functions are now in sq-dispatch.h, which is piloted by a macro that tells it which SIMD level to instanciate.
ScalarQuantizer.cpp instanciates level NONE and the sq-XXX.cpp versions instanciate the other SIMD levels.
Differential Revision: D94588394