Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5159
After the SIMD dispatch refactoring, the PQ code distance implementations
(pq_code_distance_single_impl<SL>, pq_code_distance_four_impl<SL>) lived in
separate translation units from the scanner loops (IVFPQScannerT::scan_list_with_table,
PQDistanceComputer::distance_to_code). The compiler could not inline the SIMD
gather/accumulate code into the hot inner loops.
This diff converts the per-SIMD pq_code_distance .cpp files to .h headers and
includes them in the corresponding scanner TUs before the scanner _impl.h
includes. This puts the kernel definitions in the same TU, enabling the compiler
to inline the AVX2/AVX512 vgatherdps code directly into scan_list_with_table and
scan_list_polysemous_hc.
Changes:
- pq_code_distance-avx2.cpp → pq_code_distance-avx2.h (header, #pragma once)
- pq_code_distance-avx512.cpp → pq_code_distance-avx512.h (same)
- New pq_code_distance-generic.h with inline NONE/ARM_NEON specializations
- Scanner TUs (avx2.cpp, avx512.cpp, neon.cpp) include the PQ distance headers
- PQCodeDistance gains static constexpr simd_level member
- scan_list_polysemous uses PQCodeDist::simd_level for Hamming computer dispatch
(was hardcoded to SIMDLevel::NONE)
- Scanner TUs include per-ISA hamming_computer headers for SIMD Hamming dispatch
- Build files (xplat.bzl, CMakeLists.txt) updated
Verified via objdump that scan_list_with_table and scan_list_polysemous_hc contain
zero calls to pq_code_distance_*_impl — all AVX2/AVX512 gather code is fully inlined.
Reviewed By: algoriddle
Differential Revision: D102942787
fbshipit-source-id: d2979f9cd629652ac1de4886afd3c335fbb4fac8
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/5127
Attempt to enable FAISS dynamic dispatch (DD) mode on Windows/MSVC.
Changes:
- CMakeLists.txt: Remove if(NOT WIN32) guard from DD section, add MSVC per-file
SIMD flags (/arch:AVX2, /arch:AVX512, /bigobj) alongside existing GCC/Clang flags
- build-pull-request.yml: Add windows-x86_64-DD-cmake job that runs immediately
(no dependency on linux-x86_64-cmake), builds with MSVC and FAISS_OPT_LEVEL=dd,
runs C++ tests and Python tests
This diff is expected to fail on Windows due to MSVC requiring explicit template
specialization declarations (C++ §17.8.3) which GCC/Clang don't enforce. The CI
failure will surface the exact errors to guide the fix.
UPDATE: in fact, MSVC does not seem to require this. After fixing build scripts and a few classical Windows error, the C++ and python tests pass.
Reviewed By: algoriddle
Differential Revision: D101649751
fbshipit-source-id: 765ef8483d02652ce58625cd22baab8870acf718
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4808
Convert PQ code distance from compile-time #ifdef __AVX2__ header dispatch to DD-compatible runtime dispatch using PQCodeDistance<PQDecoderT, SIMDLevel> struct templates with per-file SIMD compilation.
Key changes:
- Replace free functions (distance_single_code, distance_four_codes) with PQCodeDistance<PQDecoderT, SIMDLevel> struct template
- Rename impl/code_distance/ to impl/pq_code_distance/ with pq_ prefix on all filenames
- Move public header to faiss/utils/pq_code_distance.h; keep private -inl.h in faiss/impl/pq_code_distance/
- Add enclosing namespace pq_code_distance inside namespace faiss, with using re-exports in the public header for backward compatibility
- Rename .h implementation files to .cpp for per-file SIMD flag compilation
- Add forward declarations of specializations in pq_code_distance-inl.h to prevent callers from silently using the generic primary template
- Use COMPILE_SIMD_* guards only (no redundant || __AVX2__ since build system always defines COMPILE_SIMD_* alongside compiler flags)
- Add pq_code_distance-generic.cpp with DISPATCH_SIMDLevel wrappers for runtime dispatch
- Update IndexIVFPQ.cpp and IndexPQ.cpp to use DISPATCH_SIMDLevel at scanner/distance-computer construction boundary
- Update xplat.bzl SIMD_FILES and CMakeLists.txt SIMD registries
- Update unicorn callers (PQFSTable.h, FeatureEncoding.cpp, FeatureEncodingBenchmark.cpp) to new include path
Based on D72937709, reworked to match current master and DD design doc.
Reviewed By: mdouze
Differential Revision: D93217005
fbshipit-source-id: 8a1b0cce2757e9e96eb2f2e2fb28b71dcdf71557