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

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

#include <RangeSegment.hpp>

Public Types

Types used in implementation based on template parameters.
using iterator = Iterators::strided_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 iterator begin () const
 Get iterator to the beginning of this segment. More...
 
RAJA_HOST_DEVICE iterator end () const
 Get iterator to the end of this segment. More...
 
RAJA_HOST_DEVICE DiffT size () const
 Get size of this segment. More...
 

Constructors, destructor, and copy assignment.

using StripStorageT = strip_index_type_t< StorageT >
 Construct a range segment for the interval [begin, end) with given stride. More...
 
RAJA_HOST_DEVICE TypedRangeStrideSegment (StripStorageT begin, StripStorageT end, DiffT stride)
 
 TypedRangeStrideSegment ()=delete
 Disable compiler generated constructor. More...
 
 TypedRangeStrideSegment (TypedRangeStrideSegment &&)=default
 Defaulted move constructor. More...
 
 TypedRangeStrideSegment (TypedRangeStrideSegment const &)=default
 Defaulted copy constructor. More...
 
TypedRangeStrideSegmentoperator= (TypedRangeStrideSegment const &)=default
 Defaulted copy assignment operator. More...
 
 ~TypedRangeStrideSegment ()=default
 Defaulted destructore. More...
 

Segment comparison methods

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

Detailed Description

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

Segment class representing a strided 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 TypedRangeStrideSegment models an Iterable interface:

begin() – returns an iterator (TypedRangeStrideSegment::iterator) end() – returns an iterator (TypedRangeStrideSegment::iterator) size() – returns total size of the Segment iteration space, which is not the distance between begin() and end() for non-unit strides

NOTE: TypedRangeStrideSegment::iterator is a RandomAccessIterator

NOTE: TypedRangeStrideSegment allows for positive or negative strides and indices. This allows for forward (stride > 0) or backward (stride < 0) traversal of the iteration space. A stride of zero is undefined and will cause divide-by-zero errors.

As with RangeSegment, the iteration space is inclusive of begin() and exclusive of end()

For positive strides, begin() > end() implies size()==0 For negative strides, begin() < end() implies size()==0

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

Usage:

A common C-style loop traversal pattern would be:

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

Or, equivalently for a negative stride (stride < 0):

* for (T i = begin; i > end; i += stride) {
*   // loop body -- use i as index value
* }
* 
* Using a TypedRangeStrideSegment, this becomes:
* TypedRangeStrideSegment<T> seg (begin, end, stride);
* 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 : TypedRangeStrideSegment<T>(begin, end, stride)) {
*   // loop body -- use i as index value
* }
* 

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

* forall<exec_pol>(TypedRangeStrideSegment<T>(beg, end, stride), [=] (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::TypedRangeStrideSegment< StorageT, DiffT >::iterator = Iterators::strided_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::TypedRangeStrideSegment< 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::TypedRangeStrideSegment< 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::TypedRangeStrideSegment< StorageT, DiffT >::StripStorageT = strip_index_type_t<StorageT>

Construct a range segment for the interval [begin, end) with given stride.

Parameters
beginstart value (inclusive) for the range
endend value (exclusive) for the range
stridestride value when iterating over the range

Constructor & Destructor Documentation

◆ TypedRangeStrideSegment() [1/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA_HOST_DEVICE RAJA::TypedRangeStrideSegment< StorageT, DiffT >::TypedRangeStrideSegment ( StripStorageT  begin,
StripStorageT  end,
DiffT  stride 
)
inline

◆ TypedRangeStrideSegment() [2/4]

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

Disable compiler generated constructor.

◆ TypedRangeStrideSegment() [3/4]

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
RAJA::TypedRangeStrideSegment< StorageT, DiffT >::TypedRangeStrideSegment ( TypedRangeStrideSegment< StorageT, DiffT > &&  )
default

Defaulted move constructor.

◆ TypedRangeStrideSegment() [4/4]

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

Defaulted copy constructor.

◆ ~TypedRangeStrideSegment()

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

Defaulted destructore.

Member Function Documentation

◆ operator=()

template<typename StorageT , typename DiffT = make_signed_t<strip_index_type_t<StorageT>>>
TypedRangeStrideSegment& RAJA::TypedRangeStrideSegment< StorageT, DiffT >::operator= ( TypedRangeStrideSegment< 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 iterator RAJA::TypedRangeStrideSegment< 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 iterator RAJA::TypedRangeStrideSegment< 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 DiffT RAJA::TypedRangeStrideSegment< StorageT, DiffT >::size ( ) const
inline

Get size of this segment.

The size is the number of iterates in the interval [begin, end) when striding over it

◆ operator==()

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

Compare this segment to another for equality.

Returns
true if begin, end, and size match, else false

◆ operator!=()

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

Compare this segment to another for inequality.

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

◆ slice()

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

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

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

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

*
*     // r represents the set of indices {10, 9, ..., 1, 0}
*     auto r = RAJA::TypedRangeSegment<int>(10, -1, -1);
*
*     // s repreents the subset of indices {4, 3, 2, 1, 0}
*     // Note: the length of s is 5, not 6, because there are only
*     //       5 indices in r starting at the 6th entry
*     auto s = r.slice(6, 6);
*
*   

◆ swap()

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

Swap this segment with another.


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