Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_OpenMPTarget.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_OPENMPTARGET_HPP
45 #define KOKKOS_OPENMPTARGET_HPP
46 
47 #include <Kokkos_Core_fwd.hpp>
48 
49 #if defined( KOKKOS_ENABLE_OPENMPTARGET ) && defined( _OPENMP )
50 
51 #include <omp.h>
52 
53 #include <cstddef>
54 #include <iosfwd>
55 #include <Kokkos_OpenMPTargetSpace.hpp>
56 #include <Kokkos_ScratchSpace.hpp>
57 #include <Kokkos_Parallel.hpp>
58 #include <Kokkos_TaskPolicy.hpp>
59 #include <Kokkos_Layout.hpp>
60 #include <impl/Kokkos_Tags.hpp>
61 
62 #include <KokkosExp_MDRangePolicy.hpp>
63 /*--------------------------------------------------------------------------*/
64 
65 namespace Kokkos {
66 namespace Experimental {
69 class OpenMPTarget {
70 public:
71  //------------------------------------
73 
74 
76  typedef OpenMPTarget execution_space ;
77  typedef OpenMPTargetSpace memory_space ;
79  typedef Kokkos::Device<execution_space,memory_space> device_type;
80 
81  typedef LayoutLeft array_layout ;
82  typedef memory_space::size_type size_type ;
83 
84  typedef ScratchMemorySpace< OpenMPTarget > scratch_memory_space ;
85 
87  //------------------------------------
89 
90 
91  inline static bool in_parallel() { return omp_in_parallel(); }
92 
94  static bool sleep();
95 
97  static bool wake();
98 
100  static void fence() {}
101 
103  static void print_configuration( std::ostream & , const bool detail = false );
104 
106  static void finalize();
107 
117  static void initialize( unsigned thread_count = 0 ,
118  unsigned use_numa_count = 0 ,
119  unsigned use_cores_per_numa = 0 );
120 
121  static int is_initialized();
122 
124  static int concurrency();
125 
127  //------------------------------------
135  inline static int thread_pool_size( int depth = 0 );
136 
138  KOKKOS_INLINE_FUNCTION static int thread_pool_rank();
139 
140  //------------------------------------
141 
142  inline static unsigned max_hardware_threads() { return thread_pool_size(0); }
143 
144  KOKKOS_INLINE_FUNCTION static
145  unsigned hardware_thread_id() { return thread_pool_rank(); }
146 
147  static const char* name();
148 private:
149  static bool m_is_initialized;
150 };
151 } // namespace Experimental
152 } // namespace Kokkos
153 
154 /*--------------------------------------------------------------------------*/
155 /*--------------------------------------------------------------------------*/
156 
157 namespace Kokkos {
158 namespace Impl {
159 
160 template<>
161 struct VerifyExecutionCanAccessMemorySpace
162  < Kokkos::Experimental::OpenMPTarget::memory_space
163  , Kokkos::Experimental::OpenMPTarget::scratch_memory_space
164  >
165 {
166  enum { value = true };
167  inline static void verify( void ) { }
168  inline static void verify( const void * ) { }
169 };
170 
171 } // namespace Impl
172 } // namespace Kokkos
173 
174 /*--------------------------------------------------------------------------*/
175 /*--------------------------------------------------------------------------*/
176 
177 #include <OpenMPTarget/Kokkos_OpenMPTarget_Exec.hpp>
178 #include <OpenMPTarget/Kokkos_OpenMPTarget_Parallel.hpp>
179 #include <OpenMPTarget/Kokkos_OpenMPTarget_Task.hpp>
180 
181 /*--------------------------------------------------------------------------*/
182 
183 #endif /* #if defined( KOKKOS_ENABLE_OPENMPTARGET ) && defined( _OPENMP ) */
184 #endif /* #ifndef KOKKOS_OPENMPTARGET_HPP */
185 
186 
void print_configuration(std::ostream &, const bool detail=false)
Print &quot;Bill of Materials&quot;.
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.