alpaka
Abstraction Library for Parallel Kernel Acceleration
AccCpuOmp2Blocks.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Axel Huebl, Benjamin Worpitz, RenĂ© Widera, Jan Stephan, Bernhard Manfred Gruber, Andrea Bocci
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 // 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 <limits>
39 #include <typeinfo>
40 
41 #ifdef ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED
42 
43 # if _OPENMP < 200203
44 # error If ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED is set, the compiler has to support OpenMP 2.0 or higher!
45 # endif
46 
47 namespace alpaka
48 {
49  template<typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
51 
52  //! The CPU OpenMP 2.0 block accelerator.
53  //!
54  //! This accelerator allows parallel kernel execution on a CPU device.
55  //! It uses OpenMP 2.0 to implement the grid block parallelism.
56  //! The block idx is restricted to 1x1x1.
57  template<typename TDim, typename TIdx>
58  class AccCpuOmp2Blocks final
59  : public WorkDivMembers<TDim, TIdx>
60  , public gb::IdxGbRef<TDim, TIdx>
61  , public bt::IdxBtZero<TDim, TIdx>
62  , public AtomicHierarchy<
63  AtomicCpu, // grid atomics
64  AtomicOmpBuiltIn, // block atomics
65  AtomicNoOp> // thread atomics
66  , public math::MathStdLib
67  , public BlockSharedMemDynMember<>
68  , public BlockSharedMemStMember<>
69  , public BlockSyncNoOp
70  , public IntrinsicCpu
71  , public MemFenceOmp2Blocks
72 # ifdef ALPAKA_DISABLE_VENDOR_RNG
73  , public rand::RandDefault
74 # else
75  , public rand::RandStdLib
76 # endif
77  , public warp::WarpSingleThread
78  , public concepts::Implements<ConceptAcc, AccCpuOmp2Blocks<TDim, TIdx>>
79  {
80  static_assert(
81  sizeof(TIdx) >= sizeof(int),
82  "Index type is not supported, consider using int or a larger type.");
83 
84  public:
85  // Partial specialization with the correct TDim and TIdx is not allowed.
86  template<typename TDim2, typename TIdx2, typename TKernelFnObj, typename... TArgs>
87  friend class ::alpaka::TaskKernelCpuOmp2Blocks;
88 
91  auto operator=(AccCpuOmp2Blocks const&) -> AccCpuOmp2Blocks& = delete;
93 
94  private:
95  template<typename TWorkDiv>
96  ALPAKA_FN_HOST AccCpuOmp2Blocks(TWorkDiv const& workDiv, std::size_t const& blockSharedMemDynSizeBytes)
97  : WorkDivMembers<TDim, TIdx>(workDiv)
98  , gb::IdxGbRef<TDim, TIdx>(m_gridBlockIdx)
99  , BlockSharedMemDynMember<>(blockSharedMemDynSizeBytes)
101  , m_gridBlockIdx(Vec<TDim, TIdx>::zeros())
102  {
103  }
104 
105  private:
106  // getIdx
107  Vec<TDim, TIdx> mutable m_gridBlockIdx; //!< The index of the currently executed block.
108  };
109 
110  namespace trait
111  {
112  //! The CPU OpenMP 2.0 block accelerator accelerator type trait specialization.
113  template<typename TDim, typename TIdx>
114  struct AccType<AccCpuOmp2Blocks<TDim, TIdx>>
115  {
117  };
118 
119  //! The CPU OpenMP 2.0 block single thread accelerator type trait specialization.
120  template<typename TDim, typename TIdx>
121  struct IsSingleThreadAcc<AccCpuOmp2Blocks<TDim, TIdx>> : std::true_type
122  {
123  };
124 
125  //! The CPU OpenMP 2.0 block multi thread accelerator type trait specialization.
126  template<typename TDim, typename TIdx>
127  struct IsMultiThreadAcc<AccCpuOmp2Blocks<TDim, TIdx>> : std::false_type
128  {
129  };
130 
131  //! The CPU OpenMP 2.0 block accelerator device properties get trait specialization.
132  template<typename TDim, typename TIdx>
133  struct GetAccDevProps<AccCpuOmp2Blocks<TDim, TIdx>>
134  {
136  {
137  return {// m_multiProcessorCount
138  static_cast<TIdx>(1),
139  // m_gridBlockExtentMax
141  // m_gridBlockCountMax
143  // m_blockThreadExtentMax
145  // m_blockThreadCountMax
146  static_cast<TIdx>(1),
147  // m_threadElemExtentMax
149  // m_threadElemCountMax
151  // m_sharedMemSizeBytes
152  static_cast<size_t>(AccCpuOmp2Blocks<TDim, TIdx>::staticAllocBytes()),
153  // m_globalMemSizeBytes
154  getMemBytes(dev)};
155  }
156  };
157 
158  //! The CPU OpenMP 2.0 block accelerator name trait specialization.
159  template<typename TDim, typename TIdx>
160  struct GetAccName<AccCpuOmp2Blocks<TDim, TIdx>>
161  {
162  ALPAKA_FN_HOST static auto getAccName() -> std::string
163  {
164  return "AccCpuOmp2Blocks<" + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
165  }
166  };
167 
168  //! The CPU OpenMP 2.0 block accelerator device type trait specialization.
169  template<typename TDim, typename TIdx>
170  struct DevType<AccCpuOmp2Blocks<TDim, TIdx>>
171  {
172  using type = DevCpu;
173  };
174 
175  //! The CPU OpenMP 2.0 block accelerator dimension getter trait specialization.
176  template<typename TDim, typename TIdx>
177  struct DimType<AccCpuOmp2Blocks<TDim, TIdx>>
178  {
179  using type = TDim;
180  };
181 
182  //! The CPU OpenMP 2.0 block accelerator execution task type trait specialization.
183  template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
184  struct CreateTaskKernel<AccCpuOmp2Blocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
185  {
187  TWorkDiv const& workDiv,
188  TKernelFnObj const& kernelFnObj,
189  TArgs&&... args)
190  {
191  return TaskKernelCpuOmp2Blocks<TDim, TIdx, TKernelFnObj, TArgs...>(
192  workDiv,
193  kernelFnObj,
194  std::forward<TArgs>(args)...);
195  }
196  };
197 
198  //! The CPU OpenMP 2.0 block execution task platform type trait specialization.
199  template<typename TDim, typename TIdx>
200  struct PlatformType<AccCpuOmp2Blocks<TDim, TIdx>>
201  {
202  using type = PlatformCpu;
203  };
204 
205  //! The CPU OpenMP 2.0 block accelerator idx type trait specialization.
206  template<typename TDim, typename TIdx>
207  struct IdxType<AccCpuOmp2Blocks<TDim, TIdx>>
208  {
209  using type = TIdx;
210  };
211 
212  template<typename TDim, typename TIdx>
213  struct AccToTag<alpaka::AccCpuOmp2Blocks<TDim, TIdx>>
214  {
216  };
217 
218  template<typename TDim, typename TIdx>
219  struct TagToAcc<alpaka::TagCpuOmp2Blocks, TDim, TIdx>
220  {
222  };
223  } // namespace trait
224 } // namespace alpaka
225 
226 #endif
The CPU OpenMP 2.0 block accelerator.
AccCpuOmp2Blocks(AccCpuOmp2Blocks const &)=delete
auto operator=(AccCpuOmp2Blocks const &) -> AccCpuOmp2Blocks &=delete
AccCpuOmp2Blocks(AccCpuOmp2Blocks &&)=delete
auto operator=(AccCpuOmp2Blocks &&) -> AccCpuOmp2Blocks &=delete
Dynamic block shared memory provider using fixed-size member array to allocate memory on the stack or...
static constexpr auto staticAllocBytes() -> std::uint32_t
auto staticMemBegin() const -> uint8_t *
auto staticMemCapacity() const -> std::uint32_t
Static block shared memory provider using a pointer to externally allocated fixed-size memory,...
The no op block synchronization.
The CPU device handle.
Definition: DevCpu.hpp:56
The CPU intrinsic.
The CPU OpenMP 2.0 block memory fence.
The CPU OpenMP 2.0 block accelerator execution task.
A n-dimensional vector.
Definition: Vec.hpp:38
ALPAKA_NO_HOST_ACC_WARNING static constexpr ALPAKA_FN_HOST_ACC auto ones() -> Vec< TDim, TVal >
One value constructor.
Definition: Vec.hpp:133
A basic class holding the work division as grid block extent, block thread and thread element extent.
A zero block thread index provider.
Definition: IdxBtZero.hpp:19
A IdxGbRef grid block index.
Definition: IdxGbRef.hpp:20
IdxGbRef(Vec< TDim, TIdx > const &gridBlockIdx)
Definition: IdxGbRef.hpp:22
The standard library math trait specializations.
Definition: MathStdLib.hpp:249
"Tiny" state mersenne twister implementation
Definition: RandStdLib.hpp:20
The single-threaded warp to emulate it on CPUs.
#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
The alpaka accelerator library.
ALPAKA_FN_HOST auto getMemBytes(TDev const &dev) -> std::size_t
Definition: Traits.hpp:95
The acceleration properties on a device.
Definition: AccDevProps.hpp:18
The CPU device platform.
Definition: PlatformCpu.hpp:18
Tag used in class inheritance hierarchies that describes that a specific concept (TConcept) is implem...
Definition: Concepts.hpp:15
The accelerator type trait.
Definition: Traits.hpp:37
static ALPAKA_FN_HOST auto createTaskKernel(TWorkDiv const &workDiv, TKernelFnObj const &kernelFnObj, TArgs &&... args)
The kernel execution task creation trait.
Definition: Traits.hpp:34
The device type trait.
Definition: Traits.hpp:23
The dimension getter type trait.
Definition: Traits.hpp:14
static ALPAKA_FN_HOST auto getAccDevProps(DevCpu const &dev) -> alpaka::AccDevProps< TDim, TIdx >
The device properties get trait.
Definition: Traits.hpp:61
static ALPAKA_FN_HOST auto getAccName() -> std::string
The accelerator name trait.
Definition: Traits.hpp:68
The idx type trait.
Definition: Traits.hpp:25
The multi thread accelerator trait.
Definition: Traits.hpp:56
The single thread accelerator trait.
Definition: Traits.hpp:46
The platform type trait.
Definition: Traits.hpp:30