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

[AMD] Handling denorms in lowering math.sqrt and math.sqrt_rn #5422

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

Conversation

knwng
Copy link
Contributor

@knwng knwng commented Dec 13, 2024

In this commit, we handled the denorm flushing behaviors of math.sqrt and math.sqrt_rn. They read HIP_FTZ to determine whether denorms should be preserved or flushed to zero.

Backend sqrt non-ftz sqrt ftz sqrt_rn non-ftz sqrt_rn ftz
CUDA sqrt.approx.f32 sqrt.approx.ftz.f32 sqrt.rn.f32 sqrt.rn.ftz.f32
AMD scaling + llvm.amdgcn.sqrt.f32 llvm.amdgcn.sqrt.f32 llvm.sqrt.f32 llvm.amdgcn.rsq.f32 + mul + refinement

math.sqrt provides approximation of SQRT. In AMD backend, we use llvm.amdgcn.sqrt.f32, which provides direct access to v_sqrt_f32 and has 1ULP accuracy.

math.sqrt_rn provides IEEE-compliant result(round-to-nearest-or-even) of SQRT. Following the implementation in LLVM, we use extra refinement to get correctly rounded result.

New contributor declaration

  • I am not making a trivial change, such as fixing a typo in a comment.

  • I have written a PR description following these
    rules.

  • I have run pre-commit run --from-ref origin/main --to-ref HEAD.

  • Select one of the following.

    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because FILL THIS IN.
  • Select one of the following.

    • I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

In this commit, we handled the denorm flushing
behaviors of math.sqrt and math.sqrt_rn. They read
HIP_FTZ to determine whether denorms should be
preserved or flushed to zero.
@knwng knwng requested a review from antiagainst January 6, 2025 12:09
Copy link
Collaborator

@zhanglx13 zhanglx13 left a comment

Choose a reason for hiding this comment

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

LGTM. good to go after the comment is fixed

@antiagainst antiagainst marked this pull request as ready for review January 9, 2025 16:46
@antiagainst antiagainst requested a review from ptillet as a code owner January 9, 2025 16:46
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.

3 participants