1 Commits
Author SHA1 Message Date
Gergely Szilvasy 56ae01622f Introduce Dynamic Dispatch infrastructure with SIMDConfig (#4780)
Summary:
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4780

Introduces Dynamic Dispatch (DD) infrastructure for FAISS, enabling runtime SIMD level selection via buckconfig parameterization.

Build Configuration:
- Enable with: buck build -c faiss.dynamic_dispatch=true //faiss:faiss
- is_dd_enabled() function in fbcode.bzl reads buckconfig
- DD mode is purely additive - all static build options remain available

Core Components:

simd_levels.h/cpp - Runtime SIMD detection:
- SIMDLevel enum: NONE, AVX2, AVX512, AVX512_SPR, ARM_NEON
- SIMDConfig class: auto-detects CPU capabilities via CPUID
- FAISS_SIMD_LEVEL env var override for testing/debugging
- Guarded by FAISS_ENABLE_DD preprocessor flag

DISPATCH_SIMDLevel macro - Dual-mode dispatch:
- DD mode: runtime switch on SIMDConfig::level
- Static mode: compiles to direct call (zero overhead)

simd_dispatch.bzl - Build configuration:
- Per-architecture SIMD level configuration
- Per-file compiler flags (SIMD files get -mavx2/-mavx512f, common files get baseline)
- Generates source file lists and flags for each SIMD level

Test Infrastructure:
- DD-only tests use target_compatible_with to exclude from static builds
- Static tests continue to work unchanged
- Both modes share the same test logic where applicable

Reviewed By: mdouze, mnorris11

Differential Revision: D72937710

fbshipit-source-id: c9f06595f1ac6966ab1d2f3b5bc25afcf25638a4
2026-02-09 01:19:35 -08:00