Skip to content

Add module_options dict parameter to @wp.kernel decorator #1250

@shi-eric

Description

@shi-eric

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:

  1. Calling wp.set_module_options() which affects the entire module, or
  2. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions