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 
52 namespace {
55 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
56 } // namespace
57 
58 struct InvalidType {};
59 
60 } // namespace Kokkos
61 
62 //----------------------------------------------------------------------------
63 // Forward declarations for class interrelationships
64 
65 namespace Kokkos {
66 
67 class HostSpace;
68 class AnonymousSpace;
69 
70 template <class ExecutionSpace, class MemorySpace>
71 struct Device;
72 
73 // forward declare here so that backend initializer calls can use it.
74 class InitializationSettings;
75 
76 } // namespace Kokkos
77 
78 // Include backend forward statements as determined by build options
79 #include <KokkosCore_Config_FwdBackend.hpp>
80 
81 //----------------------------------------------------------------------------
82 // Set the default execution space.
83 
88 
89 #if defined(__clang_analyzer__)
90 #define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION \
91  [[clang::annotate("DefaultExecutionSpace")]]
92 #define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION \
93  [[clang::annotate("DefaultHostExecutionSpace")]]
94 #else
95 #define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION
96 #define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION
97 #endif
98 
99 namespace Kokkos {
100 
101 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
102 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
103 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
104 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
105  Experimental::OpenMPTarget;
106 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
107 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = HIP;
108 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
109 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = SYCL;
110 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
111 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
112  Experimental::OpenACC;
113 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
114 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
115 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
116 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
117 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
118 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
119  Kokkos::Experimental::HPX;
120 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
121 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Serial;
122 #else
123 #error \
124  "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."
125 #endif
126 
127 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
128 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
129  OpenMP;
130 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
131 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
132  Threads;
133 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
134 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
135  Kokkos::Experimental::HPX;
136 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
137 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
138  Serial;
139 #elif defined(KOKKOS_ENABLE_OPENMP)
140 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
141  OpenMP;
142 #elif defined(KOKKOS_ENABLE_THREADS)
143 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
144  Threads;
145 #elif defined(KOKKOS_ENABLE_HPX)
146 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
147  Kokkos::Experimental::HPX;
148 #elif defined(KOKKOS_ENABLE_SERIAL)
149 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
150  Serial;
151 #else
152 #error \
153  "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."
154 #endif
155 
156 // check for devices that support sharedSpace
157 #if defined(KOKKOS_ENABLE_CUDA)
158 using SharedSpace = CudaUVMSpace;
159 #define KOKKOS_HAS_SHARED_SPACE
160 #elif defined(KOKKOS_ENABLE_HIP)
161 using SharedSpace = HIPManagedSpace;
162 #define KOKKOS_HAS_SHARED_SPACE
163 #elif defined(KOKKOS_ENABLE_SYCL)
164 using SharedSpace = SYCLSharedUSMSpace;
165 #define KOKKOS_HAS_SHARED_SPACE
166 // if only host compile point to HostSpace
167 #elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
168 using SharedSpace = HostSpace;
169 #define KOKKOS_HAS_SHARED_SPACE
170 #endif
171 
172 inline constexpr bool has_shared_space =
173 #if defined KOKKOS_HAS_SHARED_SPACE
174  true;
175 #else
176  false;
177 #endif
178 
179 #if defined(KOKKOS_ENABLE_CUDA)
180 using SharedHostPinnedSpace = CudaHostPinnedSpace;
181 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
182 #elif defined(KOKKOS_ENABLE_HIP)
183 using SharedHostPinnedSpace = HIPHostPinnedSpace;
184 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
185 #elif defined(KOKKOS_ENABLE_SYCL)
186  using SharedHostPinnedSpace = SYCLHostUSMSpace;
187 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
188 #elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
189  using SharedHostPinnedSpace = HostSpace;
190 #define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
191 #endif
192 
193 inline constexpr bool has_shared_host_pinned_space =
194 #if defined KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
195  true;
196 #else
197  false;
198 #endif
199 
200 } // namespace Kokkos
201 
202 //----------------------------------------------------------------------------
203 // Detect the active execution space and define its memory space.
204 // This is used to verify whether a running kernel can access
205 // a given memory space.
206 
207 namespace Kokkos {
208 
209 template <class AccessSpace, class MemorySpace>
210 struct SpaceAccessibility;
211 
212 namespace Impl {
213 
214 // primary template: memory space is accessible, do nothing.
215 template <class MemorySpace, class AccessSpace,
216  bool = SpaceAccessibility<AccessSpace, MemorySpace>::accessible>
217 struct RuntimeCheckMemoryAccessViolation {
218  KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const) {}
219 };
220 
221 // explicit specialization: memory access violation will occur, call abort with
222 // the specified error message.
223 template <class MemorySpace, class AccessSpace>
224 struct RuntimeCheckMemoryAccessViolation<MemorySpace, AccessSpace, false> {
225  KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const msg) {
226  Kokkos::abort(msg);
227  }
228 };
229 
230 // calls abort with default error message at runtime if memory access violation
231 // will occur
232 template <class MemorySpace>
233 KOKKOS_FUNCTION void runtime_check_memory_access_violation() {
234  KOKKOS_IF_ON_HOST((
235  RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultHostExecutionSpace>(
236  "ERROR: attempt to access inaccessible memory space");))
237  KOKKOS_IF_ON_DEVICE(
238  (RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
239  "ERROR: attempt to access inaccessible memory space");))
240 }
241 
242 // calls abort with specified error message at runtime if memory access
243 // violation will occur
244 template <class MemorySpace>
245 KOKKOS_FUNCTION void runtime_check_memory_access_violation(
246  char const *const msg) {
247  KOKKOS_IF_ON_HOST((
248  (void)RuntimeCheckMemoryAccessViolation<MemorySpace,
249  DefaultHostExecutionSpace>(msg);))
250  KOKKOS_IF_ON_DEVICE((
251  (void)
252  RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
253  msg);))
254 }
255 
256 } // namespace Impl
257 } // namespace Kokkos
258 
259 //----------------------------------------------------------------------------
260 
261 namespace Kokkos {
262 // Getting ICE in Trilinos in Sacado and Intrepid in deep_copy
263 // See issue https://github.com/kokkos/kokkos/issues/5290
264 // Simply taking string by value did not resolve the issue
265 #ifdef KOKKOS_COMPILER_INTEL
266 void fence();
267 void fence(const std::string &name);
268 #else
269 void fence(const std::string &name = "Kokkos::fence: Unnamed Global Fence");
270 #endif
271 } // namespace Kokkos
272 
273 //----------------------------------------------------------------------------
274 
275 namespace Kokkos {
276 
277 template <class DataType, class... Properties>
278 class View;
279 
280 namespace Impl {
281 
282 template <class DstSpace, class SrcSpace,
283  class ExecutionSpace = typename DstSpace::execution_space,
284  class Enable = void>
285 struct DeepCopy;
286 
287 template <class ViewType, class Layout = typename ViewType::array_layout,
288  class ExecSpace = typename ViewType::execution_space,
289  int Rank = ViewType::rank, typename iType = int64_t>
290 struct ViewFill;
291 
292 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
293  int Rank, typename iType>
294 struct ViewCopy;
295 
296 template <class Functor, class Policy>
298 
299 //----------------------------------------------------------------------------
306 template <class FunctorType, class ExecPolicy,
307  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
308  FunctorType, ExecPolicy>::execution_space>
310 
316 template <typename CombinedFunctorReducerType, typename PolicyType,
317  typename ExecutionSpaceType>
319 
320 template <typename FunctorType, typename FunctorAnalysisReducerType,
321  typename Enable = void>
322 class CombinedFunctorReducer;
323 
330 template <class FunctorType, class ExecPolicy,
331  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
332  FunctorType, ExecPolicy>::execution_space>
334 
335 template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
336  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
337  FunctorType, ExecPolicy>::execution_space>
338 class ParallelScanWithTotal;
339 
340 } // namespace Impl
341 
342 template <class ScalarType, class Space = HostSpace>
343 struct Sum;
344 template <class ScalarType, class Space = HostSpace>
345 struct Prod;
346 template <class ScalarType, class Space = HostSpace>
347 struct Min;
348 template <class ScalarType, class Space = HostSpace>
349 struct Max;
350 template <class ScalarType, class Space = HostSpace>
351 struct MinMax;
352 template <class ScalarType, class Index, class Space = HostSpace>
353 struct MinLoc;
354 template <class ScalarType, class Index, class Space = HostSpace>
355 struct MaxLoc;
356 template <class ScalarType, class Index, class Space = HostSpace>
357 struct MinMaxLoc;
358 template <class ScalarType, class Space = HostSpace>
359 struct BAnd;
360 template <class ScalarType, class Space = HostSpace>
361 struct BOr;
362 template <class ScalarType, class Space = HostSpace>
363 struct LAnd;
364 template <class ScalarType, class Space = HostSpace>
365 struct LOr;
366 
367 template <class Scalar, class Index, class Space = HostSpace>
368 struct MaxFirstLoc;
369 template <class Scalar, class Index, class ComparatorType,
370  class Space = HostSpace>
371 struct MaxFirstLocCustomComparator;
372 
373 template <class Scalar, class Index, class Space = HostSpace>
374 struct MinFirstLoc;
375 template <class Scalar, class Index, class ComparatorType,
376  class Space = HostSpace>
377 struct MinFirstLocCustomComparator;
378 
379 template <class Scalar, class Index, class Space = HostSpace>
380 struct MinMaxFirstLastLoc;
381 template <class Scalar, class Index, class ComparatorType,
382  class Space = HostSpace>
383 struct MinMaxFirstLastLocCustomComparator;
384 
385 template <class Index, class Space = HostSpace>
386 struct FirstLoc;
387 template <class Index, class Space = HostSpace>
388 struct LastLoc;
389 template <class Index, class Space = HostSpace>
390 struct StdIsPartitioned;
391 template <class Index, class Space = HostSpace>
392 struct StdPartitionPoint;
393 } // namespace Kokkos
394 
395 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
396 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
397 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
398 #endif
399 #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.