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 64bit build (8byte pointers) throughout the code base.
38
39static_assert(sizeof(void *) == 8,
40 "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
41
42//----------------------------------------------------------------------------
43
44namespace Kokkos {
45
46struct AUTO_t {
47 KOKKOS_INLINE_FUNCTION
48 constexpr const AUTO_t &operator()() const { return *this; }
49};
50
51namespace {
54constexpr AUTO_t AUTO = Kokkos::AUTO_t();
55} // namespace
56
57struct InvalidType {};
58
59} // namespace Kokkos
60
61//----------------------------------------------------------------------------
62// Forward declarations for class interrelationships
63
64namespace Kokkos {
65
66class HostSpace;
67class AnonymousSpace;
68
69template <class ExecutionSpace, class MemorySpace>
70struct Device;
71
72// forward declare here so that backend initializer calls can use it.
73#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_3
74struct InitArguments;
75#endif
76class 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
101namespace Kokkos {
102
103#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
104using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
105#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
106using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
107 Experimental::OpenMPTarget;
108#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
109using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = HIP;
110#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
111using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
112 Experimental::SYCL;
113#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
114using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
115 Experimental::OpenACC;
116#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
117using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
118#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
119using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
120#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
121using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
122 Kokkos::Experimental::HPX;
123#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
124using 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)
131using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
132 OpenMP;
133#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
134using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
135 Threads;
136#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
137using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
138 Kokkos::Experimental::HPX;
139#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
140using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
141 Serial;
142#elif defined(KOKKOS_ENABLE_OPENMP)
143using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
144 OpenMP;
145#elif defined(KOKKOS_ENABLE_THREADS)
146using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
147 Threads;
148#elif defined(KOKKOS_ENABLE_HPX)
149using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
150 Kokkos::Experimental::HPX;
151#elif defined(KOKKOS_ENABLE_SERIAL)
152using 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)
161using SharedSpace = CudaUVMSpace;
162#define KOKKOS_HAS_SHARED_SPACE
163#elif defined(KOKKOS_ENABLE_HIP)
164using SharedSpace = HIPManagedSpace;
165#define KOKKOS_HAS_SHARED_SPACE
166#elif defined(KOKKOS_ENABLE_SYCL)
167using 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)
171using SharedSpace = HostSpace;
172#define KOKKOS_HAS_SHARED_SPACE
173#endif
174
175inline 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)
183using SharedHostPinnedSpace = CudaHostPinnedSpace;
184#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
185#elif defined(KOKKOS_ENABLE_HIP)
186using 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
196inline 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
210namespace Kokkos {
211
212template <class AccessSpace, class MemorySpace>
213struct SpaceAccessibility;
214
215namespace Impl {
216
217// primary template: memory space is accessible, do nothing.
218template <class MemorySpace, class AccessSpace,
219 bool = SpaceAccessibility<AccessSpace, MemorySpace>::accessible>
220struct 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.
226template <class MemorySpace, class AccessSpace>
227struct 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
235template <class MemorySpace>
236KOKKOS_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
247template <class MemorySpace>
248KOKKOS_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
261namespace Experimental {
262template <class, class, class, class>
263class LogicalMemorySpace;
264}
265
266} // namespace Kokkos
267
268//----------------------------------------------------------------------------
269
270namespace 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
275void fence();
276void fence(const std::string &name);
277#else
278void fence(const std::string &name = "Kokkos::fence: Unnamed Global Fence");
279#endif
280} // namespace Kokkos
281
282//----------------------------------------------------------------------------
283
284namespace Kokkos {
285
286template <class DataType, class... Properties>
287class View;
288
289namespace Impl {
290
291template <class DstSpace, class SrcSpace,
292 class ExecutionSpace = typename DstSpace::execution_space,
293 class Enable = void>
294struct DeepCopy;
295
296template <typename ExecutionSpace, class DT, class... DP>
297struct ZeroMemset;
298
299template <class ViewType, class Layout = typename ViewType::array_layout,
300 class ExecSpace = typename ViewType::execution_space,
301 int Rank = ViewType::Rank, typename iType = int64_t>
302struct ViewFill;
303
304template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
305 int Rank, typename iType>
306struct ViewCopy;
307
308template <class Functor, class Policy>
309struct FunctorPolicyExecutionSpace;
310
311//----------------------------------------------------------------------------
318template <class FunctorType, class ExecPolicy,
319 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
320 FunctorType, ExecPolicy>::execution_space>
322
328template <class FunctorType, class ExecPolicy, class ReducerType = InvalidType,
329 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
330 FunctorType, ExecPolicy>::execution_space>
332
339template <class FunctorType, class ExecPolicy,
340 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
341 FunctorType, ExecPolicy>::execution_space>
343
344template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
345 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
346 FunctorType, ExecPolicy>::execution_space>
347class ParallelScanWithTotal;
348
349} // namespace Impl
350
351template <class ScalarType, class Space = HostSpace>
352struct Sum;
353template <class ScalarType, class Space = HostSpace>
354struct Prod;
355template <class ScalarType, class Space = HostSpace>
356struct Min;
357template <class ScalarType, class Space = HostSpace>
358struct Max;
359template <class ScalarType, class Space = HostSpace>
360struct MinMax;
361template <class ScalarType, class Index, class Space = HostSpace>
362struct MinLoc;
363template <class ScalarType, class Index, class Space = HostSpace>
364struct MaxLoc;
365template <class ScalarType, class Index, class Space = HostSpace>
366struct MinMaxLoc;
367template <class ScalarType, class Space = HostSpace>
368struct BAnd;
369template <class ScalarType, class Space = HostSpace>
370struct BOr;
371template <class ScalarType, class Space = HostSpace>
372struct LAnd;
373template <class ScalarType, class Space = HostSpace>
374struct LOr;
375
376template <class Scalar, class Index, class Space = HostSpace>
377struct MaxFirstLoc;
378template <class Scalar, class Index, class ComparatorType,
379 class Space = HostSpace>
380struct MaxFirstLocCustomComparator;
381
382template <class Scalar, class Index, class Space = HostSpace>
383struct MinFirstLoc;
384template <class Scalar, class Index, class ComparatorType,
385 class Space = HostSpace>
386struct MinFirstLocCustomComparator;
387
388template <class Scalar, class Index, class Space = HostSpace>
389struct MinMaxFirstLastLoc;
390template <class Scalar, class Index, class ComparatorType,
391 class Space = HostSpace>
392struct MinMaxFirstLastLocCustomComparator;
393
394template <class Index, class Space = HostSpace>
395struct FirstLoc;
396template <class Index, class Space = HostSpace>
397struct LastLoc;
398template <class Index, class Space = HostSpace>
399struct StdIsPartitioned;
400template <class Index, class Space = HostSpace>
401struct 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 */
A thread safe view to a bitset.
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.
ReturnType
Given a Functor and Execution Policy query an execution space.