Skip to content

[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 7 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions sycl/test-e2e/DeviceLib/built-ins/offload-prec-div-sqrt.cpp
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;
}
Loading