Repository navigation
vulkan-shaders-gen: retry an empty shader compile instead of failing at link (potential fix for CI failures) - #540
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) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EkxqpYvUbjCpRDnFiNiVfx
|
@christopherthompson81 Thanks! I’ll keep it open for now until I get some feedback from the nix sub. |
|
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. |
|
Got nothing from nix sub. I'm going to merge this PR. |
|
@christopherthompson81 I don’t know much about CI, so I left the review entirely to Codex. Does that make sense?
|
…atomic Review feedback on 0xShug0#540. Two holes in the previous commit: Judging success by the artefact alone means a compile that fails and leaves an earlier build's .spv in place is credited with that stale file. Reproduced against a fake glslc that exits 0, prints nothing and writes nothing, with a 26-byte stale artefact already present: the generator exited 0 and embedded the stale bytes as the shader. execute_command discarded the exit status at the syscall -- waitpid with a null status, and no GetExitCodeProcess on Win32 -- so no caller could have checked it. It now returns the status, and a non-zero exit or any stderr fails the shader immediately, without retrying; a compiler that reports failure is believed the first time. Only a silent empty result is retried, and out_path is removed before each attempt so no stale file can stand in for a missing one. generation_failed was a plain bool written from the compile threads. It is std::atomic<bool> now, and the catch handler sets it too: an exception there leaves the shader out of shader_fnames, which is the same undefined reference by another route. Verified standalone against fake compilers over add.comp's 16 variants: healthy exits 0 clean; a non-zero exit fails at once naming the code; a transient first-attempt-empty recovers with all 16 definitions emitted; a permanent empty and the stale-file case both stop at generation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3
|
It makes sense — both points were right, and I've pushed a fix for each in ae72096. Exit code. Worse than it looked: The stale-file case wasn't hypothetical. Against a fake Data race. Correct — On the ordering point — "the retry should be added on top of reliable subprocess failure handling" — that's exactly the shape now: exit code first, artefact second, retry only on the silent-empty case. Verified standalone over And yes — llama.cpp master has the exit-code check but not the empty-file retry. I have the retry on a local branch there; I'll send it upstream once this one settles, so the two trees don't drift further. |
…atomic Review feedback on 0xShug0#540. Two holes in the previous commit: Judging success by the artefact alone means a compile that fails and leaves an earlier build's .spv in place is credited with that stale file. Reproduced against a fake glslc that exits 0, prints nothing and writes nothing, with a 26-byte stale artefact already present: the generator exited 0 and embedded the stale bytes as the shader. execute_command discarded the exit status at the syscall -- waitpid with a null status, and no GetExitCodeProcess on Win32 -- so no caller could have checked it. It now returns the status, and a non-zero exit or any stderr fails the shader immediately, without retrying; a compiler that reports failure is believed the first time. Only a silent empty result is retried, and out_path is removed before each attempt so no stale file can stand in for a missing one. generation_failed was a plain bool written from the compile threads. It is std::atomic<bool> now, and the catch handler sets it too: an exception there leaves the shader out of shader_fnames, which is the same undefined reference by another route. Verified standalone against fake compilers over add.comp's 16 variants: healthy exits 0 clean; a non-zero exit fails at once naming the code; a transient first-attempt-empty recovers with all 16 definitions emitted; a permanent empty and the stale-file case both stop at generation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3
Backported from the shape llama.cpp master already has: the failure check belongs before write_output_files(), not after it. A partial header and source carry fresh timestamps, so a second build finds them newer than their inputs, skips regeneration and links the gap instead. The check after write_output_files() stays, because the embed step has its own way to fail -- a shader that compiled but whose artefact is unreadable by the time it is read back. llama.cpp sets its flag there and then returns EXIT_SUCCESS without re-reading it, so that one is detected and dropped upstream; keeping both checks here closes it. execute_command is now byte-identical to llama.cpp master, which should make the next ggml sync of this file a clean one. Verified with ci/run-local.sh linux-vulkan on a real glslc: 1932 shader symbols declared, every one defined, binary links with no undefined generated symbols. Against the fake-compiler matrix, no output file is written on any failure path. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3
ae72096 to
8c11f8b
Compare
|
Two follow-ups — the branch has been force-pushed, so the One more backport from llama.cpp master. The failure check belongs before I kept the check after
Line endings. My first push normalized the whole file CRLF→LF and showed up as a 2496-line diff. On testing CI locally — you mentioned not knowing much about CI, so: I added Running it against this branch: 1932 shader symbols declared, every one defined, binary links with no undefined generated symbols. One unrelated thing it turned up: the "Build and run unit tests" step ends in |
|
Thanks! Merged and let's see how it goes. |
… off under memory pressure (#634) * vulkan-shaders-gen: retry a compiler that cannot be started, and back off under memory pressure #540 made an empty SPIR-V artefact retryable, which turned a link-time undefined reference into a named generation failure. The Nix (vulkan) job now reports the real cause, and it is one that fix does not cover: Error executing command for matmul_id_subgroup_nvfp4_f16_aligned_f16acc_cm1: Failed to fork process Cannot allocate memory `execute_command` throws when fork() fails, and #540 opened its try block OUTSIDE the retry loop -- so a spawn failure skipped every attempt and went straight to the outer catch. An empty artefact was retried; not being able to start the compiler at all, which is the more obviously transient of the two, was fatal on the first occurrence. The generator runs as one ninja target among many, so the C++ compiles of this same build are what exhaust the memory. Two changes: - A spawn failure is an attempt like any other, with backoff that grows (250ms, 500ms, 1s, 2s) rather than the flat 100ms an empty artefact needed: the wait has to be able to outlast a neighbouring translation unit. - Failing to start a process is a statement about the machine, not about one shader, so it now halves the whole generator's concurrency cap. Repeated pressure converges on serial compilation instead of every remaining shader hitting the same wall in turn, which is what the CI log shows happening. Also: both error paths leaked pipe descriptors before throwing, which only mattered once they became retryable -- leaking under EMFILE would turn a transient shortage into the permanent one it was mistaken for. errno now travels in the exception rather than to stderr, and the messages are composed before being written, since compile threads report concurrently and chained << from each interleaves into unreadable lines. Verified with a real glslc and an injected ENOMEM at the fork site: clean run 16/16 SPIR-V and silent; transient recovers with the cap stepping 16->8->4->2->1 and exits 0; permanent still names the shader and exits 1 at generation. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3 * vulkan-shaders-gen: hold no permit while waiting, and retry only a resource shortage Both review points were right, and the first one was not theoretical. 1. The lowered cap did not reach the retries. The compile permit is acquired once per shader in string_to_spv and held for the whole of string_to_spv_func, so it spanned every attempt and every backoff. A reduced cap therefore governed only shaders that had not started yet: the tasks already running -- the ones that had just exhausted the machine -- kept their permits and retried in lockstep into the same wall. The permit is now released before the wait and re-acquired after it, so a task resumes only when the generator is back under its limit. Measured with 40 injected ENOMEMs, probing held-permits against the cap at each launch: without the release: 48 attempts, 26 over cap, worst held=6 vs cap=1 -> generation FAILED, 8/16 shaders with the release: 56 attempts, 2 over cap, worst held=4 vs cap=1 -> generation succeeded, 16/16 Reproducible 3/3 each way. The two remaining over-cap attempts are a benign race: the cap can fall between a permit being granted and the attempt starting. The permit was valid when taken, so this costs one in-flight compile, not a pile-up. 2. Every launch failure was treated as memory pressure. "Cannot start the compiler" covered both a shortage that clears on its own and a missing or malformed compiler that never will, and the second was retried five times with four concurrency halvings before failing. On Windows a missing glslc lands exactly there, because CreateProcess reports it to the caller rather than to a child that has already forked; on POSIX execvp fails in the child and arrives as an exit code, so only pipe() and fork() throw. Launch failures now raise spawn_resource_error only for ENOMEM, EAGAIN, EMFILE and ENFILE -- or their Win32 equivalents -- and the retry catches that type alone. Anything else reaches the outer handler and fails at once. Verified by injecting EACCES: 0 retries, 0 concurrency reductions, exit 1 naming the shader, against ENOMEM in the same harness recovering with 12 retries and 4 reductions. Clean run against a real glslc is unchanged: 16/16 SPIR-V, no stderr, exit 0.
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