RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
List of all members
RAJA::TypedRangeSegment< StorageT, DiffT > Class Template Reference

Segment class representing a contiguous range of typed indices. More...

#include <RangeSegment.hpp>

Public Types

Types used in implementation based on template parameters.
using iterator = Iterators::numeric_iterator< StorageT, DiffT >
 The underlying iterator type. More...
 
using value_type = StorageT
 The underlying value type. More...
 
using IndexType = DiffT
 The underlying type for a difference in index values. More...
 

Public Member Functions

Accessor methods
RAJA_HOST_DEVICE RAJA_INLINE iterator begin () const
 Get iterator to the beginning of this segment. More...
 
RAJA_HOST_DEVICE RAJA_INLINE iterator end () const
 Get iterator to the end of this segment. More...
 
RAJA_HOST_DEVICE RAJA_INLINE DiffT size () const
 Get size of this segment (end - begin) More...
 

Constructors, destructor, and copy assignment.

using StripStorageT = strip_index_type_t< StorageT >
 Construct a range segment repreenting the interval [begin, end) More...
 
constexpr RAJA_HOST_DEVICE TypedRangeSegment (StripStorageT begin, StripStorageT end)
 
RAJA_HOST_DEVICE TypedRangeSegment ()=delete
 Disable compiler generated constructor. More...
 
constexpr TypedRangeSegment (TypedRangeSegment &&)=default
 Defaulted move constructor. More...
 
constexpr TypedRangeSegment (TypedRangeSegment const &)=default
 Defaulted copy constructor. More...
 
RAJA_INLINE TypedRangeSegmentoperator= (TypedRangeSegment const &)=default
 Defaulted copy assignment operator. More...
 
RAJA_INLINE ~TypedRangeSegment ()=default
 Defaulted destructor. More...
 

Segment comparison methods

RAJA_HOST_DEVICE RAJA_INLINE bool operator== (TypedRangeSegment const &o) const
 Compare this segment to another for equality. More...
 
RAJA_HOST_DEVICE RAJA_INLINE bool operator!= (TypedRangeSegment const &o) const
 Compare this segment to another for inequality. More...
 
RAJA_HOST_DEVICE RAJA_INLINE TypedRangeSegment slice (StorageT begin, DiffT length) const
 Get a new TypedRangeSegment instance representing a slice of existing segment. More...
 
RAJA_HOST_DEVICE RAJA_INLINE void swap (TypedRangeSegment &other)
 Swap this segment with another. More...
 

Detailed Description

template<typename StorageT, typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
class RAJA::TypedRangeSegment< StorageT, DiffT >

Segment class representing a contiguous range of typed indices.

Template Parameters
StorageTunderlying data type for the segment indices (required)
DiffTunderlying data type for the difference between two segment indices (optional)

A TypedRangeSegment models an Iterable interface:

begin() – returns an iterator (TypedRangeSegment::iterator) end() – returns an iterator (TypedRangeSegment::iterator) size() – returns the total size of the Segment iteration space (DiffT)

NOTE: TypedRangeSegment::iterator is a RandomAccessIterator

NOTE: TypedRangeSegment supports negative indices; e.g., an interval of indices [-5, 3).

NOTE: Proper handling of indices strides requires that StorageT is a signed type.

Usage:

A common C-style loop traversal pattern would be:

* for (T i = begin; i < end; ++i) {
*   // loop body -- use i as index value
* }
* 

Using a TypedRangeSegment, this becomes:

* TypedRangeSegment<T> seg (begin, end);
* for (auto i = seg.begin(); i != seg.end(); ++i) {
*   // loop body -- use (*i) as index value
* }
* 

This can also be used in a C++11 style range-based for:

* for (auto i : TypedRangeSegment<T>(begin, end)) {
*   // loop body -- use i as index value
* }
* 

Or, as it would be commonly used with a RAJA forall execution template:

* forall<exec_pol>(TypedRangeSegment<T>(beg, end), [=] (T i) {
*   // loop body -- use i as index value
* });
* 

Member Typedef Documentation

◆ iterator

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
using RAJA::TypedRangeSegment< StorageT, DiffT >::iterator = Iterators::numeric_iterator<StorageT, DiffT>

The underlying iterator type.

◆ value_type

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
using RAJA::TypedRangeSegment< StorageT, DiffT >::value_type = StorageT

The underlying value type.

◆ IndexType

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
using RAJA::TypedRangeSegment< StorageT, DiffT >::IndexType = DiffT

The underlying type for a difference in index values.

◆ StripStorageT

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
using RAJA::TypedRangeSegment< StorageT, DiffT >::StripStorageT = strip_index_type_t<StorageT>

Construct a range segment repreenting the interval [begin, end)

Parameters
beginstart value (inclusive) for the range
endend value (exclusive) for the range

Constructor & Destructor Documentation

◆ TypedRangeSegment() [1/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
constexpr RAJA_HOST_DEVICE RAJA::TypedRangeSegment< StorageT, DiffT >::TypedRangeSegment ( StripStorageT  begin,
StripStorageT  end 
)
inlineconstexpr

◆ TypedRangeSegment() [2/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA::TypedRangeSegment< StorageT, DiffT >::TypedRangeSegment ( )
delete

Disable compiler generated constructor.

◆ TypedRangeSegment() [3/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
constexpr RAJA::TypedRangeSegment< StorageT, DiffT >::TypedRangeSegment ( TypedRangeSegment< StorageT, DiffT > &&  )
constexprdefault

Defaulted move constructor.

◆ TypedRangeSegment() [4/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
constexpr RAJA::TypedRangeSegment< StorageT, DiffT >::TypedRangeSegment ( TypedRangeSegment< StorageT, DiffT > const &  )
constexprdefault

Defaulted copy constructor.

◆ ~TypedRangeSegment()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_INLINE RAJA::TypedRangeSegment< StorageT, DiffT >::~TypedRangeSegment ( )
default

Defaulted destructor.

Member Function Documentation

◆ operator=()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_INLINE TypedRangeSegment& RAJA::TypedRangeSegment< StorageT, DiffT >::operator= ( TypedRangeSegment< StorageT, DiffT > const &  )
default

Defaulted copy assignment operator.

◆ begin()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE iterator RAJA::TypedRangeSegment< StorageT, DiffT >::begin ( ) const
inline

Get iterator to the beginning of this segment.

◆ end()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE iterator RAJA::TypedRangeSegment< StorageT, DiffT >::end ( ) const
inline

Get iterator to the end of this segment.

◆ size()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE DiffT RAJA::TypedRangeSegment< StorageT, DiffT >::size ( ) const
inline

Get size of this segment (end - begin)

◆ operator==()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE bool RAJA::TypedRangeSegment< StorageT, DiffT >::operator== ( TypedRangeSegment< StorageT, DiffT > const &  o) const
inline

Compare this segment to another for equality.

Returns
true if begin and end match, else false

◆ operator!=()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE bool RAJA::TypedRangeSegment< StorageT, DiffT >::operator!= ( TypedRangeSegment< StorageT, DiffT > const &  o) const
inline

Compare this segment to another for inequality.

Returns
true if begin or end does not match, else false

◆ slice()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE TypedRangeSegment RAJA::TypedRangeSegment< StorageT, DiffT >::slice ( StorageT  begin,
DiffT  length 
) const
inline

Get a new TypedRangeSegment instance representing a slice of existing segment.

Parameters
beginstart iterate of new range
lengthmaximum length of new range
Returns
TypedRangeSegment representing the interval [ *begin() + begin, min( *begin() + begin + length, *end() ) )

Here's an example of a slice operation on a range segment with negative indices:

*
*     // r represents the index interval [-4, 4)
*     auto r = RAJA::TypedRangeSegment<int>(-4, 4);
*
*     // s repreents the subinterval  [-3, 2)
*     auto s = r.slice(1, 5);
*
*   

◆ swap()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA_INLINE void RAJA::TypedRangeSegment< StorageT, DiffT >::swap ( TypedRangeSegment< StorageT, DiffT > &  other)
inline

Swap this segment with another.


The documentation for this class was generated from the following file: