@@ -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+
5160template <typename PropertyList>
5261property_list GetReductionPropertyList (PropertyList properties) {
5362 if constexpr (properties.template has_property <
@@ -79,13 +88,16 @@ struct IsDeterministicOperator<DeterministicOperatorWrapper<BinaryOperation>>
7988template <typename BufferT, typename BinaryOperation, typename PropertyList>
8089auto 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
8798template <typename T, typename BinaryOperation, typename PropertyList>
8899auto 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>
96108auto 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