Skip to content

Commit aa1cc48

Browse files
mdouzefacebook-github-bot
authored andcommitted
Enable dynamic dispatch build on Windows
Summary: 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. Differential Revision: D101649751
1 parent e23c661 commit aa1cc48

2 files changed

Lines changed: 72 additions & 13 deletions

File tree

.github/workflows/build-pull-request.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,54 @@ jobs:
170170
fetch-tags: true
171171
- name: Build and Package (conda)
172172
uses: ./.github/actions/build_conda
173+
windows-x86_64-DD-cmake:
174+
name: Windows x86_64 Dynamic Dispatch (cmake)
175+
runs-on: windows-2022
176+
steps:
177+
- name: Checkout
178+
uses: actions/checkout@v4
179+
- name: Setup miniconda
180+
uses: conda-incubator/setup-miniconda@v3
181+
with:
182+
python-version: '3.12'
183+
miniforge-version: latest
184+
channels: conda-forge
185+
- name: Install dependencies
186+
shell: pwsh
187+
run: |
188+
conda install -y -q cmake swig "numpy>=2.0,<3.0" scipy pytest gflags setuptools
189+
conda install -y -q mkl=2024.2.2 mkl-devel=2024.2.2
190+
conda install -y -q "pytorch<2.5" -c pytorch
191+
- name: Build
192+
shell: pwsh
193+
run: |
194+
cmake -B build -T v143 -A x64 -G "Visual Studio 17 2022" `
195+
-DBUILD_TESTING=ON `
196+
-DBUILD_SHARED_LIBS=ON `
197+
-DFAISS_ENABLE_GPU=OFF `
198+
-DFAISS_OPT_LEVEL=dd `
199+
-DFAISS_ENABLE_PYTHON=ON `
200+
-DFAISS_ENABLE_C_API=ON `
201+
-DPYTHON_EXECUTABLE="$env:CONDA\python.exe" `
202+
-DBLA_VENDOR=Intel10_64_dyn `
203+
-DCMAKE_BUILD_TYPE=Release `
204+
.
205+
cmake --build build --config Release -j $env:NUMBER_OF_PROCESSORS
206+
- name: C++ tests
207+
shell: pwsh
208+
run: |
209+
cd build
210+
ctest --output-on-failure -C Release
211+
- name: Install Python extension
212+
shell: pwsh
213+
working-directory: build/faiss/python
214+
run: |
215+
& "$env:CONDA\python.exe" setup.py install
216+
- name: Python tests
217+
shell: pwsh
218+
run: |
219+
& "$env:CONDA\python.exe" -m pytest tests/test_*.py
220+
& "$env:CONDA\python.exe" -m pytest tests/torch_*.py
173221
windows-x86_64-conda:
174222
name: Windows x86_64 (conda)
175223
needs: linux-x86_64-cmake

faiss/CMakeLists.txt

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,16 @@ target_compile_definitions(faiss_sve PRIVATE COMPILE_SIMD_ARM_NEON COMPILE_SIMD_
450450
if(FAISS_OPT_LEVEL STREQUAL "dd")
451451
# Add SIMD source files to main faiss target for DD builds
452452
target_sources(faiss PRIVATE ${FAISS_SIMD_SRC})
453-
if(NOT WIN32)
454-
target_compile_definitions(faiss PRIVATE FAISS_ENABLE_DD)
455-
# Architecture-specific SIMD definitions for Dynamic Dispatch
456-
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64|AMD64)")
457-
target_compile_definitions(faiss PRIVATE
458-
COMPILE_SIMD_AVX2 COMPILE_SIMD_AVX512 COMPILE_SIMD_AVX512_SPR)
453+
target_compile_definitions(faiss PRIVATE FAISS_ENABLE_DD)
454+
# Architecture-specific SIMD definitions for Dynamic Dispatch
455+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64|AMD64)")
456+
target_compile_definitions(faiss PRIVATE
457+
COMPILE_SIMD_AVX2 COMPILE_SIMD_AVX512 COMPILE_SIMD_AVX512_SPR)
458+
if(NOT WIN32)
459459
# Baseline flags for common files (prevents auto-vectorization)
460460
target_compile_options(faiss PRIVATE
461461
$<$<COMPILE_LANGUAGE:CXX>:-mpopcnt -msse4 -mno-avx -mno-avx2>)
462-
# Per-file SIMD flags
462+
# Per-file SIMD flags (GCC/Clang)
463463
set_source_files_properties(${FAISS_SIMD_AVX2_SRC}
464464
TARGET_DIRECTORY faiss
465465
PROPERTIES COMPILE_OPTIONS "-mavx2;-mfma;-mf16c;-mpopcnt"
@@ -469,15 +469,26 @@ if(FAISS_OPT_LEVEL STREQUAL "dd")
469469
PROPERTIES COMPILE_OPTIONS
470470
"-mavx512f;-mavx512cd;-mavx512vl;-mavx512dq;-mavx512bw;-mfma;-mf16c;-mpopcnt"
471471
)
472-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64|arm64|ARM64)")
473-
# ARM NEON is always available on aarch64, no special compiler flags needed
474-
target_compile_definitions(faiss PRIVATE COMPILE_SIMD_ARM_NEON COMPILE_SIMD_ARM_SVE)
475-
# Per-file SVE flags (NEON needs no flags on aarch64)
476-
set_source_files_properties(${FAISS_SIMD_SVE_SRC}
472+
else()
473+
# Per-file SIMD flags (MSVC)
474+
add_compile_options(/bigobj)
475+
set_source_files_properties(${FAISS_SIMD_AVX2_SRC}
476+
TARGET_DIRECTORY faiss
477+
PROPERTIES COMPILE_OPTIONS "/arch:AVX2"
478+
)
479+
set_source_files_properties(${FAISS_SIMD_AVX512_SRC}
477480
TARGET_DIRECTORY faiss
478-
PROPERTIES COMPILE_OPTIONS "-march=armv8.2-a+sve"
481+
PROPERTIES COMPILE_OPTIONS "/arch:AVX512"
479482
)
480483
endif()
484+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64|arm64|ARM64)")
485+
# ARM NEON is always available on aarch64, no special compiler flags needed
486+
target_compile_definitions(faiss PRIVATE COMPILE_SIMD_ARM_NEON COMPILE_SIMD_ARM_SVE)
487+
# Per-file SVE flags (NEON needs no flags on aarch64)
488+
set_source_files_properties(${FAISS_SIMD_SVE_SRC}
489+
TARGET_DIRECTORY faiss
490+
PROPERTIES COMPILE_OPTIONS "-march=armv8.2-a+sve"
491+
)
481492
endif()
482493
endif()
483494

0 commit comments

Comments
 (0)