tilelang.language.meta¶
Turn Python classes/methods into TIR, in both eager and lazy modes.
Two DSL primitives – inline (method -> inlined TIR) and meta_class
(class of JIT-time stateful helpers) – that behave the same in eager
(@tilelang.jit) and lazy (@T.prim_func) frontends. See each function’s
docstring for the details.
Functions¶
|
Decorator: lower a method body to TIR, inlined at each call site. |
|
Class decorator for JIT-time stateful helpers (e.g. tile schedulers). |
Module Contents¶
- tilelang.language.meta.inline(func)¶
Decorator: lower a method body to TIR, inlined at each call site.
selfis bound automatically. The lowering engine is chosen per call so the same method works in both frontends:eager mode (an eager
Builderis active) -> the eagermacroengine;lazy mode (no eager builder; a TVMScript parser is active) -> TVM’s parser-level
inline(TIRInline).
Both engines are built lazily on first use of the respective mode.
Inside an inlined method, read scalar state via
self.x[0]and write viaself.x[0] = ...; the store lowers toBufferStorethrough whichever engine is active, so no core builder/parser changes are needed.- Parameters:
func (collections.abc.Callable)
- Return type:
_InlineMethod
- tilelang.language.meta.meta_class(cls)¶
Class decorator for JIT-time stateful helpers (e.g. tile schedulers).
Instances exist only during JIT tracing / parsing and hold
T.alloc_varbuffers as state (T.alloc_varemits into the active IR frame in both modes). The decorator has three responsibilities:Mark the class with
_is_meta_class. The lazy parser needs this to bindsched = Sched(...)as a (non-TIR) instance in its scope instead of trying to turn it into a constant.Auto-
inlineevery TIR-emitting method, so methods need no per-method@inline. A method is considered TIR-emitting iff it contains a buffer store, i.e. a subscript-target assignmentself.x[...] = ...(see_emits_store). Left as plain Python:dunders (
__init__allocates state as plain Python),staticmethod/classmethod/property,methods already decorated with
@inline,methods with no buffer store – pure compile-time helpers that only build/return
PrimExprexpressions (e.g.validreturning a loop condition, or acoord(tile_id)decode returning(m, n)). These stay plain so they can return values and be reused statelessly. A method that emits TIR only through control flow / nested calls (no direct store) should be marked explicitly with@inline.
Auto-name state buffers
{prefix}_{attr}in the generated IR, whereprefixis the constructor argument namedprefix(soSched("sched", ...)yieldssched_m_idxetc.). This wraps__init__to captureprefixand installs a__setattr__that names anyBufferassigned to a non-underscore attribute; non-buffers (compile-time ints likenum_n_tiles) and underscore attributes are skipped, and naming is best-effort (never fatal). It runs at construction while an IR builder is active, so it works in both modes.
- Parameters:
cls (_C)
- Return type:
_C