Repository navigation
Precompile what the worker calls along with cooperative_wait - #49
Merged
Merged
Conversation
A worker thread performs a wait by calling `perform!` dynamically, so a package image that contains a caller's `cooperative_wait` doesn't contain the `perform!` specialization it needs, which is then compiled the first time a wait is handed to a worker (about 10 ms in CUDA.jl). To avoid that, packages had to precompile `perform!` for GPUToolbox's internal request types themselves. While generating output, perform the request on the calling thread instead of calling `wait` directly. That gives `cooperative_wait` a static call to the same `perform!` specialization, which is compiled and cached along with it.
maleadt
force-pushed
the
tb/precompile-perform
branch
from
December 2, 2026 14:43
2c0c9ac to
7aef0d5
Compare
maleadt
added a commit
to JuliaGPU/CUDA.jl
that referenced
this pull request
Dec 3, 2026
GPUToolbox 3.8 caches what a wait worker calls along with `cooperative_wait` (JuliaGPU/GPUToolbox.jl#49), so CUDACore no longer has to precompile `perform!` for GPUToolbox's internal request types, which depended on their names, parameters and the inferred result type.
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.
Worker threads call
perform!dynamically, so a package image that contains a caller'scooperative_waitdoesn't contain the matchingperform!specialization. It's compiled on the first wait handed to a worker: 8.5–9.7 ms in CUDA.jl, which works around it by precompilingGPUToolbox.perform!forWaitRequest{typeof(worker_synchronize), Tuple{CuStream, CuContext}, CUresult}by name (JuliaGPU/CUDA.jl#3659). That statement names internals and copies the result type GPUToolbox infers, so it breaks or silently goes stale when either changes.While generating output,
cooperative_waitnow performs a request on the calling thread instead of callingwaitdirectly. That gives it a static call to the sameperform!specialization, which is then cached along with it. Nothing changes at run time outside precompilation.A new test precompiles a package that calls
cooperative_wait, and checks with--trace-compilethat the first wait on a worker compiles nothing from GPUToolbox. On CUDA.jl main with itsperform!statements removed, theperform!entry disappears from the trace of the first synchronizing launch, and nothing else changes. After this is released, CUDA.jl can require 3.7.1 and drop those statements.