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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
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
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
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
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 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 | |
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
355 356 357 358 359 360 361 362 363 364 365 366 367 | |
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
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 | |
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
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
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
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
push_aggregates_up(expr)
Apply push-aggregate and merge-aggregate rewrites to fixpoint. Produces an expression where reduction indices are not parent-related
Source code in src/finch/autoschedule/factorizer/galley_factorizer/query_normalization.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |