alpaka
Abstraction Library for Parallel Kernel Acceleration
IdxBtLinear.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Jeffrey Kelling, Benjamin Worpitz, RenĂ© Widera, 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 bt
17  {
18  //! General ND bt index provider based on a linear index.
19  template<typename TDim, typename TIdx>
20  class IdxBtLinear : public concepts::Implements<ConceptIdxBt, IdxBtLinear<TDim, TIdx>>
21  {
22  public:
23  IdxBtLinear(TIdx blockThreadIdx) : m_blockThreadIdx(blockThreadIdx)
24  {
25  }
26 
27  const TIdx m_blockThreadIdx;
28  };
29  } // namespace bt
30 
31  namespace trait
32  {
33  //! The IdxBtLinear index dimension get trait specialization.
34  template<typename TDim, typename TIdx>
35  struct DimType<bt::IdxBtLinear<TDim, TIdx>>
36  {
37  using type = TDim;
38  };
39 
40  //! The IdxBtLinear block thread index get trait specialization.
41  template<typename TDim, typename TIdx>
42  struct GetIdx<bt::IdxBtLinear<TDim, TIdx>, origin::Block, unit::Threads>
43  {
44  //! \return The index of the current thread in the block.
45  template<typename TWorkDiv>
46  static auto getIdx(bt::IdxBtLinear<TDim, TIdx> const& idx, TWorkDiv const& workDiv) -> Vec<TDim, TIdx>
47  {
48  return mapIdx<TDim::value>(
49  Vec<DimInt<1u>, TIdx>(idx.m_blockThreadIdx),
50  getWorkDiv<Block, Threads>(workDiv));
51  }
52  };
53 
54  template<typename TIdx>
55  struct GetIdx<bt::IdxBtLinear<DimInt<1u>, TIdx>, origin::Block, unit::Threads>
56  {
57  //! \return The index of the current thread in the block.
58  template<typename TWorkDiv>
59  static auto getIdx(bt::IdxBtLinear<DimInt<1u>, TIdx> const& idx, TWorkDiv const&) -> Vec<DimInt<1u>, TIdx>
60  {
61  return idx.m_blockThreadIdx;
62  }
63  };
64 
65  //! The IdxBtLinear block thread index idx type trait specialization.
66  template<typename TDim, typename TIdx>
67  struct IdxType<bt::IdxBtLinear<TDim, TIdx>>
68  {
69  using type = TIdx;
70  };
71  } // namespace trait
72 } // namespace alpaka
General ND bt index provider based on a linear index.
Definition: IdxBtLinear.hpp:21
IdxBtLinear(TIdx blockThreadIdx)
Definition: IdxBtLinear.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(bt::IdxBtLinear< DimInt< 1u >, TIdx > const &idx, TWorkDiv const &) -> Vec< DimInt< 1u >, TIdx >
Definition: IdxBtLinear.hpp:59
static auto getIdx(bt::IdxBtLinear< TDim, TIdx > const &idx, TWorkDiv const &workDiv) -> Vec< TDim, TIdx >
Definition: IdxBtLinear.hpp:46
The index get trait.
Definition: Traits.hpp:42
The idx type trait.
Definition: Traits.hpp:25