Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 Christian R. Trott (crtrott@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 #include <impl/Kokkos_Utilities.hpp>
53 
54 #include <Kokkos_UniqueToken.hpp>
55 #include <Kokkos_MasterLock.hpp>
56 
57 //----------------------------------------------------------------------------
58 // Have assumed a 64bit build (8byte pointers) throughout the code base.
59 
60 static_assert( sizeof(void*) == 8
61  , "Kokkos assumes 64-bit build; i.e., 8-byte pointers" );
62 
63 //----------------------------------------------------------------------------
64 
65 namespace Kokkos {
66 
67 struct AUTO_t {
68  KOKKOS_INLINE_FUNCTION
69  constexpr const AUTO_t & operator()() const { return *this; }
70 };
71 
72 namespace {
74 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
75 }
76 
77 struct InvalidType {};
78 
79 } // namespace Kokkos
80 
81 //----------------------------------------------------------------------------
82 // Forward declarations for class inter-relationships
83 
84 namespace Kokkos {
85 
86 class HostSpace;
87 class AnonymousSpace;
88 
89 #ifdef KOKKOS_ENABLE_HBWSPACE
90 namespace Experimental {
91 class HBWSpace;
92 }
93 #endif
94 
95 #if defined( KOKKOS_ENABLE_SERIAL )
96 class Serial;
97 #endif
98 
99 #if defined( KOKKOS_ENABLE_QTHREADS )
100 class Qthreads;
101 #endif
102 
103 #if defined( KOKKOS_ENABLE_THREADS )
104 class Threads;
105 #endif
106 
107 #if defined( KOKKOS_ENABLE_OPENMP )
108 class OpenMP;
109 #endif
110 
111 #if defined( KOKKOS_ENABLE_OPENMPTARGET )
112 namespace Experimental {
113 class OpenMPTarget;
114 class OpenMPTargetSpace;
115 }
116 #endif
117 
118 
119 #if defined( KOKKOS_ENABLE_CUDA )
120 class CudaSpace;
121 class CudaUVMSpace;
122 class CudaHostPinnedSpace;
123 class Cuda;
124 #endif
125 
126 #if defined( KOKKOS_ENABLE_ROCM )
127 namespace Experimental {
128 class ROCmSpace ;
129 class ROCm ;
130 }
131 #endif
132 
133 template<class ExecutionSpace, class MemorySpace>
134 struct Device;
135 
136 } // namespace Kokkos
137 
138 //----------------------------------------------------------------------------
139 // Set the default execution space.
140 
144 
145 namespace Kokkos {
146 
147 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA )
148  typedef Cuda DefaultExecutionSpace;
149 #elif defined ( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET )
150  typedef Experimental::OpenMPTarget DefaultExecutionSpace ;
151 #elif defined ( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_ROCM )
152  typedef Experimental::ROCm DefaultExecutionSpace ;
153 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
154  typedef OpenMP DefaultExecutionSpace;
155 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
156  typedef Threads DefaultExecutionSpace;
157 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
158 // typedef Qthreads DefaultExecutionSpace;
159 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
160  typedef Serial DefaultExecutionSpace;
161 #else
162 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::Experimental::OpenMPTarget, Kokkos::OpenMP, Kokkos::Threads, Kokkos::Qthreads, or Kokkos::Serial."
163 #endif
164 
165 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
166  typedef OpenMP DefaultHostExecutionSpace;
167 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
168  typedef Threads DefaultHostExecutionSpace;
169 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
170 // typedef Qthreads DefaultHostExecutionSpace;
171 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
172  typedef Serial DefaultHostExecutionSpace;
173 #elif defined( KOKKOS_ENABLE_OPENMP )
174  typedef OpenMP DefaultHostExecutionSpace;
175 #elif defined( KOKKOS_ENABLE_THREADS )
176  typedef Threads DefaultHostExecutionSpace;
177 //#elif defined( KOKKOS_ENABLE_QTHREADS )
178 // typedef Qthreads DefaultHostExecutionSpace;
179 #elif defined( KOKKOS_ENABLE_SERIAL )
180  typedef Serial DefaultHostExecutionSpace;
181 #else
182 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::OpenMP, Kokkos::Threads, Kokkos::Qthreads, or Kokkos::Serial."
183 #endif
184 
185 } // namespace Kokkos
186 
187 //----------------------------------------------------------------------------
188 // Detect the active execution space and define its memory space.
189 // This is used to verify whether a running kernel can access
190 // a given memory space.
191 
192 namespace Kokkos {
193 
194 namespace Impl {
195 
196 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA ) && defined( KOKKOS_ENABLE_CUDA )
197 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace;
198 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_ROCM_GPU )
199 typedef Kokkos::HostSpace ActiveExecutionMemorySpace ;
200 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
201 typedef Kokkos::HostSpace ActiveExecutionMemorySpace;
202 #else
203 typedef void ActiveExecutionMemorySpace;
204 #endif
205 
206 template< class ActiveSpace, class MemorySpace >
207 struct VerifyExecutionCanAccessMemorySpace {
208  enum {value = 0};
209 };
210 
211 template< class Space >
212 struct VerifyExecutionCanAccessMemorySpace< Space, Space >
213 {
214  enum {value = 1};
215  KOKKOS_INLINE_FUNCTION static void verify(void) {}
216  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
217 };
218 } // namespace Impl
219 
220 } // namespace Kokkos
221 
222 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA( DATA_SPACE, DATA_PTR ) \
223  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
224  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify( DATA_PTR )
225 
226 #define KOKKOS_RESTRICT_EXECUTION_TO_( DATA_SPACE ) \
227  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
228  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify()
229 
230 //----------------------------------------------------------------------------
231 
232 namespace Kokkos {
233  void fence();
234 }
235 
236 //----------------------------------------------------------------------------
237 
238 namespace Kokkos {
239 
240 namespace Impl {
241 
242 template< class DstSpace, class SrcSpace, class ExecutionSpace = typename DstSpace::execution_space >
243 struct DeepCopy;
244 
245 template<class ViewType, class Layout, class ExecSpace, int Rank, typename iType>
246 struct ViewFillETIAvail;
247 
248 template<class ViewType, class Layout = typename ViewType::array_layout,
249  class ExecSpace = typename ViewType::execution_space, int Rank = ViewType::Rank, typename iType = int64_t,
250  bool EtiAvail = ViewFillETIAvail<ViewType,Layout,ExecSpace,Rank,iType>::value>
251 struct ViewFill;
252 
253 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace, int Rank, typename iType>
254 struct ViewCopyETIAvail;
255 
256 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace, int Rank, typename iType,
257  bool EtiAvail = ViewCopyETIAvail<ViewTypeA,ViewTypeB,Layout,ExecSpace,Rank,iType>::value>
258 struct ViewCopy;
259 
260 template< class Functor
261  , class Policy
262  , class EnableFunctor = void
263  , class EnablePolicy = void
264  >
266 
267 //----------------------------------------------------------------------------
274 template< class FunctorType, class ExecPolicy, class ExecutionSpace =
275  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
276  > class ParallelFor;
277 
283 template< class FunctorType, class ExecPolicy, class ReducerType = InvalidType, class ExecutionSpace =
284  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
285  > class ParallelReduce;
286 
293 template< class FunctorType, class ExecPolicy, class ExecutionSapce =
294  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
295  > class ParallelScan;
296 
297 template< class FunctorType, class ExecPolicy, class ReturnType = InvalidType, class ExecutionSapce =
298  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
299  > class ParallelScanWithTotal;
300 
301 } // namespace Impl
302 
303 template<class ScalarType , class Space = HostSpace> struct Sum;
304 template<class ScalarType , class Space = HostSpace> struct Prod;
305 template<class ScalarType , class Space = HostSpace> struct Min;
306 template<class ScalarType , class Space = HostSpace> struct Max;
307 template<class ScalarType , class Space = HostSpace> struct MinMax;
308 template<class ScalarType , class Index, class Space = HostSpace> struct MinLoc;
309 template<class ScalarType , class Index, class Space = HostSpace> struct MaxLoc;
310 template<class ScalarType , class Index, class Space = HostSpace> struct MinMaxLoc;
311 template<class ScalarType , class Space = HostSpace> struct BAnd;
312 template<class ScalarType , class Space = HostSpace> struct BOr;
313 template<class ScalarType , class Space = HostSpace> struct LAnd;
314 template<class ScalarType , class Space = HostSpace> struct LOr;
315 
316 
317 } // namespace Kokkos
318 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
319 namespace Kokkos{
320  template<class ScalarType> struct MinMaxScalar;
321  template<class ScalarType, class Index> struct MinMaxLocScalar;
322  template<class ScalarType, class Index> struct ValLocScalar;
323 
324  namespace Experimental {
325  using Kokkos::Sum;
326  using Kokkos::Prod;
327  using Kokkos::Min;
328  using Kokkos::Max;
329  using Kokkos::MinMax;
330  using Kokkos::MinLoc;
331  using Kokkos::MaxLoc;
332  using Kokkos::MinMaxLoc;
333  using Kokkos::BAnd;
334  using Kokkos::BOr;
335  using Kokkos::LAnd;
336  using Kokkos::LOr;
337  using Kokkos::MinMaxScalar;
338  using Kokkos::MinMaxLocScalar;
339  using Kokkos::ValLocScalar;
340  }
341 }
342 #endif
343 
344 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
345 
Implementation detail of parallel_scan.
Memory management for host memory.
Implementation of the ParallelFor operator that has a partial specialization for the device...
ReturnType
Given a Functor and Execution Policy query an execution space.
Implementation detail of parallel_reduce.