alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Benjamin Worpitz, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
10 #include "alpaka/idx/Traits.hpp"
11 #include "alpaka/vec/Vec.hpp"
12 
13 #include <type_traits>
14 #include <utility>
15 
16 namespace alpaka
17 {
19  {
20  };
21 
22  //! The work division trait.
23  namespace trait
24  {
25  //! The work div trait.
26  template<typename TWorkDiv, typename TOrigin, typename TUnit, typename TSfinae = void>
27  struct GetWorkDiv;
28  } // namespace trait
29 
30  //! Get the extent requested.
32  template<typename TOrigin, typename TUnit, typename TWorkDiv>
33  ALPAKA_FN_HOST_ACC auto getWorkDiv(TWorkDiv const& workDiv) -> Vec<Dim<TWorkDiv>, Idx<TWorkDiv>>
34  {
37  }
38 
39  namespace trait
40  {
41  //! The work div grid thread extent trait specialization.
42  template<typename TWorkDiv>
43  struct GetWorkDiv<TWorkDiv, origin::Grid, unit::Threads>
44  {
46  ALPAKA_FN_HOST_ACC static auto getWorkDiv(TWorkDiv const& workDiv)
47  {
48  return alpaka::getWorkDiv<origin::Grid, unit::Blocks>(workDiv)
49  * alpaka::getWorkDiv<origin::Block, unit::Threads>(workDiv);
50  }
51  };
52 
53  //! The work div grid element extent trait specialization.
54  template<typename TWorkDiv>
55  struct GetWorkDiv<TWorkDiv, origin::Grid, unit::Elems>
56  {
58  ALPAKA_FN_HOST_ACC static auto getWorkDiv(TWorkDiv const& workDiv)
59  {
60  return alpaka::getWorkDiv<origin::Grid, unit::Threads>(workDiv)
61  * alpaka::getWorkDiv<origin::Thread, unit::Elems>(workDiv);
62  }
63  };
64 
65  //! The work div block element extent trait specialization.
66  template<typename TWorkDiv>
67  struct GetWorkDiv<TWorkDiv, origin::Block, unit::Elems>
68  {
70  ALPAKA_FN_HOST_ACC static auto getWorkDiv(TWorkDiv const& workDiv)
71  {
72  return alpaka::getWorkDiv<origin::Block, unit::Threads>(workDiv)
73  * alpaka::getWorkDiv<origin::Thread, unit::Elems>(workDiv);
74  }
75  };
76  } // namespace trait
77 } // namespace alpaka
A n-dimensional vector.
Definition: Vec.hpp:38
#define ALPAKA_FN_HOST_ACC
Definition: Common.hpp:39
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
typename detail::ImplementationBaseType< TInterface, TDerived >::type ImplementationBase
Returns the type that implements the given interface in the inheritance hierarchy.
Definition: Interface.hpp:66
The alpaka accelerator library.
typename trait::IdxType< T >::type Idx
Definition: Traits.hpp:29
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getWorkDiv(TWorkDiv const &workDiv) -> Vec< Dim< TWorkDiv >, Idx< TWorkDiv >>
Get the extent requested.
Definition: Traits.hpp:33
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC auto getWorkDiv(TWorkDiv const &workDiv)
Definition: Traits.hpp:70
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC auto getWorkDiv(TWorkDiv const &workDiv)
Definition: Traits.hpp:58
ALPAKA_NO_HOST_ACC_WARNING static ALPAKA_FN_HOST_ACC auto getWorkDiv(TWorkDiv const &workDiv)
Definition: Traits.hpp:46
The work div trait.
Definition: Traits.hpp:27