[complex-math-expander] Add mode option and basic complex arithmetic decomposition#2916
Open
brucechanglongxu wants to merge 1 commit intoopenxla:mainfrom
Open
Conversation
…decomposition Add a `mode` option to the `stablehlo-complex-math-expander` pass to distinguish between: - `precision` (default): Expands only precision-sensitive transcendental ops (log, sqrt, exp, log_plus_one) using numerically stable algorithms. - `all`: Additionally decomposes basic complex arithmetic (add, subtract, multiply, divide, negate) into real-valued operations, for hardware backends that lack native complex number support. The arithmetic decomposition patterns are implemented as C++ RewritePattern classes, keeping them cleanly separated from the precision patterns generated via functional_algorithms. Complex division uses Smith's method for numerical stability. A new `populateStablehloComplexArithmeticExpanderPatterns` API is exposed for downstream users who want to use these patterns independently. Addresses openxla#2913
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per the discussion in #2913, this adds a
modeflag tostablehlo-complex-math-expanderso the pass can also decompose basic complex arithmetic (add, subtract, multiply, divide, negate) into real-valued ops — useful for backends without native complex support.--stablehlo-complex-math-expander=mode=precision(default) keeps current behavior (only transcendental ops like log/sqrt/exp/log1p).--stablehlo-complex-math-expander=mode=alladditionally lowers the basic arithmetic ops.The new patterns are C++
OpRewritePatterns rather than TableGen DRR so they can be conditionally registered based on the mode, and stay separate from thefunctional_algorithms-generated precision patterns. Division uses Smith's method to avoid blowup when one component of the divisor dominates.Also exposes
populateStablehloComplexArithmeticExpanderPatternsfor anyone who wants to use these patterns outside the pass.Tests cover both modes, f32/f64, dynamic shapes, scalars, and multi-dim tensors.
Closes #2913