Skip to content

fix(euclidean): Declare the missing AVX2 extern template for L2 at d=160 - #371

Open
ahuber21 wants to merge 1 commit into
mainfrom
dispatch/01-l2-d160-extern
Open

fix(euclidean): Declare the missing AVX2 extern template for L2 at d=160#371
ahuber21 wants to merge 1 commit into
mainfrom
dispatch/01-l2-d160-extern

Conversation

@ahuber21

Copy link
Copy Markdown
Contributor

The AVX2 extern template list in euclidean.h listed 200 twice and never
listed 160, while avx2.cpp instantiates L2 at 160 like every other extent. A
missing extern template is not an error: every consumer that computed an L2
distance at d=160 instantiated the kernel itself instead, from the generic
primary template, and so got a scalar loop where the library had a vectorized
AVX2 kernel sitting unused in the archive.

One character of a duplicated line, and the reason the rest of this stack
exists: a hand-maintained list of 182 extents cannot be reviewed by reading it.

Part 1 of 5 of the ISA dispatching v2 milestone.

The AVX2 `extern template` list in euclidean.h listed 200 twice and never
listed 160, while avx2.cpp instantiates L2 at 160 like every other extent.
With no declaration in the header, a consumer translation unit implicitly
instantiates `L2Impl<160, ..., AVX2>` itself, at the consumer's own
`-march`. Against the baseline `-march=x86-64` the library is built with,
that local copy is a scalar loop (movss/subss/mulss/addss, 50 bytes) rather
than the 508-byte AVX2 kernel that is sitting unused in
libsvs_x86_objects.a -- so the AVX2 dispatch path silently runs unvectorized
code at d=160, and differs between translation units, which is an ODR
violation.

inner_product.h and cosine.h already list all nine extents correctly; this
brings euclidean.h in line with them and with avx2.cpp. Verified by
compiling a consumer at -march=x86-64: `L2Impl<160, float, float, AVX2>`
goes from a locally defined symbol to an undefined reference resolved from
the archive, matching 128 and 200.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ahuber21 ahuber21 added this to the ISA dispatching v2 milestone Aug 24, 2026
@ahuber21 ahuber21 changed the title Declare the missing AVX2 extern template for L2 at d=160 fix(euclidean): Declare the missing AVX2 extern template for L2 at d=160 Aug 24, 2026
@ahuber21
ahuber21 marked this pull request as ready for review August 24, 2026 11:42
@ahuber21
ahuber21 requested a review from ibhati as a code owner August 24, 2026 11:42
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.

1 participant