Skip to content

Commit 1eca2fc

Browse files
Further splitted command_graph into modifiable and executable
1 parent 2668239 commit 1eca2fc

File tree

4 files changed

+329
-251
lines changed

4 files changed

+329
-251
lines changed

sycl/include/sycl/ext/oneapi/experimental/graph.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
#pragma once
1010

1111
#include "graph/command_graph.hpp"
12+
#include "graph/executable_graph.hpp"
1213
#include "graph/graph_dynamic.hpp"
1314
#include "graph/graph_node.hpp"
15+
#include "graph/modifiable_graph.hpp"

sycl/include/sycl/ext/oneapi/experimental/graph/command_graph.hpp

Lines changed: 3 additions & 251 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99

1010
#pragma once
1111

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"
1714
#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
2015

2116
#include <functional> // for function
2217
#include <memory> // for shared_ptr
@@ -26,22 +21,17 @@
2621
namespace sycl {
2722
inline namespace _V1 {
2823
// Forward declarations
29-
class handler;
3024
class queue;
3125
class device;
3226
class context;
27+
class property_list;
3328

3429
namespace ext {
3530
namespace oneapi {
3631
namespace experimental {
37-
// Forward declarations
38-
template <graph_state State> class command_graph;
39-
class dynamic_command_group;
40-
4132
namespace detail {
4233
// Forward declarations
4334
class graph_impl;
44-
class exec_graph_impl;
4535

4636
// List of sycl features and extensions which are not supported by graphs. Used
4737
// for throwing errors when these features are used with graphs.
@@ -93,244 +83,6 @@ UnsupportedFeatureToString(UnsupportedGraphFeatures Feature) {
9383
assert(false && "Unhandled graphs feature");
9484
return {};
9585
}
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-
};
33486
} // namespace detail
33587

33688
/// Graph in the modifiable state.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//==--------- executable_graph.hpp --- SYCL graph extension ----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
12+
#include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
13+
#include <sycl/ext/oneapi/experimental/detail/properties/graph_properties.hpp> // for graph_state
14+
#include <sycl/ext/oneapi/experimental/graph/graph_node.hpp> // for node class
15+
#include <sycl/property_list.hpp> // for property_list
16+
17+
#include <memory> // for shared_ptr
18+
#include <vector> // for vector
19+
20+
namespace sycl {
21+
inline namespace _V1 {
22+
// Forward declarations
23+
class context;
24+
25+
namespace ext {
26+
namespace oneapi {
27+
namespace experimental {
28+
namespace detail {
29+
// Forward declarations
30+
class graph_impl;
31+
class exec_graph_impl;
32+
33+
// Templateless executable command-graph base class.
34+
class __SYCL_EXPORT executable_command_graph
35+
: public sycl::detail::OwnerLessBase<executable_command_graph> {
36+
public:
37+
/// An executable command-graph is not user constructable.
38+
executable_command_graph() = delete;
39+
40+
/// Update the inputs & output of the graph.
41+
/// @param Graph Graph to use the inputs and outputs of.
42+
void update(const command_graph<graph_state::modifiable> &Graph);
43+
44+
/// Updates a single node in this graph based on the contents of the provided
45+
/// node.
46+
/// @param Node The node to use for updating the graph.
47+
void update(const node &Node);
48+
49+
/// Updates a number of nodes in this graph based on the contents of the
50+
/// provided nodes.
51+
/// @param Nodes The nodes to use for updating the graph.
52+
void update(const std::vector<node> &Nodes);
53+
54+
/// Return the total amount of memory required by this graph for graph-owned
55+
/// memory allocations.
56+
size_t get_required_mem_size() const;
57+
58+
/// Common Reference Semantics
59+
friend bool operator==(const executable_command_graph &LHS,
60+
const executable_command_graph &RHS) {
61+
return LHS.impl == RHS.impl;
62+
}
63+
friend bool operator!=(const executable_command_graph &LHS,
64+
const executable_command_graph &RHS) {
65+
return !operator==(LHS, RHS);
66+
}
67+
68+
protected:
69+
/// Constructor used by internal runtime.
70+
/// @param Graph Detail implementation class to construct with.
71+
/// @param Ctx Context to use for graph.
72+
/// @param PropList Optional list of properties to pass.
73+
executable_command_graph(const std::shared_ptr<detail::graph_impl> &Graph,
74+
const sycl::context &Ctx,
75+
const property_list &PropList = {});
76+
77+
template <class Obj>
78+
friend const decltype(Obj::impl) &
79+
sycl::detail::getSyclObjImpl(const Obj &SyclObject);
80+
81+
/// Creates a backend representation of the graph in \p impl member variable.
82+
void finalizeImpl();
83+
84+
std::shared_ptr<detail::exec_graph_impl> impl;
85+
};
86+
} // namespace detail
87+
} // namespace experimental
88+
} // namespace oneapi
89+
} // namespace ext
90+
91+
} // namespace _V1
92+
} // namespace sycl

0 commit comments

Comments
 (0)