Skip to content

[SYCL] Add missing cmath builtin #11012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libdevice/cmath_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ lldiv_t lldiv(long long x, long long y) { return __devicelib_lldiv(x, y); }
DEVICE_EXTERN_C_INLINE
float roundf(float x) { return __devicelib_roundf(x); }

DEVICE_EXTERN_C_INLINE
float floorf(float x) { return __devicelib_floorf(x); }

DEVICE_EXTERN_C_INLINE
float scalbnf(float x, int n) { return __devicelib_scalbnf(x, n); }

Expand Down
3 changes: 3 additions & 0 deletions libdevice/cmath_wrapper_fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ double log(double x) { return __devicelib_log(x); }
DEVICE_EXTERN_C_INLINE
double round(double x) { return __devicelib_round(x); }

DEVICE_EXTERN_C_INLINE
double floor(double x) { return __devicelib_floor(x); }

DEVICE_EXTERN_C_INLINE
double exp(double x) { return __devicelib_exp(x); }

Expand Down
6 changes: 6 additions & 0 deletions libdevice/device_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ double __devicelib_round(double x);
DEVICE_EXTERN_C
float __devicelib_roundf(float x);

DEVICE_EXTERN_C
double __devicelib_floor(double x);

DEVICE_EXTERN_C
float __devicelib_floorf(float x);

DEVICE_EXTERN_C
double __devicelib_log(double x);

Expand Down
3 changes: 3 additions & 0 deletions libdevice/fallback-cmath-fp64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ double __devicelib_modf(double x, double *intpart) {
DEVICE_EXTERN_C_INLINE
double __devicelib_round(double x) { return __spirv_ocl_round(x); }

DEVICE_EXTERN_C_INLINE
double __devicelib_floor(double x) { return __spirv_ocl_floor(x); }

DEVICE_EXTERN_C_INLINE
double __devicelib_exp2(double x) { return __spirv_ocl_exp2(x); }

Expand Down
3 changes: 3 additions & 0 deletions libdevice/fallback-cmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ float __devicelib_scalbnf(float x, int n) { return __spirv_ocl_ldexp(x, n); }
DEVICE_EXTERN_C_INLINE
float __devicelib_roundf(float x) { return __spirv_ocl_round(x); }

DEVICE_EXTERN_C_INLINE
float __devicelib_floorf(float x) { return __spirv_ocl_floor(x); }

DEVICE_EXTERN_C_INLINE
float __devicelib_logf(float x) { return __spirv_ocl_log(x); }

Expand Down
9 changes: 5 additions & 4 deletions sycl/test-e2e/DeviceLib/cmath_fp64_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ namespace s = sycl;
constexpr s::access::mode sycl_read = s::access::mode::read;
constexpr s::access::mode sycl_write = s::access::mode::write;

#define TEST_NUM 62
#define TEST_NUM 63

double ref[TEST_NUM] = {
1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0,
0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

double refIptr = 1;

Expand Down Expand Up @@ -62,6 +62,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
res_access[i++] = std::cos(0.0);
res_access[i++] = std::sin(0.0);
res_access[i++] = std::round(1.0);
res_access[i++] = std::floor(1.0);
res_access[i++] = std::log(1.0);
res_access[i++] = std::acos(1.0);
res_access[i++] = std::asin(0.0);
Expand Down
11 changes: 6 additions & 5 deletions sycl/test-e2e/DeviceLib/cmath_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace s = sycl;
constexpr s::access::mode sycl_read = s::access::mode::read;
constexpr s::access::mode sycl_write = s::access::mode::write;

#define TEST_NUM 60
#define TEST_NUM 61

float ref[TEST_NUM] = {1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0, 1, 0,
2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0,
0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
float ref[TEST_NUM] = {1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0, 1, 0,
2, 0, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 2, 5, 0, 0,
0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

float refIptr = 1;

Expand Down Expand Up @@ -59,6 +59,7 @@ template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
res_access[i++] = std::cos(0.0f);
res_access[i++] = std::sin(0.0f);
res_access[i++] = std::round(1.0f);
res_access[i++] = std::floor(1.0f);
res_access[i++] = std::log(1.0f);
res_access[i++] = std::acos(1.0f);
res_access[i++] = std::asin(0.0f);
Expand Down