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 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 
17 #ifndef KOKKOS_CORE_FWD_HPP
18 #define KOKKOS_CORE_FWD_HPP
19 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE
21 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
22 #endif
23 
24 //----------------------------------------------------------------------------
25 // Kokkos_Macros.hpp does introspection on configuration options
26 // and compiler environment then sets a collection of #define macros.
27 
28 #include <Kokkos_Macros.hpp>
29 #include <Kokkos_Printf.hpp>
30 #include <impl/Kokkos_Error.hpp>
31 #include <impl/Kokkos_Utilities.hpp>
32 
33 //----------------------------------------------------------------------------
34 // Have assumed a 64-bit build (8-byte pointers) throughout the code base.
35 // 32-bit build allowed but unsupported.
36 #ifdef KOKKOS_IMPL_32BIT
37 static_assert(sizeof(void *) == 4,
38  "Kokkos assumes 64-bit build; i.e., 4-byte pointers");
39 #else
40 static_assert(sizeof(void *) == 8,
41  "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
42 #endif
43 //----------------------------------------------------------------------------
44 
45 namespace Kokkos {
46 
47 struct AUTO_t {
48  KOKKOS_INLINE_FUNCTION
49  constexpr const AUTO_t &operator()() const { return *this; }
50 };
51 
54 inline constexpr AUTO_t AUTO{};
55 
56 struct InvalidType {};
57 
58 } // namespace Kokkos
59 
60 //----------------------------------------------------------------------------
61 // Forward declarations for class interrelationships
62 
63 namespace Kokkos {
64 
65 class HostSpace;
66 class AnonymousSpace;
67 
68 template <class ExecutionSpace, class MemorySpace>
69 struct Device;
70 
71 // forward declare here so that backend initializer calls can use it.
72 class InitializationSettings;
73 
74 } // namespace Kokkos
75 
76 // Include backend forward statements as determined by build options
77 #include <KokkosCore_Config_FwdBackend.hpp>
78 
79 //----------------------------------------------------------------------------
80 // Set the default execution space.
81 
86 
87 #if defined(__clang_analyzer__)
88 #define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION \
89  [[clang::annotate("DefaultExecutionSpace")]]
90 #define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION \
91  [[clang::annotate("DefaultHostExecutionSpace")]]
92 #else
93 #define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION
94 #define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION
95 #endif
96 
97 namespace Kokkos {
98 
99 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
100 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
101 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
102 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
103  Experimental::OpenMPTarget;
104 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
105 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = HIP;
106 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
107 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = SYCL;
108 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
109 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
110  Experimental::OpenACC;
111 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
112 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
113 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
114 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
115 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
116 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
117  Kokkos::Experimental::HPX;
118 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
119 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Serial;
120 #else
121 #error \
122  "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::HIP, Kokkos::SYCL, Kokkos::Experimental::OpenMPTarget, Kokkos::Experimental::OpenACC, Kokkos::OpenMP, Kokkos::Threads, Kokkos::Experimental::HPX, or Kokkos::Serial."
123 #endif
124 
125 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
126 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
127  OpenMP;
128 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
129 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
130  Threads;
131 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
132 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
133  Kokkos::Experimental::HPX;
134 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
135 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
136  Serial;
137 #elif defined(KOKKOS_ENABLE_OPENMP)
138 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
139  OpenMP;
140 #elif defined(KOKKOS_ENABLE_THREADS)
141 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
142  Threads;
143 #elif defined(KOKKOS_ENABLE_HPX)
144 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
145  Kokkos::Experimental::HPX;
146 #elif defined(KOKKOS_ENABLE_SERIAL)
147 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
148  Serial;
149 #else
150 #error \
151  "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."
152 #endif
153 
154 // check for devices that support sharedSpace
155 #if defined(KOKKOS_ENABLE_CUDA)
156 using SharedSpace = CudaUVMSpace;
157 #define KOKKOS_HAS_SHARED_SPACE
158 #elif defined(KOKKOS_ENABLE_HIP)
159 using SharedSpace = HIPManagedSpace;
160 #define KOKKOS_HAS_SHARED_SPACE
161 #elif defined(KOKKOS_ENABLE_SYCL)
162 using SharedSpace = SYCLSharedUSMSpace;
163 #define KOKKOS_HAS_SHARED_SPACE
164 // if only host compile point to HostSpace
165 #elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
166 using SharedSpace = HostSpace;
167 #define KOKKOS_HAS_SHARED_SPACE
168 #endif
169 
170 inline constexpr bool has_shared_space =
171 #if defined KOKKOS_HAS_SHARED_SPACE
172  true;
173 #else
174  false;
175 #endif
176 
177 #if defined(KOKKOS_ENABLE_CUDA)
178 using SharedHostPinnedSpace = CudaHostPinnedSpace;
179 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
180 #elif defined(KOKKOS_ENABLE_HIP)
181 using SharedHostPinnedSpace = HIPHostPinnedSpace;
182 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
183 #elif defined(KOKKOS_ENABLE_SYCL)
184  using SharedHostPinnedSpace = SYCLHostUSMSpace;
185 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
186 #elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
187  using SharedHostPinnedSpace = HostSpace;
188 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
189 #endif
190 
191 inline constexpr bool has_shared_host_pinned_space =
192 #if defined KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
193  true;
194 #else
195  false;
196 #endif
197 
198 } // namespace Kokkos
199 
200 //----------------------------------------------------------------------------
201 // Detect the active execution space and define its memory space.
202 // This is used to verify whether a running kernel can access
203 // a given memory space.
204 
205 namespace Kokkos {
206 
207 template <class AccessSpace, class MemorySpace>
208 struct SpaceAccessibility;
209 
210 namespace Impl {
211 
212 // primary template: memory space is accessible, do nothing.
213 template <class MemorySpace, class AccessSpace,
214  bool = SpaceAccessibility<AccessSpace, MemorySpace>::accessible>
215 struct RuntimeCheckMemoryAccessViolation {
216  KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const) {}
217 };
218 
219 // explicit specialization: memory access violation will occur, call abort with
220 // the specified error message.
221 template <class MemorySpace, class AccessSpace>
222 struct RuntimeCheckMemoryAccessViolation<MemorySpace, AccessSpace, false> {
223  KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const msg) {
224  Kokkos::abort(msg);
225  }
226 };
227 
228 // calls abort with default error message at runtime if memory access violation
229 // will occur
230 template <class MemorySpace>
231 KOKKOS_FUNCTION void runtime_check_memory_access_violation() {
232  KOKKOS_IF_ON_HOST((
233  RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultHostExecutionSpace>(
234  "ERROR: attempt to access inaccessible memory space");))
235  KOKKOS_IF_ON_DEVICE(
236  (RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
237  "ERROR: attempt to access inaccessible memory space");))
238 }
239 
240 // calls abort with specified error message at runtime if memory access
241 // violation will occur
242 template <class MemorySpace>
243 KOKKOS_FUNCTION void runtime_check_memory_access_violation(
244  char const *const msg) {
245  KOKKOS_IF_ON_HOST((
246  (void)RuntimeCheckMemoryAccessViolation<MemorySpace,
247  DefaultHostExecutionSpace>(msg);))
248  KOKKOS_IF_ON_DEVICE((
249  (void)
250  RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
251  msg);))
252 }
253 
254 } // namespace Impl
255 } // namespace Kokkos
256 
257 //----------------------------------------------------------------------------
258 
259 namespace Kokkos {
260 void fence(const std::string &name = "Kokkos::fence: Unnamed Global Fence");
261 } // namespace Kokkos
262 
263 //----------------------------------------------------------------------------
264 
265 namespace Kokkos {
266 
267 template <class DataType, class... Properties>
268 class View;
269 
270 namespace Impl {
271 
272 template <class DstSpace, class SrcSpace,
273  class ExecutionSpace = typename DstSpace::execution_space,
274  class Enable = void>
275 struct DeepCopy;
276 
277 template <class ViewType, class Layout = typename ViewType::array_layout,
278  class ExecSpace = typename ViewType::execution_space,
279  int Rank = ViewType::rank, typename iType = int64_t>
280 struct ViewFill;
281 
282 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
283  int Rank, typename iType>
284 struct ViewCopy;
285 
286 template <class Functor, class Policy>
288 
289 //----------------------------------------------------------------------------
296 template <class FunctorType, class ExecPolicy,
297  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
298  FunctorType, ExecPolicy>::execution_space>
300 
306 template <typename CombinedFunctorReducerType, typename PolicyType,
307  typename ExecutionSpaceType>
309 
310 template <typename FunctorType, typename FunctorAnalysisReducerType,
311  typename Enable = void>
312 class CombinedFunctorReducer;
313 
320 template <class FunctorType, class ExecPolicy,
321  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
322  FunctorType, ExecPolicy>::execution_space>
324 
325 template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
326  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
327  FunctorType, ExecPolicy>::execution_space>
328 class ParallelScanWithTotal;
329 
330 } // namespace Impl
331 
332 template <class ScalarType, class Space = HostSpace>
333 struct Sum;
334 template <class ScalarType, class Space = HostSpace>
335 struct Prod;
336 template <class ScalarType, class Space = HostSpace>
337 struct Min;
338 template <class ScalarType, class Space = HostSpace>
339 struct Max;
340 template <class ScalarType, class Space = HostSpace>
341 struct MinMax;
342 template <class ScalarType, class Index, class Space = HostSpace>
343 struct MinLoc;
344 template <class ScalarType, class Index, class Space = HostSpace>
345 struct MaxLoc;
346 template <class ScalarType, class Index, class Space = HostSpace>
347 struct MinMaxLoc;
348 template <class ScalarType, class Space = HostSpace>
349 struct BAnd;
350 template <class ScalarType, class Space = HostSpace>
351 struct BOr;
352 template <class ScalarType, class Space = HostSpace>
353 struct LAnd;
354 template <class ScalarType, class Space = HostSpace>
355 struct LOr;
356 
357 template <class Scalar, class Index, class Space = HostSpace>
358 struct MaxFirstLoc;
359 template <class Scalar, class Index, class ComparatorType,
360  class Space = HostSpace>
361 struct MaxFirstLocCustomComparator;
362 
363 template <class Scalar, class Index, class Space = HostSpace>
364 struct MinFirstLoc;
365 template <class Scalar, class Index, class ComparatorType,
366  class Space = HostSpace>
367 struct MinFirstLocCustomComparator;
368 
369 template <class Scalar, class Index, class Space = HostSpace>
370 struct MinMaxFirstLastLoc;
371 template <class Scalar, class Index, class ComparatorType,
372  class Space = HostSpace>
373 struct MinMaxFirstLastLocCustomComparator;
374 
375 template <class Index, class Space = HostSpace>
376 struct FirstLoc;
377 template <class Index, class Space = HostSpace>
378 struct LastLoc;
379 template <class Index, class Space = HostSpace>
380 struct StdIsPartitioned;
381 template <class Index, class Space = HostSpace>
382 struct StdPartitionPoint;
383 } // namespace Kokkos
384 
385 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
386 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
387 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
388 #endif
389 #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.