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
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 {
105 }
106 };
107
108 //! The CPU device available memory get trait specialization.
109 template<>
110 struct GetMemBytes<DevCpu>
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<>
120 struct GetFreeMemBytes<DevCpu>
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<>
130 struct GetWarpSizes<DevCpu>
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<>
140 struct GetPreferredWarpSize<DevCpu>
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<>
161 struct NativeHandle<DevCpu>
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 {
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 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:191
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:190
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
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