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. 3.0
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44 
45 #ifndef KOKKOS_CORE_FWD_HPP
46 #define KOKKOS_CORE_FWD_HPP
47 
48 //----------------------------------------------------------------------------
49 // Kokkos_Macros.hpp does introspection on configuration options
50 // and compiler environment then sets a collection of #define macros.
51 
52 #include <Kokkos_Macros.hpp>
53 #include <impl/Kokkos_Utilities.hpp>
54 
55 #include <Kokkos_UniqueToken.hpp>
56 #include <Kokkos_MasterLock.hpp>
57 
58 //----------------------------------------------------------------------------
59 // Have assumed a 64bit build (8byte pointers) throughout the code base.
60 
61 static_assert(sizeof(void *) == 8,
62  "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
63 
64 //----------------------------------------------------------------------------
65 
66 namespace Kokkos {
67 
68 struct AUTO_t {
69  KOKKOS_INLINE_FUNCTION
70  constexpr const AUTO_t &operator()() const { return *this; }
71 };
72 
73 namespace {
76 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
77 } // namespace
78 
79 struct InvalidType {};
80 
81 } // namespace Kokkos
82 
83 //----------------------------------------------------------------------------
84 // Forward declarations for class inter-relationships
85 
86 namespace Kokkos {
87 
88 class HostSpace;
89 class AnonymousSpace;
90 
91 #ifdef KOKKOS_ENABLE_HBWSPACE
92 namespace Experimental {
93 class HBWSpace;
94 }
96 #endif
97 
98 #if defined(KOKKOS_ENABLE_SERIAL)
99 class Serial;
100 #endif
101 
102 #if defined(KOKKOS_ENABLE_HPX)
103 namespace Experimental {
104 class HPX;
105 }
106 #endif
107 
108 #if defined(KOKKOS_ENABLE_THREADS)
109 class Threads;
110 #endif
111 
112 #if defined(KOKKOS_ENABLE_OPENMP)
113 class OpenMP;
114 #endif
115 
116 #if defined(KOKKOS_ENABLE_OPENMPTARGET)
117 namespace Experimental {
118 class OpenMPTarget;
119 class OpenMPTargetSpace;
120 } // namespace Experimental
121 #endif
122 
123 #if defined(KOKKOS_ENABLE_ROCM)
124 namespace Experimental {
125 class ROCmSpace;
126 class ROCm;
127 } // namespace Experimental
128 #endif
129 
130 #if defined(KOKKOS_ENABLE_HIP)
131 namespace Experimental {
132 class HIPSpace;
133 class HIP;
134 } // namespace Experimental
135 #endif
136 
137 template <class ExecutionSpace, class MemorySpace>
138 struct Device;
139 
140 } // namespace Kokkos
141 
142 #include "Cuda/Kokkos_Cuda_fwd.hpp"
143 
144 //----------------------------------------------------------------------------
145 // Set the default execution space.
146 
151 
152 namespace Kokkos {
153 
154 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
155 typedef Cuda DefaultExecutionSpace;
156 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
157 typedef Experimental::OpenMPTarget DefaultExecutionSpace;
158 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
159 typedef Experimental::HIP DefaultExecutionSpace;
160 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_ROCM)
161 typedef Experimental::ROCm DefaultExecutionSpace;
162 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
163 typedef OpenMP DefaultExecutionSpace;
164 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
165 typedef Threads DefaultExecutionSpace;
166 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
167 typedef Kokkos::Experimental::HPX DefaultExecutionSpace;
168 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
169 typedef Serial DefaultExecutionSpace;
170 #else
171 #error \
172  "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::Experimental::HIP, Kokkos::Experimental::OpenMPTarget, Kokkos::OpenMP, Kokkos::Threads, Kokkos::Experimental::HPX, or Kokkos::Serial."
173 #endif
174 
175 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
176 typedef OpenMP DefaultHostExecutionSpace;
177 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
178 typedef Threads DefaultHostExecutionSpace;
179 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
180 typedef Kokkos::Experimental::HPX DefaultHostExecutionSpace;
181 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
182 typedef Serial DefaultHostExecutionSpace;
183 #elif defined(KOKKOS_ENABLE_OPENMP)
184 typedef OpenMP DefaultHostExecutionSpace;
185 #elif defined(KOKKOS_ENABLE_THREADS)
186 typedef Threads 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 \
193  "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::OpenMP, Kokkos::Threads, Kokkos::Experimental::HPX, or Kokkos::Serial."
194 #endif
195 
196 } // namespace Kokkos
197 
198 //----------------------------------------------------------------------------
199 // Detect the active execution space and define its memory space.
200 // This is used to verify whether a running kernel can access
201 // a given memory space.
202 
203 namespace Kokkos {
204 
205 namespace Impl {
206 
207 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA) && \
208  defined(KOKKOS_ENABLE_CUDA)
209 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace;
210 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_ROCM_GPU)
211 typedef Kokkos::HostSpace ActiveExecutionMemorySpace;
212 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HIP_GPU)
213 typedef Kokkos::Experimental::HIPSpace ActiveExecutionMemorySpace;
214 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
215 typedef Kokkos::HostSpace ActiveExecutionMemorySpace;
216 #else
217 typedef void ActiveExecutionMemorySpace;
218 #endif
219 
220 template <class ActiveSpace, class MemorySpace>
221 struct VerifyExecutionCanAccessMemorySpace {
222  enum { value = 0 };
223 };
224 
225 template <class Space>
226 struct VerifyExecutionCanAccessMemorySpace<Space, Space> {
227  enum { value = 1 };
228  KOKKOS_INLINE_FUNCTION static void verify(void) {}
229  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
230 };
231 } // namespace Impl
232 
233 } // namespace Kokkos
234 
235 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA(DATA_SPACE, DATA_PTR) \
236  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
237  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE>::verify(DATA_PTR)
238 
239 #define KOKKOS_RESTRICT_EXECUTION_TO_(DATA_SPACE) \
240  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
241  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE>::verify()
242 
243 //----------------------------------------------------------------------------
244 
245 namespace Kokkos {
246 void fence();
247 }
248 
249 //----------------------------------------------------------------------------
250 
251 namespace Kokkos {
252 
253 namespace Impl {
254 
255 template <class DstSpace, class SrcSpace,
256  class ExecutionSpace = typename DstSpace::execution_space>
257 struct DeepCopy;
258 
259 template <class ViewType, class Layout, class ExecSpace, int Rank,
260  typename iType>
261 struct ViewFillETIAvail;
262 
263 template <class ViewType, class Layout = typename ViewType::array_layout,
264  class ExecSpace = typename ViewType::execution_space,
265  int Rank = ViewType::Rank, typename iType = int64_t,
266  bool EtiAvail =
267  ViewFillETIAvail<ViewType, Layout, ExecSpace, Rank, iType>::value>
268 struct ViewFill;
269 
270 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
271  int Rank, typename iType>
272 struct ViewCopyETIAvail;
273 
274 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
275  int Rank, typename iType,
276  bool EtiAvail = ViewCopyETIAvail<ViewTypeA, ViewTypeB, Layout,
277  ExecSpace, Rank, iType>::value>
278 struct ViewCopy;
279 
280 template <class Functor, class Policy, class EnableFunctor = void,
281  class EnablePolicy = void>
283 
284 //----------------------------------------------------------------------------
291 template <class FunctorType, class ExecPolicy,
292  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
293  FunctorType, ExecPolicy>::execution_space>
295 
301 template <class FunctorType, class ExecPolicy, class ReducerType = InvalidType,
302  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
303  FunctorType, ExecPolicy>::execution_space>
305 
312 template <class FunctorType, class ExecPolicy,
313  class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
314  FunctorType, ExecPolicy>::execution_space>
316 
317 template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
318  class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
319  FunctorType, ExecPolicy>::execution_space>
320 class ParallelScanWithTotal;
321 
322 } // namespace Impl
323 
324 template <class ScalarType, class Space = HostSpace>
325 struct Sum;
326 template <class ScalarType, class Space = HostSpace>
327 struct Prod;
328 template <class ScalarType, class Space = HostSpace>
329 struct Min;
330 template <class ScalarType, class Space = HostSpace>
331 struct Max;
332 template <class ScalarType, class Space = HostSpace>
333 struct MinMax;
334 template <class ScalarType, class Index, class Space = HostSpace>
335 struct MinLoc;
336 template <class ScalarType, class Index, class Space = HostSpace>
337 struct MaxLoc;
338 template <class ScalarType, class Index, class Space = HostSpace>
339 struct MinMaxLoc;
340 template <class ScalarType, class Space = HostSpace>
341 struct BAnd;
342 template <class ScalarType, class Space = HostSpace>
343 struct BOr;
344 template <class ScalarType, class Space = HostSpace>
345 struct LAnd;
346 template <class ScalarType, class Space = HostSpace>
347 struct LOr;
348 
349 } // namespace Kokkos
350 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
351 namespace Kokkos {
352 template <class ScalarType>
353 struct MinMaxScalar;
354 template <class ScalarType, class Index>
355 struct MinMaxLocScalar;
356 template <class ScalarType, class Index>
357 struct ValLocScalar;
358 
359 namespace Experimental {
360 using Kokkos::BAnd;
361 using Kokkos::BOr;
362 using Kokkos::LAnd;
363 using Kokkos::LOr;
364 using Kokkos::Max;
365 using Kokkos::MaxLoc;
366 using Kokkos::Min;
367 using Kokkos::MinLoc;
368 using Kokkos::MinMax;
369 using Kokkos::MinMaxLoc;
370 using Kokkos::MinMaxLocScalar;
371 using Kokkos::MinMaxScalar;
372 using Kokkos::Prod;
373 using Kokkos::Sum;
374 using Kokkos::ValLocScalar;
375 } // namespace Experimental
376 } // namespace Kokkos
377 #endif
378 
379 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
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.