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 <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
37static_assert(sizeof(void *) == 4,
38 "Kokkos assumes 64-bit build; i.e., 4-byte pointers");
39#else
40static_assert(sizeof(void *) == 8,
41 "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
42#endif
43//----------------------------------------------------------------------------
44
45namespace Kokkos {
46
47struct AUTO_t {
48 KOKKOS_INLINE_FUNCTION
49 constexpr const AUTO_t &operator()() const { return *this; }
50};
51
52namespace {
55constexpr AUTO_t AUTO = Kokkos::AUTO_t();
56} // namespace
57
58struct InvalidType {};
59
60} // namespace Kokkos
61
62//----------------------------------------------------------------------------
63// Forward declarations for class interrelationships
64
65namespace Kokkos {
66
67class HostSpace;
68class AnonymousSpace;
69
70template <class ExecutionSpace, class MemorySpace>
71struct Device;
72
73// forward declare here so that backend initializer calls can use it.
74class 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
99namespace Kokkos {
100
101#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
102using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
103#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
104using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
105 Experimental::OpenMPTarget;
106#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
107using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = HIP;
108#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
109using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = SYCL;
110#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
111using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
112 Experimental::OpenACC;
113#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
114using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
115#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
116using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
117#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
118using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
119 Kokkos::Experimental::HPX;
120#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
121using 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)
128using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
129 OpenMP;
130#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
131using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
132 Threads;
133#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
134using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
135 Kokkos::Experimental::HPX;
136#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
137using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
138 Serial;
139#elif defined(KOKKOS_ENABLE_OPENMP)
140using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
141 OpenMP;
142#elif defined(KOKKOS_ENABLE_THREADS)
143using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
144 Threads;
145#elif defined(KOKKOS_ENABLE_HPX)
146using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
147 Kokkos::Experimental::HPX;
148#elif defined(KOKKOS_ENABLE_SERIAL)
149using 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)
158using SharedSpace = CudaUVMSpace;
159#define KOKKOS_HAS_SHARED_SPACE
160#elif defined(KOKKOS_ENABLE_HIP)
161using SharedSpace = HIPManagedSpace;
162#define KOKKOS_HAS_SHARED_SPACE
163#elif defined(KOKKOS_ENABLE_SYCL)
164using 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)
168using SharedSpace = HostSpace;
169#define KOKKOS_HAS_SHARED_SPACE
170#endif
171
172inline 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)
180using SharedHostPinnedSpace = CudaHostPinnedSpace;
181#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
182#elif defined(KOKKOS_ENABLE_HIP)
183using 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
193inline 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
207namespace Kokkos {
208
209template <class AccessSpace, class MemorySpace>
210struct SpaceAccessibility;
211
212namespace Impl {
213
214// primary template: memory space is accessible, do nothing.
215template <class MemorySpace, class AccessSpace,
216 bool = SpaceAccessibility<AccessSpace, MemorySpace>::accessible>
217struct 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.
223template <class MemorySpace, class AccessSpace>
224struct 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
232template <class MemorySpace>
233KOKKOS_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
244template <class MemorySpace>
245KOKKOS_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
261namespace 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
266void fence();
267void fence(const std::string &name);
268#else
269void fence(const std::string &name = "Kokkos::fence: Unnamed Global Fence");
270#endif
271} // namespace Kokkos
272
273//----------------------------------------------------------------------------
274
275namespace Kokkos {
276
277template <class DataType, class... Properties>
278class View;
279
280namespace Impl {
281
282template <class DstSpace, class SrcSpace,
283 class ExecutionSpace = typename DstSpace::execution_space,
284 class Enable = void>
285struct DeepCopy;
286
287template <class ViewType, class Layout = typename ViewType::array_layout,
288 class ExecSpace = typename ViewType::execution_space,
289 int Rank = ViewType::rank, typename iType = int64_t>
290struct ViewFill;
291
292template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
293 int Rank, typename iType>
294struct ViewCopy;
295
296template <class Functor, class Policy>
298
299//----------------------------------------------------------------------------
306template <class FunctorType, class ExecPolicy,
307 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
308 FunctorType, ExecPolicy>::execution_space>
310
316template <typename CombinedFunctorReducerType, typename PolicyType,
317 typename ExecutionSpaceType>
319
320template <typename FunctorType, typename FunctorAnalysisReducerType,
321 typename Enable = void>
322class CombinedFunctorReducer;
323
330template <class FunctorType, class ExecPolicy,
331 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
332 FunctorType, ExecPolicy>::execution_space>
334
335template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
336 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
337 FunctorType, ExecPolicy>::execution_space>
338class ParallelScanWithTotal;
339
340} // namespace Impl
341
342template <class ScalarType, class Space = HostSpace>
343struct Sum;
344template <class ScalarType, class Space = HostSpace>
345struct Prod;
346template <class ScalarType, class Space = HostSpace>
347struct Min;
348template <class ScalarType, class Space = HostSpace>
349struct Max;
350template <class ScalarType, class Space = HostSpace>
351struct MinMax;
352template <class ScalarType, class Index, class Space = HostSpace>
353struct MinLoc;
354template <class ScalarType, class Index, class Space = HostSpace>
355struct MaxLoc;
356template <class ScalarType, class Index, class Space = HostSpace>
357struct MinMaxLoc;
358template <class ScalarType, class Space = HostSpace>
359struct BAnd;
360template <class ScalarType, class Space = HostSpace>
361struct BOr;
362template <class ScalarType, class Space = HostSpace>
363struct LAnd;
364template <class ScalarType, class Space = HostSpace>
365struct LOr;
366
367template <class Scalar, class Index, class Space = HostSpace>
368struct MaxFirstLoc;
369template <class Scalar, class Index, class ComparatorType,
370 class Space = HostSpace>
371struct MaxFirstLocCustomComparator;
372
373template <class Scalar, class Index, class Space = HostSpace>
374struct MinFirstLoc;
375template <class Scalar, class Index, class ComparatorType,
376 class Space = HostSpace>
377struct MinFirstLocCustomComparator;
378
379template <class Scalar, class Index, class Space = HostSpace>
380struct MinMaxFirstLastLoc;
381template <class Scalar, class Index, class ComparatorType,
382 class Space = HostSpace>
383struct MinMaxFirstLastLocCustomComparator;
384
385template <class Index, class Space = HostSpace>
386struct FirstLoc;
387template <class Index, class Space = HostSpace>
388struct LastLoc;
389template <class Index, class Space = HostSpace>
390struct StdIsPartitioned;
391template <class Index, class Space = HostSpace>
392struct 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 */
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
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 ?