Skip to content

[SYCL] Augment known_identity for std::complex and std::plus. #8425

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 5 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ NOTE: `sycl::bit_and`, `sycl::bit_or`, `sycl::bit_xor`, `sycl::logical_and`,
because their behaviors are defined in terms of operators that `std::complex`
does not implement.

=== Known Identities

This extension adds the following known identities, augmenting https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#table.identities[Table 123] in the core SYCL specification:
[cols="5,30,70"]
[grid="rows"]
[options="header"]
|========================================
|Operator|Available When|Identity
|`sycl::plus`|`std::is_same_v<std::remove_cv_t<AccumulatorT>, std::complex<float>> \|\|
std::is_same_v<std::remove_cv_t<AccumulatorT>, std::complex<double>>`|`AccumulatorT{}`
|========================================

== Issues

None.
Expand Down
10 changes: 9 additions & 1 deletion sycl/include/sycl/known_identity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,22 @@ using IsLogicalOR =
bool_constant<std::is_same<BinaryOperation, sycl::logical_or<T>>::value ||
std::is_same<BinaryOperation, sycl::logical_or<void>>::value>;

template <typename T>
using isComplex =
bool_constant<std::is_same<T, std::complex<float>>::value ||
std::is_same<T, std::complex<double>>::value>;

// Identity = 0
template <typename T, class BinaryOperation>
using IsZeroIdentityOp =
bool_constant<(is_geninteger<T>::value &&
(IsPlus<T, BinaryOperation>::value ||
IsBitOR<T, BinaryOperation>::value ||
IsBitXOR<T, BinaryOperation>::value)) ||
(is_genfloat<T>::value && IsPlus<T, BinaryOperation>::value)>;
(is_genfloat<T>::value &&
IsPlus<T, BinaryOperation>::value) ||
(isComplex<T>::value &&
IsPlus<T, BinaryOperation>::value)>;

// Identity = 1
template <typename T, class BinaryOperation>
Expand Down