~/bend-docscommunity

kernel_pipeline.bend checks

raw source on the hub · import stelliferous@0.0.4.0/kernel_pipeline.bend as Kernel_pipeline

A convolution call owns the cells of its input window, packs them block by block and writes the cells of its output positions, the groups of a position side by side. The caller validates dimensions and chooses the calls.

16 imports
import Base
import ./kernel_gemm.bend as Gemm
import ./kernel_gemm_buffer.bend as GemmBuffer
import ./kernel_tile.bend as Tile
import ./kernel_spatial_packing.bend as Packing
import ./kernel_packing_buffer.bend as PackingBuffer
import ./storage_buffer.bend as Storage
import ./tensor.bend as Tensors
import ./kernel_window.bend as KernelWindow
import ./traversal_array.bend as Traversal
import ./math_activation.bend as Activations
import ./proofs/traversal_certificate.bend as TraversalCertificate
import ./math_gelu_lanes.bend as GeluLanes
import ./tensor_tiled_map.bend as TiledMap
import ./tensor_tiled.bend as Tiled
import ./tensor_grid.bend as Grid

Types

type Work source · line 22 · raw

Data

type WindowWork source · line 28 · raw

Data

The matrix and its source stencil are independent. Forward convolution is the square specialization; an adjoint phase uses rectangular taps and origins. end is the position after the last one a call writes.

type BlockState source · line 83 · raw

Type

The blocks of a call pack their tiles from the planes of the call and store the channel groups of their positions, eight channels a tile.

type Kept source · line 89 · raw

Type

What a call gives back: its input, weights and bias, its two workspaces and its output.

Definitions

def leaky_relu_value source · line 39 · raw

@slope:F32 -> @value:F32 -> F32

def gelu_mapped source · line 45 · raw

@+count:U32 -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

def block_tiles source · line 69 · raw

U32

def block_positions source · line 72 · raw

@inner:U32 -> U32

def workspace_prefix source · line 75 · raw

@+target:U32 -> @+inner:U32 -> @positions:U32 -> U32

def workspace_tiles source · line 78 · raw

@+target:U32 -> @+inner:U32 -> @+positions:U32 -> U32

def kept_from_blocks source · line 93 · raw

@input:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @state:BlockState -> Kept

def output_tiles source · line 97 · raw

@+rows:U32 -> @+positions:U32 -> U32

def block_kept source · line 106 · raw

@planes:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @kept:0xa2af805348d03b11eb853850859654f6/kernel_gemm_buffer.CellKept -> BlockState

def block_packed source · line 110 · raw

@+rows:U32 -> @+end:U32 -> @inner:U32 -> @+start:U32 -> @+span:U32 -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @packed:Pair(0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>) -> BlockState

def block_step_window source · line 119 · raw

@work:WindowWork -> @+planes:0xa2af805348d03b11eb853850859654f6/kernel_spatial_packing.Planes -> @pack_start:U32 -> @output_start:U32 -> @+span:U32 -> @state:BlockState -> BlockState

Packing addresses the planes of the call; output positions are those of the output buffer, none at or after end. Each block overwrites tiles from zero and writes directly into the output.

def blocks_window source · line 126 · raw

@remaining:Nat -> @+work:WindowWork -> @+planes:0xa2af805348d03b11eb853850859654f6/kernel_spatial_packing.Planes -> @+pack_start:U32 -> @+output_start:U32 -> @+padded:U32 -> @+span:U32 -> @state:BlockState -> BlockState

def blocked_window_with source · line 135 · raw

@+work:WindowWork -> @+planes:0xa2af805348d03b11eb853850859654f6/kernel_spatial_packing.Planes -> @pack_start:U32 -> @+offset:U32 -> @+padded:U32 -> @state:BlockState -> BlockState

An inner larger than the target still needs one complete eight-position group.

def planes_ready source · line 140 · raw

@+work:WindowWork -> @+planes:0xa2af805348d03b11eb853850859654f6/kernel_spatial_packing.Planes -> @pack_start:U32 -> @+offset:U32 -> @+padded:U32 -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @tiles:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @transposed:Pair(0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>) -> Kept

def blocked_into source · line 151 · raw

@+work:WindowWork -> @+pack_start:U32 -> @+offset:U32 -> @input:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @weights:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @bias:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @planes:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tiles:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> Kept

The cells of positions [offset, end) of output from the window, read from the packing start pack_start: the input is transposed once into planes, a workspace of at least Packing.plane_bound(window, end - offset rounded up to 8) pairs, and packed block by block into tiles, a workspace of at least workspace_tiles(block_tiles(), inner, end - offset) tiles; input, weights, bias and the workspaces come back.

def depth_limit source · line 159 · raw

@+padded:U32 -> U32

The deepest split that leaves every leaf at least one eight-position block.

def staged_dropped source · line 164 · raw

@result:Pair(0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>) -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

def kept_tile source · line 168 · raw

@context:Unit -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8

def packed_tile_rows source · line 200 · raw

F32

What packing one workspace tile counts: its reads, shift and store are four rows, its addressing eight steps.

def packed_tile_steps source · line 203 · raw

F32

def transposed_pair_rows source · line 208 · raw

F32

What transposing one pair of a plane counts: its gather, pair and store are four rows, its addressing eight steps.

def transposed_pair_steps source · line 211 · raw

F32

Templates

template activated_value source · line 31 · raw

@-activation:(@_:F32 -> F32) -> @context:Unit -> @value:F32 -> F32

template mapped source · line 34 · raw

@-Context:Data -> @-operation:(@_:Context -> @_:F32 -> F32) -> @+count:U32 -> @+context:Context -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

template unit_mapped source · line 42 · raw

@-operation:(@_:F32 -> F32) -> @+count:U32 -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

template activated source · line 54 · raw

@-custom:(@_:F32 -> F32) -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @+count:U32 -> @buffer:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

One tight pass over the cells of each finished leaf while they are still in cache; applying the activation inside the store measured about twice as slow. The built-in is chosen once per leaf, so each pass is specialized; the identity skips it.

template finished source · line 102 · raw

@-custom:(@_:F32 -> F32) -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @+rows:U32 -> @+positions:U32 -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

The cells of the channels over positions positions, activated, with +0 in the lanes past the channels.

template unit_converted source · line 171 · raw

@-operation:(@_:F32 -> F32) -> @+channels:U32 -> @+count:U32 -> @staged:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

template converted source · line 175 · raw

@-custom:(@_:F32 -> F32) -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @+channels:U32 -> @+count:U32 -> @staged:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @output:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

The cells of the staged pairs, the activation applied in the same pass.

template point_finished source · line 193 · raw

@-custom:(@_:F32 -> F32) -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @+rows:U32 -> @+positions:U32 -> @staged:0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> 0xa2af805348d03b11eb853850859654f6/storage_buffer.Buffer<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>

The cells of the channels over positions positions from their staged pairs, activated, with +0 in the lanes past the channels.