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