Expand description
Fusing chains of elementwise verbs into one blockwise pass.
A chain like +/ w * x runs one pass per verb: the product is written to
memory in full and read back to be reduced. This pass finds maximal
subtrees of elementwise primitives at compile time and replaces them with
Expr::Fused, which evaluates the whole chain a block at a time — the
block stays in cache, so the arrays at the leaves are read once and the
result is written once.
The kernel is a postfix program over a small stack of block buffers. It covers only what it can compute exactly as the unfused pipeline would; everything else — a shape that needs broadcasting, a dtype the chain would narrow, an integer overflow — declines at run time and the original subtree, kept inside the node, evaluates instead. Fusion therefore cannot change a result or an error message.
A chain does not have to be written as one sentence. d =. {x} - m
followed by +/ d * d names a value that nothing needs as an array, and
the pass moves such a value into the sentences that read it — see
inline_once for the rules that keep that sound.
Structs§
- Fused
Kernel - A fused elementwise chain and what is made of its values.
- Summary
- What a compiled kernel is made of.
Enums§
- Decline
- Why a kernel handed its work back to the chain it came from.
- Instr
- One step of a kernel: postfix, so operands are already on the stack.
- Yield
- What one evaluation of a kernel produces.
Constants§
- BLOCK
- Elements a block buffer holds.
Functions§
- decline_
reason - Why this kernel would decline these inputs, or None if it would run.
- fallback_
count - Number of fallbacks since the process started.
- inlined_
names - The names the pass took out of the program: values it moved into the kernels that read them, so no sentence computes them as arrays any more.
- is_
fused - Does any sentence of this program run a fused kernel?
- is_
inlined - Did the pass move a named value into the sentences that read it?
- pass
- Optimise a compiled program’s sentences: move the values that are only named for the reader into the sentences that read them, then fuse every chain that is left.
- summary
- Describe a compiled kernel: what it computes, and with what.
- unfused
- The program as the plain evaluator would run it: the sentences it was compiled from, with every fused node replaced by the subtree it came from. The two must compute the same thing; tests hold them to it.