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