-
Notifications
You must be signed in to change notification settings - Fork 808
[SYCL] Add E2E test for -foffload-fp32-prec-div/sqrt #17037
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4a5678f
[SYCL] Add E2E test for -foffload-fp32-prec-div/sqrt
65049e6
remove sycl.hpp
20068a6
simplify
8cd6672
apply suggestions
7761947
std->sycl
d5b8823
apply suggestion
f1eacfc
Merge remote-tracking branch 'origin/sycl' into add-test-fp32-opt
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
sycl/test-e2e/DeviceLib/built-ins/offload-prec-div-sqrt.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // RUN: %{build} -foffload-fp32-prec-div -foffload-fp32-prec-sqrt -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| // Test if div and sqrt become precise from IEEE-754 perspective when | ||
| // -foffload-fp32-prec-div -foffload-fp32-prec-sqrt are passed. | ||
|
|
||
| #include <cmath> | ||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/usm.hpp> | ||
|
|
||
| constexpr float value = 560.0f; | ||
| constexpr float divider = 280.0f; | ||
MrSidims marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Reference | ||
| // https://github.com/KhronosGroup/SYCL-CTS/blob/SYCL-2020/util/accuracy.h | ||
| template <typename T> T get_ulp_std(T x) { | ||
| const T inf = std::numeric_limits<T>::infinity(); | ||
| const T negative = std::fabs(std::nextafter(x, -inf) - x); | ||
| const T positive = std::fabs(std::nextafter(x, inf) - x); | ||
| return std::fmin(negative, positive); | ||
| } | ||
|
|
||
| template <typename T> int ulp_difference(const T &lhs, const T &rhs) { | ||
MrSidims marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return get_ulp_std(lhs) - get_ulp_std(rhs); | ||
| } | ||
|
|
||
| void test_div() { | ||
| sycl::queue q(sycl::default_selector_v); | ||
| float *in_value = (float *)sycl::malloc_shared(sizeof(float), q); | ||
| float *in_divider = (float *)sycl::malloc_shared(sizeof(float), q); | ||
| float *output = (float *)sycl::malloc_shared(sizeof(float), q); | ||
| *in_value = value; | ||
| *in_divider = divider; | ||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task([=] { | ||
| float res = *in_value / *in_divider; | ||
| *output = res; | ||
| }); | ||
| }).wait(); | ||
|
|
||
| float hostRef = value / divider; | ||
| int ulpDiff = ulp_difference<float>(hostRef, *output); | ||
| assert(std::abs(ulpDiff) < 1 && "Division is not precise"); | ||
MrSidims marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void test_sqrt() { | ||
| sycl::queue q(sycl::default_selector_v); | ||
| float *in_value = (float *)sycl::malloc_shared(sizeof(float), q); | ||
| float *output = (float *)sycl::malloc_shared(sizeof(float), q); | ||
| *in_value = value; | ||
| q.submit([&](sycl::handler &h) { | ||
| h.single_task([=] { | ||
| float res = sycl::sqrt(*in_value); | ||
| *output = res; | ||
| }); | ||
| }).wait(); | ||
|
|
||
| float hostRef = std::sqrt(value); | ||
| int ulpDiff = ulp_difference<float>(hostRef, *output); | ||
| assert(std::abs(ulpDiff) < 1 && "Sqrt is not precise"); | ||
| } | ||
|
|
||
| int main() { | ||
| test_div(); | ||
| test_sqrt(); | ||
| return 0; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.