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 
61 static_assert(sizeof(void *) == 8,
62  "Kokkos assumes 64-bit build; i.e., 8-byte pointers");
63 
64 //----------------------------------------------------------------------------
65 
66 namespace Kokkos {
67 
68 struct AUTO_t {
69  KOKKOS_INLINE_FUNCTION
70  constexpr const AUTO_t &operator()() const { return *this; }
71 };
72 
73 namespace {
76 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
77 } // namespace
78 
79 struct InvalidType {};
80 
81 } // namespace Kokkos
82 
83 //----------------------------------------------------------------------------
84 // Forward declarations for class inter-relationships
85 
86 namespace Kokkos {
87 
88 class HostSpace;
89 class AnonymousSpace;
90 
91 template <class ExecutionSpace, class MemorySpace>
92 struct Device;
93 
94 // forward declare here so that backend initializer calls can use it.
95 struct 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 
120 namespace Kokkos {
121 
122 #if defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA)
123 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Cuda;
124 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET)
125 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
126  Experimental::OpenMPTarget;
127 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HIP)
128 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
129  Experimental::HIP;
130 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SYCL)
131 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
132  Experimental::SYCL;
133 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP)
134 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = OpenMP;
135 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
136 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION = Threads;
137 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
138 using DefaultExecutionSpace KOKKOS_IMPL_DEFAULT_EXEC_SPACE_ANNOTATION =
139  Kokkos::Experimental::HPX;
140 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
141 using 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)
148 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
149  OpenMP;
150 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS)
151 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
152  Threads;
153 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_HPX)
154 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
155  Kokkos::Experimental::HPX;
156 #elif defined(KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL)
157 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
158  Serial;
159 #elif defined(KOKKOS_ENABLE_OPENMP)
160 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
161  OpenMP;
162 #elif defined(KOKKOS_ENABLE_THREADS)
163 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
164  Threads;
165 #elif defined(KOKKOS_ENABLE_HPX)
166 using DefaultHostExecutionSpace KOKKOS_IMPL_DEFAULT_HOST_EXEC_SPACE_ANNOTATION =
167  Kokkos::Experimental::HPX;
168 #elif defined(KOKKOS_ENABLE_SERIAL)
169 using 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 
183 namespace Kokkos {
184 namespace Impl {
185 
186 #if defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA) && \
187  defined(KOKKOS_ENABLE_CUDA)
188 using ActiveExecutionMemorySpace = Kokkos::CudaSpace;
189 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_SYCL)
190 using ActiveExecutionMemorySpace = Kokkos::Experimental::SYCLDeviceUSMSpace;
191 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HIP_GPU)
192 using ActiveExecutionMemorySpace = Kokkos::Experimental::HIPSpace;
193 #elif defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST)
194 using ActiveExecutionMemorySpace = Kokkos::HostSpace;
195 #else
196 using ActiveExecutionMemorySpace = void;
197 #endif
198 
199 template <typename DstMemorySpace, typename SrcMemorySpace>
200 struct MemorySpaceAccess;
201 
202 template <typename DstMemorySpace, typename SrcMemorySpace,
203  bool = Kokkos::Impl::MemorySpaceAccess<DstMemorySpace,
204  SrcMemorySpace>::accessible>
205 struct verify_space {
206  KOKKOS_FUNCTION static void check() {}
207 };
208 
209 template <typename DstMemorySpace, typename SrcMemorySpace>
210 struct 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
218 class ExecSpaceInitializerBase;
219 
220 } // namespace Impl
221 
222 namespace Experimental {
223 template <class, class, class, class>
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 
239 namespace Kokkos {
240 void fence();
241 }
242 
243 //----------------------------------------------------------------------------
244 
245 namespace Kokkos {
246 
247 template <class DataType, class... Properties>
248 class View;
249 
250 namespace Impl {
251 
252 template <class DstSpace, class SrcSpace,
253  class ExecutionSpace = typename DstSpace::execution_space>
254 struct DeepCopy;
255 
256 template <class ViewType, class Layout = typename ViewType::array_layout,
257  class ExecSpace = typename ViewType::execution_space,
258  int Rank = ViewType::Rank, typename iType = int64_t>
259 struct ViewFill;
260 
261 template <class ViewTypeA, class ViewTypeB, class Layout, class ExecSpace,
262  int Rank, typename iType>
263 struct ViewCopy;
264 
265 template <class Functor, class Policy>
267 
268 //----------------------------------------------------------------------------
275 template <class FunctorType, class ExecPolicy,
276  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
277  FunctorType, ExecPolicy>::execution_space>
279 
285 template <class FunctorType, class ExecPolicy, class ReducerType = InvalidType,
286  class ExecutionSpace = typename Impl::FunctorPolicyExecutionSpace<
287  FunctorType, ExecPolicy>::execution_space>
289 
296 template <class FunctorType, class ExecPolicy,
297  class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
298  FunctorType, ExecPolicy>::execution_space>
300 
301 template <class FunctorType, class ExecPolicy, class ReturnType = InvalidType,
302  class ExecutionSapce = typename Impl::FunctorPolicyExecutionSpace<
303  FunctorType, ExecPolicy>::execution_space>
304 class ParallelScanWithTotal;
305 
306 } // namespace Impl
307 
308 template <class ScalarType, class Space = HostSpace>
309 struct Sum;
310 template <class ScalarType, class Space = HostSpace>
311 struct Prod;
312 template <class ScalarType, class Space = HostSpace>
313 struct Min;
314 template <class ScalarType, class Space = HostSpace>
315 struct Max;
316 template <class ScalarType, class Space = HostSpace>
317 struct MinMax;
318 template <class ScalarType, class Index, class Space = HostSpace>
319 struct MinLoc;
320 template <class ScalarType, class Index, class Space = HostSpace>
321 struct MaxLoc;
322 template <class ScalarType, class Index, class Space = HostSpace>
323 struct MinMaxLoc;
324 template <class ScalarType, class Space = HostSpace>
325 struct BAnd;
326 template <class ScalarType, class Space = HostSpace>
327 struct BOr;
328 template <class ScalarType, class Space = HostSpace>
329 struct LAnd;
330 template <class ScalarType, class Space = HostSpace>
331 struct LOr;
332 
333 } // namespace Kokkos
334 
335 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
Implementation detail of parallel_scan.
View to an array of data.
Memory management for host memory.
Implementation of the ParallelFor operator that has a partial specialization for the device...
ReturnType
Given a Functor and Execution Policy query an execution space.
Implementation detail of parallel_reduce.
LogicalMemorySpace is a space that is identical to another space, but differentiable by name and temp...
Definition: dummy.cpp:3
Access relationship between DstMemorySpace and SrcMemorySpace.