Computations inside custom tensor operations #
Tensor graphs describe dependencies between operations. A kernel expression describes the calculation of one output element inside an operation. Variables are typed, inputs are read-only, branches are lazy, and folds accumulate in increasing index order. Arithmetic is supplied explicitly; no field laws or floating-point reassociation are assumed.
Indices use unsigned 64-bit arithmetic rather than silently compiling unbounded natural numbers to machine integers. The frontend must reject constants outside that range. Tensor reads return errors instead of inventing a value for an invalid address.
Scalar arithmetic remains a parameter of the semantics.
Instances For
Input access is shared by reference execution and lowered execution.
Instances For
A typed expression with explicitly ordered arithmetic and bounded sequential folds.
The fold body binds the accumulator first and the iteration index second. A count of zero leaves the initial value unchanged. Only the selected conditional branch is evaluated.
- scalar {α : Type} {Γ : List Ty} (value : α) : Expr α Γ Ty.scalar
- index {α : Type} {Γ : List Ty} (value : UInt64) : Expr α Γ Ty.index
- predicate {α : Type} {Γ : List Ty} (value : Bool) : Expr α Γ Ty.predicate
- var {α : Type} {Γ : List Ty} {t : Ty} (v : Var Γ t) : Expr α Γ t
- load {α : Type} {Γ : List Ty} (operand : Nat) (index : Expr α Γ Ty.index) : Expr α Γ Ty.scalar
- binary {α : Type} {Γ : List Ty} (op : ScalarOp) (x y : Expr α Γ Ty.scalar) : Expr α Γ Ty.scalar
- neg {α : Type} {Γ : List Ty} (x : Expr α Γ Ty.scalar) : Expr α Γ Ty.scalar
- indexBinary {α : Type} {Γ : List Ty} (op : IndexOp) (x y : Expr α Γ Ty.index) : Expr α Γ Ty.index
- compare {α : Type} {Γ : List Ty} (op : Compare) (x y : Expr α Γ Ty.scalar) : Expr α Γ Ty.predicate
- indexCompare {α : Type} {Γ : List Ty} (op : Compare) (x y : Expr α Γ Ty.index) : Expr α Γ Ty.predicate
- cond {α : Type} {Γ : List Ty} {t : Ty} (p : Expr α Γ Ty.predicate) (yes no : Expr α Γ t) : Expr α Γ t
- letIn {α : Type} {Γ : List Ty} {s t : Ty} (value : Expr α Γ s) (body : Expr α (s :: Γ) t) : Expr α Γ t
- fold {α : Type} {Γ : List Ty} (count : Expr α Γ Ty.index) (initial : Expr α Γ Ty.scalar) (body : Expr α (Ty.scalar :: Ty.index :: Γ) Ty.scalar) : Expr α Γ Ty.scalar
Instances For
A recursive calculation can use the loop backend when its equations give a scalar recurrence. This includes failing input reads: neither later steps nor the final result mask an earlier error. No laws about the scalar arithmetic, and no reassociation of operations, are assumed.
A type-preserving change of variable addresses.