alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
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
10#include "alpaka/idx/Traits.hpp"
11#include "alpaka/vec/Vec.hpp"
13
14namespace 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 interface::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
A n-dimensional vector.
Definition Vec.hpp:38
General ND bt index provider based on a linear index.
IdxBtLinear(TIdx blockThreadIdx)
The alpaka accelerator library.
std::integral_constant< std::size_t, N > DimInt
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.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 >
static auto getIdx(bt::IdxBtLinear< TDim, TIdx > const &idx, TWorkDiv const &workDiv) -> Vec< TDim, TIdx >
The index get trait.
Definition Traits.hpp:42
The idx type trait.
Definition Traits.hpp:25