alpaka
Abstraction Library for Parallel Kernel Acceleration
DevCpu.hpp
Go to the documentation of this file.
1 /* Copyright 2024 Axel Huebl, Benjamin Worpitz, Matthias Werner, Jan Stephan, Bernhard Manfred Gruber,
2  * Antonio Di Pilato, Andrea Bocci
3  * SPDX-License-Identifier: MPL-2.0
4  */
5 
6 #pragma once
7 
8 #include "alpaka/dev/Traits.hpp"
16 #include "alpaka/queue/Traits.hpp"
18 #include "alpaka/traits/Traits.hpp"
19 #include "alpaka/wait/Traits.hpp"
20 
21 #include <algorithm>
22 #include <cstddef>
23 #include <map>
24 #include <memory>
25 #include <mutex>
26 #include <string>
27 #include <vector>
28 
29 namespace alpaka
30 {
31  class DevCpu;
32 
33  namespace cpu
34  {
36  } // namespace cpu
37 
38  namespace trait
39  {
40  template<typename TPlatform, typename TSfinae>
41  struct GetDevByIdx;
42  } // namespace trait
43  struct PlatformCpu;
44 
45  //! The CPU device.
46  namespace cpu::detail
47  {
48  //! The CPU device implementation.
50  } // namespace cpu::detail
51 
52  //! The CPU device handle.
53  class DevCpu
54  : public concepts::Implements<ConceptCurrentThreadWaitFor, DevCpu>
55  , public concepts::Implements<ConceptDev, DevCpu>
56  {
57  friend struct trait::GetDevByIdx<PlatformCpu>;
58 
59  protected:
60  DevCpu() : m_spDevCpuImpl(std::make_shared<cpu::detail::DevCpuImpl>())
61  {
62  }
63 
64  public:
65  auto operator==(DevCpu const&) const -> bool
66  {
67  return true;
68  }
69 
70  auto operator!=(DevCpu const& rhs) const -> bool
71  {
72  return !((*this) == rhs);
73  }
74 
75  [[nodiscard]] ALPAKA_FN_HOST auto getAllQueues() const -> std::vector<std::shared_ptr<cpu::ICpuQueue>>
76  {
77  return m_spDevCpuImpl->getAllExistingQueues();
78  }
79 
80  //! Registers the given queue on this device.
81  //! NOTE: Every queue has to be registered for correct functionality of device wait operations!
82  ALPAKA_FN_HOST auto registerQueue(std::shared_ptr<cpu::ICpuQueue> spQueue) const -> void
83  {
84  m_spDevCpuImpl->registerQueue(spQueue);
85  }
86 
87  [[nodiscard]] auto getNativeHandle() const noexcept
88  {
89  return 0;
90  }
91 
92  private:
93  std::shared_ptr<cpu::detail::DevCpuImpl> m_spDevCpuImpl;
94  };
95 
96  namespace trait
97  {
98  //! The CPU device name get trait specialization.
99  template<>
100  struct GetName<DevCpu>
101  {
102  ALPAKA_FN_HOST static auto getName(DevCpu const& /* dev */) -> std::string
103  {
104  return cpu::detail::getCpuName();
105  }
106  };
107 
108  //! The CPU device available memory get trait specialization.
109  template<>
111  {
112  ALPAKA_FN_HOST static auto getMemBytes(DevCpu const& /* dev */) -> std::size_t
113  {
115  }
116  };
117 
118  //! The CPU device free memory get trait specialization.
119  template<>
121  {
122  ALPAKA_FN_HOST static auto getFreeMemBytes(DevCpu const& /* dev */) -> std::size_t
123  {
125  }
126  };
127 
128  //! The CPU device warp size get trait specialization.
129  template<>
131  {
132  ALPAKA_FN_HOST static auto getWarpSizes(DevCpu const& /* dev */) -> std::vector<std::size_t>
133  {
134  return {1u};
135  }
136  };
137 
138  //! The CPU device preferred warp size get trait specialization.
139  template<>
141  {
142  ALPAKA_FN_HOST static constexpr auto getPreferredWarpSize(DevCpu const& /* dev */) -> std::size_t
143  {
144  return 1u;
145  }
146  };
147 
148  //! The CPU device reset trait specialization.
149  template<>
150  struct Reset<DevCpu>
151  {
152  ALPAKA_FN_HOST static auto reset(DevCpu const& /* dev */) -> void
153  {
155  // The CPU does nothing on reset.
156  }
157  };
158 
159  //! The CPU device native handle type trait specialization.
160  template<>
162  {
163  [[nodiscard]] static auto getNativeHandle(DevCpu const& dev)
164  {
165  return dev.getNativeHandle();
166  }
167  };
168  } // namespace trait
169 
170  template<typename TElem, typename TDim, typename TIdx>
171  class BufCpu;
172 
173  namespace trait
174  {
175  //! The CPU device memory buffer type trait specialization.
176  template<typename TElem, typename TDim, typename TIdx>
177  struct BufType<DevCpu, TElem, TDim, TIdx>
178  {
180  };
181 
182  //! The CPU device platform type trait specialization.
183  template<>
185  {
186  using type = PlatformCpu;
187  };
188  } // namespace trait
189 
192 
193  namespace trait
194  {
195  template<>
196  struct QueueType<DevCpu, Blocking>
197  {
199  };
200 
201  template<>
202  struct QueueType<DevCpu, NonBlocking>
203  {
205  };
206  } // namespace trait
207 } // namespace alpaka
#define ALPAKA_DEBUG_FULL_LOG_SCOPE
Definition: Debug.hpp:62
The CPU memory buffer.
Definition: BufCpu.hpp:90
The CPU device handle.
Definition: DevCpu.hpp:56
auto operator!=(DevCpu const &rhs) const -> bool
Definition: DevCpu.hpp:70
auto getNativeHandle() const noexcept
Definition: DevCpu.hpp:87
auto operator==(DevCpu const &) const -> bool
Definition: DevCpu.hpp:65
ALPAKA_FN_HOST auto registerQueue(std::shared_ptr< cpu::ICpuQueue > spQueue) const -> void
Registers the given queue on this device. NOTE: Every queue has to be registered for correct function...
Definition: DevCpu.hpp:82
ALPAKA_FN_HOST auto getAllQueues() const -> std::vector< std::shared_ptr< cpu::ICpuQueue >>
Definition: DevCpu.hpp:75
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
alpaka::detail::QueueRegistry< cpu::ICpuQueue > DevCpuImpl
The CPU device implementation.
Definition: DevCpu.hpp:49
auto getTotalGlobalMemSizeBytes() -> std::size_t
Definition: SysInfo.hpp:146
auto getFreeGlobalMemSizeBytes() -> std::size_t
Definition: SysInfo.hpp:209
auto getCpuName() -> std::string
Definition: SysInfo.hpp:77
IGenericThreadsQueue< DevCpu > ICpuQueue
The CPU queue interface.
Definition: DevCpu.hpp:35
The alpaka accelerator library.
QueueGenericThreadsBlocking< DevCpu > QueueCpuBlocking
Definition: DevCpu.hpp:191
QueueGenericThreadsNonBlocking< DevCpu > QueueCpuNonBlocking
Definition: DevCpu.hpp:190
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 CPU/GPU device queue registry implementation.
The memory buffer type trait.
Definition: Traits.hpp:23
The device get trait.
Definition: DevCpu.hpp:41
static ALPAKA_FN_HOST auto getFreeMemBytes(DevCpu const &) -> std::size_t
Definition: DevCpu.hpp:122
The device free memory size get trait.
Definition: Traits.hpp:39
static ALPAKA_FN_HOST auto getMemBytes(DevCpu const &) -> std::size_t
Definition: DevCpu.hpp:112
The device memory size get trait.
Definition: Traits.hpp:35
static ALPAKA_FN_HOST auto getName(DevCpu const &) -> std::string
Definition: DevCpu.hpp:102
The device name get trait.
Definition: Traits.hpp:31
static constexpr ALPAKA_FN_HOST auto getPreferredWarpSize(DevCpu const &) -> std::size_t
Definition: DevCpu.hpp:142
The device preferred warp size get trait.
Definition: Traits.hpp:47
static ALPAKA_FN_HOST auto getWarpSizes(DevCpu const &) -> std::vector< std::size_t >
Definition: DevCpu.hpp:132
The device warp size get trait.
Definition: Traits.hpp:43
static auto getNativeHandle(DevCpu const &dev)
Definition: DevCpu.hpp:163
The native handle trait.
Definition: Traits.hpp:17
The platform type trait.
Definition: Traits.hpp:30
Queue for an accelerator.
Definition: Traits.hpp:35
static ALPAKA_FN_HOST auto reset(DevCpu const &) -> void
Definition: DevCpu.hpp:152
The device reset trait.
Definition: Traits.hpp:51