RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
PermutedLayout.hpp
Go to the documentation of this file.
1 
12 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
13 // Copyright (c) Lawrence Livermore National Security, LLC and other
14 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
15 // files for dates and other details. No copyright assignment is required
16 // to contribute to RAJA.
17 //
18 // SPDX-License-Identifier: (BSD-3-Clause)
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 
21 #ifndef RAJA_PERMUTEDLAYOUT_HPP
22 #define RAJA_PERMUTEDLAYOUT_HPP
23 
24 #include "RAJA/config.hpp"
25 
26 #include <iostream>
27 
29 
30 #include "RAJA/util/Layout.hpp"
31 #include "RAJA/util/Operators.hpp"
33 
34 namespace RAJA
35 {
36 
65 template<size_t Rank, typename IdxLin = Index_type>
66 constexpr RAJA_INLINE RAJA_HOST_DEVICE auto make_permuted_layout(
67  std::array<IdxLin, Rank> sizes,
68  std::array<camp::idx_t, Rank> permutation) -> Layout<Rank, IdxLin>
69 {
70  std::array<IdxLin, Rank> strides;
71  std::array<IdxLin, Rank> folded_strides;
72  for (size_t i = 0; i < Rank; ++i)
73  {
74  // If the size of dimension i is zero, then the stride is zero
75  folded_strides[i] = sizes[permutation[i]] ? 1 : 0;
76  for (size_t j = i + 1; j < Rank; ++j)
77  {
78  folded_strides[i] *= sizes[permutation[j]] ? sizes[permutation[j]] : 1;
79  }
80  }
81 
82  for (size_t i = 0; i < Rank; ++i)
83  {
84  strides[permutation[i]] = folded_strides[i];
85  }
86 
87 
88  // return Layout<Rank, IdxLin>(sizes, strides);
89  auto ret = Layout<Rank, IdxLin>();
90  for (size_t i = 0; i < Rank; ++i)
91  {
92  ret.sizes[i] = sizes[i];
93  ret.strides[i] = strides[i];
94  ret.inv_strides[i] = strides[i] ? strides[i] : 1;
95  ret.inv_mods[i] = sizes[i] ? sizes[i] : 1;
96  }
97  return ret;
98 }
99 
100 template<camp::idx_t... Ints>
101 using Perm = camp::idx_seq<Ints...>;
102 template<camp::idx_t N>
103 using MakePerm = typename camp::make_idx_seq<N>::type;
104 
105 } // namespace RAJA
106 
107 #endif
RAJA header file for strongly-typed integer class.
RAJA header file defining Layout, a N-dimensional index calculator.
Header file for RAJA operator definitions.
RAJA header file defining permutations.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
typename camp::make_idx_seq< N >::type MakePerm
Definition: PermutedLayout.hpp:103
camp::idx_seq< Ints... > Perm
Definition: PermutedLayout.hpp:101
constexpr RAJA_INLINE RAJA_HOST_DEVICE auto make_permuted_layout(std::array< IdxLin, Rank > sizes, std::array< camp::idx_t, Rank > permutation) -> Layout< Rank, IdxLin >
Creates a permuted Layout object.
Definition: PermutedLayout.hpp:66
Definition: Layout.hpp:46