tests: cover the AVX2/AVX-512 dot-product kernels - #39
Merged
Merged
Conversation
Signed-off-by: Zirui Song <zrsong@amazon.com>
zirui-song-18
requested review from
chishui,
model-collapse and
yuye-aws
as code owners
August 28, 2026 04:54
chishui
approved these changes
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.