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