alpaka
Abstraction Library for Parallel Kernel Acceleration
IdxGbLinear.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jeffrey Kelling, Jan Stephan, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 #include "alpaka/idx/MapIdx.hpp"
10 #include "alpaka/idx/Traits.hpp"
11 #include "alpaka/vec/Vec.hpp"
13 
14 namespace alpaka
15 {
16  namespace gb
17  {
18  //! General ND index provider based on a linear index.
19  template<typename TDim, typename TIdx>
20  class IdxGbLinear : public concepts::Implements<ConceptIdxGb, IdxGbLinear<TDim, TIdx>>
21  {
22  public:
23  IdxGbLinear(TIdx const& teamOffset = static_cast<TIdx>(0u)) : m_gridBlockIdx(teamOffset)
24  {
25  }
26 
27  TIdx const m_gridBlockIdx;
28  };
29  } // namespace gb
30 
31  namespace trait
32  {
33  //! The IdxGbLinear index dimension get trait specialization.
34  template<typename TDim, typename TIdx>
35  struct DimType<gb::IdxGbLinear<TDim, TIdx>>
36  {
37  using type = TDim;
38  };
39 
40  //! The IdxGbLinear grid block index get trait specialization.
41  template<typename TDim, typename TIdx>
42  struct GetIdx<gb::IdxGbLinear<TDim, TIdx>, origin::Grid, unit::Blocks>
43  {
44  //! \return The index of the current block in the grid.
45  template<typename TWorkDiv>
46  static auto getIdx(gb::IdxGbLinear<TDim, TIdx> const& idx, TWorkDiv const& workDiv) -> Vec<TDim, TIdx>
47  {
48  // \TODO: Would it be faster to precompute the index and cache it inside an array?
49  return mapIdx<TDim::value>(
50  Vec<DimInt<1u>, TIdx>(idx.m_gridBlockIdx),
51  getWorkDiv<Grid, Blocks>(workDiv));
52  }
53  };
54 
55  template<typename TIdx>
56  struct GetIdx<gb::IdxGbLinear<DimInt<1u>, TIdx>, origin::Grid, unit::Blocks>
57  {
58  //! \return The index of the current block in the grid.
59  template<typename TWorkDiv>
60  static auto getIdx(gb::IdxGbLinear<DimInt<1u>, TIdx> const& idx, TWorkDiv const&) -> Vec<DimInt<1u>, TIdx>
61  {
62  return idx.m_gridBlockIdx;
63  }
64  };
65 
66  //! The IdxGbLinear grid block index idx type trait specialization.
67  template<typename TDim, typename TIdx>
68  struct IdxType<gb::IdxGbLinear<TDim, TIdx>>
69  {
70  using type = TIdx;
71  };
72  } // namespace trait
73 } // namespace alpaka
General ND index provider based on a linear index.
Definition: IdxGbLinear.hpp:21
IdxGbLinear(TIdx const &teamOffset=static_cast< TIdx >(0u))
Definition: IdxGbLinear.hpp:23
The alpaka accelerator library.
std::integral_constant< std::size_t, N > DimInt
Tag used in class inheritance hierarchies that describes that a specific concept (TConcept) is implem...
Definition: Concepts.hpp:15
The dimension getter type trait.
Definition: Traits.hpp:14
static auto getIdx(gb::IdxGbLinear< DimInt< 1u >, TIdx > const &idx, TWorkDiv const &) -> Vec< DimInt< 1u >, TIdx >
Definition: IdxGbLinear.hpp:60
static auto getIdx(gb::IdxGbLinear< TDim, TIdx > const &idx, TWorkDiv const &workDiv) -> Vec< TDim, TIdx >
Definition: IdxGbLinear.hpp:46
The index get trait.
Definition: Traits.hpp:42
The idx type trait.
Definition: Traits.hpp:25