Skip to content

Commit

Permalink
Update various constructors in Val.
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen20 committed Sep 19, 2024
1 parent 1e13b59 commit a414e12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
33 changes: 22 additions & 11 deletions include/RAJA/pattern/params/params_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ namespace expt

template<typename T, typename IndexType = RAJA::Index_type>
struct ValLoc {
public:
using index_type = IndexType;
using value_type = T;

RAJA_HOST_DEVICE constexpr ValLoc() {}
RAJA_HOST_DEVICE constexpr ValLoc() = default;
RAJA_HOST_DEVICE constexpr explicit ValLoc(value_type v) : val(v) {}
RAJA_HOST_DEVICE constexpr ValLoc(value_type v, index_type l) : val(v), loc(l) {}
RAJA_HOST_DEVICE constexpr explicit ValLoc(value_type v, index_type l) : val(v), loc(l) {}

RAJA_HOST_DEVICE constexpr ValLoc(ValLoc const &) = default;
RAJA_HOST_DEVICE constexpr ValLoc(ValLoc &&) = default;
RAJA_HOST_DEVICE ValLoc& operator=(ValLoc const &) = default;
RAJA_HOST_DEVICE ValLoc& operator=(ValLoc &&) = default;

RAJA_HOST_DEVICE constexpr bool operator<(const ValLoc& rhs) const { return val < rhs.val; }
RAJA_HOST_DEVICE constexpr bool operator>(const ValLoc& rhs) const { return val > rhs.val; }

RAJA_HOST_DEVICE constexpr value_type getVal() const {return val;}
RAJA_HOST_DEVICE constexpr index_type getLoc() const {return loc;}
RAJA_HOST_DEVICE constexpr const value_type& getVal() const {return val;}
RAJA_HOST_DEVICE constexpr const index_type& getLoc() const {return loc;}

RAJA_HOST_DEVICE void set(T inval, IndexType inindex) {val = inval; loc = inindex;}

Expand All @@ -31,13 +35,17 @@ namespace expt

template<typename T, template <typename, typename, typename> class Op>
struct ValOp {
public:
using value_type = T;
using op_type = Op<T,T,T>;

RAJA_HOST_DEVICE constexpr ValOp() {}
RAJA_HOST_DEVICE constexpr ValOp() = default;
RAJA_HOST_DEVICE constexpr explicit ValOp(value_type v) : val(v) {}

RAJA_HOST_DEVICE constexpr ValOp(ValOp const &) = default;
RAJA_HOST_DEVICE constexpr ValOp(ValOp &&) = default;
RAJA_HOST_DEVICE ValOp& operator=(ValOp const &) = default;
RAJA_HOST_DEVICE ValOp& operator=(ValOp &&) = default;

template <typename U = op_type, std::enable_if_t<std::is_same<U, RAJA::operators::minimum<T,T,T>>::value> * = nullptr>
RAJA_HOST_DEVICE constexpr ValOp & min(value_type v) { if (v < val) { val = v; } return *this; }
template <typename U = op_type, std::enable_if_t<std::is_same<U, RAJA::operators::maximum<T,T,T>>::value> * = nullptr>
Expand Down Expand Up @@ -66,17 +74,20 @@ namespace expt

template<typename T, typename IndexType, template <typename, typename, typename> class Op>
struct ValOp <ValLoc<T,IndexType>, Op> {
public:
using index_type = IndexType;
using value_type = ValLoc<T,index_type>;
using op_type = Op<value_type,value_type,value_type>;
using valloc_value_type = typename value_type::value_type;
using valloc_index_type = typename value_type::index_type;

RAJA_HOST_DEVICE constexpr ValOp() {}
RAJA_HOST_DEVICE constexpr ValOp() = default;
RAJA_HOST_DEVICE constexpr explicit ValOp(value_type v) : val(v) {}
RAJA_HOST_DEVICE constexpr explicit ValOp(valloc_value_type v) : val(v) {}
RAJA_HOST_DEVICE constexpr ValOp(valloc_value_type v, valloc_index_type l) : val(v, l) {}
RAJA_HOST_DEVICE constexpr explicit ValOp(valloc_value_type v, valloc_index_type l) : val(v, l) {}

RAJA_HOST_DEVICE constexpr ValOp(ValOp const &) = default;
RAJA_HOST_DEVICE constexpr ValOp(ValOp &&) = default;
RAJA_HOST_DEVICE ValOp& operator=(ValOp const &) = default;
RAJA_HOST_DEVICE ValOp& operator=(ValOp &&) = default;

template <typename U = op_type, std::enable_if_t<std::is_same<U, RAJA::operators::minimum<value_type,value_type,value_type>>::value> * = nullptr>
RAJA_HOST_DEVICE constexpr ValOp & min(value_type v) { if (v < val) { val = v; } return *this; }
Expand Down
7 changes: 6 additions & 1 deletion include/RAJA/pattern/params/reducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ namespace detail
using op = Op<T,T,T>;
using value_type = T;

RAJA_HOST_DEVICE Reducer() {}
RAJA_HOST_DEVICE Reducer() = default;
RAJA_HOST_DEVICE Reducer(value_type *target_in) : valop_m(VType{}), target(target_in){}
RAJA_HOST_DEVICE Reducer(DataType *data_in, IndexType *index_in) : valop_m(VType(*data_in, *index_in)), target(&valop_m.val), passthruval(data_in), passthruindex(index_in) {}

RAJA_HOST_DEVICE constexpr Reducer(Reducer const &) = default;
RAJA_HOST_DEVICE constexpr Reducer(Reducer &&) = default;
RAJA_HOST_DEVICE Reducer& operator=(Reducer const &) = default;
RAJA_HOST_DEVICE Reducer& operator=(Reducer &&) = default;

VType valop_m = VType{};
value_type *target = nullptr;
DataType *passthruval = nullptr;
Expand Down

0 comments on commit a414e12

Please sign in to comment.