diff --git a/faiss/impl/pq_code_distance/pq_code_distance-generic.h b/faiss/impl/pq_code_distance/pq_code_distance-generic.h index cc8171811..09dbc0b84 100644 --- a/faiss/impl/pq_code_distance/pq_code_distance-generic.h +++ b/faiss/impl/pq_code_distance/pq_code_distance-generic.h @@ -20,8 +20,8 @@ inline float pq_code_distance_8bit_single_impl( size_t M, const float* sim_table, const uint8_t* code) { - return PQCodeDistanceScalar::distance_single_code( - M, 8, sim_table, code); + return PQCodeDistanceScalar:: + distance_single_code(M, 8, sim_table, code); } // NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization) @@ -37,7 +37,7 @@ inline void pq_code_distance_8bit_four_impl( float& result1, float& result2, float& result3) { - PQCodeDistanceScalar::distance_four_codes( + PQCodeDistanceScalar::distance_four_codes( M, 8, sim_table, @@ -60,8 +60,8 @@ inline float pq_code_distance_8bit_single_impl( size_t M, const float* sim_table, const uint8_t* code) { - return PQCodeDistanceScalar::distance_single_code( - M, 8, sim_table, code); + return PQCodeDistanceScalar:: + distance_single_code(M, 8, sim_table, code); } // NOLINTNEXTLINE(facebook-hte-MisplacedTemplateSpecialization) @@ -77,7 +77,7 @@ inline void pq_code_distance_8bit_four_impl( float& result1, float& result2, float& result3) { - PQCodeDistanceScalar::distance_four_codes( + PQCodeDistanceScalar::distance_four_codes( M, 8, sim_table, diff --git a/faiss/impl/pq_code_distance/pq_code_distance-inl.h b/faiss/impl/pq_code_distance/pq_code_distance-inl.h index 6cb80339d..5900fd09e 100644 --- a/faiss/impl/pq_code_distance/pq_code_distance-inl.h +++ b/faiss/impl/pq_code_distance/pq_code_distance-inl.h @@ -62,10 +62,14 @@ namespace pq_code_distance { *********************************************************************/ /// Scalar PQ code distance implementation. -/// Templated only on decoder type, independent of SIMD level. /// Used directly by non-PQDecoder8 decoders (PQDecoder16, /// PQDecoderGeneric) and as fallback for PQDecoder8 at NONE/NEON. -template +// SL keeps each SIMD-level TU's instantiation a distinct symbol. Without it +// the linker merges them and may keep one compiled with -mavx512*, which +// then runs on the AVX2 path and raises SIGILL on CPUs without AVX512. +// The default keeps callers outside faiss that name only the decoder (e.g. +// unicorn/features/encoders/PQFSTable.h) compiling; faiss passes SL itself. +template struct PQCodeDistanceScalar { using PQDecoder = PQDecoderT; @@ -168,7 +172,7 @@ struct PQCodeDistance { if constexpr (std::is_same_v) { return pq_code_distance_8bit_single_impl(M, sim_table, code); } else { - return PQCodeDistanceScalar::distance_single_code( + return PQCodeDistanceScalar::distance_single_code( M, nbits, sim_table, code); } } @@ -198,7 +202,7 @@ struct PQCodeDistance { result2, result3); } else { - PQCodeDistanceScalar::distance_four_codes( + PQCodeDistanceScalar::distance_four_codes( M, nbits, sim_table, diff --git a/faiss/utils/pq_code_distance.h b/faiss/utils/pq_code_distance.h index a2dd4f901..46604df9b 100644 --- a/faiss/utils/pq_code_distance.h +++ b/faiss/utils/pq_code_distance.h @@ -53,10 +53,14 @@ namespace pq_code_distance { *********************************************************************/ /// Scalar PQ code distance implementation. -/// Templated only on decoder type, independent of SIMD level. /// Used directly by non-PQDecoder8 decoders (PQDecoder16, /// PQDecoderGeneric) and as fallback for PQDecoder8 at NONE/NEON. -template +// SL keeps each SIMD-level TU's instantiation a distinct symbol. Without it +// the linker merges them and may keep one compiled with -mavx512*, which +// then runs on the AVX2 path and raises SIGILL on CPUs without AVX512. +// The default keeps callers outside faiss that name only the decoder (e.g. +// unicorn/features/encoders/PQFSTable.h) compiling; faiss passes SL itself. +template struct PQCodeDistanceScalar { using PQDecoder = PQDecoderT; @@ -160,7 +164,7 @@ struct PQCodeDistance { if constexpr (std::is_same_v) { return pq_code_distance_single_impl(M, nbits, sim_table, code); } else { - return PQCodeDistanceScalar::distance_single_code( + return PQCodeDistanceScalar::distance_single_code( M, nbits, sim_table, code); } } @@ -191,7 +195,7 @@ struct PQCodeDistance { result2, result3); } else { - PQCodeDistanceScalar::distance_four_codes( + PQCodeDistanceScalar::distance_four_codes( M, nbits, sim_table,