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