alpaka
Abstraction Library for Parallel Kernel Acceleration
AccCpuTbbBlocks.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Axel Huebl, Benjamin Worpitz, Erik Zenker, RenĂ© Widera, Jan Stephan, Bernhard Manfred Gruber,
2  * Andrea Bocci
3  * SPDX-License-Identifier: MPL-2.0
4  */
5 
6 #pragma once
7 
8 // Base classes.
25 
26 // Specialized traits.
27 #include "alpaka/acc/Traits.hpp"
28 #include "alpaka/dev/Traits.hpp"
29 #include "alpaka/idx/Traits.hpp"
30 #include "alpaka/kernel/Traits.hpp"
32 
33 // Implementation details.
34 #include "alpaka/acc/Tag.hpp"
35 #include "alpaka/core/Concepts.hpp"
36 #include "alpaka/dev/DevCpu.hpp"
37 
38 #include <memory>
39 #include <typeinfo>
40 
41 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
42 
43 namespace alpaka
44 {
45  template<typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
46  class TaskKernelCpuTbbBlocks;
47 
48  //! The CPU TBB block accelerator.
49  template<typename TDim, typename TIdx>
50  class AccCpuTbbBlocks final
51  : public WorkDivMembers<TDim, TIdx>
52  , public gb::IdxGbRef<TDim, TIdx>
53  , public bt::IdxBtZero<TDim, TIdx>
54  , public AtomicHierarchy<
55  AtomicCpu, // grid atomics
56  AtomicCpu, // block atomics
57  AtomicNoOp> // thread atomics
58  , public math::MathStdLib
59  , public BlockSharedMemDynMember<>
60  , public BlockSharedMemStMember<>
61  , public BlockSyncNoOp
62  , public IntrinsicCpu
63  , public MemFenceCpu
64 # ifdef ALPAKA_DISABLE_VENDOR_RNG
65  , public rand::RandDefault
66 # else
67  , public rand::RandStdLib
68 # endif
69  , public warp::WarpSingleThread
70  , public concepts::Implements<ConceptAcc, AccCpuTbbBlocks<TDim, TIdx>>
71  {
72  static_assert(
73  sizeof(TIdx) >= sizeof(int),
74  "Index type is not supported, consider using int or a larger type.");
75 
76  public:
77  // Partial specialization with the correct TDim and TIdx is not allowed.
78  template<typename TDim2, typename TIdx2, typename TKernelFnObj, typename... TArgs>
79  friend class ::alpaka::TaskKernelCpuTbbBlocks;
80 
81  AccCpuTbbBlocks(AccCpuTbbBlocks const&) = delete;
82  AccCpuTbbBlocks(AccCpuTbbBlocks&&) = delete;
83  auto operator=(AccCpuTbbBlocks const&) -> AccCpuTbbBlocks& = delete;
84  auto operator=(AccCpuTbbBlocks&&) -> AccCpuTbbBlocks& = delete;
85 
86  private:
87  template<typename TWorkDiv>
88  ALPAKA_FN_HOST AccCpuTbbBlocks(TWorkDiv const& workDiv, std::size_t const& blockSharedMemDynSizeBytes)
89  : WorkDivMembers<TDim, TIdx>(workDiv)
90  , gb::IdxGbRef<TDim, TIdx>(m_gridBlockIdx)
91  , BlockSharedMemDynMember<>(blockSharedMemDynSizeBytes)
92  , BlockSharedMemStMember<>(staticMemBegin(), staticMemCapacity())
93  , m_gridBlockIdx(Vec<TDim, TIdx>::zeros())
94  {
95  }
96 
97  private:
98  // getIdx
99  Vec<TDim, TIdx> mutable m_gridBlockIdx; //!< The index of the currently executed block.
100  };
101 
102  namespace trait
103  {
104  //! The CPU TBB block accelerator type trait specialization.
105  template<typename TDim, typename TIdx>
106  struct AccType<AccCpuTbbBlocks<TDim, TIdx>>
107  {
108  using type = AccCpuTbbBlocks<TDim, TIdx>;
109  };
110 
111  //! The CPU TBB block single thread accelerator type trait specialization.
112  template<typename TDim, typename TIdx>
113  struct IsSingleThreadAcc<AccCpuTbbBlocks<TDim, TIdx>> : std::true_type
114  {
115  };
116 
117  //! The CPU TBB block multi thread accelerator type trait specialization.
118  template<typename TDim, typename TIdx>
119  struct IsMultiThreadAcc<AccCpuTbbBlocks<TDim, TIdx>> : std::false_type
120  {
121  };
122 
123  //! The CPU TBB block accelerator device properties get trait specialization.
124  template<typename TDim, typename TIdx>
125  struct GetAccDevProps<AccCpuTbbBlocks<TDim, TIdx>>
126  {
127  ALPAKA_FN_HOST static auto getAccDevProps(DevCpu const& dev) -> AccDevProps<TDim, TIdx>
128  {
129  return {// m_multiProcessorCount
130  static_cast<TIdx>(1),
131  // m_gridBlockExtentMax
133  // m_gridBlockCountMax
135  // m_blockThreadExtentMax
137  // m_blockThreadCountMax
138  static_cast<TIdx>(1),
139  // m_threadElemExtentMax
141  // m_threadElemCountMax
143  // m_sharedMemSizeBytes
144  static_cast<size_t>(AccCpuTbbBlocks<TDim, TIdx>::staticAllocBytes()),
145  // m_globalMemSizeBytes
146  getMemBytes(dev)};
147  }
148  };
149 
150  //! The CPU TBB block accelerator name trait specialization.
151  template<typename TDim, typename TIdx>
152  struct GetAccName<AccCpuTbbBlocks<TDim, TIdx>>
153  {
154  ALPAKA_FN_HOST static auto getAccName() -> std::string
155  {
156  return "AccCpuTbbBlocks<" + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
157  }
158  };
159 
160  //! The CPU TBB block accelerator device type trait specialization.
161  template<typename TDim, typename TIdx>
162  struct DevType<AccCpuTbbBlocks<TDim, TIdx>>
163  {
164  using type = DevCpu;
165  };
166 
167  //! The CPU TBB block accelerator dimension getter trait specialization.
168  template<typename TDim, typename TIdx>
169  struct DimType<AccCpuTbbBlocks<TDim, TIdx>>
170  {
171  using type = TDim;
172  };
173 
174  //! The CPU TBB block accelerator execution task type trait specialization.
175  template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
176  struct CreateTaskKernel<AccCpuTbbBlocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
177  {
178  ALPAKA_FN_HOST static auto createTaskKernel(
179  TWorkDiv const& workDiv,
180  TKernelFnObj const& kernelFnObj,
181  TArgs&&... args)
182  {
183  return TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>(
184  workDiv,
185  kernelFnObj,
186  std::forward<TArgs>(args)...);
187  }
188  };
189 
190  //! The CPU TBB block execution task platform type trait specialization.
191  template<typename TDim, typename TIdx>
192  struct PlatformType<AccCpuTbbBlocks<TDim, TIdx>>
193  {
194  using type = PlatformCpu;
195  };
196 
197  //! The CPU TBB block accelerator idx type trait specialization.
198  template<typename TDim, typename TIdx>
199  struct IdxType<AccCpuTbbBlocks<TDim, TIdx>>
200  {
201  using type = TIdx;
202  };
203 
204  template<typename TDim, typename TIdx>
205  struct AccToTag<alpaka::AccCpuTbbBlocks<TDim, TIdx>>
206  {
207  using type = alpaka::TagCpuTbbBlocks;
208  };
209 
210  template<typename TDim, typename TIdx>
211  struct TagToAcc<alpaka::TagCpuTbbBlocks, TDim, TIdx>
212  {
213  using type = alpaka::AccCpuTbbBlocks<TDim, TIdx>;
214  };
215  } // namespace trait
216 } // namespace alpaka
217 
218 #endif
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto ones() -> Vec< TDim, TVal >
One value constructor.
Definition: Vec.hpp:133
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto all(TIdx const &val) -> Vec< TDim, TIdx >
Single value constructor.
Definition: Vec.hpp:116
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
Definition: Traits.hpp:1263
TinyMersenneTwister RandStdLib
Definition: RandStdLib.hpp:23
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC WorkDivMembers(alpaka::Vec< TDim, TIdx > const &gridBlockExtent, alpaka::Vec< TDim, TIdx > const &blockThreadExtent, alpaka::Vec< TDim, TIdx > const &elemExtent) -> WorkDivMembers< TDim, TIdx >
Deduction guide for the constructor which can be called without explicit template type parameters.
ALPAKA_FN_HOST auto getAccDevProps(TDev const &dev) -> AccDevProps< Dim< TAcc >, Idx< TAcc >>
Definition: Traits.hpp:90
ALPAKA_FN_HOST auto createTaskKernel(TWorkDiv const &workDiv, TKernelFnObj const &kernelFnObj, TArgs &&... args)
Creates a kernel execution task.
Definition: Traits.hpp:262
ALPAKA_FN_HOST auto getMemBytes(TDev const &dev) -> std::size_t
Definition: Traits.hpp:95
Vec(TFirstIndex &&, TRestIndices &&...) -> Vec< DimInt< 1+sizeof...(TRestIndices)>, std::decay_t< TFirstIndex >>
alpaka::meta::InheritFromList< alpaka::meta::Unique< std::tuple< TGridAtomic, TBlockAtomic, TThreadAtomic, concepts::Implements< ConceptAtomicGrids, TGridAtomic >, concepts::Implements< ConceptAtomicBlocks, TBlockAtomic >, concepts::Implements< ConceptAtomicThreads, TThreadAtomic > >> > AtomicHierarchy
build a single class to inherit from different atomic implementations
typename trait::AccToTag< TAcc >::type AccToTag
maps an acc type to a tag type
Definition: Tag.hpp:47
typename trait::TagToAcc< TTag, TDim, TIdx >::type TagToAcc
maps a tag type to an acc type
Definition: Tag.hpp:54
static ALPAKA_FN_HOST auto getAccName() -> std::string
Definition: Traits.hpp:69