Index
Aggregate
dataclass
¶
Bases: LogicTree, LogicExpression
Represents a logical AST statement that reduces arg using op, starting
with init. idxs are the dimensions to reduce. May happen in any order.
init may be a literal or a tensor expression. The fields of the result
are those of arg which are not reduced, followed by the fields of init
which are not in arg. init and arg are broadcast over the fields of
the result which they lack, as in a MapJoin.
Attributes:
| Name | Type | Description |
|---|---|---|
op |
Literal
|
The reduction operation. |
init |
LogicExpression
|
The initial value for the reduction. |
arg |
LogicExpression
|
The argument to reduce. |
idxs |
tuple[Field, ...]
|
The dimensions to reduce. |
Source code in src/finch/finch_logic/nodes.py
Alias
dataclass
¶
Shared base for hard and fused aliases referring to tensors.
Source code in src/finch/finch_logic/nodes.py
DefaultProtocol
dataclass
¶
Extrude
dataclass
¶
Field
dataclass
¶
Represents a logical AST expression for a field named name.
Fields are used to name the dimensions of a tensor. The named
tensor is referred to as a "table".
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the field. |
Source code in src/finch/finch_logic/nodes.py
FillTable
dataclass
¶
Bases: LogicTree, LogicExpression
Represents a logical AST expression for the fill value of the tensor tns,
as a zero-dimensional tensor. Like a literal, it has no fields, but its
value is only known once tns is bound.
Attributes:
| Name | Type | Description |
|---|---|---|
tns |
Alias
|
The alias of the tensor whose fill value is taken. |
Source code in src/finch/finch_logic/nodes.py
Follow
dataclass
¶
Fuse
dataclass
¶
Bases: LogicTree, LogicStatement
Executes body together for each value of idx. Enclosing Fuse nodes,
from outermost to innermost, bind the leading indices of FusedAlias tables.
Attributes:
| Name | Type | Description |
|---|---|---|
idx |
Field
|
The field over which to fuse the body. |
body |
LogicStatement
|
The statement to execute for each value of the field. |
Source code in src/finch/finch_logic/nodes.py
FusedAlias
dataclass
¶
Bases: Alias
An alias whose first n dimensions index independent scratch tensors.
The remaining dimensions are materialized within each scratch tensor. Bindings use the wrapped alias and describe the full logical shape.
Source code in src/finch/finch_logic/nodes.py
Gallop
dataclass
¶
HardAlias
dataclass
¶
Bases: Alias
A named tensor alias whose dimensions are all materialized.
Source code in src/finch/finch_logic/nodes.py
Laminate
dataclass
¶
Literal
dataclass
¶
Bases: LogicExpression, LiteralTerm, ExpressionTerm
Represents a logical AST expression for the literal value val.
A literal behaves as a zero-dimensional tensor: it has no fields, and its
element type and fill value are those of val itself.
Attributes:
| Name | Type | Description |
|---|---|---|
val |
T
|
The literal value. |
Source code in src/finch/finch_logic/nodes.py
LogicEvaluator
¶
Bases: Stage
Source code in src/finch/finch_logic/stages.py
LogicExpression
dataclass
¶
Bases: LogicNode
Logic AST expression base class.
A Logic expression is a program node which evaluates to a TableValue, a tensor with named dimensions.
Source code in src/finch/finch_logic/nodes.py
dimmap(op, dim_bindings)
abstractmethod
¶
Compute per-dimension values, combining using op. When dimensions
are expanded, None is used. When dimensions are contracted, the value
is combined with None.
Source code in src/finch/finch_logic/nodes.py
element_type(bindings)
¶
fields()
abstractmethod
¶
fill_type(bindings)
¶
Returns the fill of the node's format.
fill_value(bindings)
¶
shape(dim_bindings)
¶
shape_type(dim_bindings)
¶
Returns the shape type of the node.
valmap(f, g, h, bindings)
abstractmethod
¶
Compute per-tensor values. The value of an alias comes from
bindings, and the value of a literal is h(fill) of its fill value.
f(op, args) is used to combine values in mapjoin, and
g(op, init, arg) is used to combine values in aggregation.
Source code in src/finch/finch_logic/nodes.py
LogicLoader
¶
Bases: Stage
Source code in src/finch/finch_logic/stages.py
lower(prgm, bindings, stats, stats_factory)
abstractmethod
¶
Generate Finch Library from the given logic and input types, with a
single method called main which implements the logic. Also return a
dictionary including additional tables needed to run the kernel.
Source code in src/finch/finch_logic/stages.py
LogicNode
dataclass
¶
LogicNode
Represents a Finch Logic IR node. Finch uses a variant of Concrete Field Notation as an intermediate representation.
The LogicNode struct represents many different Finch IR nodes.
Source code in src/finch/finch_logic/nodes.py
__str__()
¶
LogicSimplify
¶
Bases: UnvalidatedForm, LogicLoader
Simplify a logic program before it is lowered.
Source code in src/finch/finch_logic/simplification.py
LogicStatement
dataclass
¶
Bases: LogicNode
Logic AST statement base class.
A Logic statement may modify the state of the machine by assigning tensors to Aliases.
Logic statements evaluate to a tuple of tensors.
Source code in src/finch/finch_logic/nodes.py
infer_dimmap(op, dim_bindings)
abstractmethod
¶
Infers dimmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_element_type(bindings)
¶
Infers element types for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_fill_type(bindings)
¶
Infers the fills of the formats of all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_fill_value(bindings)
¶
Infers fill_values for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_shape(dim_bindings)
¶
Infers shapes for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_shape_type(dim_bindings)
¶
Infers shape_type for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_valmap(f, g, h, bindings)
abstractmethod
¶
Infers valmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
MapJoin
dataclass
¶
Bases: LogicTree, LogicExpression, CallTerm
Represents a logical AST expression for mapping the function op across args....
Dimensions which are not present are broadcasted. Dimensions which are
present must match. The order of fields in the mapjoin is
unique(vcat(map(getfields, args)...))
Attributes:
| Name | Type | Description |
|---|---|---|
op |
Literal
|
The function to map. |
args |
tuple[LogicExpression, ...]
|
The arguments to map the function across. |
Source code in src/finch/finch_logic/nodes.py
children
property
¶
Returns the children of the node.
Plan
dataclass
¶
Bases: LogicTree, LogicStatement
Represents a logical AST statement that executes a sequence of statements
bodies.... Returns the last statement.
Attributes:
| Name | Type | Description |
|---|---|---|
bodies |
tuple[LogicStatement, ...]
|
The sequence of statements to execute. |
Source code in src/finch/finch_logic/nodes.py
children
property
¶
Returns the children of the node.
infer_dimmap(op, dim_bindings)
¶
Infers dimmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_valmap(f, g, h, bindings)
¶
Infers valmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
Produces
dataclass
¶
Bases: LogicTree, LogicStatement
Represents a logical AST statement that returns args... from the current plan.
Halts execution of the program.
Attributes:
| Name | Type | Description |
|---|---|---|
args |
tuple[Alias | LogicExpression, ...]
|
The arguments to return. |
Source code in src/finch/finch_logic/nodes.py
children
property
¶
Returns the children of the node.
infer_dimmap(op, dim_bindings)
¶
Infers dimmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_valmap(f, g, h, bindings)
¶
Infers valmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
Protocol
dataclass
¶
Query
dataclass
¶
Bases: LogicTree, LogicStatement
Represents a logical AST statement that evaluates rhs, storing the result
in the table lhs. The alias lhs.tns is bound to a tensor whose
dimensions are ordered as lhs.idxs, so a query behaves as though its
right-hand side were wrapped in Reorder(rhs, lhs.idxs). A query is not
in place: the previous value of lhs.tns is replaced, and is only read if
rhs refers to it. See QueryInto for in-place updates.
Attributes:
| Name | Type | Description |
|---|---|---|
lhs |
Table
|
The table to write, a |
rhs |
LogicExpression
|
The right-hand side to evaluate. |
Source code in src/finch/finch_logic/nodes.py
children
property
¶
Returns the children of the node.
infer_dimmap(op, dim_bindings)
¶
Infers dimmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_valmap(f, g, h, bindings)
¶
Infers valmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
QueryInto
dataclass
¶
Bases: LogicTree, LogicStatement
Represents a logical AST statement that updates the table lhs in place,
using the reduction operator op to fold each element of rhs into the
matching element of lhs. The alias lhs.tns must already be bound, and
its shape is preserved. The fields of rhs which are not in lhs.idxs
are reduced with op, and rhs is broadcast over the fields of lhs
which it lacks, so a QueryInto is equivalent to the aggregate which
starts from lhs,
Query(lhs, Aggregate(op, lhs, rhs, setdiff(rhs.fields(), lhs.idxs))).
Attributes:
| Name | Type | Description |
|---|---|---|
lhs |
Table
|
The table to update, a |
op |
Literal
|
The reduction operator used to combine old and new values. |
rhs |
LogicExpression
|
The right-hand side to evaluate. |
Source code in src/finch/finch_logic/nodes.py
children
property
¶
Returns the children of the node.
as_query()
¶
The equivalent aggregate query, which is not in place.
infer_dimmap(op, dim_bindings)
¶
Infers dimmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
infer_valmap(f, g, h, bindings)
¶
Infers valmaps for all aliases defined in the statement. The results will be stored in the dictionary passed to the method.
Source code in src/finch/finch_logic/nodes.py
Relabel
dataclass
¶
Bases: LogicTree, LogicExpression
Represents a logical AST statement that relabels the dimensions of arg to be
idxs.... Number of fields of arg and idxs must match.
Attributes:
| Name | Type | Description |
|---|---|---|
arg |
LogicExpression
|
The argument to relabel. |
idxs |
tuple[Field, ...]
|
The new labels for dimensions. |
Source code in src/finch/finch_logic/nodes.py
Reorder
dataclass
¶
Bases: LogicTree, LogicExpression
Represents a logical AST statement that reorders the dimensions of arg to be
idxs.... Dimensions known to be length 1 may be dropped. Dimensions that do not
exist in arg may be added.
Attributes:
| Name | Type | Description |
|---|---|---|
arg |
LogicExpression
|
The argument to reorder. |
idxs |
tuple[Field, ...]
|
The new order of dimensions. |
Source code in src/finch/finch_logic/nodes.py
StatsFactory
¶
Source code in src/finch/finch_logic/tensor_stats.py
support(stat)
¶
Statistics of the boolean indicator of non-fill entries.
Source code in src/finch/finch_logic/tensor_stats.py
Table
dataclass
¶
Bases: LogicTree, LogicExpression
Represents a logical AST expression for a tensor object tns, indexed by fields
idxs.... A table is a tensor with named dimensions.
Attributes:
| Name | Type | Description |
|---|---|---|
tns |
Literal | Alias
|
The tensor object. |
idxs |
tuple[Field, ...]
|
The fields indexing the tensor. |
protocols |
tuple[Protocol, ...]
|
How a loop visits each field of the table when it reads it, or none to let the tensor choose every protocol. |
Source code in src/finch/finch_logic/nodes.py
TensorStats
¶
Bases: ABC
Source code in src/finch/finch_logic/tensor_stats.py
fill_type
abstractmethod
property
writable
¶
The fill of the tensor's format, which a kernel may depend on.
Value
dataclass
¶
Walk
dataclass
¶
fill_expression(ex)
¶
A zero-dimensional expression for the fill value of ex, made of the fill
values of the tensors which ex reads.
Source code in src/finch/finch_logic/nodes.py
is_fill_expression(ex)
¶
Whether ex is made of literals and fill values, as fill_expression.
Source code in src/finch/finch_logic/nodes.py
parse_logic(text, namespace=None)
¶
Parse a program, or an expression, as LogicNode.str prints it. Names in literals are looked up in LITERALS, updated with namespace if given, which can name values that don't print as text, such as tensors.