Skip to content

[SYCL][Devicelib] Add missing round in devicelib #10904

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 23, 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 @@ -28,6 +28,9 @@ ldiv_t ldiv(long x, long y) { return __devicelib_ldiv(x, y); }
DEVICE_EXTERN_C_INLINE
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 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 @@ -18,6 +18,9 @@
DEVICE_EXTERN_C_INLINE
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 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 @@ -49,6 +49,12 @@ ldiv_t __devicelib_ldiv(long int x, long int y);
DEVICE_EXTERN_C
lldiv_t __devicelib_lldiv(long long int x, long long int y);

DEVICE_EXTERN_C
double __devicelib_round(double x);

DEVICE_EXTERN_C
float __devicelib_roundf(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 @@ -38,6 +38,9 @@ double __devicelib_modf(double x, double *intpart) {
return __spirv_ocl_modf(x, intpart);
}

DEVICE_EXTERN_C_INLINE
double __devicelib_round(double x) { return __spirv_ocl_round(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 @@ -37,6 +37,9 @@ lldiv_t __devicelib_lldiv(long long x, long long y) { return {x / y, x % y}; }
DEVICE_EXTERN_C_INLINE
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_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 61
#define TEST_NUM 62

double ref[TEST_NUM] = {
1, 0, 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, 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 @@ -61,6 +61,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
*((uint64_t *)&subnormal) = 0xFFFFFFFFFFFFFULL;
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::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 59
#define TEST_NUM 60

float ref[TEST_NUM] = {1, 0, 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, 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 @@ -58,6 +58,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::log(1.0f);
res_access[i++] = std::acos(1.0f);
res_access[i++] = std::asin(0.0f);
Expand Down