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 }
77 
78 //----------------------------------------------------------------------------
79 //----------------------------------------------------------------------------
80 // Forward declarations for class inter-relationships
81 
82 namespace Kokkos {
83 
84 class HostSpace ;
85 
86 #ifdef KOKKOS_HAVE_HBWSPACE
87 namespace Experimental {
88 class HBWSpace ;
89 }
90 #endif
91 
92 #if defined( KOKKOS_HAVE_SERIAL )
93 class Serial ;
94 #endif // defined( KOKKOS_HAVE_SERIAL )
95 
96 #if defined( KOKKOS_HAVE_PTHREAD )
97 class Threads ;
98 #endif
99 
100 #if defined( KOKKOS_HAVE_OPENMP )
101 class OpenMP ;
102 #endif
103 
104 #if defined( KOKKOS_HAVE_CUDA )
105 class CudaSpace ;
106 class CudaUVMSpace ;
107 class CudaHostPinnedSpace ;
108 class Cuda ;
109 #endif
110 
111 template<class ExecutionSpace, class MemorySpace>
112 struct Device;
113 } // namespace Kokkos
114 
115 //----------------------------------------------------------------------------
116 //----------------------------------------------------------------------------
117 // Set the default execution space.
118 
122 
123 namespace Kokkos {
124 
125 #if defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_CUDA )
126  typedef Cuda DefaultExecutionSpace ;
127 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP )
128  typedef OpenMP DefaultExecutionSpace ;
129 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS )
130  typedef Threads DefaultExecutionSpace ;
131 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL )
132  typedef Serial DefaultExecutionSpace ;
133 #else
134 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::Cuda, Kokkos::OpenMP, Kokkos::Serial, or Kokkos::Threads."
135 #endif
136 
137 #if defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_OPENMP )
138  typedef OpenMP DefaultHostExecutionSpace ;
139 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_THREADS )
140  typedef Threads DefaultHostExecutionSpace ;
141 #elif defined ( KOKKOS_HAVE_DEFAULT_DEVICE_TYPE_SERIAL )
142  typedef Serial DefaultHostExecutionSpace ;
143 #elif defined ( KOKKOS_HAVE_OPENMP )
144  typedef OpenMP DefaultHostExecutionSpace ;
145 #elif defined ( KOKKOS_HAVE_PTHREAD )
146  typedef Threads DefaultHostExecutionSpace ;
147 #elif defined ( KOKKOS_HAVE_SERIAL )
148  typedef Serial DefaultHostExecutionSpace ;
149 #else
150 # error "At least one of the following execution spaces must be defined in order to use Kokkos: Kokkos::OpenMP, Kokkos::Serial, or Kokkos::Threads."
151 #endif
152 
153 } // namespace Kokkos
154 
155 //----------------------------------------------------------------------------
156 //----------------------------------------------------------------------------
157 // Detect the active execution space and define its memory space.
158 // This is used to verify whether a running kernel can access
159 // a given memory space.
160 
161 namespace Kokkos {
162 namespace Impl {
163 
164 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA ) && defined (KOKKOS_HAVE_CUDA)
165 typedef Kokkos::CudaSpace ActiveExecutionMemorySpace ;
166 #elif defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST )
167 typedef Kokkos::HostSpace ActiveExecutionMemorySpace ;
168 #else
169 typedef void ActiveExecutionMemorySpace ;
170 #endif
171 
172 template< class ActiveSpace , class MemorySpace >
173 struct VerifyExecutionCanAccessMemorySpace {
174  enum {value = 0};
175 };
176 
177 template< class Space >
178 struct VerifyExecutionCanAccessMemorySpace< Space , Space >
179 {
180  enum {value = 1};
181  KOKKOS_INLINE_FUNCTION static void verify(void) {}
182  KOKKOS_INLINE_FUNCTION static void verify(const void *) {}
183 };
184 
185 } // namespace Impl
186 } // namespace Kokkos
187 
188 #define KOKKOS_RESTRICT_EXECUTION_TO_DATA( DATA_SPACE , DATA_PTR ) \
189  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
190  Kokkos::Impl::ActiveExecutionMemorySpace , DATA_SPACE >::verify( DATA_PTR )
191 
192 #define KOKKOS_RESTRICT_EXECUTION_TO_( DATA_SPACE ) \
193  Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< \
194  Kokkos::Impl::ActiveExecutionMemorySpace , DATA_SPACE >::verify()
195 
196 //----------------------------------------------------------------------------
197 //----------------------------------------------------------------------------
198 
199 namespace Kokkos {
200  void fence();
201 }
202 
203 //----------------------------------------------------------------------------
204 //----------------------------------------------------------------------------
205 
206 namespace Kokkos {
207 namespace Impl {
208 
209 template< class Functor
210  , class Policy
211  , class EnableFunctor = void
212  , class EnablePolicy = void
213  >
215 
216 //----------------------------------------------------------------------------
223 template< class FunctorType , class ExecPolicy , class ExecutionSpace =
224  typename Impl::FunctorPolicyExecutionSpace< FunctorType , ExecPolicy >::execution_space
225  > class ParallelFor ;
226 
232 template< class FunctorType , class ExecPolicy , class ReducerType = InvalidType, class ExecutionSpace =
233  typename Impl::FunctorPolicyExecutionSpace< FunctorType , ExecPolicy >::execution_space
234  > class ParallelReduce ;
235 
242 template< class FunctorType , class ExecPolicy , class ExecutionSapce =
243  typename Impl::FunctorPolicyExecutionSpace< FunctorType , ExecPolicy >::execution_space
244  > class ParallelScan ;
245 
246 }}
247 #endif /* #ifndef KOKKOS_CORE_FWD_HPP */
248 
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.