cuda.tile.static_eval#
- cuda.tile.static_eval(expr, /)#
Evaluates the given Python expression at compile time.
The expression is evaluated using standard Python semantics, not Tile semantics. It can reference global variables and local variables from the surrounding tile function.
If a referenced variable is a compile-time constant value, it will be represented with a corresponding Python object of that value. For example, a constant integer 3 will be passed as a plain
intobject of value 3.If a referenced variable has dynamic value, such as a tile or an array, it will be passed as a proxy object that allows querying compile-time attributes. For example, if
xis a tile, one can usex.shapeto obtain the tile shape as a tuple of integers.The expression is allowed to return a proxy object for a dynamic value. This can be used to select one of multiple dynamic values based on a compile-time condition. For example, if
Nis an integer constant andx,yare dynamic tiles, then one can writex_or_y = ct.static_eval(x if N % 2 == 0 else y)to select eitherxoryat compile tile, depending on the parity ofN.However, the expression is not allowed to perform any run-time operations. For example, if
xrefers to a dynamic tile, thenct.static_eval(x + 1)will raise an error.The expression must not assign to local variables (e.g., via the walrus operator
:=).Despite being declared as a function, static_eval() is treated like a keyword: it skips the translation of the surrounded expression according to the Tile semantics. Moreover, the expression is allowed to use the full Python syntax, unlike the rest of the Tile code, which is limited to a stricter subset of the language.