Skip to content

Commit d5c094f

Browse files
authored
[SYCL] Add missing cmath builtin (#11012)
Same as #10904 for cmath func `floor`
1 parent 9249bf8 commit d5c094f

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
@@ -31,6 +31,9 @@ lldiv_t lldiv(long long x, long long y) { return __devicelib_lldiv(x, y); }
3131
DEVICE_EXTERN_C_INLINE
3232
float roundf(float x) { return __devicelib_roundf(x); }
3333

34+
DEVICE_EXTERN_C_INLINE
35+
float floorf(float x) { return __devicelib_floorf(x); }
36+
3437
DEVICE_EXTERN_C_INLINE
3538
float scalbnf(float x, int n) { return __devicelib_scalbnf(x, n); }
3639

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ double log(double x) { return __devicelib_log(x); }
2121
DEVICE_EXTERN_C_INLINE
2222
double round(double x) { return __devicelib_round(x); }
2323

24+
DEVICE_EXTERN_C_INLINE
25+
double floor(double x) { return __devicelib_floor(x); }
26+
2427
DEVICE_EXTERN_C_INLINE
2528
double exp(double x) { return __devicelib_exp(x); }
2629

libdevice/device_math.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ double __devicelib_round(double x);
5555
DEVICE_EXTERN_C
5656
float __devicelib_roundf(float x);
5757

58+
DEVICE_EXTERN_C
59+
double __devicelib_floor(double x);
60+
61+
DEVICE_EXTERN_C
62+
float __devicelib_floorf(float x);
63+
5864
DEVICE_EXTERN_C
5965
double __devicelib_log(double x);
6066

libdevice/fallback-cmath-fp64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ double __devicelib_modf(double x, double *intpart) {
4141
DEVICE_EXTERN_C_INLINE
4242
double __devicelib_round(double x) { return __spirv_ocl_round(x); }
4343

44+
DEVICE_EXTERN_C_INLINE
45+
double __devicelib_floor(double x) { return __spirv_ocl_floor(x); }
46+
4447
DEVICE_EXTERN_C_INLINE
4548
double __devicelib_exp2(double x) { return __spirv_ocl_exp2(x); }
4649

libdevice/fallback-cmath.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ float __devicelib_scalbnf(float x, int n) { return __spirv_ocl_ldexp(x, n); }
4040
DEVICE_EXTERN_C_INLINE
4141
float __devicelib_roundf(float x) { return __spirv_ocl_round(x); }
4242

43+
DEVICE_EXTERN_C_INLINE
44+
float __devicelib_floorf(float x) { return __spirv_ocl_floor(x); }
45+
4346
DEVICE_EXTERN_C_INLINE
4447
float __devicelib_logf(float x) { return __spirv_ocl_log(x); }
4548

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

2424
double ref[TEST_NUM] = {
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};
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};
2828

2929
double refIptr = 1;
3030

@@ -62,6 +62,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
6262
res_access[i++] = std::cos(0.0);
6363
res_access[i++] = std::sin(0.0);
6464
res_access[i++] = std::round(1.0);
65+
res_access[i++] = std::floor(1.0);
6566
res_access[i++] = std::log(1.0);
6667
res_access[i++] = std::acos(1.0);
6768
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 60
24+
#define TEST_NUM 61
2525

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};
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};
3030

3131
float refIptr = 1;
3232

@@ -59,6 +59,7 @@ template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
5959
res_access[i++] = std::cos(0.0f);
6060
res_access[i++] = std::sin(0.0f);
6161
res_access[i++] = std::round(1.0f);
62+
res_access[i++] = std::floor(1.0f);
6263
res_access[i++] = std::log(1.0f);
6364
res_access[i++] = std::acos(1.0f);
6465
res_access[i++] = std::asin(0.0f);

0 commit comments

Comments
 (0)