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
- Variables
- func Abs(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Add(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func ArgMinMax(f *gobackend.Function, operandOp compute.Value, axis int, ...) (compute.Value, error)
- func Atan2(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func BitCount(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Bitcast(f *gobackend.Function, operandOp compute.Value, targetDType dtypes.DType) (compute.Value, error)
- func BitwiseAnd(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func BitwiseNot(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func BitwiseOr(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func BitwiseXor(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func BroadcastInDim(f *gobackend.Function, operandValue compute.Value, outputShape shapes.Shape, ...) (compute.Value, error)
- func Call(f *gobackend.Function, target compute.Function, inputs ...compute.Value) ([]compute.Value, error)
- func Ceil(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Clamp(f *gobackend.Function, minV, x, maxV compute.Value) (compute.Value, error)
- func Clz(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Concatenate(f *gobackend.Function, axis int, operandOps ...compute.Value) (compute.Value, error)
- func ConvGeneral(f *gobackend.Function, inputOp, kernelOp compute.Value, ...) (compute.Value, error)
- func ConvertDType(f *gobackend.Function, operandOp compute.Value, dtype dtypes.DType) (compute.Value, error)
- func Cos(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func CumMax(f *gobackend.Function, operandValue compute.Value, axis int, ...) (compute.Value, error)
- func CumSum(f *gobackend.Function, operandValue compute.Value, axis int, ...) (compute.Value, error)
- func Div(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func DynamicBroadcastInDim(f *gobackend.Function, operandValue compute.Value, broadcastAxes []int, ...) (compute.Value, error)
- func DynamicDimensionSize(f *gobackend.Function, operandValue compute.Value, axis int) (compute.Value, error)
- func DynamicIota(f *gobackend.Function, dtype dtypes.DType, iotaAxis int, ...) (compute.Value, error)
- func DynamicPad(f *gobackend.Function, operandOp, fillValueOp compute.Value, ...) (compute.Value, error)
- func DynamicReshape(f *gobackend.Function, operandValue compute.Value, ...) (compute.Value, error)
- func DynamicShape(f *gobackend.Function, operandValue compute.Value) (compute.Value, error)
- func DynamicUpdateSlice(f *gobackend.Function, operandOp, updateOp compute.Value, ...) (compute.Value, error)
- func Equal(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Erf(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func ExecuteTranspose(backend *gobackend.Backend, operand, output *gobackend.Buffer, ...)
- func Exp(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Expm1(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func ExtractPatches2DFloat32(p *Conv2DParams, input, patchBuf []float32, mStart, mCount int)
- func Floor(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Gather(f *gobackend.Function, operandValue, startIndicesValue compute.Value, ...) (compute.Value, error)
- func GetBroadcastConfig(node *gobackend.Node, lhs, rhs, output *gobackend.Buffer) gobackend.BroadcastConfig
- func GreaterOrEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func GreaterThan(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Identity(f *gobackend.Function, operandOp compute.Value) (compute.Value, error)
- func If(f *gobackend.Function, pred compute.Value, ...) ([]compute.Value, error)
- func Iota(f *gobackend.Function, shape shapes.Shape, iotaAxis int) (compute.Value, error)
- func IsFinite(f *gobackend.Function, operandOp compute.Value) (compute.Value, error)
- func IsNaN(f *gobackend.Function, x compute.Value) (compute.Value, error)
- func LessOrEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func LessThan(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Log(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Log1p(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func LogicalAnd(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func LogicalNot(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func LogicalOr(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func LogicalXor(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Logistic(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Max(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Min(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Mul(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Neg(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func NotEqual(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func OptimizationBarrier(f *gobackend.Function, operands ...compute.Value) ([]compute.Value, error)
- func PackConvKernelFloat32(p *Conv2DParams, kernel, packedRHS []float32, panelCols int)
- func Pad(f *gobackend.Function, operandOp, fillValueOp compute.Value, ...) (compute.Value, error)
- func Pow(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func RNGBitGenerator(f *gobackend.Function, stateOp compute.Value, shape shapes.Shape) (newState, values compute.Value, err error)
- func ReduceBitwiseAnd(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceBitwiseOr(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceBitwiseXor(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceLogicalAnd(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceLogicalOr(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceLogicalXor(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceMax(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceMin(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceProduct(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceSum(f *gobackend.Function, operand compute.Value, axis ...int) (compute.Value, error)
- func ReduceWindow(f *gobackend.Function, operandOp compute.Value, ...) (compute.Value, error)
- func Rem(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Reshape(f *gobackend.Function, operandValue compute.Value, dims ...int) (compute.Value, error)
- func Reverse(f *gobackend.Function, operandValue compute.Value, axes ...int) (compute.Value, error)
- func Round(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Rsqrt(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func ScatterMax(f *gobackend.Function, operandOp, scatterIndicesOp, updatesOp compute.Value, ...) (compute.Value, error)
- func ScatterMin(f *gobackend.Function, operandOp, scatterIndicesOp, updatesOp compute.Value, ...) (compute.Value, error)
- func ScatterSum(f *gobackend.Function, operandOp, scatterIndicesOp, updatesOp compute.Value, ...) (compute.Value, error)
- func SchedulingBarrier(f *gobackend.Function, operand compute.Value, dependencies ...compute.Value) (compute.Value, error)
- func SelectAndScatterMax(f *gobackend.Function, operandOp, sourceOp compute.Value, ...) (compute.Value, error)
- func SelectAndScatterMin(f *gobackend.Function, operandOp, sourceOp compute.Value, ...) (compute.Value, error)
- func ShiftLeft(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func ShiftRightArithmetic(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func ShiftRightLogical(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Sign(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Sin(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Slice(f *gobackend.Function, operandOp compute.Value, starts, limits, strides []int) (compute.Value, error)
- func Sort(f *gobackend.Function, comparator compute.Function, axis int, isStable bool, ...) ([]compute.Value, error)
- func Sqrt(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Sub(f *gobackend.Function, lhsOp, rhsOp compute.Value) (compute.Value, error)
- func Tanh(f *gobackend.Function, operand compute.Value) (compute.Value, error)
- func Transpose(f *gobackend.Function, operandValue compute.Value, permutations ...int) (compute.Value, error)
- func Where(f *gobackend.Function, conditionOp, onTrueOp, onFalseOp compute.Value) (compute.Value, error)
- func While(f *gobackend.Function, cond, body compute.Function, ...) ([]compute.Value, error)
- type Conv2DKind
- type Conv2DParams
- type ConvertFnType
- type GenericReduceFn
- type ReduceConfig
- type ReduceOutputIterator
- type ReducePattern
- type TransposeIterator
Constants ¶
const MaxArgMinMaxReductionSize = 0x8000_0000
Variables ¶
var ConvertDTypePairMap = gobackend.NewDTypePairMap("ConvertDType")
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 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 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 ¶
BitwiseAnd implements the compute.Builder interface.
func BitwiseNot ¶
BitwiseNot implements the compute.Builder interface.
func BitwiseXor ¶
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 Clamp ¶
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 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 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 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 ¶
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 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 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 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 GreaterOrEqual ¶
GreaterOrEqual implements the compute.Builder interface.
func GreaterThan ¶
GreaterThan implements the compute.Builder interface.
func Identity ¶
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 Iota ¶
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 IsNaN ¶
IsNaN implements compute.Builder interface. Notice there is no executor because it uses f.NotEqual instead.
func LessOrEqual ¶
LessOrEqual implements the compute.Builder interface.
func LogicalAnd ¶
LogicalAnd implements the compute.Builder interface.
func LogicalNot ¶
LogicalNot implements the compute.Builder interface.
func LogicalXor ¶
LogicalXor implements the compute.Builder interface.
func Logistic ¶
Logistic implements the compute.Builder interface. Aka as sigmoid. It returns 1/(1+exp(-x)).
func OptimizationBarrier ¶
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 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 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 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 Reverse ¶
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 ScatterMax ¶
func ScatterMin ¶
func ScatterSum ¶
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 ShiftRightArithmetic ¶
ShiftRightArithmetic implements the compute.Builder interface.
func ShiftRightLogical ¶
ShiftRightLogical 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 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 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.
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.
Source Files
¶
- argminmax.go
- binaryops.go
- bitcast.go
- broadcastindim.go
- call.go
- clamp.go
- concatenate.go
- convertdtype.go
- convgeneral.go
- convgeneral_exec_base.go
- convgeneral_simd.go
- cummax.go
- cumsum.go
- dynamic.go
- dynamicupdateslice.go
- gather.go
- gen_convgeneral_exec_full.go
- gen_convgeneral_exec_full_half.go
- gen_convgeneral_exec_half.go
- gen_dtypemaps_registration.go
- gen_exec_binary.go
- identity.go
- if.go
- iota.go
- isnan.go
- ops.go
- optimizationbarrier.go
- pad.go
- reduce.go
- reducewindow.go
- reshape.go
- reverse.go
- rngbitgenerator.go
- scatter.go
- schedulingbarrier.go
- selectandscatter.go
- shiftops.go
- slice.go
- sort.go
- transpose.go
- unaryops.go
- where.go
- where_amd64.go
- while.go
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. |