Kokkos Core Kernels Package  Version of the Day
Kokkos_Core_fwd.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 H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_CORE_FWD_HPP
45 #define KOKKOS_CORE_FWD_HPP
46 
47 //----------------------------------------------------------------------------
48 // Kokkos_Macros.hpp does introspection on configuration options
49 // and compiler environment then sets a collection of #define macros.
50 
51 #include <Kokkos_Macros.hpp>
52 
53 //----------------------------------------------------------------------------
54 //----------------------------------------------------------------------------
55 
56 namespace Kokkos {
57 
58 struct AUTO_t {
59  KOKKOS_INLINE_FUNCTION
60  constexpr const AUTO_t & operator()() const { return *this ; }
61 };
62 
63 namespace {
65 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
66 }
67 }
68 
69 //----------------------------------------------------------------------------
70 //----------------------------------------------------------------------------
71 // Forward declarations for class inter-relationships
72 
73 namespace Kokkos {
74 
75 class HostSpace ;
76 
77 #ifdef KOKKOS_HAVE_HBWSPACE
78 namespace Experimental {
79 class HBWSpace ;
80 }
81 #endif
82 
83 #if defined( KOKKOS_HAVE_SERIAL )
84 class Serial ;
85 #endif // defined( KOKKOS_HAVE_SERIAL )
86 
87 #if defined( KOKKOS_HAVE_PTHREAD )
88 class Threads ;
89 #endif
90 
91 #if defined( KOKKOS_HAVE_OPENMP )
92 class OpenMP ;
93 #endif
94 
95 #if defined( KOKKOS_HAVE_CUDA )
96 class CudaSpace ;
97 class CudaUVMSpace ;
98 class CudaHostPinnedSpace ;
99 class Cuda ;
100 #endif
101 
102 template<class ExecutionSpace, class MemorySpace>
103 struct Device;
104 } // namespace Kokkos
105 
106 //----------------------------------------------------------------------------
107 //----------------------------------------------------------------------------
108 // Set the default execution space.
109 
113 
114 namespace Kokkos {
115 
116 #if defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_CUDA )
117  typedef Cuda DefaultExecutionSpace ;
118 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP )
119  typedef OpenMP DefaultExecutionSpace ;
120 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS )
121  typedef Threads DefaultExecutionSpace ;
122 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL )
123  typedef Serial DefaultExecutionSpace ;
124 #else
125 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::OpenMP, Kokkos::Serial, or Kokkos::Threads."
126 #endif
127 
128 #if defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP )
129  typedef OpenMP DefaultHostExecutionSpace ;
130 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS )
131  typedef Threads DefaultHostExecutionSpace ;
132 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL )
133  typedef Serial DefaultHostExecutionSpace ;
134 #elif defined ( KOKKOS_HAVE_OPENMP )
135  typedef OpenMP DefaultHostExecutionSpace ;
136 #elif defined ( KOKKOS_HAVE_PTHREAD )
137  typedef Threads DefaultHostExecutionSpace ;
138 #elif defined ( KOKKOS_HAVE_SERIAL )
139  typedef Serial DefaultHostExecutionSpace ;
140 #else
141 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::OpenMP, Kokkos::Serial, or Kokkos::Threads."
142 #endif
143 
144 } // namespace Kokkos
145 
146 //----------------------------------------------------------------------------
147 //----------------------------------------------------------------------------
148 // Detect the active execution space and define its memory space.
149 // This is used to verify whether a running kernel can access
150 // a given memory space.
151 
152 namespace Kokkos {
153 namespace Impl {
154 
155 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA ) && defined (KOKKOS_HAVE_CUDA)
156 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace ;
157 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
158 typedef Kokkos::HostSpace ActiveExecutionMemorySpace ;
159 #else
160 typedef void ActiveExecutionMemorySpace ;
161 #endif
162 
163 template< class ActiveSpace , class MemorySpace >
164 struct VerifyExecutionCanAccessMemorySpace {
165  enum {value = 0};
166 };
167 
168 template< class Space >
169 struct VerifyExecutionCanAccessMemorySpace< Space , Space >
170 {
171  enum {value = 1};
172  KOKKOS_INLINE_FUNCTION static void verify(void) {}
173  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
174 };
175 
176 } // namespace Impl
177 } // namespace Kokkos
178 
179 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA( DATA_SPACE , DATA_PTR ) \
180  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
181  Kokkos::Impl::ActiveExecutionMemorySpace , DATA_SPACE >::verify( DATA_PTR )
182 
183 #define KOKKOS_RESTRICT_EXECUTION_TO_( DATA_SPACE ) \
184  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
185  Kokkos::Impl::ActiveExecutionMemorySpace , DATA_SPACE >::verify()
186 
187 //----------------------------------------------------------------------------
188 //----------------------------------------------------------------------------
189 
190 namespace Kokkos {
191  void fence();
192 }
193 
194 //----------------------------------------------------------------------------
195 //----------------------------------------------------------------------------
196 
197 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
198 
Memory space for main process and CPU execution spaces.
Memory management for host memory.