src/tensor/parallel.bend checks
raw source on the hub · import bendtorch-core@0.1.0.0/src/tensor/parallel.bend as Parallel
2 imports
import Base import ../storage/model.bend as Model
Types
type Certified source · line 89 · raw
@-S:Type -> @-depth:Nat -> @-expected:Pair(Array<F32>, S) -> Type
A run of the one-thread tree next to its proof of balance: result is
the term the code computes, and its first component is balanced at
depth. The proofs only follow the code, so they cost nothing at runtime.
Certified@-S:Type -> @-depth:Nat -> @-expected:Pair(Array<F32>, S) -> @result:Pair(Array<F32>, S) -> @same:{result == expected : Pair(Array<F32>, S)} -> @balanced:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, depth, Pair.fst(Array<F32>, S, result)) -> Certified<S, depth, expected>
Definitions
def upper source · line 32 · raw
@+inner:Nat -> @+base:Nat -> Nat
The first cell of the high half of a node whose halves hold 2^inner cells.
Templates
template leaf source · line 16 · raw
@-S:Type -> @pair:Pair(F32, S) -> Pair(Array<F32>, S)
template join source · line 20 · raw
@-S:Type -> @a:Array<F32> -> @high:Pair(Array<F32>, S) -> Pair(Array<F32>, S)
template node source · line 26 · raw
@-A:Type -> @-B:Type -> @rec:(@_:A -> @_:B -> Pair(Array<F32>, Pair(A, B))) -> @low:Pair(Array<F32>, Pair(A, B)) -> Pair(Array<F32>, Pair(A, B))
The two components of the state go to rec one by one, so a closure
call never boxes the state.
template pair_join source · line 40 · raw
@-S:Type -> @x:F32 -> @high:Pair(F32, S) -> Pair(Array<F32>, S)
The depth-1 tree, cells base and base + 1: the second cell reads the
state the first hands back, and the node of the two leaves is built here.
The bottom level of every deeper tree runs this, so no leaf returns
through leaf and half of the tree's nodes create no closure. The second
cell is Nat.add(1n, base), which is upper(0n, base) but a flat add.
template pair source · line 44 · raw
@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @+count:Nat -> @+base:Nat -> @low:Pair(F32, Pair(A, B)) -> Pair(Array<F32>, Pair(A, B))
template tree source · line 52 · raw
@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> Pair(Array<F32>, Pair(A, B))
The cells base .. base + 2^depth as a balanced tree, built in index order
on one thread. A cell at or past count is padding.
template fork source · line 65 · raw
@-A:Type -> @-B:Type -> @pair:Pair(Pair(A, B), Pair(A, B)) -> @low:(@_:A -> @_:B -> Array<F32>) -> @high:(@_:A -> @_:B -> Array<F32>) -> Array<F32>
template build source · line 74 · 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 -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> Array<F32>
The parallel build. Every cell gets the F32 the one-thread tree computes
there, so no output word depends on splits or on the thread count.
template leaf_certified source · line 93 · raw
@-S:Type -> @pair:Pair(F32, S) -> Certified<S, 0n, leaf(S, pair)>
template node_joined source · line 97 · raw
@-A:Type -> @-B:Type -> @+inner:Nat -> @-rec:(@_:A -> @_:B -> Pair(Array<F32>, Pair(A, B))) -> @-low:Pair(Array<F32>, Pair(A, B)) -> @a:Array<F32> -> @-l:A -> @-r:B -> @same:{(a, l, r) == low : Pair(Array<F32>, Pair(A, B))} -> @balanced:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, inner, a) -> @high:Certified<Pair(A, B), inner, rec(l, r)> -> Certified<Pair(A, B), 1n+inner, node(A, B, rec, low)>
template node_split source · line 108 · raw
@-A:Type -> @-B:Type -> @+inner:Nat -> @-rec:(@_:A -> @_:B -> Pair(Array<F32>, Pair(A, B))) -> @-low:Pair(Array<F32>, Pair(A, B)) -> @result:Pair(Array<F32>, Pair(A, B)) -> @same:{result == low : Pair(Array<F32>, Pair(A, B))} -> @balanced:0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, inner, Pair.fst(Array<F32>, Pair(A, B), result)) -> @next:(@l:A -> @r:B -> Certified<Pair(A, B), inner, rec(l, r)>) -> Certified<Pair(A, B), 1n+inner, node(A, B, rec, low)>
template node_certified source · line 116 · raw
@-A:Type -> @-B:Type -> @+inner:Nat -> @-rec:(@_:A -> @_:B -> Pair(Array<F32>, Pair(A, B))) -> @-low:Pair(Array<F32>, Pair(A, B)) -> @certified:Certified<Pair(A, B), inner, low> -> @next:(@l:A -> @r:B -> Certified<Pair(A, B), inner, rec(l, r)>) -> Certified<Pair(A, B), 1n+inner, node(A, B, rec, low)>
template pair_joined source · line 122 · raw
@-S:Type -> @x:F32 -> @high:Pair(F32, S) -> Certified<S, 1n, pair_join(S, x, high)>
template pair_certified source · line 126 · raw
@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @+count:Nat -> @+base:Nat -> @low:Pair(F32, Pair(A, B)) -> Certified<Pair(A, B), 1n, pair(P, A, B, cell, p, count, base, low)>
template tree_certified 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 -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> Certified<Pair(A, B), depth, tree(P, A, B, cell, p, depth, count, base, state)>
template tree_balanced source · line 149 · raw
@-P:Data -> @-A:Type -> @-B:Type -> @-cell:(@+p:P -> @+position:Nat -> @_:Pair(A, B) -> @_:Bool -> Pair(F32, Pair(A, B))) -> @+p:P -> @+depth:Nat -> @+count:Nat -> @+base:Nat -> @-state:Pair(A, B) -> @certified:Certified<Pair(A, B), depth, tree(P, A, B, cell, p, depth, count, base, state)> -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, depth, Pair.fst(Array<F32>, Pair(A, B), tree(P, A, B, cell, p, depth, count, base, state)))
The one-thread tree is balanced at its depth.
template fork_balanced source · line 157 · raw
@-A:Type -> @-B:Type -> @+inner:Nat -> @pair:Pair(Pair(A, B), Pair(A, B)) -> @-low:(@_:A -> @_:B -> Array<F32>) -> @-high:(@_:A -> @_:B -> Array<F32>) -> @low_valid:(@l:A -> @r:B -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, inner, low(l, r))) -> @high_valid:(@l:A -> @r:B -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, inner, high(l, r))) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, 1n+inner, fork(A, B, pair, low, high))
template balanced source · line 168 · 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 -> @+depth:Nat -> @+splits:Nat -> @+count:Nat -> @+base:Nat -> @state:Pair(A, B) -> 0x1689e5deb278c16abd3bd45eac101ef3/src/storage/model.Balanced(F32, depth, build(Q, P, A, B, prepare, split, cell, q, depth, splits, count, base, state))
The parallel build returns a balanced tree of its depth, whatever the split. It is the certificate the output storage carries, erased at runtime.