Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
120 changes: 107 additions & 13 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,13 +59,17 @@ 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.
* \brief Constructor.
* \param v Initial value
*/
RAJA_HOST_DEVICE RAJA_INLINE constexpr explicit IndexValue(value_type v)
: value(v)
{}
RAJA_HOST_DEVICE RAJA_INLINE constexpr IndexValue(value_type v) : value(v) {}
Comment thread
johnbowen42 marked this conversation as resolved.
Outdated

//! Dereference provides cast-to-integer.
RAJA_HOST_DEVICE RAJA_INLINE value_type& operator*() { return value; }
Expand Down Expand Up @@ -302,19 +307,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 +488,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 +512,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
13 changes: 1 addition & 12 deletions include/RAJA/util/Span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
#ifndef RAJA_SPAN_HPP
#define RAJA_SPAN_HPP

#include <concepts>
#include <type_traits>

#include "RAJA/index/IndexValue.hpp"
#include "RAJA/util/concepts.hpp"
#include "RAJA/util/macros.hpp"
#include "RAJA/util/types.hpp"
#include "camp/concepts.hpp"
Expand Down Expand Up @@ -61,14 +57,7 @@ namespace RAJA
* compile time extents
*
*/

namespace concepts
{
template<typename T>
concept SpanIndex = concepts::Integral<T> || concepts::IndexValued<T>;
};

template<concepts::RandomAccessIterator IterType, concepts::SpanIndex IndexType>
template<concepts::RandomAccessIterator IterType, concepts::Index IndexType>
struct Span
{
using element_type = typename std::iterator_traits<IterType>::value_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Cartesian product of types used in parameterized tests
//
using @BACKEND@ForallCombiningAdapter@DIMENSION@Types =
Test< camp::cartesian_product</*Strong*/IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@ForallExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Cartesian product of types used in parameterized tests
//
using @BACKEND@ForallIndexSetViewTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@ForallIndexSetExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Cartesian product of types used in parameterized tests
//
using @BACKEND@ForallIndexSetTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@ForallIndexSetExecPols>>::Types;

Expand Down
3 changes: 1 addition & 2 deletions test/functional/forall/region/test-forall-region.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using OpenMPForallRegionExecPols =
// Cartesian product of types used in parameterized tests
//
using @REGION_BACKEND@ForallRegionTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@REGION_BACKEND@ResourceList,
@REGION_BACKEND@RegionPols,
@REGION_BACKEND@ForallRegionExecPols>>::Types;
Expand All @@ -60,4 +60,3 @@ INSTANTIATE_TYPED_TEST_SUITE_P(@REGION_BACKEND@,
@REGION_BACKEND@ForallRegionTypes);



Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Cartesian product of types used in parameterized tests
//
using @BACKEND@ForallResourceIndexSetTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@ForallIndexSetExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// Cartesian product of types used in parameterized tests
//
using @BACKEND@ForallSegmentViewTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@ForallExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ using HipKernelHyperplaneExecPols =
// Cartesian product of types used in parameterized tests
//
using @BACKEND@KernelHyperplane =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
ReduceDataTypeList,
@BACKEND@ResourceList,
@BACKEND@KernelHyperplaneExecPols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ using HipKernelHyperplaneExecPols =
// Cartesian product of types used in parameterized tests
//
using @BACKEND@KernelHyperplane =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
ReduceDataTypeList,
@BACKEND@ResourceList,
@BACKEND@KernelHyperplaneExecPols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

// Sequential execution policy types
using SequentialKernelExecPols = camp::list<

RAJA::KernelPolicy<
RAJA::statement::For<0, RAJA::seq_exec,
RAJA::statement::For<1, RAJA::seq_exec,
Expand All @@ -42,7 +42,7 @@ using SequentialKernelExecPols = camp::list<

#if defined(RAJA_ENABLE_OPENMP)
using OpenMPKernelExecPols = camp::list<

RAJA::KernelPolicy<
RAJA::statement::For<0, RAJA::omp_parallel_for_exec,
RAJA::statement::For<1, RAJA::seq_exec,
Expand Down Expand Up @@ -174,7 +174,7 @@ using SyclKernelExecPols = camp::list<
// Cartesian product of types used in parameterized tests
//
using @BACKEND@KernelNestedLoopsSegmentTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@KernelExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ camp::list<
// Cartesian product of types used in parameterized tests
//
using @BACKEND@KernelNestesLoop@TESTTYPE@@DIM@Types =
Test< camp::cartesian_product<SignedIdxTypeList,
Test< camp::cartesian_product<RawSignedIdxTypeList,
@BACKEND@ResourceList,
@BACKEND@Kernel@DIM@ExecPols>>::Types;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ using HipKernelLocForallPols =
// Cartesian product of types used in parameterized tests
//
using @LOC_BACKEND@KernelLocTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
ReduceDataTypeList,
@LOC_BACKEND@ResourceList,
@LOC_BACKEND@KernelLocForallPols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ using HipKernelLocForallPols =
// Cartesian product of types used in parameterized tests
//
using @BACKEND@KernelLocTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
ReduceDataTypeList,
@BACKEND@ResourceList,
@BACKEND@KernelLocForallPols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ using HipKernelLocForallPols =
// Cartesian product of types used in parameterized tests
//
using @LOC_BACKEND@KernelLocTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
ReduceDataTypeList,
@LOC_BACKEND@ResourceList,
@LOC_BACKEND@KernelLocForallPols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ using OpenMPKernelRegionSyncExecPols =
// Cartesian product of types used in parameterized tests
//
using @REGION_BACKEND@KernelRegionSyncTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@REGION_BACKEND@ResourceList,
@REGION_BACKEND@KernelRegionSyncExecPols>>::Types;

Expand Down
2 changes: 1 addition & 1 deletion test/functional/kernel/region/test-kernel-region.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ using OpenMPKernelRegionExecPols =
// Cartesian product of types used in parameterized tests
//
using @REGION_BACKEND@KernelRegionTypes =
Test< camp::cartesian_product<IdxTypeList,
Test< camp::cartesian_product<RawIdxTypeList,
@REGION_BACKEND@ResourceList,
@REGION_BACKEND@KernelRegionExecPols>>::Types;

Expand Down
Loading
Loading