Write the compiled kernel cache atomically to prevent crashes when starting renderers concurrently. - #60
Merged
duburcqa merged 1 commit intoJul 22, 2026
Conversation
…r concurrent renderer startup.
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
Starting several batched renderers concurrently on the same host (e.g.
pytest -n <N>GPU test runs, or multiple training workers) intermittently aborts withSIGABRT(exit 134) insidecuModuleLoadData, once the compiled kernel cache exists on disk. The failure is non-deterministic and disappears when the run is serialized.Root cause
The megakernel and BVH kernel caches are written in place with a plain
std::ofstreamat a shared path ($MADRONA_ROOT_CACHE_DIR/kernel_cache,$HOME/.cache/madronaby default). When one process is part-way through writing the cubin, a second process that finds the cache present (kernelCacheNeedsRecompileonly checks existence +last_write_time) opens it and feeds a truncated, half-written buffer tocuModuleLoadData, which aborts.This was confirmed deterministically: truncating the cache file to a partial cubin reproduces the exact
SIGABRTexit 134.Fix
Write each cache to a per-process temporary file (
<cache_path>.tmp.<pid>) andstd::filesystem::renameit into place. POSIXrenameis atomic, so a reader observes either the previous complete file or the new complete file, never a partial one. Concurrent compilers each write their own temp and the final rename wins with a valid, self-consistent cubin.Applied to both the megakernel cache write and the BVH kernel cache write.
Validation