query_normalization
alpha_rename_expr(expr, mapping)
¶
Apply a simple alpha-renaming to expr, replacing any Field that appears in mapping with its mapped value.
This traverses only the LogicExpression nodes that actually store fields and leaves all other nodes unchanged.
The goal is to rewrite the dimension variables of an alias definition to match the index variables at a particular call site.
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
map_pointwise_aggregate(node)
¶
Rewrite: Aggregate(op, init, arg, ()) -> MapJoin(op, (init, arg)) Galley starts each reduction from the init of the indices it reduces, so an aggregate which reduces no indices would drop an init which isn't an identity of its operator.
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
merge_queries(plan)
¶
Merge per-alias queries into larger queries, one per produced tensor.
- Builds a mapping from Alias to its defining Query in the original plan.
- For each alias mentioned in the final Produces statement, constructs a new Query(Table(alias, idxs), merged_rhs) where merged_rhs inlines any Table(Alias, ...) references using _inline_tables_in_expr.
- Ensures that we never drop a Query whose lhs alias appears in a Produces statement
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
normalize_reorders_in_plan(plan)
¶
Apply normalize_reorders_in_query to each Query body in the plan.
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
normalize_reorders_in_query(query)
¶
Normalize Reorder usage in a single query.
For a given Query(lhs, rhs): 1. Strip all Reorder nodes from rhs. 2. Remove any aggregates that references idxs created by reorders
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
postprocess_plan_after_galley(plan)
¶
Postprocessing used after running Galley greedy optimization.
- Rebuilds the plan so that, for each alias mentioned in the final Produces, there is only one Query computing it. This is necessary because the greedy optimizer may produce multiple queries with the same lhs alias as it reduces different indices, but downstream components expect at most one query per alias.
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
preprocess_plan_for_galley(plan)
¶
End-to-end preprocessing used before running Galley greedy optimization.
- First writes aggregates which reduce no indices as maps, so their inits are kept.
- Merges alias-based queries to produce roughly one query per produced alias.
- Pushes aggregates up and merges adjacent same-op aggregates so reduction indices are not parent-related (enables cost-optimal reduction order).
- Then normalizes Reorder usage so that no query RHS has Reorder nodes.
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
push_aggregates_up(expr)
¶
Apply push-aggregate and merge-aggregate rewrites to fixpoint. Produces an expression where reduction indices are not parent-related