Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_TaskScheduler_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 Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_TASKSCHEDULER_FWD_HPP
45 #define KOKKOS_TASKSCHEDULER_FWD_HPP
46 
47 //----------------------------------------------------------------------------
48 
49 #include <Kokkos_Macros.hpp>
50 #if defined( KOKKOS_ENABLE_TASKDAG )
51 
52 #include <Kokkos_Core_fwd.hpp>
53 //----------------------------------------------------------------------------
54 
55 namespace Kokkos {
56 
57 // Forward declarations used in Impl::TaskQueue
58 
59 template <typename ValueType, typename Scheduler>
60 class BasicFuture;
61 
62 template <class Space, class Queue>
63 class SimpleTaskScheduler;
64 
65 template <class Space, class Queue>
66 class BasicTaskScheduler;
67 
68 template< typename Space >
69 struct is_scheduler : public std::false_type {};
70 
71 template<class Space, class Queue>
72 struct is_scheduler<BasicTaskScheduler<Space, Queue>> : public std::true_type {};
73 
74 template<class Space, class Queue>
75 struct is_scheduler<SimpleTaskScheduler<Space, Queue>> : public std::true_type {};
76 
77 enum class TaskPriority : int {
78  High = 0,
79  Regular = 1,
80  Low = 2
81 };
82 
83 } // namespace Kokkos
84 
85 //----------------------------------------------------------------------------
86 
87 namespace Kokkos {
88 
89 template <class Device>
90 class MemoryPool;
91 
92 namespace Impl {
93 
94 template <class TaskQueueTraits>
95 class TaskNode;
96 
97 class TaskBase;
98 
99 /*\brief Implementation data for task data management, access, and execution.
100  * (Deprecated)
101  * CRTP Inheritance structure to allow static_cast from the
102  * task root type and a task's FunctorType.
103  *
104  * TaskBase< Space , ResultType , FunctorType >
105  * : TaskBase< Space , ResultType , void >
106  * , FunctorType
107  * { ... };
108  *
109  * TaskBase< Space , ResultType , void >
110  * : TaskBase< Space , void , void >
111  * { ... };
112  */
113 template< typename Space , typename ResultType , typename FunctorType >
114 class Task;
115 
116 class TaskQueueBase;
117 
118 template< typename Space, typename MemorySpace>
119 class TaskQueue;
120 
121 template< typename ExecSpace, typename MemorySpace>
122 class TaskQueueMultiple;
123 
124 template<
125  typename ExecSpace, typename MemSpace, typename TaskQueueTraits,
126  class MemoryPool = Kokkos::MemoryPool<Kokkos::Device<ExecSpace, MemSpace>>
127 >
128 class SingleTaskQueue;
129 
130 template< typename ExecSpace, typename MemSpace, typename TaskQueueTraits, class MemoryPool>
131 class MultipleTaskQueue;
132 
133 struct TaskQueueTraitsLockBased;
134 
135 template <size_t CircularBufferSize=64>
136 struct TaskQueueTraitsChaseLev;
137 
138 template< typename ResultType >
139 struct TaskResult;
140 
141 struct TaskSchedulerBase;
142 
143 template <class ExecSpace>
144 struct default_tasking_memory_space_for_execution_space
145 {
146  using type = typename ExecSpace::memory_space;
147 };
148 
149 #if defined( KOKKOS_ENABLE_CUDA )
150 template <>
151 struct default_tasking_memory_space_for_execution_space<Kokkos::Cuda>
152 {
153  using type = Kokkos::CudaUVMSpace;
154 };
155 #endif
156 
157 template <class ExecSpace>
158 using default_tasking_memory_space_for_execution_space_t =
159  typename default_tasking_memory_space_for_execution_space<ExecSpace>::type;
160 
161 } // namespace Impl
162 } // namespace Kokkos
163 
164 //----------------------------------------------------------------------------
165 
166 namespace Kokkos {
167 
168 template< typename Space >
169 using DeprecatedTaskScheduler = BasicTaskScheduler<
170  Space,
171  Impl::TaskQueue<Space, Impl::default_tasking_memory_space_for_execution_space_t<Space>>
172 >;
173 
174 template< typename Space >
175 using DeprecatedTaskSchedulerMultiple = BasicTaskScheduler<
176  Space,
177  Impl::TaskQueueMultiple<Space, Impl::default_tasking_memory_space_for_execution_space_t<Space>>
178 >;
179 
180 template< typename Space >
181 using TaskScheduler = SimpleTaskScheduler<
182  Space,
183  Impl::SingleTaskQueue<
184  Space,
185  Impl::default_tasking_memory_space_for_execution_space_t<Space>,
186  Impl::TaskQueueTraitsLockBased
187  >
188 >;
189 
190 template< typename Space >
191 using TaskSchedulerMultiple = SimpleTaskScheduler<
192  Space,
193  Impl::MultipleTaskQueue<
194  Space,
195  Impl::default_tasking_memory_space_for_execution_space_t<Space>,
196  Impl::TaskQueueTraitsLockBased,
197  Kokkos::MemoryPool<
198  Kokkos::Device<
199  Space,
200  Impl::default_tasking_memory_space_for_execution_space_t<Space>
201  >
202  >
203  >
204 >;
205 
206 template< typename Space >
207 using ChaseLevTaskScheduler = SimpleTaskScheduler<
208  Space,
209  Impl::MultipleTaskQueue<
210  Space,
211  Impl::default_tasking_memory_space_for_execution_space_t<Space>,
212  Impl::TaskQueueTraitsChaseLev<>,
213  Kokkos::MemoryPool<
214  Kokkos::Device<
215  Space,
216  Impl::default_tasking_memory_space_for_execution_space_t<Space>
217  >
218  >
219  >
220 >;
221 
222 template<class Space, class QueueType>
223 void wait(BasicTaskScheduler<Space, QueueType> const&);
224 
225 namespace Impl {
226 
227 struct TaskSchedulerBase { };
228 
229 class TaskQueueBase { };
230 
231 template <typename Scheduler, typename EnableIfConstraint=void>
232 class TaskQueueSpecializationConstrained { };
233 
234 template <typename Scheduler>
235 struct TaskQueueSpecialization : TaskQueueSpecializationConstrained<Scheduler> { };
236 
237 template <int, typename>
238 struct TaskPolicyData;
239 
240 
241 } // end namespace Impl
242 
243 } // namespace Kokkos
244 
245 //----------------------------------------------------------------------------
246 
247 #endif /* #if defined( KOKKOS_ENABLE_TASKDAG ) */
248 #endif /* #ifndef KOKKOS_TASKSCHEDULER_FWD_HPP */
249