Skip to content

tests: gate cooperative-matrix tests on device feature support - #12734

Open
jvepsalainen-nv wants to merge 1 commit into
shader-slang:masterfrom
jvepsalainen-nv:fix/gate-cooperative-matrix-tests
Open

tests: gate cooperative-matrix tests on device feature support#12734
jvepsalainen-nv wants to merge 1 commit into
shader-slang:masterfrom
jvepsalainen-nv:fix/gate-cooperative-matrix-tests

Conversation

@jvepsalainen-nv

Copy link
Copy Markdown
Contributor

1. Motivation

Running the neural test directory on a machine whose Vulkan device does not implement
cooperative matrices does not skip those tests — it kills the test process.

$ build/Release/bin/slang-test tests/neural/basic-coopmat-vector-tiled-layout-test.slang
passed test: 'tests/neural/basic-coopmat-vector-tiled-layout-test.slang (vk)'
Segmentation fault (core dumped)     # exit 139

The subtest reports passed, and the process then dies. Reproduced 20/20 on Mesa lavapipe
(Mesa 25.2.8 / LLVM 20.1.2), Ubuntu 24.04, Release, clang-18.

This is not one stray test. Running the whole directory:

$ build/Release/bin/slang-test tests/neural/
... 4 tests reported ...
Segmentation fault      # after ~2.7s; the remaining ~56 tests never run

Because the crash takes down the slang-test process itself, everything scheduled after it is
lost. Sweeping every test in the directory individually, 19 of 60 exit non-zero (SIGSEGV 139 or
SIGABRT 134). tests/cooperative-matrix/ behaves the same way.

The device is not at fault, and neither is the driver. Querying it directly:

device: llvmpipe (LLVM 20.1.2, 256 bits)
  VK_KHR_cooperative_matrix advertised: no
  features.cooperativeMatrix = 0

Lavapipe correctly reports that it does not support cooperative matrices. Slang submits a
cooperative-matrix shader to it anyway; the driver cannot lower the intrinsics (it prints
Unsupported intrinsic: @cmat_muladd, a string that lives in libvulkan_lvp.so), emits broken JIT
code, and a worker thread later jumps into it. The faulting PC sits in an anonymous r-xp mapping
with no backing file and frame #1 is 0x0 — a jump into freed JIT memory.

The tests never declared that they need the feature. That is the bug.

2. Proposed solution

Declare the requirement, using the mechanism the repository already has for exactly this.

-render-feature <name> makes render-test check IDevice::hasFeature() and return
SLANG_E_NOT_AVAILABLE when it is missing, which slang-test reports as ignored. It is already
used 301 times across the suite — including for cooperative-vector (118 uses) and, in
tests/cooperative-matrix/ itself, for several cooperative-matrix sub-features. The
cooperative-matrix tests are simply the ones that omitted it.

This PR adds -render-feature cooperative-matrix to the Vulkan execution lines of every test whose
emitted SPIR-V actually contains cooperative-matrix instructions.

Membership was determined by compiling each candidate to SPIR-V with the flags from its own vk
TEST line and checking for OpTypeCooperativeMatrixKHR / OpCooperativeMatrix*, rather than by
grepping the source or by taking the list of tests that happened to crash. That distinction matters:
only 6 files in tests/neural/ mention a cooperative-matrix identifier at all (the rest reach it
through import slang.neural), and the crashing set (19) is smaller than the set that actually
uses the feature (26). Tests like mma-tiled-backward-test.slang use cooperative matrices and did
not crash in a given run — gating only the crashers would have left a latent failure behind.

3. Change summary

Area What changed
tests/neural/*.slang 26 files — added -render-feature cooperative-matrix to vk execution lines
tests/cooperative-matrix/*.slang 35 files — same
Total 61 files, 127 TEST lines

Only lines that (a) are execution tests (COMPARE_COMPUTE* / COMPARE_RENDER* / EXECUTABLE),
(b) target -vk, and (c) did not already declare a cooperative-matrix feature were touched.
-cuda, -dx12 and -mtl lines are deliberately left alone — see the process report.

4. Concepts and vocabulary

  • -render-feature <name> — a render-test option (accepted also as -render-features, taking a
    comma-separated list) that names an rhi::Feature the test requires. Unmet ⇒ render-test returns
    SLANG_E_NOT_AVAILABLE ⇒ slang-test marks the test ignored, not failed.
  • ignored vs failed — an ignored test is silently fine; a failed one breaks the build. A test
    that crashes the process is worse than either, because it also destroys the results of every test
    that would have run after it.
  • lavapipe / llvmpipe — Mesa's software Vulkan rasterizer. It JITs shaders into anonymous
    executable memory, which is why a mis-lowered shader shows up as a PC in an unnamed r-xp region.

5. Process report

Why the gate is the right layer, and not a driver work-around or an expected-failure entry.
The input shape here is a Vulkan device that reports cooperativeMatrix = 0. That shape is
correct and principled — it is a device honestly reporting a capability it lacks, and it is the
shape any non-cooperative-matrix device presents. The defect is on the consumer side: the test
declared no requirement, so the harness had nothing to check and submitted the shader regardless.
Fixing this in an expected-failure list would be wrong twice over: it would encode "this test
crashes" as acceptable, and expected-failure lists mark test outcomes, whereas a SIGSEGV takes
out the process and the rest of the run with it. Fixing it in the driver is not available to us and
would not be right anyway.

Why not gate at the module or compiler level. One could imagine slang.neural declaring a
capability so compilation fails early. That is a separate design question and would not remove the
need for this change: compilation succeeding says nothing about whether the device this test is
about to run on
implements the extension. The runtime feature check is the only thing that can
answer that, and -render-feature is how this repository asks it.

Why the SPIR-V-derived list rather than the crash list. Described in §2. The crash set is
timing-dependent — basic-coopmat-vector-test.slang passes at the default lavapipe thread count and
segfaults at LP_NUM_THREADS=28. A list derived from observed crashes would therefore be unstable
between runs and machines. Emitted SPIR-V is a property of the test, not of the run.

Why -vk lines only. The failure is demonstrated on Vulkan, and rhi::Feature::CooperativeMatrix
is reported by the Vulkan backend from cooperativeMatrix1Features.cooperativeMatrix. Whether the
CUDA and D3D12 backends report the same feature for the paths those TEST lines exercise was not
verified here, and adding the gate to a line whose backend does not report the feature would
silently disable a test that currently works — the exact failure mode PR 2 is about. Restricting to
-vk keeps this change to what is evidenced.

No coverage is lost. The gate is a runtime check: on a device that reports
cooperative-matrix, hasFeature() returns true and the test runs exactly as before. Only devices
that already could not execute these shaders are affected, and there the outcome changes from
"crash the run" to "ignored".

6. Verification

All on Mesa lavapipe 25.2.8, Ubuntu 24.04 / glibc 2.39, Release, clang-18.

before after
basic-coopmat-vector-tiled-layout-test.slang 20/20 SIGSEGV 10/10 clean
slang-test tests/neural/ SIGSEGV after ~4 tests exit 0 — 100% passed (37/37), 264 ignored
slang-test tests/cooperative-matrix/ SIGSEGV exit 0 — 100% passed (13/13), 193 ignored

⚠️ Not verified on cooperative-matrix-capable hardware. No such device was available. The
claim that these tests still run there rests on the gate being a hasFeature() check that returns
true on such a device. CI on NVIDIA hardware is the check for that, and is the one thing a reviewer
should confirm before merging.

Formatting: ./extras/formatting.sh could not run here (clang-format, prettier, shfmt not
installed). The change is confined to //TEST comment lines in .slang files, which none of those
formatters rewrite.

Tests in tests/neural/ and tests/cooperative-matrix/ that emit cooperative
matrix SPIR-V ran their Vulkan variants unconditionally, without declaring
-render-feature cooperative-matrix. On a device that reports no cooperative
matrix support the shader is still submitted, and the driver faults while
executing it: on Mesa lavapipe this kills the slang-test process with SIGSEGV
or SIGABRT after the subtest has already reported success, so the remainder of
the directory never runs.

Add -render-feature cooperative-matrix to the Vulkan execution lines of every
test whose emitted SPIR-V contains cooperative matrix instructions, matching
the gating convention already used elsewhere in tests/cooperative-matrix/.
Devices that report the feature are unaffected and still run these tests.
@jvepsalainen-nv
jvepsalainen-nv requested a review from a team as a code owner August 25, 2026 13:06
@jvepsalainen-nv
jvepsalainen-nv requested review from bmillsNV and removed request for a team August 25, 2026 13:06
@jvepsalainen-nv jvepsalainen-nv added the pr: non-breaking PRs without breaking changes label Aug 25, 2026
@jhelferty-nv
jhelferty-nv removed the request for review from bmillsNV August 25, 2026 13:06
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Vulkan test directives across the cooperative-matrix and neural suites now pass -render-feature cooperative-matrix. CUDA, Metal, shader logic, and expected outputs remain unchanged.

Cooperative matrix Vulkan tests

Layer / File(s) Summary
Enable cooperative-matrix support
tests/cooperative-matrix/*
The Vulkan test configurations now enable the cooperative-matrix render feature, including their existing variant, precision, and buffer options.

Neural Vulkan tests

Layer / File(s) Summary
Enable cooperative-matrix support
tests/neural/*
Neural Vulkan test variants now include the cooperative-matrix render feature across warp, precision, bias, layout, pointer, and size configurations.

Suggested reviewers: bmillsnv, kaizhangnv

Merge Risk: ⚪ Minimal · up to 7473c

The change makes unsupported cooperative-matrix Vulkan tests skip instead of crashing the test process. The remaining issue is limited to line-length formatting in ten test directives and has no runtime or product impact, so no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding device feature gating for cooperative-matrix tests.
Description check ✅ Passed The description directly explains the crash issue, the runtime feature-gating solution, the affected tests, scope, and verification results.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (61 skipped: 61 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b8934676-50ed-48d6-9279-289e929a9181

📥 Commits

Reviewing files that changed from the base of the PR and between eb20c14 and 7473c7c.

📒 Files selected for processing (61)
  • tests/cooperative-matrix/add.slang
  • tests/cooperative-matrix/array.slang
  • tests/cooperative-matrix/bfloat16-arith.slang
  • tests/cooperative-matrix/bfloat16-comparison.slang
  • tests/cooperative-matrix/bfloat16.slang
  • tests/cooperative-matrix/coherent-load-store-pointer.slang
  • tests/cooperative-matrix/comparison.slang
  • tests/cooperative-matrix/conversion-1.slang
  • tests/cooperative-matrix/conversion.slang
  • tests/cooperative-matrix/copyFrom.slang
  • tests/cooperative-matrix/div.slang
  • tests/cooperative-matrix/fill.slang
  • tests/cooperative-matrix/fp8.slang
  • tests/cooperative-matrix/inout.slang
  • tests/cooperative-matrix/length.slang
  • tests/cooperative-matrix/load-store-arbitrary-array-vec.slang
  • tests/cooperative-matrix/load-store-arbitrary-array.slang
  • tests/cooperative-matrix/load-store-groupshared.slang
  • tests/cooperative-matrix/load-store-pointer.slang
  • tests/cooperative-matrix/load-store-rwbyteaddressbuffer.slang
  • tests/cooperative-matrix/load-store-rwstructuredbuffer.slang
  • tests/cooperative-matrix/load-store.slang
  • tests/cooperative-matrix/mat-mul-add.slang
  • tests/cooperative-matrix/mod.slang
  • tests/cooperative-matrix/mod1.slang
  • tests/cooperative-matrix/mul.slang
  • tests/cooperative-matrix/out.slang
  • tests/cooperative-matrix/parameter.slang
  • tests/cooperative-matrix/return.slang
  • tests/cooperative-matrix/scalar-mul.slang
  • tests/cooperative-matrix/struct.slang
  • tests/cooperative-matrix/sub.slang
  • tests/cooperative-matrix/subscript-in-func.slang
  • tests/cooperative-matrix/subscript.slang
  • tests/cooperative-matrix/unary_neg.slang
  • tests/neural/basic-coopmat-vector-test.slang
  • tests/neural/basic-coopmat-vector-tiled-layout-test.slang
  • tests/neural/bias-sum-reduce.slang
  • tests/neural/fflayer-wavetangled-vector-test.slang
  • tests/neural/fflayer-wavetangled-vector-tiled-test.slang
  • tests/neural/mma-helper-test-multi-warps-arbitrary-size.slang
  • tests/neural/mma-helper-test-multi-warps.slang
  • tests/neural/mma-helper-test-single-warp-arbitrary-size.slang
  • tests/neural/mma-helper-test-single-warp.slang
  • tests/neural/mma-helper-test-transpose-multi-warps-arbitrary-size.slang
  • tests/neural/mma-helper-test-transpose-multi-warps.slang
  • tests/neural/mma-helper-test-transpose-single-warp-arbitrary-size.slang
  • tests/neural/mma-helper-test-transpose-single-warp.slang
  • tests/neural/mma-tiled-backward-test.slang
  • tests/neural/mma-tiled-layout-test-multi-warps-arbitrary-size.slang
  • tests/neural/mma-tiled-layout-test-multi-warps.slang
  • tests/neural/mma-tiled-layout-test-single-warp-arbitrary-size.slang
  • tests/neural/mma-tiled-layout-test-single-warp.slang
  • tests/neural/mma-tiled-layout-test-transpose-multi-warps-arbitrary-size.slang
  • tests/neural/mma-tiled-layout-test-transpose-multi-warps.slang
  • tests/neural/mma-tiled-layout-test-transpose-single-warp-arbitrary-size.slang
  • tests/neural/mma-tiled-layout-test-transpose-single-warp.slang
  • tests/neural/outerproduct-accumulate-test-arbitrary-size.slang
  • tests/neural/outerproduct-accumulate-test.slang
  • tests/neural/outerproduct-accumulate-tiled-test-arbitrary-size.slang
  • tests/neural/outerproduct-accumulate-tiled-test.slang

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment on lines +1 to +2
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -render-feature cooperative-matrix
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -Xslang -DBAB -render-feature cooperative-matrix

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Keep the added Vulkan directives within 100 columns.

The same added option makes the changed //TEST directives exceed the Slang line-length limit.

  • tests/cooperative-matrix/mod1.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/mul.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/out.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/parameter.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/return.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/scalar-mul.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/struct.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/sub.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/subscript-in-func.slang#L1-L2: wrap the two Vulkan directives.
  • tests/cooperative-matrix/subscript.slang#L1-L2: wrap the two Vulkan directives.

As per coding guidelines, follow a 100-column line limit in Slang files.

📍 Affects 10 files
  • tests/cooperative-matrix/mod1.slang#L1-L2 (this comment)
  • tests/cooperative-matrix/mul.slang#L1-L2
  • tests/cooperative-matrix/out.slang#L1-L2
  • tests/cooperative-matrix/parameter.slang#L1-L2
  • tests/cooperative-matrix/return.slang#L1-L2
  • tests/cooperative-matrix/scalar-mul.slang#L1-L2
  • tests/cooperative-matrix/struct.slang#L1-L2
  • tests/cooperative-matrix/sub.slang#L1-L2
  • tests/cooperative-matrix/subscript-in-func.slang#L1-L2
  • tests/cooperative-matrix/subscript.slang#L1-L2

Source: Coding guidelines

@github-actions github-actions Bot 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.

Verdict: 🟡 Has issues — 2 gap(s)

Test-only PR that appends -render-feature cooperative-matrix to the Vulkan (-vk) execution lines of tests/cooperative-matrix/*.slang and tests/neural/*.slang, so devices lacking VK_KHR_cooperative_matrix skip these tests (reported ignored) instead of segfaulting the whole slang-test process. The gating mechanism is correct: the flag was added only to -vk lines (CUDA/Metal/compile-only -target spirv lines untouched), every -vk line within each changed file was gated, and on capable devices the tests still run (a supported required-feature does not skip). The gaps below are about completeness of the sweep, not the mechanism.

Changes Overview

Cooperative-matrix test gating (tests/cooperative-matrix/*.slang — 35 files)

  • What changed: each -vk COMPARE_COMPUTE line gained -render-feature cooperative-matrix. Two files (bfloat16-arith.slang, fp8.slang) now carry both -render-features <x> and -render-feature cooperative-matrix on one line.

Neural test gating (tests/neural/*.slang — 25 files)

  • What changed: -vk lines of coopmat-backed tests (*-coopmat-*, *-wavetangled-*, mma-*, outerproduct-accumulate-*) gained -render-feature cooperative-matrix; CUDA/Metal lines left as-is.
Findings (2 total)
Severity Location Finding
🟡 Gap tests/neural/activation-coopmat-vector-test.slang:6 Coopmat WaveTangledVector Vulkan test left un-gated and absent from the PR; still segfaults on non-coopmat devices (commented on the gated sibling fflayer-wavetangled-vector-test.slang:6)
🟡 Gap tests/cooperative-matrix/bfloat16-arith.slang:1 Mixed -render-features/-render-feature spellings on one line (also fp8.slang:1) — functional but inconsistent

reviewed: 7473c7c · diff sha256 d52f6044afd8

// LinearLayout — single-warp:
// TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -xslang -experimental-feature -output-using-type -xslang -DTEST_POINTER=0 -xslang -DWARP_COUNT=1 -xslang -DTEST_TENSORVIEW=0 -emit-spirv-directly
// TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -xslang -experimental-feature -output-using-type -xslang -DTEST_POINTER=1 -xslang -DWARP_COUNT=1 -xslang -DTEST_TENSORVIEW=0 -emit-spirv-directly
// TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -xslang -experimental-feature -output-using-type -xslang -DTEST_POINTER=0 -xslang -DWARP_COUNT=1 -xslang -DTEST_TENSORVIEW=0 -emit-spirv-directly -render-feature cooperative-matrix

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.

🟡 Gap: A sibling cooperative-matrix Vulkan test was missed by the sweep

This file's -vk WaveTangledVector lines are correctly gated here, but its close sibling tests/neural/activation-coopmat-vector-test.slang was left un-gated and is not in this PR. That file's own header documents that it uses the same coopmat-backed type, yet its -vk line still has no -render-feature cooperative-matrix:

// Test activation functions with CooperativeMatrix accelerated WaveTangledVector type.
// ...
// Only run on CUDA and Vulkan (SPIR-V) which support cooperative matrix operations.
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUFFER):-vk -compute -shaderobj -xslang -experimental-feature -output-using-type -emit-spirv-directly

By the PR's own membership criterion (gate every test whose emitted SPIR-V contains cooperative-matrix instructions), this WaveTangledVector-on-Vulkan test qualifies. Leaving it un-gated means it still submits a coopmat shader to a device lacking VK_KHR_cooperative_matrix and segfaults the slang-test process — the exact failure mode this PR exists to prevent, taking down every subsequently-scheduled test.

Suggested fix: Append -render-feature cooperative-matrix to activation-coopmat-vector-test.slang:6 (the -vk line only), matching this file.

While here, it's worth re-running the SPIR-V-membership check over the other untouched neural -vk tests in the same MMA family — the tests/neural/tiled-mma-load-test-*.slang set (testLoadShA/testLoadShB) — and gating any whose SPIR-V contains OpTypeCooperativeMatrixKHR/OpCooperativeMatrix*.

@@ -1,4 +1,4 @@
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -output-using-type -capability spvBFloat16KHR -render-features bfloat16
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -emit-spirv-directly -output-using-type -capability spvBFloat16KHR -render-features bfloat16 -render-feature cooperative-matrix

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.

🟡 Gap (consistency): mixed -render-features / -render-feature on one line

This line now carries both the plural -render-features bfloat16 and the singular -render-feature cooperative-matrix. tools/render-test/options.cpp:154 treats the two spellings as aliases and both split on commas, so this is functionally correct — but mixing them on one directive reads as accidental. tests/cooperative-matrix/fp8.slang:1 has the same pattern (-render-features fp8 -render-feature cooperative-matrix).

Suggestion: collapse into a single plural form — -render-features bfloat16,cooperative-matrix (and -render-features fp8,cooperative-matrix for fp8.slang) — so each line declares its features once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants