~/bend-docscommunity

tensor_f32.bend checks

raw source on the hub · import stelliferous@0.0.4.0/tensor_f32.bend as Tensor_f32

The everyday F32 tensor module: import this one module and call F.add, F.concat, F.check, ... without element-type arguments. A tensor is held in its tiled form: one axis blocked by eight, the lanes of one Tile8, the rest row-major. Values enter and leave as F32 at the boundary: construction, files, storage and the reads. Base determines operand order, rounding, NaN and signed-zero behavior.

33 imports
import Base
import ./default_machine_limits.bend as Default
import ./machine_limits.bend as Machine
import ./storage_buffer.bend as Buffers
import ./math_activation.bend as Activations
import ./math_fp32.bend as Arithmetic
import ./math_sum.bend as Sum
import ./math_largest.bend as Largest
import ./math_random.bend as Random
import ./math_activation_lanes.bend as ActivationLanes
import ./tensor_access.bend as Access
import ./math_compare.bend as Compare
import ./tensor.bend as Tensors
import ./tensor_shape.bend as Shapes
import ./tensor_select.bend as Select
import ./tensor_layout.bend as Layout
import ./tensor_tiled.bend as Tiled
import ./tensor_grid.bend as Grid
import ./tensor_tiled_map.bend as TiledMap
import ./tensor_tiled_layout.bend as TiledLayout
import ./tensor_tiled_concat.bend as TiledConcat
import ./tensor_tiled_pool.bend as TiledPool
import ./tensor_tiled_reduce.bend as TiledReduce
import ./tensor_tiled_broadcast.bend as TiledBroadcast
import ./tensor_tiled_depthwise.bend as TiledDepthwise
import ./kernel_tile.bend as Tile
import ./math_gelu_lanes.bend as GeluLanes
import ./math_choice.bend as Choice
import ./tensor_convolution.bend as TensorConvolution
import ./tensor_matrix_products.bend as TiledProducts
import ./tensor_file.bend as Files
import ./tensor_model.bend as Models
import ./tensor_checkpoint.bend as Checkpoints

Types

type Factors source · line 639 · raw

Data

The extents before the last two, and the last two.

Definitions

def Tensor source · line 41 · raw

Type

def Problem source · line 44 · raw

Data

def Storage source · line 48 · raw

Type

Storage exchanged with foreign I/O; see from_storage and into_storage.

def full source · line 53 · raw

@+shape:List<&2, U32> -> @+value:F32 -> Tensor

def zeros source · line 56 · raw

@+shape:List<&2, U32> -> Tensor

def ones source · line 59 · raw

@+shape:List<&2, U32> -> Tensor

def from_list source · line 62 · raw

@+shape:List<&2, U32> -> @+values:List<&2, F32> -> Tensor

def from_storage source · line 65 · raw

@+shape:List<&2, U32> -> @storage:Storage -> Tensor

def loaded source · line 68 · raw

@read:IO(0xa2af805348d03b11eb853850859654f6/tensor_file.Tensor) -> IO(Tensor)

def load_raw source · line 75 · raw

@+path:String -> @+shape:List<&2, U32> -> IO(Tensor)

Raw little-endian FP32 files: the values of the shape in row-major order. A file that cannot be read, or does not match the shape, gives a failed tensor.

def save_raw source · line 78 · raw

@+path:String -> @tensor:Tensor -> IO(Tensor)

def load_u8 source · line 84 · raw

@+path:String -> @+shape:List<&2, U32> -> IO(Tensor)

One byte per value in row-major order, each an FP32 from 0 to 255, such as the records of CIFAR-10. A file that cannot be read, or does not match the shape, gives a failed tensor.

def load_npy source · line 88 · raw

@+path:String -> IO(Tensor)

NumPy .npy files of FP32 values; the file carries the shape.

def save_npy source · line 91 · raw

@+path:String -> @tensor:Tensor -> IO(Tensor)

def Weights source · line 96 · raw

Type

Models: tensors by name, loaded once. In do Model<T>: a step takes a tensor from the weights with take, or puts a copy there with keep for a later take.

def Model source · line 99 · raw

@A:Type -> Type

def Model.pure source · line 102 · raw

@-A:Type -> @value:A -> Model(A)

def Model.bind source · line 105 · raw

@-A:Type -> @-B:Type -> @step:Model(A) -> @next:(@_:A -> Model(B)) -> Model(B)

def take source · line 108 · raw

@+name:String -> Model(Tensor)

def keep source · line 111 · raw

@+name:String -> @tensor:Tensor -> Model(Tensor)

def weight_names source · line 115 · raw

Model(List<&2, String>)

The names of the tensors in the weights, in their order; the weights stay.

def load_weights source · line 119 · raw

@+folder:String -> IO(Weights)

folder/names.txt lists one name per line; folder/<name>.npy holds its tensor.

def load_checkpoint source · line 126 · raw

@+path:String -> IO(Weights)

A PyTorch checkpoint, the ZIP form torch.save writes: one tensor per state-dict entry under its PyTorch name. FP16 and BFloat16 values widen exactly, integers round to the nearest FP32. A file that cannot be read gives weights whose every take reports why.

def copy_weights source · line 129 · raw

@weights:Weights -> Pair(Weights, Weights)

def run source · line 132 · raw

@-A:Type -> @model:Model(A) -> @weights:Weights -> A

def run_keeping source · line 136 · raw

@-A:Type -> @model:Model(A) -> @weights:Weights -> Pair(A, Weights)

The result with what remains of the weights, kept tensors included.

def save_weights source · line 139 · raw

@+folder:String -> @weights:Weights -> IO(Weights)

def with_workers source · line 144 · raw

@tensor:Tensor -> @+count:U32 -> Tensor

Execution context: operations may use count workers, like a tensor's device. Read the runtime's pool once with IO.thread_count(); results keep the count.

def workers source · line 147 · raw

@tensor:Tensor -> Pair(Tensor, U32)

def shape source · line 152 · raw

@tensor:Tensor -> Pair(Tensor, List<&2, U32>)

def check source · line 155 · raw

@tensor:Tensor -> Result<&1, &1, Pair(Tensor, Problem), Tensor>

def describe source · line 158 · raw

@problem:Problem -> String

def expected source · line 161 · raw

@result:Result<&1, &1, Pair(Tensor, Problem), Tensor> -> IO(Tensor)

def expect source · line 167 · raw

@tensor:Tensor -> IO(Tensor)

Stops the program with the recorded problem, for scripts and examples.

def to_list source · line 170 · raw

@tensor:Tensor -> Result<&2, &2, Problem, List<&2, F32>>

def item source · line 173 · raw

@tensor:Tensor -> Result<&2, &2, Problem, F32>

def to_list_or source · line 178 · raw

@tensor:Tensor -> @fallback:List<&2, F32> -> List<&2, F32>

Reads with a fallback for a failed tensor, for callers that do not inspect the problem.

def item_or source · line 181 · raw

@tensor:Tensor -> @fallback:F32 -> F32

def into_storage source · line 184 · raw

@tensor:Tensor -> Result<&2, &1, Problem, Storage>

def expect_storage source · line 187 · raw

@tensor:Tensor -> IO(Storage)

def read_storage source · line 191 · raw

@storage:Storage -> @+index:U32 -> Pair(Storage, F32)

The value at index of a storage and the storage back: 0.0 past its end.

def then source · line 198 · raw

@pair:Pair(Tensor, Tensor) -> @body:(@_:Tensor -> @_:Tensor -> Tensor) -> Tensor

def then_shape source · line 201 · raw

@pair:Pair(Tensor, List<&2, U32>) -> @body:(@_:Tensor -> @_:List<&2, U32> -> Tensor) -> Tensor

def copy source · line 204 · raw

@tensor:Tensor -> Pair(Tensor, Tensor)

def add source · line 230 · raw

@left:Tensor -> @right:Tensor -> Tensor

def sub source · line 233 · raw

@left:Tensor -> @right:Tensor -> Tensor

def mul source · line 236 · raw

@left:Tensor -> @right:Tensor -> Tensor

def div source · line 240 · raw

@left:Tensor -> @right:Tensor -> Tensor

Base division: a zero divisor gives an infinity or NaN, never a failure.

def maximum source · line 243 · raw

@left:Tensor -> @right:Tensor -> Tensor

def minimum source · line 246 · raw

@left:Tensor -> @right:Tensor -> Tensor

def add_scalar source · line 264 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def sub_scalar source · line 267 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def mul_scalar source · line 270 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def div_scalar source · line 273 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def less source · line 276 · raw

@left:Tensor -> @right:Tensor -> Tensor

def less_equal source · line 279 · raw

@left:Tensor -> @right:Tensor -> Tensor

def greater source · line 282 · raw

@left:Tensor -> @right:Tensor -> Tensor

def greater_equal source · line 285 · raw

@left:Tensor -> @right:Tensor -> Tensor

def equal source · line 288 · raw

@left:Tensor -> @right:Tensor -> Tensor

def not_equal source · line 291 · raw

@left:Tensor -> @right:Tensor -> Tensor

def less_scalar source · line 297 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

Scalar comparisons share the eight-lane map and preserve the tensor layout. Costs count AVX2 arithmetic, comparison, selection and value-bit instructions in one eight-element round, divided by eight; moves and addressing are excluded.

def less_equal_scalar source · line 300 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def greater_scalar source · line 303 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def greater_equal_scalar source · line 306 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def equal_scalar source · line 309 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def not_equal_scalar source · line 312 · raw

@tensor:Tensor -> @+value:F32 -> Tensor

def select source · line 315 · raw

@mask:Tensor -> @yes:Tensor -> @no:Tensor -> Tensor

def clamp source · line 318 · raw

@tensor:Tensor -> @+low:F32 -> @+high:F32 -> Tensor

def activated source · line 330 · raw

@tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

def activate source · line 346 · raw

@tensor:Tensor -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Tensor

def relu source · line 352 · raw

@tensor:Tensor -> Tensor

def relu6 source · line 355 · raw

@tensor:Tensor -> Tensor

def leaky_relu source · line 358 · raw

@tensor:Tensor -> @slope:F32 -> Tensor

def sigmoid source · line 361 · raw

@tensor:Tensor -> Tensor

def silu source · line 364 · raw

@tensor:Tensor -> Tensor

def tanh source · line 367 · raw

@tensor:Tensor -> Tensor

def hard_sigmoid source · line 370 · raw

@tensor:Tensor -> Tensor

def hard_swish source · line 373 · raw

@tensor:Tensor -> Tensor

def gelu_tanh source · line 377 · raw

@tensor:Tensor -> Tensor

PyTorch's gelu(approximate='tanh').

def gelu source · line 381 · raw

@tensor:Tensor -> Tensor

PyTorch's gelu with approximate='none'.

def activate_derivative source · line 385 · raw

@tensor:Tensor -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Tensor

The derivative of an activation at every element, by its own arithmetic.

def sigmoid_derivative source · line 400 · raw

@tensor:Tensor -> Tensor

def tanh_derivative source · line 403 · raw

@tensor:Tensor -> Tensor

def silu_derivative source · line 406 · raw

@tensor:Tensor -> Tensor

def gelu_tanh_derivative source · line 409 · raw

@tensor:Tensor -> Tensor

def gelu_derivative source · line 412 · raw

@tensor:Tensor -> Tensor

def activated_pair source · line 415 · raw

@+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @pair:Pair(Tensor, Tensor) -> Pair(Tensor, Tensor)

def activate_forward source · line 420 · raw

@tensor:Tensor -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Pair(Tensor, Tensor)

activate beside its input, which activate_backward reads: (output, input).

def backward_when source · line 423 · raw

@same:Bool -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @gradient:Tensor -> @input:Tensor -> Tensor

def backward_shaped source · line 428 · raw

@+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> @gradient:Pair(Tensor, List<&2, U32>) -> @input:Pair(Tensor, List<&2, U32>) -> Tensor

def activate_backward source · line 435 · raw

@gradient:Tensor -> @input:Tensor -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Tensor

The gradient before an activation from the gradient after it and the activation's input of the same shape: gradient * activation'(input).

def conv2d source · line 440 · raw

@input:Tensor -> @weights:Tensor -> @bias:Tensor -> @stride:U32 -> @padding:U32 -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Tensor

Ordered convolution over CHW or NCHW; the activation runs on each finished leaf while it is in cache.

def depthwise_conv2d source · line 447 · raw

@input:Tensor -> @weights:Tensor -> @bias:Tensor -> @stride:U32 -> @padding:U32 -> @+activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Tensor

Every channel of an input of shape [N,]C,H,W convolves with its own weights of shape 1,K,K (weights of shape C,1,K,K), adds its own bias (bias of shape C) and goes through the activation, as conv2d of that channel alone does. A Custom activation fails.

def arange source · line 466 · raw

@+start:F32 -> @+count:U32 -> Tensor

start, start + 1, ... as a rank-1 tensor of count elements.

def random_uniform source · line 473 · raw

@+shape:List<&2, U32> -> @+seed:U32 -> @+stream:U32 -> Tensor

Random values by counter: element i depends only on the seed, the stream and i, in row-major order, so results do not depend on the worker count. Use one stream per purpose or step. Twenty rounds of five operations and twelve key additions make 112 a word, counted by eight lanes.

def random_below source · line 479 · raw

@+shape:List<&2, U32> -> @+bound:U32 -> @+seed:U32 -> @+stream:U32 -> Tensor

Whole numbers below the bound as FP32 values, by the top of the product of the word and the bound. The bound is at most 2^24 for exact values.

def sum_axes source · line 490 · raw

@tensor:Tensor -> @+axes:List<&2, U32> -> Tensor

Reductions over listed axes remove those axes; the reductions of all elements return a rank-0 tensor, so failures propagate like any result. A sum adds in the order of tensor_partials.bend: every row of the last axis folds with the sum of math_sum.bend (eight lanes of TwoSum and a fixed merge tree), and the rows merge in one tree over the reduced axes. The maximum and the minimum take the elements of the reduced axes in row-major order, from -inf and +inf. An axis is listed once.

def max_axes source · line 493 · raw

@tensor:Tensor -> @+axes:List<&2, U32> -> Tensor

def min_axes source · line 496 · raw

@tensor:Tensor -> @+axes:List<&2, U32> -> Tensor

def mean_axes source · line 500 · raw

@tensor:Tensor -> @+axes:List<&2, U32> -> Tensor

sum_axes divided by the number of elements it adds; no element gives NaN.

def argmax source · line 508 · raw

@tensor:Tensor -> @+axis:U32 -> Tensor

The place along the axis of the first largest element, as an FP32; a NaN counts as the largest. The axis is removed.

def sum source · line 511 · raw

@tensor:Tensor -> Tensor

def max source · line 514 · raw

@tensor:Tensor -> Tensor

def min source · line 517 · raw

@tensor:Tensor -> Tensor

def mean source · line 521 · raw

@tensor:Tensor -> Tensor

sum divided by the number of elements; an empty tensor gives NaN.

def reshape source · line 529 · raw

@tensor:Tensor -> @+shape:List<&2, U32> -> Tensor

def transpose source · line 533 · raw

@tensor:Tensor -> @order:List<&2, U32> -> Tensor

The result's axis i is the argument's axis order[i].

def flip source · line 537 · raw

@tensor:Tensor -> @axes:List<&2, U32> -> Tensor

The elements in reverse order along every listed axis.

def slice source · line 541 · raw

@tensor:Tensor -> @axis:U32 -> @start:U32 -> @count:U32 -> @step:U32 -> Tensor

count elements from start along axis, every step-th one.

def set_slice source · line 545 · raw

@target:Tensor -> @axis:U32 -> @start:U32 -> @part:Tensor -> Tensor

target with part written at start along axis.

def Parts source · line 548 · raw

Type

def single source · line 552 · raw

@tensor:Tensor -> Parts

Build the parts of concat: F.cons(a, F.cons(b, F.single(c))).

def cons source · line 555 · raw

@tensor:Tensor -> @rest:Parts -> Parts

def concat source · line 558 · raw

@parts:Parts -> @+axis:U32 -> Tensor

def upsample_nearest source · line 562 · raw

@tensor:Tensor -> @+scale:U32 -> Tensor

Repeats each element of the last two axes scale times in each direction.

def max_pool2d_with source · line 566 · raw

@tensor:Tensor -> @+kernel:U32 -> @+stride:U32 -> @+padding:U32 -> Tensor

Over the last two axes; positions outside the input count as -inf.

def max_pool2d source · line 570 · raw

@tensor:Tensor -> @+kernel:U32 -> Tensor

Windows of kernel by kernel that do not overlap: stride kernel, padding 0.

def broadcast_to source · line 577 · raw

@tensor:Tensor -> @+shape:List<&2, U32> -> Tensor

The tensor repeated to shape under NumPy broadcasting; add, sub, mul, max and min broadcast their operands in the same way.

def exp source · line 581 · raw

@tensor:Tensor -> Tensor

Elementwise functions share the tiled map of the activations.

def log source · line 584 · raw

@tensor:Tensor -> Tensor

def sqrt source · line 588 · raw

@tensor:Tensor -> Tensor

One square-root instruction per eight lanes.

def exp_centered source · line 593 · raw

@value:F32 -> @maximum:F32 -> F32

def softmax_maximum source · line 596 · raw

@maximum:F32 -> @value:F32 -> F32

def softmax_exponentials source · line 600 · raw

@+axis:U32 -> @+unit:List<&2, U32> -> @pair:Pair(Tensor, Tensor) -> Tensor

The exponentials of the values less the maximum of their line.

def softmax_divided source · line 605 · raw

@+axis:U32 -> @+unit:List<&2, U32> -> @pair:Pair(Tensor, Tensor) -> Tensor

The exponentials divided by the sum of their line.

def softmax_lines source · line 609 · raw

@+axis:U32 -> @+shape:List<&2, U32> -> @tensor:Tensor -> Tensor

def softmax_valid source · line 613 · raw

@valid:Bool -> @empty:Bool -> @+shape:List<&2, U32> -> @+axis:U32 -> @tensor:Tensor -> Tensor

def softmax source · line 622 · raw

@tensor:Tensor -> @+axis:U32 -> Tensor

Along the axis, every line of values folds twice and maps once: the maximum from -inf, then the sum of math_sum.bend of the exponentials of the values less the maximum, then each such exponential divided by the sum.

def pad source · line 629 · raw

@tensor:Tensor -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> @+value:F32 -> Tensor

before[i] new elements in front of axis i and after[i] behind it, all equal to value.

def pad_edge source · line 633 · raw

@tensor:Tensor -> @+before:List<&2, U32> -> @+after:List<&2, U32> -> Tensor

The same, each new element repeating the nearest element of the tensor.

def factors_extended source · line 642 · raw

@+extent:U32 -> @found:Maybe<&2, Factors> -> Maybe<&2, Factors>

def factors source · line 647 · raw

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

def products source · line 657 · raw

@left:Tensor -> @right:Tensor -> @bias:Tensor -> @+count:U32 -> @+rows:U32 -> @+inner:U32 -> @+outputs:U32 -> @+workers:U32 -> @+right_axis:Nat -> Tensor

left [count,rows,inner], right with its outputs at right_axis and bias [outputs]: the products [count,rows,outputs] of each image, each output adding them from +0.0 and then its bias.

def products_shared source · line 661 · raw

@left:Tensor -> @right:Tensor -> @bias:Tensor -> @+count:U32 -> @+rows:U32 -> @+inner:U32 -> @+outputs:U32 -> @+workers:U32 -> Tensor

One right for all of left: its matrices are the rows of one matrix.

def matmul_inner source · line 666 · raw

@valid:Bool -> @left:Tensor -> @right:Tensor -> @+images:U32 -> @+image_rows:U32 -> @+leading:List<&2, U32> -> @+rows:U32 -> @+inner:U32 -> @+outputs:U32 -> @+workers:U32 -> Tensor

images of image_rows rows each: one image of all rows when one right is shared.

def matmul_found source · line 673 · raw

@left_factors:Maybe<&2, Factors> -> @right_factors:Maybe<&2, Factors> -> @+workers:U32 -> @+limits:0xa2af805348d03b11eb853850859654f6/machine_limits.Limits -> @left:Tensor -> @right:Tensor -> Tensor

def matmul_status source · line 684 · raw

@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+left_shape:List<&2, U32> -> @+right_shape:List<&2, U32> -> @+workers:U32 -> @left:Tensor -> @right:Tensor -> Tensor

def matmul source · line 692 · raw

@left:Tensor -> @right:Tensor -> Tensor

left [...,m,k] and right [...,k,n], with the same axes in front or none on the right: at each row i and column j, the products left[i,k] * right[k,j] added in increasing k from +0.0, as a convolution adds them.

def linear_shaped source · line 697 · raw

@valid:Bool -> @x:Tensor -> @weight:Tensor -> @bias:Tensor -> @+leading:List<&2, U32> -> @+rows:U32 -> @+inputs:U32 -> @+outputs:U32 -> @+workers:U32 -> Tensor

def linear_found source · line 703 · raw

@found:Maybe<&2, Factors> -> @+inputs:U32 -> @+outputs:U32 -> @+bias_shape:List<&2, U32> -> @+workers:U32 -> @+limits:0xa2af805348d03b11eb853850859654f6/machine_limits.Limits -> @x:Tensor -> @weight:Tensor -> @bias:Tensor -> Tensor

def linear_weight source · line 710 · raw

@+weight_shape:List<&2, U32> -> @+shape:List<&2, U32> -> @+bias_shape:List<&2, U32> -> @+workers:U32 -> @x:Tensor -> @weight:Tensor -> @bias:Tensor -> Tensor

def linear_status source · line 715 · raw

@status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+weight_shape:List<&2, U32> -> @+shape:List<&2, U32> -> @+bias_shape:List<&2, U32> -> @+workers:U32 -> @x:Tensor -> @weight:Tensor -> @bias:Tensor -> Tensor

def linear source · line 723 · raw

@x:Tensor -> @weight:Tensor -> @bias:Tensor -> Tensor

x [...,rows,inputs], weight [outputs,inputs] and bias [outputs], as PyTorch stores them: x weight^T + bias, each output adding its products in increasing input from +0.0 and then the bias.

Templates

template binary_usable source · line 212 · raw

@-operation:(@_:F32 -> @_:F32 -> F32) -> @name:String -> @operations:F32 -> @same:Bool -> @+ls:List<&2, U32> -> @+rs:List<&2, U32> -> @left:Tensor -> @right:Tensor -> Tensor

Binary elementwise operations reuse the left tensor's storage. The number after the name is the operation's scalar work for the band schedule. Operands of one shape combine cell by cell, with the lanes of the right on the axis of the left; operands of other extents broadcast on the cells (TiledBroadcast).

template binary_status source · line 218 · raw

@-operation:(@_:F32 -> @_:F32 -> F32) -> @name:String -> @operations:F32 -> @status:0xa2af805348d03b11eb853850859654f6/tensor.Status -> @+ls:List<&2, U32> -> @+rs:List<&2, U32> -> @+workers:U32 -> @left:Tensor -> @right:Tensor -> Tensor

A failed operand fails the call and keeps the left tensor.

template binary source · line 225 · raw

@-operation:(@_:F32 -> @_:F32 -> F32) -> @name:String -> @operations:F32 -> @left:Tensor -> @right:Tensor -> Tensor

operation(left element, right element); operations counts its scalar work.

template tiled_map source · line 251 · raw

@-Context:Data -> @-transform:(@_:Context -> @_:0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8 -> 0xa2af805348d03b11eb853850859654f6/kernel_tile.Tile8) -> @context:Context -> @operations:F32 -> @tensor:Tensor -> Tensor

Elementwise functions of one tensor run on its tiled form. The number is the scalar work of one value for the band schedule.

template tiled_lanes source · line 254 · raw

@-operation:(@_:F32 -> F32) -> @operations:F32 -> @tensor:Tensor -> Tensor

template scalar_value source · line 258 · raw

@-operation:(@_:F32 -> @_:F32 -> F32) -> @value:F32 -> @element:F32 -> F32

The operation of an element and the value.

template tiled_scalar source · line 261 · raw

@-operation:(@_:F32 -> @_:F32 -> F32) -> @operations:F32 -> @tensor:Tensor -> @value:F32 -> Tensor

template lanes_of source · line 327 · raw

@-operation:(@_:F32 -> F32) -> @operations:F32 -> @tiled:0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled -> 0xa2af805348d03b11eb853850859654f6/tensor_tiled.Tiled

Activations: Act.silu() and the other values of lib/math_activation.bend carry their own planner cost. activated applies one to a tiled form, lane by lane: Identity leaves the cells as they are, and Custom, which carries only a cost, reaches no caller of it. activate applies one to a tensor; relu, silu, ... below are its shorthands. The function of Custom reaches conv2d_custom or apply, and activate fails on it.

template conv2d_custom source · line 453 · raw

@-activation:(@_:F32 -> F32) -> @operations:F32 -> @input:Tensor -> @weights:Tensor -> @bias:Tensor -> @stride:U32 -> @padding:U32 -> Tensor

conv2d with a custom activation of the given scalar operations per element.

template apply source · line 458 · raw

@-operation:(@_:F32 -> F32) -> @operations:F32 -> @tensor:Tensor -> Tensor

Custom elementwise functions are passed as direct templates, never records, with their scalar operations per element.

template apply_indexed source · line 462 · raw

@-operation:(@_:U32 -> @_:F32 -> F32) -> @operations:F32 -> @tensor:Tensor -> Tensor

The function also receives the element's row-major index.