~/bend-docscommunity

tensor_tiled_reduce.bend checks

raw source on the hub · import stelliferous@0.0.4.0/tensor_tiled_reduce.bend as Tensor_tiled_reduce

Reductions of tiled tensors, read in the layout of the input. With the lanes on a kept axis every lane reduces its own values: the cells reduce their cell axes with eight accumulators a cell, and every piece of the result sets the lanes past the extent to +0. With the lanes on a reduced axis the result holds one value a cell, its lanes then moved to the longest kept axis. A fold reads the values in increasing index: along the cells of a lane axis reduced last every cell steps its lanes in order. A sum follows Partials: the rows of the last axis folded by Sum and the rows merged in the tree of the reduced axes. With the lanes on a reduced last axis a row is its cells in order and every lane of a cell that holds a value adds it to one lane of the sum. Lanes on another reduced axis first move to the last axis, the groups innermost.

14 imports
import Base
import ./kernel_tile.bend as Tile
import ./math_sum.bend as Sum
import ./tensor.bend as Tensors
import ./tensor_grid.bend as Grid
import ./tensor_layout.bend as Layout
import ./tensor_operations.bend as Operations
import ./tensor_partials.bend as Partials
import ./tensor_shape.bend as Shapes
import ./tensor_view.bend as Views
import ./tensor_tiled.bend as Tiled
import ./tensor_tiled_map.bend as TiledMap
import ./traversal_array.bend as Traversal
import ./proofs/traversal_witness.bend as TraversalWitness

Types

type Folds source · line 31 · raw

@-Accumulator:Data -> Data

One accumulator a lane.

type Route source · line 133 · raw

Data

How a reduction reads the lanes of its input: one value a cell, the lanes on a kept axis, along a reduced lane axis, or across it.

type LaneLine source · line 172 · raw

@-Accumulator:Data -> Data

A line along the lane axis: its cells in order, each stepping the lanes that hold values. The first lane of a cell is eight past that of the cell before, and 0 again after the last group.

type SumLine source · line 316 · raw

Data

A row along the lane axis: its cells in order, lane j of the parts the sum of lane j of Sum, every cell adding only its lanes that hold values. The first lane of a cell is eight past that of the cell before, and 0 again after the last group.

Definitions

def longest_kept source · line 68 · raw

@kept:List<&2, Nat> -> @+shape:List<&2, U32> -> @+place:Nat -> @+best:Nat -> @+extent:U32 -> Nat

The place among the kept axes of the one of the largest extent, the later among equal extents, or the count of kept axes when none is kept.

def flags_placed source · line 78 · raw

@position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> @flags:List<&2, Bool> -> @+flag:Bool -> List<&2, Bool>

The flags but the one of an axis. The flags of the other axes with the flag of the groups at their position.

def flagged_words source · line 84 · raw

@flags:List<&2, Bool> -> @+index:U32 -> List<&2, U32>

The axes from index on whose flag is set.

def cell_axes source · line 95 · raw

@+reduced:List<&2, Nat> -> @+rank:Nat -> @+lane:Nat -> @position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> List<&2, U32>

The reduced cell axes with the lanes on lane: the reduced axes but the lane axis in order, and the groups at their position when the lane axis is reduced.

def kept_place source · line 100 · raw

@kept:List<&2, Nat> -> @+axis:Nat -> @+place:Nat -> Nat

The place of an axis among the kept axes, from place on.

def trimmed source · line 105 · raw

@pair:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, 0xa2af805348d03b11eb853850859654f6/tensor_tiled_map.Padding) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

def kept_result source · line 111 · raw

@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

The result of a reduction with the lanes on a kept axis: lanes past the extent hold what the accumulators made of +0, set to +0 here.

def kept_cells source · line 114 · raw

@+reduced:List<&2, Nat> -> @+rank:Nat -> @+lane:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> @cells:0xa2af805348d03b11eb853850859654f6/tensor.Tensor<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

def route_of source · line 139 · raw

@+lane:Nat -> @+rank:Nat -> @+reduced:List<&2, Nat> -> @along:Bool -> Route

def none_flagged source · line 143 · raw

@flags:List<&2, Bool> -> Bool

Whether no flag is set.

def none_after source · line 149 · raw

@flags:List<&2, Bool> -> @axis:Nat -> Bool

Whether no flag after the one of an axis is set.

def result_arranged source · line 155 · raw

@kept:Bool -> @+axis:Nat -> @result:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

def result_lanes source · line 162 · raw

@+shape:List<&2, U32> -> @+reduced:List<&2, Nat> -> @result:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

A result of one value a cell with its lanes on the longest kept axis, or on the unit axis when no axis is kept.

def all_hold source · line 203 · raw

@+first:U32 -> @+lanes:U32 -> Bool

Whether all eight lanes from first on hold values.

def valid_axes source · line 266 · raw

@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> Bool

A valid list of axes of a usable, nonempty tensor.

def every_axis source · line 278 · raw

@remaining:Nat -> @+index:U32 -> List<&2, U32>

def parts_zero source · line 290 · raw

0xa2af805348d03b11eb853850859654f6/math_sum.Parts

def lane_rounded source · line 293 · raw

@parts:0xa2af805348d03b11eb853850859654f6/math_sum.Parts -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

def row_kept source · line 296 · raw

@lo:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @parts:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> 0xa2af805348d03b11eb853850859654f6/math_sum.TileParts

def row_added source · line 301 · raw

@parts:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> @value:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/math_sum.TileParts

A row of cells: lane j of the parts adds the values of lane j of the sum.

def row_closed source · line 305 · raw

@parts:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> 0xa2af805348d03b11eb853850859654f6/math_sum.Parts

def sum_begun source · line 309 · raw

@context:Unit -> 0xa2af805348d03b11eb853850859654f6/math_sum.Lanes

def lanes_below source · line 320 · raw

@+count:U32 -> @added:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @kept:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

The lanes of added below count, the others of kept.

def parts_below source · line 326 · raw

@+count:U32 -> @added:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> @kept:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> 0xa2af805348d03b11eb853850859654f6/math_sum.TileParts

def cell_added source · line 332 · raw

@whole:Bool -> @+count:U32 -> @+parts:0xa2af805348d03b11eb853850859654f6/math_sum.TileParts -> @value:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/math_sum.TileParts

A cell whose lanes all hold values adds them at once.

def line_added source · line 337 · raw

@line:SumLine -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> SumLine

def line_begun source · line 343 · raw

@lanes:U32 -> SumLine

def line_closed source · line 346 · raw

@line:SumLine -> 0xa2af805348d03b11eb853850859654f6/math_sum.Parts

def kept_position source · line 353 · raw

@+lane:Nat -> @+rank:Nat -> 0xa2af805348d03b11eb853850859654f6/tensor_grid.Position

The groups of lanes on a kept axis lie innermost when the lanes are on the last axis, every cell then a row, otherwise outermost, the last axis then the last of the cells too.

def summed_kept source · line 357 · raw

@name:String -> @+axes:List<&2, U32> -> @+rank:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Lanes on a kept axis, the groups at kept_position.

def summed_along source · line 367 · raw

@name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @+rank:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Lanes along the reduced last axis, the groups innermost: a row is its cells in order.

def summed_last source · line 374 · raw

@reduced:Bool -> @name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @+rank:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Lanes on the last axis, the groups innermost: along it when it is reduced, otherwise on a kept axis.

def summed source · line 379 · raw

@route:Route -> @name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @+rank:Nat -> @+lane:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

def sum_valid source · line 392 · raw

@valid:Bool -> @name:String -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Valid axes sum the lanes where they lie. Invalid axes, an empty tensor and a failed tensor sum on the unit axis, which reports them.

def sum_axes source · line 406 · raw

@name:String -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+axes:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

The sums of the listed axes in the order of Partials. An invalid list of axes, an empty tensor and a failed tensor sum the cells on the unit axis, which reports them.

def sum_all source · line 411 · raw

@name:String -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Templates

template started source · line 34 · raw

@-Accumulator:Data -> @+initial:Accumulator -> Folds<Accumulator>

template stepped source · line 37 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @folds:Folds<Accumulator> -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Folds<Accumulator>

template finished source · line 42 · raw

@-Accumulator:Data -> @-finish:(@_:Accumulator -> F32) -> @folds:Folds<Accumulator> -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

template closed source · line 46 · raw

@-Row:Data -> @-Partial:Data -> @-close:(@_:Row -> Partial) -> @folds:Folds<Row> -> Folds<Partial>

template merged source · line 50 · raw

@-Partial:Data -> @-merge:(@_:Partial -> @_:Partial -> Partial) -> @left:Folds<Partial> -> @right:Folds<Partial> -> Folds<Partial>

template lane_operation source · line 57 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @accumulator:Accumulator -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Accumulator

The operation on a cell of the unit axis reads its first lane; the finished value is a cell of the unit axis.

template unit_finish source · line 61 · raw

@-Accumulator:Data -> @-finish:(@_:Accumulator -> F32) -> @accumulator:Accumulator -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

template folded_kept source · line 119 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @unit:Bool -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @+axes:List<&2, U32> -> @+rank:Nat -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template lane_applied source · line 175 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @valid:Bool -> @value:Accumulator -> @lane:F32 -> Accumulator

template lanes_all source · line 181 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @value:Accumulator -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Accumulator

The eight lanes of a tile, one after another.

template lanes_masked source · line 186 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @+first:U32 -> @+lanes:U32 -> @value:Accumulator -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Accumulator

The lanes of a tile that hold values, one after another.

template lanes_whole source · line 197 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @whole:Bool -> @+first:U32 -> @+lanes:U32 -> @value:Accumulator -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Accumulator

template lanes_stepped source · line 209 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @+first:U32 -> @+lanes:U32 -> @value:Accumulator -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> Accumulator

A cell steps the lanes that hold values: all eight without a test when each of them does.

template line_step source · line 212 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @line:LaneLine<Accumulator> -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> LaneLine<Accumulator>

template line_finish source · line 217 · raw

@-Accumulator:Data -> @-finish:(@_:Accumulator -> F32) -> @line:LaneLine<Accumulator> -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

template folded_along source · line 223 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Lanes along a reduced axis with no reduced axis after it, the groups innermost: every line steps its cells in order.

template folded_last source · line 233 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @reduced:Bool -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Lanes on the last axis, the groups innermost: along it when it is reduced, otherwise on a kept axis.

template folded source · line 239 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @route:Route -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template folded_valid source · line 251 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @valid:Bool -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @+shape:List<&2, U32> -> @+axes:List<&2, U32> -> @started:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, Nat) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Valid axes reduce the lanes where they lie. Invalid axes, an empty tensor and a failed tensor reduce on the unit axis, which reports them.

template reduce_axes source · line 272 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+axes:List<&2, U32> -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Layout.reduce_axes of a tiled tensor: every value folded in increasing index. An invalid list of axes, an empty tensor and a failed tensor reduce the cells on the unit axis, which reports them.

template reduce_all source · line 283 · raw

@-Accumulator:Data -> @-operation:(@_:Accumulator -> @_:F32 -> Accumulator) -> @-finish:(@_:Accumulator -> F32) -> @name:String -> @+operations:F32 -> @+initial:Accumulator -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled