Skip to content

Commit 160e45d

Browse files
authored
[SYCL][Doc] Deprecate reduction extension (#4941)
As discussed in #4831, we should officially deprecate the original reduction extension in favor of the equivalent SYCL 2020 reduction functionality. This PR only makes the changes to the documentation -- adding deprecation notices to the implementation will be done in a separate PR.
1 parent 2675499 commit 160e45d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

sycl/doc/extensions/Reduction/Reduction.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SYCL(TM) Proposals: Reductions for ND-Range Parallelism
22

3-
**IMPORTANT**: This specification is a draft.
3+
**IMPORTANT**: The functionality introduced by this extension is deprecated in favor of the standard reduction functionality outlined in [Section 4.9.2 "Reduction variables"](https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:reduction) of the SYCL 2020 Specification, Revision 3.
44

55
**NOTE**: Khronos(R) is a registered trademark and SYCL(TM) is a trademark of the Khronos Group, Inc.
66

@@ -17,6 +17,9 @@ It should also be noted that reductions are not limited to scalar values: the be
1717
# `reduction` Objects
1818

1919
```c++
20+
namespace sycl {
21+
namespace ext {
22+
namespace oneapi {
2023
template <class T, class BinaryOperation>
2124
unspecified reduction(accessor<T>& var, BinaryOperation combiner);
2225

@@ -34,12 +37,18 @@ unspecified reduction(span<T, Extent> var, BinaryOperation combiner);
3437

3538
template <class T, class Extent, class BinaryOperation>
3639
unspecified reduction(span<T, Extent> var, const T& identity, BinaryOperation combiner);
40+
}
41+
}
42+
}
3743
```
3844
3945
The exact behavior of a reduction is specific to an implementation; the only interface exposed to the user is the set of functions above, which construct an unspecified `reduction` object encapsulating the reduction variable, an optional operator identity and the reduction operator. For user-defined binary operations, an implementation should issue a compile-time warning if an identity is not specified and this is known to negatively impact performance (e.g. as a result of the implementation choosing a different reduction algorithm). For standard binary operations (e.g. `std::plus`) on arithmetic types, the implementation must determine the correct identity automatically in order to avoid performance penalties.
4046
4147
If an implementation can identify the identity value for a given combination of accumulator type `AccumulatorT` and function object type `BinaryOperation`, the value is defined as a member of the `known_identity` trait class:
4248
```c++
49+
namespace sycl {
50+
namespace ext {
51+
namespace oneapi {
4352
template <typename BinaryOperation, typename AccumulatorT>
4453
struct known_identity {
4554
static constexpr AccumulatorT value;
@@ -48,11 +57,17 @@ struct known_identity {
4857
// Available if C++17
4958
template <typename BinaryOperation, typename AccumulatorT>
5059
inline constexpr AccumulatorT known_identity_v = known_identity<BinaryOperation, AccumulatorT>::value;
60+
}
61+
}
62+
}
5163
```
5264

5365
Whether `known_identity<BinaryOperation, AccumulatorT>::value` exists can be tested using the `has_known_identity` trait class:
5466

5567
```c++
68+
namespace sycl {
69+
namespace ext {
70+
namespace oneapi {
5671
template <typename BinaryOperation, typename AccumulatorT>
5772
struct has_known_identity {
5873
static constexpr bool value;
@@ -61,6 +76,9 @@ struct has_known_identity {
6176
// Available if C++17
6277
template <typename BinaryOperation, typename AccumulatorT>
6378
inline constexpr bool has_known_identity_v = has_known_identity<BinaryOperation, AccumulatorT>::value;
79+
}
80+
}
81+
}
6482
```
6583
6684
The dimensionality of the `accessor` passed to the `reduction` function specifies the dimensionality of the reduction variable: a 0-dimensional `accessor` represents a scalar reduction, and any other dimensionality represents an array reduction. Specifying an array reduction of size N is functionally equivalent to specifying N independent scalar reductions. The access mode of the accessor determines whether the reduction variable's original value is included in the reduction (i.e. for `access::mode::read_write` it is included, and for `access::mode::discard_write` it is not). Multiple reductions aliasing the same output results in undefined behavior.
@@ -70,6 +88,9 @@ The dimensionality of the `accessor` passed to the `reduction` function specifie
7088
# `reducer` Objects
7189
7290
```c++
91+
namespace sycl {
92+
namespace ext {
93+
namespace oneapi {
7394
// Exposition only
7495
template <class T, class BinaryOperation, int Dimensions, /* implementation-defined */>
7596
class reducer
@@ -91,6 +112,9 @@ class reducer
91112
92113
// other operators should be made available for standard functors
93114
template <typename T> auto& operator+=(reducer<T,std::plus<T>,0>&, const T&);
115+
}
116+
}
117+
}
94118
```
95119

96120
The `reducer` class is not user-constructible, and can only be constructed by an implementation given a `reduction` object. The `combine` function uses the specified `BinaryOperation` to combine the `partial` result with the value held (or referenced) by an instance of `reducer`, and is the only way to update the reducer value for user-supplied combination functions. Other convenience operators should be defined for standard combination functions (e.g. `+=` for `std::plus`).

0 commit comments

Comments
 (0)