Skip to content

test(dispatch): Add a link probe that checks the dispatch surface - #374

Closed
ahuber21 wants to merge 2 commits into
dispatch/03-validate-surfacefrom
dispatch/04-link-probe
Closed

test(dispatch): Add a link probe that checks the dispatch surface#374
ahuber21 wants to merge 2 commits into
dispatch/03-validate-surfacefrom
dispatch/04-link-probe

Conversation

@ahuber21

Copy link
Copy Markdown
Contributor

A kernel missing its extern template does not produce an error. The consumer
instantiates it locally instead, from the generic primary template, at its own
-march -- which is how L2 at d=160 shipped a scalar loop while a vectorized
AVX2 kernel sat unused in the archive. Generating the declarations makes that
mistake harder to write; it does not make it detectable.

tests/multi-arch/x86/link_probe.cpp is a consumer that names every kernel the
surface declares -- every (extent, ISA level), every element-type pair, all three
distances -- and nothing else. It is compiled at -march=x86-64, guaranteeing
nothing about the host, and three things are required of it:

  • It must link. A declared-but-never-instantiated kernel is an undefined
    symbol here and nowhere else, because nothing else references the whole surface
    at once.
  • It must define no kernel of its own. cmake/check-dispatch-linkage.cmake
    compares the mangled svs::distance::*Impl symbols the probe object defines,
    the ones it references, and the ones the archive defines. All three set
    differences must be empty. Counts of mangled names, because GCC clones
    instantiations as local .isra symbols.
  • It must run. Every kernel whose ISA level the host satisfies is called, so
    a kernel compiled beyond what its level guarantees faults here rather than in
    the field.

Two ctest tests, 0.4 s. On the default surface: 918 kernels declared,
instantiated and reachable, 0 instantiated by the consumer, the two mangled-name
sets identical. All three failure modes were provoked and each fires with the
right message.

What this checks is reachability, not output identity: a specialization that
vanishes because an #if guard turned off still links and still matches on
count. That blind spot is the reason for PR 5.

Part 4 of 5 of the ISA dispatching v2 milestone.

@ahuber21 ahuber21 added this to the ISA dispatching v2 milestone Aug 24, 2026
@ahuber21 ahuber21 changed the title Add a link probe that checks the dispatch surface test(dispatch): Add a link probe that checks the dispatch surface Aug 24, 2026
ahuber21 and others added 2 commits August 23, 2026 23:55
The declaration added in the preceding commit is only worth something if it
is checked rather than trusted, and if the knob that overrides it is
actually turned by something other than a person debugging.

Move the validation out of `generate-dispatch-surface.cmake` into
`validate-dispatch-surface.cmake`, which touches no build-system state and
so runs in script mode:

    cmake -DSVS_DISPATCH_SURFACE_FILE=<file> -DSVS_X86_SRC_DIR=<dir> \
          -P cmake/validate-dispatch-surface.cmake

`tests/cmake/dispatch-surface/` holds two declarations that must be accepted
and eleven that must be rejected, each carrying the substring its rejection
has to mention. `.github/scripts/check_dispatch_surface.sh` runs the lot --
plus the default declaration -- in 0.2s, needing nothing but cmake. It is a
pre-commit hook and a CI job.

Script mode has no `cmake_minimum_required`, so CMP0007 and CMP0057 default
to OLD there. Both matter: without CMP0007 an empty `|`-field disappears
when the entry is split, and without CMP0057 `IN_LIST` is not an operator.
Set both, scoped with cmake_policy PUSH/POP.

The new `Dispatch Surface` workflow adds what the script cannot check:

  - a configure with the default declaration must leave the committed
    `dispatch_surface.h` untouched. This catches a declaration changed
    without a reconfigure, and a generated header edited by hand.
  - a full build and test run against `valid-reduced.cmake`, which shares no
    extent with the default declaration -- so a build that quietly fell back
    to the committed header would fail to compile rather than pass by
    accident. That build's archive holds 288 kernels at extents 32, 384 and
    svs::Dynamic, against 864 at the default nine.
  - that same overridden build must leave the committed header alone.

Correctness does not depend on which extents have a fixed-extent kernel: an
extent without one is served by the svs::Dynamic kernel. `ctest -LE long`
against the reduced surface passes 153 of 154, the one failure being
`Testing Binary Reader Iterator`, which fails identically on the unmodified
default-surface build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A kernel that is missing its `extern template` declaration does not
produce an error. The consumer instantiates it locally instead, from the
generic primary template -- and in a baseline consumer translation unit
the vectorized partial specializations are not even visible, since they
are guarded on SVS_AVX2 / SVS_AVX512_F. So the consumer silently gets a
scalar loop where the library has a vectorized kernel, compiled at
whatever -march the consumer happens to use. That is the bug that shipped
for L2 at d=160 with AVX2.

Nothing could catch it, because nothing referenced the whole surface at
once. This adds a consumer that does: tests/multi-arch/x86/link_probe.cpp
names every kernel the surface declares -- every (extent, ISA level) pair,
every element-type pair, all three distances -- and nothing else. It is
compiled at -march=x86-64, like an arbitrary consumer of the headers, and
two tests are run against it:

  dispatch_surface_probe    calls every kernel whose ISA level this host
                            satisfies, so a kernel compiled beyond what
                            its level guarantees faults here
  dispatch_surface_linkage  reads the object's symbol table and requires
                            the kernels it references to be exactly the
                            kernels the library defines

The linkage check is host-independent and covers the whole surface
everywhere; the run covers only what the host can reach.

On the default surface the two sets match exactly at 864 kernels, and on
the reduced surface used by the non-default-surface CI job, at 288. All
three failure modes were confirmed to fire: dropping the L2 extern block
reports 288 kernels instantiated by the probe itself, and checking against
an archive missing the AVX-512 translation unit reports its 432 kernels as
declared but never instantiated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ahuber21
ahuber21 force-pushed the dispatch/03-validate-surface branch from 61c06f9 to 7200927 Compare August 24, 2026 06:57
@ahuber21
ahuber21 force-pushed the dispatch/04-link-probe branch from f2849e6 to bdd2303 Compare August 24, 2026 06:57
@ahuber21
ahuber21 force-pushed the dispatch/03-validate-surface branch from 7200927 to 0a0a6e7 Compare August 24, 2026 09:44
@ahuber21

Copy link
Copy Markdown
Contributor Author

Collapsed into #372: the link probe and the surface checks belong with the generator that produces the surface they check.

@ahuber21 ahuber21 closed this Aug 24, 2026
@ahuber21
ahuber21 deleted the dispatch/04-link-probe branch August 24, 2026 09:44
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