Function sequant::eval::detail::apply_persistence_frontier

Function Documentation

inline void sequant::eval::detail::apply_persistence_frontier(CellTable &table, std::function<bool(std::size_t)> const &volatile_of)

Demotes every persistence candidate (set_residency_flags: no volatile leaf, bound to no enclosing loop) that is not on the frontier of the invariant region, so that

persistent == carries no volatile leaf and is bound to no enclosing loop instance and (some consumer of it holds a volatile value or it has no consumer at all &#8212; a forest root; validator rule 4 admits a zero-consumer cell only at the root scope).

The consumers of a cell are the consumer cells of every Read whose source is it, plus every Assemble whose production.source is it &#8212; the same edge set the runtime’s cache-halt closure walks, by source cell and not by value, so the two cannot disagree about what reads a form.

Why the frontier and not the whole invariant region: a persistent cell is held across evaluations and skipped by cache-halt on every later one. A non-volatile cell all of whose consumers are non-volatile is therefore never read again &#8212; each such consumer is itself either persistent-and-held (skipped by cache-halt rule 1) or demoted here and, by induction from the roots, skipped by rule 2 because all of its consumers are skipped. Keeping such a cell resident across evaluations buys nothing and costs its bytes in the persistent value store for the life of the cache handle. Only the cells feeding volatile work &#8212; and the forest’s own results &#8212; have a reader on a later evaluation.

Leaves follow the same rule: an input tensor whose every consumer is non-volatile is re-fetched on the (rare) evaluation that actually needs it rather than held forever.