Skip to content

Commit 62793b7

Browse files
authored
[SYCL] Add support for scalbln (#14401)
Add support for missing scalbln function
1 parent 4443eff commit 62793b7

File tree

7 files changed

+36
-11
lines changed

7 files changed

+36
-11
lines changed

libdevice/cmath_wrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ float floorf(float x) { return __devicelib_floorf(x); }
6969
DEVICE_EXTERN_C_INLINE
7070
float scalbnf(float x, int n) { return __devicelib_scalbnf(x, n); }
7171

72+
DEVICE_EXTERN_C_INLINE
73+
float scalblnf(float x, long int n) { return __devicelib_scalblnf(x, n); }
74+
7275
DEVICE_EXTERN_C_INLINE
7376
float logf(float x) { return __devicelib_logf(x); }
7477

libdevice/cmath_wrapper_fp64.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ double ceil(double x) { return __devicelib_ceil(x); }
2525
DEVICE_EXTERN_C_INLINE
2626
double copysign(double x, double y) { return __devicelib_copysign(x, y); }
2727

28+
DEVICE_EXTERN_C_INLINE
29+
double scalbln(double x, long y) { return __devicelib_scalbln(x, y); }
30+
2831
DEVICE_EXTERN_C_INLINE
2932
double cospi(double x) { return __devicelib_cospi(x); }
3033

libdevice/device_math.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ float __devicelib_cospif(float x);
6464
DEVICE_EXTERN_C
6565
double __devicelib_cospi(double x);
6666

67+
DEVICE_EXTERN_C
68+
float __devicelib_scalblnf(float x, long int y);
69+
70+
DEVICE_EXTERN_C
71+
double __devicelib_scalbln(double x, long int y);
72+
6773
DEVICE_EXTERN_C
6874
float __devicelib_fmaxf(float x, float y);
6975

libdevice/fallback-cmath-fp64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ double __devicelib_copysign(double x, double y) {
2929
DEVICE_EXTERN_C_INLINE
3030
double __devicelib_cospi(double x) { return __spirv_ocl_cospi(x); }
3131

32+
DEVICE_EXTERN_C_INLINE
33+
double __devicelib_scalbln(double x, long int y) {
34+
return __spirv_ocl_ldexp(x, (int)y);
35+
}
36+
3237
DEVICE_EXTERN_C_INLINE
3338
double __devicelib_fmax(double x, double y) { return __spirv_ocl_fmax(x, y); }
3439

libdevice/fallback-cmath.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ float __devicelib_copysignf(float x, float y) {
3939
DEVICE_EXTERN_C_INLINE
4040
float __devicelib_cospif(float x) { return __spirv_ocl_cospi(x); }
4141

42+
DEVICE_EXTERN_C_INLINE
43+
float __devicelib_scalblnf(float x, long int y) {
44+
return __spirv_ocl_ldexp(x, (int)y);
45+
}
46+
4247
DEVICE_EXTERN_C_INLINE
4348
float __devicelib_fmaxf(float x, float y) { return __spirv_ocl_fmax(x, y); }
4449

sycl/test-e2e/DeviceLib/cmath_fp64_test.cpp

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

23-
#define TEST_NUM 73
23+
#define TEST_NUM 74
2424

2525
double ref[TEST_NUM] = {
26-
100, 0.5, 1.0, 0, 0, -2, 1, 2, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0,
27-
1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2,
28-
0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0, 0,
29-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
26+
6, 100, 0.5, 1.0, 0, 0, -2, 1, 2, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0,
27+
0, 1, 1, 0.5, 0, 2, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1,
28+
2, 0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN, 2, 0, 0, 0, 0, 0,
29+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
3030

3131
double refIptr = 1;
3232

@@ -61,6 +61,7 @@ template <class T> void device_cmath_test(s::queue &deviceQueue) {
6161
T minus_infinity = -INFINITY;
6262
double subnormal;
6363
*((uint64_t *)&subnormal) = 0xFFFFFFFFFFFFFULL;
64+
res_access[i++] = std::scalbln(1.5, 2);
6465
res_access[i++] = sycl::exp10(2.0);
6566
res_access[i++] = sycl::rsqrt(4.0);
6667
res_access[i++] = std::trunc(1.3);

sycl/test-e2e/DeviceLib/cmath_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cmath>
1616
#include <cstdint>
1717
#include <iostream>
18+
#include <std/experimental/simd.hpp>
1819
#include <sycl/detail/core.hpp>
1920
#include <sycl/usm.hpp>
2021

@@ -154,15 +155,15 @@ template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
154155
assert(quo == 0);
155156
}
156157

157-
// MSVC implements std::ldexp<float>, std::fabs<float> and std::frexp<float> by
158-
// invoking the 'double' version of corresponding C math functions(ldexp, fabs
159-
// and frexp). Those functions can only work on Windows with fp64 extension
160-
// support from underlying device.
158+
// MSVC implements std::scalbln<float>, std::ldexp<float>, std::fabs<float> and
159+
// std::frexp<float> by invoking the 'double' version of corresponding C math
160+
// functions(scalbln, ldexp, fabs and frexp). Those functions can only work on
161+
// Windows with fp64 extension support from underlying device.
161162
#ifndef _WIN32
162163
template <class T> void device_cmath_test_2(s::queue &deviceQueue) {
163-
constexpr int NumOfTestItems = 3;
164+
constexpr int NumOfTestItems = 4;
164165
T result[NumOfTestItems] = {-1};
165-
T ref[NumOfTestItems] = {0, 2, 1};
166+
T ref[NumOfTestItems] = {6, 0, 2, 1};
166167
// Variable exponent is an integer value to store the exponent in frexp
167168
// function
168169
int exponent = -1;
@@ -175,6 +176,7 @@ template <class T> void device_cmath_test_2(s::queue &deviceQueue) {
175176
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
176177
cgh.single_task<class DeviceMathTest2>([=]() {
177178
int i = 0;
179+
res_access[i++] = std::scalbln(1.5f, 2);
178180
res_access[i++] = std::frexp(0.0f, &exp_access[0]);
179181
res_access[i++] = std::ldexp(1.0f, 1);
180182
res_access[i++] = std::fabs(-1.0f);

0 commit comments

Comments
 (0)