20 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
21 #include <Kokkos_Macros.hpp>
23 "Including non-public Kokkos header files is not allowed.");
25 #ifndef KOKKOS_SERIAL_HPP
26 #define KOKKOS_SERIAL_HPP
28 #include <Kokkos_Macros.hpp>
29 #if defined(KOKKOS_ENABLE_SERIAL)
35 #include <Kokkos_Core_fwd.hpp>
36 #include <Kokkos_TaskScheduler.hpp>
37 #include <Kokkos_Layout.hpp>
38 #include <Kokkos_HostSpace.hpp>
39 #include <Kokkos_ScratchSpace.hpp>
40 #include <Kokkos_MemoryTraits.hpp>
41 #include <impl/Kokkos_HostThreadTeam.hpp>
42 #include <impl/Kokkos_FunctorAnalysis.hpp>
43 #include <impl/Kokkos_Tools.hpp>
44 #include <impl/Kokkos_HostSharedPtr.hpp>
45 #include <impl/Kokkos_InitializationSettings.hpp>
50 class SerialInternal {
52 SerialInternal() =
default;
54 bool is_initialized();
60 static SerialInternal& singleton();
62 std::mutex m_thread_team_data_mutex;
65 void resize_thread_team_data(
size_t pool_reduce_bytes,
66 size_t team_reduce_bytes,
67 size_t team_shared_bytes,
68 size_t thread_local_bytes);
70 HostThreadTeamData m_thread_team_data;
71 bool m_is_initialized =
false;
93 using execution_space = Serial;
97 using size_type = memory_space::size_type;
99 using device_type = Kokkos::Device<execution_space, memory_space>;
102 using array_layout = LayoutRight;
105 using scratch_memory_space = ScratchMemorySpace<Kokkos::Serial>;
117 inline static int in_parallel() {
return false; }
125 static void impl_static_fence(
const std::string& name) {
126 Kokkos::Tools::Experimental::Impl::profile_fence_event<Kokkos::Serial>(
128 Kokkos::Tools::Experimental::SpecialSynchronizationCases::
129 GlobalDeviceSynchronization,
131 Kokkos::memory_fence();
134 void fence(
const std::string& name =
135 "Kokkos::Serial::fence: Unnamed Instance Fence")
const {
136 Kokkos::Tools::Experimental::Impl::profile_fence_event<Kokkos::Serial>(
137 name, Kokkos::Tools::Experimental::Impl::DirectFenceIDHandle{1},
139 Kokkos::memory_fence();
143 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
144 static int concurrency() {
return 1; }
146 int concurrency()
const {
return 1; }
150 void print_configuration(std::ostream& os,
bool verbose =
false)
const;
152 static void impl_initialize(InitializationSettings
const&);
154 static bool impl_is_initialized();
157 static void impl_finalize();
161 inline static int impl_thread_pool_size(
int = 0) {
return 1; }
162 KOKKOS_INLINE_FUNCTION
static int impl_thread_pool_rank() {
return 0; }
166 KOKKOS_INLINE_FUNCTION
static unsigned impl_hardware_thread_id() {
167 return impl_thread_pool_rank();
169 inline static unsigned impl_max_hardware_threads() {
170 return impl_thread_pool_size(0);
173 uint32_t impl_instance_id() const noexcept {
return 1; }
175 static const char* name();
177 Impl::SerialInternal* impl_internal_space_instance()
const {
178 return m_space_instance.get();
182 Kokkos::Impl::HostSharedPtr<Impl::SerialInternal> m_space_instance;
183 friend bool operator==(Serial
const& lhs, Serial
const& rhs) {
184 return lhs.impl_internal_space_instance() ==
185 rhs.impl_internal_space_instance();
187 friend bool operator!=(Serial
const& lhs, Serial
const& rhs) {
188 return !(lhs == rhs);
194 namespace Experimental {
196 struct DeviceTypeTraits<Serial> {
197 static constexpr DeviceType
id = DeviceType::Serial;
198 static int device_id(
const Serial&) {
return 0; }
213 struct DummyExecutionSpace;
214 template <
class DT,
class... DP>
216 std::conditional_t<!std::is_same<Serial, DefaultHostExecutionSpace>::value,
217 Serial, DummyExecutionSpace>,
218 DT, DP...> :
public ZeroMemset<DefaultHostExecutionSpace, DT, DP...> {
219 using Base = ZeroMemset<DefaultHostExecutionSpace, DT, DP...>;
222 ZeroMemset(
const Serial&,
const View<DT, DP...>& dst,
223 typename View<DT, DP...>::const_value_type& value)
224 : Base(dst, value) {}
228 struct MemorySpaceAccess<Kokkos::Serial::memory_space,
229 Kokkos::Serial::scratch_memory_space> {
230 enum :
bool { assignable =
false };
231 enum :
bool { accessible =
true };
232 enum :
bool { deepcopy =
false };
238 #include <Serial/Kokkos_Serial_Parallel_Range.hpp>
239 #include <Serial/Kokkos_Serial_Parallel_MDRange.hpp>
240 #include <Serial/Kokkos_Serial_Parallel_Team.hpp>
241 #include <Serial/Kokkos_Serial_Task.hpp>
242 #include <Serial/Kokkos_Serial_UniqueToken.hpp>
244 #endif // defined( KOKKOS_ENABLE_SERIAL )
Memory management for host memory.