Template Struct PeakBatchedModel

Nested Relationships

Nested Types

Struct Documentation

template<typename IdxToSz>
struct PeakBatchedModel

Multi-mode batched peak-memory single-term cost model (DensePeakSizeBatched objective).

Implements the per-batchable-index all-co-resident pebble-game DP, factored into the CostModel hooks driven by run_single_term_opt. Follows the batch-aware cost model design (section 6.2, model A): each DP cell is indexed by both a subset n and a sliced-set context B over the batchable indices, so a model State is the [B]-vector of per-context BatchedRes. No CSE; persistence-gated batching.

Template Parameters:

IdxToSz – A callable mapping an Index to its extent.

Public Types

using State = container::vector<container::vector<BFrontPoint>>

Per-subset DP cell: a [B]-vector (size nB = 2^m) of Pareto frontiers, one non-dominated (peak, flops) set per sliced-set context B.

Public Functions

template<typename TIdxs>
inline Context build_context(TensorNetwork const &network, TIdxs const &tidxs) const
inline State leaf(Context const &ctx, size_t n) const
inline State init(Context const &ctx, size_t) const
inline void relax(Context &ctx, size_t n, size_t lp, size_t rp, State const &lp_st, State const &rp_st, State &acc) const
inline void finalize(Context&, size_t, container::vector<State>&) const
inline EvalSequence reconstruct(Context const &ctx, container::vector<State> const &st) const

Public Members

IdxToSz idxsz
std::function<bool(Index const&)> is_batchable
std::function<std::size_t(Index const&)> batch
std::function<bool(Tensor const&)> is_volatile_leaf
std::function<double(Index const&, std::size_t)> inner_pow = {}

Optional k-aware inner (CSV/PNO composite) extent; see footprint_counter.

double volatile_weight = 1.0

Replay weight applied to volatile contractions in the flop tie-break.

double machine_balance = 0.0

Roofline parameters for the secondary (tie-break) cost; see RooflineParams and roofline_op_cost. machine_balance == 0 (default) => pure-flop tie-break (no behavior change). Uses full (unsliced) operand+result footprints (total per-replay traffic; slicing reduces peak, not total work).

double fast_mem_elems = 0.0
double block_tiles = 3.0
double block_prefactor = 1.0
bool batch_persistent_only = false

If true, batch only persistent subtrees (decline any subset containing a volatile leaf). Default false = batch across the board. See BatchPolicy::persistent_only.

double peak_flops_tolerance = 0.0

Relative peak tolerance for the final (root) selection; see PeakModel::peak_flops_tolerance. 0 (default) = strict peak-min.

double accumulation_factor = 0.0

In-flight batch-contribution footprint multiplier; see BatchPolicy::accumulation_factor. Charged only on nodes that contract a batchable index (Ap != 0), into the all-co-resident peak term, to price the accumulator + contribution co-residency of K += contribution.

bool prune_outer_products = true

Prune disconnected (outer-product) subsets from the DP (see OptimizeOptions::prune_outer_products). Default true.

struct BFrontPoint

One non-dominated (peak, flops) trade-off for a (subset, sliced-set B) cell. aprime is the sliced-set chosen at this node; the children are read at context C = B | aprime, at frontier indices lp_idx / rp_idx. See PeakModel::FrontPoint for why a frontier (not a single peak-min cell) is needed.

Public Members

double peak = std::numeric_limits<double>::max()
double flops = std::numeric_limits<double>::max()
size_t lp = 0
size_t rp = 0
bool lp_first = true
std::size_t aprime = 0
int lp_idx = -1
int rp_idx = -1
struct Context

Precomputed tables and per-(subset, sliced-set) lookup parameters built once by build_context.

Public Functions

inline double fast_flops(std::size_t lp, std::size_t rp) const

Flop count of the binary contraction (subset lp) x (subset rp), equivalent to flops_of(idx[lp], idx[rp], idx[n]) with n = lp|rp, but reading precomputed atom-ID lists instead of rebuilding index sets per call. (idx[n] is a subset of idx[lp] U idx[rp], so it adds nothing.)

inline double sz(std::size_t s, std::size_t ctx) const

Context-restricted size of subset s under sliced-set ctx (the table is indexed by the part of ctx actually open in s; mirrors the oracle).

inline double Lof(std::size_t s, std::size_t ctx) const

Per-context leaf-sum of subset s (sum of singleton sizes under ctx).

Public Members

container::vector<Index> aux

Ordered, deduplicated batchable indices (bit k maps to aux[k]).

std::size_t m = 0

Number of batchable indices (= aux.size()).

std::size_t nB = 1

Number of sliced-sets (= 2^m).

std::size_t nt = 0

Number of tensors in the network.

container::vector<container::vector<double>> tables

tables[B][n] = footprint of subset n under sliced-set B.

container::vector<std::size_t> open_aux

open_aux[n] = bitmask of batchable indices open in subset n.

std::size_t volatile_mask = 0

Bitmask of volatile leaf tensors.

container::vector<IndexSet> idx

idx[n] = subset n’s open (result) indices, for the flop tie-break.

std::function<double(IndexSet const&, IndexSet const&, IndexSet const&)> flops_of

flops_of(lhs, rhs, result) = flop count of one binary contraction. Retained as the reference for the fast_flops parity test; the relax hot loop uses fast_flops (see below).

bool use_fast_flops = true
container::vector<container::svector<std::uint32_t>> f_outer
container::vector<container::svector<std::uint32_t>> f_inner
container::vector<double> fo_ext
container::vector<double> fi_ext
container::vector<Index> fi_index
container::vector<std::uint32_t> fi_grp
bool f_inner_engaged = false
std::function<double(Index const&, std::size_t)> f_inner_pow
mutable container::vector<std::uint32_t> f_grpcount
mutable container::svector<std::uint32_t> f_union_in