alpaka
Abstraction Library for Parallel Kernel Acceleration
AccCpuTbbBlocks.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, Erik Zenker, RenĂ© Widera, Jan Stephan, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 // Base classes.
24 
25 // Specialized traits.
26 #include "alpaka/acc/Traits.hpp"
27 #include "alpaka/dev/Traits.hpp"
28 #include "alpaka/idx/Traits.hpp"
29 #include "alpaka/kernel/Traits.hpp"
31 
32 // Implementation details.
33 #include "alpaka/acc/Tag.hpp"
34 #include "alpaka/core/Concepts.hpp"
35 #include "alpaka/dev/DevCpu.hpp"
36 
37 #include <memory>
38 #include <typeinfo>
39 
40 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED
41 
42 namespace alpaka
43 {
44  template<typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
45  class TaskKernelCpuTbbBlocks;
46 
47  //! The CPU TBB block accelerator.
48  template<typename TDim, typename TIdx>
49  class AccCpuTbbBlocks final
50  : public WorkDivMembers<TDim, TIdx>
51  , public gb::IdxGbRef<TDim, TIdx>
52  , public bt::IdxBtZero<TDim, TIdx>
53  , public AtomicHierarchy<
54  AtomicCpu, // grid atomics
55  AtomicCpu, // block atomics
56  AtomicNoOp> // thread atomics
57  , public math::MathStdLib
58  , public BlockSharedMemDynMember<>
59  , public BlockSharedMemStMember<>
60  , public BlockSyncNoOp
61  , public IntrinsicCpu
62  , public MemFenceCpu
63 # ifdef ALPAKA_DISABLE_VENDOR_RNG
64  , public rand::RandDefault
65 # else
66  , public rand::RandStdLib
67 # endif
68  , public warp::WarpSingleThread
69  , public concepts::Implements<ConceptAcc, AccCpuTbbBlocks<TDim, TIdx>>
70  {
71  static_assert(
72  sizeof(TIdx) >= sizeof(int),
73  "Index type is not supported, consider using int or a larger type.");
74 
75  public:
76  // Partial specialization with the correct TDim and TIdx is not allowed.
77  template<typename TDim2, typename TIdx2, typename TKernelFnObj, typename... TArgs>
78  friend class ::alpaka::TaskKernelCpuTbbBlocks;
79 
80  AccCpuTbbBlocks(AccCpuTbbBlocks const&) = delete;
81  AccCpuTbbBlocks(AccCpuTbbBlocks&&) = delete;
82  auto operator=(AccCpuTbbBlocks const&) -> AccCpuTbbBlocks& = delete;
83  auto operator=(AccCpuTbbBlocks&&) -> AccCpuTbbBlocks& = delete;
84 
85  private:
86  template<typename TWorkDiv>
87  ALPAKA_FN_HOST AccCpuTbbBlocks(TWorkDiv const& workDiv, std::size_t const& blockSharedMemDynSizeBytes)
88  : WorkDivMembers<TDim, TIdx>(workDiv)
89  , gb::IdxGbRef<TDim, TIdx>(m_gridBlockIdx)
90  , BlockSharedMemDynMember<>(blockSharedMemDynSizeBytes)
91  , BlockSharedMemStMember<>(staticMemBegin(), staticMemCapacity())
92  , m_gridBlockIdx(Vec<TDim, TIdx>::zeros())
93  {
94  }
95 
96  private:
97  // getIdx
98  Vec<TDim, TIdx> mutable m_gridBlockIdx; //!< The index of the currently executed block.
99  };
100 
101  namespace trait
102  {
103  //! The CPU TBB block accelerator type trait specialization.
104  template<typename TDim, typename TIdx>
105  struct AccType<AccCpuTbbBlocks<TDim, TIdx>>
106  {
107  using type = AccCpuTbbBlocks<TDim, TIdx>;
108  };
109 
110  //! The CPU TBB block accelerator device properties get trait specialization.
111  template<typename TDim, typename TIdx>
112  struct GetAccDevProps<AccCpuTbbBlocks<TDim, TIdx>>
113  {
114  ALPAKA_FN_HOST static auto getAccDevProps(DevCpu const& dev) -> AccDevProps<TDim, TIdx>
115  {
116  return {// m_multiProcessorCount
117  static_cast<TIdx>(1),
118  // m_gridBlockExtentMax
120  // m_gridBlockCountMax
122  // m_blockThreadExtentMax
124  // m_blockThreadCountMax
125  static_cast<TIdx>(1),
126  // m_threadElemExtentMax
128  // m_threadElemCountMax
130  // m_sharedMemSizeBytes
131  static_cast<size_t>(AccCpuTbbBlocks<TDim, TIdx>::staticAllocBytes()),
132  // m_globalMemSizeBytes
133  getMemBytes(dev)};
134  }
135  };
136 
137  //! The CPU TBB block accelerator name trait specialization.
138  template<typename TDim, typename TIdx>
139  struct GetAccName<AccCpuTbbBlocks<TDim, TIdx>>
140  {
141  ALPAKA_FN_HOST static auto getAccName() -> std::string
142  {
143  return "AccCpuTbbBlocks<" + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
144  }
145  };
146 
147  //! The CPU TBB block accelerator device type trait specialization.
148  template<typename TDim, typename TIdx>
149  struct DevType<AccCpuTbbBlocks<TDim, TIdx>>
150  {
151  using type = DevCpu;
152  };
153 
154  //! The CPU TBB block accelerator dimension getter trait specialization.
155  template<typename TDim, typename TIdx>
156  struct DimType<AccCpuTbbBlocks<TDim, TIdx>>
157  {
158  using type = TDim;
159  };
160 
161  //! The CPU TBB block accelerator execution task type trait specialization.
162  template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
163  struct CreateTaskKernel<AccCpuTbbBlocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
164  {
165  ALPAKA_FN_HOST static auto createTaskKernel(
166  TWorkDiv const& workDiv,
167  TKernelFnObj const& kernelFnObj,
168  TArgs&&... args)
169  {
170  return TaskKernelCpuTbbBlocks<TDim, TIdx, TKernelFnObj, TArgs...>(
171  workDiv,
172  kernelFnObj,
173  std::forward<TArgs>(args)...);
174  }
175  };
176 
177  //! The CPU TBB block execution task platform type trait specialization.
178  template<typename TDim, typename TIdx>
179  struct PlatformType<AccCpuTbbBlocks<TDim, TIdx>>
180  {
181  using type = PlatformCpu;
182  };
183 
184  //! The CPU TBB block accelerator idx type trait specialization.
185  template<typename TDim, typename TIdx>
186  struct IdxType<AccCpuTbbBlocks<TDim, TIdx>>
187  {
188  using type = TIdx;
189  };
190 
191  template<typename TDim, typename TIdx>
192  struct AccToTag<alpaka::AccCpuTbbBlocks<TDim, TIdx>>
193  {
194  using type = alpaka::TagCpuTbbBlocks;
195  };
196 
197  template<typename TDim, typename TIdx>
198  struct TagToAcc<alpaka::TagCpuTbbBlocks, TDim, TIdx>
199  {
200  using type = alpaka::AccCpuTbbBlocks<TDim, TIdx>;
201  };
202  } // namespace trait
203 } // namespace alpaka
204 
205 #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:62
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:49