alpaka
Abstraction Library for Parallel Kernel Acceleration
AccCpuOmp2Blocks.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Axel Huebl, Benjamin Worpitz, RenĂ© Widera, Jan Stephan, Bernhard Manfred Gruber
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 accelerator device properties get trait specialization.
120  template<typename TDim, typename TIdx>
121  struct GetAccDevProps<AccCpuOmp2Blocks<TDim, TIdx>>
122  {
124  {
125  return {// m_multiProcessorCount
126  static_cast<TIdx>(1),
127  // m_gridBlockExtentMax
129  // m_gridBlockCountMax
131  // m_blockThreadExtentMax
133  // m_blockThreadCountMax
134  static_cast<TIdx>(1),
135  // m_threadElemExtentMax
137  // m_threadElemCountMax
139  // m_sharedMemSizeBytes
140  static_cast<size_t>(AccCpuOmp2Blocks<TDim, TIdx>::staticAllocBytes()),
141  // m_globalMemSizeBytes
142  getMemBytes(dev)};
143  }
144  };
145 
146  //! The CPU OpenMP 2.0 block accelerator name trait specialization.
147  template<typename TDim, typename TIdx>
148  struct GetAccName<AccCpuOmp2Blocks<TDim, TIdx>>
149  {
150  ALPAKA_FN_HOST static auto getAccName() -> std::string
151  {
152  return "AccCpuOmp2Blocks<" + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
153  }
154  };
155 
156  //! The CPU OpenMP 2.0 block accelerator device type trait specialization.
157  template<typename TDim, typename TIdx>
158  struct DevType<AccCpuOmp2Blocks<TDim, TIdx>>
159  {
160  using type = DevCpu;
161  };
162 
163  //! The CPU OpenMP 2.0 block accelerator dimension getter trait specialization.
164  template<typename TDim, typename TIdx>
165  struct DimType<AccCpuOmp2Blocks<TDim, TIdx>>
166  {
167  using type = TDim;
168  };
169 
170  //! The CPU OpenMP 2.0 block accelerator execution task type trait specialization.
171  template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
172  struct CreateTaskKernel<AccCpuOmp2Blocks<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
173  {
175  TWorkDiv const& workDiv,
176  TKernelFnObj const& kernelFnObj,
177  TArgs&&... args)
178  {
179  return TaskKernelCpuOmp2Blocks<TDim, TIdx, TKernelFnObj, TArgs...>(
180  workDiv,
181  kernelFnObj,
182  std::forward<TArgs>(args)...);
183  }
184  };
185 
186  //! The CPU OpenMP 2.0 block execution task platform type trait specialization.
187  template<typename TDim, typename TIdx>
188  struct PlatformType<AccCpuOmp2Blocks<TDim, TIdx>>
189  {
190  using type = PlatformCpu;
191  };
192 
193  //! The CPU OpenMP 2.0 block accelerator idx type trait specialization.
194  template<typename TDim, typename TIdx>
195  struct IdxType<AccCpuOmp2Blocks<TDim, TIdx>>
196  {
197  using type = TIdx;
198  };
199 
200  template<typename TDim, typename TIdx>
201  struct AccToTag<alpaka::AccCpuOmp2Blocks<TDim, TIdx>>
202  {
204  };
205 
206  template<typename TDim, typename TIdx>
207  struct TagToAcc<alpaka::TagCpuOmp2Blocks, TDim, TIdx>
208  {
210  };
211  } // namespace trait
212 } // namespace alpaka
213 
214 #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:41
static ALPAKA_FN_HOST auto getAccName() -> std::string
The accelerator name trait.
Definition: Traits.hpp:48
The idx type trait.
Definition: Traits.hpp:25
The platform type trait.
Definition: Traits.hpp:30