Skip to content

Commit 2e73312

Browse files
[SYCL] Augment known_identity for std::complex and std::plus. (#8425)
This PR proposes to augment sycl::has_known_identity to return true for std::complex and std::plus operator. This will have two benefits: 1. It enables support for complex numbers in sycl::reduction without the user having to explicitly pass identity. 2. sycl::known_identity can now be used to simplify the implementation of group algorithms (See PR #5394). Also, this PR addresses the Github issue #5477. Test Case PR: intel/llvm-test-suite#1609
1 parent 8ac8200 commit 2e73312

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sycl/doc/extensions/proposed/sycl_ext_oneapi_complex_algorithms.asciidoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ NOTE: `sycl::bit_and`, `sycl::bit_or`, `sycl::bit_xor`, `sycl::logical_and`,
125125
because their behaviors are defined in terms of operators that `std::complex`
126126
does not implement.
127127

128+
=== Known Identities
129+
130+
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:
131+
[cols="5,30,70"]
132+
[grid="rows"]
133+
[options="header"]
134+
|========================================
135+
|Operator|Available When|Identity
136+
|`sycl::plus`|`std::is_same_v<std::remove_cv_t<AccumulatorT>, std::complex<float>> \|\|
137+
std::is_same_v<std::remove_cv_t<AccumulatorT>, std::complex<double>>`|`AccumulatorT{}`
138+
|========================================
139+
128140
== Issues
129141

130142
None.

sycl/include/sycl/known_identity.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,22 @@ using IsLogicalOR =
6363
bool_constant<std::is_same<BinaryOperation, sycl::logical_or<T>>::value ||
6464
std::is_same<BinaryOperation, sycl::logical_or<void>>::value>;
6565

66+
template <typename T>
67+
using isComplex =
68+
bool_constant<std::is_same<T, std::complex<float>>::value ||
69+
std::is_same<T, std::complex<double>>::value>;
70+
6671
// Identity = 0
6772
template <typename T, class BinaryOperation>
6873
using IsZeroIdentityOp =
6974
bool_constant<(is_geninteger<T>::value &&
7075
(IsPlus<T, BinaryOperation>::value ||
7176
IsBitOR<T, BinaryOperation>::value ||
7277
IsBitXOR<T, BinaryOperation>::value)) ||
73-
(is_genfloat<T>::value && IsPlus<T, BinaryOperation>::value)>;
78+
(is_genfloat<T>::value &&
79+
IsPlus<T, BinaryOperation>::value) ||
80+
(isComplex<T>::value &&
81+
IsPlus<T, BinaryOperation>::value)>;
7482

7583
// Identity = 1
7684
template <typename T, class BinaryOperation>

0 commit comments

Comments
 (0)