Kokkos Core Kernels Package Version of the Day
Kokkos_Core_fwd.hpp
1/*
2//@HEADER
3// ************************************************************************
4//
5// Kokkos v. 3.0
6// Copyright (2020) National Technology & Engineering
7// Solutions of Sandia, LLC (NTESS).
8//
9// Under the terms of Contract DE-NA0003525 with NTESS,
10// the U.S. Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40//
41// ************************************************************************
42//@HEADER
43*/
44
45#ifndef KOKKOS_CORE_FWD_HPP
46#define KOKKOS_CORE_FWD_HPP
47
48//----------------------------------------------------------------------------
49// Kokkos_Macros.hpp does introspection on configuration options
50// and compiler environment then sets a collection of #define macros.
51
52#include <Kokkos_Macros.hpp>
53#include <impl/Kokkos_Error.hpp>
54#include <impl/Kokkos_Utilities.hpp>
55
56#include <Kokkos_MasterLock.hpp>
57
58//----------------------------------------------------------------------------
59// Have assumed a 64bit build (8byte pointers) throughout the code base.
60
61static_assert(sizeof(void *) == 8,
62 "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
63
64//----------------------------------------------------------------------------
65
66namespace Kokkos {
67
68struct AUTO_t {
69 KOKKOS_INLINE_FUNCTION
70 constexpr const AUTO_t &operator()() const { return *this; }
71};
72
73namespace {
76constexpr AUTO_t AUTO = Kokkos::AUTO_t();
77} // namespace
78
79struct InvalidType {};
80
81} // namespace Kokkos
82
83//----------------------------------------------------------------------------
84// Forward declarations for class inter-relationships
85
86namespace Kokkos {
87
88class HostSpace;
89class AnonymousSpace;
90
91template <class ExecutionSpace, class MemorySpace>
92struct Device;
93
94// forward declare here so that backend initializer calls can use it.
95struct InitArguments;
96
97} // namespace Kokkos
98
99// Include backend forward statements as determined by build options
100#include <KokkosCore_Config_FwdBackend.hpp>
101
102//----------------------------------------------------------------------------
103// Set the default execution space.
104
109
110#if defined(__clang_analyzer__)
111#define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION \
112 [[clang::annotate("DefaultExecutionSpace")]]
113#define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION \
114 [[clang::annotate("DefaultHostExecutionSpace")]]
115#else
116#define KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION
117#define KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION
118#endif
119
120namespace Kokkos {
121
122#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
123using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
124#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
125using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
126 Experimental::OpenMPTarget;
127#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
128using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
129 Experimental::HIP;
130#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
131using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
132 Experimental::SYCL;
133#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
134using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
135#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
136using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
137#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
138using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
139 Kokkos::Experimental::HPX;
140#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
141using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Serial;
142#else
143#error \
144 "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::Experimental::HIP, Kokkos::Experimental::SYCL, Kokkos::Experimental::OpenMPTarget, Kokkos::OpenMP, Kokkos::Threads, Kokkos::Experimental::HPX, or Kokkos::Serial."
145#endif
146
147#if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
148using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
149 OpenMP;
150#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
151using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
152 Threads;
153#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
154using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
155 Kokkos::Experimental::HPX;
156#elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
157using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
158 Serial;
159#elif defined(KOKKOS_ENABLE_OPENMP)
160using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
161 OpenMP;
162#elif defined(KOKKOS_ENABLE_THREADS)
163using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
164 Threads;
165#elif defined(KOKKOS_ENABLE_HPX)
166using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
167 Kokkos::Experimental::HPX;
168#elif defined(KOKKOS_ENABLE_SERIAL)
169using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
170 Serial;
171#else
172#error \
173 "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."
174#endif
175
176} // namespace Kokkos
177
178//----------------------------------------------------------------------------
179// Detect the active execution space and define its memory space.
180// This is used to verify whether a running kernel can access
181// a given memory space.
182
183namespace Kokkos {
184namespace Impl {
185
186#if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA) && \
187 defined(KOKKOS_ENABLE_CUDA)
188using ActiveExecutionMemorySpace = Kokkos::CudaSpace;
189#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_SYCL)
190using ActiveExecutionMemorySpace = Kokkos::Experimental::SYCLDeviceUSMSpace;
191#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HIP_GPU)
192using ActiveExecutionMemorySpace = Kokkos::Experimental::HIPSpace;
193#elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
194using ActiveExecutionMemorySpace = Kokkos::HostSpace;
195#else
196using ActiveExecutionMemorySpace = void;
197#endif
198
199template <typename DstMemorySpace, typename SrcMemorySpace>
200struct MemorySpaceAccess;
201
202template <typename DstMemorySpace, typename SrcMemorySpace,
203 bool = Kokkos::Impl::MemorySpaceAccess<DstMemorySpace,
204 SrcMemorySpace>::accessible>
205struct verify_space {
206 KOKKOS_FUNCTION static void check() {}
207};
208
209template <typename DstMemorySpace, typename SrcMemorySpace>
210struct verify_space<DstMemorySpace, SrcMemorySpace, false> {
211 KOKKOS_FUNCTION static void check() {
212 Kokkos::abort(
213 "Kokkos::View ERROR: attempt to access inaccessible memory space");
214 };
215};
216
217// Base class for exec space initializer factories
218class ExecSpaceInitializerBase;
219
220} // namespace Impl
221
222namespace Experimental {
223template <class, class, class, class>
224class LogicalMemorySpace;
225}
226
227} // namespace Kokkos
228
229#define KOKKOS_RESTRICT_EXECUTION_TO_DATA(DATA_SPACE, DATA_PTR) \
230 Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
231 DATA_SPACE>::check();
232
233#define KOKKOS_RESTRICT_EXECUTION_TO_(DATA_SPACE) \
234 Kokkos::Impl::verify_space<Kokkos::Impl::ActiveExecutionMemorySpace, \
235 DATA_SPACE>::check();
236
237//----------------------------------------------------------------------------
238
239namespace Kokkos {
240void fence();
241}
242
243//----------------------------------------------------------------------------
244
245namespace Kokkos {
246
247template <class DataType, class... Properties>
248class View;
249
250namespace Impl {
251
252template <class DstSpace, class SrcSpace,
253 class ExecutionSpace = typename DstSpace::execution_space>
254struct DeepCopy;
255
256template <class ViewType, class Layout = typename ViewType::array_layout,
257 class ExecSpace = typename ViewType::execution_space,
258 int Rank = ViewType::Rank, typename iType = int64_t>
259struct ViewFill;
260
261template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
262 int Rank, typename iType>
263struct ViewCopy;
264
265template <class Functor, class Policy>
266struct FunctorPolicyExecutionSpace;
267
268//----------------------------------------------------------------------------
275template <class FunctorType, class ExecPolicy,
276 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
277 FunctorType, ExecPolicy>::execution_space>
279
285template <class FunctorType, class ExecPolicy, class ReducerType = InvalidType,
286 class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
287 FunctorType, ExecPolicy>::execution_space>
289
296template <class FunctorType, class ExecPolicy,
297 class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
298 FunctorType, ExecPolicy>::execution_space>
300
301template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
302 class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
303 FunctorType, ExecPolicy>::execution_space>
304class ParallelScanWithTotal;
305
306} // namespace Impl
307
308template <class ScalarType, class Space = HostSpace>
309struct Sum;
310template <class ScalarType, class Space = HostSpace>
311struct Prod;
312template <class ScalarType, class Space = HostSpace>
313struct Min;
314template <class ScalarType, class Space = HostSpace>
315struct Max;
316template <class ScalarType, class Space = HostSpace>
317struct MinMax;
318template <class ScalarType, class Index, class Space = HostSpace>
319struct MinLoc;
320template <class ScalarType, class Index, class Space = HostSpace>
321struct MaxLoc;
322template <class ScalarType, class Index, class Space = HostSpace>
323struct MinMaxLoc;
324template <class ScalarType, class Space = HostSpace>
325struct BAnd;
326template <class ScalarType, class Space = HostSpace>
327struct BOr;
328template <class ScalarType, class Space = HostSpace>
329struct LAnd;
330template <class ScalarType, class Space = HostSpace>
331struct LOr;
332
333} // namespace Kokkos
334
335#endif /* #ifndef KOKKOS_CORE_FWD_HPP */
View
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.
Access relationship between DstMemorySpace and SrcMemorySpace.