kernel_spatial_packing.bend checks
raw source on the hub · import stelliferous@0.0.4.0/kernel_spatial_packing.bend as Kernel_spatial_packing
One packer for every window. A tile holds eight consecutive output positions; its entries follow the reduction order: channel, kernel row, kernel column. A call first transposes its input cells into planes, one for each column phase and channel: plane row r holds the input row of the window's first output row times the stride plus r, its columns every stride-th input column from the phase on, +0 outside the input. The rows lie end to end, each a whole number of tiles wide, so the positions of one output row are consecutive plane values for every tap. A plane is kept as pairs of a tile and the next one, sixteen words behind one index. A packed tile is one pass for each output row its positions touch: the pass reads a pair shifted by a lane count fixed for the pass, the first pass stores the tile and a later one moves its lanes into it.
5 imports
import Base import ./traversal_loop.bend as Loop import ./kernel_packing_samples.bend as PackingSamples import ./kernel_tile.bend as Tile import ./math_fp32.bend as FP32
Types
type PixelBlock source · line 40 · raw
Data
PixelBlock@row:U32 -> @column:U32 -> @channel_base:U32 -> @height:U32 -> @width:U32 -> @stride:U32 -> @step:U32 -> PixelBlock
type Stencil source · line 65 · raw
Data
The input cells of a call from base on, height rows of width pixels, groups cells a pixel; output position q of an output output_width wide reads input row (q / output_width) * stride + kernel row + row_origin and input column (q % output_width) * stride + kernel column + column_origin.
Stencil@base:U32 -> @height:U32 -> @width:U32 -> @tap_rows:U32 -> @tap_columns:U32 -> @stride:U32 -> @row_origin:U32 -> @column_origin:U32 -> @output_width:U32 -> @inner:U32 -> @groups:U32 -> Stencil
type Planes source · line 81 · raw
Data
The planes of output positions [start, start + count): their first output row, the plane rows, the width of a row in values (the output width and the column taps past it, whole tiles) and the elements of a plane, one for each tile of its rows.
Planes@first_output_row:U32 -> @rows:U32 -> @width:U32 -> @elements:U32 -> Planes
type Rowing source · line 118 · raw
Type
One plane: the first step reads tile 0, step j after it reads tile j and writes the pair of tiles j - 1 and j at element j - 1. The channels of an element lie side by side, so the elements of a plane are channels apart.
Rowing@input:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @previous:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @column:U32 -> @write:U32 -> @row:U32 -> @in_row:U32 -> @row_tiles:U32 -> @first_column:U32 -> @channel_base:U32 -> @height:U32 -> @width:U32 -> @stride:U32 -> @groups:U32 -> @channels:U32 -> Rowing
type Transposing source · line 178 · raw
Type
Plane phase * channels + channel, in turn.
Transposing@input:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @plane:U32 -> @window:Stencil -> @planes:Planes -> Transposing
type Passing source · line 272 · raw
Type
Entries (channel, kernel row) of one kernel column, the kernel row innermost. The read steps one plane row a kernel row; a new channel starts one past the previous channel's start. The first pass stores its tiles, a later one merges its lanes from lane on into them.
Passing@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @start:U32 -> @read:U32 -> @kernel_row:U32 -> @write:U32 -> @lane:U32 -> @tap_rows:U32 -> @tap_columns:U32 -> @row_step:U32 -> Passing
type Arrays source · line 328 · raw
Type
Arrays@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> Arrays
type Passes source · line 340 · raw
Type
The passes of a unit for one kernel column: pass m starts at lane, its lane 0 at plane offset base. The next output row lies stride plane rows further, its first position one output row on.
Passes@arrays:Arrays -> @pass:U32 -> @lane:U32 -> @base:U32 -> @second_lane:U32 -> @kernel_column:U32 -> @unit:U32 -> @window:Stencil -> @planes:Planes -> Passes
Definitions
def identity source · line 22 · raw
@value:F32 -> F32
A sample of an input element: the value itself, or one lane of a cell.
def square source · line 68 · raw
@height:U32 -> @width:U32 -> @+kernel:U32 -> @stride:U32 -> @+padding:U32 -> @output_width:U32 -> @inner:U32 -> @groups:U32 -> Stencil
def channels_of source · line 71 · raw
@window:Stencil -> U32
def planes_of source · line 84 · raw
@window:Stencil -> @+start:U32 -> @+count:U32 -> Planes
def call_planes_when source · line 93 · raw
@empty:Bool -> @+window:Stencil -> @+start:U32 -> @+count:U32 -> Planes
The planes of a call on count positions from start; a call on no positions has none.
def call_planes source · line 98 · raw
@+window:Stencil -> @+start:U32 -> @+count:U32 -> Planes
def plane_pairs source · line 102 · raw
@+window:Stencil -> @planes:Planes -> U32
The pairs of all planes: one plane for each column phase and channel.
def plane_bound source · line 108 · raw
@+window:Stencil -> @+count:U32 -> U32
Room for the planes of any count consecutive positions.
def row_moved source · line 122 · raw
@input:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+column:U32 -> @write:U32 -> @+row:U32 -> @+in_row:U32 -> @+row_tiles:U32 -> @+first_column:U32 -> @channel_base:U32 -> @height:U32 -> @width:U32 -> @+stride:U32 -> @groups:U32 -> @channels:U32 -> Rowing
def row_kept source · line 128 · raw
@input:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @previous:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+column:U32 -> @+write:U32 -> @+row:U32 -> @+in_row:U32 -> @+row_tiles:U32 -> @+first_column:U32 -> @+channel_base:U32 -> @+height:U32 -> @+width:U32 -> @+stride:U32 -> @+groups:U32 -> @+channels:U32 -> Rowing
def row_read source · line 133 · raw
@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @previous:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+column:U32 -> @+write:U32 -> @+row:U32 -> @+in_row:U32 -> @+row_tiles:U32 -> @+first_column:U32 -> @+channel_base:U32 -> @+height:U32 -> @+width:U32 -> @+stride:U32 -> @+groups:U32 -> @+channels:U32 -> @read:Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> Rowing
def row_first_read source · line 143 · raw
@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @previous:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+column:U32 -> @+write:U32 -> @+row:U32 -> @+in_row:U32 -> @+row_tiles:U32 -> @+first_column:U32 -> @+channel_base:U32 -> @+height:U32 -> @+width:U32 -> @+stride:U32 -> @+groups:U32 -> @+channels:U32 -> @read:Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> Rowing
def row_low source · line 158 · raw
@low:Bool -> @first:Bool -> @count:Nat -> @state:Rowing -> Rowing
A channel reads lane channel % 8 of the cells of its group; the lane is chosen once for the plane.
def row_high source · line 165 · raw
@low:Bool -> @first:Bool -> @count:Nat -> @state:Rowing -> Rowing
def row_lane source · line 172 · raw
@half:Bool -> @low:Bool -> @first:Bool -> @count:Nat -> @state:Rowing -> Rowing
def plane_done source · line 181 · raw
@+plane:U32 -> @+window:Stencil -> @+planes:Planes -> @done:Rowing -> Transposing
def plane_step source · line 185 · raw
@state:Transposing -> Transposing
def transposed source · line 197 · raw
@state:Transposing -> Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>)
def transpose source · line 202 · raw
@+window:Stencil -> @+planes:Planes -> @input:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>)
The planes of a call: the input comes back unchanged.
def shifted0 source · line 209 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
Lanes shift to shift + 7 of a pair.
def shifted1 source · line 213 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted2 source · line 219 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted3 source · line 225 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted4 source · line 231 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted5 source · line 237 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted6 source · line 243 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def shifted7 source · line 249 · raw
@pair:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def lane_mask source · line 257 · raw
@+lane:U32 -> @+index:U32 -> U32
Lanes from lane on take the pass's tile. A word select, so both tiles are read whole and every bit is kept.
def merged source · line 260 · raw
@+lane:U32 -> @kept:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8
def advanced source · line 275 · raw
@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+start:U32 -> @+read:U32 -> @+kernel_row:U32 -> @+write:U32 -> @+lane:U32 -> @+tap_rows:U32 -> @+tap_columns:U32 -> @+row_step:U32 -> Passing
def merge_stored source · line 290 · raw
@pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @+tile:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> @+start:U32 -> @+read:U32 -> @+kernel_row:U32 -> @+write:U32 -> @+lane:U32 -> @+tap_rows:U32 -> @+tap_columns:U32 -> @+row_step:U32 -> @old:Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> Passing
def pass_low source · line 309 · raw
@low:Bool -> @odd:Bool -> @first:Bool -> @count:Nat -> @state:Passing -> Passing
def pass_high source · line 316 · raw
@low:Bool -> @odd:Bool -> @first:Bool -> @count:Nat -> @state:Passing -> Passing
def pass_shift source · line 323 · raw
@half:Bool -> @low:Bool -> @odd:Bool -> @first:Bool -> @count:Nat -> @state:Passing -> Passing
def passed source · line 331 · raw
@state:Passing -> Arrays
def pass_step source · line 343 · raw
@state:Passes -> Passes
def passes_done source · line 356 · raw
@state:Passes -> Arrays
def kernel_column_step source · line 362 · raw
@+kernel_column:U32 -> @+window:Stencil -> @+planes:Planes -> @+position:U32 -> @+unit:U32 -> @arrays:Arrays -> Arrays
The unit at position: output row oy, column ox. Lane output_width - ox starts its second output row, every output_width lanes another.
def kernel_columns source · line 371 · raw
@remaining:Nat -> @+kernel_column:U32 -> @+window:Stencil -> @+planes:Planes -> @+position:U32 -> @+unit:U32 -> @arrays:Arrays -> Arrays
def units source · line 376 · raw
@remaining:Nat -> @+window:Stencil -> @+planes:Planes -> @+position:U32 -> @+unit:U32 -> @arrays:Arrays -> Arrays
def packed source · line 383 · raw
@arrays:Arrays -> Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>)
def pack source · line 389 · raw
@+window:Stencil -> @+planes:Planes -> @count:Nat -> @start:U32 -> @pairs:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16> -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8>)
count entries, inner per tile, of output positions from start, read from the planes of a range that holds them; tiles are written from zero.
Templates
template field_of source · line 25 · raw
@-Element:Data -> @-field:(@_:Element -> F32) -> @read:Pair(Array<Element>, Element) -> Pair(Array<Element>, F32)
template masked_field source · line 29 · raw
@-Element:Data -> @inside:Bool -> @pair:Pair(Array<Element>, F32) -> Pair(Array<Element>, F32)
template pixel source · line 35 · raw
@-Element:Data -> @-field:(@_:Element -> F32) -> @input_storage:Array<Element> -> @+input_row:U32 -> @+input_column:U32 -> @+channel_base:U32 -> @+input_height:U32 -> @+input_width:U32 -> @+step:U32 -> Pair(Array<Element>, F32)
The element of a channel at a pixel lies step elements a pixel from the element of the channel at pixel zero.
template read_block_pixel source · line 43 · raw
@-Element:Data -> @-field:(@_:Element -> F32) -> @input:Array<Element> -> @context:PixelBlock -> @index:Nat -> Pair(Array<Element>, F32)
template block source · line 48 · raw
@-Element:Data -> @-field:(@_:Element -> F32) -> @input:Array<Element> -> @row:U32 -> @column:U32 -> @channel_base:U32 -> @height:U32 -> @width:U32 -> @stride:U32 -> @next_row:U32 -> @offset:U32 -> @output_width:U32 -> @kernel_column:U32 -> @padding:U32 -> @step:U32 -> Pair(Array<Element>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8)
Eight lanes of one input row, stride columns apart.
template row_step source · line 138 · raw
@-lane:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> F32) -> @state:Rowing -> Rowing
template row_first source · line 148 · raw
@-lane:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> F32) -> @state:Rowing -> Rowing
template row_run source · line 153 · raw
@-lane:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> F32) -> @count:Nat -> @state:Rowing -> Rowing
template first_stored source · line 281 · raw
@-shift:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+start:U32 -> @+read:U32 -> @+kernel_row:U32 -> @+write:U32 -> @+lane:U32 -> @+tap_rows:U32 -> @+tap_columns:U32 -> @+row_step:U32 -> @pair_read:Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16) -> Passing
template first_step source · line 286 · raw
@-shift:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @state:Passing -> Passing
template merge_read source · line 295 · raw
@-shift:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @tiles:Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8> -> @+start:U32 -> @+read:U32 -> @+kernel_row:U32 -> @+write:U32 -> @+lane:U32 -> @+tap_rows:U32 -> @+tap_columns:U32 -> @+row_step:U32 -> @pair_read:Pair(Array<0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16>, 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16) -> Passing
template merge_step source · line 300 · raw
@-shift:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @state:Passing -> Passing
template pass_run source · line 304 · raw
@-shift:(@_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile16 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @first:Bool -> @count:Nat -> @state:Passing -> Passing