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 int object 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 x is a tile, one can use x.shape to 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 N is an integer constant and x, y are dynamic tiles, then one can write x_or_y = ct.static_eval(x if N % 2 == 0 else y) to select either x or y at compile tile, depending on the parity of N.

However, the expression is not allowed to perform any run-time operations. For example, if x refers to a dynamic tile, then ct.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.