~/bend-docscommunity

src/tensor/parallel_proofs.bend checks

raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/parallel_proofs.bend as Parallel_proofs

7 imports
import Base
import ../shape/nat_proofs.bend as Nats
import ../shape/index_proofs.bend as Index
import ../storage/model.bend as Model
import ../storage/refinement.bend as Refinement
import ../storage/clone.bend as Clone
import ./parallel.bend as Build

Types

type Fact source · line 15 · raw

@-P:Type -> Data

Definitions

def position_step source · line 71 · raw

@+capacity:Nat -> @+offset:Nat -> @+base:Nat -> {Nat.add(offset, Nat.add(capacity, base)) == Nat.add(Nat.add(capacity, offset), base) : Nat}

def half_equal source · line 181 · raw

@-S:Type -> @-start:S -> @-state:S -> @-half:S -> @-split:(@_:S -> Pair(S, S)) -> @-pick:(@_:Pair(S, S) -> S) -> @picked:{half == pick(split(state)) : S} -> @at:{state == start : S} -> @copied:{pick(split(start)) == start : S} -> {half == start : S}

Templates

template CellIs source · line 20 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+count:Nat -> @+position:Nat -> @-observed:Maybe<&2, F32> -> Type

What cell position holds: the F32 its cell function computes from start.

template Cells source · line 26 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @-out:Array<F32> -> Type

Every slot of out, the cells base .. base + 2^depth, holds what CellIs names for its index.

template Keeps source · line 32 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> Type

A cell hands its input state back unchanged.

template TreeFacts source · line 37 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @-result:Pair(Array<F32>, Pair(A, B)) -> Type

A run of the one-thread tree: it hands start back and fills its cells.

template facts_kept source · line 41 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @-result:Pair(Array<F32>, Pair(A, B)) -> @-facts:Fact<TreeFacts(P, A, B, cell, p, start, depth, count, base, result)> -> Fact<{Pair.snd(Array<F32>, Pair(A, B), result) == start : Pair(A, B)}>

template facts_cells source · line 50 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @-result:Pair(Array<F32>, Pair(A, B)) -> @-facts:Fact<TreeFacts(P, A, B, cell, p, start, depth, count, base, result)> -> Fact<Cells(P, A, B, cell, p, start, depth, count, base, Pair.fst(Array<F32>, Pair(A, B), result))>

template leaf_facts source · line 59 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+count:Nat -> @+base:Nat -> @pair:Pair(F32, Pair(A, B)) -> @-exact:{pair == cell(p, base, start, Nat.is_lt(base, count)) : Pair(F32, Pair(A, B))} -> @-keeps:Keeps(P, A, B, cell, p, start) -> Fact<TreeFacts(P, A, B, cell, p, start, 0n, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.leaf(Pair(A, B), pair))>

template node_cell source · line 76 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+inner:Nat -> @+count:Nat -> @+base:Nat -> @-a:Array<F32> -> @-b:Array<F32> -> @+path:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Path(1n+inner) -> @-low:Fact<Cells(P, A, B, cell, p, start, inner, count, base, a)> -> @-high:Fact<Cells(P, A, B, cell, p, start, inner, count, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.upper(inner, base), b)> -> Fact<CellIs(P, A, B, cell, p, start, count, Nat.add(0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.offset(1n+inner, path), base), 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.observe(F32, 1n+inner, ANode{a, b}, path))>

template node_cells source · line 93 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+inner:Nat -> @+count:Nat -> @+base:Nat -> @-a:Array<F32> -> @-b:Array<F32> -> @-low:Fact<Cells(P, A, B, cell, p, start, inner, count, base, a)> -> @-high:Fact<Cells(P, A, B, cell, p, start, inner, count, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.upper(inner, base), b)> -> Fact<Cells(P, A, B, cell, p, start, 1n+inner, count, base, ANode{a, b})>

template join_facts source · line 103 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+inner:Nat -> @+count:Nat -> @+base:Nat -> @-a:Array<F32> -> @high:Pair(Array<F32>, Pair(A, B)) -> @-low:Fact<Cells(P, A, B, cell, p, start, inner, count, base, a)> -> @-facts:Fact<TreeFacts(P, A, B, cell, p, start, inner, count, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.upper(inner, base), high)> -> Fact<TreeFacts(P, A, B, cell, p, start, 1n+inner, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.join(Pair(A, B), a, high))>

template node_facts source · line 117 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+inner:Nat -> @+count:Nat -> @+base:Nat -> @rec:(@_:A -> @_:B -> Pair(Array<F32>, Pair(A, B))) -> @low:Pair(Array<F32>, Pair(A, B)) -> @-facts:Fact<TreeFacts(P, A, B, cell, p, start, inner, count, base, low)> -> @-next:(@l:A -> @r:B -> @-at:{(l, r) == start : Pair(A, B)} -> Fact<TreeFacts(P, A, B, cell, p, start, inner, count, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.upper(inner, base), rec(l, r))>) -> Fact<TreeFacts(P, A, B, cell, p, start, 1n+inner, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.node(A, B, rec, low))>

template pair_join_facts source · line 132 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+count:Nat -> @+base:Nat -> @x:F32 -> @high:Pair(F32, Pair(A, B)) -> @-low:Fact<Cells(P, A, B, cell, p, start, 0n, count, base, [x])> -> @-exact:{high == cell(p, Nat.add(1n, base), start, Nat.is_lt(Nat.add(1n, base), count)) : Pair(F32, Pair(A, B))} -> @-keeps:Keeps(P, A, B, cell, p, start) -> Fact<TreeFacts(P, A, B, cell, p, start, 1n, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.pair_join(Pair(A, B), x, high))>

The depth-1 tree: the leaf of cell base next to the leaf of the cell after it, which reads the state the first hands back.

template pair_facts source · line 142 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+count:Nat -> @+base:Nat -> @low:Pair(F32, Pair(A, B)) -> @-exact:{low == cell(p, base, start, Nat.is_lt(base, count)) : Pair(F32, Pair(A, B))} -> @-keeps:Keeps(P, A, B, cell, p, start) -> Fact<TreeFacts(P, A, B, cell, p, start, 1n, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.pair(P, A, B, cell, p, count, base, low))>

template tree_facts source · line 161 · raw

@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @-start:Pair(A, B) -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> @-at:{state == start : Pair(A, B)} -> @-keeps:Keeps(P, A, B, cell, p, start) -> Fact<TreeFacts(P, A, B, cell, p, start, depth, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.tree(P, A, B, cell, p, depth, count, base, state))>

The one-thread tree hands start back and fills every cell as CellIs says.

template fork_cells source · line 188 · raw

@-Q:Data -> @-P:Data -> @-A:Type -> @-B:Type -> @-prepare:(@+q:Q -> P) -> @-split:(@_:Pair(A, B) -> Pair(Pair(A, B), Pair(A, B))) -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+q:Q -> @-start:Pair(A, B) -> @+inner:Nat -> @+count:Nat -> @+base:Nat -> @-state:Pair(A, B) -> @pair:Pair(Pair(A, B), Pair(A, B)) -> @-exact:{pair == split(state) : Pair(Pair(A, B), Pair(A, B))} -> @-low:(@_:A -> @_:B -> Array<F32>) -> @-high:(@_:A -> @_:B -> Array<F32>) -> @-at:{state == start : Pair(A, B)} -> @-first:{Pair.fst(Pair(A, B), Pair(A, B), split(start)) == start : Pair(A, B)} -> @-second:{Pair.snd(Pair(A, B), Pair(A, B), split(start)) == start : Pair(A, B)} -> @-low_cells:(@l:A -> @r:B -> @-at:{(l, r) == start : Pair(A, B)} -> Fact<Cells(P, A, B, cell, prepare(q), start, inner, count, base, low(l, r))>) -> @-high_cells:(@l:A -> @r:B -> @-at:{(l, r) == start : Pair(A, B)} -> Fact<Cells(P, A, B, cell, prepare(q), start, inner, count, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.upper(inner, base), high(l, r))>) -> Fact<Cells(P, A, B, cell, prepare(q), start, 1n+inner, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.fork(A, B, pair, low, high))>

template build_cells source · line 209 · raw

@-Q:Data -> @-P:Data -> @-A:Type -> @-B:Type -> @-prepare:(@+q:Q -> P) -> @-split:(@_:Pair(A, B) -> Pair(Pair(A, B), Pair(A, B))) -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+q:Q -> @-start:Pair(A, B) -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> @-at:{state == start : Pair(A, B)} -> @-keeps:Keeps(P, A, B, cell, prepare(q), start) -> @-first:{Pair.fst(Pair(A, B), Pair(A, B), split(start)) == start : Pair(A, B)} -> @-second:{Pair.snd(Pair(A, B), Pair(A, B), split(start)) == start : Pair(A, B)} -> Fact<Cells(P, A, B, cell, prepare(q), start, depth, count, base, 0x1689e5deb278c16abd3bd45eac101ef3/src/tensor/parallel.build(Q, P, A, B, prepare, split, cell, q, depth, splits, count, base, state))>

Whatever the split, every cell of the parallel build holds what the one-thread tree computes there from start.