Skip to content

ScaleInvariantMatrixMatch: give the Default kernel its own context name - #1935

Open
Gin890 wants to merge 1 commit into
mainfrom
fix-matrix-match-default-context
Open

Gin890 wants to merge 1 commit into
mainfrom
fix-matrix-match-default-context

Conversation

@Gin890

@Gin890 Gin890 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

The Default matrix-match kernel used the same struct name as the SSE kernel, Context_x86_SSE41. This can make the Default kernel run SSE code by mistake. This PR renames the Default struct to Context_Default.

What was wrong

Both kernels defined struct Context_x86_SSE41 in the same namespace, but the two structs are different. The Default one works on single floats. The SSE one works on 4-float vectors. C++ allows only one definition per name, so this is undefined behavior.

The shared templates in Kernels_ScaleInvariantMatrixMatch_Routines.h (SumATA2, SumError, compute_scale, compute_error) are built with this struct in both files. So both files make functions with the same symbol names and different code. When the compiler keeps one of them out of line, the linker keeps a single copy for the whole program. The Default kernel can then call the SSE version on its scalar state.

Why we think this causes the Windows CI failures

Windows MSVC CI has failed on several PRs that don't touch the kernels, while main passed. Each time, all Kernels::ScaleInvariantMatrixMatch tests fail for widths where w % 16 is 0 or 1 (16, 17, 32, 64, 128, 256, 257, 512, 513). SSE, AVX2 and AVX512 agree with each other. Only Default differs, even for a 16x1 matrix. That points at the Default kernel computing the wrong thing, which this name clash explains.

This is the likely cause, but it is not proven: there is no local MSVC build to reproduce it. The Windows CI run on this PR is the real check.

The change

  • Rename the Default struct and its 4 uses to Context_Default. The Default kernels of SpikeConvolution and AbsFFT already use that name.
  • I checked the other kernels for the same problem. No other Default kernel defines a type with the same name as an ISA kernel's type in the same namespace. The other repeated names live in different namespaces or anonymous namespaces, or are overloads with different parameter types.

Testing

  • Builds on macOS arm64 (Release, Ninja). The SSE file isn't compiled there, so this build only shows the rename compiles.
  • Windows CI on this PR should show whether the matrix-match failures go away.

🤖 Generated with Claude Code

The Default and SSE matrix-match kernels both defined a struct named
Context_x86_SSE41 in the same namespace. The two structs are different:
the Default one works on single floats, the SSE one on 4-float vectors.
C++ requires one definition per name, so this is undefined behavior.

The shared templates in Kernels_ScaleInvariantMatrixMatch_Routines.h
(SumATA2, SumError, compute_scale, compute_error) are built with this
struct in both files. Both files then make functions with the same
symbol names but different code. When the compiler keeps a function
out of line instead of inlining it, the linker keeps only one copy for
the whole program. The Default kernel can then call the SSE code on
its scalar state.

This matches failures seen on Windows MSVC CI. All
Kernels::ScaleInvariantMatrixMatch tests fail for widths where w % 16
is 0 or 1 (16, 17, 32, 64, ..., 513). SSE, AVX2 and AVX512 agree with
each other, and only Default differs, even for a 16x1 matrix.

Rename the Default struct to Context_Default, the name the Default
kernels of SpikeConvolution and AbsFFT already use. No other kernel
has a Default type that shares its name with an ISA type in the same
namespace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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