Skip to content

Commit 20068a6

Browse files
committed
simplify
Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 65049e6 commit 20068a6

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

sycl/test-e2e/DeviceLib/built-ins/offload-prec-div-sqrt.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,46 @@
1111
constexpr float value = 560.0f;
1212
constexpr float divider = 280.0f;
1313

14-
// Reference
15-
// https://github.com/KhronosGroup/SYCL-CTS/blob/SYCL-2020/util/accuracy.h
16-
template <typename T> T get_ulp_std(T x) {
17-
const T inf = std::numeric_limits<T>::infinity();
18-
const T negative = std::fabs(std::nextafter(x, -inf) - x);
19-
const T positive = std::fabs(std::nextafter(x, inf) - x);
20-
return std::fmin(negative, positive);
21-
}
14+
int32_t ulp_difference(float lhs, float rhs) {
15+
int32_t lhsInt = *reinterpret_cast<int32_t *>(&lhs);
16+
int32_t rhsInt = *reinterpret_cast<int32_t *>(&rhs);
2217

23-
template <typename T> int ulp_difference(const T &lhs, const T &rhs) {
24-
return get_ulp_std(lhs) - get_ulp_std(rhs);
18+
return std::abs(lhsInt - rhsInt);
2519
}
2620

2721
void test_div() {
2822
sycl::queue q(sycl::default_selector_v);
29-
float *in_value = (float *)sycl::malloc_shared(sizeof(float), q);
30-
float *in_divider = (float *)sycl::malloc_shared(sizeof(float), q);
23+
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q);
24+
float *inDivider = (float *)sycl::malloc_shared(sizeof(float), q);
3125
float *output = (float *)sycl::malloc_shared(sizeof(float), q);
32-
*in_value = value;
33-
*in_divider = divider;
26+
*inValue = value;
27+
*inDivider = divider;
3428
q.submit([&](sycl::handler &h) {
3529
h.single_task([=] {
36-
float res = *in_value / *in_divider;
30+
float res = *inValue / *inDivider;
3731
*output = res;
3832
});
3933
}).wait();
4034

4135
float hostRef = value / divider;
42-
int ulpDiff = ulp_difference<float>(hostRef, *output);
36+
int ulpDiff = ulp_difference(hostRef, *output);
4337
assert(std::abs(ulpDiff) < 1 && "Division is not precise");
4438
}
4539

4640
void test_sqrt() {
4741
sycl::queue q(sycl::default_selector_v);
48-
float *in_value = (float *)sycl::malloc_shared(sizeof(float), q);
42+
float *inValue = (float *)sycl::malloc_shared(sizeof(float), q);
4943
float *output = (float *)sycl::malloc_shared(sizeof(float), q);
50-
*in_value = value;
44+
*inValue = value;
5145
q.submit([&](sycl::handler &h) {
5246
h.single_task([=] {
53-
float res = sycl::sqrt(*in_value);
47+
float res = sycl::sqrt(*inValue);
5448
*output = res;
5549
});
5650
}).wait();
5751

5852
float hostRef = std::sqrt(value);
59-
int ulpDiff = ulp_difference<float>(hostRef, *output);
53+
int ulpDiff = ulp_difference(hostRef, *output);
6054
assert(std::abs(ulpDiff) < 1 && "Sqrt is not precise");
6155
}
6256

0 commit comments

Comments
 (0)