Skip to content

Commit 2a828f4

Browse files
author
Hugh Delaney
committed
Add missing fabs
1 parent 9138b6f commit 2a828f4

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

libdevice/cmath_wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ long int labs(long int x) { return __devicelib_labs(x); }
1919
DEVICE_EXTERN_C_INLINE
2020
long long int llabs(long long int x) { return __devicelib_llabs(x); }
2121

22+
DEVICE_EXTERN_C_INLINE
23+
float fabsf(float x) { return __devicelib_fabsf(x); }
24+
2225
DEVICE_EXTERN_C_INLINE
2326
div_t div(int x, int y) { return __devicelib_div(x, y); }
2427

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
// reference. If users provide their own math or complex functions(with
1616
// the prototype), functions in device libraries will be ignored and
1717
// overrided by users' version.
18+
19+
DEVICE_EXTERN_C_INLINE
20+
double fabs(double x) { return __devicelib_fabs(x); }
21+
1822
DEVICE_EXTERN_C_INLINE
1923
double log(double x) { return __devicelib_log(x); }
2024

libdevice/device_math.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ long int __devicelib_labs(long int x);
4040
DEVICE_EXTERN_C
4141
long long int __devicelib_llabs(long long int x);
4242

43+
DEVICE_EXTERN_C
44+
float __devicelib_fabsf(float x);
45+
46+
DEVICE_EXTERN_C
47+
double __devicelib_fabs(double x);
48+
4349
DEVICE_EXTERN_C
4450
div_t __devicelib_div(int x, int y);
4551

libdevice/fallback-cmath-fp64.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// To support fallback device libraries on-demand loading, please update the
1515
// DeviceLibFuncMap in llvm/tools/sycl-post-link/sycl-post-link.cpp if you add
1616
// or remove any item in this file.
17+
18+
DEVICE_EXTERN_C_INLINE
19+
double __devicelib_fabs(double x) { return x < 0 ? -x : x; }
20+
1721
DEVICE_EXTERN_C_INLINE
1822
double __devicelib_log(double x) { return __spirv_ocl_log(x); }
1923

libdevice/fallback-cmath.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ long int __devicelib_labs(long int x) { return x < 0 ? -x : x; }
2525
DEVICE_EXTERN_C_INLINE
2626
long long int __devicelib_llabs(long long int x) { return x < 0 ? -x : x; }
2727

28+
DEVICE_EXTERN_C_INLINE
29+
float __devicelib_fabsf(float x) { return x < 0 ? -x : x; }
30+
2831
DEVICE_EXTERN_C_INLINE
2932
div_t __devicelib_div(int x, int y) { return {x / y, x % y}; }
3033

sycl/test-e2e/DeviceLib/cmath_fp64_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ namespace s = sycl;
1919
constexpr s::access::mode sycl_read = s::access::mode::read;
2020
constexpr s::access::mode sycl_write = s::access::mode::write;
2121

22-
#define TEST_NUM 63
22+
#define TEST_NUM 64
2323

2424
double ref[TEST_NUM] = {
25-
1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0,
26-
0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0,
27-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
25+
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0,
26+
0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0,
27+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
2828

2929
double refIptr = 1;
3030

@@ -59,6 +59,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
5959
T minus_infinity = -INFINITY;
6060
double subnormal;
6161
*((uint64_t *)&subnormal) = 0xFFFFFFFFFFFFFULL;
62+
res_access[i++] = std::fabs(-1.0);
6263
res_access[i++] = std::cos(0.0);
6364
res_access[i++] = std::sin(0.0);
6465
res_access[i++] = std::round(1.0);

sycl/test-e2e/DeviceLib/cmath_test.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ namespace s = sycl;
2121
constexpr s::access::mode sycl_read = s::access::mode::read;
2222
constexpr s::access::mode sycl_write = s::access::mode::write;
2323

24-
#define TEST_NUM 61
24+
#define TEST_NUM 62
2525

26-
float ref[TEST_NUM] = {1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0, 1, 0,
27-
2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0,
28-
0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
26+
float ref[TEST_NUM] = {1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0, 1,
27+
0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0,
28+
0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0, 0, 0,
29+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3030

3131
float refIptr = 1;
3232

@@ -56,6 +56,7 @@ template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
5656
float subnormal;
5757
*((uint32_t *)&subnormal) = 0x7FFFFF;
5858

59+
res_access[i++] = std::fabs(-1.0f);
5960
res_access[i++] = std::cos(0.0f);
6061
res_access[i++] = std::sin(0.0f);
6162
res_access[i++] = std::round(1.0f);

0 commit comments

Comments
 (0)