flowchart TB
Choice{"Choose phase boundaries"} --> Separate
Choice --> Composed
subgraph Separate["Separate phases"]
direction TB
A["Read smoothing input"] --> B["Smooth owned cores"]
B --> C["Store intermediate image"]
C --> D["Read intermediate with derivative halo"]
D --> E["Derivative and output"]
end
subgraph Composed["One composed phase"]
direction TB
F["Read combined upstream footprint"] --> G["Smooth larger intermediate region"]
G --> H["Derivative in local buffers"]
H --> I["Write final owned core"]
end
Fusion and intermediate storage
Fusion is useful when it avoids work or storage between operations. Blockflow provides several forms of sharing, and they have different limits: composing kernels inside a phase, folding branch outputs, reusing specialized transforms, and choosing a ready-task order are separate mechanisms.
Composing operations within one phase
Chain::sequence runs operations in order within one task. An intermediate buffer produced by the first kernel is consumed locally by the next kernel; it is not published as a complete phase image. PlanBuilder::pixels turns that chain into one phase. Splitting the same sequence across two builder calls introduces a stored image between them.
This is task-level composition. It does not automatically compile the kernels into one pixel loop, remove every intermediate array, vectorize arbitrary Rust code or invoke a GPU graph compiler. The computation still calls the operations in the declared order. Temporary buffer lifetimes and source borrowing can reduce allocation, but the kernel boundaries remain meaningful.
Why wider reach can offset the saving
Consider smoothing of radius two followed by a radius-one derivative. To produce final core [10,20), the derivative needs smoothed values on [9,21). Smoothing that interval correctly requires raw input [7,23). The composed task therefore needs a three-voxel raw halo, not the maximum individual radius of two.
With separate phases, the smoothing phase computes each owned smoothed voxel once and stores it. The derivative phase reads neighboring owned smoothed outputs. With composition, neighboring tasks can recompute some smoothed values in their intermediate halos. The stored image disappears, but that repeated arithmetic does not.
Composition is attractive when the intermediate is large, storage or compression is expensive, and the upstream kernel is relatively cheap. Materialisation can win when an expensive intermediate has many consumers or when combined reach makes blocks too large. A shared intermediate used by two later phases should not be recomputed blindly just because a chain API can express each consumer separately.
PlanBuilder::partition lets a strategy price cuts in a chain using the caller’s Constraints. It does not silently discover all reusable subexpressions in a larger application. Inspect the chosen phases and measure traffic rather than assuming that fewer phases always means a smaller or faster working set.
Branches and incremental combination
Chain::parallel represents branches over a common input, combined through Combine. Its name describes the computation graph: every branch is evaluated. It is not a promise that every branch runs on a separate worker at the same time. Chain::alternative represents mutually exclusive branches and runs the selected one; those two shapes must not be confused when deriving cost or reach.
A naive branch evaluation retains all branch outputs until combination. A Combine implementation can instead declare an incremental folding carrier and combine outputs as they become available. That can replace several live full-block outputs with a carrier, the current branch, and any new output buffer required by the fold. An in-place fold can reduce that further. The carrier’s type, accepted operand types and folding behavior must match the operation; associativity, overflow and numerical order still matter.
Chain::source names an already stored image rather than computing another branch. Source operands can borrow fetched buffers where ownership permits; they cannot be overwritten simply because a combine would prefer an in-place accumulator. The same physical buffer may also be needed by another branch or a later phase.
Specialized reuse can go beyond generic composition
TransformBankOp reuses one input Fourier transform for multiple correlations. This shares expensive mathematical work, while a generic sequence or parallel tree by itself only describes how kernels connect. Similar specialized kernels may share intermediate statistics or workspaces when their algorithms justify it. Such sharing should state the unchanged output convention and be checked against independent kernels.
Task priority does not fuse phases
SchedulePriority::BlockMajor favors advancing ready blocks into later phases. SchedulePriority::PhaseMajor, the default, favors finishing a phase across its blocks. Both operate on the same recorded task graph. Neither changes the number of phase images allocated by the environment.
A block-major visit order can even keep more intermediate images live at once: several phases have started before their last readers finish. Locality depends on cache size, halos and the number of consumers; it does not follow from the name of the priority. Use scheduler events and the memory/storage model to compare actual alternatives.