Skip to content

[ESIMD] Enable op(vector, scalar) variant of binary ext. math functions. #5651

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
Feb 25, 2022
Merged
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
15 changes: 10 additions & 5 deletions sycl/include/sycl/ext/intel/experimental/esimd/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ __ESIMD_UNARY_INTRINSIC_DEF(__ESIMD_EMATH_COND, cos, cos)
#undef __ESIMD_UNARY_INTRINSIC_DEF

#define __ESIMD_BINARY_INTRINSIC_DEF(COND, name, iname) \
/** Vector version. */ \
/** (vector, vector) version. */ \
template <class T, int N, class U, class Sat = saturation_off_tag, \
class = std::enable_if_t<COND>> \
__ESIMD_API simd<T, N> name(simd<T, N> src0, simd<U, N> src1, \
Expand All @@ -1486,13 +1486,18 @@ __ESIMD_UNARY_INTRINSIC_DEF(__ESIMD_EMATH_COND, cos, cos)
return esimd::saturate<T>(simd<T, N>(res_raw)); \
} \
\
/** Scalar version. */ \
/** (vector, scalar) version. */ \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't (scalar, vector) variant be supported as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a good point, thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out, scalar vector is supported as well, as implicit conversion works for the first parameter. I updated the test adding this (and few other similar) test cases.

template <class T, int N, class U, class Sat = saturation_off_tag, \
class = std::enable_if_t<COND>> \
__ESIMD_API simd<T, N> name(simd<T, N> src0, U src1, Sat sat = {}) { \
return name<T, N, U>(src0, simd<U, N>(src1), sat); \
} \
\
/** (scalar, scalar) version. */ \
template <class T, class U, class Sat = saturation_off_tag, \
class = std::enable_if_t<COND>> \
__ESIMD_API T name(T src0, U src1, Sat sat = {}) { \
simd<T, 1> src0_vec = src0; \
simd<U, 1> src1_vec = src1; \
simd<T, 1> res = name<T, 1, U>(src0_vec, src1_vec, sat); \
simd<T, 1> res = name<T, 1, U>(simd<T, 1>(src0), simd<U, 1>(src1), sat); \
return res[0]; \
}

Expand Down