Skip to content

Switch all search paths to FastScanCodeScanner and remove make_knn_handler#4904

Open
algoriddle wants to merge 3 commits intofacebookresearch:mainfrom
algoriddle:export-D96116555
Open

Switch all search paths to FastScanCodeScanner and remove make_knn_handler#4904
algoriddle wants to merge 3 commits intofacebookresearch:mainfrom
algoriddle:export-D96116555

Conversation

@algoriddle
Copy link
Contributor

Summary:
Now that every make_knn_scanner() returns a real scanner (never nullptr),
switch all callers to use scanners directly and remove make_knn_handler.

Add impl param to make_knn_scanner and its factory so heap vs reservoir
selection respects the implem setting. Switch IndexFastScan
search_implem_12/14, IndexIVFFastScan search_dispatch_implem/range_search,
and IndexIVFPQFastScan scan_codes to scanner-only paths. Add range scanner
factories (make_range_scanner, make_partial_range_scanner). Remove
make_knn_handler from all classes. Change search_implem_10/12 scanner
param from pointer to reference.

Differential Revision: D96116555

@meta-codesync
Copy link
Contributor

meta-codesync bot commented Mar 11, 2026

@algoriddle has exported this pull request. If you are a Meta employee, you can view the originating Diff in D96116555.

algoriddle added a commit to algoriddle/faiss that referenced this pull request Mar 11, 2026
…ndler (facebookresearch#4904)

Summary:
Pull Request resolved: facebookresearch#4904

Now that every make_knn_scanner() returns a real scanner (never nullptr),
switch all callers to use scanners directly and remove make_knn_handler.

Add impl param to make_knn_scanner and its factory so heap vs reservoir
selection respects the implem setting. Switch IndexFastScan
search_implem_12/14, IndexIVFFastScan search_dispatch_implem/range_search,
and IndexIVFPQFastScan scan_codes to scanner-only paths. Add range scanner
factories (make_range_scanner, make_partial_range_scanner). Remove
make_knn_handler from all classes. Change search_implem_10/12 scanner
param from pointer to reference.

Differential Revision: D96116555
algoriddle added a commit to algoriddle/faiss that referenced this pull request Mar 11, 2026
…ndler (facebookresearch#4904)

Summary:
Pull Request resolved: facebookresearch#4904

Now that every make_knn_scanner() returns a real scanner (never nullptr),
switch all callers to use scanners directly and remove make_knn_handler.

Add impl param to make_knn_scanner and its factory so heap vs reservoir
selection respects the implem setting. Switch IndexFastScan
search_implem_12/14, IndexIVFFastScan search_dispatch_implem/range_search,
and IndexIVFPQFastScan scan_codes to scanner-only paths. Add range scanner
factories (make_range_scanner, make_partial_range_scanner). Remove
make_knn_handler from all classes. Change search_implem_10/12 scanner
param from pointer to reference.

Differential Revision: D96116555
Summary:
Add `FastScanCodeScanner`, a virtual base that bundles handler + kernel
behind the SIMD dispatch boundary. In DD mode, `SINGLE_SIMD_LEVEL = NONE`
so the existing fast scan code path uses emulated SIMD types. The new
scanner provides per-SIMD translation units (AVX2, AVX512, ARM_NEON)
compiled with the correct ISA flags, and a factory function
(`make_fast_scan_knn_scanner`) that uses `DISPATCH_SIMDLevel` to select
the right TU at runtime.

This follows the proven `THE_LEVEL_TO_DISPATCH` pattern from the scalar
quantizer per-SIMD TUs (`sq-dispatch.h`). Each per-SIMD TU includes
`dispatching.h` which provides:
- `ScannerMixIn<Handler>`: wraps a concrete handler and calls accumulation
  kernels (both search_1 multi-BB and QBS paths)
- Factory specialization `make_fast_scan_scanner_impl<SL>()` with
  combinatorial dispatch over `is_max × with_id_map × handler_type`
  (SingleResultHandler for k=1, HeapHandler for k≤20, ReservoirHandler
  for k>20)

New files:
- `impl/fast_scan/dispatching.h` — dispatch template header
- `impl/fast_scan/impl-avx2.cpp` — AVX2 per-SIMD TU
- `impl/fast_scan/impl-avx512.cpp` — AVX512 per-SIMD TU
- `impl/fast_scan/impl-neon.cpp` — ARM NEON TU (with ARM_SVE forwarding)

Modified files:
- `impl/fast_scan/pq4_fast_scan.h` — FastScanCodeScanner base + factory decl
- `impl/fast_scan/pq4_fast_scan.cpp` — NONE specialization + dispatch wrapper
- `xplat.bzl` / `CMakeLists.txt` — register SIMD files and header

Note: RaBitQ handler is not wired through FastScanCodeScanner in this
diff. That comes in later diffs when callers are switched.

Differential Revision: D95950483
Summary:
Add make_knn_scanner() virtual to IndexFastScan and IndexIVFFastScan
that returns a SIMD-dispatched FastScanCodeScanner. Override in
RaBitQ classes to produce rabitq-specific scanners via per-SIMD TU
factories (rabitq_dispatching.h). Move RaBitQ handler method bodies
into headers, add context pointer, and update rabitq_result_handler.h
for SL template param. Wire IVFRaBitQFastScanScanner::scan_codes to
use the new scanner. Update build files and SWIG ignores.

Callers (search_implem_12/14, search_dispatch_implem) are unchanged
and still use make_knn_handler.

Differential Revision: D96116557
…ndler (facebookresearch#4904)

Summary:
Pull Request resolved: facebookresearch#4904

Now that every make_knn_scanner() returns a real scanner (never nullptr),
switch all callers to use scanners directly and remove make_knn_handler.

Add impl param to make_knn_scanner and its factory so heap vs reservoir
selection respects the implem setting. Switch IndexFastScan
search_implem_12/14, IndexIVFFastScan search_dispatch_implem/range_search,
and IndexIVFPQFastScan scan_codes to scanner-only paths. Add range scanner
factories (make_range_scanner, make_partial_range_scanner). Remove
make_knn_handler from all classes. Change search_implem_10/12 scanner
param from pointer to reference.

Reviewed By: mdouze

Differential Revision: D96116555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant