`@cuda` only accepted keyword arguments written out as `key=value`, so
a launch configuration or compiler options held in a `NamedTuple`, such
as the configurations of an autotuner, had to be spelled out one by
one. Splatting it, as in `@cuda blocks=n config... kernel(a)`, threw
an "Invalid keyword argument" error, because the macro routes keyword
arguments to the launch or the compiler by name when it is expanded,
and the names in a splat are only known at run time.
Port the macro to GPUToolbox's `parse_launch_macro`, and route the
keyword arguments of host-side launches at run time instead: they are
evaluated together into one `NamedTuple`, so that they are evaluated
in the order they are written and repeated names resolve as in a
function call, and partitioned with `partition_kwargs`. For a
`NamedTuple` this folds away at compile time, so launches are as fast
as before and don't allocate. As a consequence, launch keyword
arguments with `launch=false` are now reported when the launch
executes rather than when the macro is expanded. `launch`, `dynamic`
and `backend` must still be written out, once, and device-side
launches (`dynamic=true`) don't accept splats.
This also passes the launch flag as a `Val` instance rather than a call
to `Val`, which resolved in the caller's scope.
@cudaonly accepts keyword arguments that are written out, so a configuration held in aNamedTuplehas to be spelled out one by one. Splatting it throws:cuTile.jl needs this for autotuning, where a configuration is a
NamedTupleof compiler hints.The macro routed keyword arguments to compilation or launch by name at expansion time, but a splat's names are only known at run time. It now uses GPUToolbox's
parse_launch_macro(JuliaGPU/GPUToolbox.jl#48), and routes the keyword arguments of host launches at run time: they are evaluated into oneNamedTuple, in the order written and with the rightmost occurrence of a name winning, and partitioned withpartition_kwargsinto launch keywords and compiler keywords (backend-specific ones included). For aNamedTuplethe partition folds away at compile time. On an RTX 5080 a launch with written-out keywords took 1.44 µs before and after, and one with splatted keywords 1.45–1.47 µs, all without allocating.launch,dynamicandbackendstill have to be written out, once; splatting them throws. Device-side launches (dynamic=true) don't accept splats.This also changes a few things for calls without a splat:
launch=falsetogether with a launch keyword is reported when the call executes instead of at macro expansion;launch,dynamicorbackendtwice is an error, where the last one used to win;Valin the caller's scope.Requires GPUToolbox 3.8.