~/bend-docscommunity

tensor_convolution.bend checks

raw source on the hub · import stelliferous@0.0.4.0/tensor_convolution.bend as Tensor_convolution

CHW / NCHW entry. Geometry and allocation checks finish before planning. The input has its lanes on the channels with the groups innermost, the weights their lanes on the output channels with the groups outermost, so that their cells are the lane tiles of the product. The output pieces are those of the output cells.

17 imports
import Base
import ./tensor.bend as Tensors
import ./storage_buffer.bend as Storage
import ./kernel_shape.bend as KernelShape
import ./kernel_tile.bend as Tile
import ./kernel_cost.bend as Cost
import ./default_kernel_cost.bend as DefaultCost
import ./default_machine_limits.bend as Default
import ./machine_limits.bend as Machine
import ./proofs/storage_certificate.bend as Certificate
import ./kernel_window_pipeline.bend as WindowPipeline
import ./kernel_pipeline.bend as Pipeline
import ./math_activation.bend as Activations
import ./tensor_grid.bend as Grid
import ./tensor_pieces.bend as Pieces
import ./tensor_tasks.bend as Tasks
import ./tensor_tiled.bend as Tiled

Types

type InputShape source · line 24 · raw

Data

type Geometry source · line 27 · raw

Data

Definitions

def input_shape source · line 30 · raw

@shape:List<&2, U32> -> Maybe<&2, InputShape>

def matched source · line 36 · raw

@matches:Bool -> @geometry:Geometry -> Maybe<&2, Geometry>

def geometry source · line 41 · raw

@input:Maybe<&2, InputShape> -> @weights:List<&2, U32> -> @bias:List<&2, U32> -> @stride:U32 -> @padding:U32 -> Maybe<&2, Geometry>

def output_shape source · line 48 · raw

@batched:Bool -> @batch:U32 -> @rows:U32 -> @height:U32 -> @width:U32 -> List<&2, U32>

def image_cells source · line 55 · raw

@batched:Bool -> @+batch:U32 -> @+height:U32 -> @+width:U32 -> @+groups:U32 -> List<&2, U32>

The cells of an image batch: the positions of every image, the groups of a position side by side.

def lane_of source · line 61 · raw

@batched:Bool -> Nat

The lane axis of an input or output of the call: its channels.

def machine_support source · line 66 · raw

@geometry:Geometry -> @+limits:0xa2af805348d03b11eb853850859654f6/machine_limits.Limits -> Bool

def prefix_of source · line 72 · raw

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

def images_of source · line 76 · raw

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

def whole_cells source · line 82 · raw

@+lead:U32 -> @+input:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+output:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+input_image:U32 -> @+output_image:U32 -> U32

When the pieces of both grids hold whole images, a task holds whole pieces of both: the output cells of the most images a piece of either holds.

def packed_share source · line 88 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> F32

The packed input tiles of one output cell: its share of the inner extent of a position over the output groups, unless the input is read in place.

def plane_pairs source · line 94 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> U32

The pairs of the planes of the whole output, unless the input is read in place.

def transposed_share source · line 99 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> F32

The transposed pairs of one output cell: its share of the planes.

def cell_rows source · line 105 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> F32

One output cell: a multiply-add row of its eight channels for every inner index, its store, its activation, eight lanes a row, its packed tiles and its transposed pairs.

def cell_steps source · line 110 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> F32

def extra_of source · line 117 · raw

@+whole:U32 -> @+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> 0xa2af805348d03b11eb853850859654f6/tensor_tasks.Extra

What a task beyond the first adds: its own weights, bias and workspace, and a halo of the rows a window reaches past the step when tasks split images. Its planes hold the pairs of its own positions, so they grow with its cells, which the transposed share of a cell counts.

def cut_cell_ns source · line 125 · raw

@+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> F32

What a cut task pays for each of its output cells: a copy of the input cells it reads, which another task owns, and the copy of its cell into the piece.

def failed source · line 153 · raw

@+reason:0xa2af805348d03b11eb853850859654f6/tensor.Reason -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @+cells:List<&2, U32> -> @fill:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @workers:U32 -> @+axis:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

A failure of the call keeps the input cells.

def parameters_valid source · line 171 · raw

@+dimensions:0xa2af805348d03b11eb853850859654f6/kernel_shape.Dimensions -> @+weight_length:Nat -> @+weight_depth:Nat -> @+bias_length:Nat -> @+bias_depth:Nat -> Bool

def channel_lanes source · line 208 · raw

@pair:Pair(0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled, List<&2, U32>) -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

The input with its lanes on the channels, the axis before the rows, and the groups innermost.

def products source · line 229 · raw

@+count:U32 -> @+rows:U32 -> @+inner:U32 -> @+outputs:U32 -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+workers:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor.Tensor<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

The products of count images of rows positions and inner channels with outputs rows of inner weights that every image shares, plus the bias: a convolution of a one-cell window. The cells of the input are [count,rows,1,input groups], those of the result [count,rows,1,output groups].

Templates

template run_windowed source · line 129 · raw

@-custom:(@_:F32 -> F32) -> @+lead:U32 -> @+convolution:0xa2af805348d03b11eb853850859654f6/kernel_window_pipeline.Convolution -> @+input_grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+output_grid:0xa2af805348d03b11eb853850859654f6/tensor_grid.Grid -> @+rows:F32 -> @+steps:F32 -> @+workers:U32 -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8)

template run source · line 134 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @+geometry:Geometry -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+workers:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template band_machine source · line 156 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @supported:Bool -> @+geometry:Geometry -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+shape:List<&2, U32> -> @+cells:List<&2, U32> -> @fill:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+workers:U32 -> @+axis:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template band_supported source · line 163 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @valid:Bool -> @+geometry:Geometry -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+shape:List<&2, U32> -> @+cells:List<&2, U32> -> @fill:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+workers:U32 -> @+axis:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template band_checked source · line 179 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @geometry:Maybe<&2, Geometry> -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+shape:List<&2, U32> -> @+cells:List<&2, U32> -> @fill:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+workers:U32 -> @+axis:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template band_status source · line 192 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @pieces:0xa2af805348d03b11eb853850859654f6/tensor_pieces.Pieces(0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @+shape:List<&2, U32> -> @+cells:List<&2, U32> -> @+fill:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @weight_shape:List<&2, U32> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias_shape:List<&2, U32> -> @stride:U32 -> @padding:U32 -> @+workers:U32 -> @+axis:Nat -> @+lanes:U32 -> @+position:0xa2af805348d03b11eb853850859654f6/tensor_grid.Position -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template input_cells source · line 200 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @input:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @weight_shape:List<&2, U32> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias_shape:List<&2, U32> -> @parameter_status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @parameter_workers:U32 -> @stride:U32 -> @padding:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

template conv2d_aligned source · line 214 · raw

@-custom:(@_:F32 -> F32) -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @input:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @weights:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @bias:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+stride:U32 -> @+padding:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

The cells of the weights are the lane tiles of the product; the bias is one cell per output-channel group.

template conv2d source · line 222 · raw

@-custom:(@_:F32 -> F32) -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @input:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @weights:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @bias:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @stride:U32 -> @padding:U32 -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled