[cuda.compute]: Serialize hostjit builds and improve tests#9998
Open
NaderAlAwar wants to merge 1 commit into
Open
[cuda.compute]: Serialize hostjit builds and improve tests#9998NaderAlAwar wants to merge 1 commit into
NaderAlAwar wants to merge 1 commit into
Conversation
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughChangesThe change serializes CUDACompiler’s native compilation and linking operations with a process-wide mutex and increases concurrency in the Numba build-storm thread-safety test. Native Compile Safety
Suggested reviewers: Comment |
Jacobfaib
approved these changes
Jul 17, 2026
| // clang concurrently and corrupt that shared state. Serialize every native | ||
| // compile/link through one process-wide mutex. This guards only the (cached, | ||
| // one-time) build path; kernel launches are unaffected. | ||
| static std::mutex g_native_compile_mutex; |
Contributor
There was a problem hiding this comment.
Suggested change
| static std::mutex g_native_compile_mutex; | |
| namespace { | |
| std::mutex g_native_compile_mutex; | |
| } // namespace |
Prefer anon namespaces to static
This comment has been minimized.
This comment has been minimized.
Contributor
🥳 CI Workflow Results🟩 Finished in 3h 08m: Pass: 100%/61 | Total: 20h 26m | Max: 1h 02m | Hits: 99%/5269See results here. |
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.
This fixes the issue seen here https://github.com/NVIDIA/cccl/actions/runs/29535459932/job/87894484801?pr=9985.
Root cause
The v2 (HostJIT) backend compiles each op by embedding clang/LLVM in-process, which is not thread-safe for concurrent compilation (shared global registries, cl::opt state, allocator use). Since cuda.compute releases the GIL around native builds, building distinct ops from multiple threads runs clang concurrently and corrupts shared state — surfacing as a SIGSEGV/SIGBUS/SIGABRT heap-corruption crash. This is not FT-specific; it reproduces on a stock GIL interpreter too. (v1/NVRTC is unaffected — NVRTC is thread-safe.)
Fix
Serialize native compilation with a process-wide mutex around the three public compiler entry points (compileToObject / compileToDeviceBitcode / linkToSharedLibrary) in c/parallel.v2/src/hostjit/compiler.cpp. Only one clang invocation runs at a time. This guards the (cached, one-time) build path only — kernel launches are unaffected.
Test
The crash was already covered by test_concurrent_distinct_python_ops_build_storm, but at THREADS = 4 it almost never fired — it only surfaced in CI under xdist load. Bumped the build-storm test to a dedicated 24 threads so it reliably trips the race if the lock regresses, and raised the shared THREADS for the file's other thread-safety tests from 4 → 8 (all use tiny inputs, so no GPU-memory concern).