Skip to content

Commit 5fa19f2

Browse files
committed
Add ufunc implementation
1 parent caee787 commit 5fa19f2

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

dpnp/backend/extensions/ufunc/elementwise_functions/erf_funcs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static void populate(py::module_ m,
209209

210210
MACRO_DEFINE_IMPL(erf, Erf);
211211
MACRO_DEFINE_IMPL(erfc, Erfc);
212+
MACRO_DEFINE_IMPL(erfcx, Erfcx);
212213
} // namespace impl
213214

214215
void init_erf_funcs(py::module_ m)
@@ -228,5 +229,9 @@ void init_erf_funcs(py::module_ m)
228229
impl::populate<impl::ErfcContigFactory, impl::ErfcStridedFactory>(
229230
m, "_erfc", "", impl::erfc_contig_dispatch_vector,
230231
impl::erfc_strided_dispatch_vector);
232+
233+
impl::populate<impl::ErfcxContigFactory, impl::ErfcxStridedFactory>(
234+
m, "_erfcx", "", impl::erfcx_contig_dispatch_vector,
235+
impl::erfcx_strided_dispatch_vector);
231236
}
232237
} // namespace dpnp::extensions::ufunc

dpnp/backend/kernels/elementwise_functions/erf.hpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@
2929

3030
#include <sycl/sycl.hpp>
3131

32+
/**
33+
* Include <sycl/ext/intel/math.hpp> only when targeting to Intel devices.
34+
*/
35+
#if defined(__INTEL_LLVM_COMPILER)
36+
#define __SYCL_EXT_INTEL_MATH_SUPPORT
37+
#endif
38+
39+
#if defined(__SYCL_EXT_INTEL_MATH_SUPPORT)
40+
#include <sycl/ext/intel/math.hpp>
41+
#else
42+
#include <cmath>
43+
#endif
44+
3245
namespace dpnp::kernels::erfs
3346
{
3447
template <typename OpT, typename ArgT, typename ResT>
@@ -62,13 +75,20 @@ struct BaseFunctor
6275
template <typename Tp> \
6376
static Tp apply(const Tp &x) \
6477
{ \
65-
return sycl::__name__(x); \
78+
return __name__(x); \
6679
} \
6780
}; \
6881
\
6982
template <typename ArgT, typename ResT> \
7083
using __f_name__##Functor = BaseFunctor<__f_name__##Op, ArgT, ResT>;
7184

72-
MACRO_DEFINE_FUNCTOR(erf, Erf);
73-
MACRO_DEFINE_FUNCTOR(erfc, Erfc);
85+
MACRO_DEFINE_FUNCTOR(sycl::erf, Erf);
86+
MACRO_DEFINE_FUNCTOR(sycl::erfc, Erfc);
87+
MACRO_DEFINE_FUNCTOR(
88+
#if defined(__SYCL_EXT_INTEL_MATH_SUPPORT)
89+
sycl::ext::intel::math::erfcx,
90+
#else
91+
std::erfc,
92+
#endif
93+
Erfcx);
7494
} // namespace dpnp::kernels::erfs

0 commit comments

Comments
 (0)