alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
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
20
21#include <algorithm>
22#include <cstddef>
23#include <map>
24#include <memory>
25#include <mutex>
26#include <string>
27#include <vector>
28
29namespace alpaka
30{
31 class DevCpu;
32
33 namespace cpu
34 {
36 } // namespace cpu
37
38 namespace trait
39 {
40 template<typename TPlatform, typename TSfinae>
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 interface::Implements<ConceptCurrentThreadWaitFor, DevCpu>
55 , public interface::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
93 {
94 devProperties.name = cpu::detail::getCpuName();
96 }
97
98 friend struct trait::GetName<DevCpu>;
99 friend struct trait::GetMemBytes<DevCpu>;
100 friend struct trait::GetFreeMemBytes<DevCpu>;
101 friend struct trait::GetWarpSizes<DevCpu>;
102 friend struct trait::GetPreferredWarpSize<DevCpu>;
103
104 private:
105 std::shared_ptr<cpu::detail::DevCpuImpl> m_spDevCpuImpl;
106 };
107
108 namespace trait
109 {
110
111 //! The CPU device name get trait specialization.
112 template<>
113 struct GetName<DevCpu>
114 {
115 ALPAKA_FN_HOST static auto getName(DevCpu const& dev) -> std::string
116 {
117 return dev.m_spDevCpuImpl->deviceProperties(dev)->name;
118 }
119 };
120
121 //! The CPU device available memory get trait specialization.
122 template<>
123 struct GetMemBytes<DevCpu>
124 {
125 ALPAKA_FN_HOST static auto getMemBytes(DevCpu const& dev) -> std::size_t
126 {
127 return dev.m_spDevCpuImpl->deviceProperties(dev)->totalGlobalMem;
128 }
129 };
130
131 //! The CPU device free memory get trait specialization.
132 template<>
133 struct GetFreeMemBytes<DevCpu>
134 {
135 ALPAKA_FN_HOST static auto getFreeMemBytes(DevCpu const& /* dev */) -> std::size_t
136 {
138 }
139 };
140
141 //! The CPU device warp size get trait specialization.
142 template<>
143 struct GetWarpSizes<DevCpu>
144 {
145 ALPAKA_FN_HOST static auto getWarpSizes(DevCpu const& /* dev */) -> std::vector<std::size_t>
146 {
147 return {1u};
148 }
149 };
150
151 //! The CPU device preferred warp size get trait specialization.
152 template<>
153 struct GetPreferredWarpSize<DevCpu>
154 {
155 ALPAKA_FN_HOST static constexpr auto getPreferredWarpSize(DevCpu const& /* dev */) -> std::size_t
156 {
157 return 1u;
158 }
159 };
160
161 //! The CPU device reset trait specialization.
162 template<>
163 struct Reset<DevCpu>
164 {
165 ALPAKA_FN_HOST static auto reset(DevCpu const& /* dev */) -> void
166 {
168 // The CPU does nothing on reset.
169 }
170 };
171
172 //! The CPU device native handle type trait specialization.
173 template<>
174 struct NativeHandle<DevCpu>
175 {
176 [[nodiscard]] static auto getNativeHandle(DevCpu const& dev)
177 {
178 return dev.getNativeHandle();
179 }
180 };
181 } // namespace trait
182
183 template<typename TElem, typename TDim, typename TIdx>
184 class BufCpu;
185
186 namespace trait
187 {
188 //! The CPU device memory buffer type trait specialization.
189 template<typename TElem, typename TDim, typename TIdx>
190 struct BufType<DevCpu, TElem, TDim, TIdx>
191 {
193 };
194
195 //! The CPU device platform type trait specialization.
196 template<>
198 {
200 };
201 } // namespace trait
202
205
206 namespace trait
207 {
208 template<>
209 struct QueueType<DevCpu, Blocking>
210 {
212 };
213
214 template<>
215 struct QueueType<DevCpu, NonBlocking>
216 {
218 };
219 } // namespace trait
220} // 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
static void setDeviceProperties(alpaka::DevCpu const &, alpaka::DeviceProperties &devProperties)
Definition DevCpu.hpp:92
auto getNativeHandle() const noexcept
Definition DevCpu.hpp:87
auto operator==(DevCpu const &) const -> bool
Definition DevCpu.hpp:65
ALPAKA_FN_HOST auto getAllQueues() const -> std::vector< std::shared_ptr< cpu::ICpuQueue > >
Definition DevCpu.hpp:75
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
#define ALPAKA_FN_HOST
Definition Common.hpp:40
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
The alpaka accelerator library.
ALPAKA_FN_HOST constexpr auto getPreferredWarpSize(TDev const &dev) -> std::size_t
Definition Traits.hpp:118
ALPAKA_FN_HOST auto getName(TDev const &dev) -> std::string
Definition Traits.hpp:87
ALPAKA_FN_HOST auto getWarpSizes(TDev const &dev) -> std::vector< std::size_t >
Definition Traits.hpp:111
ALPAKA_FN_HOST auto reset(TDev const &dev) -> void
Resets the device. What this method does is dependent on the accelerator.
Definition Traits.hpp:126
QueueGenericThreadsBlocking< DevCpu > QueueCpuBlocking
Definition DevCpu.hpp:204
ALPAKA_FN_HOST auto getFreeMemBytes(TDev const &dev) -> std::size_t
Definition Traits.hpp:104
ALPAKA_FN_HOST auto getMemBytes(TDev const &dev) -> std::size_t
Definition Traits.hpp:95
decltype(getNativeHandle(std::declval< TImpl >())) NativeHandle
Alias to the type of the native handle.
Definition Traits.hpp:36
QueueGenericThreadsNonBlocking< DevCpu > QueueCpuNonBlocking
Definition DevCpu.hpp:203
STL namespace.
The CPU device platform.
The CPU/GPU device queue registry implementation.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15
The memory buffer type trait.
Definition Traits.hpp:23
The device get trait.
Definition DevCpu.hpp:41
The device free memory size get trait.
Definition Traits.hpp:39
The device memory size get trait.
Definition Traits.hpp:35
The device name get trait.
Definition Traits.hpp:31
The device preferred warp size get trait.
Definition Traits.hpp:47
The device warp size get trait.
Definition Traits.hpp:43
static auto getNativeHandle(TImpl const &)
Definition Traits.hpp:18
The platform type trait.
Definition Traits.hpp:30
Queue for an accelerator.
Definition Traits.hpp:35