-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL][ESIMD] Convert esimd operator to friend method. #2994
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,13 +180,26 @@ template <typename BaseTy, typename RegionTy> class simd_view { | |
} | ||
|
||
#define DEF_BINOP(BINOP, OPASSIGN) \ | ||
auto operator BINOP(const value_type &RHS) const { \ | ||
ESIMD_INLINE friend auto operator BINOP(const simd_view &X, \ | ||
const value_type &Y) { \ | ||
using ComputeTy = compute_type_t<value_type>; \ | ||
auto V0 = convert<typename ComputeTy::vector_type>(read().data()); \ | ||
auto V1 = convert<typename ComputeTy::vector_type>(RHS.data()); \ | ||
auto V0 = convert<typename ComputeTy::vector_type>(X.read().data()); \ | ||
auto V1 = convert<typename ComputeTy::vector_type>(Y.data()); \ | ||
auto V2 = V0 BINOP V1; \ | ||
return ComputeTy(V2); \ | ||
} \ | ||
ESIMD_INLINE friend auto operator BINOP(const value_type &X, \ | ||
const simd_view &Y) { \ | ||
using ComputeTy = compute_type_t<value_type>; \ | ||
auto V0 = convert<typename ComputeTy::vector_type>(X.data()); \ | ||
auto V1 = convert<typename ComputeTy::vector_type>(Y.read().data()); \ | ||
auto V2 = V0 BINOP V1; \ | ||
return ComputeTy(V2); \ | ||
} \ | ||
ESIMD_INLINE friend auto operator BINOP(const simd_view &X, \ | ||
const simd_view &Y) { \ | ||
return (X BINOP Y.read()); \ | ||
} \ | ||
simd_view &operator OPASSIGN(const value_type &RHS) { \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is value_type BINOP value_type combination missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot have that, cause ambiguous with the friend method definition in simd class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see thanks. |
||
using ComputeTy = compute_type_t<value_type>; \ | ||
auto V0 = convert<typename ComputeTy::vector_type>(read().data()); \ | ||
|
@@ -195,6 +208,9 @@ template <typename BaseTy, typename RegionTy> class simd_view { | |
auto V3 = convert<vector_type>(V2); \ | ||
write(V3); \ | ||
return *this; \ | ||
} \ | ||
simd_view &operator OPASSIGN(const simd_view &RHS) { \ | ||
return (*this OPASSIGN RHS.read()); \ | ||
} | ||
|
||
DEF_BINOP(+, +=) | ||
|
@@ -205,10 +221,21 @@ template <typename BaseTy, typename RegionTy> class simd_view { | |
#undef DEF_BINOP | ||
|
||
#define DEF_RELOP(RELOP) \ | ||
simd<uint16_t, length> operator RELOP(const simd_view &RHS) const { \ | ||
auto R = read().data() RELOP RHS.read().data(); \ | ||
ESIMD_INLINE friend simd<uint16_t, length> operator RELOP( \ | ||
const simd_view &X, const value_type &Y) { \ | ||
auto R = X.read().data() RELOP Y.data(); \ | ||
mask_type_t<length> M(1); \ | ||
return M & convert<mask_type_t<length>>(R); \ | ||
} \ | ||
ESIMD_INLINE friend simd<uint16_t, length> operator RELOP( \ | ||
const value_type &X, const simd_view &Y) { \ | ||
auto R = X.data() RELOP Y.read().data(); \ | ||
mask_type_t<length> M(1); \ | ||
return M & convert<mask_type_t<length>>(R); \ | ||
} \ | ||
ESIMD_INLINE friend simd<uint16_t, length> operator RELOP( \ | ||
const simd_view &X, const simd_view &Y) { \ | ||
return (X RELOP Y.read()); \ | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is value_type RELOP value_type combination missing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot have that, cause ambiguous with the friend method definition in simd class |
||
|
||
DEF_RELOP(>) | ||
|
@@ -221,19 +248,32 @@ template <typename BaseTy, typename RegionTy> class simd_view { | |
#undef DEF_RELOP | ||
|
||
#define DEF_LOGIC_OP(LOGIC_OP, OPASSIGN) \ | ||
simd_view operator LOGIC_OP(const simd_view &RHS) const { \ | ||
ESIMD_INLINE friend auto operator LOGIC_OP(const simd_view &X, \ | ||
const value_type &Y) { \ | ||
static_assert(std::is_integral<element_type>(), "not integral type"); \ | ||
auto V2 = read().data() LOGIC_OP RHS.read().data(); \ | ||
return simd_view(V2); \ | ||
auto V2 = X.read().data() LOGIC_OP Y.data(); \ | ||
return simd<element_type, length>(V2); \ | ||
} \ | ||
simd_view &operator OPASSIGN(const simd_view &RHS) { \ | ||
ESIMD_INLINE friend auto operator LOGIC_OP(const value_type &X, \ | ||
const simd_view &Y) { \ | ||
static_assert(std::is_integral<element_type>(), "not integral type"); \ | ||
auto V2 = X.data() LOGIC_OP Y.read().data(); \ | ||
return simd<element_type, length>(V2); \ | ||
} \ | ||
ESIMD_INLINE friend auto operator LOGIC_OP(const simd_view &X, \ | ||
const simd_view &Y) { \ | ||
return (X LOGIC_OP Y.read()); \ | ||
} \ | ||
simd_view &operator OPASSIGN(const value_type &RHS) { \ | ||
static_assert(std::is_integral<element_type>(), "not integeral type"); \ | ||
auto V2 = read().data LOGIC_OP RHS.read().data(); \ | ||
auto V2 = read().data() LOGIC_OP RHS.data(); \ | ||
auto V3 = convert<vector_type>(V2); \ | ||
write(V3); \ | ||
return *this; \ | ||
} \ | ||
simd_view &operator OPASSIGN(const simd_view &RHS) { \ | ||
return (*this OPASSIGN RHS.read()); \ | ||
} | ||
|
||
DEF_LOGIC_OP(&, &=) | ||
DEF_LOGIC_OP(|, |=) | ||
DEF_LOGIC_OP(^, ^=) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (maybe for another patch): since
M
is all ones, isn'tM & convert<mask_type_t<N>>(R)
equivalent toconvert<mask_type_t<N>>(R)
thus making M redundant?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M(1) is not part of my change. Not sure why it is written this way. I would be cautious to make unnecessary change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see that it is not part of this change, that's why it is just a nit for another patch. I thought you wrote this part.