RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
Public Types | Public Member Functions | List of all members
RAJA::CombiningAdapter< Lambda, Layout_ > Struct Template Reference

A holder for adapting lambdas meant for multidimensional index spaces to allow their use in 1-dimensional index spaces. More...

#include <CombiningAdapter.hpp>

Public Types

using Layout = Layout_
 
using IndexRange = typename Layout::IndexRange
 
using StrippedIdxLin = typename Layout::StrippedIdxLin
 
using IndexLinear = typename Layout::IndexLinear
 
using DimTuple = typename Layout::DimTuple
 
using DimArr = typename Layout::DimArr
 
using RangeLinear = RAJA::TypedRangeSegment< IndexLinear >
 

Public Member Functions

template<typename C_Lambda , typename C_Layout >
RAJA_HOST_DEVICE CombiningAdapter (C_Lambda &&lambda, C_Layout &&layout)
 
RAJA_HOST_DEVICE RAJA_INLINE auto operator() (IndexLinear linear_index) -> decltype(call_helper(linear_index, IndexRange()))
 
RAJA_HOST_DEVICE RAJA_INLINE auto operator() (IndexLinear linear_index) const -> decltype(call_helper(linear_index, IndexRange()))
 
RAJA_HOST_DEVICE RAJA_INLINE IndexLinear size () const
 
RAJA_HOST_DEVICE RAJA_INLINE RangeLinear getRange () const
 

Detailed Description

template<typename Lambda, typename Layout_>
struct RAJA::CombiningAdapter< Lambda, Layout_ >

A holder for adapting lambdas meant for multidimensional index spaces to allow their use in 1-dimensional index spaces.

Creates callable object that when called with a 1-dimensional index, converts that index to a multi-dimensional index and calls the given lambda. This allows lambdas meant for use in multi-dimensional loop abstractions to be used in 1-dimensional loop abstractions. The 1-dimensional index is of the type of the IndexType template parameter.

For example:

// lambda for use in 3-d loop
auto lambda = [=](int i, int j, int k) {...};

// 3D loop bounds
int isize;
int jsize;
int ksize;

// example lambda usage
for (int i = 0; i < isize; ++i) {
  for (int j = 0; j < jsize; ++j) {
    for (int k = 0; k < ksize; ++k) {
      lambda(i, j, k);
    }
  }
}

using Layout = Layout<3, int, // 3 dimensions, index type is int
                      2>;    // optimization, stride 1 dim is 2

// Create a CombiningAdapter object for lambda and the ranges
// NOTE Use make_CombiningAdapter
RAJA::CombiningAdapter<decltype(lambda), Layout>
    adapter(lambda, Layout(isize, jsize, ksize));

// Use with RAJA forall
RAJA::forall<policy>(adapter.getRange(), adapter);

// Use with c++-style loop
auto range = adapter.getRange();
for (auto it = begin(range); it < end(range); ++it) {
  adapter(*it)
}

Member Typedef Documentation

◆ Layout

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::Layout = Layout_

◆ IndexRange

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::IndexRange = typename Layout::IndexRange

◆ StrippedIdxLin

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::StrippedIdxLin = typename Layout::StrippedIdxLin

◆ IndexLinear

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::IndexLinear = typename Layout::IndexLinear

◆ DimTuple

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::DimTuple = typename Layout::DimTuple

◆ DimArr

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::DimArr = typename Layout::DimArr

◆ RangeLinear

template<typename Lambda , typename Layout_ >
using RAJA::CombiningAdapter< Lambda, Layout_ >::RangeLinear = RAJA::TypedRangeSegment<IndexLinear>

Constructor & Destructor Documentation

◆ CombiningAdapter()

template<typename Lambda , typename Layout_ >
template<typename C_Lambda , typename C_Layout >
RAJA_HOST_DEVICE RAJA::CombiningAdapter< Lambda, Layout_ >::CombiningAdapter ( C_Lambda &&  lambda,
C_Layout &&  layout 
)
inline

Constructor from lambda and layout.

Member Function Documentation

◆ operator()() [1/2]

template<typename Lambda , typename Layout_ >
RAJA_HOST_DEVICE RAJA_INLINE auto RAJA::CombiningAdapter< Lambda, Layout_ >::operator() ( IndexLinear  linear_index) -> decltype(call_helper(linear_index, IndexRange()))
inline

Call the lambda by converting the linear index to multidimensional indices.

Returns
return value of lambda

◆ operator()() [2/2]

template<typename Lambda , typename Layout_ >
RAJA_HOST_DEVICE RAJA_INLINE auto RAJA::CombiningAdapter< Lambda, Layout_ >::operator() ( IndexLinear  linear_index) const -> decltype(call_helper(linear_index, IndexRange()))
inline

◆ size()

template<typename Lambda , typename Layout_ >
RAJA_HOST_DEVICE RAJA_INLINE IndexLinear RAJA::CombiningAdapter< Lambda, Layout_ >::size ( ) const
inline

Computes the total size of the layout's space.

Returns
Total size of layout

◆ getRange()

template<typename Lambda , typename Layout_ >
RAJA_HOST_DEVICE RAJA_INLINE RangeLinear RAJA::CombiningAdapter< Lambda, Layout_ >::getRange ( ) const
inline

Convenience method to get a 1-dimensional range representing the total size of the layout.

Returns
Range representing the total size of the layout

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