Repository navigation
[HIP] Fix double to E8M0 conversion underflow (avoid unsigned exp wraparound) - #2461
Conversation
|
@AidanBeltonS I noticed you've worked on the FP8_E8M0 data type. Could you please review these changes? |
There was a problem hiding this comment.
Pull request overview
This PR fixes an exponent underflow bug in the double-to-E8M0 conversion function where unsigned arithmetic caused wraparound for small normal double exponents, incorrectly classifying them as NaN.
Key Changes:
- Replace unsigned exponent arithmetic with signed arithmetic to prevent underflow wraparound
- Add explicit clamping logic for underflow (
float_exp <= 0), valid range, and overflow cases - Extend test coverage with edge cases for subnormal and small normal doubles
- Update Catch2 matcher syntax to current API (
Catch::Matchers::WithinAbs/WithinRel)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
projects/clr/hipamd/include/hip/amd_detail/amd_hip_fp8.h |
Refactored __hip_cvt_double_to_e8m0() to use signed arithmetic for exponent conversion, preventing unsigned underflow and correctly handling small normal doubles |
projects/hip-tests/catch/unit/deviceLib/fp8_e8m0.cc |
Added comprehensive underflow test cases (1e-50, denorm_min, double::min, float::min cast to double) with correct expected values, and updated Catch2 matcher syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
AidanBeltonS
left a comment
There was a problem hiding this comment.
Thanks for the patch and regression test. This looks good to me, thanks for catching this! One minor comment.
|
@AidanBeltonS @b-sumner thanks for the review! |
a16170d to
f48ea24
Compare
b67b36d to
bc61454
Compare
|
Force merging as occurs here as well: https://github.com/ROCm/rocm-systems/actions/runs/21760049052/job/62785319334 |
exp wraparound) (#2461) Co-authored-by: Andrei Kochin <andrei.kochin@amd.com> [rocm-systems] ROCm/rocm-systems#2461 (commit 5d84cba)
exp wraparound) (#2461) Co-authored-by: Andrei Kochin <andrei.kochin@amd.com> [rocm-systems] ROCm/rocm-systems#2461 (commit 5d84cba)
This PR fixes an exponent underflow bug in the FP8 E8M0 conversion path for doubles
Motivation
Currently,
__hip_cvt_double_to_e8m0()computes the float-domain exponent using unsigned short arithmetic. For small normal double exponents (non-zero but less than the bias delta), this subtraction underflowed, producing a large value and incorrectly takingNaNpathTechnical Details
float_exp <= 0to0x0U(underflow to float subnormal/zero domain)float_exp > 0xFF -> e8m0_NaN, and leave the existing rounding/saturation post-processing intactCatch::Matchers::WithinAbs/WithinRelto match current Catch2 APITest Plan
projects/hip-tests/catch/unit/deviceLib/fp8_e8m0.ccwith underflow-focused inputsTest Result
Submission Checklist