20 #ifndef RAJA_PATTERN_DETAIL_REDUCE_HPP
21 #define RAJA_PATTERN_DETAIL_REDUCE_HPP
26 #define RAJA_DECLARE_REDUCER(OP, POL, COMBINER) \
27 template<typename T> \
28 class Reduce##OP<POL, T> \
29 : public reduce::detail::BaseReduce##OP<T, COMBINER> \
32 using Base = reduce::detail::BaseReduce##OP<T, COMBINER>; \
36 #define RAJA_DECLARE_INDEX_REDUCER(OP, POL, COMBINER) \
37 template<typename T, typename IndexType> \
38 class Reduce##OP<POL, T, IndexType> \
39 : public reduce::detail::BaseReduce##OP<T, IndexType, COMBINER> \
42 using Base = reduce::detail::BaseReduce##OP<T, IndexType, COMBINER>; \
46 #define RAJA_DECLARE_ALL_REDUCERS(POL, COMBINER) \
47 RAJA_DECLARE_REDUCER(Sum, POL, COMBINER) \
48 RAJA_DECLARE_REDUCER(Min, POL, COMBINER) \
49 RAJA_DECLARE_REDUCER(Max, POL, COMBINER) \
50 RAJA_DECLARE_INDEX_REDUCER(MinLoc, POL, COMBINER) \
51 RAJA_DECLARE_INDEX_REDUCER(MaxLoc, POL, COMBINER) \
52 RAJA_DECLARE_REDUCER(BitOr, POL, COMBINER) \
53 RAJA_DECLARE_REDUCER(BitAnd, POL, COMBINER)
61 #if defined(RAJA_ENABLE_TARGET_OPENMP)
62 #pragma omp declare target
68 template<
typename T,
template<
typename...>
class Op>
75 return operator_type::identity();
80 val = operator_type::operator()(val, v);
106 #if defined(RAJA_ENABLE_TARGET_OPENMP)
107 #pragma omp end declare target
113 template<typename T, bool = std::is_integral<T>::value>
129 template<
typename T,
typename IndexType,
bool doing_min = true>
136 #if __NVCC__ && defined(CUDART_VERSION) && CUDART_VERSION < 9020 || \
189 template<
typename T,
typename IndexType,
bool B>
193 ValueLoc<T, IndexType, B>
196 return ::RAJA::reduce::detail::ValueLoc<T, IndexType, B>(
limits<T>::min());
200 ValueLoc<T, IndexType, B>
203 return ::RAJA::reduce::detail::ValueLoc<T, IndexType, B>(
limits<T>::max());
215 template<
typename>
class Reduce_,
216 template<
typename,
typename>
class Combiner_>
219 using Reduce = Reduce_<T>;
221 using Combiner_t = Combiner_<T, Reduce>;
222 Combiner_t
mutable c;
237 : c {init_val, identity_}
243 void reset(T val, T identity_ = Reduce::identity())
246 c.reset(val, identity_);
271 void combine(T
const& other)
const { c.combine(other); }
273 T&
local()
const {
return c.local(); }
276 operator T()
const {
return c.get(); }
279 T
get()
const {
return c.get(); }
282 template<
typename T,
typename Reduce,
typename Derived>
341 T
get()
const {
return derived().get_combined(); }
352 const Derived& derived()
const
354 return *(
static_cast<const Derived*
>(
this));
357 Derived& derived() {
return *(
static_cast<Derived*
>(
this)); }
367 template<
typename T,
template<
typename,
typename>
class Combiner>
392 template<
typename,
typename>
class Combiner>
394 :
public BaseReduce<ValueLoc<T, IndexType>, RAJA::reduce::min, Combiner>
407 T identity_val_ = reduce_type::identity(),
415 T identity_val_ = reduce_type::identity(),
445 template<
typename T,
template<
typename,
typename>
class Combiner>
468 template<
typename T,
template<
typename,
typename>
class Combiner>
493 template<
typename T,
template<
typename,
typename>
class Combiner>
518 template<
typename T,
template<
typename,
typename>
class Combiner>
545 template<
typename,
typename>
class Combiner>
562 T identity_val_ = reduce_type::identity(),
570 T identity_val_ = reduce_type::identity(),
Header file for RAJA operator definitions.
Definition: reduce.hpp:284
RAJA_SUPPRESS_HD_WARN constexpr RAJA_HOST_DEVICE BaseCombinable()
Definition: reduce.hpp:294
RAJA_SUPPRESS_HD_WARN constexpr RAJA_HOST_DEVICE BaseCombinable(BaseCombinable const &other)
Definition: reduce.hpp:316
T get() const
Definition: reduce.hpp:341
T identity
Definition: reduce.hpp:287
RAJA_SUPPRESS_HD_WARN constexpr RAJA_HOST_DEVICE BaseCombinable(T init_val, T identity_=T())
Definition: reduce.hpp:299
T my_data
Definition: reduce.hpp:288
T get_combined() const
Definition: reduce.hpp:348
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE ~BaseCombinable()
Definition: reduce.hpp:325
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE void reset(T init_val, T identity_)
Definition: reduce.hpp:307
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE void combine(T const &other)
Definition: reduce.hpp:336
BaseCombinable const * parent
Definition: reduce.hpp:286
T & local() const
Definition: reduce.hpp:346
Bitwise AND reducer class template.
Definition: reduce.hpp:520
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE const BaseReduceBitAnd & operator&=(T rhs) const
reducer function; updates the current instance's state
Definition: reduce.hpp:529
Bitwise OR reducer class template.
Definition: reduce.hpp:495
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE const BaseReduceBitOr & operator|=(T rhs) const
reducer function; updates the current instance's state
Definition: reduce.hpp:504
MaxLoc reducer class template.
Definition: reduce.hpp:549
void reset(T init_val, IndexType init_idx, T identity_val_=reduce_type::identity(), IndexType identity_loc_=DefaultLoc< IndexType >().value())
Definition: reduce.hpp:568
constexpr BaseReduceMaxLoc()
Definition: reduce.hpp:557
typename Base::value_type value_type
Definition: reduce.hpp:553
constexpr BaseReduceMaxLoc(T init_val, IndexType init_idx, T identity_val_=reduce_type::identity(), IndexType identity_loc_=DefaultLoc< IndexType >().value())
Definition: reduce.hpp:559
typename Base::reduce_type reduce_type
Definition: reduce.hpp:554
RAJA_HOST_DEVICE const BaseReduceMaxLoc & maxloc(T rhs, IndexType loc) const
reducer function; updates the current instance's state
Definition: reduce.hpp:580
IndexType getLoc() const
Get the calculated reduced value.
Definition: reduce.hpp:587
Max reducer class template.
Definition: reduce.hpp:447
RAJA_HOST_DEVICE const BaseReduceMax & max(T rhs) const
reducer function; updates the current instance's state
Definition: reduce.hpp:454
MinLoc reducer class template.
Definition: reduce.hpp:395
IndexType getLoc() const
Get the calculated reduced value.
Definition: reduce.hpp:432
typename Base::value_type value_type
Definition: reduce.hpp:398
typename Base::reduce_type reduce_type
Definition: reduce.hpp:399
void reset(T init_val, IndexType init_idx, T identity_val_=reduce_type::identity(), IndexType identity_loc_=DefaultLoc< IndexType >().value())
Definition: reduce.hpp:413
constexpr BaseReduceMinLoc()
Definition: reduce.hpp:402
constexpr BaseReduceMinLoc(T init_val, IndexType init_idx, T identity_val_=reduce_type::identity(), IndexType identity_loc_=DefaultLoc< IndexType >().value())
Definition: reduce.hpp:404
RAJA_HOST_DEVICE const BaseReduceMinLoc & minloc(T rhs, IndexType loc) const
reducer function; updates the current instance's state
Definition: reduce.hpp:425
Min reducer class template.
Definition: reduce.hpp:369
RAJA_HOST_DEVICE const BaseReduceMin & min(T rhs) const
reducer function; updates the current instance's state
Definition: reduce.hpp:376
Sum reducer class template.
Definition: reduce.hpp:470
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE const BaseReduceSum & operator+=(T rhs) const
reducer function; updates the current instance's state
Definition: reduce.hpp:479
Definition: reduce.hpp:218
BaseReduce & operator=(BaseReduce &&)=default
compiler-generated move assignment
T value_type
Definition: reduce.hpp:225
BaseReduce & operator=(const BaseReduce &)=delete
prohibit compiler-generated copy assignment
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE BaseReduce(T init_val, T identity_=Reduce::identity())
Definition: reduce.hpp:236
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE BaseReduce()
Definition: reduce.hpp:231
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE BaseReduce(const BaseReduce ©)
compiler-generated copy constructor
Definition: reduce.hpp:256
T & local() const
Definition: reduce.hpp:273
T get() const
Get the calculated reduced value.
Definition: reduce.hpp:279
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE void reset(T val, T identity_=Reduce::identity())
Definition: reduce.hpp:243
Reduce reduce_type
Definition: reduce.hpp:226
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE RAJA_INLINE BaseReduce(BaseReduce &©)
compiler-generated move constructor
Definition: reduce.hpp:263
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE void combine(T const &other) const
Definition: reduce.hpp:271
Definition: reduce.hpp:131
constexpr ValueLoc()=default
constexpr RAJA_HOST_DEVICE ValueLoc(T const &val_, IndexType const &loc_)
Definition: reduce.hpp:163
T val
Definition: reduce.hpp:133
constexpr ValueLoc(ValueLoc const &)=default
RAJA_HOST_DEVICE bool operator>(ValueLoc const &rhs) const
Definition: reduce.hpp:177
IndexType loc
Definition: reduce.hpp:134
constexpr RAJA_HOST_DEVICE ValueLoc(T const &val_)
Definition: reduce.hpp:158
RAJA_HOST_DEVICE bool operator<(ValueLoc const &rhs) const
Definition: reduce.hpp:172
ValueLoc & operator=(ValueLoc const &)=default
RAJA_HOST_DEVICE IndexType getLoc()
Definition: reduce.hpp:170
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_SUPPRESS_HD_WARN
Definition: macros.hpp:68
constexpr auto Reduce(T *target)
Definition: reducer.hpp:231
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result min(Args... args)
Definition: foldl.hpp:161
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Definition: ListSegment.hpp:416
RAJA_INLINE static RAJA_HOST_DEVICE constexpr ::RAJA::reduce::detail::ValueLoc< T, IndexType, B > max()
Definition: reduce.hpp:201
RAJA_INLINE static RAJA_HOST_DEVICE constexpr ::RAJA::reduce::detail::ValueLoc< T, IndexType, B > min()
Definition: reduce.hpp:194
Definition: Operators.hpp:250
Definition: reduce.hpp:103
constexpr RAJA_HOST_DEVICE T value() const
Definition: reduce.hpp:120
constexpr RAJA_HOST_DEVICE T value() const
Definition: reduce.hpp:126
Definition: reduce.hpp:115
Definition: reduce.hpp:70
RAJA_HOST_DEVICE RAJA_INLINE void operator()(T &val, const T v) const
Definition: reduce.hpp:78
Op< T, T, T > operator_type
Definition: reduce.hpp:71
static constexpr RAJA_HOST_DEVICE T identity()
Definition: reduce.hpp:73
Definition: reduce.hpp:95
Definition: reduce.hpp:91
Definition: reduce.hpp:99
Definition: reduce.hpp:87
Header file for RAJA type definitions.