@@ -24,7 +24,7 @@ using _iml_half_internal = uint16_t;
2424using _iml_bf16_internal = uint16_t ;
2525
2626#include < sycl/bit_cast.hpp>
27- #include < sycl/builtins .hpp>
27+ #include < sycl/detail/defines_elementary .hpp>
2828#include < sycl/ext/intel/math/imf_fp_conversions.hpp>
2929#include < sycl/ext/intel/math/imf_half_trivial.hpp>
3030#include < sycl/ext/intel/math/imf_integer_utils.hpp>
@@ -34,50 +34,37 @@ using _iml_bf16_internal = uint16_t;
3434#include < sycl/half_type.hpp>
3535#include < type_traits>
3636
37- extern " C" {
38- float __imf_saturatef (float );
39- float __imf_copysignf (float , float );
40- double __imf_copysign (double , double );
41- _iml_half_internal __imf_copysignf16 (_iml_half_internal, _iml_half_internal);
42- float __imf_ceilf (float );
43- double __imf_ceil (double );
44- _iml_half_internal __imf_ceilf16 (_iml_half_internal);
45- float __imf_floorf (float );
46- double __imf_floor (double );
47- _iml_half_internal __imf_floorf16 (_iml_half_internal);
48- float __imf_fsigmf (float );
49- _iml_half_internal __imf_fsigmf16 (_iml_half_internal);
50- _iml_bf16_internal __imf_fsigmbf16 (_iml_bf16_internal);
51- float __imf_rintf (float );
52- double __imf_rint (double );
53- _iml_half_internal __imf_invf16 (_iml_half_internal);
54- float __imf_invf (float );
55- double __imf_inv (double );
56- _iml_half_internal __imf_rintf16 (_iml_half_internal);
57- float __imf_sqrtf (float );
58- double __imf_sqrt (double );
59- _iml_half_internal __imf_sqrtf16 (_iml_half_internal);
60- float __imf_rsqrtf (float );
61- double __imf_rsqrt (double );
62- _iml_half_internal __imf_rsqrtf16 (_iml_half_internal);
63- float __imf_truncf (float );
64- double __imf_trunc (double );
65- _iml_half_internal __imf_truncf16 (_iml_half_internal);
66- double __imf_rcp64h (double );
67- };
68-
6937namespace sycl {
7038inline namespace _V1 {
7139namespace ext ::intel::math {
7240
7341static_assert (sizeof (sycl::half) == sizeof (_iml_half_internal),
7442 " sycl::half is not compatible with _iml_half_internal." );
7543
44+ // / --------------------------------------------------------------------------
45+ // / saturate(x) function
46+ // / Clamps the float input to [+0.0, 1.0].
47+ // / --------------------------------------------------------------------------
48+ extern " C" {
49+ __DPCPP_SYCL_EXTERNAL float __imf_saturatef (float );
50+ }
51+
7652template <typename Tp>
7753std::enable_if_t <std::is_same_v<Tp, float >, float > saturate (Tp x) {
7854 return __imf_saturatef (x);
7955}
8056
57+ // / --------------------------------------------------------------------------
58+ // / copysign(x) function
59+ // / Creates value with given magnitude, copying sign of second input.
60+ // / --------------------------------------------------------------------------
61+ extern " C" {
62+ __DPCPP_SYCL_EXTERNAL float __imf_copysignf (float , float );
63+ __DPCPP_SYCL_EXTERNAL double __imf_copysign (double , double );
64+ __DPCPP_SYCL_EXTERNAL
65+ _iml_half_internal __imf_copysignf16 (_iml_half_internal, _iml_half_internal);
66+ }
67+
8168template <typename Tp>
8269std::enable_if_t <std::is_same_v<Tp, float >, float > copysign (Tp x, Tp y) {
8370 return __imf_copysignf (x, y);
@@ -96,6 +83,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half>, sycl::half> copysign(Tp x,
9683 return sycl::bit_cast<sycl::half>(__imf_copysignf16 (xi, yi));
9784}
9885
86+ // / --------------------------------------------------------------------------
87+ // / ceil(x) function
88+ // / Returns ceiling value of the input.
89+ // / --------------------------------------------------------------------------
90+ extern " C" {
91+ __DPCPP_SYCL_EXTERNAL float __imf_ceilf (float );
92+ __DPCPP_SYCL_EXTERNAL double __imf_ceil (double );
93+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_ceilf16 (_iml_half_internal);
94+ }
95+
9996template <typename Tp>
10097std::enable_if_t <std::is_same_v<Tp, float >, float > ceil (Tp x) {
10198 return __imf_ceilf (x);
@@ -117,6 +114,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> ceil(Tp x) {
117114 return sycl::half2{ceil (x.s0 ()), ceil (x.s1 ())};
118115}
119116
117+ // / --------------------------------------------------------------------------
118+ // / floor(x) function
119+ // / Returns the largest integral value less than or equal to input.
120+ // / --------------------------------------------------------------------------
121+ extern " C" {
122+ __DPCPP_SYCL_EXTERNAL float __imf_floorf (float );
123+ __DPCPP_SYCL_EXTERNAL double __imf_floor (double );
124+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_floorf16 (_iml_half_internal);
125+ }
126+
120127template <typename Tp>
121128std::enable_if_t <std::is_same_v<Tp, float >, float > floor (Tp x) {
122129 return __imf_floorf (x);
@@ -138,6 +145,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> floor(Tp x) {
138145 return sycl::half2{floor (x.s0 ()), floor (x.s1 ())};
139146}
140147
148+ // / --------------------------------------------------------------------------
149+ // / inv(x) function
150+ // / Returns 1.0 / x.
151+ // / --------------------------------------------------------------------------
152+ extern " C" {
153+ __DPCPP_SYCL_EXTERNAL float __imf_invf (float );
154+ __DPCPP_SYCL_EXTERNAL double __imf_inv (double );
155+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_invf16 (_iml_half_internal);
156+ }
157+
141158template <typename Tp>
142159std::enable_if_t <std::is_same_v<Tp, float >, float > inv (Tp x) {
143160 return __imf_invf (x);
@@ -159,6 +176,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> inv(Tp x) {
159176 return sycl::half2{inv (x.s0 ()), inv (x.s1 ())};
160177}
161178
179+ // / --------------------------------------------------------------------------
180+ // / rint(x) function
181+ // / Rounds a floating-point value to the nearest integer value.
182+ // / --------------------------------------------------------------------------
183+ extern " C" {
184+ __DPCPP_SYCL_EXTERNAL float __imf_rintf (float );
185+ __DPCPP_SYCL_EXTERNAL double __imf_rint (double );
186+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_rintf16 (_iml_half_internal);
187+ }
188+
162189template <typename Tp>
163190std::enable_if_t <std::is_same_v<Tp, float >, float > rint (Tp x) {
164191 return __imf_rintf (x);
@@ -180,6 +207,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> rint(Tp x) {
180207 return sycl::half2{rint (x.s0 ()), rint (x.s1 ())};
181208}
182209
210+ // / --------------------------------------------------------------------------
211+ // / sqrt(x) function
212+ // / Returns square root of input.
213+ // / --------------------------------------------------------------------------
214+ extern " C" {
215+ __DPCPP_SYCL_EXTERNAL float __imf_sqrtf (float );
216+ __DPCPP_SYCL_EXTERNAL double __imf_sqrt (double );
217+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_sqrtf16 (_iml_half_internal);
218+ }
219+
183220template <typename Tp>
184221std::enable_if_t <std::is_same_v<Tp, float >, float > sqrt (Tp x) {
185222 return __imf_sqrtf (x);
@@ -201,6 +238,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> sqrt(Tp x) {
201238 return sycl::half2{sqrt (x.s0 ()), sqrt (x.s1 ())};
202239}
203240
241+ // / --------------------------------------------------------------------------
242+ // / rsqrt(x) function
243+ // / Returns 1.0 / sqrt(x).
244+ // / --------------------------------------------------------------------------
245+ extern " C" {
246+ __DPCPP_SYCL_EXTERNAL float __imf_rsqrtf (float );
247+ __DPCPP_SYCL_EXTERNAL double __imf_rsqrt (double );
248+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_rsqrtf16 (_iml_half_internal);
249+ }
250+
204251template <typename Tp>
205252std::enable_if_t <std::is_same_v<Tp, float >, float > rsqrt (Tp x) {
206253 return __imf_rsqrtf (x);
@@ -222,6 +269,16 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> rsqrt(Tp x) {
222269 return sycl::half2{rsqrt (x.s0 ()), rsqrt (x.s1 ())};
223270}
224271
272+ // / --------------------------------------------------------------------------
273+ // / trunc(x) function
274+ // / Truncates input to the integral part.
275+ // / --------------------------------------------------------------------------
276+ extern " C" {
277+ __DPCPP_SYCL_EXTERNAL float __imf_truncf (float );
278+ __DPCPP_SYCL_EXTERNAL double __imf_trunc (double );
279+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_truncf16 (_iml_half_internal);
280+ }
281+
225282template <typename Tp>
226283std::enable_if_t <std::is_same_v<Tp, float >, float > trunc (Tp x) {
227284 return __imf_truncf (x);
@@ -243,18 +300,27 @@ std::enable_if_t<std::is_same_v<Tp, sycl::half2>, sycl::half2> trunc(Tp x) {
243300 return sycl::half2{trunc (x.s0 ()), trunc (x.s1 ())};
244301}
245302
303+ // / --------------------------------------------------------------------------
304+ // / rcp64h(x) function
305+ // / Provides high 32 bits of 1.0 / x.
306+ // / --------------------------------------------------------------------------
307+ extern " C" {
308+ __DPCPP_SYCL_EXTERNAL double __imf_rcp64h (double );
309+ }
310+
246311template <typename Tp>
247312std::enable_if_t <std::is_same_v<Tp, double >, double > rcp64h (Tp x) {
248313 return __imf_rcp64h (x);
249314}
315+
250316// / --------------------------------------------------------------------------
251317// / sigmoid(x) function
252318// / --------------------------------------------------------------------------
253319extern " C" {
254- _iml_bf16_internal __imf_fsigmbf16 (_iml_bf16_internal x);
255- _iml_half_internal __imf_fsigmf16 (_iml_half_internal x);
256- float __imf_fsigmf (float x);
257- };
320+ __DPCPP_SYCL_EXTERNAL _iml_bf16_internal __imf_fsigmbf16 (_iml_bf16_internal x);
321+ __DPCPP_SYCL_EXTERNAL _iml_half_internal __imf_fsigmf16 (_iml_half_internal x);
322+ __DPCPP_SYCL_EXTERNAL float __imf_fsigmf (float x);
323+ }
258324
259325template <typename Tp>
260326std::enable_if_t <std::is_same_v<Tp, sycl::half>, sycl::half> sigmoid (Tp x) {
0 commit comments