|
9 | 9 |
|
10 | 10 | #pragma once
|
11 | 11 |
|
12 |
| -#include <sycl/detail/export.hpp> // for __SYCL_EXPORT |
13 |
| -#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase |
14 |
| -#ifdef __INTEL_PREVIEW_BREAKING_CHANGES |
15 |
| -#include <sycl/detail/string_view.hpp> // for string_view |
16 |
| -#endif |
| 12 | +#include "executable_graph.hpp" |
| 13 | +#include "modifiable_graph.hpp" |
17 | 14 | #include <sycl/ext/oneapi/experimental/detail/properties/graph_properties.hpp> // for graph_state
|
18 |
| -#include <sycl/ext/oneapi/experimental/graph/graph_node.hpp> // for node class |
19 |
| -#include <sycl/property_list.hpp> // for property_list |
20 | 15 |
|
21 | 16 | #include <functional> // for function
|
22 | 17 | #include <memory> // for shared_ptr
|
|
26 | 21 | namespace sycl {
|
27 | 22 | inline namespace _V1 {
|
28 | 23 | // Forward declarations
|
29 |
| -class handler; |
30 | 24 | class queue;
|
31 | 25 | class device;
|
32 | 26 | class context;
|
| 27 | +class property_list; |
33 | 28 |
|
34 | 29 | namespace ext {
|
35 | 30 | namespace oneapi {
|
36 | 31 | namespace experimental {
|
37 |
| -// Forward declarations |
38 |
| -template <graph_state State> class command_graph; |
39 |
| -class dynamic_command_group; |
40 |
| - |
41 | 32 | namespace detail {
|
42 | 33 | // Forward declarations
|
43 | 34 | class graph_impl;
|
44 |
| -class exec_graph_impl; |
45 | 35 |
|
46 | 36 | // List of sycl features and extensions which are not supported by graphs. Used
|
47 | 37 | // for throwing errors when these features are used with graphs.
|
@@ -93,244 +83,6 @@ UnsupportedFeatureToString(UnsupportedGraphFeatures Feature) {
|
93 | 83 | assert(false && "Unhandled graphs feature");
|
94 | 84 | return {};
|
95 | 85 | }
|
96 |
| - |
97 |
| -// Templateless modifiable command-graph base class. |
98 |
| -class __SYCL_EXPORT modifiable_command_graph |
99 |
| - : public sycl::detail::OwnerLessBase<modifiable_command_graph> { |
100 |
| -public: |
101 |
| - /// Constructor. |
102 |
| - /// @param SyclContext Context to use for graph. |
103 |
| - /// @param SyclDevice Device all nodes will be associated with. |
104 |
| - /// @param PropList Optional list of properties to pass. |
105 |
| - modifiable_command_graph(const context &SyclContext, const device &SyclDevice, |
106 |
| - const property_list &PropList = {}); |
107 |
| - |
108 |
| - /// Constructor. |
109 |
| - /// @param SyclQueue Queue to use for the graph device and context. |
110 |
| - /// @param PropList Optional list of properties to pass. |
111 |
| - modifiable_command_graph(const queue &SyclQueue, |
112 |
| - const property_list &PropList = {}); |
113 |
| - |
114 |
| - /// Add an empty node to the graph. |
115 |
| - /// @param PropList Property list used to pass [0..n] predecessor nodes. |
116 |
| - /// @return Constructed empty node which has been added to the graph. |
117 |
| - node add(const property_list &PropList = {}) { |
118 |
| - checkNodePropertiesAndThrow(PropList); |
119 |
| - if (PropList.has_property<property::node::depends_on>()) { |
120 |
| - auto Deps = PropList.get_property<property::node::depends_on>(); |
121 |
| - node Node = addImpl(Deps.get_dependencies()); |
122 |
| - if (PropList.has_property<property::node::depends_on_all_leaves>()) { |
123 |
| - addGraphLeafDependencies(Node); |
124 |
| - } |
125 |
| - return Node; |
126 |
| - } |
127 |
| - node Node = addImpl({}); |
128 |
| - if (PropList.has_property<property::node::depends_on_all_leaves>()) { |
129 |
| - addGraphLeafDependencies(Node); |
130 |
| - } |
131 |
| - return Node; |
132 |
| - } |
133 |
| - |
134 |
| - /// Add a command-group node to the graph. |
135 |
| - /// @param CGF Command-group function to create node with. |
136 |
| - /// @param PropList Property list used to pass [0..n] predecessor nodes. |
137 |
| - /// @return Constructed node which has been added to the graph. |
138 |
| - template <typename T> node add(T CGF, const property_list &PropList = {}) { |
139 |
| - checkNodePropertiesAndThrow(PropList); |
140 |
| - if (PropList.has_property<property::node::depends_on>()) { |
141 |
| - auto Deps = PropList.get_property<property::node::depends_on>(); |
142 |
| - node Node = addImpl(CGF, Deps.get_dependencies()); |
143 |
| - if (PropList.has_property<property::node::depends_on_all_leaves>()) { |
144 |
| - addGraphLeafDependencies(Node); |
145 |
| - } |
146 |
| - return Node; |
147 |
| - } |
148 |
| - node Node = addImpl(CGF, {}); |
149 |
| - if (PropList.has_property<property::node::depends_on_all_leaves>()) { |
150 |
| - addGraphLeafDependencies(Node); |
151 |
| - } |
152 |
| - return Node; |
153 |
| - } |
154 |
| - |
155 |
| - /// Add a dependency between two nodes. |
156 |
| - /// @param Src Node which will be a dependency of \p Dest. |
157 |
| - /// @param Dest Node which will be dependent on \p Src. |
158 |
| - void make_edge(node &Src, node &Dest); |
159 |
| - |
160 |
| - /// Finalize modifiable graph into an executable graph. |
161 |
| - /// @param PropList Property list used to pass properties for finalization. |
162 |
| - /// @return Executable graph object. |
163 |
| - command_graph<graph_state::executable> |
164 |
| - finalize(const property_list &PropList = {}) const; |
165 |
| - |
166 |
| - /// Change the state of a queue to be recording and associate this graph with |
167 |
| - /// it. |
168 |
| - /// @param RecordingQueue The queue to change state on and associate this |
169 |
| - /// graph with. |
170 |
| - /// @param PropList Property list used to pass properties for recording. |
171 |
| - void begin_recording(queue &RecordingQueue, |
172 |
| - const property_list &PropList = {}); |
173 |
| - |
174 |
| - /// Change the state of multiple queues to be recording and associate this |
175 |
| - /// graph with each of them. |
176 |
| - /// @param RecordingQueues The queues to change state on and associate this |
177 |
| - /// graph with. |
178 |
| - /// @param PropList Property list used to pass properties for recording. |
179 |
| - void begin_recording(const std::vector<queue> &RecordingQueues, |
180 |
| - const property_list &PropList = {}); |
181 |
| - |
182 |
| - /// Set all queues currently recording to this graph to the executing state. |
183 |
| - void end_recording(); |
184 |
| - |
185 |
| - /// Set a queue currently recording to this graph to the executing state. |
186 |
| - /// @param RecordingQueue The queue to change state on. |
187 |
| - void end_recording(queue &RecordingQueue); |
188 |
| - |
189 |
| - /// Set multiple queues currently recording to this graph to the executing |
190 |
| - /// state. |
191 |
| - /// @param RecordingQueues The queues to change state on. |
192 |
| - void end_recording(const std::vector<queue> &RecordingQueues); |
193 |
| - |
194 |
| - /// Synchronous operation that writes a DOT formatted description of the graph |
195 |
| - /// to the provided path. By default, this includes the graph topology, node |
196 |
| - /// types, node id and kernel names. |
197 |
| - /// @param path The path to write the DOT file to. |
198 |
| - /// @param verbose If true, print additional information about the nodes such |
199 |
| - /// as kernel args or memory access where applicable. |
200 |
| -#ifdef ___INTEL_PREVIEW_BREAKING_CHANGES |
201 |
| - void print_graph(const std::string path, bool verbose = false) const { |
202 |
| - print_graph(sycl::detail::string_view{path}, verbose); |
203 |
| - } |
204 |
| -#else |
205 |
| -#ifdef __SYCL_GRAPH_IMPL_CPP |
206 |
| - // Magic combination found by trial and error: |
207 |
| - __SYCL_EXPORT |
208 |
| -#if _WIN32 |
209 |
| - inline |
210 |
| -#endif |
211 |
| -#else |
212 |
| - inline |
213 |
| -#endif |
214 |
| - void |
215 |
| - print_graph(const std::string path, bool verbose = false) const { |
216 |
| - print_graph(sycl::detail::string_view{path}, verbose); |
217 |
| - } |
218 |
| -#endif |
219 |
| - |
220 |
| - /// Get a list of all nodes contained in this graph. |
221 |
| - std::vector<node> get_nodes() const; |
222 |
| - |
223 |
| - /// Get a list of all root nodes (nodes without dependencies) in this graph. |
224 |
| - std::vector<node> get_root_nodes() const; |
225 |
| - |
226 |
| - /// Common Reference Semantics |
227 |
| - friend bool operator==(const modifiable_command_graph &LHS, |
228 |
| - const modifiable_command_graph &RHS) { |
229 |
| - return LHS.impl == RHS.impl; |
230 |
| - } |
231 |
| - friend bool operator!=(const modifiable_command_graph &LHS, |
232 |
| - const modifiable_command_graph &RHS) { |
233 |
| - return !operator==(LHS, RHS); |
234 |
| - } |
235 |
| - |
236 |
| -protected: |
237 |
| - /// Constructor used internally by the runtime. |
238 |
| - /// @param Impl Detail implementation class to construct object with. |
239 |
| - modifiable_command_graph(const std::shared_ptr<detail::graph_impl> &Impl) |
240 |
| - : impl(Impl) {} |
241 |
| - |
242 |
| - /// Template-less implementation of add() for dynamic command-group nodes. |
243 |
| - /// @param DynCGF Dynamic Command-group function object to add. |
244 |
| - /// @param Dep List of predecessor nodes. |
245 |
| - /// @return Node added to the graph. |
246 |
| - node addImpl(dynamic_command_group &DynCGF, const std::vector<node> &Dep); |
247 |
| - |
248 |
| - /// Template-less implementation of add() for CGF nodes. |
249 |
| - /// @param CGF Command-group function to add. |
250 |
| - /// @param Dep List of predecessor nodes. |
251 |
| - /// @return Node added to the graph. |
252 |
| - node addImpl(std::function<void(handler &)> CGF, |
253 |
| - const std::vector<node> &Dep); |
254 |
| - |
255 |
| - /// Template-less implementation of add() for empty nodes. |
256 |
| - /// @param Dep List of predecessor nodes. |
257 |
| - /// @return Node added to the graph. |
258 |
| - node addImpl(const std::vector<node> &Dep); |
259 |
| - |
260 |
| - /// Adds all graph leaves as dependencies |
261 |
| - /// @param Node Destination node to which the leaves of the graph will be |
262 |
| - /// added as dependencies. |
263 |
| - void addGraphLeafDependencies(node Node); |
264 |
| - |
265 |
| - void print_graph(sycl::detail::string_view path, bool verbose = false) const; |
266 |
| - |
267 |
| - template <class Obj> |
268 |
| - friend const decltype(Obj::impl) & |
269 |
| - sycl::detail::getSyclObjImpl(const Obj &SyclObject); |
270 |
| - template <class T> |
271 |
| - friend T sycl::detail::createSyclObjFromImpl( |
272 |
| - std::add_rvalue_reference_t<decltype(T::impl)> ImplObj); |
273 |
| - template <class T> |
274 |
| - friend T sycl::detail::createSyclObjFromImpl( |
275 |
| - std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj); |
276 |
| - std::shared_ptr<detail::graph_impl> impl; |
277 |
| - |
278 |
| - static void checkNodePropertiesAndThrow(const property_list &Properties); |
279 |
| -}; |
280 |
| - |
281 |
| -// Templateless executable command-graph base class. |
282 |
| -class __SYCL_EXPORT executable_command_graph |
283 |
| - : public sycl::detail::OwnerLessBase<executable_command_graph> { |
284 |
| -public: |
285 |
| - /// An executable command-graph is not user constructable. |
286 |
| - executable_command_graph() = delete; |
287 |
| - |
288 |
| - /// Update the inputs & output of the graph. |
289 |
| - /// @param Graph Graph to use the inputs and outputs of. |
290 |
| - void update(const command_graph<graph_state::modifiable> &Graph); |
291 |
| - |
292 |
| - /// Updates a single node in this graph based on the contents of the provided |
293 |
| - /// node. |
294 |
| - /// @param Node The node to use for updating the graph. |
295 |
| - void update(const node &Node); |
296 |
| - |
297 |
| - /// Updates a number of nodes in this graph based on the contents of the |
298 |
| - /// provided nodes. |
299 |
| - /// @param Nodes The nodes to use for updating the graph. |
300 |
| - void update(const std::vector<node> &Nodes); |
301 |
| - |
302 |
| - /// Return the total amount of memory required by this graph for graph-owned |
303 |
| - /// memory allocations. |
304 |
| - size_t get_required_mem_size() const; |
305 |
| - |
306 |
| - /// Common Reference Semantics |
307 |
| - friend bool operator==(const executable_command_graph &LHS, |
308 |
| - const executable_command_graph &RHS) { |
309 |
| - return LHS.impl == RHS.impl; |
310 |
| - } |
311 |
| - friend bool operator!=(const executable_command_graph &LHS, |
312 |
| - const executable_command_graph &RHS) { |
313 |
| - return !operator==(LHS, RHS); |
314 |
| - } |
315 |
| - |
316 |
| -protected: |
317 |
| - /// Constructor used by internal runtime. |
318 |
| - /// @param Graph Detail implementation class to construct with. |
319 |
| - /// @param Ctx Context to use for graph. |
320 |
| - /// @param PropList Optional list of properties to pass. |
321 |
| - executable_command_graph(const std::shared_ptr<detail::graph_impl> &Graph, |
322 |
| - const sycl::context &Ctx, |
323 |
| - const property_list &PropList = {}); |
324 |
| - |
325 |
| - template <class Obj> |
326 |
| - friend const decltype(Obj::impl) & |
327 |
| - sycl::detail::getSyclObjImpl(const Obj &SyclObject); |
328 |
| - |
329 |
| - /// Creates a backend representation of the graph in \p impl member variable. |
330 |
| - void finalizeImpl(); |
331 |
| - |
332 |
| - std::shared_ptr<detail::exec_graph_impl> impl; |
333 |
| -}; |
334 | 86 | } // namespace detail
|
335 | 87 |
|
336 | 88 | /// Graph in the modifiable state.
|
|
0 commit comments