13
13
#include < list>
14
14
#include < set>
15
15
16
- // __SYCL_INLINE_NAMESPACE(cl) {
17
16
namespace sycl {
18
17
namespace ext {
19
18
namespace oneapi {
@@ -30,117 +29,117 @@ using graph_ptr = std::shared_ptr<graph_impl>;
30
29
31
30
class wrapper {
32
31
using T = std::function<void (sycl::handler &)>;
33
- T my_func ;
34
- std::vector<sycl::event> my_deps ;
32
+ T MFunc ;
33
+ std::vector<sycl::event> MDeps ;
35
34
36
35
public:
37
36
wrapper (T t, const std::vector<sycl::event> &deps)
38
- : my_func (t), my_deps (deps){};
37
+ : MFunc (t), MDeps (deps){};
39
38
40
39
void operator ()(sycl::handler &cgh) {
41
- cgh.depends_on (my_deps );
42
- std::invoke (my_func , cgh);
40
+ cgh.depends_on (MDeps );
41
+ std::invoke (MFunc , cgh);
43
42
}
44
43
};
45
44
46
45
struct node_impl {
47
- bool is_scheduled ;
46
+ bool MScheduled ;
48
47
49
- graph_ptr my_graph ;
50
- sycl::event my_event ;
48
+ graph_ptr MGraph ;
49
+ sycl::event MEvent ;
51
50
52
- std::vector<node_ptr> my_successors ;
53
- std::vector<node_ptr> my_predecessors ;
51
+ std::vector<node_ptr> MSuccessors ;
52
+ std::vector<node_ptr> MPredecessors ;
54
53
55
- std::function<void (sycl::handler &)> my_body ;
54
+ std::function<void (sycl::handler &)> MBody ;
56
55
57
56
void exec (sycl::queue q) {
58
- std::vector<sycl::event> __deps ;
59
- for (auto i : my_predecessors )
60
- __deps .push_back (i->get_event ());
61
- my_event = q.submit (wrapper{my_body, __deps });
57
+ std::vector<sycl::event> deps ;
58
+ for (auto i : MPredecessors )
59
+ deps .push_back (i->get_event ());
60
+ MEvent = q.submit (wrapper{MBody, deps });
62
61
}
63
62
64
63
void register_successor (node_ptr n) {
65
- my_successors .push_back (n);
64
+ MSuccessors .push_back (n);
66
65
n->register_predecessor (node_ptr (this ));
67
66
}
68
67
69
- void register_predecessor (node_ptr n) { my_predecessors .push_back (n); }
68
+ void register_predecessor (node_ptr n) { MPredecessors .push_back (n); }
70
69
71
- sycl::event get_event (void ) { return my_event ; }
70
+ sycl::event get_event (void ) { return MEvent ; }
72
71
73
72
template <typename T>
74
73
node_impl (graph_ptr g, T cgf)
75
- : is_scheduled (false ), my_graph (g), my_body (cgf) {}
74
+ : MScheduled (false ), MGraph (g), MBody (cgf) {}
76
75
77
76
// Recursively adding nodes to execution stack:
78
77
void topology_sort (std::list<node_ptr> &schedule) {
79
- is_scheduled = true ;
80
- for (auto i : my_successors ) {
81
- if (!i->is_scheduled )
78
+ MScheduled = true ;
79
+ for (auto i : MSuccessors ) {
80
+ if (!i->MScheduled )
82
81
i->topology_sort (schedule);
83
82
}
84
83
schedule.push_front (node_ptr (this ));
85
84
}
86
85
};
87
86
88
87
struct graph_impl {
89
- std::set<node_ptr> my_roots ;
90
- std::list<node_ptr> my_schedule ;
88
+ std::set<node_ptr> MRoots ;
89
+ std::list<node_ptr> MSchedule ;
91
90
// TODO: Change one time initialization to per executable object
92
- bool first ;
91
+ bool MFirst ;
93
92
94
- graph_ptr parent ;
93
+ graph_ptr MParent ;
95
94
96
95
void exec (sycl::queue q) {
97
- if (my_schedule .empty ()) {
98
- for (auto n : my_roots ) {
99
- n->topology_sort (my_schedule );
96
+ if (MSchedule .empty ()) {
97
+ for (auto n : MRoots ) {
98
+ n->topology_sort (MSchedule );
100
99
}
101
100
}
102
- for (auto n : my_schedule )
101
+ for (auto n : MSchedule )
103
102
n->exec (q);
104
103
}
105
104
106
105
void exec_and_wait (sycl::queue q) {
107
- if (first ) {
106
+ if (MFirst ) {
108
107
exec (q);
109
- first = false ;
108
+ MFirst = false ;
110
109
}
111
110
q.wait ();
112
111
}
113
112
114
113
void add_root (node_ptr n) {
115
- my_roots .insert (n);
116
- for (auto n : my_schedule )
117
- n->is_scheduled = false ;
118
- my_schedule .clear ();
114
+ MRoots .insert (n);
115
+ for (auto n : MSchedule )
116
+ n->MScheduled = false ;
117
+ MSchedule .clear ();
119
118
}
120
119
121
120
void remove_root (node_ptr n) {
122
- my_roots .erase (n);
123
- for (auto n : my_schedule )
124
- n->is_scheduled = false ;
125
- my_schedule .clear ();
121
+ MRoots .erase (n);
122
+ for (auto n : MSchedule )
123
+ n->MScheduled = false ;
124
+ MSchedule .clear ();
126
125
}
127
126
128
- graph_impl () : first (true ) {}
127
+ graph_impl () : MFirst (true ) {}
129
128
};
130
129
131
130
} // namespace detail
132
131
133
132
struct node {
134
- detail::node_ptr my_node ;
135
- detail::graph_ptr my_graph ;
133
+ detail::node_ptr MNode ;
134
+ detail::graph_ptr MGraph ;
136
135
137
136
template <typename T>
138
137
node (detail::graph_ptr g, T cgf)
139
- : my_graph (g), my_node (new detail::node_impl(g, cgf)){};
140
- void register_successor (node n) { my_node ->register_successor (n.my_node ); }
141
- void exec (sycl::queue q, sycl::event = sycl::event()) { my_node ->exec (q); }
138
+ : MGraph (g), MNode (new detail::node_impl(g, cgf)){};
139
+ void register_successor (node n) { MNode ->register_successor (n.MNode ); }
140
+ void exec (sycl::queue q, sycl::event = sycl::event()) { MNode ->exec (q); }
142
141
143
- void set_root () { my_graph ->add_root (my_node ); }
142
+ void set_root () { MGraph ->add_root (MNode ); }
144
143
};
145
144
146
145
enum class graph_state { modifiable, executable };
@@ -162,63 +161,63 @@ template <graph_state State = graph_state::modifiable> class command_graph {
162
161
command_graph<graph_state::executable>
163
162
finalize (const sycl::context &syclContext) const ;
164
163
165
- command_graph () : my_graph (new detail::graph_impl()) {}
164
+ command_graph () : MGraph (new detail::graph_impl()) {}
166
165
167
166
private:
168
- detail::graph_ptr my_graph ;
167
+ detail::graph_ptr MGraph ;
169
168
};
170
169
171
170
template <> class command_graph <graph_state::executable> {
172
171
public:
173
- int my_tag ;
174
- const sycl::context &my_ctx ;
172
+ int MTag ;
173
+ const sycl::context &MCtx ;
175
174
176
175
void exec_and_wait (sycl::queue q);
177
176
178
177
command_graph () = delete ;
179
178
180
179
command_graph (detail::graph_ptr g, const sycl::context &ctx)
181
- : my_graph (g), my_ctx (ctx), my_tag (rand()) {}
180
+ : MGraph (g), MCtx (ctx), MTag (rand()) {}
182
181
183
182
private:
184
- detail::graph_ptr my_graph ;
183
+ detail::graph_ptr MGraph ;
185
184
};
186
185
187
186
template <>
188
187
template <typename T>
189
188
node command_graph<graph_state::modifiable>::add(T cgf,
190
189
const std::vector<node> &dep) {
191
- node _node (my_graph , cgf);
190
+ node ret_val (MGraph , cgf);
192
191
if (!dep.empty ()) {
193
192
for (auto n : dep)
194
- this ->make_edge (n, _node );
193
+ this ->make_edge (n, ret_val );
195
194
} else {
196
- _node .set_root ();
195
+ ret_val .set_root ();
197
196
}
198
- return _node ;
197
+ return ret_val ;
199
198
}
200
199
201
200
template <>
202
201
void command_graph<graph_state::modifiable>::make_edge(node sender,
203
202
node receiver) {
204
203
sender.register_successor (receiver); // register successor
205
- my_graph ->remove_root (receiver.my_node ); // remove receiver from root node
204
+ MGraph ->remove_root (receiver.MNode ); // remove receiver from root node
206
205
// list
207
206
}
208
207
209
208
template <>
210
209
command_graph<graph_state::executable>
211
210
command_graph<graph_state::modifiable>::finalize(
212
211
const sycl::context &ctx) const {
213
- return command_graph<graph_state::executable>{this ->my_graph , ctx};
212
+ return command_graph<graph_state::executable>{this ->MGraph , ctx};
214
213
}
215
214
216
215
void command_graph<graph_state::executable>::exec_and_wait(sycl::queue q) {
217
- my_graph ->exec_and_wait (q);
216
+ MGraph ->exec_and_wait (q);
218
217
};
219
218
220
219
} // namespace experimental
221
220
} // namespace oneapi
222
221
} // namespace ext
223
222
} // namespace sycl
224
- // } // __SYCL_INLINE_NAMESPACE(cl)
223
+
0 commit comments