Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Kokkos_Threads.hpp
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
17#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18#include <Kokkos_Macros.hpp>
19static_assert(false,
20 "Including non-public Kokkos header files is not allowed.");
21#endif
22#ifndef KOKKOS_THREADS_HPP
23#define KOKKOS_THREADS_HPP
24
25#include <Kokkos_Macros.hpp>
26#if defined(KOKKOS_ENABLE_THREADS)
27
28#include <Kokkos_Core_fwd.hpp>
29
30#include <cstddef>
31#include <iosfwd>
32#include <Kokkos_HostSpace.hpp>
33#include <Kokkos_ScratchSpace.hpp>
34#include <Kokkos_Layout.hpp>
35#include <Kokkos_MemoryTraits.hpp>
36#include <impl/Kokkos_Profiling_Interface.hpp>
37#include <impl/Kokkos_InitializationSettings.hpp>
38
39/*--------------------------------------------------------------------------*/
40
41namespace Kokkos {
42namespace Impl {
43class ThreadsExec;
44enum class fence_is_static { yes, no };
45} // namespace Impl
46} // namespace Kokkos
47
48/*--------------------------------------------------------------------------*/
49
50namespace Kokkos {
51
53class Threads {
54 public:
56
57
58 using execution_space = Threads;
59 using memory_space = Kokkos::HostSpace;
60
62 using device_type = Kokkos::Device<execution_space, memory_space>;
63
64 using array_layout = Kokkos::LayoutRight;
65 using size_type = memory_space::size_type;
66
67 using scratch_memory_space = ScratchMemorySpace<Threads>;
68
70 /*------------------------------------------------------------------------*/
72
73
76 static int in_parallel();
77
79 void print_configuration(std::ostream& os, bool verbose = false) const;
80
87 static void impl_static_fence(const std::string& name);
88
89 void fence(const std::string& name =
90 "Kokkos::Threads::fence: Unnamed Instance Fence") const;
91
93#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
94 static int concurrency();
95#else
96 int concurrency() const;
97#endif
98
102 static void impl_finalize();
103
105 /*------------------------------------------------------------------------*/
106 /*------------------------------------------------------------------------*/
108
109
110 static void impl_initialize(InitializationSettings const&);
111
112 static int impl_is_initialized();
113
114 static Threads& impl_instance(int = 0);
115
116 //----------------------------------------
117
118 static int impl_thread_pool_size(int depth = 0);
119
120 static int impl_thread_pool_rank_host();
121
122 static KOKKOS_FUNCTION int impl_thread_pool_rank() {
123 KOKKOS_IF_ON_HOST((return impl_thread_pool_rank_host();))
124
125 KOKKOS_IF_ON_DEVICE((return 0;))
126 }
127
128 inline static unsigned impl_max_hardware_threads() {
129 return impl_thread_pool_size(0);
130 }
131 KOKKOS_INLINE_FUNCTION static unsigned impl_hardware_thread_id() {
132 return impl_thread_pool_rank();
133 }
134
135 uint32_t impl_instance_id() const noexcept { return 1; }
136
137 static const char* name();
139 //----------------------------------------
140 private:
141 friend bool operator==(Threads const&, Threads const&) { return true; }
142 friend bool operator!=(Threads const&, Threads const&) { return false; }
143};
144
145namespace Tools {
146namespace Experimental {
147template <>
148struct DeviceTypeTraits<Threads> {
149 static constexpr DeviceType id = DeviceType::Threads;
150 static int device_id(const Threads&) { return 0; }
151};
152} // namespace Experimental
153} // namespace Tools
154} // namespace Kokkos
155
156/*--------------------------------------------------------------------------*/
157
158namespace Kokkos {
159namespace Impl {
160
161template <>
162struct MemorySpaceAccess<Kokkos::Threads::memory_space,
163 Kokkos::Threads::scratch_memory_space> {
164 enum : bool { assignable = false };
165 enum : bool { accessible = true };
166 enum : bool { deepcopy = false };
167};
168
169} // namespace Impl
170} // namespace Kokkos
171
172/*--------------------------------------------------------------------------*/
173
174#include <Kokkos_ExecPolicy.hpp>
175#include <Kokkos_Parallel.hpp>
176#include <Threads/Kokkos_ThreadsExec.hpp>
177#include <Threads/Kokkos_ThreadsTeam.hpp>
178#include <Threads/Kokkos_Threads_Parallel_Range.hpp>
179#include <Threads/Kokkos_Threads_Parallel_MDRange.hpp>
180#include <Threads/Kokkos_Threads_Parallel_Team.hpp>
181#include <Threads/Kokkos_Threads_UniqueToken.hpp>
182
183#include <KokkosExp_MDRangePolicy.hpp>
184
185//----------------------------------------------------------------------------
186//----------------------------------------------------------------------------
187
188#endif /* #if defined( KOKKOS_ENABLE_THREADS ) */
189#endif /* #define KOKKOS_THREADS_HPP */
Declaration of various MemoryLayout options.
Declaration of parallel operators.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices.