Commit ccc934f
ScalarQuantizer: split SIMD specializations into per-SIMD TUs + DD dispatch (#4839)
Summary:
Pull Request resolved: #4839
Split the SIMD-gated template specializations out of ScalarQuantizer.cpp
and the shared headers into per-SIMD compilation units and wire up the
Dynamic Dispatch (DD) infrastructure (COMPILE_SIMD_*, with_simd_level).
**What moved where**
- SIMD specializations removed from `codecs.h`, `quantizers.h`,
`similarities.h`, `distance_computers.h` — these now contain only
primary templates and scalar (`SIMDLevel::NONE`) specializations.
(Most use empty primary templates; `quantizers.h` uses an inheriting
fallback pattern for `QuantizerFP16`, `QuantizerBF16`, etc.)
- SIMD specializations moved into `sq-avx2.cpp` / `sq-avx512.cpp` /
`sq-neon.cpp`, each guarded by `COMPILE_SIMD_*`.
- `sq-generic.cpp` deleted — the `NONE` level is now instantiated
directly in `ScalarQuantizer.cpp` via `sq-dispatch.h`.
- `sq-inl.h` renamed to `scanners.h`.
**Dispatch mechanism**
- `sq-dispatch.h` is an X-macro-style header: each per-SIMD `.cpp` file
`#define`s `THE_LEVEL_TO_DISPATCH` and `#include`s it to stamp out
explicit template specializations of the selection functions
(`sq_select_quantizer`, `sq_select_distance_computer`,
`sq_select_InvertedListScanner`).
- `ScalarQuantizer.cpp` uses `with_simd_level` for runtime dispatch
and instantiates the `NONE` level via the same `sq-dispatch.h`.
- Each per-SIMD selection function returns `nullptr` when the dimension
doesn't align, and the caller falls back to `NONE`.
- `sq-neon.cpp` handles both `ARM_NEON` and `ARM_SVE` (SVE forwards
to NEON — no dedicated SVE SQ implementation yet).
**Build**
- `xplat.bzl`, `CMakeLists.txt` — register new SIMD source files and
headers.
- Within the SQ module, `COMPILE_SIMD_*` macros gate all SIMD code
paths. (Compiler-defined macros like `__AVX2__` are still used in
lower-level shared headers like `simdlib.h` and `fp16.h`.)
Reviewed By: mdouze
Differential Revision: D94375408
fbshipit-source-id: a07c31540242defcc605dd74e07bd25b8c163f431 parent db9ba35 commit ccc934f
14 files changed
Lines changed: 1980 additions & 1699 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
| 252 | + | |
249 | 253 | | |
| 254 | + | |
250 | 255 | | |
251 | 256 | | |
252 | 257 | | |
| |||
440 | 445 | | |
441 | 446 | | |
442 | 447 | | |
443 | | - | |
| 448 | + | |
444 | 449 | | |
445 | 450 | | |
446 | 451 | | |
| |||
0 commit comments