Documentation
¶
Overview ¶
Package xla implements a GoMLX backend using Google's XLA (see github.com/gomlx/go-xla).
The backend is registered with the aliases "xla", "stablehlo", "shlo" or "hlo" (all aliases to the same backend).
By default, the XLA/PJRT backend loads the requested plugins after the program starts and specifies the desired plugin name (default to "cpu") using `dlopen`.
If the plugins are not available, the backend will download them automatically ("auto-install):
- From github.com/gomlx/pjrt-cpu-binaries for CPU PJRT plugins. - From pypi.org, using the Jax pacakges for the CUDA and TPU PJRT plugins.
Auto-install has no effect if default plugins are already installed. But to control it you can:
- Call xla.AutoInstall() directly if you want to call it immediately.
- Configure it with xla.EnableAutoInstall() if you want to enable/disable it globally (default is enabled).
- Set GOMLX_NO_AUTO_INSTALL, which sets the global auto-install flag to false -- but it can be overridden by calling xla.EnableAutoInstall().
Experimentally, one can get this backend to work with pre-linked PJRT plugins, but it will require the user to add the `.so` files in a library in LD_LIBRARY_PATH, or precompile a `.a` static library.
- Pre-link the CPU PJRT plugin statically: this will generate a bigger binary (+ ~200Mb, so slower to build), but allows one to build a static binary that can be deployed without extra dependencies (except the standard C and C++ libraries, usually available in most machines). To enable, build using the tag `pjrt_cpu_static` (e.g.: `go build --tags pjrt_cpu_static ...`), or import `github.com/gomlx/gomlx/backends/xla/cpu/static`. Both methods have the same effect.
- Pre-link the CPU PJRT plugin dynamically: build with the build tag `pjrt_cpu_dynamic` (e.g.: `go test --tags pjrt_cpu_dynamic ...`), or import `github.com/gomlx/gomlx/backends/xla/cpu/dynamic`. Not much difference from linking the PJRT plugin after the program starts, as default.
Shared Buffers Support: ¶
XLA/PJRT for CPU allows the "device buffer" (where device=CPU) to be addressed directly, which saves the copy from "host/local tensor" to the "on-device tensor" when executing a computation. This is enabled by default if the plugin is called "cpu". To force advertising support for this for other PJRTs provide the "shared_buffers" option, e.g.: GOMLX_BACKEND="xla:my_pjrt,shared_buffers". Or to force disabling the support, provide the "noshared_buffers" option.
Options ¶
Those can be passed after the plugin name, e.g.: GOMLX_BACKEND="xla:my_pjrt,notf32,shared_buffers".
- "tf32", "notf32": controls whether to use TF32 for DotGeneral operations that are using float32 (it can be faster in modern GPUs). It's enabled by default.
- "shared_buffers", "noshared_buffers": controls whether to use shared buffers for the device buffer (where device=CPU). It's enabled by default if the plugin is called "cpu".
Index ¶
- Constants
- Variables
- func AutoInstall() error
- func BFloat16SliceFromXLA(slice []xlabfloat16.BFloat16) []bfloat16.BFloat16
- func BFloat16SliceToXLA(slice []bfloat16.BFloat16) []xlabfloat16.BFloat16
- func DTypeFromXLA(xlaDType xladtypes.DType) dtypes.DType
- func DTypeToXLA(dtype dtypes.DType) xladtypes.DType
- func EnableAutoInstall(enable bool)
- func GetAvailablePlugins() []string
- func New(config string) (backends.Backend, error)
- func ShapeFromXLA(shape xlashapes.Shape) shapes.Shape
- func ShapeToXLA(shape shapes.Shape) xlashapes.Shape
- type Backend
- func (backend *Backend) BufferCopyToDevice(source backends.Buffer, deviceNum backends.DeviceNum) (bufferOnDevice backends.Buffer, err error)
- func (backend *Backend) BufferData(buffer backends.Buffer) (flat any, err error)
- func (backend *Backend) BufferDeviceNum(buffer backends.Buffer) (backends.DeviceNum, error)
- func (backend *Backend) BufferFinalize(buffer backends.Buffer) error
- func (backend *Backend) BufferFromFlatData(deviceNum backends.DeviceNum, flat any, shape shapes.Shape) (backends.Buffer, error)
- func (backend *Backend) BufferShape(buffer backends.Buffer) (shapes.Shape, error)
- func (backend *Backend) BufferToFlatData(buffer backends.Buffer, flat any) error
- func (backend *Backend) Builder(name string) backends.Builder
- func (backend *Backend) Capabilities() backends.Capabilities
- func (backend *Backend) CheckValid() error
- func (backend *Backend) Description() string
- func (backend *Backend) DeviceDescription(deviceNum backends.DeviceNum) string
- func (backend *Backend) Finalize()
- func (backend *Backend) HasSharedBuffers() bool
- func (backend *Backend) IsFinalized() bool
- func (backend *Backend) Name() string
- func (backend *Backend) NewSharedBuffer(deviceNum backends.DeviceNum, shape shapes.Shape) (buffer backends.Buffer, flat any, err error)
- func (backend *Backend) NumDevices() int
- func (backend *Backend) String() string
- type Builder
- func (b *Builder) CheckValid() error
- func (b *Builder) Compile() (backends.Executable, error)
- func (b *Builder) DeviceAssignment(devices ...backends.DeviceNum) error
- func (b *Builder) DistributedAutoSharding(meshes ...backends.Mesh) error
- func (b *Builder) DistributedSPMD(numDevices int) error
- func (b *Builder) Main() backends.Function
- func (b *Builder) Name() string
- func (b *Builder) NewFunction(name string) (backends.Function, error)
- func (b *Builder) OpShape(op backends.Value) (shapes.Shape, error)
- type Executable
- func (e *Executable) CheckValid() error
- func (e *Executable) Execute(inputs []backends.Buffer, donate []bool, defaultDevice backends.DeviceNum) ([]backends.Buffer, error)
- func (e *Executable) Finalize()
- func (e *Executable) Inputs() (names []string, inputShapes []shapes.Shape)
- func (e *Executable) Outputs() (outputShapes []shapes.Shape)
- type Function
- func (f *Function) Abs(operand backends.Value) (backends.Value, error)
- func (f *Function) Add(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) AllReduce(operands []backends.Value, reductionType backends.ReduceOpType, ...) ([]backends.Value, error)
- func (f *Function) ArgMinMax(x backends.Value, axis int, outputDType dtypes.DType, isMin bool) (backends.Value, error)
- func (f *Function) Atan2(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) BatchNormForInference(input, scale, offset, mean, variance backends.Value, epsilon float32, ...) (backends.Value, error)
- func (f *Function) BatchNormForTraining(input, scale, offset backends.Value, epsilon float32, featureAxis int) (output, batchMean, batchVar backends.Value, err error)
- func (f *Function) BatchNormGradient(gradOutput, input, scale, mean, variance backends.Value, epsilon float32, ...) (gradInput, gradScale, gradOffset backends.Value, err error)
- func (f *Function) BitCount(operand backends.Value) (backends.Value, error)
- func (f *Function) Bitcast(x backends.Value, targetDType dtypes.DType) (backends.Value, error)
- func (f *Function) BitwiseAnd(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) BitwiseNot(operand backends.Value) (backends.Value, error)
- func (f *Function) BitwiseOr(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) BitwiseXor(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) BroadcastInDim(x backends.Value, outputShape shapes.Shape, broadcastAxes []int) (backends.Value, error)
- func (f *Function) Call(target backends.Function, inputs ...backends.Value) ([]backends.Value, error)
- func (f *Function) Ceil(operand backends.Value) (backends.Value, error)
- func (f *Function) CheckValid() error
- func (f *Function) Clamp(min, a backends.Value, max backends.Value) (backends.Value, error)
- func (f *Function) Closure() (backends.Function, error)
- func (f *Function) Clz(operand backends.Value) (backends.Value, error)
- func (f *Function) Complex(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Concatenate(axis int, operands ...backends.Value) (backends.Value, error)
- func (f *Function) Conj(operand backends.Value) (backends.Value, error)
- func (f *Function) Constant(flat any, dimensions ...int) (backends.Value, error)
- func (f *Function) ConvGeneral(input, kernel backends.Value, axes backends.ConvolveAxesConfig, strides []int, ...) (backends.Value, error)
- func (f *Function) ConvertDType(x backends.Value, dtype dtypes.DType) (backends.Value, error)
- func (f *Function) Cos(operand backends.Value) (backends.Value, error)
- func (f *Function) Div(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) DotGeneral(lhs backends.Value, lhsContractingAxes, lhsBatchAxes []int, rhs backends.Value, ...) (backends.Value, error)
- func (f *Function) DynamicSlice(operand backends.Value, startIndices []backends.Value, sliceDims []int) (backends.Value, error)
- func (f *Function) DynamicUpdateSlice(operand, update backends.Value, startIndices []backends.Value) (backends.Value, error)
- func (f *Function) Equal(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) EqualTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Erf(operand backends.Value) (backends.Value, error)
- func (f *Function) Exp(operand backends.Value) (backends.Value, error)
- func (f *Function) Expm1(operand backends.Value) (backends.Value, error)
- func (f *Function) FFT(x backends.Value, fftType backends.FFTType, fftLength []int) (backends.Value, error)
- func (f *Function) Floor(operand backends.Value) (backends.Value, error)
- func (f *Function) FusedAttentionQKVProjection(x, wQKV, biasQ, biasK, biasV backends.Value, queryDim, keyValueDim int) (query, key, value backends.Value, err error)
- func (f *Function) FusedDense(x, weight, bias backends.Value, activation backends.ActivationType) (backends.Value, error)
- func (f *Function) FusedGelu(x backends.Value, exact bool) (backends.Value, error)
- func (f *Function) FusedLayerNorm(x backends.Value, axes []int, epsilon float64, gamma, beta backends.Value) (backends.Value, error)
- func (f *Function) FusedQuantizedDense(x, weights, bias backends.Value, weightsQuantization *backends.Quantization, ...) (backends.Value, error)
- func (f *Function) FusedScaledDotProductAttention(query, key, value, mask backends.Value, numHeads, numKVHeads int, ...) (backends.Value, error)
- func (f *Function) FusedSoftmax(x backends.Value, axis int) (backends.Value, error)
- func (f *Function) Gather(operand, startIndices backends.Value, indexVectorAxis int, ...) (backends.Value, error)
- func (f *Function) GreaterOrEqual(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) GreaterOrEqualTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) GreaterThan(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) GreaterThanTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Identity(x backends.Value) (backends.Value, error)
- func (f *Function) If(pred backends.Value, trueBranch, falseBranch backends.Function) ([]backends.Value, error)
- func (f *Function) Imag(operand backends.Value) (backends.Value, error)
- func (f *Function) Iota(shape shapes.Shape, iotaAxis int) (backends.Value, error)
- func (f *Function) IsFinite(operand backends.Value) (backends.Value, error)
- func (f *Function) IsNaN(x backends.Value) (backends.Value, error)
- func (f *Function) LessOrEqual(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) LessOrEqualTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) LessThan(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) LessThanTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Log(operand backends.Value) (backends.Value, error)
- func (f *Function) Log1p(operand backends.Value) (backends.Value, error)
- func (f *Function) LogicalAnd(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) LogicalNot(operand backends.Value) (backends.Value, error)
- func (f *Function) LogicalOr(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) LogicalXor(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Logistic(operand backends.Value) (backends.Value, error)
- func (f *Function) Max(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Min(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Mul(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Name() string
- func (f *Function) Neg(operand backends.Value) (backends.Value, error)
- func (f *Function) NotEqual(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) NotEqualTotalOrder(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) OptimizationBarrier(operands ...backends.Value) ([]backends.Value, error)
- func (f *Function) Pad(x, fillValue backends.Value, axesConfig ...backends.PadAxis) (backends.Value, error)
- func (f *Function) Parameter(name string, shape shapes.Shape, sharding *backends.ShardingSpec) (backends.Value, error)
- func (f *Function) Parent() backends.Function
- func (f *Function) Pow(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) QuantizedEmbeddingLookup(data, indices backends.Value, dataQuantization *backends.Quantization) (backends.Value, error)
- func (f *Function) RNGBitGenerator(state backends.Value, shape shapes.Shape) (newState backends.Value, values backends.Value, err error)
- func (f *Function) Real(operand backends.Value) (backends.Value, error)
- func (f *Function) ReduceBitwiseAnd(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceBitwiseOr(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceBitwiseXor(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceLogicalAnd(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceLogicalOr(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceLogicalXor(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceMax(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceMin(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceProduct(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceSum(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) ReduceWindow(x backends.Value, reductionType backends.ReduceOpType, ...) (backends.Value, error)
- func (f *Function) Rem(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Reshape(x backends.Value, dimensions ...int) (backends.Value, error)
- func (f *Function) Return(outputs []backends.Value, shardings []*backends.ShardingSpec) error
- func (f *Function) Reverse(x backends.Value, axes ...int) (backends.Value, error)
- func (f *Function) Round(operand backends.Value) (backends.Value, error)
- func (f *Function) Rsqrt(operand backends.Value) (backends.Value, error)
- func (f *Function) ScatterMax(operand, scatterIndices, updates backends.Value, indexVectorAxis int, ...) (backends.Value, error)
- func (f *Function) ScatterMin(operand, scatterIndices, updates backends.Value, indexVectorAxis int, ...) (backends.Value, error)
- func (f *Function) ScatterSum(operand, scatterIndices, updates backends.Value, indexVectorAxis int, ...) (backends.Value, error)
- func (f *Function) SelectAndScatterMax(operand, source backends.Value, windowDimensions, windowStrides []int, ...) (backends.Value, error)
- func (f *Function) SelectAndScatterMin(operand, source backends.Value, windowDimensions, windowStrides []int, ...) (backends.Value, error)
- func (f *Function) ShiftLeft(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) ShiftRightArithmetic(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) ShiftRightLogical(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Sign(operand backends.Value) (backends.Value, error)
- func (f *Function) Sin(operand backends.Value) (backends.Value, error)
- func (f *Function) Slice(x backends.Value, starts, limits, strides []int) (backends.Value, error)
- func (f *Function) Sort(comparator backends.Function, axis int, isStable bool, ...) ([]backends.Value, error)
- func (f *Function) Sqrt(operand backends.Value) (backends.Value, error)
- func (f *Function) Sub(lhs, rhs backends.Value) (backends.Value, error)
- func (f *Function) Tanh(operand backends.Value) (backends.Value, error)
- func (f *Function) Transpose(x backends.Value, permutation ...int) (backends.Value, error)
- func (f *Function) Where(condition, onTrue, onFalse backends.Value) (backends.Value, error)
- func (f *Function) While(cond, body backends.Function, initialState ...backends.Value) ([]backends.Value, error)
- type Node
Constants ¶
const BackendName = "xla"
BackendName is the name of the backend.
The stablehlo backend also accepts the "xla", "hlo" and "pjrt" aliases.
const NoAutoInstallEnv = "GOMLX_NO_AUTO_INSTALL"
Variables ¶
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.OpTypeIsNaN: 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.OpTypeEqualTotalOrder: true, backends.OpTypeGreaterOrEqual: true, backends.OpTypeGreaterOrEqualTotalOrder: true, backends.OpTypeGreaterThan: true, backends.OpTypeGreaterThanTotalOrder: true, backends.OpTypeLessOrEqual: true, backends.OpTypeLessOrEqualTotalOrder: true, backends.OpTypeLessThan: true, backends.OpTypeLessThanTotalOrder: true, backends.OpTypeNotEqual: true, backends.OpTypeNotEqualTotalOrder: true, backends.OpTypeComplex: true, backends.OpTypeConj: true, backends.OpTypeImag: true, backends.OpTypeReal: true, backends.OpTypeArgMinMax: true, backends.OpTypeBatchNormForInference: true, backends.OpTypeBatchNormForTraining: true, backends.OpTypeBatchNormGradient: true, backends.OpTypeBitcast: true, backends.OpTypeBroadcast: true, backends.OpTypeBroadcastInDim: true, backends.OpTypeClamp: true, backends.OpTypeConcatenate: true, backends.OpTypeConvertDType: true, backends.OpTypeConvGeneral: true, backends.OpTypeDynamicSlice: true, backends.OpTypeDynamicUpdateSlice: true, backends.OpTypeDot: true, backends.OpTypeDotGeneral: true, backends.OpTypeFFT: true, backends.OpTypeGather: true, backends.OpTypeIdentity: true, backends.OpTypeIota: true, backends.OpTypePad: 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.OpTypeReverse: true, backends.OpTypeRNGBitGenerator: true, backends.OpTypeScatterSum: true, backends.OpTypeScatterMax: true, backends.OpTypeScatterMin: true, backends.OpTypeSelectAndScatterMax: true, backends.OpTypeSelectAndScatterMin: true, backends.OpTypeShiftLeft: true, backends.OpTypeShiftRightArithmetic: true, backends.OpTypeShiftRightLogical: true, backends.OpTypeSlice: true, backends.OpTypeTranspose: true, backends.OpTypeWhere: true, backends.OpTypeAllReduce: true, }, Functions: 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, dtypes.Complex64: true, dtypes.Complex128: true, }, }
Capabilities of the SimpleGo backends: the set of supported operations and data types.
var ( // DefaultPlugins is the list of plugins to use in preference order, if not otherwise specified. DefaultPlugins = []string{"cuda", "cpu"} )
Functions ¶
func AutoInstall ¶ added in v0.26.0
func AutoInstall() error
AutoInstall the standard plugin version tested for the current go-xla version. If GPU or TPU are detected, it will also install the corresponding plugins.
This simply calls github.com/gomlx/go-xla/pkg/installer.AutoInstall(). If you want more control over the installation path, cache usage, or verbosity, you can use the AutoInstall function from go-xla's installer package directly.
func BFloat16SliceFromXLA ¶ added in v0.26.0
func BFloat16SliceFromXLA(slice []xlabfloat16.BFloat16) []bfloat16.BFloat16
BFloat16SliceFromXLA converts a go-xla []xlabfloat16.BFloat16 slice to a GoMLX []bfloat16.BFloat16 slice. Both types are defined as `type BFloat16 uint16`, so this is a zero-copy conversion using unsafe.
func BFloat16SliceToXLA ¶ added in v0.26.0
func BFloat16SliceToXLA(slice []bfloat16.BFloat16) []xlabfloat16.BFloat16
BFloat16SliceToXLA converts a GoMLX []bfloat16.BFloat16 slice to a go-xla []xlabfloat16.BFloat16 slice. Both types are defined as `type BFloat16 uint16`, so this is a zero-copy conversion using unsafe.
func DTypeFromXLA ¶ added in v0.26.0
DTypeFromXLA converts a go-xla xladtypes.DType to a GoMLX dtypes.DType. Currently, they are identical types, but this function centralizes the conversion in case they diverge in the future.
func DTypeToXLA ¶ added in v0.26.0
DTypeToXLA converts a GoMLX dtypes.DType to a go-xla xladtypes.DType. Currently, they are identical types, but this function centralizes the conversion in case they diverge in the future.
func EnableAutoInstall ¶ added in v0.26.0
func EnableAutoInstall(enable bool)
EnableAutoInstall sets whether AutoInstall should be triggered automatically for GetAvailablePlugins or New.
If enabled, the default, the AutoInstall function will be called automatically when GetAvailablePlugins or New is called.
func GetAvailablePlugins ¶
func GetAvailablePlugins() []string
GetAvailablePlugins lists the available platforms -- it caches and reuses the result in future calls.
This function triggers AutoInstall if it is enabled (the default). See EnableAutoInstall to disable it.
Plugins are searched in the PJRT_PLUGIN_LIBRARY_PATH directory -- or directories if it is a ":" separated list. If it is not set, it will search the system "/usr/local/lib/go-xla", the users $HOME/.local/lib/go-xla (or "$HOME/Library/Application Support/go-xla" in MacOS) and the standard libraries directories of the system (in linux in LD_LIBRARY_PATH and /etc/ld.so.conf file) in that order.
If there are plugins with the same name but different versions in different directories, it respects the order of the directories given by PJRT_PLUGIN_LIBRARY_PATH or by the system.
See details in pjrt.AvailablePlugins.
func New ¶
New returns a new Backend using the config as a configuration. The config string should be the name of the PJRT plugin to use.
This function triggers AutoInstall if it is enabled (the default). See EnableAutoInstall to disable it.
func ShapeFromXLA ¶ added in v0.26.0
ShapeFromXLA converts a go-xla shape to a GoMLX shape.
Types ¶
type Backend ¶
type Backend struct {
// DotGeneralUseTF32 controls whether to use TF32 for DotGeneral operations that are using float32.
// (it can be faster in modern GPUs, and it's enabled by default)
DotGeneralUseTF32 bool
// contains filtered or unexported fields
}
Backend implements the XLA/PJRT backends.Backend for GoMLX.
func NewWithOptions ¶
func NewWithOptions(config string, options pjrt.NamedValuesMap) (*Backend, error)
NewWithOptions creates a StableHLO backend with the given client options. It allows more control, not available with the default New constructor.
This function triggers AutoInstall if it is enabled (the default). See EnableAutoInstall to disable it.
func (*Backend) BufferCopyToDevice ¶ added in v0.25.0
func (backend *Backend) BufferCopyToDevice(source backends.Buffer, deviceNum backends.DeviceNum) ( bufferOnDevice backends.Buffer, err error)
BufferCopyToDevice implements the backends.Backend interface.
func (*Backend) BufferData ¶ added in v0.16.0
BufferData implements backends.Backend interface.
For XLA this means allocating the aligned memory and calling pjrt.Client.CreateViewOfDeviceBuffer to create a buffer that shares the memory.
func (*Backend) BufferDeviceNum ¶
BufferDeviceNum returns the deviceNum for the buffer.
func (*Backend) BufferFinalize ¶
BufferFinalize implements backends.DataInterface.
func (*Backend) BufferFromFlatData ¶
func (backend *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 Buffer.
func (*Backend) BufferShape ¶
BufferShape returns the shape for the buffer.
func (*Backend) BufferToFlatData ¶
BufferToFlatData transfers the flat values of buffer to the Go flat array. The slice flat must have the exact number of elements required to store the Buffer shape.
See also FlatDataToBuffer, BufferShape, and shapes.Shape.Size.
func (*Backend) Capabilities ¶ added in v0.19.0
func (backend *Backend) Capabilities() backends.Capabilities
Capabilities returns information about what is supported by this backend.
func (*Backend) CheckValid ¶ added in v0.19.3
CheckValid returns an error if the backend is not valid: if it's nil or has already been finalized.
func (*Backend) Description ¶
Description is a longer description of the Backend that can be used to pretty-print.
func (*Backend) DeviceDescription ¶ added in v0.25.0
DeviceDescription returns a description of the deviceNum.
func (*Backend) Finalize ¶
func (backend *Backend) Finalize()
Finalize releases all the associated resources immediately and makes the backend invalid.
func (*Backend) HasSharedBuffers ¶ added in v0.16.0
HasSharedBuffers returns whether this PJRT plugin supports "shared buffers". In PJRT that means supporting pjrt.Client.CreateViewOfDeviceBuffer.
func (*Backend) IsFinalized ¶ added in v0.20.0
IsFinalized returns true if the backend is in an invalid state.
func (*Backend) Name ¶
Name returns the short name of the backend. E.g.: "stablehlo" for the StableHLO/PJRT plugin.
func (*Backend) NewSharedBuffer ¶ added in v0.16.0
func (backend *Backend) NewSharedBuffer(deviceNum backends.DeviceNum, shape shapes.Shape) (buffer backends.Buffer, flat any, err error)
NewSharedBuffer implements backends.Backend interface.
For XLA this means allocating the aligned memory and calling pjrt.Client.CreateViewOfDeviceBuffer to create a buffer that shares the memory.
func (*Backend) NumDevices ¶
NumDevices return the number of devices available for this Backend.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder keeps track of the computation graph being defined.
func (*Builder) CheckValid ¶ added in v0.19.3
CheckValid returns an error if the backend or the builder are not ok.
E.g.: they have been finalized or the builder has already been compiled.
func (*Builder) DeviceAssignment ¶ added in v0.25.0
DeviceAssignment assigns the devices to the computation.
The number of devices must match the number of devices in the computation. Usually, that is 1. But if DistributedSPMD was used, it can be more.
func (*Builder) DistributedAutoSharding ¶ added in v0.25.0
DistributedAutoSharding creates a computation that will be executed on multiple devices with auto-sharding. This currently aims at XLA Shardy [1] framework. But other backends can implement it with the same semantics, if appropriate.
func (*Builder) DistributedSPMD ¶ added in v0.25.0
DistributedSPMD creates a computation that will be executed on multiple devices in SPMD fashion (SPMD = single program, multiple data).
func (*Builder) NewFunction ¶ added in v0.27.0
NewFunction creates a new named function within this builder.
type Executable ¶
type Executable struct {
// contains filtered or unexported fields
}
Executable implements the backends.Executable for XLA/PJRT github.com/gomlx/gopjrt.
func (*Executable) CheckValid ¶ added in v0.19.3
func (e *Executable) CheckValid() error
CheckValid returns an error if the backend or the executable are not ok -- e.g.: if they have been finalized or the builder has already been compiled.
func (*Executable) Execute ¶
func (e *Executable) Execute( inputs []backends.Buffer, donate []bool, defaultDevice backends.DeviceNum, ) ([]backends.Buffer, error)
Execute the executable on the default device (0). The number and shapes of the inputs must match those returned by Inputs.
func (*Executable) Finalize ¶
func (e *Executable) Finalize()
Finalize immediately frees resources associated with the executable.
func (*Executable) Inputs ¶
func (e *Executable) Inputs() (names []string, inputShapes []shapes.Shape)
Inputs returns the parameters' names and shapes, in order created by the Builder.Parameter calls.
func (*Executable) Outputs ¶
func (e *Executable) Outputs() (outputShapes []shapes.Shape)
Outputs return the computation's output shapes, in the order given to the Builder.Compile call.
type Function ¶ added in v0.27.0
type Function struct {
// contains filtered or unexported fields
}
Function implements backends.Function for XLA.
func (*Function) Abs ¶ added in v0.27.0
Abs returns the Op that represents the output of the corresponding operation.
It is special-cased here because StableHLO doesn't define the Abs() of complex numbers.
func (*Function) Add ¶ added in v0.27.0
Add returns the element-wise sum of the two values. Standard broadcasting rules apply (see documentation).
func (*Function) AllReduce ¶ added in v0.27.0
func (f *Function) AllReduce(operands []backends.Value, reductionType backends.ReduceOpType, replicaGroups [][]int) ([]backends.Value, error)
AllReduce implements the collective AllReduce operation.
func (*Function) ArgMinMax ¶ added in v0.27.0
func (f *Function) ArgMinMax(x backends.Value, axis int, outputDType dtypes.DType, isMin bool) (backends.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 (*Function) Atan2 ¶ added in v0.27.0
Atan2 returns element-wise the arc tangent of y/x, using the signs of both arguments to determine the correct quadrant of the result. Standard broadcasting rules apply (see documentation).
func (*Function) BatchNormForInference ¶ added in v0.27.0
func (f *Function) BatchNormForInference(input, scale, offset, mean, variance backends.Value, epsilon float32, featureAxis int) (backends.Value, error)
BatchNormForInference implements backends.Function interface.
func (*Function) BatchNormForTraining ¶ added in v0.27.0
func (f *Function) BatchNormForTraining(input, scale, offset backends.Value, epsilon float32, featureAxis int) (output, batchMean, batchVar backends.Value, err error)
BatchNormForTraining implements backends.Function interface.
func (*Function) BatchNormGradient ¶ added in v0.27.0
func (f *Function) BatchNormGradient(gradOutput, input, scale, mean, variance backends.Value, epsilon float32, featureAxis int) (gradInput, gradScale, gradOffset backends.Value, err error)
BatchNormGradient implements backends.Function interface.
func (*Function) BitCount ¶ added in v0.27.0
BitCount returns the number of bits that are set to one. Also known as Population Count ("Popcnt") or Hamming Weight.
func (*Function) BitwiseAnd ¶ added in v0.27.0
BitwiseAnd returns the element-wise bitwise AND operation.
func (*Function) BitwiseNot ¶ added in v0.27.0
BitwiseNot returns the element-wise bitwise AND operation.
func (*Function) BitwiseOr ¶ added in v0.27.0
BitwiseOr returns the element-wise bitwise OR operation.
func (*Function) BitwiseXor ¶ added in v0.27.0
BitwiseXor returns the element-wise bitwise XOR operator.
func (*Function) BroadcastInDim ¶ added in v0.27.0
func (f *Function) BroadcastInDim(x backends.Value, outputShape shapes.Shape, broadcastAxes []int) (backends.Value, error)
BroadcastInDim broadcasts x to an output with the given shape. broadcastAxes has an output axes value for each x 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 (*Function) Call ¶ added in v0.27.0
func (f *Function) Call(target backends.Function, inputs ...backends.Value) ([]backends.Value, error)
Call implements the backends.Function interface.
func (*Function) Ceil ¶ added in v0.27.0
Ceil returns the Op that represents the output of the corresponding operation.
func (*Function) CheckValid ¶ added in v0.27.0
CheckValid returns an error if the builder or the function are not ok.
func (*Function) Clamp ¶ added in v0.27.0
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 (*Function) Closure ¶ added in v0.27.0
Closure creates a new closure function, within this function.
func (*Function) Clz ¶ added in v0.27.0
Clz returns element-wise the "count leading zeros" bits of input node x -- for integer values.
func (*Function) Complex ¶ added in v0.27.0
Complex returns the complex number taking x0 as the real part and x1 as the imaginary part. The real (x0) and imaginary (x1) must have the same dtype, and they must be either `dtypes.Float32` or `dtypes.Float64`. The output will be either `dtypes.Complex64` or `dtypes.Complex128`, depending on x0 and x1 dtypes. The shapes of `real` or `imaginary` must be the same, or one must be a scalar, in which case the value is broadcast to every other value.
func (*Function) Concatenate ¶ added in v0.27.0
Concatenate operands on the given axis.
All axes that are not being concatenated must match dimensions, except on the axes being concatenated. It doesn't work with scalars -- use ExpandAxes. If there is only one operand, it is returned and this is a no-op.
func (*Function) Conj ¶ added in v0.27.0
Conj returns the conjugate of a complex number. E.g: Conj(1+3i) = 1-3i
func (*Function) Constant ¶ added in v0.27.0
Constant creates a constant in the function with the given flat values and the shape defined by the dimensions.
func (*Function) ConvGeneral ¶ added in v0.27.0
func (f *Function) ConvGeneral(input, kernel backends.Value, axes backends.ConvolveAxesConfig, strides []int, paddings [][2]int, inputDilations, kernelDilations []int, channelGroupCount, batchGroupCount int) (backends.Value, error)
ConvGeneral implements the backends.Function interface.
func (*Function) ConvertDType ¶ added in v0.27.0
ConvertDType implements backends.Function interface.
func (*Function) Cos ¶ added in v0.27.0
Cos returns the Op that represents the output of the corresponding operation.
func (*Function) Div ¶ added in v0.27.0
Div returns the element-wise division of the two values. Standard broadcasting rules apply (see documentation).
func (*Function) DotGeneral ¶ added in v0.27.0
func (f *Function) DotGeneral( lhs backends.Value, lhsContractingAxes, lhsBatchAxes []int, rhs backends.Value, rhsContractingAxes []int, rhsBatchAxes []int, config backends.DotGeneralConfig) (backends.Value, 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.
The XLA implementation only supports accumulation in F32 (if different than the input dtypes). So when it receives a different accumulation dtype, it simply converts the inputs to F32.
func (*Function) DynamicSlice ¶ added in v0.27.0
func (f *Function) DynamicSlice(operand backends.Value, startIndices []backends.Value, sliceDims []int) (backends.Value, error)
DynamicSlice extracts a slice from the operand at the startIndices position and the given sliceSizes.
- operand: tensor from where to take the slice. - startIndices: scalar tensors, one per axis of operand: len(startIndices) == operand.Rank(). - sliceSizes: static values and fixed to keep the shape of the output static.
The startIndices are adjusted as follows:
adjustedStartIndices[i] = clamp(0, StartIndices[i], operand.Dimensions[i] - sliceSizes[i])
See description in https://openxla.org/xla/operation_semantics#dynamicslice
func (*Function) DynamicUpdateSlice ¶ added in v0.27.0
func (f *Function) DynamicUpdateSlice(operand, update backends.Value, startIndices []backends.Value) (backends.Value, error)
DynamicUpdateSlice updates the operand with the values given in update, at the position given by startIndices.
- operand: original value that to be updated. - update: values to "paste" on top of operand, at position startIndices. - startIndices: scalar tensors, one per axis of operand: len(startIndices) == operand.Rank(). - sliceSizes: static values and fixed to keep the shape of the output static.
It returns a value with the same shape as the operand, with the values updated.
The startIndices are adjusted as follows:
adjustedStartIndices[i] = clamp(0, StartIndices[i], operand.Dimensions[i] - update.Dimensions[i])
func (*Function) Equal ¶ added in v0.27.0
Equal returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) EqualTotalOrder ¶ added in v0.27.0
EqualTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) Erf ¶ added in v0.27.0
Erf returns the "error function", defined as erf(x) = 2/Pi * \int_{0}^{x}{e^{-t^2}dt}.
func (*Function) Exp ¶ added in v0.27.0
Exp returns the Op that represents the output of the corresponding operation.
func (*Function) Expm1 ¶ added in v0.27.0
Expm1 returns the Op that represents the output of the corresponding operation.
func (*Function) FFT ¶ added in v0.27.0
func (f *Function) FFT(x backends.Value, fftType backends.FFTType, fftLength []int) (backends.Value, error)
FFT implements the Fast Fourier Transform operation. fftType specifies the type of FFT operation to perform. fftLength specifies the length of the transform for each axis.
func (*Function) Floor ¶ added in v0.27.0
Floor returns the Op that represents the output of the corresponding operation.
func (*Function) FusedAttentionQKVProjection ¶ added in v0.27.0
func (*Function) FusedDense ¶ added in v0.27.0
func (*Function) FusedLayerNorm ¶ added in v0.27.0
func (*Function) FusedQuantizedDense ¶ added in v0.27.0
func (f *Function) FusedQuantizedDense(x, weights, bias backends.Value, weightsQuantization *backends.Quantization, activation backends.ActivationType) (backends.Value, error)
func (*Function) FusedScaledDotProductAttention ¶ added in v0.27.0
func (*Function) FusedSoftmax ¶ added in v0.27.0
func (*Function) Gather ¶ added in v0.27.0
func (f *Function) Gather(operand, startIndices backends.Value, indexVectorAxis int, offsetOutputAxes, collapsedSliceAxes, startIndexMap, sliceSizes []int, indicesAreSorted bool) (backends.Value, error)
Gather is a powerful but cumbersome Gather operation. See details in the backend.
Notice GoMLX backend Gather operation doesn't support batching axes, which StableHLO does. For compatibility, we simply leave them empty.
func (*Function) GreaterOrEqual ¶ added in v0.27.0
GreaterOrEqual returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) GreaterOrEqualTotalOrder ¶ added in v0.27.0
GreaterOrEqualTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) GreaterThan ¶ added in v0.27.0
GreaterThan returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) GreaterThanTotalOrder ¶ added in v0.27.0
GreaterThanTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) Identity ¶ added in v0.27.0
Identity returns an Op whose output is the same as its input. It's a no-op that can serve as a place-holder.
func (*Function) If ¶ added in v0.27.0
func (f *Function) If(pred backends.Value, trueBranch, falseBranch backends.Function) ([]backends.Value, error)
If executes one of two branches based on a predicate.
func (*Function) Imag ¶ added in v0.27.0
Imag returns the imaginary part of a complex number. It returns 0 if the x is a float number.
func (*Function) IsFinite ¶ added in v0.27.0
IsFinite tests whether each element of operand is finite, i.e., if it is not positive nor negative infinity, and it is not NaN. It returns the same shape as the input, but with boolean values where each element is true if and only if the corresponding input element is finite.
func (*Function) LessOrEqual ¶ added in v0.27.0
LessOrEqual returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) LessOrEqualTotalOrder ¶ added in v0.27.0
LessOrEqualTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) LessThan ¶ added in v0.27.0
LessThan returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) LessThanTotalOrder ¶ added in v0.27.0
LessThanTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) Log ¶ added in v0.27.0
Log returns the Op that represents the output of the corresponding operation.
func (*Function) LogicalAnd ¶ added in v0.27.0
LogicalAnd returns the element-wise logical AND operation.
func (*Function) LogicalNot ¶ added in v0.27.0
LogicalNot returns the Op that represents the output of the corresponding operation.
func (*Function) LogicalOr ¶ added in v0.27.0
LogicalOr returns the element-wise logical OR operation.
func (*Function) LogicalXor ¶ added in v0.27.0
LogicalXor returns the element-wise logical XOR operator.
func (*Function) Logistic ¶ added in v0.27.0
Logistic returns the element-wise expression 1/(1+exp(-x)). Also known as the Sigmoid function.
func (*Function) Mul ¶ added in v0.27.0
Mul returns the element-wise multiplication of the two values. Standard broadcasting rules apply (see documentation).
func (*Function) Neg ¶ added in v0.27.0
Neg returns the Op that represents the output of the corresponding operation.
func (*Function) NotEqual ¶ added in v0.27.0
NotEqual returns the element-wise operation. Standard broadcasting rules apply (see documentation).
func (*Function) NotEqualTotalOrder ¶ added in v0.27.0
NotEqualTotalOrder returns the element-wise operation. Standard broadcasting rules apply (see documentation).
The "TotalOrder" version of the operation enforces `-NaN < -Inf < -Finite < -0 < +0 < +Finite < +Inf < +NaN`.
func (*Function) OptimizationBarrier ¶ added in v0.27.2
OptimizationBarrier returned values are identity to the operands, but they become only available in compilation time once all the inptus are calculated.
func (*Function) Pad ¶ added in v0.27.0
func (f *Function) Pad(x, fillValue backends.Value, axesConfig ...backends.PadAxis) (backends.Value, error)
Pad injects padding on the start, end, or interior (in between each element) of the given operand. There must be at most `operand.Rank()` axesConfig values. Missing PadAxis are assumed to be zeros, that is, no padding for those axes.
func (*Function) Parameter ¶ added in v0.27.0
func (f *Function) Parameter(name string, shape shapes.Shape, sharding *backends.ShardingSpec) ( backends.Value, error)
Parameter creates an input parameter for this function.
func (*Function) Pow ¶ added in v0.27.0
Pow returns the Op that represents the output of the corresponding operation.
func (*Function) QuantizedEmbeddingLookup ¶ added in v0.27.3
func (*Function) RNGBitGenerator ¶ added in v0.27.0
func (f *Function) RNGBitGenerator(state backends.Value, shape shapes.Shape) (newState backends.Value, values backends.Value, err error)
RNGBitGenerator generates the given shape filled with random bits.
It takes as input a state (usually [3]uint64) and returns the updated state and the generated values (with random bits).
Currently, the backend only supports the Philox algorithm. See https://dl.acm.org/doi/10.1145/2063384.2063405
func (*Function) Real ¶ added in v0.27.0
Real return the real part of a complex number. It returns x if the x is a float number.
func (*Function) ReduceBitwiseAnd ¶ added in v0.27.0
ReduceBitwiseAnd implements the corresponding method of the backends.Function interface.
func (*Function) ReduceBitwiseOr ¶ added in v0.27.0
ReduceBitwiseOr implements the corresponding method of the backends.Function interface.
func (*Function) ReduceBitwiseXor ¶ added in v0.27.0
ReduceBitwiseXor implements the corresponding method of the backends.Function interface.
func (*Function) ReduceLogicalAnd ¶ added in v0.27.0
ReduceLogicalAnd implements the corresponding method of the backends.Function interface.
func (*Function) ReduceLogicalOr ¶ added in v0.27.0
ReduceLogicalOr implements the corresponding method of the backends.Function interface.
func (*Function) ReduceLogicalXor ¶ added in v0.27.0
ReduceLogicalXor implements the corresponding method of the backends.Function interface.
func (*Function) ReduceMax ¶ added in v0.27.0
ReduceMax implements the corresponding method of the backends.Function interface.
func (*Function) ReduceMin ¶ added in v0.27.0
ReduceMin implements the corresponding method of the backends.Function interface.
func (*Function) ReduceProduct ¶ added in v0.27.0
ReduceProduct implements the corresponding method of the backends.Function interface.
func (*Function) ReduceSum ¶ added in v0.27.0
ReduceSum implements the corresponding method of the backends.Function interface.
func (*Function) ReduceWindow ¶ added in v0.27.0
func (f *Function) ReduceWindow(x backends.Value, reductionType backends.ReduceOpType, windowDimensions, strides, baseDilations, windowDilations []int, paddings [][2]int) (backends.Value, error)
ReduceWindow runs a reduction function of the type given by reduceType. It can be either ReduceMaxNode, ReduceSumNode or ReduceMultiplyNode.
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 (*Function) Rem ¶ added in v0.27.0
Rem returns the remainder operation, also known as modulo (or Mod for short). Notice despite the name XLA implements Mod not IEEE754 Remainder operation.
func (*Function) Round ¶ added in v0.27.0
Round returns the Op that represents the output of the corresponding operation. This operation rounds to the nearest even.
func (*Function) Rsqrt ¶ added in v0.27.0
Rsqrt returns the element-wise reciprocal of square root operation 1/sqrt(x).
func (*Function) ScatterMax ¶ added in v0.27.0
func (f *Function) ScatterMax(operand, scatterIndices, updates backends.Value, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Value, error)
ScatterMax scatter values from updates pointed by scatterIndices to operand, by taking the Max.
func (*Function) ScatterMin ¶ added in v0.27.0
func (f *Function) ScatterMin(operand, scatterIndices, updates backends.Value, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Value, error)
ScatterMin scatter values from updates pointed by scatterIndices to operand, by taking the Min.
func (*Function) ScatterSum ¶ added in v0.27.0
func (f *Function) ScatterSum(operand, scatterIndices, updates backends.Value, indexVectorAxis int, updateWindowAxes, insertedWindowAxes, scatterAxesToOperandAxes []int, indicesAreSorted, uniqueIndices bool) (backends.Value, error)
ScatterSum values from updates pointed by scatterIndices to operand.
func (*Function) SelectAndScatterMax ¶ added in v0.27.0
func (f *Function) SelectAndScatterMax(operand, source backends.Value, windowDimensions, windowStrides []int, paddings [][2]int) (backends.Value, error)
SelectAndScatterMax runs windows (similar to ReduceWindow) over the operand and selects the lowest values to update the output (like ScatterSum)
It selects the values in the window such that it works as reverse for a PoolMax operation.
Note: "Max" refers to the selection. After selected, the values are added into the output position.
See details in https://openxla.org/xla/operation_semantics#selectandscatter
func (*Function) SelectAndScatterMin ¶ added in v0.27.0
func (f *Function) SelectAndScatterMin(operand, source backends.Value, windowDimensions, windowStrides []int, paddings [][2]int) (backends.Value, error)
SelectAndScatterMin runs windows (similar to ReduceWindow) over the operand and selects the lowest values to update the output (like ScatterSum)
It selects the values in the window such that it works as reverse for a PoolMax operation.
Note: "Min" refers to the selection. After selected, values are added into the output position.
See details in https://openxla.org/xla/operation_semantics#selectandscatter
func (*Function) ShiftLeft ¶ added in v0.27.0
ShiftLeft n bits. It implicitly preserves the sign bit if there is no overflow. So ShiftLeft(-1, 1) = -2.
func (*Function) ShiftRightArithmetic ¶ added in v0.27.0
ShiftRightArithmetic shifts right by n bits, preserving the sign bit. So ShiftRight(-2, 1) = -1.
func (*Function) ShiftRightLogical ¶ added in v0.27.0
ShiftRightLogical shifts right by n bits, destroying the sign bit.
func (*Function) Sign ¶ added in v0.27.0
Sign returns element-wise +1, +/-0 or -1 depending on the sign of x. It returns NaN if the input is NaN.
func (*Function) Sin ¶ added in v0.27.0
Sin returns the Op that represents the output of the corresponding operation.
func (*Function) Sort ¶ added in v0.27.0
func (f *Function) Sort(comparator backends.Function, axis int, isStable bool, inputs ...backends.Value) ([]backends.Value, error)
Sort sorts one or more tensors along the specified axis using a comparator function.
func (*Function) Sqrt ¶ added in v0.27.0
Sqrt returns the Op that represents the output of the corresponding operation.
func (*Function) Sub ¶ added in v0.27.0
Sub returns the element-wise subtraction of the two values. Standard broadcasting rules apply (see documentation).
func (*Function) Tanh ¶ added in v0.27.0
Tanh returns the Op that represents the output of the corresponding operation.
func (*Function) Transpose ¶ added in v0.27.0
Transpose implements backends.Function interface. It transposes input tensor x according to the given permutation axes.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cpu
|
|
|
dynamic
Package dynamic links the XLA/PJRT CPU plugin dynamically (as in ".so" libraries) with your binary.
|
Package dynamic links the XLA/PJRT CPU plugin dynamically (as in ".so" libraries) with your binary. |
|
static
Package static links the XLA/PJRT CPU plugin statically with your binary.
|
Package static links the XLA/PJRT CPU plugin statically with your binary. |