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
54inline constexpr AUTO_t AUTO{};
55
56struct InvalidType {};
57
58} // namespace Kokkos
59
60//----------------------------------------------------------------------------
61// Forward declarations for class interrelationships
62
63namespace Kokkos {
64
65class HostSpace;
66class AnonymousSpace;
67
68template <class ExecutionSpace, class MemorySpace>
69struct Device;
70
71// forward declare here so that backend initializer calls can use it.
72class InitializationSettings;
73
74} // namespace Kokkos
75
76// Include backend forward statements as determined by build options
77#include <KokkosCore_Config_FwdBackend.hpp>
78
79//----------------------------------------------------------------------------
80// Set the default execution space.
81
86
87#if defined(__clang_analyzer__)
88#define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION \
89 [[clang::annotate("DefaultExecutionSpace")]]
90#define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION \
91 [[clang::annotate("DefaultHostExecutionSpace")]]
92#else
93#define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION
94#define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION
95#endif
96
97namespace Kokkos {
98
99#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
100using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
101#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
102using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
103 Experimental::OpenMPTarget;
104#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
105using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = HIP;
106#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
107using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = SYCL;
108#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENACC)
109using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
110 Experimental::OpenACC;
111#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
112using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
113#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
114using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
115#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
116using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
117 Kokkos::Experimental::HPX;
118#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
119using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Serial;
120#else
121#error \
122 "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."
123#endif
124
125#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
126using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
127 OpenMP;
128#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
129using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
130 Threads;
131#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
132using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
133 Kokkos::Experimental::HPX;
134#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
135using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
136 Serial;
137#elif defined(KOKKOS_ENABLE_OPENMP)
138using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
139 OpenMP;
140#elif defined(KOKKOS_ENABLE_THREADS)
141using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
142 Threads;
143#elif defined(KOKKOS_ENABLE_HPX)
144using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
145 Kokkos::Experimental::HPX;
146#elif defined(KOKKOS_ENABLE_SERIAL)
147using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
148 Serial;
149#else
150#error \
151 "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."
152#endif
153
154// check for devices that support sharedSpace
155#if defined(KOKKOS_ENABLE_CUDA)
156using SharedSpace = CudaUVMSpace;
157#define KOKKOS_HAS_SHARED_SPACE
158#elif defined(KOKKOS_ENABLE_HIP)
159using SharedSpace = HIPManagedSpace;
160#define KOKKOS_HAS_SHARED_SPACE
161#elif defined(KOKKOS_ENABLE_SYCL)
162using SharedSpace = SYCLSharedUSMSpace;
163#define KOKKOS_HAS_SHARED_SPACE
164// if only host compile point to HostSpace
165#elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
166using SharedSpace = HostSpace;
167#define KOKKOS_HAS_SHARED_SPACE
168#endif
169
170inline constexpr bool has_shared_space =
171#if defined KOKKOS_HAS_SHARED_SPACE
172 true;
173#else
174 false;
175#endif
176
177#if defined(KOKKOS_ENABLE_CUDA)
178using SharedHostPinnedSpace = CudaHostPinnedSpace;
179#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
180#elif defined(KOKKOS_ENABLE_HIP)
181using SharedHostPinnedSpace = HIPHostPinnedSpace;
182#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
183#elif defined(KOKKOS_ENABLE_SYCL)
184 using SharedHostPinnedSpace = SYCLHostUSMSpace;
185#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
186#elif !defined(KOKKOS_ENABLE_OPENACC) && !defined(KOKKOS_ENABLE_OPENMPTARGET)
187 using SharedHostPinnedSpace = HostSpace;
188#define KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
189#endif
190
191inline constexpr bool has_shared_host_pinned_space =
192#if defined KOKKOS_HAS_SHARED_HOST_PINNED_SPACE
193 true;
194#else
195 false;
196#endif
197
198} // namespace Kokkos
199
200//----------------------------------------------------------------------------
201// Detect the active execution space and define its memory space.
202// This is used to verify whether a running kernel can access
203// a given memory space.
204
205namespace Kokkos {
206
207template <class AccessSpace, class MemorySpace>
208struct SpaceAccessibility;
209
210namespace Impl {
211
212// primary template: memory space is accessible, do nothing.
213template <class MemorySpace, class AccessSpace,
214 bool = SpaceAccessibility<AccessSpace, MemorySpace>::accessible>
215struct RuntimeCheckMemoryAccessViolation {
216 KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const) {}
217};
218
219// explicit specialization: memory access violation will occur, call abort with
220// the specified error message.
221template <class MemorySpace, class AccessSpace>
222struct RuntimeCheckMemoryAccessViolation<MemorySpace, AccessSpace, false> {
223 KOKKOS_FUNCTION RuntimeCheckMemoryAccessViolation(char const *const msg) {
224 Kokkos::abort(msg);
225 }
226};
227
228// calls abort with default error message at runtime if memory access violation
229// will occur
230template <class MemorySpace>
231KOKKOS_FUNCTION void runtime_check_memory_access_violation() {
232 KOKKOS_IF_ON_HOST((
233 RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultHostExecutionSpace>(
234 "ERROR: attempt to access inaccessible memory space");))
235 KOKKOS_IF_ON_DEVICE(
236 (RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
237 "ERROR: attempt to access inaccessible memory space");))
238}
239
240// calls abort with specified error message at runtime if memory access
241// violation will occur
242template <class MemorySpace>
243KOKKOS_FUNCTION void runtime_check_memory_access_violation(
244 char const *const msg) {
245 KOKKOS_IF_ON_HOST((
246 (void)RuntimeCheckMemoryAccessViolation<MemorySpace,
247 DefaultHostExecutionSpace>(msg);))
248 KOKKOS_IF_ON_DEVICE((
249 (void)
250 RuntimeCheckMemoryAccessViolation<MemorySpace, DefaultExecutionSpace>(
251 msg);))
252}
253
254} // namespace Impl
255} // namespace Kokkos
256
257//----------------------------------------------------------------------------
258
259namespace Kokkos {
260void fence(const std::string &name = "Kokkos::fence: Unnamed Global Fence");
261} // namespace Kokkos
262
263//----------------------------------------------------------------------------
264
265namespace Kokkos {
266
267template <class DataType, class... Properties>
268class View;
269
270namespace Impl {
271
272template <class DstSpace, class SrcSpace,
273 class ExecutionSpace = typename DstSpace::execution_space,
274 class Enable = void>
275struct DeepCopy;
276
277template <class ViewType, class Layout = typename ViewType::array_layout,
278 class ExecSpace = typename ViewType::execution_space,
279 int Rank = ViewType::rank, typename iType = int64_t>
280struct ViewFill;
281
282template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
283 int Rank, typename iType>
284struct ViewCopy;
285
286template <class Functor, class Policy>
287struct FunctorPolicyExecutionSpace;
288
289//----------------------------------------------------------------------------
296template <class FunctorType, class ExecPolicy,
297 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
298 FunctorType, ExecPolicy>::execution_space>
300
306template <typename CombinedFunctorReducerType, typename PolicyType,
307 typename ExecutionSpaceType>
309
310template <typename FunctorType, typename FunctorAnalysisReducerType,
311 typename Enable = void>
312class CombinedFunctorReducer;
313
320template <class FunctorType, class ExecPolicy,
321 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
322 FunctorType, ExecPolicy>::execution_space>
324
325template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
326 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
327 FunctorType, ExecPolicy>::execution_space>
328class ParallelScanWithTotal;
329
330} // namespace Impl
331
332template <class ScalarType, class Space = HostSpace>
333struct Sum;
334template <class ScalarType, class Space = HostSpace>
335struct Prod;
336template <class ScalarType, class Space = HostSpace>
337struct Min;
338template <class ScalarType, class Space = HostSpace>
339struct Max;
340template <class ScalarType, class Space = HostSpace>
341struct MinMax;
342template <class ScalarType, class Index, class Space = HostSpace>
343struct MinLoc;
344template <class ScalarType, class Index, class Space = HostSpace>
345struct MaxLoc;
346template <class ScalarType, class Index, class Space = HostSpace>
347struct MinMaxLoc;
348template <class ScalarType, class Space = HostSpace>
349struct BAnd;
350template <class ScalarType, class Space = HostSpace>
351struct BOr;
352template <class ScalarType, class Space = HostSpace>
353struct LAnd;
354template <class ScalarType, class Space = HostSpace>
355struct LOr;
356
357template <class Scalar, class Index, class Space = HostSpace>
358struct MaxFirstLoc;
359template <class Scalar, class Index, class ComparatorType,
360 class Space = HostSpace>
361struct MaxFirstLocCustomComparator;
362
363template <class Scalar, class Index, class Space = HostSpace>
364struct MinFirstLoc;
365template <class Scalar, class Index, class ComparatorType,
366 class Space = HostSpace>
367struct MinFirstLocCustomComparator;
368
369template <class Scalar, class Index, class Space = HostSpace>
370struct MinMaxFirstLastLoc;
371template <class Scalar, class Index, class ComparatorType,
372 class Space = HostSpace>
373struct MinMaxFirstLastLocCustomComparator;
374
375template <class Index, class Space = HostSpace>
376struct FirstLoc;
377template <class Index, class Space = HostSpace>
378struct LastLoc;
379template <class Index, class Space = HostSpace>
380struct StdIsPartitioned;
381template <class Index, class Space = HostSpace>
382struct StdPartitionPoint;
383} // namespace Kokkos
384
385#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
386#undef KOKKOS_IMPL_PUBLIC_INCLUDE
387#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE_FWD
388#endif
389#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.