Repository navigation
Poll an event capturing the context's work when synchronizing the device - #3396
Merged
Merged
Conversation
Contributor
CUDA.jl BenchmarksDetails
This comment was automatically generated by workflow using github-action-benchmark. |
The resource callbacks run while the driver holds its locks, but disassembling yields (temporary files, running nvdisasm). Any task that calls into the driver meanwhile, like the timer draining retired resources, then blocks on those locks and the process deadlocks. Only copy the cubins in the callback, and disassemble them afterwards.
Since #3315, device_synchronize always handed the synchronization to a worker thread, as a context can't be polled. That made synchronizing an idle device take ~7 µs instead of ~1 µs on CI. With CUDA 12.5, cuCtxRecordEvent records an event that captures all of a context's work, which can be polled like any other event. Synchronize that event instead, so that an idle device is detected without the round trip to a worker. The event blocks when waited for if the context is configured for blocking synchronization, as cuCtxSynchronize would. Blocking synchronization, and older drivers, still use cuCtxSynchronize.
maleadt
force-pushed
the
tb/context-sync-event
branch
from
October 15, 2026 14:15
b9e4601 to
282fa89
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3396 +/- ##
==========================================
- Coverage 86.56% 85.08% -1.49%
==========================================
Files 192 191 -1
Lines 19497 19236 -261
==========================================
- Hits 16878 16366 -512
- Misses 2619 2870 +251 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Since #3315,
device_synchronize()always hands the synchronization to a worker thread, because a context can't be polled. On the benchmark dashboard,cuda/synchronization/context/autowent from ~1.0 µs to ~6.8 µs as a result. It reached ~7.8 µs after the #3318 stack landed: the worker handoff got ~10% slower, and gpuci1's clocks were locked the same day.CUDA 12.5 added
cuCtxRecordEvent, which records an event capturing all of a context's work (including its green contexts). Unlike the context, that event can be polled. On 12.5+ drivers, nonblockingdevice_synchronizenow goes through the existing event path: poll, and if done, synchronize the event so that kernel output is flushed; otherwise wait on a worker as before. The event getsEVENT_BLOCKING_SYNCwhen the context is configured withCTX_SCHED_BLOCKING_SYNC, so long waits keep following the context's scheduling policy. Blocking synchronization and older drivers still usecuCtxSynchronize.Median times on an RTX 5080 (3 interleaved runs):
context/autocontext/nonblockingcontext/blockingThe printf-flush test now covers
device_synchronizeas well, and the non-blocking-stream gate test also runs withspin=false.