Skip to content

Commit b465652

Browse files
committed
Add mandate for known identity values
1 parent 79f4805 commit b465652

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_reduction_properties.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ __unspecified__ reduction(span<T, Extent> vars, const T& identity,
133133
}
134134
----
135135

136+
_Mandates_: The specified `properties` are compatible with the reduction,
137+
according to the description of each individual property.
138+
136139
=== Reduction properties
137140

138141
New `reduction` properties are introduced to allow developers to constrain
@@ -186,6 +189,10 @@ use of atomic operations, etc. _{endnote}_]
186189
|Adds the same requirement as
187190
`sycl::property::reduction::initialize_to_identity`.
188191

192+
For `reduction` overloads without an `identity` parameter, the identity of the
193+
combination operation must be identifiable via the `known_identity` trait
194+
class.
195+
189196
|===
190197

191198

sycl/include/sycl/ext/oneapi/experimental/reduction_properties.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ auto WrapOp(BinaryOperation combiner, PropertyList properties) {
4848
}
4949
}
5050

51+
template <typename T, typename BinaryOperation, typename PropertyList>
52+
void CheckReductionIdentity(PropertyList properties) {
53+
if constexpr (properties.template has_property<
54+
ext::oneapi::experimental::initialize_to_identity_key>()) {
55+
static_assert(has_known_identity_v<BinaryOperation, T>,
56+
"initialize_to_identity requires an identity value.");
57+
}
58+
}
59+
5160
template <typename PropertyList>
5261
property_list GetReductionPropertyList(PropertyList properties) {
5362
if constexpr (properties.template has_property<
@@ -79,13 +88,16 @@ struct IsDeterministicOperator<DeterministicOperatorWrapper<BinaryOperation>>
7988
template <typename BufferT, typename BinaryOperation, typename PropertyList>
8089
auto reduction(BufferT vars, handler &cgh, BinaryOperation combiner,
8190
PropertyList properties) {
91+
detail::CheckReductionIdentity<typename BufferT::value_type, BinaryOperation>(
92+
properties);
8293
auto WrappedOp = detail::WrapOp(combiner, properties);
8394
auto RuntimeProps = detail::GetReductionPropertyList(properties);
8495
return reduction(vars, cgh, WrappedOp, RuntimeProps);
8596
}
8697

8798
template <typename T, typename BinaryOperation, typename PropertyList>
8899
auto reduction(T *var, BinaryOperation combiner, PropertyList properties) {
100+
detail::CheckReductionIdentity<T, BinaryOperation>(properties);
89101
auto WrappedOp = detail::WrapOp(combiner, properties);
90102
auto RuntimeProps = detail::GetReductionPropertyList(properties);
91103
return reduction(var, WrappedOp, RuntimeProps);
@@ -95,6 +107,7 @@ template <typename T, size_t Extent, typename BinaryOperation,
95107
typename PropertyList>
96108
auto reduction(span<T, Extent> vars, BinaryOperation combiner,
97109
PropertyList properties) {
110+
detail::CheckReductionIdentity<T, BinaryOperation>(properties);
98111
auto WrappedOp = detail::WrapOp(combiner, properties);
99112
auto RuntimeProps = detail::GetReductionPropertyList(properties);
100113
return reduction(vars, WrappedOp, RuntimeProps);

0 commit comments

Comments
 (0)