Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/svs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(USE_SVS)
cmake_dependent_option(SVS_SHARED_LIB "Use SVS pre-compiled shared library" ON "USE_SVS AND GLIBC_FOUND AND SVS_LVQ_SUPPORTED" OFF)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: revert this change upon SVS binaries update

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (GLIBC_2_28_FOUND)
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.11/svs-shared-library-0.0.11-reduced-clang.tar.gz" CACHE STRING "SVS URL")
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/svs-shared-library-1.0.0-NIGHTLY-20251211-869-reduced-clang.tar.gz" CACHE STRING "SVS URL")
else()
message(STATUS "GLIBC>=2.28 is required for Clang build - disabling SVS_SHARED_LIB")
set(SVS_SHARED_LIB OFF)
Expand All @@ -59,7 +59,7 @@ if(USE_SVS)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "14.0")
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.11/svs-shared-library-0.0.11-reduced-gcc14.tar.gz" CACHE STRING "SVS URL")
else()
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.11/svs-shared-library-0.0.11-reduced.tar.gz" CACHE STRING "SVS URL")
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v1.0.0-dev/svs-shared-library-1.0.0-NIGHTLY-20251211-869-reduced.tar.gz" CACHE STRING "SVS URL")
endif()
elseif(GLIBC_2_26_FOUND)
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.11/svs-shared-library-0.0.11-reduced-glibc2_26.tar.gz" CACHE STRING "SVS URL")
Expand Down
71 changes: 71 additions & 0 deletions tests/unit/test_svs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,77 @@ TEST(SVSTest, scalar_quantization_query) {
}
}

#ifdef __linux__
TEST(SVSTest, compute_distance) {
// Test svs::distance computation for custom data allocations and alignments
constexpr size_t dim = 4;

// get system pagesize
size_t page_size = sysconf(_SC_PAGESIZE);
ASSERT_GT(page_size, 16);

// Allocate two consecutive pages: one for data, one as a guard (inaccessible)
uint8_t *raw_a = (uint8_t *)mmap(nullptr, 2 * page_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_NE(raw_a, MAP_FAILED);
// Protect the second page to prevent access
ASSERT_EQ(mprotect(raw_a + page_size, page_size, PROT_NONE), 0);

// Allocate the second buffer
uint8_t *raw_b = (uint8_t *)mmap(nullptr, 2 * page_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
ASSERT_NE(raw_b, MAP_FAILED);
// Protect the second page to prevent access
ASSERT_EQ(mprotect(raw_b + page_size, page_size, PROT_NONE), 0);

// use last bytes of page for data
// Note: Accessing above 'dim' should trigger Memory Access Error.
constexpr size_t data_size = dim * sizeof(float);
float *a = reinterpret_cast<float *>(raw_a + page_size - data_size);
float *b = reinterpret_cast<float *>(raw_b + page_size - data_size);

std::iota(a, a + dim, 1.f);
std::iota(b, b + dim, 2.f);

// Verify default implementation
auto dist_l2 = svs::distance::compute(svs::DistanceL2{}, std::span(a, dim), std::span(b, dim));
EXPECT_GT(dist_l2, 0.0);
auto dist_ip = svs::distance::compute(svs::DistanceIP{}, std::span(a, dim), std::span(b, dim));
EXPECT_GT(dist_ip, 0.0);

#ifdef __x86_64__
// Verify AVX2 and AVX512 implementations
if (svs::detail::avx_runtime_flags.is_avx2_supported()) {
// AVX2 implementations
auto dist_l2_avx2 = svs::distance::
L2Impl<svs::Dynamic, float, float, svs::distance::AVX_AVAILABILITY::AVX2>::compute(
a, b, svs::lib::MaybeStatic(dim));
auto dist_ip_avx2 = svs::distance::
IPImpl<svs::Dynamic, float, float, svs::distance::AVX_AVAILABILITY::AVX2>::compute(
a, b, svs::lib::MaybeStatic(dim));
EXPECT_DOUBLE_EQ(dist_l2, dist_l2_avx2);
EXPECT_DOUBLE_EQ(dist_ip, dist_ip_avx2);
}

if (svs::detail::avx_runtime_flags.is_avx512f_supported()) {
// AVX512 implementations
auto dist_l2_avx512 = svs::distance::
L2Impl<svs::Dynamic, float, float, svs::distance::AVX_AVAILABILITY::AVX512>::compute(
a, b, svs::lib::MaybeStatic(dim));
auto dist_ip_avx512 = svs::distance::
IPImpl<svs::Dynamic, float, float, svs::distance::AVX_AVAILABILITY::AVX512>::compute(
a, b, svs::lib::MaybeStatic(dim));
EXPECT_DOUBLE_EQ(dist_l2, dist_l2_avx512);
EXPECT_DOUBLE_EQ(dist_ip, dist_ip_avx512);
}
#endif // __x86_64__

// unmap pages
munmap(raw_a, 2 * page_size);
munmap(raw_b, 2 * page_size);
}
#endif // __linux__

#else // HAVE_SVS

TEST(SVSTest, svs_not_supported) {
Expand Down