Skip to content

Commit 9164df1

Browse files
authored
[SYCL][E2E] Add E2E test for -foffload-fp32-prec-div/sqrt (#17037)
Supporting doc: #17033 --------- Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 152bca8 commit 9164df1

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %{build} -foffload-fp32-prec-div -foffload-fp32-prec-sqrt -o %t.out
2+
// RUN: %{run} %t.out
3+
4+
// Test if div and sqrt become precise from IEEE-754 perspective when
5+
// -foffload-fp32-prec-div -foffload-fp32-prec-sqrt are passed.
6+
7+
#include <cmath>
8+
#include <sycl/detail/core.hpp>
9+
#include <sycl/usm.hpp>
10+
11+
constexpr float value = 560.0f;
12+
constexpr float divider = 279.9f;
13+
14+
void test_div() {
15+
sycl::queue q(sycl::default_selector_v);
16+
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q);
17+
float *inDivider = (float *)sycl::malloc_shared(sizeof(float), q);
18+
float *output = (float *)sycl::malloc_shared(sizeof(float), q);
19+
*inValue = value;
20+
*inDivider = divider;
21+
q.submit([&](sycl::handler &h) {
22+
h.single_task([=] {
23+
float res = *inValue / *inDivider;
24+
*output = res;
25+
});
26+
}).wait();
27+
28+
float hostRef = value / divider;
29+
int ulpDist = std::abs(sycl::bit_cast<int32_t>(hostRef) -
30+
sycl::bit_cast<int32_t>(*output));
31+
assert(ulpDist == 0 && "Division is not precise");
32+
}
33+
34+
void test_sqrt() {
35+
sycl::queue q(sycl::default_selector_v);
36+
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q);
37+
float *output = (float *)sycl::malloc_shared(sizeof(float), q);
38+
*inValue = value;
39+
q.submit([&](sycl::handler &h) {
40+
h.single_task([=] {
41+
float res = sycl::sqrt(*inValue);
42+
*output = res;
43+
});
44+
}).wait();
45+
46+
float hostRef = std::sqrt(value);
47+
int ulpDist = std::abs(sycl::bit_cast<int32_t>(hostRef) -
48+
sycl::bit_cast<int32_t>(*output));
49+
assert(ulpDist == 0 && "Sqrt is not precise");
50+
}
51+
52+
int main() {
53+
test_div();
54+
test_sqrt();
55+
return 0;
56+
}

0 commit comments

Comments
 (0)