ops

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ops has the base implementation for most operations for the Go backend.

It works by registration, so it simply needs to be imported to be made available.

Index

Constants

View Source
const MaxArgMinMaxReductionSize = 0x8000_0000

Variables

View Source
var ConvertDTypePairMap = gobackend.NewDTypePairMap("ConvertDType")
View Source
var TransposeDTypeMap = gobackend.NewDTypeMap("Transpose")

TransposeDTypeMap is used to dispatch Transpose to type-specific implementations. gobackend:dtypemap execTransposeGeneric ints,uints,floats,half,bool

Functions

func Abs

func Abs(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Abs implements the compute.Builder interface.

func Add

func Add(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Add implements the compute.Builder interface.

func ArgMinMax

func ArgMinMax(f *gobackend.Function,
	operandOp compute.Value,
	axis int,
	outputDType dtypes.DType,
	isMin bool,
) (compute.Value, error)

ArgMinMax calculates the "argmin" or "argmax" across an axis of the given input array x. outputDType defines the output of the argmin/argmax, it doesn't need to be the same as the input. It's a form of reduction on the given axis, and that axis goes away. So the rank of the result is one less than the rank of x. Examples:

ArgMinMax(x={{2, 0, 7}, {-3, 4, 2}}, axis=1, isMin=true) -> {1, 0}  // (it chooses the 0 and the -3)
ArgMinMax(x={{2, 0, 7}, {-3, 4, 2}}, axis=0, isMin=false) -> {0, 1, 0} // (it choose the 2, 4 and 7)

func Atan2

func Atan2(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Atan2 implements the compute.Builder interface.

func BitCount

func BitCount(f *gobackend.Function, operand compute.Value) (compute.Value, error)

BitCount implements the compute.Builder interface.

func Bitcast

func Bitcast(f *gobackend.Function, operandOp compute.Value, targetDType dtypes.DType) (compute.Value, error)

Bitcast performs an elementwise bitcast operation from a dtype to another dtype.

The Bitcast doesn't "convert", rather it just reinterprets the bits from operand.DType() to the targetDType.

If the element sizes (in bytes/bits) differ, the last dimension is adjusted:

  • Smaller target: a new trailing axis of size (srcBits / dstBits) is appended, so rank is increased by 1.
  • Larger target: the last axis must be equal to (dstBits / srcBits), and the resultign rank is decreased by 1 ("squeezed").

E.g:

Bitcast([1]uint32{0xdeadbeef}, dtypes.UInt16) -> [1][2]uint16{{0xbeef, 0xdead}} // Little-endian encoding.
Bitcast([1][2]uint16{{0xbeef, 0xdead}}, dtypes.UInt32) -> [1]uint32{0xdeadbeef}

func BitwiseAnd

func BitwiseAnd(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

BitwiseAnd implements the compute.Builder interface.

func BitwiseNot

func BitwiseNot(f *gobackend.Function, operand compute.Value) (compute.Value, error)

BitwiseNot implements the compute.Builder interface.

func BitwiseOr

func BitwiseOr(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

BitwiseOr implements the compute.Builder interface.

func BitwiseXor

func BitwiseXor(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

BitwiseXor implements the compute.Builder interface.

func BroadcastInDim

func BroadcastInDim(
	f *gobackend.Function,
	operandValue compute.Value,
	outputShape shapes.Shape,
	broadcastAxes []int,
) (compute.Value, error)

BroadcastInDim broadcasts x to an output with the given shape.

  • outputShape will be the new shape after x is broadcast.
  • broadcastAxes maps x-axes to the corresponding outputShape axes (len(broadcastAxes) == x.Shape.Rank()), the i-th axis of x is mapped to the broadcastAxes[i]-th dimension of the output. broadcastAxes must be also increasing: this operation cannot be used to transpose axes, it will only broadcast and introduce new axes in-between. -

This also requires that the i-th input axis is either 1 or is the same as the output dimension it's broadcasting into. For example, say operand `x = (s32)[2]{1, 2}`; outputShape = `(s32)[2,2]`:

  • Specifying []int{1} as broadcastAxes will generate output {{1, 2}, {1, 2}}
  • On the other hand, specifying []int{0} as broadcastAxes will generate output {{1 , 1}, {2 , 2}}

func Call

func Call(f *gobackend.Function, target compute.Function, inputs ...compute.Value) ([]compute.Value, error)

func Ceil

func Ceil(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Ceil implements the compute.Builder interface.

func Clamp

func Clamp(f *gobackend.Function, minV, x, maxV compute.Value) (compute.Value, error)

Clamp returns the element-wise clamping operation.

The values max and min can either be a scalar or have the same shape as x.

func Clz

func Clz(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Clz implements the compute.Builder interface.

func Concatenate

func Concatenate(f *gobackend.Function, axis int, operandOps ...compute.Value) (compute.Value, error)

Concatenate joins a sequence of tensors along the given axis (it must exist already). All input tensors must have the same shape, except potentially in the concatenation dimension. They must also have the same data type (DType). It returns an error if inputs are invalid (e.g., no inputs, mismatched graphs, shapes, dtypes, or invalid dimension).

func ConvGeneral

func ConvGeneral(f *gobackend.Function, inputOp, kernelOp compute.Value, axes compute.ConvolveAxesConfig,
	strides []int, paddings [][2]int,
	inputDilations, kernelDilations []int,
	channelGroupCount, batchGroupCount int) (compute.Value, error)

ConvGeneral is a generic Convolution operation with support for:

- Arbitrary number of spatial axes. - Arbitrary transposition of axes. - Strides and padding. - Dilations of the input. - Dilations of the kernel, aka. atrous convolution. - Feature grouping (on the input channels). - Batch grouping.

Some details in https://www.tensorflow.org/xla/operation_semantics#convwithgeneralpadding_convolution. There operand and filter are called lhs and rhs. (XLA documentation is unfortunately poor, much is guess-work). Also useful, https://arxiv.org/pdf/1603.07285v1.pdf.

Note: input is aka. operand; kernel is aka. "filters". The input and output "channels" are also known as "features dimensions".

func ConvertDType

func ConvertDType(f *gobackend.Function, operandOp compute.Value, dtype dtypes.DType) (compute.Value, error)

func Cos

func Cos(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Cos implements the compute.Builder interface.

func CumMax added in v0.1.19

func CumMax(f *gobackend.Function, operandValue compute.Value, axis int, options compute.CumSumOptions) (compute.Value, error)

CumMax returns the cumulative maximum of the elements along the given axis.

func CumSum added in v0.1.5

func CumSum(f *gobackend.Function, operandValue compute.Value, axis int, options compute.CumSumOptions) (compute.Value, error)

CumSum returns the cumulative sum of the elements along the given axis.

func Div

func Div(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Div implements the compute.Builder interface.

func DynamicBroadcastInDim added in v0.1.5

func DynamicBroadcastInDim(
	f *gobackend.Function,
	operandValue compute.Value,
	broadcastAxes []int,
	specs ...compute.DynamicDimensionSpec,
) (compute.Value, error)

DynamicBroadcastInDim broadcasts operand to target dimensions specified by specs.

func DynamicDimensionSize

func DynamicDimensionSize(f *gobackend.Function, operandValue compute.Value, axis int) (compute.Value, error)

DynamicDimensionSize returns the size of the given dimension of x as a scalar Node.

func DynamicIota added in v0.1.5

func DynamicIota(f *gobackend.Function, dtype dtypes.DType, iotaAxis int, specs ...compute.DynamicDimensionSpec) (compute.Value, error)

DynamicIota creates a tensor with the given dynamic dimensions and dtype, filled with increasing numbers (starting from 0) along the specified iotaAxis.

func DynamicPad added in v0.1.5

func DynamicPad(f *gobackend.Function, operandOp, fillValueOp compute.Value, axesConfig ...compute.DynamicPadAxis) (compute.Value, error)

DynamicPad implements the compute.DynamicOps interface.

func DynamicReshape added in v0.1.1

func DynamicReshape(f *gobackend.Function, operandValue compute.Value, specs ...compute.DynamicDimensionSpec) (compute.Value, error)

DynamicReshape reshapes the operand to target dimensions specified by specs.

func DynamicShape

func DynamicShape(f *gobackend.Function, operandValue compute.Value) (compute.Value, error)

DynamicShape returns the shape of x as a 1D tensor.

func DynamicUpdateSlice added in v0.1.11

func DynamicUpdateSlice(f *gobackend.Function, operandOp, updateOp compute.Value, startIndicesOps []compute.Value) (compute.Value, error)

DynamicUpdateSlice implements compute.Function.

func Equal

func Equal(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Equal implements the compute.Builder interface.

func Erf

func Erf(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Erf implements the compute.Builder interface.

func ExecConvGeneral added in v0.1.26

func ExecConvGeneral(backend *gobackend.Backend, node *gobackend.Node, inputs []*gobackend.Buffer, _ []bool) (*gobackend.Buffer, error)

ExecConvGeneral executes the generic ConvGeneral operation without architecture-specific SIMD.

func ExecuteTranspose added in v0.1.11

func ExecuteTranspose(backend *gobackend.Backend, operand, output *gobackend.Buffer, permutations []int)

ExecuteTranspose transposes operand into output given permutations, using fast paths if available.

func Exp

func Exp(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Exp implements the compute.Builder interface.

func Expm1

func Expm1(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Expm1 implements the compute.Builder interface. It returns e(x)-1.

func ExtractPatches2DFloat32 added in v0.1.24

func ExtractPatches2DFloat32(p *Conv2DParams, input, patchBuf []float32, mStart, mCount int)

ExtractPatches2DFloat32 extracts `mCount` output pixel patches starting at flat pixel index `mStart` into `patchBuf` of shape `[mCount, K]` where `K = p.KernelH * p.KernelW * p.InChannels`.

func Floor

func Floor(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Floor implements the compute.Builder interface.

func Gather

func Gather(
	f *gobackend.Function,
	operandValue, startIndicesValue compute.Value,
	indexVectorAxis int,
	offsetOutputAxes, collapsedSliceAxes, startIndexMap, sliceSizes []int,
	indicesAreSorted bool,
) (compute.Value, error)

Gather implements the compute.Builder. It's a complex operation, fully described in the compute.Builder.Gather documentation.

func GetBroadcastConfig added in v0.1.9

func GetBroadcastConfig(node *gobackend.Node, lhs, rhs, output *gobackend.Buffer) gobackend.BroadcastConfig

GetBroadcastConfig returns the BroadcastConfig for the binary node, either from its cached Data or computed dynamically.

func GetScratchFloat32 added in v0.1.26

func GetScratchFloat32(backend *gobackend.Backend, size int) (*gobackend.Buffer, []float32, error)

GetScratchFloat32 allocates a temporary float32 buffer of the given size from the backend pool.

func GreaterOrEqual

func GreaterOrEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

GreaterOrEqual implements the compute.Builder interface.

func GreaterThan

func GreaterThan(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

GreaterThan implements the compute.Builder interface.

func Identity

func Identity(f *gobackend.Function, operandOp compute.Value) (compute.Value, error)

Identity implements the compute.Identity interface. This operation is not de-duplicated: if you issue it twice, it will not reuse the previous instance.

func If

func If(f *gobackend.Function, pred compute.Value, trueBranch, falseBranch compute.Function) ([]compute.Value, error)

func Iota

func Iota(f *gobackend.Function, shape shapes.Shape, iotaAxis int) (compute.Value, error)

Iota creates a constant of the given shape with increasing numbers (starting from 0) on the given axis. So Iota([2,2], 1) returns [[0 1][0 1]], while Iota([2,2], 0) returns [[0 0][1 1]].

func IsFinite

func IsFinite(f *gobackend.Function, operandOp compute.Value) (compute.Value, error)

IsFinite implements the compute.Builder interface.

func IsNaN

IsNaN implements compute.Builder interface. Notice there is no executor because it uses f.NotEqual instead.

func LessOrEqual

func LessOrEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

LessOrEqual implements the compute.Builder interface.

func LessThan

func LessThan(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

LessThan implements the compute.Builder interface.

func Log

func Log(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Log implements the compute.Builder interface.

func Log1p

func Log1p(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Log1p implements the compute.Builder interface.

func LogicalAnd

func LogicalAnd(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

LogicalAnd implements the compute.Builder interface.

func LogicalNot

func LogicalNot(f *gobackend.Function, operand compute.Value) (compute.Value, error)

LogicalNot implements the compute.Builder interface.

func LogicalOr

func LogicalOr(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

LogicalOr implements the compute.Builder interface.

func LogicalXor

func LogicalXor(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

LogicalXor implements the compute.Builder interface.

func Logistic

func Logistic(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Logistic implements the compute.Builder interface. Aka as sigmoid. It returns 1/(1+exp(-x)).

func Max

func Max(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Max implements the compute.Builder interface.

func Min

func Min(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Min implements the compute.Builder interface.

func Mul

func Mul(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Mul implements the compute.Builder interface.

func Neg

func Neg(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Neg implements the compute.Builder interface.

func NotEqual

func NotEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

NotEqual implements the compute.Builder interface.

func OptimizationBarrier

func OptimizationBarrier(f *gobackend.Function, operands ...compute.Value) ([]compute.Value, error)

OptimizationBarrier implements the compute.OptimizationBarrier interface. This operation is not de-duplicated: if you issue it twice, it will not reuse the previous instance.

func PackConvKernelFloat32 added in v0.1.24

func PackConvKernelFloat32(p *Conv2DParams, kernel, packedRHS []float32, panelCols int)

PackConvKernelFloat32 packs the convolution kernel into panels of width `panelCols`: shape `[numPanels, K, panelCols]` where `numPanels = (OutChannels + panelCols - 1) / panelCols` and `K = KernelH * KernelW * InChannels`. Handles both standard layout `[kH, kW, InChannels, OutChannels]` and transposed channel layout `[kH, kW, OutChannels, InChannels]` (used in VJP wrt Input).

func Pad

func Pad(f *gobackend.Function, operandOp, fillValueOp compute.Value, axesConfig ...compute.PadAxis) (compute.Value, error)

Pad implements the compute.Builder interface.

func Pow

func Pow(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Pow implements the compute.Builder interface.

func RNGBitGenerator

func RNGBitGenerator(f *gobackend.Function, stateOp compute.Value, shape shapes.Shape) (newState, values compute.Value, err error)

RNGBitGenerator generates the given shape filled with random bits. It takes as input the current random number generator (RNG) state, see RNGState or RNGStateFromSeed. The algorithm is hard-coded to use Philox algorithm for now.

It returns the new state of the RNG and the generated values (with random bits) with the given shape.

func ReduceBitwiseAnd

func ReduceBitwiseAnd(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceBitwiseAnd reduces the operand by taking the bitwise AND of values along the given axes.

func ReduceBitwiseOr

func ReduceBitwiseOr(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceBitwiseOr reduces the operand by taking the bitwise OR of values along the given axes.

func ReduceBitwiseXor

func ReduceBitwiseXor(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceBitwiseXor reduces the operand by taking the bitwise XOR of values along the given axes.

func ReduceLogicalAnd

func ReduceLogicalAnd(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceLogicalAnd reduces the operand by taking the logical AND of values along the given axes.

func ReduceLogicalOr

func ReduceLogicalOr(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceLogicalOr reduces the operand by taking the logical OR of values along the given axes.

func ReduceLogicalXor

func ReduceLogicalXor(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceLogicalXor reduces the operand by taking the logical XOR of values along the given axes.

func ReduceMax

func ReduceMax(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceMax reduces the operand by taking the maximum value along the given axes.

func ReduceMin

func ReduceMin(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceMin reduces the operand by taking the minimum value along the given axes.

func ReduceProduct

func ReduceProduct(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceProduct reduces the operand by taking the product of values along the given axes.

func ReduceSum

func ReduceSum(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)

ReduceSum reduces the operand by taking the sum of values along the given axes.

func ReduceWindow

func ReduceWindow(f *gobackend.Function,
	operandOp compute.Value,
	reductionType compute.ReduceOpType,
	windowDimensions, strides, inputDilations, windowDilations []int,
	paddings [][2]int,
) (compute.Value, error)

ReduceWindow runs a reduction function of the type given by reductionType, it can be either ReduceMaxNode, ReduceSumNode, or ReduceMultiplyNode.

  • reductionType: the type of reduction to perform. E.g.: [ReduceOpMax], [ReduceOpSum],...
  • windowDimensions: the dimensions of the window, must be defined for each axis.
  • strides: stride over elements in each axis for each window reduction. If nil, it's assume to be the same as the windowDimensions -- that is, the strides jump a window at a time.
  • inputDilations: "virtually" expand the input by introducing "holes" between elements. I.e. if inputDilations are 2, then the input is expanded by inserting `2-1` copies of `0` (or whatever is the reduciton "zero" value) between the elements in each dimension. If nil, it's assumed to be 1 (no dilation) for each axis. Values must be >= 1.
  • windowDilations: "virtually" expand the window by inserting `2-1` copies of `0` between the elements in each dimension. If nil, it's assumed to be 1 (no dilation) for each axis. Values must be >= 1.
  • paddings: virtual padding to be added to the input at the edges (start and end) of each axis. If nil, it's assumed to be 0 for each axis.

func Rem

func Rem(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Rem implements the compute.Builder interface.

func Reshape

func Reshape(f *gobackend.Function, operandValue compute.Value, dims ...int) (compute.Value, error)

Reshape reshapes the operand to the given dimensions.

func Reverse

func Reverse(f *gobackend.Function, operandValue compute.Value, axes ...int) (compute.Value, error)

Reverse returns x with the values for the given dimensions reversed, that is, the value indexed at `i` will be swapped with the value at indexed `(dimension_size - 1 - i)`. The shape remains the same.

func Round

func Round(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Round implements the compute.Builder interface.

func Rsqrt

func Rsqrt(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Rsqrt implements the compute.Builder interface.

func ScatterMax

func ScatterMax(f *gobackend.Function,
	operandOp, scatterIndicesOp, updatesOp compute.Value,
	indexVectorAxis int,
	updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int,
	indicesAreSorted, uniqueIndices bool,
) (compute.Value, error)

func ScatterMin

func ScatterMin(f *gobackend.Function,
	operandOp, scatterIndicesOp, updatesOp compute.Value,
	indexVectorAxis int,
	updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int,
	indicesAreSorted, uniqueIndices bool,
) (compute.Value, error)

func ScatterSum

func ScatterSum(f *gobackend.Function,
	operandOp, scatterIndicesOp, updatesOp compute.Value,
	indexVectorAxis int,
	updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int,
	indicesAreSorted, uniqueIndices bool,
) (compute.Value, error)

func SchedulingBarrier

func SchedulingBarrier(f *gobackend.Function, operand compute.Value, dependencies ...compute.Value) (compute.Value, error)

SchedulingBarrier implements the compute.SchedulingBarrier interface. This operation is not de-duplicated: if you issue it twice, it will not reuse the previous instance.

func SelectAndScatterMax added in v0.1.3

func SelectAndScatterMax(f *gobackend.Function,
	operandOp, sourceOp compute.Value,
	windowDimensions, strides []int,
	paddings [][2]int,
) (compute.Value, error)

SelectAndScatterMax runs windows over operand, selects maximum elements in each window, and scatters source values to the output.

func SelectAndScatterMin added in v0.1.3

func SelectAndScatterMin(f *gobackend.Function,
	operandOp, sourceOp compute.Value,
	windowDimensions, strides []int,
	paddings [][2]int,
) (compute.Value, error)

SelectAndScatterMin runs windows over operand, selects minimum elements in each window, and scatters source values to the output.

func SetWhereFloat32ArchDispatcher added in v0.1.26

func SetWhereFloat32ArchDispatcher(priority gobackend.RegisterPriority, fn WhereFloat32ArchFn)

SetWhereFloat32ArchDispatcher registers an architecture-specific float32 Where dispatcher with a priority. Dispatchers are tried in descending order of priority; if a higher-priority dispatcher returns false, the next one is tried before falling back to the generic implementation.

func ShiftLeft

func ShiftLeft(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

ShiftLeft implements the compute.Builder interface.

func ShiftRightArithmetic

func ShiftRightArithmetic(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

ShiftRightArithmetic implements the compute.Builder interface.

func ShiftRightLogical

func ShiftRightLogical(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

ShiftRightLogical implements the compute.Builder interface.

func Sign

func Sign(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Sign implements the compute.Builder interface.

func Sin

func Sin(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Sin implements the compute.Builder interface.

func Slice

func Slice(f *gobackend.Function, operandOp compute.Value, starts, limits, strides []int) (compute.Value, error)

Slice extracts a subarray from the input array.

The subarray is of the same rank as the input and contains the values inside a bounding box within the input array where the dimensions and indices of the bounding box are given as arguments to the slice operation.

The strides set the input stride of the slice in each axis and must be >= 1. It is optional, and if missing, it is assumed to be 1 for every dimension.

The limits are defined on the x axes, and they are exclusive upper bounds, i.e. the slice includes elements from starts up to (but not including) limits.

Examples:

Slice(x={0, 1, 2, 3, 4}, starts={2}, limits={4}, strides=nil) -> {2, 3}
Slice(x={0, 1, 2, 3, 4}, starts={2}, limits={5}, strides={2}) -> {2, 4}

func Sort

func Sort(
	f *gobackend.Function,
	comparator compute.Function,
	axis int,
	isStable bool,
	inputs ...compute.Value,
) ([]compute.Value, error)

Sort sorts one or more tensors along the specified axis using a comparator closure.

The comparator closure takes 2*N scalar parameters (lhs_0, rhs_0, lhs_1, rhs_1, ...) where N is the number of input tensors, and returns a scalar boolean indicating whether lhs should come before rhs.

func Sqrt

func Sqrt(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Sqrt implements the compute.Builder interface.

func Sub

func Sub(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)

Sub implements the compute.Builder interface.

func Tanh

func Tanh(f *gobackend.Function, operand compute.Value) (compute.Value, error)

Tanh implements the compute.Builder interface.

func Transpose

func Transpose(f *gobackend.Function, operandValue compute.Value, permutations ...int) (compute.Value, error)

Transpose axes of x. There must be one value in permutations for each axis in the operand. The output will have: output.Shape.Dimension[ii] = operand.Shape.Dimension[permutations[i]].

func Where

func Where(f *gobackend.Function, conditionOp, onTrueOp, onFalseOp compute.Value) (compute.Value, error)

Where implements the compute.Builder interface.

func While

func While(f *gobackend.Function, cond, body compute.Function, initialState ...compute.Value) ([]compute.Value, error)

While executes a loop while a condition is true.

The condition closure takes the current state values and returns a scalar boolean. The body closure takes the current state values and returns new state values. Both must have the same number of parameters matching the initialState count.

Types

type Conv2DKind added in v0.1.24

type Conv2DKind int

Conv2DKind classifies a 1D or 2D convolution into a specialized SIMD execution family.

const (
	// Conv2DUnsupported indicates the convolution axes/grouping cannot use the 1D/2D ChannelsLast SIMD fast paths.
	Conv2DUnsupported Conv2DKind = iota

	// Conv2DStandard is a 1D or 2D ChannelsLast spatial convolution:
	//   input:  [B, H, W, Cin] (or [B, W, Cin] normalized to H=1)
	//   kernel: [kH, kW, Cin, Cout] (IsKernelTransposed=false, forward)
	//        or [kH, kW, Cout, Cin] (IsKernelTransposed=true, VJP wrt input)
	//   output: [B, OutH, OutW, Cout]
	Conv2DStandard

	// Conv2DKernelGrad is a 1D or 2D ChannelsLast VJP wrt kernel convolution:
	//   input (x):  [B, H, W, Cin]  (InputBatch=rank-1 (Cin), InputSpatial={1..}, InputChannels=0 (B))
	//   kernel (v): [B, OutH, OutW, Cout] (KernelSpatial={1..}, KernelInputChannels=0 (B), KernelOutputChannels=rank-1 (Cout))
	//   output:     [kH, kW, Cin, Cout] (OutputSpatial={0..}, OutputBatch=rank-2 (Cin), OutputChannels=rank-1 (Cout))
	Conv2DKernelGrad
)

type Conv2DParams added in v0.1.24

type Conv2DParams struct {
	Kind Conv2DKind

	BatchSize   int
	InH, InW    int
	InChannels  int
	OutH, OutW  int
	OutChannels int
	KernelH     int
	KernelW     int

	StrideH, StrideW int
	PadTop, PadLeft  int
	InDilH, InDilW   int
	KerDilH, KerDilW int

	// IsKernelTransposed is true for VJP wrt input where kernel shape is [kH, kW, Cout, Cin]
	// (KernelInputChannels=rank-1, KernelOutputChannels=rank-2).
	IsKernelTransposed bool

	// Is1x1Unit is true for Conv2DStandard when KernelH==1, KernelW==1, StrideH==1, StrideW==1,
	// PadTop==0, PadLeft==0, InDilH==1, InDilW==1, OutH==InH, OutW==InW.
	Is1x1Unit bool
}

Conv2DParams holds normalized 2D parameters for 1D and 2D ChannelsLast convolutions. For 1D convolutions, the height dimension is normalized to 1 (InH=1, OutH=1, KernelH=1, StrideH=1, PadTop=0, InDilH=1, KerDilH=1).

func GetConv2DParams added in v0.1.24

func GetConv2DParams(node *gobackend.Node) Conv2DParams

GetConv2DParams returns the precomputed Conv2DParams for a ConvGeneral node.

func (*Conv2DParams) KernelGradValidRange added in v0.1.24

func (p *Conv2DParams) KernelGradValidRange(ky, kx int) (outYStart, outYEnd, inYStart, outXStart, outXEnd, inXStart int)

KernelGradValidRange computes the valid output spatial range [outYStart, outYEnd) and [outXStart, outXEnd) and the corresponding starting input coordinates (inYStart, inXStart) for a given filter position (ky, kx) in Conv2DKernelGrad (when InDilH == 1 && InDilW == 1).

type ConvertFnType

type ConvertFnType = func(operand, output *gobackend.Buffer)

type GenericReduceFn

type GenericReduceFn = func(operand, output *gobackend.Buffer, it *ReduceOutputIterator, dtype dtypes.DType) error

GenericReduceFn is the type for the reduction functions.

type ReduceConfig added in v0.1.9

type ReduceConfig struct {
	Axes       []int
	Pattern    ReducePattern
	A, B, C, D int
}

ReduceConfig contains pre-computed metadata for reduction operations.

func DetermineReduceConfig added in v0.1.9

func DetermineReduceConfig(shape shapes.Shape, axes []int) ReduceConfig

DetermineReduceConfig classifies the reduction pattern for a given operand shape and reduce axes.

func (*ReduceConfig) EqualNodeData added in v0.1.9

func (c *ReduceConfig) EqualNodeData(other gobackend.NodeDataComparable) bool

EqualNodeData implements gobackend.NodeDataComparable.

func (*ReduceConfig) Recompute added in v0.1.9

func (c *ReduceConfig) Recompute(backend *gobackend.Backend, resolvedNodes []*gobackend.Node, originalNode *gobackend.Node) (any, error)

Recompute implements gobackend.RecomputableNodeData.

type ReduceOutputIterator

type ReduceOutputIterator struct {
	Config  ReduceConfig
	Backend *gobackend.Backend
	// contains filtered or unexported fields
}

ReduceOutputIterator is a dynamic iterator that yields output flat indices for the corresponding flat index on the input operand, assuming the operand flat index is moving incrementally.

func NewReduceOutputIterator

func NewReduceOutputIterator(dimensions []int, reduceAxes []int) *ReduceOutputIterator

NewReduceOutputIterator creates a dynamic iterator that yields output flat indices for the corresponding flat index on the input operand, assuming the operand flat index is moving incrementally.

func (*ReduceOutputIterator) Next

func (it *ReduceOutputIterator) Next() int

Next returns the next flat index in the output.

type ReducePattern added in v0.1.9

type ReducePattern int

ReducePattern classifies the geometric shape of the reduction for fast-path execution.

const (
	// ReduceAll indicates all axes of the tensor are being reduced, yielding a scalar or size-1 output.
	ReduceAll ReducePattern = iota

	// ReduceTrailing indicates a contiguous suffix of axes is reduced: operand [A, B] -> output [A].
	ReduceTrailing

	// ReduceLeading indicates a contiguous prefix of axes is reduced: operand [A, B] -> output [B].
	ReduceLeading

	// ReduceMiddle indicates a contiguous middle segment of axes is reduced: operand [A, B, C] -> output [A, C].
	ReduceMiddle

	// ReduceStrided indicates two non-contiguous reduced segments where the second is trailing:
	// operand [A, B, C, D] -> output [A, C] (with A >= 1, e.g. 5D GroupNorm [Batch, H*W, G, C/G] reduced on [1, 2, 4]).
	ReduceStrided

	// ReduceGeneral indicates arbitrary non-contiguous axes requiring index calculation.
	ReduceGeneral
)

type TransposeIterator

type TransposeIterator struct {
	// contains filtered or unexported fields
}

TransposeIterator creates a dynamic iterator that yields output flat indices for the corresponding flat index on the input operand, assuming the operand flat index is moving incrementally.

func NewTransposeIterator

func NewTransposeIterator(operand shapes.Shape, permutations []int) *TransposeIterator

NewTransposeIterator creates a dynamic iterator that yields output flat indices for the corresponding flat index on the input operand, assuming the operand flat index is moving incrementally.

func (*TransposeIterator) Next

func (it *TransposeIterator) Next() int

Next returns the next flat index in the output.

type WhereFloat32ArchFn added in v0.1.26

type WhereFloat32ArchFn func(cond []bool, onTrue, onFalse, out []float32, onTrueIsScalar, onFalseIsScalar bool) bool

WhereFloat32ArchFn executes Where on contiguous float32 slices. Returns true if handled, false to fall back to generic.

Directories

Path Synopsis
Package avx2 provides AVX2 SIMD implementations for normal operations.
Package avx2 provides AVX2 SIMD implementations for normal operations.
Package avx512 provides AVX2 SIMD implementations for normal operations.
Package avx512 provides AVX2 SIMD implementations for normal operations.
Package neon provides ARM64 AdvSIMD (NEON) accelerated kernels for standard operations.
Package neon provides ARM64 AdvSIMD (NEON) accelerated kernels for standard operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL