~/bend-docscommunity

tensor_pieces.bend checks

raw source on the hub · import stelliferous@0.0.4.0/tensor_pieces.bend as Tensor_pieces

Pieces own the cells of a tensor: a tree of buffers whose leaves hold contiguous ranges of the canonical order of lib/tensor_grid.bend, offset and span counted in cells. Ranges describe the tree without its buffers. The skeleton below walks, folds, builds and runs work over the tree. The work of one task may own several adjacent pieces.

6 imports
import Base
import ./storage_buffer.bend as Storage
import ./storage_clone.bend as Clone
import ./storage_allocation.bend as Allocation
import ./traversal_partition.bend as Partition
import ./tensor_grid.bend as Grid

Types

type Lefts source · line 17 · raw

@-Output:Type -> Type

The output trees left of the walk, each waiting for the tree on its right.

type Walking source · line 22 · raw

@-Output:Type -> @-State:Type -> Type

What a walk carries into a subtree, and what it gives back after it.

type Walked source · line 25 · raw

@-Output:Type -> @-State:Type -> Type

type Ranges source · line 97 · raw

Data

A description of the pieces holds no Buffer. It is a concrete Data type: duplicating Tree<&2,...> through a computed type makes all constructors shared in the official compiler, including the affine Buffer tree.

type Paired source · line 137 · raw

@-Left:Type -> @-Right:Type -> Type

Two trees of one shape, joined leaf by leaf. A left leaf without a partner keeps its own range, so the left tree can be returned unchanged.

type Division source · line 179 · raw

@-State:Type -> Type

What a split gives its halves: a state for each, or the whole state when it cannot be divided.

type Queue source · line 392 · raw

@-Block:Type -> Type

The blocks of a tree in order, and a tree of them in the shape of ranges whose every range is one block. Only the tree changes: no block moves. A range past the last block gets a vacant block.

Definitions

def first source · line 112 · raw

@layout:Ranges -> U32

def last source · line 117 · raw

@layout:Ranges -> U32

def unshared source · line 171 · raw

@resource:Unit -> Pair(Unit, Unit)

def always source · line 189 · raw

@schedule:Unit -> @layout:Ranges -> Bool

Every split may run its halves in parallel.

def in_parallel source · line 243 · raw

@enabled:Bool -> @layout:Ranges -> Bool

The planner decides once for an operation: every split of an enabled walk may run its halves in parallel, whatever cells they hold.

def group_unit source · line 291 · raw

@left:Unit -> @right:Unit -> Unit

def unit_ranges source · line 312 · raw

@depth:Nat -> @+unit:U32 -> @+first:U32 -> @+count:U32 -> Ranges

Positions [first, first + count) halved depth times. The first half of every split is a whole number of units.

def bounds source · line 320 · raw

@+layout:Ranges -> Pair(U32, U32)

The first cell of ranges and how many cells they hold.

def cells_of source · line 352 · raw

@+grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+first:U32 -> @+count:U32 -> U32

The ranges of the pieces of a grid: a left-complete tree over the outer indices whose leaves are left-complete trees over the pieces of one outer index. A left half holds the largest power of two below the count, so every aligned block of a power of two is a complete subtree.

def below source · line 356 · raw

@+count:U32 -> U32

def inner_ranges source · line 359 · raw

@depth:Nat -> @single:Bool -> @+grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+first:U32 -> @+count:U32 -> Ranges

def outer_ranges source · line 368 · raw

@depth:Nat -> @single:Bool -> @+grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+per:U32 -> @+first:U32 -> @+count:U32 -> Ranges

def ranges_in source · line 380 · raw

@+grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+group:U32 -> Ranges

The ranges of groups of outer indices, group of them each: a left-complete tree over the groups whose leaves are left-complete trees over the pieces of one group.

def ranges_of_grid source · line 386 · raw

@+grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> Ranges

Templates

template Pieces source · line 13 · raw

@-Element:Data -> Type

template leaf_walked source · line 28 · raw

@-Output:Type -> @-State:Type -> @lefts:Lefts<Output> -> @result:Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, State) -> Walked<Output, State>

template piece_walked source · line 33 · raw

@-Element:Data -> @-State:Type -> @lefts:Lefts<0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<Element>> -> @+first:U32 -> @+count:U32 -> @result:Pair(0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<Element>, State) -> Walked<0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<Element>, State>

One output piece of first cell first and count cells.

template pushed source · line 38 · raw

@-Output:Type -> @-State:Type -> @walked:Walked<Output, State> -> Walking<Output, State>

template joined source · line 43 · raw

@-Output:Type -> @-State:Type -> @walked:Walked<Output, State> -> Walked<Output, State>

The tree just walked joins the tree waiting on its left.

template walk_result source · line 48 · raw

@-Output:Type -> @-State:Type -> @walked:Walked<Output, State> -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, State)

template walked source · line 54 · raw

@-Input:Type -> @-Output:Type -> @-State:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Input -> @_:State -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, State)) -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Input, Unit> -> @ready:Walking<Output, State> -> Walked<Output, State>

The walk calls no closure, so a task whose leaf walks its pieces stays fork-free and the runtime keeps it for the work turn.

template walk source · line 67 · raw

@-Input:Type -> @-Output:Type -> @-State:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Input -> @_:State -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, State)) -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Input, Unit> -> @state:State -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, State)

An existing tree with a state threaded through its leaves in order. The leaf takes the state and gives it back beside what it leaves in the tree.

template fold source · line 73 · raw

@-Input:Type -> @-State:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Input -> @_:State -> State) -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Input, Unit> -> @state:State -> State

Every leaf of a tree consumed into a state, in order.

template reduced source · line 79 · raw

@-Output:Type -> @-Value:Type -> @-join:(@_:Value -> @_:Value -> Value) -> @left:Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Value) -> @right:Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Value) -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Value)

template reduce source · line 86 · raw

@-Input:Type -> @-Output:Type -> @-Value:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Input -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Value)) -> @-join:(@_:Value -> @_:Value -> Value) -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Input, Unit> -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Value)

A value from every leaf, joined where the tree forks. The leaf gives its value beside what it leaves in the tree.

template ranges_fold source · line 101 · raw

@-Value:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> Value) -> @-join:(@_:Context -> @_:Ranges -> @_:Ranges -> @_:Value -> @_:Value -> Value) -> @layout:Ranges -> @+context:Context -> Value

template plain source · line 109 · raw

@-Value:Type -> @-Context:Data -> @-join:(@_:Value -> @_:Value -> Value) -> @context:Context -> @left:Ranges -> @right:Ranges -> @first:Value -> @second:Value -> Value

A join that needs neither the context nor the halves of the split.

template build source · line 124 · raw

@-Output:Type -> @-State:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:State -> Pair(State, 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>)) -> @layout:Ranges -> @+context:Context -> @state:State -> Pair(State, 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>)

A tree made from ranges, with a state threaded through the leaves in order. The leaf takes the state and gives it back beside the piece it made.

template only source · line 141 · raw

@-Left:Type -> @-Right:Type -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Paired<Left, Right>, Unit>

template zip source · line 146 · raw

@-Left:Type -> @-Right:Type -> @left:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit> -> @right:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Right, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Paired<Left, Right>, Unit>

template left_leaf source · line 154 · raw

@-Left:Type -> @-Right:Type -> @pair:Paired<Left, Right> -> @first:U32 -> @count:U32 -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit>

template left_of source · line 159 · raw

@-Left:Type -> @-Right:Type -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Paired<Left, Right>, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit>

template paired source · line 164 · raw

@-Left:Type -> @-Right:Type -> @-Resource:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Left -> @_:Right -> @_:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit>) -> @context:Context -> @first:U32 -> @count:U32 -> @pair:Paired<Left, Right> -> @resource:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Left, Unit>

template same source · line 174 · raw

@-Block:Type -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit>

template divided source · line 183 · raw

@-State:Type -> @-Result:Type -> @division:Division<State> -> @whole:(@_:State -> Result) -> @halves:(@_:State -> @_:State -> Result) -> Result

template each_part source · line 199 · raw

@-State:Type -> @-Output:Type -> @-Details:Data -> @-Context:Data -> @-Schedule:Data -> @-parallel:(@_:Schedule -> @_:Ranges -> Bool) -> @-divide:(@_:Context -> @_:Ranges -> @_:Ranges -> @_:State -> Division<State>) -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:State -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Details>) -> @-keep:(@_:Context -> @_:Ranges -> @_:State -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Details>) -> @layout:Ranges -> @mode:Bool -> @+schedule:Schedule -> @+context:Context -> @state:State -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Details>

The one recursion over ranges. The ranges give every part its range and the structure. divide gives each half of a split its own state, a state it keeps whole becomes one part through keep. A split whose schedule allows it runs its halves in parallel. The last split calls its two leaves directly: a leaf that neither forks nor calls a closure is then its own task, which the runtime keeps for the work turn. A leaf reached through the forking recursion would run in the grow turn on one worker per ring row.

template Pieced source · line 238 · raw

@-Block:Type -> @-Resource:Type -> Type

A piece walk carries the tree beside the resource. A split divides the tree where it forks. A tree of another shape is kept.

template shared_halves source · line 246 · raw

@-Block:Type -> @-Resource:Type -> @left:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> @right:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> @resources:Pair(Resource, Resource) -> Division<Pieced(Block, Resource)>

template piece_divide source · line 250 · raw

@-Block:Type -> @-Resource:Type -> @-Context:Data -> @-share:(@_:Resource -> Pair(Resource, Resource)) -> @context:Context -> @left:Ranges -> @right:Ranges -> @state:Pieced(Block, Resource) -> Division<Pieced(Block, Resource)>

template piece_leaf source · line 257 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @-keep:(@_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @first:U32 -> @count:U32 -> @state:Pieced(Block, Resource) -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template piece_kept source · line 266 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-keep:(@_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @layout:Ranges -> @state:Pieced(Block, Resource) -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template each source · line 274 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-share:(@_:Resource -> Pair(Resource, Resource)) -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @-keep:(@_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @layout:Ranges -> @+enabled:Bool -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> @resource:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

The piece recursion. share gives each half its own owner of a read-only resource.

template group_piece source · line 286 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Unit -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @first:U32 -> @count:U32 -> @block:Block -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Unit)

A task may own several existing pieces. Its serial walk keeps their metadata and owners. The outer ranges are the tasks, the pieces stay as they are.

template group_run source · line 294 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Unit -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template group_divide source · line 300 · raw

@-Block:Type -> @-Context:Data -> @context:Context -> @left:Ranges -> @right:Ranges -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> Division<0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit>>

template group_task source · line 305 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Unit -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @first:U32 -> @count:U32 -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template subtree_bounded source · line 324 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-task:(@_:Context -> @_:U32 -> @_:U32 -> @_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @bounded:Pair(U32, U32) -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template subtree_kept source · line 330 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-task:(@_:Context -> @_:U32 -> @_:U32 -> @_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @context:Context -> @layout:Ranges -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template subtrees source · line 337 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-task:(@_:Context -> @_:U32 -> @_:U32 -> @_:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @layout:Ranges -> @+enabled:Bool -> @context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

Every task given the subtree of its pieces, its first cell and its cells. A split whose tree does not fork stays one task.

template grouped source · line 343 · raw

@-Block:Type -> @-Output:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Unit -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>) -> @layout:Ranges -> @+enabled:Bool -> @context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template queued source · line 396 · raw

@-Block:Type -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> @rest:Queue<Block> -> Queue<Block>

template dequeued source · line 401 · raw

@-Block:Type -> @-Fill:Data -> @-vacant:(@_:Fill -> Block) -> @fill:Fill -> @first:U32 -> @count:U32 -> @queue:Queue<Block> -> Pair(Queue<Block>, 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit>)

template blocks_regrouped source · line 406 · raw

@-Block:Type -> @-Fill:Data -> @-vacant:(@_:Fill -> Block) -> @+layout:Ranges -> @+fill:Fill -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit>

template vacant_buffer source · line 410 · raw

@-Element:Data -> @fill:Element -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<Element>

template task_walk source · line 416 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Resource -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Resource)) -> @context:Context -> @first:U32 -> @count:U32 -> @state:Pieced(Block, Resource) -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

Tasks over adjacent pieces with one owner of a read-only resource per task: share gives each half of a split its own owner, and a task walks its pieces in order with the one owner it holds.

template task_kept source · line 422 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Resource -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Resource)) -> @context:Context -> @layout:Ranges -> @state:Pieced(Block, Resource) -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>

template grouped_with source · line 428 · raw

@-Block:Type -> @-Output:Type -> @-Resource:Type -> @-Context:Data -> @-share:(@_:Resource -> Pair(Resource, Resource)) -> @-leaf:(@_:Context -> @_:U32 -> @_:U32 -> @_:Block -> @_:Resource -> Pair(0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>, Resource)) -> @layout:Ranges -> @+enabled:Bool -> @+context:Context -> @tree:0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Block, Unit> -> @resource:Resource -> 0xa2af805348d03b11eb853850859654f6/traversal_partition.Tree<&1, Output, Unit>