Skip to content

test(dispatch): check the dispatch surface declaration with cmake fixtures - #491

Open
ahuber21 wants to merge 5 commits into
mainfrom
dev/isa-dispatching-cmake
Open

ahuber21 wants to merge 5 commits into
mainfrom
dev/isa-dispatching-cmake

Conversation

@ahuber21

@ahuber21 ahuber21 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #395. Adds configure-time tests for the dispatch surface declaration, split out of #372.

It adds a bunch of cmake files that define valid- and invalid- tests. valid = no failure expected, should compile. invalid = cmake configure failure expected. A shell script pulls the files in one by one and reports if all produced the expected result. A CI job was added that executes this script.

Also removes one hard-coded dimensions list in include/svs/core/distance/distance_core.h that wasn't refactored in the previous PR.

…tures

Bring in the configure-time fixtures, checker script, pre-commit hook and
workflow from PR 372, adapted to main's validator. Main has no VNNI level and
no mandatory-level rule, so that fixture is dropped and the VNNI lines are
replaced with legal levels. The multi-arch probe tests stay for a later PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ahuber21
ahuber21 marked this pull request as ready for review November 26, 2026 13:48
@ahuber21
ahuber21 requested a balanced review from Copilot November 26, 2026 13:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The override job lacks assertions that would catch the runtime dimension table disagreeing with the reduced surface, rejecting 32/384 while accepting removed extents such as 160.

1 open issue
What changed in this PR

Adds dispatch-surface validation tests following #395, bringing fixture-based checks from #372 into the CMake test setup.

Changes:

  • Adds valid declarations and invalid fixtures with expected diagnostics.
  • Adds a shell runner and pre-commit hook for declaration validation.
  • Adds CI checks for default configuration and reduced-surface builds and tests.
File Description
tests/​cmake/​dispatch-surface/​valid-reduced.cmake Defines a surface with non-default dimensions.
tests/​cmake/​dispatch-surface/​valid-minimal.cmake Defines a single-fixed-dimension surface.
tests/​cmake/​dispatch-surface/​invalid-zero-extent.cmake Checks rejection of zero dimensions.
tests/​cmake/​dispatch-surface/​invalid-unknown-level.cmake Checks rejection of unknown ISA levels.
tests/​cmake/​dispatch-surface/​invalid-non-numeric-extent.cmake Checks rejection of nonnumeric dimensions.
tests/​cmake/​dispatch-surface/​invalid-no-levels.cmake Checks rejection of an empty ISA list.
tests/​cmake/​dispatch-surface/​invalid-no-extents.cmake Checks rejection of an empty dimension list.
tests/​cmake/​dispatch-surface/​invalid-missing-extents.cmake Checks rejection of an unset dimension list.
tests/​cmake/​dispatch-surface/​invalid-level-without-tu.cmake Checks rejection of missing kernel translation units.
tests/​cmake/​dispatch-surface/​invalid-level-none.cmake Checks rejection of the NONE sentinel.
tests/​cmake/​dispatch-surface/​invalid-level-missing-field.cmake Checks rejection of incomplete ISA entries.
tests/​cmake/​dispatch-surface/​invalid-level-empty-field.cmake Checks rejection of empty architecture fields.
tests/​cmake/​dispatch-surface/​invalid-dynamic-listed.cmake Checks rejection of explicitly listed Dynamic dimensions.
tests/​cmake/​dispatch-surface/​invalid-duplicate-level.cmake Checks rejection of duplicate ISA levels.
tests/​cmake/​dispatch-surface/​invalid-duplicate-infix.cmake Checks rejection of duplicate translation-unit infixes.
tests/​cmake/​dispatch-surface/​invalid-duplicate-extent.cmake Checks rejection of duplicate dimensions.
tests/​cmake/​dispatch-surface/​invalid-duplicate-arch.cmake Checks rejection of shared architecture targets.
.pre-commit-config.yaml Runs validation on relevant file changes.
.github/​workflows/​dispatch-surface.yml Adds declaration and reduced-surface CI jobs.
.github/​scripts/​check_dispatch_surface.sh Checks fixture outcomes and expected diagnostics.

Review effort: Balanced

Comment thread .github/workflows/dispatch-surface.yml Outdated
-DCMAKE_BUILD_TYPE=Release \
-DSVS_BUILD_TESTS=YES \
-DSVS_BUILD_BINARIES=NO \
-DSVS_DISPATCH_SURFACE_FILE="${GITHUB_WORKSPACE}/tests/cmake/dispatch-surface/valid-reduced.cmake"
ahuber21 and others added 4 commits December 2, 2026 07:52
…d probe the override

distance_core.h hardcoded supported_dim_list, so is_dim_supported<N>() ignored
an overridden surface. Build it from SVS_FOR_EACH_SUPPORTED_DIM instead.

Replace the non-default-surface CI job with a compile-only probe that
static_asserts on the reduced surface, drop the redundant default configure
step and the pre-commit hook, and align valid-minimal.cmake with the default
ISA levels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he probe

distance_core.h includes dispatch_surface.h on every host, but only x86
generated and installed it. Install the committed default when nothing is
generated, and warn when an override is ignored on a non-x86 host.

The probe now also includes the distance headers, so their extern template
declarations expand over the reduced surface, and asserts the dispatch-target
count and ISA-level macros. Run it with:
  cmake -S tests/cmake/dispatch-surface-probe -B build-probe
  cmake --build build-probe --target dispatch_surface_probe
Passing -DSVS_DISPATCH_SURFACE_FILE=<repo>/cmake/dispatch-surface.cmake makes it
fail against the default surface. Comments are corrected and shortened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compare the resolved SVS_DISPATCH_SURFACE_FILE with the default path
so that a relative or symlinked spelling of the default does not warn.

Install the committed dispatch_surface.h from the else() of the x86
processor check, so the condition that decides generation also decides
the fallback.

Drop the ISA-level #error from the probe: both surfaces declare the
same levels, so it could not detect an ignored override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idator

The validator and generator parsed `enum class AVX_AVAILABILITY` from
distance_core.h with a regex, which rejects legal C++ such as explicit
values (`AMX = 4`) or comments. Remove that parsing, the "Unknown ISA
level" check and its fixture. A wrong level name now fails when the first
per-level translation unit compiles: the extern template blocks expand
each row through SVS_TYPE_PAIRS_<LEVEL> and AVX_AVAILABILITY::<LEVEL>.
The how-to for adding a level now lists the enumerator step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@ethanglaser ethanglaser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread CMakeLists.txt
endif()
endif()
# distance_core.h includes dispatch_surface.h on every host, but only x86 generates it.
install(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up for innersource: now that distance_core.h includes dispatch_surface.h on every host, innersource needs the same fallback. Its CMakeLists.txt only calls the generator on x86 (include("cmake/multi-arch.cmake") has no else()), and since intel-innersource/libraries.ai.vector-search.svs#399 its install of ScalableVectorSearch/include/svs excludes dispatch_surface.h. So an innersource install on a non-x86 host would ship a distance_core.h that includes a missing file.

No innersource workflow builds non-x86 today, so nothing breaks now. But it's the same gap #399 fixed for x86, so it'd be good to mirror this else() install there when the submodule is bumped past this PR.

@@ -236,31 +236,6 @@ function(svs_generate_dispatch_surface out_tu_specs out_header)
message(STATUS " level: ${entry}")
endforeach()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping the regex makes sense, but this also removes the only signal for a surface that leaves out AVX2 or AVX512. When AVX512 is missing, the compute() entry points still dispatch to AVX_AVAILABILITY::AVX512, so every consumer instantiates those kernels at its own -march. I checked on #395: at the default -march that kernel has no zmm instructions, so AVX512 hosts silently run SSE code.

The levels the dispatcher needs don't have to be parsed from anywhere. They're the hard-coded branches in euclidean.h / inner_product.h / cosine.h. Would something like this work?

# The compute() entry points dispatch to these levels by name; see euclidean.h.
foreach(dispatched_level AVX2 AVX512)
    if(NOT dispatched_level IN_LIST levels)
        message(WARNING
            "${dispatched_level} is dispatched to but not in the surface: consumers compile "
            "its kernels at their own -march."
        )
    endif()
endforeach()

STATUS instead of WARNING is fine too if leaving a level out is an expected configuration.

This branch has not been deployed

No deployments
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.

3 participants