Skip to content

Commit 2aa6ea1

Browse files
committed
Use nearbyint() as alias of rint() for Kokkos SYCL backend
1 parent e7a7238 commit 2aa6ea1

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/utilities/include/metaphysicl/metaphysicl_math.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,34 @@ namespace math {
9090
return detail::unqualified_##NAME(x); \
9191
}
9292

93+
#ifdef METAPHYSICL_KOKKOS_COMPILATION
94+
#define METAPHYSICL_MATH_UNARY_ALIAS(ALIAS, NAME) \
95+
namespace detail { \
96+
template <class X> METAPHYSICL_INLINE auto unqualified_##ALIAS(const X &x) { \
97+
if constexpr (std::is_arithmetic_v<X>) \
98+
return Kokkos::NAME(x); \
99+
else \
100+
return NAME(x); \
101+
} \
102+
} \
103+
template <class X> METAPHYSICL_INLINE auto ALIAS(const X &x) { \
104+
return detail::unqualified_##ALIAS(x); \
105+
}
106+
#else
107+
#define METAPHYSICL_MATH_UNARY_ALIAS(ALIAS, NAME) \
108+
namespace detail { \
109+
template <class X> METAPHYSICL_INLINE auto unqualified_##ALIAS(const X &x) { \
110+
if constexpr (std::is_arithmetic_v<X>) \
111+
return std::NAME(x); \
112+
else \
113+
return NAME(x); \
114+
} \
115+
} \
116+
template <class X> METAPHYSICL_INLINE auto ALIAS(const X &x) { \
117+
return detail::unqualified_##ALIAS(x); \
118+
}
119+
#endif
120+
93121
// Macro to call when there is a backing math function in c
94122
#define METAPHYSICL_MATH_BINARY(NAME) \
95123
METAPHYSICL_MATH_DETAIL_UNQUALIFIED_BINARY(NAME) \
@@ -129,7 +157,11 @@ METAPHYSICL_MATH_UNARY(erf)
129157
METAPHYSICL_MATH_UNARY(erfc)
130158
METAPHYSICL_MATH_UNARY(trunc)
131159
METAPHYSICL_MATH_UNARY(round)
160+
#if defined (METAPHYSICL_KOKKOS_COMPILATION) && defined(KOKKOS_ENABLE_SYCL)
161+
METAPHYSICL_MATH_UNARY_ALIAS(nearbyint, rint)
162+
#else
132163
METAPHYSICL_MATH_UNARY(nearbyint)
164+
#endif
133165
METAPHYSICL_MATH_UNARY_STD(rint)
134166
METAPHYSICL_MATH_UNARY(real)
135167
METAPHYSICL_MATH_UNARY(imag)

0 commit comments

Comments
 (0)