-
Notifications
You must be signed in to change notification settings - Fork 787
[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 all 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
MrSidims 65049e6
remove sycl.hpp
MrSidims 20068a6
simplify
MrSidims 8cd6672
apply suggestions
MrSidims 7761947
std->sycl
MrSidims d5b8823
apply suggestion
MrSidims f1eacfc
Merge remote-tracking branch 'origin/sycl' into add-test-fp32-opt
MrSidims 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
56 changes: 56 additions & 0 deletions
56
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,56 @@ | ||
// 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 = 279.9f; | ||
|
||
void test_div() { | ||
sycl::queue q(sycl::default_selector_v); | ||
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q); | ||
float *inDivider = (float *)sycl::malloc_shared(sizeof(float), q); | ||
float *output = (float *)sycl::malloc_shared(sizeof(float), q); | ||
*inValue = value; | ||
*inDivider = divider; | ||
q.submit([&](sycl::handler &h) { | ||
h.single_task([=] { | ||
float res = *inValue / *inDivider; | ||
*output = res; | ||
}); | ||
}).wait(); | ||
|
||
float hostRef = value / divider; | ||
int ulpDist = std::abs(sycl::bit_cast<int32_t>(hostRef) - | ||
sycl::bit_cast<int32_t>(*output)); | ||
assert(ulpDist == 0 && "Division is not precise"); | ||
} | ||
|
||
void test_sqrt() { | ||
sycl::queue q(sycl::default_selector_v); | ||
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q); | ||
float *output = (float *)sycl::malloc_shared(sizeof(float), q); | ||
*inValue = value; | ||
q.submit([&](sycl::handler &h) { | ||
h.single_task([=] { | ||
float res = sycl::sqrt(*inValue); | ||
*output = res; | ||
}); | ||
}).wait(); | ||
|
||
float hostRef = std::sqrt(value); | ||
int ulpDist = std::abs(sycl::bit_cast<int32_t>(hostRef) - | ||
sycl::bit_cast<int32_t>(*output)); | ||
assert(ulpDist == 0 && "Sqrt is not precise"); | ||
} | ||
|
||
int main() { | ||
test_div(); | ||
test_sqrt(); | ||
return 0; | ||
} |
Oops, something went wrong.
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.