Summary
Add a module_options dict parameter to @wp.kernel that allows passing module-level compilation options inline at decoration time. This provides a more ergonomic way to set per-kernel module options without needing to call wp.set_module_options() separately or create named modules.
Motivation
Currently, setting module-level compilation options (like fast_math, fuse_fp, etc.) requires either:
- Calling
wp.set_module_options() which affects the entire module, or
- Creating a named module and configuring it separately
With module_options, users can set these options directly on the kernel decorator when combined with module="unique" to isolate the kernel in its own module:
@wp.kernel(module_options={"fast_math": True}, module="unique")
def my_fast_kernel(a: wp.array(dtype=float), b: wp.array(dtype=float)):
tid = wp.tid()
b[tid] = a[tid] + 1.0
Design
module_options accepts only module-level compilation options (the keys defined in Module.options, e.g. fast_math, mode, max_unroll, enable_backward, etc.).
- Requires
module="unique" — raises ValueError if module_options is provided without it.
- Validates keys against the module's known options and raises
ValueError for unrecognized keys, catching typos early.
- Kernel-level options (
enable_backward, launch_bounds) remain separate explicit keyword arguments on @wp.kernel.
Summary
Add a
module_optionsdict parameter to@wp.kernelthat allows passing module-level compilation options inline at decoration time. This provides a more ergonomic way to set per-kernel module options without needing to callwp.set_module_options()separately or create named modules.Motivation
Currently, setting module-level compilation options (like
fast_math,fuse_fp, etc.) requires either:wp.set_module_options()which affects the entire module, orWith
module_options, users can set these options directly on the kernel decorator when combined withmodule="unique"to isolate the kernel in its own module:Design
module_optionsaccepts only module-level compilation options (the keys defined inModule.options, e.g.fast_math,mode,max_unroll,enable_backward, etc.).module="unique"— raisesValueErrorifmodule_optionsis provided without it.ValueErrorfor unrecognized keys, catching typos early.enable_backward,launch_bounds) remain separate explicit keyword arguments on@wp.kernel.