Documentation
¶
Overview ¶
Package simplego implements a simple, and not very fast, but very portable backend for GoMLX.
It only implements the most popular dtypes and operations. But generally, it's easy to add new ops, if you need, just open an issue in GoMLX.
Index ¶
- Constants
- Variables
- func New(config string) backends.Backend
- type Backend
- func (b *Backend) BufferData(buffer backends.Buffer) (flat any, err error)
- func (b *Backend) BufferDeviceNum(buffer backends.Buffer) (backends.DeviceNum, error)
- func (b *Backend) BufferFinalize(backendBuffer backends.Buffer) error
- func (b *Backend) BufferFromFlatData(deviceNum backends.DeviceNum, flat any, shape shapes.Shape) (backends.Buffer, error)
- func (b *Backend) BufferShape(buffer backends.Buffer) (shapes.Shape, error)
- func (b *Backend) BufferToFlatData(backendBuffer backends.Buffer, flat any) error
- func (b *Backend) Builder(name string) backends.Builder
- func (b *Backend) Capabilities() backends.Capabilities
- func (b *Backend) Description() string
- func (b *Backend) Finalize()
- func (b *Backend) HasSharedBuffers() bool
- func (b *Backend) Name() string
- func (b *Backend) NewBuffer(shape shapes.Shape) *Buffer
- func (b *Backend) NewSharedBuffer(deviceNum backends.DeviceNum, shape shapes.Shape) (buffer backends.Buffer, flat any, err error)
- func (b *Backend) NumDevices() backends.DeviceNum
- func (b *Backend) String() string
- type Buffer
- type Builder
- func (b *Builder) Abs(operand backends.Op) (backends.Op, error)
- func (b *Builder) Add(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) ArgMinMax(operandOp backends.Op, axis int, outputDType dtypes.DType, isMin bool) (backends.Op, error)
- func (b *Builder) BitCount(operand backends.Op) (backends.Op, error)
- func (b *Builder) BitwiseAnd(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) BitwiseNot(operand backends.Op) (backends.Op, error)
- func (b *Builder) BitwiseOr(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) BitwiseXor(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Broadcast(operandOp backends.Op, prefixDims ...int) (backends.Op, error)
- func (b *Builder) BroadcastInDim(operandOp backends.Op, outputShape shapes.Shape, broadcastAxes []int) (backends.Op, error)
- func (b *Builder) Ceil(operand backends.Op) (backends.Op, error)
- func (b *Builder) Clz(operand backends.Op) (backends.Op, error)
- func (b *Builder) Compile(outputs ...backends.Op) (backends.Executable, error)
- func (b *Builder) Concatenate(axis int, operandOps ...backends.Op) (backends.Op, error)
- func (b *Builder) Constant(flat any, dims ...int) (backends.Op, error)
- func (b *Builder) ConvertDType(operandOp backends.Op, dtype dtypes.DType) (backends.Op, error)
- func (b *Builder) Cos(operand backends.Op) (backends.Op, error)
- func (b *Builder) Div(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Dot(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) DotGeneral(lhsOp backends.Op, lhsContractingAxes, lhsBatchAxes []int, rhsOp backends.Op, ...) (backends.Op, error)
- func (b *Builder) Equal(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Erf(operand backends.Op) (backends.Op, error)
- func (b *Builder) Exp(operand backends.Op) (backends.Op, error)
- func (b *Builder) Expm1(operand backends.Op) (backends.Op, error)
- func (b *Builder) Finalize()
- func (b *Builder) Floor(operand backends.Op) (backends.Op, error)
- func (b *Builder) Gather(operandOp, startIndicesOp backends.Op, indexVectorAxis int, ...) (backends.Op, error)
- func (b *Builder) GreaterOrEqual(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) GreaterThan(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Identity(operandOp backends.Op) (backends.Op, error)
- func (b *Builder) Iota(shape shapes.Shape, iotaAxis int) (backends.Op, error)
- func (b *Builder) IsFinite(operandOp backends.Op) (backends.Op, error)
- func (b *Builder) LessOrEqual(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) LessThan(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Log(operand backends.Op) (backends.Op, error)
- func (b *Builder) Log1p(operand backends.Op) (backends.Op, error)
- func (b *Builder) LogicalAnd(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) LogicalNot(operand backends.Op) (backends.Op, error)
- func (b *Builder) LogicalOr(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) LogicalXor(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Logistic(operand backends.Op) (backends.Op, error)
- func (b *Builder) Max(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Min(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Mul(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Name() string
- func (b *Builder) Neg(operand backends.Op) (backends.Op, error)
- func (b *Builder) NotEqual(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) OpShape(op backends.Op) (shapes.Shape, error)
- func (b *Builder) Parameter(name string, shape shapes.Shape) (backends.Op, error)
- func (b *Builder) Pow(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) ReduceBitwiseAnd(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceBitwiseOr(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceBitwiseXor(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceLogicalAnd(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceLogicalOr(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceLogicalXor(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceMax(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceMin(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceProduct(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceSum(operandOp backends.Op, axis ...int) (backends.Op, error)
- func (b *Builder) ReduceWindow(operandOp backends.Op, reductionType backends.ReduceOpType, ...) (backends.Op, error)
- func (b *Builder) Rem(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Reshape(operandOp backends.Op, dims ...int) (backends.Op, error)
- func (b *Builder) RngBitGenerator(stateOp backends.Op, shape shapes.Shape) (newState, values backends.Op, err error)
- func (b *Builder) Round(operand backends.Op) (backends.Op, error)
- func (b *Builder) Rsqrt(operand backends.Op) (backends.Op, error)
- func (b *Builder) ScatterMax(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, ...) (backends.Op, error)
- func (b *Builder) ScatterMin(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, ...) (backends.Op, error)
- func (b *Builder) ScatterSum(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, ...) (backends.Op, error)
- func (b *Builder) Sign(operand backends.Op) (backends.Op, error)
- func (b *Builder) Sin(operand backends.Op) (backends.Op, error)
- func (b *Builder) Slice(operandOp backends.Op, starts, limits, strides []int) (backends.Op, error)
- func (b *Builder) Sqrt(operand backends.Op) (backends.Op, error)
- func (b *Builder) Sub(lhsOp, rhsOp backends.Op) (backends.Op, error)
- func (b *Builder) Tanh(operand backends.Op) (backends.Op, error)
- func (b *Builder) Transpose(operandOp backends.Op, permutations ...int) (backends.Op, error)
- func (b *Builder) Where(conditionOp, onTrueOp, onFalseOp backends.Op) (backends.Op, error)
- type DTypeDispatcher
- type DTypeMap
- type DTypePairMap
- type Executable
- type FuncForDispatcher
- type Node
- type PODBooleanConstraints
- type PODFloatConstraints
- type PODIntegerConstraints
- type PODNumericConstraints
- type PODSignedNumericConstraints
- type PODUnsignedConstraints
- type SupportedTypesConstraints
Constants ¶
const BackendName = "go"
BackendName to be used in GOMLX_BACKEND to specify this backend.
const MaxArgMinMaxReductionSize = 0x8000_0000
const MaxDTypes = 32
Variables ¶
var ( // DotGeneralTargetBlockSize is hardware-specific, it should be aligned with the L1 cache size // and maybe page-size. // It should be the number per thread, not necessarily the number per core. // It was empirically optimized in an AMD 9950x3d. // TODO: find out how to initialize this number in runtime. DotGeneralTargetBlockSize = 4 * 1024 // DotGeneralTargetBlockLog2Dim is set per dtype, such that it is square and fits DotGeneralTargetBlockSize. // The block dim is 2^(DotGeneralTargetBlockLog2Dim[dtype]). DotGeneralTargetBlockLog2Dim [MaxDTypes]int )
var Capabilities = backends.Capabilities{ Operations: map[backends.OpType]bool{ backends.OpTypeParameter: true, backends.OpTypeConstant: true, backends.OpTypeAbs: true, backends.OpTypeBitCount: true, backends.OpTypeBitwiseNot: true, backends.OpTypeCeil: true, backends.OpTypeClz: true, backends.OpTypeCos: true, backends.OpTypeErf: true, backends.OpTypeExp: true, backends.OpTypeExpm1: true, backends.OpTypeFloor: true, backends.OpTypeIsFinite: true, backends.OpTypeLog1p: true, backends.OpTypeLog: true, backends.OpTypeLogicalNot: true, backends.OpTypeLogistic: true, backends.OpTypeNeg: true, backends.OpTypeRound: true, backends.OpTypeRsqrt: true, backends.OpTypeSign: true, backends.OpTypeSin: true, backends.OpTypeSqrt: true, backends.OpTypeTanh: true, backends.OpTypeAdd: true, backends.OpTypeBitwiseAnd: true, backends.OpTypeBitwiseOr: true, backends.OpTypeBitwiseXor: true, backends.OpTypeDiv: true, backends.OpTypeLogicalAnd: true, backends.OpTypeLogicalOr: true, backends.OpTypeLogicalXor: true, backends.OpTypeMax: true, backends.OpTypeMin: true, backends.OpTypeMul: true, backends.OpTypePow: true, backends.OpTypeRem: true, backends.OpTypeSub: true, backends.OpTypeEqual: true, backends.OpTypeNotEqual: true, backends.OpTypeGreaterOrEqual: true, backends.OpTypeGreaterThan: true, backends.OpTypeLessOrEqual: true, backends.OpTypeLessThan: true, backends.OpTypeArgMinMax: true, backends.OpTypeBroadcast: true, backends.OpTypeBroadcastInDim: true, backends.OpTypeConcatenate: true, backends.OpTypeConvertDType: true, backends.OpTypeDot: true, backends.OpTypeDotGeneral: true, backends.OpTypeGather: true, backends.OpTypeIdentity: true, backends.OpTypeIota: true, backends.OpTypeReduceBitwiseAnd: true, backends.OpTypeReduceBitwiseOr: true, backends.OpTypeReduceBitwiseXor: true, backends.OpTypeReduceLogicalAnd: true, backends.OpTypeReduceLogicalOr: true, backends.OpTypeReduceLogicalXor: true, backends.OpTypeReduceMax: true, backends.OpTypeReduceMin: true, backends.OpTypeReduceProduct: true, backends.OpTypeReduceSum: true, backends.OpTypeReduceWindow: true, backends.OpTypeReshape: true, backends.OpTypeRngBitGenerator: true, backends.OpTypeScatterMax: true, backends.OpTypeScatterMin: true, backends.OpTypeScatterSum: true, backends.OpTypeSlice: true, backends.OpTypeTranspose: true, backends.OpTypeWhere: true, }, DTypes: map[dtypes.DType]bool{ dtypes.Bool: true, dtypes.Int8: true, dtypes.Int16: true, dtypes.Int32: true, dtypes.Int64: true, dtypes.Uint8: true, dtypes.Uint16: true, dtypes.Uint32: true, dtypes.Uint64: true, dtypes.Float32: true, dtypes.Float64: true, dtypes.BFloat16: true, }, }
Capabilities of the SimpleGo backends: the set of supported operations and data types.
Functions ¶
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend implements the backends.Backend interface.
func (*Backend) BufferData ¶
BufferData returns a slice pointing to the buffer storage memory directly.
This only works if HasSharedBuffer is true, that is, if the backend engine runs on CPU, or shares CPU memory.
The returned slice becomes invalid after the buffer is destroyed.
func (*Backend) BufferDeviceNum ¶
BufferDeviceNum returns the deviceNum for the buffer.
func (*Backend) BufferFinalize ¶
BufferFinalize allows the client to inform backend that buffer is no longer needed and associated resources can be freed immediately.
A finalized buffer should never be used again. Preferably, the caller should set its references to it to nil.
func (*Backend) BufferFromFlatData ¶
func (b *Backend) BufferFromFlatData(deviceNum backends.DeviceNum, flat any, shape shapes.Shape) (backends.Buffer, error)
BufferFromFlatData transfers data from Go given as a flat slice (of the type corresponding to the shape DType) to the deviceNum, and returns the corresponding backends.Buffer.
func (*Backend) BufferShape ¶
BufferShape returns the shape for the buffer.
func (*Backend) BufferToFlatData ¶
BufferToFlatData transfers the flat values of the buffer to the Go flat array. The slice flat must have the exact number of elements required to store the backends.Buffer shape.
See also FlatDataToBuffer, BufferShape, and shapes.Shape.Size.
func (*Backend) Capabilities ¶
func (b *Backend) Capabilities() backends.Capabilities
Capabilities returns information about what is supported by this backend.
func (*Backend) Description ¶
Description is a longer description of the Backend that can be used to pretty-print.
func (*Backend) Finalize ¶
func (b *Backend) Finalize()
Finalize releases all the associated resources immediately, and makes the backend invalid.
func (*Backend) HasSharedBuffers ¶
HasSharedBuffers returns whether the backend supports "shared buffers": these are buffers that can be used directly by the engine and has a local address that can be read or mutated directly by the client.
func (*Backend) Name ¶
Name returns the short name of the backend. E.g.: "xla" for the Xla/PJRT plugin.
func (*Backend) NewSharedBuffer ¶
func (b *Backend) NewSharedBuffer(deviceNum backends.DeviceNum, shape shapes.Shape) (buffer backends.Buffer, flat any, err error)
NewSharedBuffer returns a "shared buffer" that can be both used as input for execution of computations and directly read or mutated by the clients.
It panics if the backend doesn't support shared buffers -- see HasSharedBuffer.
The shared buffer should not be mutated while it is used by an execution. Also, the shared buffer cannot be "donated" during execution.
When done, to release the memory, call BufferFinalized on the returned buffer.
It returns a handle to the buffer and a slice of the corresponding data type pointing to the shared data.
func (*Backend) NumDevices ¶
NumDevices return the number of devices available for this Backend.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer for SimpleGo backend holds a shape and a reference to the flat data.
The flat data may be shared -- for temporary buffers from compiled graphs they are taken from larger blobs of bytes allocated in one Go -- or owned by the buffer.
func (*Buffer) Fill ¶ added in v0.19.3
Fill the buffer with the given value. It returns an error if the value type doesn't correspond to the buffer dtype.
As a special case, if value is nil, it will fill the buffer with zeroes for the corresponding DType.
type Builder ¶
type Builder struct {
notimplemented.Builder
// contains filtered or unexported fields
}
Builder keeps track of the computation graph being defined.
func (*Builder) ArgMinMax ¶ added in v0.19.3
func (b *Builder) ArgMinMax(operandOp backends.Op, axis int, outputDType dtypes.DType, isMin bool) (backends.Op, 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 (*Builder) BitwiseAnd ¶
BitwiseAnd implements the backends.Builder interface.
func (*Builder) BitwiseNot ¶
BitwiseNot implements the backends.Builder interface.
func (*Builder) BitwiseXor ¶
BitwiseXor implements the backends.Builder interface.
func (*Builder) Broadcast ¶
Broadcast prefixes dimensions to an array by duplicating the data in the array. See BroadcastInDim for a broadcast in between the axes. The new dimensions dims are inserted on the left, i.e., if prefixDims has values `{a0, ..., aN}` and the operand shape has dimensions {b0, ..., bM} then the shape of the output has dimensions {a0, ..., aN, b0, ..., bM}. The new dimensions id into copies of the operand, i.e.
output[i0, ..., iN, j0, ..., jM] = operand[j0, ..., jM]
func (*Builder) BroadcastInDim ¶
func (b *Builder) BroadcastInDim(operandOp backends.Op, outputShape shapes.Shape, broadcastAxes []int) (backends.Op, 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 (*Builder) Concatenate ¶
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 (*Builder) Constant ¶
Constant creates a constant in the graph with the given flat values, and the shape defined by dims.
flat must be a slice of a basic type supported -- that can be converted to a DType.
The value is copied into the graph. It's recommended that for very large tensors, even if constants, that they are passed as side inputNodes (or variables, see context package) instead.
func (*Builder) ConvertDType ¶
ConvertDType converts operandOp to the given dtype. It implement the backends.Builder interface.
func (*Builder) Dot ¶
Dot ------------------------------------------------------------------------------------------------------ Dot implements backends.Builder interface.
It is implemented using DotGeneral and Reshape.
Dot returns the "dot product" operation. The exact semantics of this operation depend on the ranks of the operands: | Input | Output | Semantics | | vector [n] dot vector [n] | scalar | vector dot product | | matrix [m x k] dot vector [k] | vector [m] matrix-vector multiplication | | matrix [m x k] dot matrix [k x n] | matrix [m x n] | matrix-matrix multiplication | The operation performs sum of products over the second dimension of x0 (or the first if it has rank 1) and the first dimension of x1. These are the "contracted" dimensions. The contracted dimensions of x0 and x1 must be of the same size. In practice, it can be used to perform dot products between vectors, vector/matrix multiplications or matrix/matrix multiplications. The op is created on the same XlaBuilder as used for x0 and x1.
func (*Builder) DotGeneral ¶
func (b *Builder) DotGeneral(lhsOp backends.Op, lhsContractingAxes, lhsBatchAxes []int, rhsOp backends.Op, rhsContractingAxes, rhsBatchAxes []int) (backends.Op, error)
DotGeneral takes as input lhs (left-hand-side) and rhs (right-hand-side) specifications for a general vector product -- a generalized "Einsum". Each axis can be:
- Just aligned (batch axes), so the output has the same axes as the inputs. The dimensions must match in lhs and rhs.
- Crossed (default), in which case the output is the combination (concatenation) of the dimensions.
- Contracted (contracting axes), where the output does multiply the values and reduce sum those dimensions.
It follows that the resulting dimension number starts with the batch dimension, then the 'lhs' non-contracting/non-batch dimension and finally the 'rhs' non-contracting/non-batch dimension. It provides the basic means of implementing Einsum.
This function implements backends.Builder interface.
This is the graph building part of DotGeneral. It first transposes the operands to a normalized shape with rank=3 ([batchSize, crossSize, contractingSize]), and then it issues the DotGeneral node with normalized inputs. Finally, it reshapes back to the final result.
See execDotGeneral for the implementation.
func (*Builder) Finalize ¶
func (b *Builder) Finalize()
Finalize immediately release the resources associated with the Builder.
func (*Builder) Gather ¶
func (b *Builder) Gather(operandOp, startIndicesOp backends.Op, indexVectorAxis int, offsetOutputAxes, collapsedSliceAxes, startIndexMap, sliceSizes []int, indicesAreSorted bool) (backends.Op, error)
Gather implements the backends.Builder. It's a complex operation, fully described in the backends.Builder.Gather documentation.
func (*Builder) GreaterOrEqual ¶
GreaterOrEqual implements the backends.Builder interface.
func (*Builder) GreaterThan ¶
GreaterThan implements the backends.Builder interface.
func (*Builder) 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 (*Builder) LessOrEqual ¶
LessOrEqual implements the backends.Builder interface.
func (*Builder) LogicalAnd ¶
LogicalAnd implements the backends.Builder interface.
func (*Builder) LogicalNot ¶
LogicalNot implements the backends.Builder interface.
func (*Builder) LogicalXor ¶
LogicalXor implements the backends.Builder interface.
func (*Builder) Logistic ¶
Logistic implements the backends.Builder interface. Aka as sigmoid. It returns 1/(1+exp(-x)).
func (*Builder) Parameter ¶
Parameter creates an input parameter for the computation. During execution of the computation this value will need to be fed, in the same order it is created.
func (*Builder) ReduceBitwiseAnd ¶ added in v0.19.3
ReduceBitwiseAnd implements the backends.Builder interface.
func (*Builder) ReduceBitwiseOr ¶ added in v0.19.3
ReduceBitwiseOr implements the backends.Builder interface.
func (*Builder) ReduceBitwiseXor ¶ added in v0.19.3
ReduceBitwiseXor implements the backends.Builder interface.
func (*Builder) ReduceLogicalAnd ¶ added in v0.19.3
ReduceLogicalAnd implements the backends.Builder interface.
func (*Builder) ReduceLogicalOr ¶ added in v0.19.3
ReduceLogicalOr implements the backends.Builder interface.
func (*Builder) ReduceLogicalXor ¶ added in v0.19.3
ReduceLogicalXor implements the backends.Builder interface.
func (*Builder) ReduceProduct ¶
ReduceProduct implements the backends.Builder interface.
func (*Builder) ReduceWindow ¶ added in v0.19.3
func (b *Builder) ReduceWindow(operandOp backends.Op, reductionType backends.ReduceOpType, windowDimensions, strides, baseDilations, windowDilations []int, paddings [][2]int) (backends.Op, error)
ReduceWindow runs a reduction function of reduceType (backends.ReduceOpMax, backends.ReduceOpSum or backends.ReduceOpProduct).
The parameter windowDimensions must be set and have a value for each axis. If strides is nil, it's assumed to be the same as windowDimensions -- that is, the strides jump a window at a time. If baseDilations, windowDilations are nil, they are assumed to be 1 (no dilation). If paddings is nil, they are assumed to be 0.
func (*Builder) Reshape ¶
Reshape implements the backends.Builder interface.
Notice the backends.Reshape doesn't support auto-scaling dimensions (set to -1), as graph.Reshape does.
func (*Builder) RngBitGenerator ¶ added in v0.19.1
func (b *Builder) RngBitGenerator(stateOp backends.Op, shape shapes.Shape) (newState, values backends.Op, 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 (*Builder) ScatterMax ¶
func (b *Builder) ScatterMax(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Op, error)
ScatterMax implements the backends.Builder interface.
func (*Builder) ScatterMin ¶
func (b *Builder) ScatterMin(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Op, error)
ScatterMin implements the backends.Builder interface.
func (*Builder) ScatterSum ¶
func (b *Builder) ScatterSum(operandOp, scatterIndicesOp, updatesOp backends.Op, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Op, error)
ScatterSum implements the backends.Builder interface.
func (*Builder) Slice ¶ added in v0.19.1
Slice extracts a sub-array from the input array. The sub-array 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. 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}
type DTypeDispatcher ¶
type DTypeDispatcher struct {
Name string
// contains filtered or unexported fields
}
DTypeDispatcher manages dispatching functions to handle specific DTypes. Often, these functions will be instances of a generic function.
func NewDTypeDispatcher ¶
func NewDTypeDispatcher(name string) *DTypeDispatcher
NewDTypeDispatcher creates a new dispatcher for a class of functions.
func (*DTypeDispatcher) Dispatch ¶
func (d *DTypeDispatcher) Dispatch(dtype dtypes.DType, params ...any) any
Dispatch call the function that matches the dtype.
func (*DTypeDispatcher) Register ¶
func (d *DTypeDispatcher) Register(dtype dtypes.DType, fn FuncForDispatcher)
Register a function to handle a specific dtype. This overwrites any previous setting for the same dtype.
func (*DTypeDispatcher) RegisterIfNotSet ¶
func (d *DTypeDispatcher) RegisterIfNotSet(dtype dtypes.DType, fn FuncForDispatcher)
RegisterIfNotSet a function to handle a specific dtype.
type DTypeMap ¶
DTypeMap manages registering of an arbitrary value per dtype.
func (*DTypeMap) Get ¶
Get retrieves the value for the given dtype, or throw an exception if none was registered.
type DTypePairMap ¶
DTypePairMap manages registering of an arbitrary value per dtype pair.
func NewDTypePairMap ¶
func NewDTypePairMap(name string) *DTypePairMap
NewDTypePairMap creates a new DTypePairMap.
func (*DTypePairMap) Get ¶
func (d *DTypePairMap) Get(dtype1, dtype2 dtypes.DType) any
Get retrieves the value for the given dtype pair, or throw an exception if none was registered.
func (*DTypePairMap) Register ¶
func (d *DTypePairMap) Register(dtype1, dtype2 dtypes.DType, value any)
Register a value for a dtype pair. This overwrites any previous setting for the same dtype.
func (*DTypePairMap) RegisterIfNotSet ¶
func (d *DTypePairMap) RegisterIfNotSet(dtype1, dtype2 dtypes.DType, value any)
RegisterIfNotSet a value for a dtype pair.
type Executable ¶
type Executable struct {
// contains filtered or unexported fields
}
Executable holds a frozen Builder. It assumes the graph in Builder is valid and has been properly checked that all the shapes and data types are valid.
If any inconsistencies are found, please fix in the Builder, so Executable can be written without need of any duplicate checks.
func (*Executable) Execute ¶
Execute the executable on the default device (0). The number and shapes of the inputs must match those returned by Inputs.
The inputs marked in donate will become invalid after use. This is useful if the input buffer is no longer needed or if updating a variable so its Buffer space can be reused as an output Buffer.
Donated buffers are no longer valid after the call. If donate is nil, it is assumed to be false for all buffers, and no buffer is donated.
func (*Executable) Finalize ¶
func (e *Executable) Finalize()
Finalize immediately frees resources associated to the executable.
func (*Executable) Inputs ¶
func (e *Executable) Inputs() (names []string, inputShapes []shapes.Shape)
Inputs returns the list of parameters names and shapes, in order created by the Builder.Parameter calls.
func (*Executable) Outputs ¶
func (e *Executable) Outputs() (outputShapes []shapes.Shape)
Outputs returns the output shapes of the computation, in order given to the Builder.Compile call.
type FuncForDispatcher ¶
FuncForDispatcher is type of functions that the DTypeDispatcher can handle.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node in the SimpleGo computation graph.
func (*Node) IsMultiOutputs ¶ added in v0.19.1
IsMultiOutputs returns whether this node yields multiple outputs.
type PODBooleanConstraints ¶
type PODBooleanConstraints interface {
bool
}
PODBooleanConstraints is a simple placeholder for the gen_exec_binary.go generated code.
type PODFloatConstraints ¶
PODFloatConstraints are used for generics for the Golang pod (plain-old-data) types. BFloat16 is not included because it is a specialized type, not natively supported by Go.
type PODIntegerConstraints ¶
type PODIntegerConstraints interface {
int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
}
PODIntegerConstraints are used for generics for the Golang pod (plain-old-data) types.
type PODNumericConstraints ¶
type PODNumericConstraints interface {
int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | float32 | float64
}
PODNumericConstraints are used for generics for the Golang pod (plain-old-data) types. BFloat16 is not included because it is a specialized type, not natively supported by Go.
type PODSignedNumericConstraints ¶
PODSignedNumericConstraints are used for generics for the Golang pod (plain-old-data) types. BFloat16 is not included because it is a specialized type, not natively supported by Go.
type PODUnsignedConstraints ¶
PODUnsignedConstraints are used for generics for the Golang pod (plain-old-data) types.