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_HPX )
104 namespace Experimental {
105 class HPX;
106 }
107 #endif
108 
109 #if defined( KOKKOS_ENABLE_THREADS )
110 class Threads;
111 #endif
112 
113 #if defined( KOKKOS_ENABLE_OPENMP )
114 class OpenMP;
115 #endif
116 
117 #if defined( KOKKOS_ENABLE_OPENMPTARGET )
118 namespace Experimental {
119 class OpenMPTarget;
120 class OpenMPTargetSpace;
121 }
122 #endif
123 
124 
125 #if defined( KOKKOS_ENABLE_CUDA )
126 class CudaSpace;
127 class CudaUVMSpace;
128 class CudaHostPinnedSpace;
129 class Cuda;
130 #endif
131 
132 #if defined( KOKKOS_ENABLE_ROCM )
133 namespace Experimental {
134 class ROCmSpace ;
135 class ROCm ;
136 }
137 #endif
138 
139 template<class ExecutionSpace, class MemorySpace>
140 struct Device;
141 
142 } // namespace Kokkos
143 
144 //----------------------------------------------------------------------------
145 // Set the default execution space.
146 
150 
151 namespace Kokkos {
152 
153 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA )
154  typedef Cuda DefaultExecutionSpace;
155 #elif defined ( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET )
156  typedef Experimental::OpenMPTarget DefaultExecutionSpace ;
157 #elif defined ( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_ROCM )
158  typedef Experimental::ROCm DefaultExecutionSpace ;
159 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
160  typedef OpenMP DefaultExecutionSpace;
161 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
162  typedef Threads DefaultExecutionSpace;
163 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
164 // typedef Qthreads DefaultExecutionSpace;
165 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX )
166  typedef Kokkos::Experimental::HPX DefaultExecutionSpace;
167 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
168  typedef Serial DefaultExecutionSpace;
169 #else
170 # 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."
171 #endif
172 
173 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
174  typedef OpenMP DefaultHostExecutionSpace;
175 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
176  typedef Threads DefaultHostExecutionSpace;
177 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
178 // typedef Qthreads DefaultHostExecutionSpace;
179 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
180  typedef Serial DefaultHostExecutionSpace;
181 #elif defined( KOKKOS_ENABLE_OPENMP )
182  typedef OpenMP DefaultHostExecutionSpace;
183 #elif defined( KOKKOS_ENABLE_THREADS )
184  typedef Threads DefaultHostExecutionSpace;
185 //#elif defined( KOKKOS_ENABLE_QTHREADS )
186 // typedef Qthreads DefaultHostExecutionSpace;
187 #elif defined( KOKKOS_ENABLE_HPX )
188  typedef Kokkos::Experimental::HPX DefaultHostExecutionSpace;
189 #elif defined( KOKKOS_ENABLE_SERIAL )
190  typedef Serial DefaultHostExecutionSpace;
191 #else
192 # 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."
193 #endif
194 
195 } // namespace Kokkos
196 
197 //----------------------------------------------------------------------------
198 // Detect the active execution space and define its memory space.
199 // This is used to verify whether a running kernel can access
200 // a given memory space.
201 
202 namespace Kokkos {
203 
204 namespace Impl {
205 
206 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA ) && defined( KOKKOS_ENABLE_CUDA )
207 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace;
208 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_ROCM_GPU )
209 typedef Kokkos::HostSpace ActiveExecutionMemorySpace ;
210 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
211 typedef Kokkos::HostSpace ActiveExecutionMemorySpace;
212 #else
213 typedef void ActiveExecutionMemorySpace;
214 #endif
215 
216 template< class ActiveSpace, class MemorySpace >
217 struct VerifyExecutionCanAccessMemorySpace {
218  enum {value = 0};
219 };
220 
221 template< class Space >
222 struct VerifyExecutionCanAccessMemorySpace< Space, Space >
223 {
224  enum {value = 1};
225  KOKKOS_INLINE_FUNCTION static void verify(void) {}
226  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
227 };
228 } // namespace Impl
229 
230 } // namespace Kokkos
231 
232 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA( DATA_SPACE, DATA_PTR ) \
233  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
234  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify( DATA_PTR )
235 
236 #define KOKKOS_RESTRICT_EXECUTION_TO_( DATA_SPACE ) \
237  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
238  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify()
239 
240 //----------------------------------------------------------------------------
241 
242 namespace Kokkos {
243  void fence();
244 }
245 
246 //----------------------------------------------------------------------------
247 
248 namespace Kokkos {
249 
250 namespace Impl {
251 
252 template< class DstSpace, class SrcSpace, class ExecutionSpace = typename DstSpace::execution_space >
253 struct DeepCopy;
254 
255 template<class ViewType, class Layout, class ExecSpace, int Rank, typename iType>
256 struct ViewFillETIAvail;
257 
258 template<class ViewType, class Layout = typename ViewType::array_layout,
259  class ExecSpace = typename ViewType::execution_space, int Rank = ViewType::Rank, typename iType = int64_t,
260  bool EtiAvail = ViewFillETIAvail<ViewType,Layout,ExecSpace,Rank,iType>::value>
261 struct ViewFill;
262 
263 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace, int Rank, typename iType>
264 struct ViewCopyETIAvail;
265 
266 template<class ViewTypeA,class ViewTypeB, class Layout, class ExecSpace, int Rank, typename iType,
267  bool EtiAvail = ViewCopyETIAvail<ViewTypeA,ViewTypeB,Layout,ExecSpace,Rank,iType>::value>
268 struct ViewCopy;
269 
270 template< class Functor
271  , class Policy
272  , class EnableFunctor = void
273  , class EnablePolicy = void
274  >
276 
277 //----------------------------------------------------------------------------
284 template< class FunctorType, class ExecPolicy, class ExecutionSpace =
285  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
286  > class ParallelFor;
287 
293 template< class FunctorType, class ExecPolicy, class ReducerType = InvalidType, class ExecutionSpace =
294  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
295  > class ParallelReduce;
296 
303 template< class FunctorType, class ExecPolicy, class ExecutionSapce =
304  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
305  > class ParallelScan;
306 
307 template< class FunctorType, class ExecPolicy, class ReturnType = InvalidType, class ExecutionSapce =
308  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
309  > class ParallelScanWithTotal;
310 
311 } // namespace Impl
312 
313 template<class ScalarType , class Space = HostSpace> struct Sum;
314 template<class ScalarType , class Space = HostSpace> struct Prod;
315 template<class ScalarType , class Space = HostSpace> struct Min;
316 template<class ScalarType , class Space = HostSpace> struct Max;
317 template<class ScalarType , class Space = HostSpace> struct MinMax;
318 template<class ScalarType , class Index, class Space = HostSpace> struct MinLoc;
319 template<class ScalarType , class Index, class Space = HostSpace> struct MaxLoc;
320 template<class ScalarType , class Index, class Space = HostSpace> struct MinMaxLoc;
321 template<class ScalarType , class Space = HostSpace> struct BAnd;
322 template<class ScalarType , class Space = HostSpace> struct BOr;
323 template<class ScalarType , class Space = HostSpace> struct LAnd;
324 template<class ScalarType , class Space = HostSpace> struct LOr;
325 
326 
327 } // namespace Kokkos
328 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
329 namespace Kokkos{
330  template<class ScalarType> struct MinMaxScalar;
331  template<class ScalarType, class Index> struct MinMaxLocScalar;
332  template<class ScalarType, class Index> struct ValLocScalar;
333 
334  namespace Experimental {
335  using Kokkos::Sum;
336  using Kokkos::Prod;
337  using Kokkos::Min;
338  using Kokkos::Max;
339  using Kokkos::MinMax;
340  using Kokkos::MinLoc;
341  using Kokkos::MaxLoc;
342  using Kokkos::MinMaxLoc;
343  using Kokkos::BAnd;
344  using Kokkos::BOr;
345  using Kokkos::LAnd;
346  using Kokkos::LOr;
347  using Kokkos::MinMaxScalar;
348  using Kokkos::MinMaxLocScalar;
349  using Kokkos::ValLocScalar;
350  }
351 }
352 #endif
353 
354 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
355 
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.