Index
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
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
accumulator_depth(prgm, alias)
¶
Return the number of fields of the query defining alias, when they are its outermost loops, in any order, and it reduces over further loops, so that each element it writes stays fixed across those loops, even where it scatters into alias. A workspace fused over every field then stores nothing, and holds the running value of one element. Only an alias which one Query defines, and nothing updates, has an accumulator.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_1d_workspaces(prgm, bindings)
¶
Stage the workspaces of prgm, as stage_workspaces does, which store one field, the only one the query scatters into, without pricing them.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_accumulators(prgm, bindings)
¶
Redirect each query of prgm which reduces into an output whose fields are its outermost loops, as accumulator_depth finds, into a workspace fused over all of them, as add_workspace does. The workspace stores no fields, so it is declared before the loops it reduces over, accumulates the value of one element of the output, and is copied into it once those loops end. Return the program and the format of each workspace, a Temp0D, which a backend may keep in a register, where it would load and store the output in every iteration, and could not keep it there when another output might alias it. Where a sparse input leaves nothing to accumulate, the reset and the copy of the fill write nothing, so a backend which reads a declared tensor as its fill until it is written skips them, as the loops would without the workspace. Only an output with a static fill, which isn't an input of bindings, has one.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_cost_effective_reformats(prgm, bindings, stats, stats_factory, cost_model, options=LEVEL_OPTIONS, format_cost=format_cost)
¶
Copy the inputs of prgm into new formats, as stage_reformats does, where the program costs less with the copy under cost_model, once format_cost formats the copy, keeping the formats of the other aliases prgm defines.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_cost_effective_workspaces(prgm, bindings, stats, stats_factory, cost_model, options=LEVEL_OPTIONS, format_cost=format_cost)
¶
Add workspaces that improve cost, as defined by the format_cost function. Because this relies on further optimization, we need to be a bit careful to only reoptimize formats for the current alias and workspace.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_reformat(prgm, alias, idxs, copy)
¶
Copy alias into copy before prgm, looping over idxs, the fields of a table which reads alias, in the order alias stores them, and read copy wherever prgm reads alias, so that the formatter may store copy in any format.
Source code in src/finch/autoschedule/workspacer/workspacer.py
add_workspace(prgm, alias, depth, ws)
¶
Redirect the query which defines alias into ws, fused over the first depth loops enclosing the query, which are fields of alias in any order. ws lists those fields in loop order, and then the others in the order of alias. Right after the statement within depth Fuse nodes which holds the query, ws is copied into alias in order.
Source code in src/finch/autoschedule/workspacer/workspacer.py
galley_format_cost(prgm, bindings, stats, stats_factory, cost_model, options=LEVEL_OPTIONS)
¶
format_cost with the formats GalleyFormatter chooses from the stats of each alias, rather than those optimize_formats searches for. The program is priced once, so a workspace costs one choice of protocols rather than a search over formats; the formats are those a GalleyFormatter downstream gives the program. options is unused.
Source code in src/finch/autoschedule/workspacer/workspacer.py
stage_reformats(prgm, bindings, keep)
¶
Copy each input of bindings which prgm reads, and doesn't write, into a new alias before prgm, as add_reformat does, if keep, given prgm, the program with the copy, the input, and the copy, keeps it. A scalar has no levels to store otherwise.
Source code in src/finch/autoschedule/workspacer/workspacer.py
stage_workspaces(prgm, bindings, keep)
¶
Redirect each query of prgm which scatters into an output of prgm into a workspace fused over the fields it writes in loop order, as add_workspace does, if the workspace stores fewer fields than the output, and keep, given prgm, the program with the workspace, the output, and the workspace, keeps it. The inputs of bindings have no workspaces.
Source code in src/finch/autoschedule/workspacer/workspacer.py
workspace_depth(prgm, alias)
¶
Return the number of leading fields that the query defining alias writes in loop order, when it scatters into a later field. A workspace fused over those fields can then take the scattered writes. Only an alias which one Query defines, and nothing updates, has a workspace.