Skip to content

Commit 8f75531

Browse files
authored
[SYCL][Devicelib] Add missing round in devicelib (#10904)
Since #9768 `ffast-math` no longer chooses llvm intrinsics. This highlighted that `std::round` was missing in libdevice. This fixes that.
1 parent 6956832 commit 8f75531

File tree

7 files changed

+29
-9
lines changed

7 files changed

+29
-9
lines changed

libdevice/cmath_wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ ldiv_t ldiv(long x, long y) { return __devicelib_ldiv(x, y); }
2828
DEVICE_EXTERN_C_INLINE
2929
lldiv_t lldiv(long long x, long long y) { return __devicelib_lldiv(x, y); }
3030

31+
DEVICE_EXTERN_C_INLINE
32+
float roundf(float x) { return __devicelib_roundf(x); }
33+
3134
DEVICE_EXTERN_C_INLINE
3235
float scalbnf(float x, int n) { return __devicelib_scalbnf(x, n); }
3336

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
DEVICE_EXTERN_C_INLINE
1919
double log(double x) { return __devicelib_log(x); }
2020

21+
DEVICE_EXTERN_C_INLINE
22+
double round(double x) { return __devicelib_round(x); }
23+
2124
DEVICE_EXTERN_C_INLINE
2225
double exp(double x) { return __devicelib_exp(x); }
2326

libdevice/device_math.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ ldiv_t __devicelib_ldiv(long int x, long int y);
4949
DEVICE_EXTERN_C
5050
lldiv_t __devicelib_lldiv(long long int x, long long int y);
5151

52+
DEVICE_EXTERN_C
53+
double __devicelib_round(double x);
54+
55+
DEVICE_EXTERN_C
56+
float __devicelib_roundf(float x);
57+
5258
DEVICE_EXTERN_C
5359
double __devicelib_log(double x);
5460

libdevice/fallback-cmath-fp64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ double __devicelib_modf(double x, double *intpart) {
3838
return __spirv_ocl_modf(x, intpart);
3939
}
4040

41+
DEVICE_EXTERN_C_INLINE
42+
double __devicelib_round(double x) { return __spirv_ocl_round(x); }
43+
4144
DEVICE_EXTERN_C_INLINE
4245
double __devicelib_exp2(double x) { return __spirv_ocl_exp2(x); }
4346

libdevice/fallback-cmath.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ lldiv_t __devicelib_lldiv(long long x, long long y) { return {x / y, x % y}; }
3737
DEVICE_EXTERN_C_INLINE
3838
float __devicelib_scalbnf(float x, int n) { return __spirv_ocl_ldexp(x, n); }
3939

40+
DEVICE_EXTERN_C_INLINE
41+
float __devicelib_roundf(float x) { return __spirv_ocl_round(x); }
42+
4043
DEVICE_EXTERN_C_INLINE
4144
float __devicelib_logf(float x) { return __spirv_ocl_log(x); }
4245

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 61
22+
#define TEST_NUM 62
2323

2424
double ref[TEST_NUM] = {
25-
1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0,
26-
0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0,
27-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
25+
1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
26+
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

@@ -61,6 +61,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
6161
*((uint64_t *)&subnormal) = 0xFFFFFFFFFFFFFULL;
6262
res_access[i++] = std::cos(0.0);
6363
res_access[i++] = std::sin(0.0);
64+
res_access[i++] = std::round(1.0);
6465
res_access[i++] = std::log(1.0);
6566
res_access[i++] = std::acos(1.0);
6667
res_access[i++] = std::asin(0.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 59
24+
#define TEST_NUM 60
2525

26-
float ref[TEST_NUM] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0, 1, 0, 2,
27-
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,
29-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
26+
float ref[TEST_NUM] = {1, 0, 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,
28+
0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0, 0,
29+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3030

3131
float refIptr = 1;
3232

@@ -58,6 +58,7 @@ template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
5858

5959
res_access[i++] = std::cos(0.0f);
6060
res_access[i++] = std::sin(0.0f);
61+
res_access[i++] = std::round(1.0f);
6162
res_access[i++] = std::log(1.0f);
6263
res_access[i++] = std::acos(1.0f);
6364
res_access[i++] = std::asin(0.0f);

0 commit comments

Comments
 (0)