Skip to content

Commit f695479

Browse files
authored
[SYCL][Doc] Clarify reduction extension docs (#1535)
Add missing constructors and member functions implied by examples. Signed-off-by: John Pennycook <[email protected]>
1 parent 8bae483 commit f695479

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

sycl/doc/extensions/Reduction/Reduction.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,21 @@ unspecified reduction(accessor<T>& var, BinaryOperation combiner);
2222

2323
template <class T, class BinaryOperation>
2424
unspecified reduction(accessor<T>& var, const T& identity, BinaryOperation combiner);
25+
26+
template <class T, class BinaryOperation>
27+
unspecified reduction(T* var, BinaryOperation combiner);
28+
29+
template <class T, class BinaryOperation>
30+
unspecified reduction(T* var, const T& identity, BinaryOperation combiner);
31+
32+
template <class T, class Extent, class BinaryOperation>
33+
unspecified reduction(span<T, Extent> var, BinaryOperation combiner);
34+
35+
template <class T, class Extent, class BinaryOperation>
36+
unspecified reduction(span<T, Extent> var, const T& identity, BinaryOperation combiner);
2537
```
2638
27-
The exact behavior of a reduction is specific to an implementation; the only interface exposed to the user is the pair 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.
39+
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.
2840
2941
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.
3042
@@ -33,22 +45,27 @@ The dimensionality of the `accessor` passed to the `reduction` function specifie
3345
# `reducer` Objects
3446
3547
```c++
36-
template <class T, class BinaryOperation, /* implementation-defined */>
48+
// Exposition only
49+
template <class T, class BinaryOperation, int Dimensions, /* implementation-defined */>
3750
class reducer
3851
{
3952
// forbid reducer objects from being copied
40-
reducer(const reducer<T,BinaryOperation>&) = delete;
41-
reducer<T,BinaryOperation>& operator(const reducer<T,BinaryOperation>&) = delete;
53+
reducer(const reducer<T,BinaryOperation,Dimensions>&) = delete;
54+
reducer<T,BinaryOperation,Dimensions>& operator(const reducer<T,BinaryOperation,Dimensions>&) = delete;
4255
4356
// combine partial result with reducer
57+
// only available if Dimensions == 0
4458
void combine(const T& partial);
4559
60+
// only available if Dimensions > 1
61+
unspecified &operator[](size_t index) const;
62+
4663
// get identity of the associated reduction (if known)
4764
T identity() const;
4865
};
4966
5067
// other operators should be made available for standard functors
51-
template <typename T> auto& operator+=(reducer<T,std::plus<T>>&, const T&);
68+
template <typename T> auto& operator+=(reducer<T,std::plus<T>,0>&, const T&);
5269
```
5370

5471
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)