Repository navigation
Add helpers for implementing kernel launch macros - #48
Merged
Merged
Conversation
Back-ends' launch macros (`@cuda`, `@metal`, `@roc`, ...) each parse their arguments the same way, with GPUCompiler's `split_kwargs` and `assign_args!` and code around them, and route keyword arguments to compilation or launch by name at macro expansion time. That rules out splatted keyword arguments (`@cuda config... kernel(a)`), whose names are only known at run time, and some back-ends carry private run-time variants for their reflection functions. Add two functions for this. `parse_launch_macro` parses a launch macro's arguments into the call's function, its arguments bound to variables, the macro's own options, and the other keyword arguments, splats included, in source order. `partition_kwargs` partitions keyword arguments by name at run time, returning `NamedTuple`s. A macro builds one `NamedTuple` from the keyword arguments, which evaluates them in order and resolves repeated names like the keyword arguments of a function call, and routes it with `partition_kwargs`. For constant groups of names, that partition happens at compile time: it is type stable and doesn't allocate, so launches don't get slower for it.
This was referenced Dec 2, 2026
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.
Back-ends' launch macros (
@cuda,@metal,@roc,@oneapi,@opencl, KernelAbstractions' POCL back-end andKI.@launch) each repeat the same parsing around GPUCompiler'ssplit_kwargsandassign_args!, and route keyword arguments to compilation or launch by name when the macro is expanded. That rules out splatting keyword arguments, which an autotuner withNamedTupleconfigurations needs, because a splat's names are only known at run time:Several back-ends also carry private
split_kwargs_runtimecopies for their reflection functions.This adds two functions, public but not exported:
parse_launch_macro(ex; name, options)parses a launch macro's arguments into the called function, its arguments bound to variables (for single evaluation andGC.@preserve), the macro's own literal options such aslaunch, and the other keyword arguments in source order, splats included.partition_kwargs(kwargs, groups...)partitions keyword arguments by name intoNamedTuples.A macro builds one
NamedTuplefrom its keyword arguments, so they are evaluated in order and repeated names resolve as in a function call, and routes it withpartition_kwargs. For constant groups the partition happens at compile time: it is type stable and does not allocate, so launches don't get slower. With@cudaported to these helpers, a launch on an RTX 5080 took 1.44 µs with written-out keywords, as before, and 1.45–1.47 µs with splatted ones.partition_kwargscan also replace the back-ends' run-time copies.Routing at run time means that a literal keyword a back-end rejects is reported when the launch executes instead of at macro expansion, like an unknown keyword argument to a function.
The helpers in GPUCompiler stay as they are, deprecated, until the back-ends have moved over;
@cudais the first, in a CUDA.jl PR that needs this one released. Tested on Julia 1.10–1.13.