Documentation
¶
Overview ¶
Package elements provides generic elements, independent of the evaluator, for the interpreter.
Index ¶
- func AxesFromElement(el Element) ([]int, error)
- func ConstantFromElement(el Element) *values.HostArray
- func ConstantIntFromElement(el Element) (val int, err error)
- func ConstantScalarFromElement[T dtype.GoDataType](el Element) (val T, err error)
- func FuncDeclFromElement(el Element) (*ir.FuncDecl, error)
- func HostValueFromContext(ci *InputValues, el Element) (*values.HostArray, error)
- func ParseCompositeOf[T values.Value](f func(ir.Type, []values.Value) (T, error)) func(ir.Type, []values.Value) (values.Value, error)
- func ShapeFromElement(node Element) (*shape.Shape, error)
- func StringFromElement(el Element) (string, error)
- type ArrayOps
- type ArraySlicer
- type CallAt
- type Copier
- type Element
- type ElementWithArrayFromContext
- type ElementWithConstant
- type ExprAt
- type FieldAt
- type FileContext
- type Func
- type FuncEvaluator
- type InputElements
- type InputValues
- type Materialiser
- type NamedType
- func (n *NamedType) Flatten() ([]Element, error)
- func (n *NamedType) Kind() ir.Kind
- func (n *NamedType) NamedType() *ir.NamedType
- func (n *NamedType) RecvCopy() *NamedType
- func (n *NamedType) Select(expr SelectAt) (Element, error)
- func (n *NamedType) String() string
- func (n *NamedType) Unflatten(handles *Unflattener) (values.Value, error)
- type NewFunc
- type Node
- type NodeAt
- type NodeFile
- func (ea NodeFile[T]) ExprSrc() ast.Expr
- func (ea NodeFile[T]) FSet() *token.FileSet
- func (ea NodeFile[T]) File() *ir.File
- func (ea NodeFile[T]) Node() T
- func (ea NodeFile[T]) NodeFile() NodeFile[ir.Node]
- func (ea NodeFile[T]) String() string
- func (ea NodeFile[T]) ToExprAt() ExprAt
- func (ea NodeFile[T]) ToNodeAt() NodeAt
- func (ea NodeFile[T]) ToValueAt() ValueAt
- type NumericalElement
- type Package
- func (pkg *Package) Define(name string, el Element)
- func (pkg *Package) Flatten() ([]Element, error)
- func (pkg *Package) Kind() ir.Kind
- func (pkg *Package) Select(sel SelectAt) (Element, error)
- func (pkg *Package) String() string
- func (pkg *Package) Unflatten(handles *Unflattener) (values.Value, error)
- type PackageVarSetElement
- type Receiver
- type SelectAt
- type Selector
- type Slice
- func (n *Slice) Compare(x canonical.Comparable) bool
- func (n *Slice) Elements() []Element
- func (n *Slice) Expr() (ir.AssignableExpr, error)
- func (n *Slice) Flatten() ([]Element, error)
- func (*Slice) Kind() ir.Kind
- func (n *Slice) Len() int
- func (n *Slice) Slice(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (Element, error)
- func (n *Slice) String() string
- func (n *Slice) Unflatten(handles *Unflattener) (values.Value, error)
- type Slicer
- type StorageAt
- type String
- type Struct
- func (n *Struct) Copy() Copier
- func (n *Struct) Flatten() ([]Element, error)
- func (*Struct) Kind() ir.Kind
- func (n *Struct) Select(expr SelectAt) (Element, error)
- func (n *Struct) SetField(name string, value Element)
- func (n *Struct) String() string
- func (n *Struct) StructType() *ir.StructType
- func (n *Struct) Unflatten(handles *Unflattener) (values.Value, error)
- type Tuple
- func (n *Tuple) Elements() []Element
- func (n *Tuple) Flatten() ([]Element, error)
- func (*Tuple) Kind() ir.Kind
- func (n *Tuple) Slice(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (Element, error)
- func (n *Tuple) String() string
- func (n *Tuple) Unflatten(handles *Unflattener) (values.Value, error)
- type Unflattener
- func (h *Unflattener) CallInputs() *InputValues
- func (h *Unflattener) Device() platform.Device
- func (h *Unflattener) Next() platform.DeviceHandle
- func (h *Unflattener) ParseArray(expr ExprAt) (values.Array, error)
- func (h *Unflattener) ParseComposite(ncv newCompValue, typ ir.Type, els []Element) (values.Value, error)
- func (h *Unflattener) String() string
- func (h *Unflattener) Unflatten(el Element) (values.Value, error)
- type ValueAt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AxesFromElement ¶
AxesFromElement returns a shape from a state element. An error is returned if a concrete shape cannot be returned.
func ConstantFromElement ¶
ConstantFromElement returns the host value represented by an element. The function returns (nil, nil) if the element does not host a numerical value.
func ConstantIntFromElement ¶
ConstantIntFromElement returns a scalar on a host given an element.
func ConstantScalarFromElement ¶
func ConstantScalarFromElement[T dtype.GoDataType](el Element) (val T, err error)
ConstantScalarFromElement returns a scalar on a host given an element.
func FuncDeclFromElement ¶
FuncDeclFromElement extracts a function declaration from an element.
func HostValueFromContext ¶
func HostValueFromContext(ci *InputValues, el Element) (*values.HostArray, error)
HostValueFromContext returns a host value from the function call.
func ParseCompositeOf ¶
func ParseCompositeOf[T values.Value]( f func(ir.Type, []values.Value) (T, error), ) func(ir.Type, []values.Value) (values.Value, error)
ParseCompositeOf returns a function to unflatten a composite value.
func ShapeFromElement ¶
ShapeFromElement returns the shape of a numerical element.
func StringFromElement ¶
StringFromElement returns the string value stored in a element.
Types ¶
type ArrayOps ¶
type ArrayOps interface { // Graph returns the graph to which new nodes are being added. Graph() ops.Graph // SubGraph returns a new graph builder. SubGraph(name string) (ArrayOps, error) // Einsum calls an einstein sum on x and y given the expression in ref. Einsum(ref NodeFile[*ir.EinsumExpr], x, y NumericalElement) (NumericalElement, error) // BroadcastInDim the data of an array across dimensions. BroadcastInDim(expr ExprAt, x NumericalElement, axisLengths []NumericalElement) (NumericalElement, error) // Concat concatenates scalars elements into an array with one axis. Concat(expr ExprAt, xs []NumericalElement) (NumericalElement, error) // Set a slice in an array. Set(call NodeFile[*ir.CallExpr], x, updates, index Element) (Element, error) // ElementFromArray returns an element from an array GX value. ElementFromArray(expr ExprAt, val values.Array) (Node, error) }
ArrayOps are the operator implementations for arrays.
type ArraySlicer ¶
type ArraySlicer interface { NumericalElement SliceArray(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (NumericalElement, error) Type() ir.Type }
ArraySlicer is a state element with an array that can be sliced.
type Copier ¶
Copier is an interface implemented by nodes that need to be copied when passed to a function.
type Element ¶
type Element interface { // Flatten the element, that is: // returns itself if the element is atomic, // returns its components if the element is a composite. Flatten() ([]Element, error) // Unflatten creates a GX value from the next handles available in the Unflattener. Unflatten(handles *Unflattener) (values.Value, error) // Kind returns the kind of the element being stored. Kind() ir.Kind }
Element in the state.
type ElementWithArrayFromContext ¶
type ElementWithArrayFromContext interface { NumericalElement // ArrayFromContext fetches an array from the argument. ArrayFromContext(*InputValues) (values.Array, error) }
ElementWithArrayFromContext is an element able to return a concrete value from the current context. For example, a value passed as an argument to the function.
type ElementWithConstant ¶
type ElementWithConstant interface { NumericalElement // NumericalConstant returns the value of a constant represented by a node. NumericalConstant() *values.HostArray }
ElementWithConstant is an element with a concrete value that is already known.
type FileContext ¶
FileContext is context in which an op is being executed.
type Func ¶
type Func interface { Element Func() ir.Func Recv() *Receiver Call(ctx FileContext, call *ir.CallExpr, args []Element) ([]Element, error) }
Func is an element owning a callable function.
type FuncEvaluator ¶
type FuncEvaluator interface {
EvalFunc(f ir.Func, call *ir.CallExpr, args []Element) ([]Element, error)
}
FuncEvaluator is a context able to evaluate a function.
type InputElements ¶
type InputElements struct { // Values are the initial input GX values passed to the function call // before they were encapsulated in elements for the interpreter. Values InputValues // Receiver on which the function call was done. // Can be nil. Receiver Element // Args returns list of arguments passed to the interpreter at call time. Args []Element }
InputElements is the receiver and arguments with which the function was called.
type InputValues ¶
type InputValues struct { // Receiver on which the function call was done. // Can be nil. Receiver values.Value // Args returns list of arguments passed to the interpreter at call time. Args []values.Value }
InputValues are GX values passed to the function call.
type Materialiser ¶
type Materialiser interface { Element // Materialise returns the element with all its values from the graph. Materialise(ArrayOps) (Node, error) }
Materialiser is an element that can return an instance of itself composed only of elements from the backend ops.
type NamedType ¶
type NamedType struct {
// contains filtered or unexported fields
}
NamedType references a type exported by an imported package.
func NewNamedType ¶
NewNamedType returns a new node representing an exported type.
func (*NamedType) RecvCopy ¶
RecvCopy copies the underlying element and returns the element encapsulated in this named type.
func (*NamedType) Select ¶
Select returns the field given an index. Returns nil if the receiver type cannot select fields.
type Node ¶
type Node interface { Element OutNode() *ops.OutputNode }
Node is an element representing a numerical node in a compute graph.
type NodeFile ¶
NodeFile is an expression with the file in which it is declared.
func (NodeFile[T]) ToExprAt ¶
func (ea NodeFile[T]) ToExprAt() ExprAt
ToExprAt converts a type position into a generic node position.
type NumericalElement ¶
type NumericalElement interface { Element // UnaryOp applies a unary operator on x. UnaryOp(ctx FileContext, expr *ir.UnaryExpr) (NumericalElement, error) // BinaryOp applies a binary operator to x and y. // Note that the receiver can be either the left or right argument. BinaryOp(ctx FileContext, expr *ir.BinaryExpr, x, y NumericalElement) (NumericalElement, error) // Cast an element into a given data type. Cast(ctx FileContext, expr ir.AssignableExpr, target ir.Type) (NumericalElement, error) // Reshape an element. Reshape(ctx FileContext, expr ir.AssignableExpr, axisLengths []NumericalElement) (NumericalElement, error) // Shape of the value represented by the element. Shape() *shape.Shape }
NumericalElement is a node representing a numerical value.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package groups elements exported by a package.
func NewPackage ¶
NewPackage returns a package grouping everything that a package exports.
type PackageVarSetElement ¶
type PackageVarSetElement struct { // Pck is the package owning the variable. Pkg string // Index of the variable in the package definition. Var string // Value of the static variable for the compiler. Value Element }
PackageVarSetElement is an option to set a package variable to an element.
func (PackageVarSetElement) Package ¶
func (p PackageVarSetElement) Package() string
Package for which the option has been built.
type SelectAt ¶
type SelectAt = NodeFile[*ir.SelectorExpr]
SelectAt is a typed field at a given position.
type Slice ¶
type Slice struct {
// contains filtered or unexported fields
}
Slice element storing a slice of elements.
func (*Slice) Compare ¶
func (n *Slice) Compare(x canonical.Comparable) bool
Compare the slice to another canonical value.
func (*Slice) Expr ¶
func (n *Slice) Expr() (ir.AssignableExpr, error)
Expr returns the IR expression representing the slice.
func (*Slice) Slice ¶
func (n *Slice) Slice(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (Element, error)
Slice of the tuple.
type Slicer ¶
type Slicer interface {
Slice(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (Element, error)
}
Slicer is a state element that can be sliced.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is a GX string.
func NewString ¶
func NewString(str *ir.StringLiteral) (*String, error)
NewString returns a state element storing a string GX value.
func (*String) StringValue ¶
StringValue returns the string value as a GX value.
type Struct ¶
type Struct struct {
// contains filtered or unexported fields
}
Struct is an instance of a structure.
func NewStruct ¶
func NewStruct(structType *ir.StructType, expr ValueAt, fields map[string]Element) *Struct
NewStruct returns a new node representing a structure instance.
func NewStructFromElements ¶
func NewStructFromElements(structType *ir.StructType, expr ValueAt, vals []Element) *Struct
NewStructFromElements returns a new node representing a structure instance given a slice of
func (*Struct) StructType ¶
func (n *Struct) StructType() *ir.StructType
StructType returns the type of the structure.
type Tuple ¶
type Tuple struct {
// contains filtered or unexported fields
}
Tuple value grouping multiple values together.
func NewTuple ¶
NewTuple returns a tuple to store the result of a function returning more than one value.
func (*Tuple) Slice ¶
func (n *Tuple) Slice(ctx FileContext, expr ir.AssignableExpr, index NumericalElement) (Element, error)
Slice of the tuple.
type Unflattener ¶
type Unflattener struct {
// contains filtered or unexported fields
}
Unflattener unflattens the output of a graph computation into GX values.
func NewUnflattener ¶
func NewUnflattener(dev platform.Device, callInputs *InputValues, handles []platform.DeviceHandle) *Unflattener
NewUnflattener returns a new Unflattener given the output of a graph computation.
func (*Unflattener) CallInputs ¶
func (h *Unflattener) CallInputs() *InputValues
CallInputs returns the inputs with which the function was called.
func (*Unflattener) Device ¶
func (h *Unflattener) Device() platform.Device
Device returns to which transfers the host value to. TODO(b/388207169): Always transfer the value to device because C++ bindings do not support HostValue.
func (*Unflattener) Next ¶
func (h *Unflattener) Next() platform.DeviceHandle
Next returns a the next handle and moves the cursor to the succeeding handle.
func (*Unflattener) ParseArray ¶
func (h *Unflattener) ParseArray(expr ExprAt) (values.Array, error)
ParseArray the next value as an array.
func (*Unflattener) ParseComposite ¶
func (h *Unflattener) ParseComposite(ncv newCompValue, typ ir.Type, els []Element) (values.Value, error)
ParseComposite unflatten a slice of elements into a single GX value.
func (*Unflattener) String ¶
func (h *Unflattener) String() string