-
Notifications
You must be signed in to change notification settings - Fork 165
Description
What happened?
Cannot pass check-stablehlo-(linalg|quick|python|ci) if MLIR is built with CMake option
-DMLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=1.
When -DMLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=1 is enabled, the pattern-based infrastructure (greedy rewrites and dialect convesion) enforce additional invariants and will crash if the invariants are violated.
-
When using the greedy rewrite driver, after each pattern is applied the IR must successfully verify. Sometimes the application of multiple patterns can hide issues where invalid IR is being created.
- In Stablehlo to Linalg conversion, invalid
linalg.mapops are being created where the result type does not match the DPS init argument type. Without expensive checks enabled, this gets ignored and happens to be corrected after all patterns are finished running. But under different conditions, this may not always be true. To correct the issue, atensor.castshould be inserted.
- In Stablehlo to Linalg conversion, invalid
-
In dynamism rewriter, a
stablehlo.real_dynamic_slicecan be rewritten to astablehlo.slicethat is invalid (because the input program may have been "valid" but "incorrect", e.g. if the size of the slice is astablehlo.constantthat does not equal the actual specified static result type. I guess the upstream rule is that such canonicalization patterns should return failure vs. creating IR that does not verify. C.f.tensor.extract_slicecanonicalizer starting from here. Without expensive checks enabled, this will raise a diagnostic at the end of the pass, but with expensive checks enabled it will crash with an assertion. This seems to be an area where MLIR upstream is particularly opinionated about what rewrite patterns should do. -
Some patterns not notifying the
rewriterwhen making modifications (result type updates in Stablehlo type refinement pass being main issue I noticed)