Skip to content

Commit b249099

Browse files
authored
[SYCL] Reduction: support +=,*=,|=,^=,&= operations for custom type reducers (#3193)
The corresponding LIT test for this change-set is: intel/llvm-test-suite#140 Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 4a78734 commit b249099

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

sycl/include/CL/sycl/ONEAPI/reduction.hpp

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@ class reducer {
238238

239239
T getIdentity() const { return MIdentity; }
240240

241+
template <typename _T = T>
242+
enable_if_t<IsReduPlus<_T, BinaryOperation>::value>
243+
operator+=(const _T &Partial) {
244+
combine(Partial);
245+
}
246+
247+
template <typename _T = T>
248+
enable_if_t<IsReduMultiplies<_T, BinaryOperation>::value>
249+
operator*=(const _T &Partial) {
250+
combine(Partial);
251+
}
252+
253+
template <typename _T = T>
254+
enable_if_t<IsReduBitOR<_T, BinaryOperation>::value>
255+
operator|=(const _T &Partial) {
256+
combine(Partial);
257+
}
258+
259+
template <typename _T = T>
260+
enable_if_t<IsReduBitXOR<_T, BinaryOperation>::value>
261+
operator^=(const _T &Partial) {
262+
combine(Partial);
263+
}
264+
265+
template <typename _T = T>
266+
enable_if_t<IsReduBitAND<_T, BinaryOperation>::value>
267+
operator&=(const _T &Partial) {
268+
combine(Partial);
269+
}
270+
241271
T MValue;
242272

243273
private:
@@ -281,48 +311,33 @@ class reducer<T, BinaryOperation,
281311
}
282312

283313
template <typename _T = T>
284-
enable_if_t<std::is_same<_T, T>::value &&
285-
IsReduPlus<T, BinaryOperation>::value,
286-
reducer &>
314+
enable_if_t<IsReduPlus<_T, BinaryOperation>::value>
287315
operator+=(const _T &Partial) {
288316
combine(Partial);
289-
return *this;
290317
}
291318

292319
template <typename _T = T>
293-
enable_if_t<std::is_same<_T, T>::value &&
294-
IsReduMultiplies<T, BinaryOperation>::value,
295-
reducer &>
320+
enable_if_t<IsReduMultiplies<_T, BinaryOperation>::value>
296321
operator*=(const _T &Partial) {
297322
combine(Partial);
298-
return *this;
299323
}
300324

301325
template <typename _T = T>
302-
enable_if_t<std::is_same<_T, T>::value &&
303-
IsReduBitOR<T, BinaryOperation>::value,
304-
reducer &>
326+
enable_if_t<IsReduBitOR<_T, BinaryOperation>::value>
305327
operator|=(const _T &Partial) {
306328
combine(Partial);
307-
return *this;
308329
}
309330

310331
template <typename _T = T>
311-
enable_if_t<std::is_same<_T, T>::value &&
312-
IsReduBitXOR<T, BinaryOperation>::value,
313-
reducer &>
332+
enable_if_t<IsReduBitXOR<_T, BinaryOperation>::value>
314333
operator^=(const _T &Partial) {
315334
combine(Partial);
316-
return *this;
317335
}
318336

319337
template <typename _T = T>
320-
enable_if_t<std::is_same<_T, T>::value &&
321-
IsReduBitAND<T, BinaryOperation>::value,
322-
reducer &>
338+
enable_if_t<IsReduBitAND<_T, BinaryOperation>::value>
323339
operator&=(const _T &Partial) {
324340
combine(Partial);
325-
return *this;
326341
}
327342

328343
/// Atomic ADD operation: *ReduVarPtr += MValue;

0 commit comments

Comments
 (0)