Repository navigation
Reduce the CPU overhead of launching graphs and kernels - #3362
Merged
Merged
Conversation
acquire_managed returned a NamedTuple whose old_stream field has the type of the task's operation stream, which is only known at run time. Constructing it went through a generic, allocating path, and release_managed was called on a value of unknown type, adding ~130 ns to every launch that uses managed memory. Return a concretely typed struct instead.
Graphs and kernel launches keep their memory in a Vector{Managed}, whose
abstract element type made every lock, take_ownership! and restamp! call
dispatch dynamically and access fields of an unknown type. Split on the
kind of memory instead, which reduces the cost of launching a graph from
~60 ns to ~16 ns per array it uses.
Sorting the memory of a kernel launch hashed every lock with objectid and loaded it from a Managed of unknown type. Every Managed has its own lock, and objects don't move, so the address of the Managed gives a consistent locking order more cheaply.
Every @cuda checks whether the kernel's cubin loads on the device, which queried the device's compute capability through two driver calls. That never changes, so cache it per device.
This was referenced Oct 8, 2026
Closed
Contributor
CUDA.jl BenchmarksDetails
This comment was automatically generated by workflow using github-action-benchmark. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3362 +/- ##
==========================================
- Coverage 87.17% 85.10% -2.07%
==========================================
Files 195 194 -1
Lines 20066 19983 -83
==========================================
- Hits 17492 17007 -485
- Misses 2574 2976 +402 ☔ 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.
Launching an executable graph cost 55–70 ns of CPU time for every array the graph uses (reported in #3326 (comment)), and kernel launches paid part of the same overhead. Most of it wasn't the ownership protocol itself:
Vector{Managed}. Because of its abstract element type, everylock,take_ownership!andrestamp!call dispatched dynamically. These loops now split on the kind of memory.acquire_managed(Reduce the host code compiled for every new kernel #3359) returned a NamedTuple whose type was only known at run time. That cost an allocation and ~130 ns on every launch. It now returns a concrete struct.objectid. Locks are now ordered by the address of theirManaged.@cudaqueried the device's compute capability (two driver calls) to check whether the cubin loads.capability(dev)is now cached per device.CPU time on an RTX 5080 (Julia 1.13), compared with main:
exec(), 10 arrays (rawcuGraphLaunch1.2 µs)exec(), 1000 arrays (raw 1.8 µs)exec(), 3000 arrays (raw 3.6 µs)@cudawith 4 array argumentsWhat remains is mostly the uncontended lock of each memory (~15 ns per array), which has to be held until the operation is submitted.