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
BufferizedNDArrayFormatter
¶
Bases: MonoLogicFormatter
Source code in src/finch/autoschedule/formatter/formatter.py
get_tensor_ftype(fill_type, shape_type)
¶
Return the FType of the output tensor produced within the autoscheduler.
Source code in src/finch/autoschedule/formatter/formatter.py
CompilerFormLowerer
¶
Bases: FormattedForm, LogicLoader
Pass a program in FormattedForm to a loader which expects CompilerForm. CompilerForm keeps the definitions and updates of FormattedForm, so the program is unchanged.
Source code in src/finch/autoschedule/compiler.py
CostProtocolizer
¶
Bases: FormattedForm, LogicLoader
Pass a program in FormattedForm to ctx, after choosing the protocol which each table reads each level of its formatted tensor with, as optimize_protocols does under cost_model.
Source code in src/finch/autoschedule/protocolizer/protocolize.py
DefaultLogicWorkspacer
¶
Bases: LoopOrderedForm, LogicLoader
Pass a program in LoopOrderedForm to ctx, after redirecting the queries which scatter into one field of their outputs into workspaces, as add_1d_workspaces does, without statistics. A loop orderer wraps it, so that the copies out of workspaces aren't propagated.
Source code in src/finch/autoschedule/workspacer/workspacer.py
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
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
LogicCompiler
¶
Bases: CompilerForm, LogicLoader
Compile logic using the notation loader's safety mode for shape checks.
Source code in src/finch/autoschedule/compiler.py
LogicEinsumLowerer
¶
Bases: FormattedForm, Stage
Source code in src/finch/autoschedule/stages.py
lower(prgm, bindings, stats, stats_factory)
abstractmethod
¶
Generate Einsum Notation from the given logic and input types. Also return a dictionary including additional tables needed to run the kernel.
Source code in src/finch/autoschedule/stages.py
LogicFillDropper
¶
Bases: FormattedForm, LogicLoader
Pass a program in FormattedForm to ctx, after marking the fills its aggregates compute over dense loops to be dropped, as drop_fills does.
Source code in src/finch/autoschedule/drop_fills.py
LogicFormatter
¶
Bases: LoopOrderedForm, LogicLoader
Source code in src/finch/autoschedule/stages.py
lower(prgm, bindings, stats, stats_factory)
abstractmethod
¶
Optimize the tensor formats and output orders for each query.
Source code in src/finch/autoschedule/stages.py
LogicFuseMerger
¶
Bases: LoopOrderedForm, LogicLoader
Pass a program in LoopOrderedForm to ctx, after merging its sibling Fuse nodes, as merge_sibling_fuses does, wherever the merged program is still in LoopOrderedForm, whose Fuse nodes may only run statements together when running them for each value of the field in turn means the same.
Source code in src/finch/autoschedule/fuse_merger/fuse_merger.py
LogicNotationLowerer
¶
Bases: CompilerForm, Stage
Source code in src/finch/autoschedule/stages.py
lower(term, bindings, stats, stats_factory)
abstractmethod
¶
Generate Finch Notation from the given logic and input types. Also return a dictionary including additional tables needed to run the kernel.
Source code in src/finch/autoschedule/stages.py
LogicProtocolizer
¶
Bases: FormattedForm, LogicLoader
Pass a program in FormattedForm to ctx, after reading each level of a formatted tensor with an explicit protocol, as protocolize does.
Source code in src/finch/autoschedule/protocolizer/protocolize.py
LogicWorkspacer
¶
Bases: LoopOrderedForm, LogicLoader
Pass a program in LoopOrderedForm to ctx, after redirecting the queries which scatter into their outputs into workspaces where they cost less under cost_model, by default PROTOCOL_COST_MODEL, as add_cost_effective_workspaces does, and then copying its inputs into new formats where that costs less, as add_cost_effective_reformats does. A loop orderer wraps it, so that the copies aren't propagated, and the formatter it wraps should price programs with the same model. format_cost prices a program with the formats its formatter would choose: format_cost searches them as a CostFormatter does, and galley_format_cost takes those of a GalleyFormatter, far more cheaply. Last, unless accumulators is False, each query which reduces into fixed elements of its output across its inner loops accumulates each element in a workspace which stores nothing, as add_accumulators does.
Source code in src/finch/autoschedule/workspacer/workspacer.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
PostWalk
¶
A rewriter which recursively rewrites the arguments of each node using
rw, then rewrites the resulting node. If all rewriters return nothing,
returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.py
PreWalk
¶
A rewriter which recursively rewrites each node using rw, then rewrites
the arguments of the resulting node. If all rewriters return nothing,
returns nothing.
Attributes:
| Name | Type | Description |
|---|---|---|
rw |
RwCallable
|
The rewriter function to apply. |
Source code in src/finch/symbolic/rewriters.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
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
SmartFormatter
¶
Bases: LogicFormatter
Source code in src/finch/autoschedule/formatter/smart_formatter.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
get_tensor_ftype(fill_type, shape_type, stats, over=())
abstractmethod
¶
The format of a tensor with the given stats. If over lists
fields, each tensor stores one slice which fixes those fields.
Source code in src/finch/autoschedule/formatter/smart_formatter.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
Value
dataclass
¶
normalize_names(prgm, bindings)
¶
normalize_names(
prgm: LogicStatement, bindings: dict[Alias, T]
) -> tuple[LogicStatement, dict[Alias, T]]
Normalizes names of aliases and fields in the logic program to avoid conflicts. The fields an aggregate reduces are its own, so they are renamed apart from any field of the same name outside it, unless an enclosing Fuse loops over them.
Source code in src/finch/autoschedule/normalize.py
optimize_protocols(prgm, bindings, stats, stats_factory, cost_model=PROTOCOL_COST_MODEL)
¶
prgm, reading each level with the protocol which costs least under cost_model, as choose_protocols chooses them.