Kokkos Core Kernels Package  Version of the Day
Kokkos_Core_fwd.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_CORE_FWD_HPP
45 #define KOKKOS_CORE_FWD_HPP
46 
47 //----------------------------------------------------------------------------
48 // Kokkos_Macros.hpp does introspection on configuration options
49 // and compiler environment then sets a collection of #define macros.
50 
51 #include <Kokkos_Macros.hpp>
52 #include <impl/Kokkos_Utilities.hpp>
53 
54 //----------------------------------------------------------------------------
55 // Have assumed a 64bit build (8byte pointers) throughout the code base.
56 
57 static_assert( sizeof(void*) == 8
58  , "Kokkos assumes 64-bit build; i.e., 8-byte pointers" );
59 
60 //----------------------------------------------------------------------------
61 
62 namespace Kokkos {
63 
64 struct AUTO_t {
65  KOKKOS_INLINE_FUNCTION
66  constexpr const AUTO_t & operator()() const { return *this; }
67 };
68 
69 namespace {
71 constexpr AUTO_t AUTO = Kokkos::AUTO_t();
72 }
73 
74 struct InvalidType {};
75 
76 } // namespace Kokkos
77 
78 //----------------------------------------------------------------------------
79 // Forward declarations for class inter-relationships
80 
81 namespace Kokkos {
82 
83 class HostSpace;
84 
85 #ifdef KOKKOS_ENABLE_HBWSPACE
86 namespace Experimental {
87 class HBWSpace;
88 }
89 #endif
90 
91 #if defined( KOKKOS_ENABLE_SERIAL )
92 class Serial;
93 #endif
94 
95 #if defined( KOKKOS_ENABLE_QTHREADS )
96 class Qthreads;
97 #endif
98 
99 #if defined( KOKKOS_ENABLE_THREADS )
100 class Threads;
101 #endif
102 
103 #if defined( KOKKOS_ENABLE_OPENMP )
104 class OpenMP;
105 #endif
106 
107 #if defined( KOKKOS_ENABLE_OPENMPTARGET )
108 namespace Experimental {
109 class OpenMPTarget;
110 class OpenMPTargetSpace;
111 }
112 #endif
113 
114 
115 #if defined( KOKKOS_ENABLE_CUDA )
116 class CudaSpace;
117 class CudaUVMSpace;
118 class CudaHostPinnedSpace;
119 class Cuda;
120 #endif
121 
122 template<class ExecutionSpace, class MemorySpace>
123 struct Device;
124 
125 } // namespace Kokkos
126 
127 //----------------------------------------------------------------------------
128 // Set the default execution space.
129 
133 
134 namespace Kokkos {
135 
136 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_CUDA )
137  typedef Cuda DefaultExecutionSpace;
138 #elif defined ( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMPTARGET )
139  typedef Experimental::OpenMPTarget DefaultExecutionSpace ;
140 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
141  typedef OpenMP DefaultExecutionSpace;
142 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
143  typedef Threads DefaultExecutionSpace;
144 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
145 // typedef Qthreads DefaultExecutionSpace;
146 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
147  typedef Serial DefaultExecutionSpace;
148 #else
149 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::Experimental::OpenMPTarget, Kokkos::OpenMP, Kokkos::Threads, Kokkos::Qthreads, or Kokkos::Serial."
150 #endif
151 
152 #if defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_OPENMP )
153  typedef OpenMP DefaultHostExecutionSpace;
154 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_THREADS )
155  typedef Threads DefaultHostExecutionSpace;
156 //#elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_QTHREADS )
157 // typedef Qthreads DefaultHostExecutionSpace;
158 #elif defined( KOKKOS_ENABLE_DEFAULT_DEVICE_TYPE_SERIAL )
159  typedef Serial DefaultHostExecutionSpace;
160 #elif defined( KOKKOS_ENABLE_OPENMP )
161  typedef OpenMP DefaultHostExecutionSpace;
162 #elif defined( KOKKOS_ENABLE_THREADS )
163  typedef Threads DefaultHostExecutionSpace;
164 //#elif defined( KOKKOS_ENABLE_QTHREADS )
165 // typedef Qthreads DefaultHostExecutionSpace;
166 #elif defined( KOKKOS_ENABLE_SERIAL )
167  typedef Serial DefaultHostExecutionSpace;
168 #else
169 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::OpenMP, Kokkos::Threads, Kokkos::Qthreads, or Kokkos::Serial."
170 #endif
171 
172 } // namespace Kokkos
173 
174 //----------------------------------------------------------------------------
175 // Detect the active execution space and define its memory space.
176 // This is used to verify whether a running kernel can access
177 // a given memory space.
178 
179 namespace Kokkos {
180 
181 namespace Impl {
182 
183 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA ) && defined( KOKKOS_ENABLE_CUDA )
184 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace;
185 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
186 typedef Kokkos::HostSpace ActiveExecutionMemorySpace;
187 #else
188 typedef void ActiveExecutionMemorySpace;
189 #endif
190 
191 template< class ActiveSpace, class MemorySpace >
192 struct VerifyExecutionCanAccessMemorySpace {
193  enum {value = 0};
194 };
195 
196 template< class Space >
197 struct VerifyExecutionCanAccessMemorySpace< Space, Space >
198 {
199  enum {value = 1};
200  KOKKOS_INLINE_FUNCTION static void verify(void) {}
201  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
202 };
203 
204 } // namespace Impl
205 
206 } // namespace Kokkos
207 
208 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA( DATA_SPACE, DATA_PTR ) \
209  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
210  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify( DATA_PTR )
211 
212 #define KOKKOS_RESTRICT_EXECUTION_TO_( DATA_SPACE ) \
213  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
214  Kokkos::Impl::ActiveExecutionMemorySpace, DATA_SPACE >::verify()
215 
216 //----------------------------------------------------------------------------
217 
218 namespace Kokkos {
219  void fence();
220 }
221 
222 //----------------------------------------------------------------------------
223 
224 namespace Kokkos {
225 
226 namespace Impl {
227 
228 template< class Functor
229  , class Policy
230  , class EnableFunctor = void
231  , class EnablePolicy = void
232  >
234 
235 //----------------------------------------------------------------------------
242 template< class FunctorType, class ExecPolicy, class ExecutionSpace =
243  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
244  > class ParallelFor;
245 
251 template< class FunctorType, class ExecPolicy, class ReducerType = InvalidType, class ExecutionSpace =
252  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
253  > class ParallelReduce;
254 
261 template< class FunctorType, class ExecPolicy, class ExecutionSapce =
262  typename Impl::FunctorPolicyExecutionSpace< FunctorType, ExecPolicy >::execution_space
263  > class ParallelScan;
264 
265 } // namespace Impl
266 
267 namespace Experimental {
268 template<class ScalarType , class Space = HostSpace> struct Sum;
269 template<class ScalarType , class Space = HostSpace> struct Prod;
270 template<class ScalarType , class Space = HostSpace> struct Min;
271 template<class ScalarType , class Space = HostSpace> struct Max;
272 template<class ScalarType , class Space = HostSpace> struct MinMax;
273 template<class ScalarType , class Index, class Space = HostSpace> struct MinLoc;
274 template<class ScalarType , class Index, class Space = HostSpace> struct MaxLoc;
275 template<class ScalarType , class Index, class Space = HostSpace> struct MinMaxLoc;
276 template<class ScalarType , class Space = HostSpace> struct BAnd;
277 template<class ScalarType , class Space = HostSpace> struct BOr;
278 template<class ScalarType , class Space = HostSpace> struct LAnd;
279 template<class ScalarType , class Space = HostSpace> struct LOr;
280 }
281 } // namespace Kokkos
282 
283 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
284 
Implementation detail of parallel_scan.
Memory management for host memory.
Implementation of the ParallelFor operator that has a partial specialization for the device...
Given a Functor and Execution Policy query an execution space.
Implementation detail of parallel_reduce.