Repository navigation
Conversation
Converting an array for a launch took ~550 ns: the index type was only known at run time, so converting the sizes and strides dispatched dynamically, building the `ArraySpec` type from the layout facts (alignment, contiguity, divisibility) cost several times the rest, and calling the resulting type to construct the array cost ~100 ns more. Branch on the index type, compute the layout facts as plain values, and look the `TileArray` type up by those facts in a lock-free memo per element type, rank and index type, as a `Val` to dispatch on rather than a type to call. The memo keeps the 16 most recent layouts, so that a hit stays cheap when many are seen. A conversion now takes ~60 ns and allocates 80 instead of 384 bytes: the result and its arguments, whose type is only known at run time, are boxed. The conversion is now compiled per array type rather than inlined into every kernel's launch code, and precompiled for the common ones, which keeps the first launch from getting slower.
Every launch looked its kernel up from scratch: the method table lookup in `Base.method_instance`, the job, the CodeInstance holding the compiled results, a lock and the scan for the context's function. That took ~1.6 µs on every launch. Put `GPUCompiler.cached_lookup` in front of it, as CUDACore's `cufunction` does, keyed on the context, the options and the world. The world is the latest one, which the lookup uses, so that a redefinition still shows on the next launch from code that is already running; `cached_lookup` also matches the caller's world, which can only cost a miss. To make the cache a constant per signature, `cufunction` now specializes on the function and argument types; the compilation behind it still doesn't. `@cuda` passes the alias grouping as a constant when no arrays overlap, so that its lookup is resolved statically. The cache must not keep the kernel function, whose captured values come from each launch, so a `TileKernel` is rebuilt around the cached function and its options as given. Two lookups of one kernel share their `fun`, which the tests now compare, but no longer necessarily the rest. For the same reason the per-context function cache now holds the `CuFunction` rather than the first `TileKernel`, which kept the values captured by that launch's closure alive. A hit now takes ~0.1 µs. The precompile workload compiles the lookup's miss path, which is shared by every kernel launched without options, so the first launch doesn't get slower. `cached_lookup` requires GPUCompiler 2.18.
maleadt
force-pushed
the
tb/launch-overhead
branch
from
December 3, 2026 13:45
bb523b0 to
9985bdd
Compare
This branch has not been deployed
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.
A cuTile launch cost ~4.6 µs and 2.4 KB of host time for a two-array kernel, and ~9 µs for nine arrays, against ~1.5 µs for a CUDA.jl
@cudalaunch. Short kernels were host-bound, and the autotuner (#389) needs to look up the kernels a launch would use on every call.Two changes:
TileArraytype depends on run-time facts: the index type, and the alignment, contiguity and divisibility that make up itsArraySpec. Building that type and calling it cost ~550 ns per array. The index type now selects one of two type-stable paths, and the type is memoized by the layout facts, as aValto dispatch on rather than a type to call: ~60 ns per array.Base.method_instance, the job, the CodeInstance holding the results, a lock and the per-context scan (~1.6 µs).cufunctionnow putsGPUCompiler.cached_lookupin front of that, as CUDACore's does, keyed on the context, the options and the world: ~0.1 µs on a hit. Kernels are still looked up in the latest world, so a redefinition shows on the next launch even from running code.cufunctionspecializes on the function and argument types for this; the compiler behind it still doesn't.RTX 5080, Julia 1.13, three runs each (
launch=falseis the@cudacall without the launch; conversion iscuTileconvertof every array):@cudalaunch@cuda launch=false@cuda(reference)First launch in a fresh session (warm CUBIN cache, interleaved runs): 0.63–0.66 s → 0.55–0.58 s with two arrays, 0.67–0.74 s → 0.59–0.64 s with nine; a second kernel in the same session is unchanged (60–90 ms). The precompile workload now also compiles the conversion of common array types and the lookup's miss path, which grows the package image from 35.9 to 37.2 MiB; precompilation time is unchanged.
What remains between a cuTile launch and a CUDA.jl one:
@cudapipeline builds itsKernelCalland theNamedTupledescribing the call's sources at run time when the converted arguments' types aren't inferable, which costs ~0.5 µs per launch. With that fixed in CUDACore, a two-array launch takes ~1.9 µs andlaunch=false~0.17 µs.A
TileKernelreturned bycufunctionis rebuilt around the cached function on every call, so two lookups of one kernel are no longer===; theirfunis.TileKernel.optsnow holds the options as given, withsm_arch=nothingmeaning the device's. Requires GPUCompiler 2.18.