Module Sarek_ir_eval_int

Host-side evaluation of uniform int32 expressions (specs/matrix-pattern-rewrite.md).

A launch-time decision (the region a kernel covers, a reduction length) needs the value of IR expressions built from scalar parameters, constants and the launch's block and grid dimensions. Arithmetic is int32 and wraps, as on the device; int64 values are outside its domain.

type launch = {
  1. grid : int * int * int;
  2. block : int * int * int;
  3. scalar : Sarek_ir_types.var -> int32 option;
}

The facts of one launch: dimensions as (x, y, z), and the value of a scalar parameter.

val eval : launch -> Sarek_ir_types.expr -> int32 option

None when the expression is not uniform over the launch (it reads memory, a thread index, a loop variable), contains an operator with no int32 meaning here, or divides by zero. It is also None for anything 64-bit (an int64 constant, variable or cast): the arithmetic is int32, so such a value is refused, never truncated.

val mentions_launch_dims : Sarek_ir_types.expr -> bool

Whether an expression reads block_dim_*, grid_dim_* (or a global_size* / num_groups* intrinsic): such a value changes meaning in a kernel launched with other dimensions.