Skip to content

Add explicit template specialization declarations for MSVC linking#4992

Open
alibeklfc wants to merge 2 commits intofacebookresearch:mainfrom
alibeklfc:export-D98232371
Open

Add explicit template specialization declarations for MSVC linking#4992
alibeklfc wants to merge 2 commits intofacebookresearch:mainfrom
alibeklfc:export-D98232371

Conversation

@alibeklfc
Copy link
Copy Markdown
Contributor

Summary:
Add explicit specialization declarations for all SIMD-templated distance
functions in distances.h.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the _avx2 translation units.

The macro FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL) declares all 17
distance function specializations for a given SIMDLevel, and is expanded
for SIMDLevel::NONE and SIMDLevel::AVX2.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371

…kresearch#4989)

Summary:

Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang)
and Windows (MSVC).

**macOS fixes (AppleClang):**

1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers:
   - `simdlib_emulated.h` (4 call sites)
   - `simdlib_avx2.h` (4 call sites)
   - `simdlib_avx512.h` (3 call sites)

   AppleClang marks `sprintf` as deprecated. The fix replaces
   `ptr += sprintf(ptr, fmt, val)` with
   `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`,
   where the second argument computes the remaining buffer space. This is
   safe and behavior-preserving: these are debug-only `tostring()` methods
   that format small integers/floats into 1000-2000 byte buffers, using at
   most ~256 bytes in the worst case (64 elements × ~4 chars). When output
   fits (which it always does), `snprintf` returns the same value as
   `sprintf`, so `ptr` advances identically.

2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`:
   - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h`
   - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h`
   - `IDSelectorModulo::is_member()` in `faiss_example_external_module.swig`

   These methods override virtual base class methods but lacked the
   `override` keyword. Adding it is purely declarative — no behavioral
   change, but enables compile-time checking if the base signature changes.

**Windows fixes (MSVC):**

3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)`
   to silence MSVC C4068 "unknown pragma" warnings in:
   - `simdlib_emulated.h`, `simdlib_avx2.h`, `simdlib_avx512.h`
   - `IVFlib.cpp`, `PolysemousTraining.cpp`

   The pragmas only control warning suppression (for `-Wformat-nonliteral`)
   and have zero effect on code generation. GCC/Clang still see them and
   behave identically; MSVC skips them (it doesn't have that warning anyway).

4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for
   `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit
   on Windows, so `%ld` is wrong for both types). These are debug-only
   `IFV printf` calls gated behind a verbose flag.

5. Fix `size_t` to `int` narrowing in `IndexIVFSpectralHash.cpp` (MSVC C4267):
   `std::make_unique<RandomRotationMatrix>(d_in, nbit_in)` where `d_in` is
   `size_t` but the constructor takes `int`. Added `static_cast<int>(d_in)`.
   Safe because `d_in` is vector dimensionality (typically 64-2048).

6. Fix pointer-to-`long` truncation in `distances_sse-inl.h` (MSVC C4311):
   Alignment check `(long)ptr & 15` truncates 64-bit pointers on Windows
   where `long` is 32-bit. Changed to `(uintptr_t)ptr` which is correct
   on all platforms. The alignment test logic is unchanged.

Reviewed By: mnorris11

Differential Revision: D98197799
Summary:
Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
@meta-cla meta-cla bot added the CLA Signed label Mar 26, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 26, 2026

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

alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 26, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 27, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 27, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 27, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 28, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 30, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Mar 31, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Apr 1, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Apr 1, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Apr 1, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
alibeklfc added a commit to alibeklfc/faiss that referenced this pull request Apr 1, 2026
…acebookresearch#4992)

Summary:

Add explicit specialization declarations for all SIMD-templated distance
functions in `distances.h`.

C++ [temp.expl.spec]/7 requires that explicit specialization declarations
appear before any translation unit that might implicitly instantiate the
primary template. GCC/Clang are lenient about this ordering, but MSVC
strictly enforces it — without these declarations, the linker emits
LNK2001 (unresolved external symbol) for the specializations defined in
the `_avx2` translation units.

The macro `FAISS_DECLARE_DISTANCES_SPECIALIZATIONS(SL)` declares all 17
distance function specializations for a given `SIMDLevel`, and is expanded
for `SIMDLevel::NONE` and `SIMDLevel::AVX2`.

This is a no-op on GCC/Clang (declarations are redundant but harmless).

Differential Revision: D98232371
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.

2 participants