Skip to content

tests: cover the AVX2/AVX-512 dot-product kernels - #39

Merged
chishui merged 1 commit into
opensearch-project:mainfrom
zirui-song-18:simd-kernel-tests
Aug 28, 2026
Merged

chishui merged 1 commit into
opensearch-project:mainfrom
zirui-song-18:simd-kernel-tests

Conversation

@zirui-song-18

Copy link
Copy Markdown
Collaborator

Description

The dot-product kernels are chosen at compile time in nsparse/utils/distance_simd.h (#if AVX2 / AVX512F / …), and the -m flags live only on the per-ISA library targets. nsparse_test links the base nsparse (no flags), so distance_test.cpp only ever exercises the scalar distance.h — the AVX2/AVX-512 kernels that ship in production (selected at load time by the Python bindings) had no test coverage.

This adds a per-ISA equivalence test: distance_kernel_equivalence_test.cpp is compiled once per ISA with that ISA's -m flags (so distance_simd.h resolves to the SIMD kernel) and checks dot_product_{float,uint16,uint8}_dense against a plain reference across every SIMD tail length plus a max-value overflow case — float within tolerance, integer exact. A static_assert fails the build if a -m flag is missing, so it can't silently fall back to scalar.

Because the whole binary is compiled for the ISA, a static initializer can execute that ISA before main, so it must not even be launched on a CPU lacking the ISA (that would SIGILL). ctest runs each binary through run_if_isa_supported.cmake, which checks the host CPU first and skips otherwise.

Issues Resolved

List any issues this PR will resolve, e.g. Closes [...].

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: Zirui Song <zrsong@amazon.com>
@chishui
chishui merged commit c0dfcfa into opensearch-project:main Aug 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants