Skip to content

AVX512, default Bulk SIMD for Faiss Scala Quantized Index.#3186

Open
0ctopus13prime wants to merge 2 commits intoopensearch-project:feature/faiss-bbqfrom
0ctopus13prime:faiss-avx512-default-bulk-simd
Open

AVX512, default Bulk SIMD for Faiss Scala Quantized Index.#3186
0ctopus13prime wants to merge 2 commits intoopensearch-project:feature/faiss-bbqfrom
0ctopus13prime:faiss-avx512-default-bulk-simd

Conversation

@0ctopus13prime
Copy link
Collaborator

Description

  1. Fix: Undefined behavior in int4BitDotProduct scalar fallback
    The int4BitDotProduct function in both avx512_simd_similarity_function.cpp and arm_neon_simd_similarity_function.cpp used reinterpret_cast<const uint64_t*> on pointers that may not be 8-byte aligned when binaryCodeBytes % 8 != 0. This is undefined behavior per the C++ standard.

Replaced the casts with std::memcpy into local uint64_t variables. Compilers optimize this into a single mov — zero runtime cost, no UB.

  1. Feature: BBQ similarity support for the default (non-SIMD) fallback
    The default similarity function (default_simd_similarity_function.cpp) only supported FP16. BBQ queries on platforms without AVX512 or NEON would fail with "Invalid native similarity function type".

Added the full BBQ scoring pipeline to the default implementation:

readDataCorrections — safe unaligned reads via std::memcpy
int4BitDotProduct — scalar weighted popcount dot product (with the alignment fix)
default4bitDotProductBatch<BATCH_SIZE> — batched version, pure C++, no SIMD intrinsics
DefaultBBQSimilarityFunction — full scoring struct with batch-8/batch-4/scalar-tail pattern
Wired up BBQ_IP and BBQ_L2 in selectSimilarityFunction

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • [O] New functionality includes testing.
  • [O] New functionality has been documented.
  • [O] API changes companion pull request created.
  • [O] Commits are signed per the DCO using --signoff.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
Signed-off-by: Dooyong Kim <kdooyong@amazon.com>
@0ctopus13prime 0ctopus13prime force-pushed the faiss-avx512-default-bulk-simd branch from ad5507a to 2bc815c Compare March 19, 2026 02:02
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.

1 participant