|
RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
|
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... | |
| TypedRangeStrideSegment & | operator= (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... | |
Segment class representing a strided range of typed indices.
| StorageT | underlying data type for the segment indices (required) |
| DiffT | underlying 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
* });
* | using RAJA::TypedRangeStrideSegment< StorageT, DiffT >::iterator = Iterators::strided_numeric_iterator<StorageT, DiffT> |
The underlying iterator type.
| using RAJA::TypedRangeStrideSegment< StorageT, DiffT >::value_type = StorageT |
The underlying value type.
| using RAJA::TypedRangeStrideSegment< StorageT, DiffT >::IndexType = DiffT |
The underlying type for a difference in index values.
| using RAJA::TypedRangeStrideSegment< StorageT, DiffT >::StripStorageT = strip_index_type_t<StorageT> |
Construct a range segment for the interval [begin, end) with given stride.
| begin | start value (inclusive) for the range |
| end | end value (exclusive) for the range |
| stride | stride value when iterating over the range |
|
inline |
|
delete |
Disable compiler generated constructor.
|
default |
Defaulted move constructor.
|
default |
Defaulted copy constructor.
|
default |
Defaulted destructore.
|
default |
Defaulted copy assignment operator.
|
inline |
Get iterator to the beginning of this segment.
|
inline |
Get iterator to the end of this segment.
|
inline |
Get size of this segment.
The size is the number of iterates in the interval [begin, end) when striding over it
|
inline |
Compare this segment to another for equality.
|
inline |
Compare this segment to another for inequality.
|
inline |
Get a new TypedRangeStrideSegment instance representing a slice of existing segment.
| begin | start iterate of new range |
| length | maximum length of new range |
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);
*
*
|
inline |
Swap this segment with another.