Repository navigation
Make all Level Zero calls GC-safe - #704
Merged
Merged
Conversation
maleadt
force-pushed
the
tb/gcsafe-ccall
branch
from
October 17, 2026 18:58
a50840d to
1bfbe1c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #704 +/- ##
==========================================
- Coverage 84.04% 83.48% -0.56%
==========================================
Files 52 51 -1
Lines 4387 4263 -124
==========================================
- Hits 3687 3559 -128
- Misses 700 704 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The generated wrappers used a plain `@ccall`, keeping the calling thread GC-unsafe while in the driver. Calls that block for a long time, such as `zeModuleCreate` compiling a kernel or `wait` on a fence or event, then stall every other thread that needs a collection until they return. Like CUDA.jl, have the generator emit every Level Zero call as `@gcsafe_ccall`, which is cheap enough for the non-blocking ones too. The hand-written GC-safe synchronization calls now use the generated wrappers. libze.jl was updated in place rather than regenerated, to avoid picking up newer headers. Fixes #698
maleadt
force-pushed
the
tb/gcsafe-ccall
branch
from
October 18, 2026 13:08
1bfbe1c to
c8c290f
Compare
maleadt
added a commit
that referenced
this pull request
Oct 19, 2026
The check was advisory, but clashed with the generated wrappers (formatted with JuliaFormatter by res/wrap.jl): touching them made it suggest diffs so large that posting the comment failed, as on #704. It also required running a pull_request_target workflow on checked-out fork code.
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.
The generated Level Zero wrappers used a plain
@ccall, so a thread blocked in the driver kept every other thread that needed a collection waiting. That hurts forzeModuleCreate(the IGC compile on a cold driver cache) and forwaiton fences and events, which block for as long as the GPU work takes.Like CUDA.jl, the generator now emits every Level Zero call as GPUToolbox's
@gcsafe_ccall, enabled per library withgcsafe = truein the TOML (onlyze.tomlfor now). The overhead is negligible: around 0–5 ns per call on 1.10 and 1.12. The hand-written GC-safe synchronization calls now go through the generated wrappers.libze.jlwas updated in place rather than regenerated, because regenerating would pull in newer headers. Apart from the macro, its AST is unchanged, and each rewritten function matches the generator's output for the 1.13 headers.The new test blocks a worker thread in
wait(event, timeout)while the main thread collects. Before this changeGC.gc()stalled until the timeout (9.7 s) and the test failed; now it takes ~0.3 s (checked on 1.10 and 1.12).Fixes #698