vulkan-shaders-gen: retry an empty shader compile instead of failing at link (potential fix for CI failures) - #540
Draft
christopherthompson81 wants to merge 1 commit into
Conversation
… not defined
A shader whose compile produces no SPIR-V becomes an undefined reference
at link, twenty minutes later, naming a symbol in vendored code with
nothing earlier in the log to explain it:
ld.bfd: ggml-vulkan.cpp:3964: undefined reference to
`matmul_id_subgroup_nvfp4_f32_aligned_f16acc_cm1_len'
write_output_files() emits the declaration before reading the artefact,
then skips the definition if the file is empty, silently. The symbol is
left declared and never defined.
Compile success was also judged by stderr alone, with no exit code, so a
shader that merely warns is discarded while one that reports nothing and
writes nothing is accepted. Success is now judged by the artefact: the
SPIR-V must exist and be non-empty.
An empty result is retried up to three times with short backoff before
giving up. This has been seen in CI with no accompanying diagnostic and
does not reproduce locally, so it appears environmental and rare;
retrying costs milliseconds on a genuinely broken shader and saves a
build that would otherwise fail at link for no visible reason. After the
last attempt the shader is named and generation fails.
Verified both ways against an injected failure. A transient -- first
attempt empty, later attempts normal -- recovers and the build links.
A permanent one reports:
shader matmul_id_subgroup_nvfp4_f32_aligned_f16acc_cm1 produced no SPIR-V; retrying (2/3)
shader matmul_id_subgroup_nvfp4_f32_aligned_f16acc_cm1 produced no SPIR-V; retrying (3/3)
cannot compile matmul_id_subgroup_nvfp4_f32_aligned_f16acc_cm1 after 3 attempts
shader generation failed; see errors above
and stops at generation instead of at link.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EkxqpYvUbjCpRDnFiNiVfx
Owner
|
@christopherthompson81 Thanks! I’ll keep it open for now until I get some feedback from the nix sub. |
Contributor
Author
|
Moving this to draft so it isn't sitting in your review queue while you wait on feedback from the nix sub — no pressure either way, just ping me and I'll mark it ready again. |
christopherthompson81
marked this pull request as draft
September 15, 2026 00:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A shader whose compile produces no SPIR-V becomes an undefined reference at link, ~20 minutes into the build, naming a symbol in vendored code with nothing earlier in the log to explain it. The Nix (vulkan) job on #539 failed this way:
write_output_files()writes the declaration before it reads the artefact, then skips the definition if the file is empty, with no diagnostic:Compile success was judged by stderr alone, with no exit code, so a shader that merely warns is discarded while one that reports nothing and writes nothing is accepted.
Fix
Success is judged by the artefact — the SPIR-V must exist and be non-empty. An empty result is retried up to three times with short backoff; after the last attempt the shader is named and generation fails. Diagnostics alongside a usable artefact are treated as warnings and the shader is kept.
Why retry rather than just fail
The trigger does not reproduce locally. Investigating the #539 failure I built shaderc 2026.1 — the version this repo's Nix build uses, per the job log — and compiled the exact failing shader with the exact 17 defines: exit 0, no stderr, 27,700 bytes of valid SPIR-V. 120 repeat compiles under parallel load produced no anomalies. A full Vulkan build with that compiler and all four shader extensions enabled links cleanly: 2320 symbols declared, 2320 defined.
So the shader is fine and the compiler is fine; something environmental produced an empty file while reporting success. Retrying absorbs that. Failing loudly covers the case where it is not transient.
Verification
Against an injected failure, both directions:
Note on upstream
The same declaration-before-definition path exists in ggml-org/llama.cpp master. Upstream does already check the exit code from
execute_command, which this tree's copy does not — worth a look when these files are next synced.🤖 Generated with Claude Code
https://claude.ai/code/session_01EkxqpYvUbjCpRDnFiNiVfx