alpaka
Abstraction Library for Parallel Kernel Acceleration
AccCpuSerial.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.
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_SEQ_T_SEQ_ENABLED
41 
42 namespace alpaka
43 {
44  template<typename TDim, typename TIdx, typename TKernelFnObj, typename... TArgs>
45  class TaskKernelCpuSerial;
46 
47  //! The CPU serial accelerator.
48  //!
49  //! This accelerator allows serial kernel execution on a CPU device.
50  //! The block idx is restricted to 1x1x1 and all blocks are executed serially so there is no parallelism at all.
51  template<typename TDim, typename TIdx>
52  class AccCpuSerial final
53  : public WorkDivMembers<TDim, TIdx>
54  , public gb::IdxGbRef<TDim, TIdx>
55  , public bt::IdxBtZero<TDim, TIdx>
56  , public AtomicHierarchy<
57  AtomicCpu, // grid atomics
58  AtomicNoOp, // block atomics
59  AtomicNoOp> // thread atomics
60  , public math::MathStdLib
61  , public BlockSharedMemDynMember<>
62  , public BlockSharedMemStMember<>
63  , public BlockSyncNoOp
64  , public IntrinsicCpu
65  , public MemFenceCpuSerial
66 # ifdef ALPAKA_DISABLE_VENDOR_RNG
67  , public rand::RandDefault
68 # else
69  , public rand::RandStdLib
70 # endif
71  , public warp::WarpSingleThread
72  , public concepts::Implements<ConceptAcc, AccCpuSerial<TDim, TIdx>>
73  {
74  static_assert(
75  sizeof(TIdx) >= sizeof(int),
76  "Index type is not supported, consider using int or a larger type.");
77 
78  public:
79  // Partial specialization with the correct TDim and TIdx is not allowed.
80  template<typename TDim2, typename TIdx2, typename TKernelFnObj, typename... TArgs>
81  friend class ::alpaka::TaskKernelCpuSerial;
82 
83  AccCpuSerial(AccCpuSerial const&) = delete;
85  auto operator=(AccCpuSerial const&) -> AccCpuSerial& = delete;
86  auto operator=(AccCpuSerial&&) -> AccCpuSerial& = delete;
87 
88  private:
89  template<typename TWorkDiv>
90  ALPAKA_FN_HOST AccCpuSerial(TWorkDiv const& workDiv, size_t const& blockSharedMemDynSizeBytes)
91  : WorkDivMembers<TDim, TIdx>(workDiv)
92  , gb::IdxGbRef<TDim, TIdx>(m_gridBlockIdx)
93  , BlockSharedMemDynMember<>(blockSharedMemDynSizeBytes)
95  , m_gridBlockIdx(Vec<TDim, TIdx>::zeros())
96  {
97  }
98 
99  private:
100  // getIdx
101  Vec<TDim, TIdx> mutable m_gridBlockIdx; //!< The index of the currently executed block.
102  };
103 
104  namespace trait
105  {
106  //! The CPU serial accelerator accelerator type trait specialization.
107  template<typename TDim, typename TIdx>
108  struct AccType<AccCpuSerial<TDim, TIdx>>
109  {
111  };
112 
113  //! The CPU serial accelerator device properties get trait specialization.
114  template<typename TDim, typename TIdx>
115  struct GetAccDevProps<AccCpuSerial<TDim, TIdx>>
116  {
118  {
119  return {// m_multiProcessorCount
120  static_cast<TIdx>(1),
121  // m_gridBlockExtentMax
123  // m_gridBlockCountMax
125  // m_blockThreadExtentMax
127  // m_blockThreadCountMax
128  static_cast<TIdx>(1),
129  // m_threadElemExtentMax
131  // m_threadElemCountMax
133  // m_sharedMemSizeBytes
134  static_cast<size_t>(AccCpuSerial<TDim, TIdx>::staticAllocBytes()),
135  // m_globalMemSizeBytes
136  getMemBytes(dev)};
137  }
138  };
139 
140  //! The CPU serial accelerator name trait specialization.
141  template<typename TDim, typename TIdx>
142  struct GetAccName<AccCpuSerial<TDim, TIdx>>
143  {
144  ALPAKA_FN_HOST static auto getAccName() -> std::string
145  {
146  return "AccCpuSerial<" + std::to_string(TDim::value) + "," + core::demangled<TIdx> + ">";
147  }
148  };
149 
150  //! The CPU serial accelerator device type trait specialization.
151  template<typename TDim, typename TIdx>
152  struct DevType<AccCpuSerial<TDim, TIdx>>
153  {
154  using type = DevCpu;
155  };
156 
157  //! The CPU serial accelerator dimension getter trait specialization.
158  template<typename TDim, typename TIdx>
159  struct DimType<AccCpuSerial<TDim, TIdx>>
160  {
161  using type = TDim;
162  };
163 
164  //! The CPU serial accelerator execution task type trait specialization.
165  template<typename TDim, typename TIdx, typename TWorkDiv, typename TKernelFnObj, typename... TArgs>
166  struct CreateTaskKernel<AccCpuSerial<TDim, TIdx>, TWorkDiv, TKernelFnObj, TArgs...>
167  {
169  TWorkDiv const& workDiv,
170  TKernelFnObj const& kernelFnObj,
171  TArgs&&... args)
172  {
173  return TaskKernelCpuSerial<TDim, TIdx, TKernelFnObj, TArgs...>(
174  workDiv,
175  kernelFnObj,
176  std::forward<TArgs>(args)...);
177  }
178  };
179 
180  //! The CPU serial execution task platform type trait specialization.
181  template<typename TDim, typename TIdx>
182  struct PlatformType<AccCpuSerial<TDim, TIdx>>
183  {
184  using type = PlatformCpu;
185  };
186 
187  //! The CPU serial accelerator idx type trait specialization.
188  template<typename TDim, typename TIdx>
189  struct IdxType<AccCpuSerial<TDim, TIdx>>
190  {
191  using type = TIdx;
192  };
193 
194  template<typename TDim, typename TIdx>
195  struct AccToTag<alpaka::AccCpuSerial<TDim, TIdx>>
196  {
198  };
199 
200  template<typename TDim, typename TIdx>
201  struct TagToAcc<alpaka::TagCpuSerial, TDim, TIdx>
202  {
204  };
205  } // namespace trait
206 } // namespace alpaka
207 
208 #endif
The CPU serial accelerator.
auto operator=(AccCpuSerial &&) -> AccCpuSerial &=delete
auto operator=(AccCpuSerial const &) -> AccCpuSerial &=delete
AccCpuSerial(AccCpuSerial &&)=delete
AccCpuSerial(AccCpuSerial const &)=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 serial CPU memory fence.
The CPU serial execution task implementation.
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) -> 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