Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 105 additions & 9 deletions include/RAJA/index/IndexValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <string>

#include "RAJA/util/concepts.hpp"
#include "RAJA/util/macros.hpp"
#include "RAJA/util/types.hpp"

Expand Down Expand Up @@ -58,6 +59,12 @@ struct IndexValue : public IndexValueBase
RAJA_INLINE IndexValue& operator=(IndexValue const&) = default;
RAJA_INLINE IndexValue& operator=(IndexValue&&) = default;

RAJA_INLINE IndexValue& operator=(const value_type& v)
{
value = v;
return *this;
}

/*!
* \brief Explicit constructor.
* \param v Initial value
Expand Down Expand Up @@ -302,19 +309,100 @@ convertIndex_helper(typename FROM::IndexValueType const val)

namespace type_traits
{
template<typename T>
struct is_instance_of_index_value : std::is_base_of<RAJA::IndexValue<T>, T>
template<typename T, typename U>
struct is_instance_of_index_value : std::is_base_of<RAJA::IndexValue<T, U>, T>
{};

template<typename T>
template<typename T, typename U>
constexpr bool is_instance_of_index_value_v =
is_instance_of_index_value<T>::value;
is_instance_of_index_value<T, U>::value;
} // namespace type_traits

namespace concepts
{
template<typename T>
concept IndexValued = type_traits::is_instance_of_index_value_v<T>;
concept IndexValued =
type_traits::is_instance_of_index_value_v<T, typename T::value_type>;

template<typename T>
concept Index = concepts::Integral<T> || concepts::IndexValued<T>;
} // namespace concepts

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE TYPE operator+(typename TYPE::value_type lhs,
TYPE rhs)
{
return TYPE(lhs + *rhs);
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE TYPE operator-(typename TYPE::value_type lhs,
TYPE rhs)
{
return TYPE(lhs - *rhs);
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE TYPE operator*(typename TYPE::value_type lhs,
TYPE rhs)
{
return TYPE(lhs * *rhs);
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE TYPE operator/(typename TYPE::value_type lhs,
TYPE rhs)
{
return TYPE(lhs / *rhs);
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE TYPE operator%(typename TYPE::value_type lhs,
TYPE rhs)
{
return TYPE(lhs % *rhs);
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator<(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs < *rhs;
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator<=(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs <= *rhs;
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator>(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs > *rhs;
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator>=(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs >= *rhs;
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator==(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs == *rhs;
}

template<concepts::IndexValued TYPE>
RAJA_HOST_DEVICE RAJA_INLINE bool operator!=(typename TYPE::value_type lhs,
TYPE rhs)
{
return lhs != *rhs;
}

/*!
Expand Down Expand Up @@ -402,12 +490,15 @@ using make_signed_t =
#define RAJA_INDEX_VALUE(TYPE, NAME) \
class TYPE : public ::RAJA::IndexValue<TYPE> \
{ \
using parent = ::RAJA::IndexValue<TYPE>; \
\
public: \
using parent = ::RAJA::IndexValue<TYPE>; \
using parent::operator=; \
using parent::operator*; \
using parent::operator++; \
using parent::operator--; \
using IndexValueType = TYPE; \
RAJA_HOST_DEVICE RAJA_INLINE TYPE() : parent::IndexValue() {} \
RAJA_HOST_DEVICE RAJA_INLINE explicit TYPE(::RAJA::Index_type v) \
RAJA_HOST_DEVICE RAJA_INLINE TYPE(::RAJA::Index_type v) \
: parent::IndexValue(v) \
{} \
static inline std::string getName() { return NAME; } \
Expand All @@ -423,10 +514,15 @@ using make_signed_t =
class TYPE : public ::RAJA::IndexValue<TYPE, IDXT> \
{ \
public: \
using parent = RAJA::IndexValue<TYPE, IDXT>; \
using parent::operator=; \
using parent::operator*; \
using parent::operator++; \
using parent::operator--; \
RAJA_HOST_DEVICE RAJA_INLINE TYPE() \
: RAJA::IndexValue<TYPE, IDXT>::IndexValue() \
{} \
RAJA_HOST_DEVICE RAJA_INLINE explicit TYPE(IDXT v) \
RAJA_HOST_DEVICE RAJA_INLINE TYPE(IDXT v) \
: RAJA::IndexValue<TYPE, IDXT>::IndexValue(v) \
{} \
static inline std::string getName() { return NAME; } \
Expand Down
19 changes: 16 additions & 3 deletions include/RAJA/index/RangeSegment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace RAJA
*
******************************************************************************
*/
template<typename StorageT,
template<concepts::Index StorageT,
typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
struct TypedRangeSegment
{
Expand All @@ -105,8 +105,6 @@ struct TypedRangeSegment
//
static_assert(std::is_signed<DiffT>::value,
"TypedRangeSegment DiffT requires signed type.");
static_assert(!std::is_floating_point<StorageT>::value,
"TypedRangeSegment Type must be non floating point.");

//@{
//! @name Types used in implementation based on template parameters.
Expand Down Expand Up @@ -139,6 +137,21 @@ struct TypedRangeSegment
m_end(begin > end ? m_begin : iterator(end))
{}

//! This constructor exists whenever an IndexValued index is passed to a
//! RangeSegment So that the class may be constructed directly with values of
//! the underlying storage type
template<concepts::Index BeginT, concepts::Index EndT>
requires((concepts::IndexValued<BeginT> || concepts::IndexValued<EndT>) &&
std::is_convertible_v<strip_index_type_t<BeginT>, StripStorageT> &&
std::is_convertible_v<strip_index_type_t<EndT>, StripStorageT>)
RAJA_HOST_DEVICE constexpr TypedRangeSegment(BeginT begin, EndT end)
: m_begin(iterator(StripStorageT(stripIndexType(begin)))),
m_end(StripStorageT(stripIndexType(begin)) >
StripStorageT(stripIndexType(end))
? m_begin
: iterator(StripStorageT(stripIndexType(end))))
{}

//! Disable compiler generated constructor
RAJA_HOST_DEVICE TypedRangeSegment() = delete;

Expand Down
93 changes: 86 additions & 7 deletions include/RAJA/pattern/params/params_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,90 @@
#ifndef RAJA_PARAMS_BASE
#define RAJA_PARAMS_BASE

#include <type_traits>

#include "RAJA/index/IndexValue.hpp"

namespace RAJA
{
namespace expt
{
namespace detail
{

template<typename IndexType>
using valloc_index_storage_t =
std::conditional_t<std::is_base_of<RAJA::IndexValueBase, IndexType>::value,
RAJA::strip_index_type_t<IndexType>,
IndexType>;

template<typename IndexType>
RAJA_HOST_DEVICE constexpr valloc_index_storage_t<IndexType>
strip_valloc_index(IndexType const& index)
{
if constexpr (std::is_base_of<RAJA::IndexValueBase, IndexType>::value)
{
return RAJA::stripIndexType(index);
}
else
{
return index;
}
}

template<typename IndexType>
RAJA_HOST_DEVICE constexpr IndexType
restore_valloc_index(valloc_index_storage_t<IndexType> const& index)
{
if constexpr (std::is_base_of<RAJA::IndexValueBase, IndexType>::value)
{
return IndexType(index);
}
else
{
return index;
}
}

template<typename IndexType>
RAJA_HOST_DEVICE constexpr valloc_index_storage_t<IndexType>
default_valloc_index()
{
using stored_index_type = valloc_index_storage_t<IndexType>;

if constexpr (std::is_constructible<stored_index_type, int>::value)
{
return stored_index_type(-1);
}
else
{
return stored_index_type {};
}
}

} // namespace detail

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

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 ValLoc(value_type v, index_type l)
: val(v),
loc(detail::strip_valloc_index<index_type>(l))
{}

template<typename U = stored_index_type,
std::enable_if_t<!std::is_same<U, index_type>::value>* = nullptr>
RAJA_HOST_DEVICE constexpr ValLoc(value_type v, stored_index_type l)
: val(v),
loc(l)
{}

ValLoc(ValLoc const&) = default;
Expand All @@ -45,20 +113,31 @@ struct ValLoc

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 constexpr index_type getLoc() const
{
return detail::restore_valloc_index<index_type>(loc);
}

RAJA_HOST_DEVICE constexpr const stored_index_type& getStoredLoc() const
{
return loc;
}

RAJA_HOST_DEVICE void set(T inval, IndexType inindex)
{
val = inval;
loc = inindex;
loc = detail::strip_valloc_index<index_type>(inindex);
}

RAJA_HOST_DEVICE void setVal(T inval) { val = inval; }

RAJA_HOST_DEVICE void setLoc(IndexType inindex) { loc = inindex; }
RAJA_HOST_DEVICE void setLoc(IndexType inindex)
{
loc = detail::strip_valloc_index<index_type>(inindex);
}

value_type val;
index_type loc = -1;
stored_index_type loc = detail::default_valloc_index<index_type>();
};

template<typename T, template<typename, typename, typename> class Op>
Expand Down
Loading
Loading