Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLVMGPU] Remove some op's polynomial approximation #19910

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lialan
Copy link
Contributor

@lialan lialan commented Feb 5, 2025

Except:

  • erf, which is under investigation.
  • powf, need to also update many tests. Doing it in another PR.

@lialan lialan force-pushed the users/lialan/rocm-math2 branch from 193d874 to 2c25ab8 Compare February 5, 2025 06:13
@lialan lialan force-pushed the users/lialan/rocm-math2 branch from 2c25ab8 to 5368df4 Compare February 5, 2025 06:30
@lialan lialan changed the title Remove some op's polynomial approximation on LLVMGPU [LLVMGPU] Remove some op's polynomial approximation Feb 5, 2025
@lialan lialan marked this pull request as ready for review February 5, 2025 17:43
@lialan
Copy link
Contributor Author

lialan commented Feb 5, 2025

@bjacob @kuhar This is just a follow up to remove some unaffected ops for poly approx on LLVMGPU.

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Have you confirmed the numerics?

@lialan
Copy link
Contributor Author

lialan commented Feb 5, 2025

Looks good. Have you confirmed the numerics?

Not seeing CI complain about numerics except something is off with pow. I will wait until CI is clear.

@bjacob bjacob self-requested a review February 5, 2025 17:54
Copy link
Contributor

@bjacob bjacob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that at the moment, this is not only dropping polynomial approximation for erf, this is dropping promotion from f16 to f32 for all math functions. That is because that promotion is done by mlir::populateMathPolynomialApproximationPatterns upstream, and not exposed separately from it, and the only place where we call that function is in the polynomial approximation path for erf. I believe that to be the cause of accuracy issues currently observed when trying to drop the polynomial approximation for erf.

@kuhar
Copy link
Member

kuhar commented Feb 5, 2025

The problem is that at the moment, this is not only dropping polynomial approximation for erf, this is dropping promotion from f16 to f32 for all math functions. That is because that promotion is done by mlir::populateMathPolynomialApproximationPatterns upstream, and not exposed separately from it, and the only place where we call that function is in the polynomial approximation path for erf. I believe that to be the cause of accuracy issues currently observed when trying to drop the polynomial approximation for erf.

This PR doesn't drop polynomial approx for erf.

@bjacob
Copy link
Contributor

bjacob commented Feb 5, 2025

This PR doesn't drop polynomial approx for erf.

Oh, I see.

@bjacob
Copy link
Contributor

bjacob commented Feb 5, 2025

But I mean, the whole premise of singling out erf is depending on that ongoing investigation. It would make more sense to resolve that first.

Do we have a short term need for this PR? (Is it producing an improvement in a metric we're tracking) ?

@lialan
Copy link
Contributor Author

lialan commented Feb 5, 2025

It would make more sense to resolve that first.

This is separate so we can wait until you resolve erf and then merge this.

@lialan
Copy link
Contributor Author

lialan commented Feb 5, 2025

Using @__ocml_pow_f64 (with fptosi) return 31 for calculating 2 ** 5.0 rather than 32. other values are okay.

@bjacob
Copy link
Contributor

bjacob commented Feb 6, 2025

Interesting!!

@krzysz00
Copy link
Contributor

krzysz00 commented Feb 6, 2025

Side note: there is a standalone pass and pattern set for promoting math operations to wider types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants