TorchLean API

NN.Tensor.Internal.Elab.Einsum.Output.Planning

Einsum output-block planning #

The output compiler evaluates neighboring row-major entries together so they share contraction-coordinate work and keep a small family of scalar totals live. This module owns the static policy; tiling semantics and concrete register implementations remain independent of it.

Because TorchLean.Tensor.Internal is polymorphic over element representation, the planner measures a logical working set in element reads rather than assuming a byte width. It never changes the order of one output's contraction.

Count tensor element reads in a generated expression.

def TorchLean.Tensor.Internal.Elab.Impl.einsumOutputTileWidth? (outputLength : ) (contractionEntries : Option ) (scalarReadsPerTerm : ) :

Choose the concrete register width for one contiguous output block.

Four lanes amortize coordinate work once a contraction has more than eight terms. Exactly eight terms remain scalar: the register callback setup costs more than the coordinate sharing saves at that boundary. A single four-lane block also remains scalar when every term reads at least three tensors. Eight lanes are used whenever at least eight output positions are available and the per-step live read family remains modest. Unknown contraction lengths use the conservative four-lane implementation. The number of complete blocks and the tail are derived separately and may be arbitrary natural numbers.

Instances For