Skip to content

[HIP] Add f64 math accuracy test for exp, exp2, exp10#370

Open
yxsamliu wants to merge 3 commits intollvm:mainfrom
yxsamliu:amd/dev/yaxunl/math-ulp-exp-test
Open

[HIP] Add f64 math accuracy test for exp, exp2, exp10#370
yxsamliu wants to merge 3 commits intollvm:mainfrom
yxsamliu:amd/dev/yaxunl/math-ulp-exp-test

Conversation

@yxsamliu
Copy link
Copy Markdown
Contributor

Add an E2E test that verifies GPU exp/exp2/exp10 results are within 1 ULP of host-computed references for f64 inputs. Tests 2316 values covering special cases (0, denormals, large values), the full [-700, 700] range, and small values near zero.

This ensures that changes to math lowering (e.g. switching from OCML library calls to compiler builtins as in llvm/llvm-project#185947) maintain numerical accuracy.

Tested on gfx1100: all 2316 test points pass for all three functions with worst case exactly 1 ULP.

Add an E2E test that verifies GPU exp/exp2/exp10 results are within
1 ULP of host-computed references for f64 inputs. Tests 2316 values
covering special cases, the full [-700, 700] range, and small values
near zero.

This ensures that changes to math lowering (e.g. switching from OCML
library calls to compiler builtins) maintain accuracy.
Copy link
Copy Markdown

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

This isn't that comprehensive or pluggable for other functions

@jplehr jplehr requested a review from mhalk March 17, 2026 11:06
- Template ulp_distance, compute_exp kernel, and test_func over T
- Add IntRep trait to map float types to same-size integers for ULP
- Add special inputs: inf, -inf, NaN, denorm_min, min, max
- Use type-appropriate ranges: f32 [-87,87], f64 [-700,700]
- Use std::copy instead of memcpy for array assembly
- Add comment explaining the ULP integer-subtraction technique
@yxsamliu yxsamliu force-pushed the amd/dev/yaxunl/math-ulp-exp-test branch from b7fcee3 to 1915521 Compare March 21, 2026 18:18
Copy link
Copy Markdown

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

This could do a lot more but it's better than nothing

return 0.0;
using I = typename IntRep<T>::type;
I ai, bi;
memcpy(&ai, &a, sizeof(T));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would be better to implement this with ilogb like OpenCL conformance

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