Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_Threads.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_THREADS_HPP
45 #define KOKKOS_THREADS_HPP
46 
47 #include <Kokkos_Macros.hpp>
48 #if defined( KOKKOS_ENABLE_THREADS )
49 
50 #include <Kokkos_Core_fwd.hpp>
51 
52 #include <cstddef>
53 #include <iosfwd>
54 #include <Kokkos_HostSpace.hpp>
55 #include <Kokkos_ScratchSpace.hpp>
56 #include <Kokkos_Layout.hpp>
57 #include <Kokkos_MemoryTraits.hpp>
58 #include <impl/Kokkos_Tags.hpp>
59 
60 /*--------------------------------------------------------------------------*/
61 
62 namespace Kokkos {
63 namespace Impl {
64 class ThreadsExec ;
65 } // namespace Impl
66 } // namespace Kokkos
67 
68 /*--------------------------------------------------------------------------*/
69 
70 namespace Kokkos {
71 
73 class Threads {
74 public:
76 
77  typedef Threads execution_space ;
79  typedef Kokkos::HostSpace memory_space ;
80 
82  typedef Kokkos::Device<execution_space,memory_space> device_type;
83 
84  typedef Kokkos::LayoutRight array_layout ;
85  typedef memory_space::size_type size_type ;
86 
87  typedef ScratchMemorySpace< Threads > scratch_memory_space ;
88 
89 
91  /*------------------------------------------------------------------------*/
93 
94 
97  static int in_parallel();
98 
100  static void print_configuration( std::ostream & , const bool detail = false );
101 
108  static void impl_static_fence();
109 
110  #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
111  static void fence();
112  #else
113  void fence() const;
114  #endif
115 
117  static int concurrency();
118 
119 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
120  static bool sleep();
121 
122  static bool wake();
123 
124  static void finalize();
125 
126  static void initialize( unsigned threads_count = 0 ,
127  unsigned use_numa_count = 0 ,
128  unsigned use_cores_per_numa = 0 ,
129  bool allow_asynchronous_threadpool = false );
130 
131  static int is_initialized();
132 
133  static Threads & instance( int = 0 );
134 
135  //----------------------------------------
136 
137  static int thread_pool_size( int depth = 0 );
138 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
139  static int thread_pool_rank();
140 #else
141  KOKKOS_INLINE_FUNCTION static int thread_pool_rank() { return 0 ; }
142 #endif
143 
144  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
145  KOKKOS_INLINE_FUNCTION static unsigned hardware_thread_id() { return thread_pool_rank(); }
146 #else
147  static void impl_finalize();
151 
153  /*------------------------------------------------------------------------*/
154  /*------------------------------------------------------------------------*/
156 
157 
175  static void impl_initialize( unsigned threads_count = 0 ,
176  unsigned use_numa_count = 0 ,
177  unsigned use_cores_per_numa = 0 ,
178  bool allow_asynchronous_threadpool = false );
179 
180  static int impl_is_initialized();
181 
182  static Threads & impl_instance( int = 0 );
183 
184  //----------------------------------------
185 
186  static int impl_thread_pool_size( int depth = 0 );
187 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
188  static int impl_thread_pool_rank();
189 #else
190  KOKKOS_INLINE_FUNCTION static int impl_thread_pool_rank() { return 0 ; }
191 #endif
192 
193  inline static unsigned impl_max_hardware_threads() { return impl_thread_pool_size(0); }
194  KOKKOS_INLINE_FUNCTION static unsigned impl_hardware_thread_id() { return impl_thread_pool_rank(); }
195 #endif
196 
197  static const char* name();
199  //----------------------------------------
200 };
201 
202 } // namespace Kokkos
203 
204 /*--------------------------------------------------------------------------*/
205 
206 namespace Kokkos {
207 namespace Impl {
208 
209 template<>
210 struct MemorySpaceAccess
211  < Kokkos::Threads::memory_space
212  , Kokkos::Threads::scratch_memory_space
213  >
214 {
215  enum { assignable = false };
216  enum { accessible = true };
217  enum { deepcopy = false };
218 };
219 
220 template<>
221 struct VerifyExecutionCanAccessMemorySpace
222  < Kokkos::Threads::memory_space
223  , Kokkos::Threads::scratch_memory_space
224  >
225 {
226  enum { value = true };
227  inline static void verify( void ) { }
228  inline static void verify( const void * ) { }
229 };
230 
231 } // namespace Impl
232 } // namespace Kokkos
233 
234 /*--------------------------------------------------------------------------*/
235 
236 #include <Kokkos_ExecPolicy.hpp>
237 #include <Kokkos_Parallel.hpp>
238 #include <Threads/Kokkos_ThreadsExec.hpp>
239 #include <Threads/Kokkos_ThreadsTeam.hpp>
240 #include <Threads/Kokkos_Threads_Parallel.hpp>
241 
242 #include <KokkosExp_MDRangePolicy.hpp>
243 
244 //----------------------------------------------------------------------------
245 //----------------------------------------------------------------------------
246 
247 #endif /* #if defined( KOKKOS_ENABLE_THREADS ) */
248 #endif /* #define KOKKOS_THREADS_HPP */
249 
void print_configuration(std::ostream &, const bool detail=false)
Print &quot;Bill of Materials&quot;.
Memory management for host memory.
Memory layout tag indicating right-to-left (C or lexigraphical scheme) striding of multi-indices...
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.