Skip to content

Commit 230c93c

Browse files
[SYCL] Make base classes for graph states (#9977)
This commit attempts to fix the exported symbols after #9728 by creating templateless base classes for the different graph class specializations. This is in line with how other classes export their symbols. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 78f09e6 commit 230c93c

File tree

4 files changed

+99
-81
lines changed

4 files changed

+99
-81
lines changed

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

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,18 @@ class depends_on : public ::sycl::detail::PropertyWithData<
8787
} // namespace node
8888
} // namespace property
8989

90-
/// Graph in the modifiable state.
91-
template <graph_state State = graph_state::modifiable>
92-
class __SYCL_EXPORT command_graph {
90+
template <graph_state State> class command_graph;
91+
92+
namespace detail {
93+
// Templateless modifiable command-graph base class.
94+
class __SYCL_EXPORT modifiable_command_graph {
9395
public:
9496
/// Constructor.
9597
/// @param SyclContext Context to use for graph.
9698
/// @param SyclDevice Device all nodes will be associated with.
9799
/// @param PropList Optional list of properties to pass.
98-
command_graph(const context &SyclContext, const device &SyclDevice,
99-
const property_list &PropList = {});
100+
modifiable_command_graph(const context &SyclContext, const device &SyclDevice,
101+
const property_list &PropList = {});
100102

101103
/// Add an empty node to the graph.
102104
/// @param PropList Property list used to pass [0..n] predecessor nodes.
@@ -166,10 +168,11 @@ class __SYCL_EXPORT command_graph {
166168
/// executing.
167169
bool end_recording(const std::vector<queue> &RecordingQueues);
168170

169-
private:
171+
protected:
170172
/// Constructor used internally by the runtime.
171173
/// @param Impl Detail implementation class to construct object with.
172-
command_graph(const std::shared_ptr<detail::graph_impl> &Impl) : impl(Impl) {}
174+
modifiable_command_graph(const std::shared_ptr<detail::graph_impl> &Impl)
175+
: impl(Impl) {}
173176

174177
/// Template-less implementation of add() for CGF nodes.
175178
/// @param CGF Command-group function to add.
@@ -192,21 +195,22 @@ class __SYCL_EXPORT command_graph {
192195
std::shared_ptr<detail::graph_impl> impl;
193196
};
194197

195-
template <> class __SYCL_EXPORT command_graph<graph_state::executable> {
198+
// Templateless executable command-graph base class.
199+
class __SYCL_EXPORT executable_command_graph {
196200
public:
197201
/// An executable command-graph is not user constructable.
198-
command_graph() = delete;
202+
executable_command_graph() = delete;
199203

200204
/// Update the inputs & output of the graph.
201205
/// @param Graph Graph to use the inputs and outputs of.
202206
void update(const command_graph<graph_state::modifiable> &Graph);
203207

204-
private:
208+
protected:
205209
/// Constructor used by internal runtime.
206210
/// @param Graph Detail implementation class to construct with.
207211
/// @param Ctx Context to use for graph.
208-
command_graph(const std::shared_ptr<detail::graph_impl> &Graph,
209-
const sycl::context &Ctx);
212+
executable_command_graph(const std::shared_ptr<detail::graph_impl> &Graph,
213+
const sycl::context &Ctx);
210214

211215
template <class Obj>
212216
friend decltype(Obj::impl)
@@ -218,7 +222,34 @@ template <> class __SYCL_EXPORT command_graph<graph_state::executable> {
218222
int MTag;
219223
std::shared_ptr<detail::exec_graph_impl> impl;
220224

221-
friend class command_graph<graph_state::modifiable>;
225+
friend class modifiable_command_graph;
226+
};
227+
} // namespace detail
228+
229+
/// Graph in the modifiable state.
230+
template <graph_state State = graph_state::modifiable>
231+
class command_graph : public detail::modifiable_command_graph {
232+
public:
233+
/// Constructor.
234+
/// @param SyclContext Context to use for graph.
235+
/// @param SyclDevice Device all nodes will be associated with.
236+
/// @param PropList Optional list of properties to pass.
237+
command_graph(const context &SyclContext, const device &SyclDevice,
238+
const property_list &PropList = {})
239+
: modifiable_command_graph(SyclContext, SyclDevice, PropList) {}
240+
241+
private:
242+
/// Constructor used internally by the runtime.
243+
/// @param Impl Detail implementation class to construct object with.
244+
command_graph(const std::shared_ptr<detail::graph_impl> &Impl)
245+
: modifiable_command_graph(Impl) {}
246+
};
247+
248+
template <>
249+
class command_graph<graph_state::executable>
250+
: public detail::executable_command_graph {
251+
private:
252+
using detail::executable_command_graph::executable_command_graph;
222253
};
223254

224255
/// Additional CTAD deduction guide.

sycl/source/detail/graph_impl.cpp

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,13 @@ sycl::event exec_graph_impl::enqueue(
275275
sycl::detail::createSyclObjFromImpl<sycl::event>(NewEvent);
276276
return QueueEvent;
277277
}
278-
} // namespace detail
279278

280-
template <>
281-
command_graph<graph_state::modifiable>::command_graph(
279+
modifiable_command_graph::modifiable_command_graph(
282280
const sycl::context &SyclContext, const sycl::device &SyclDevice,
283281
const sycl::property_list &)
284282
: impl(std::make_shared<detail::graph_impl>(SyclContext, SyclDevice)) {}
285283

286-
template <>
287-
node command_graph<graph_state::modifiable>::addImpl(
288-
const std::vector<node> &Deps) {
284+
node modifiable_command_graph::addImpl(const std::vector<node> &Deps) {
289285
std::vector<std::shared_ptr<detail::node_impl>> DepImpls;
290286
for (auto &D : Deps) {
291287
DepImpls.push_back(sycl::detail::getSyclObjImpl(D));
@@ -295,9 +291,8 @@ node command_graph<graph_state::modifiable>::addImpl(
295291
return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
296292
}
297293

298-
template <>
299-
node command_graph<graph_state::modifiable>::addImpl(
300-
std::function<void(handler &)> CGF, const std::vector<node> &Deps) {
294+
node modifiable_command_graph::addImpl(std::function<void(handler &)> CGF,
295+
const std::vector<node> &Deps) {
301296
std::vector<std::shared_ptr<detail::node_impl>> DepImpls;
302297
for (auto &D : Deps) {
303298
DepImpls.push_back(sycl::detail::getSyclObjImpl(D));
@@ -308,8 +303,7 @@ node command_graph<graph_state::modifiable>::addImpl(
308303
return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
309304
}
310305

311-
template <>
312-
void command_graph<graph_state::modifiable>::make_edge(node &Src, node &Dest) {
306+
void modifiable_command_graph::make_edge(node &Src, node &Dest) {
313307
std::shared_ptr<detail::node_impl> SenderImpl =
314308
sycl::detail::getSyclObjImpl(Src);
315309
std::shared_ptr<detail::node_impl> ReceiverImpl =
@@ -320,17 +314,13 @@ void command_graph<graph_state::modifiable>::make_edge(node &Src, node &Dest) {
320314
impl->removeRoot(ReceiverImpl); // remove receiver from root node list
321315
}
322316

323-
template <>
324317
command_graph<graph_state::executable>
325-
command_graph<graph_state::modifiable>::finalize(
326-
const sycl::property_list &) const {
318+
modifiable_command_graph::finalize(const sycl::property_list &) const {
327319
return command_graph<graph_state::executable>{this->impl,
328320
this->impl->getContext()};
329321
}
330322

331-
template <>
332-
bool command_graph<graph_state::modifiable>::begin_recording(
333-
queue &RecordingQueue) {
323+
bool modifiable_command_graph::begin_recording(queue &RecordingQueue) {
334324
auto QueueImpl = sycl::detail::getSyclObjImpl(RecordingQueue);
335325
if (QueueImpl->getCommandGraph() == nullptr) {
336326
QueueImpl->setCommandGraph(impl);
@@ -347,8 +337,7 @@ bool command_graph<graph_state::modifiable>::begin_recording(
347337
return false;
348338
}
349339

350-
template <>
351-
bool command_graph<graph_state::modifiable>::begin_recording(
340+
bool modifiable_command_graph::begin_recording(
352341
const std::vector<queue> &RecordingQueues) {
353342
bool QueueStateChanged = false;
354343
for (queue Queue : RecordingQueues) {
@@ -357,13 +346,9 @@ bool command_graph<graph_state::modifiable>::begin_recording(
357346
return QueueStateChanged;
358347
}
359348

360-
template <> bool command_graph<graph_state::modifiable>::end_recording() {
361-
return impl->clearQueues();
362-
}
349+
bool modifiable_command_graph::end_recording() { return impl->clearQueues(); }
363350

364-
template <>
365-
bool command_graph<graph_state::modifiable>::end_recording(
366-
queue &RecordingQueue) {
351+
bool modifiable_command_graph::end_recording(queue &RecordingQueue) {
367352
auto QueueImpl = sycl::detail::getSyclObjImpl(RecordingQueue);
368353
if (QueueImpl->getCommandGraph() == impl) {
369354
QueueImpl->setCommandGraph(nullptr);
@@ -380,8 +365,7 @@ bool command_graph<graph_state::modifiable>::end_recording(
380365
return false;
381366
}
382367

383-
template <>
384-
bool command_graph<graph_state::modifiable>::end_recording(
368+
bool modifiable_command_graph::end_recording(
385369
const std::vector<queue> &RecordingQueues) {
386370
bool QueueStateChanged = false;
387371
for (queue Queue : RecordingQueues) {
@@ -390,25 +374,26 @@ bool command_graph<graph_state::modifiable>::end_recording(
390374
return QueueStateChanged;
391375
}
392376

393-
command_graph<graph_state::executable>::command_graph(
377+
executable_command_graph::executable_command_graph(
394378
const std::shared_ptr<detail::graph_impl> &Graph, const sycl::context &Ctx)
395379
: MTag(rand()),
396380
impl(std::make_shared<detail::exec_graph_impl>(Ctx, Graph)) {
397381
finalizeImpl(); // Create backend representation for executable graph
398382
}
399383

400-
void command_graph<graph_state::executable>::finalizeImpl() {
384+
void executable_command_graph::finalizeImpl() {
401385
// Create PI command-buffers for each device in the finalized context
402386
impl->schedule();
403387
}
404388

405-
void command_graph<graph_state::executable>::update(
389+
void executable_command_graph::update(
406390
const command_graph<graph_state::modifiable> &Graph) {
407391
(void)Graph;
408392
throw sycl::exception(sycl::make_error_code(errc::invalid),
409393
"Method not yet implemented");
410394
}
411395

396+
} // namespace detail
412397
} // namespace experimental
413398
} // namespace oneapi
414399
} // namespace ext

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,20 +3661,20 @@ _ZN4sycl3_V13ext6oneapi10level_zero10make_queueERKNS0_7contextERKNS0_6deviceEmbb
36613661
_ZN4sycl3_V13ext6oneapi10level_zero11make_deviceERKNS0_8platformEm
36623662
_ZN4sycl3_V13ext6oneapi10level_zero12make_contextERKSt6vectorINS0_6deviceESaIS5_EEmb
36633663
_ZN4sycl3_V13ext6oneapi10level_zero13make_platformEm
3664-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE13end_recordingERKSt6vectorINS0_5queueESaIS8_EE
3665-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE13end_recordingERNS0_5queueE
3666-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE13end_recordingEv
3667-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE15begin_recordingERKSt6vectorINS0_5queueESaIS8_EE
3668-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE15begin_recordingERNS0_5queueE
3669-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE7addImplERKSt6vectorINS3_4nodeESaIS8_EE
3670-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE7addImplESt8functionIFvRNS0_7handlerEEERKSt6vectorINS3_4nodeESaISD_EE
3671-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE9make_edgeERNS3_4nodeES8_
3672-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EEC1ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
3673-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EEC2ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
3674-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE1EE12finalizeImplEv
3675-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE1EE6updateERKNS4_ILS5_0EEE
3676-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE1EEC1ERKSt10shared_ptrINS3_6detail10graph_implEERKNS0_7contextE
3677-
_ZN4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE1EEC2ERKSt10shared_ptrINS3_6detail10graph_implEERKNS0_7contextE
3664+
_ZN4sycl3_V13ext6oneapi12experimental6detail24executable_command_graph12finalizeImplEv
3665+
_ZN4sycl3_V13ext6oneapi12experimental6detail24executable_command_graph6updateERKNS3_13command_graphILNS3_11graph_stateE0EEE
3666+
_ZN4sycl3_V13ext6oneapi12experimental6detail24executable_command_graphC1ERKSt10shared_ptrINS4_10graph_implEERKNS0_7contextE
3667+
_ZN4sycl3_V13ext6oneapi12experimental6detail24executable_command_graphC2ERKSt10shared_ptrINS4_10graph_implEERKNS0_7contextE
3668+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph13end_recordingERKSt6vectorINS0_5queueESaIS7_EE
3669+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph13end_recordingERNS0_5queueE
3670+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph13end_recordingEv
3671+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph15begin_recordingERKSt6vectorINS0_5queueESaIS7_EE
3672+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph15begin_recordingERNS0_5queueE
3673+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph7addImplERKSt6vectorINS3_4nodeESaIS7_EE
3674+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph7addImplESt8functionIFvRNS0_7handlerEEERKSt6vectorINS3_4nodeESaISC_EE
3675+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph9make_edgeERNS3_4nodeES7_
3676+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC1ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
3677+
_ZN4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graphC2ERKNS0_7contextERKNS0_6deviceERKNS0_13property_listE
36783678
_ZN4sycl3_V13ext6oneapi15filter_selectorC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
36793679
_ZN4sycl3_V13ext6oneapi15filter_selectorC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
36803680
_ZN4sycl3_V13ext8codeplay12experimental14fusion_wrapper12start_fusionEv
@@ -4098,7 +4098,7 @@ _ZNK4sycl3_V115interop_handler12GetNativeMemEPNS0_6detail16AccessorImplHostE
40984098
_ZNK4sycl3_V115interop_handler14GetNativeQueueERi
40994099
_ZNK4sycl3_V116default_selectorclERKNS0_6deviceE
41004100
_ZNK4sycl3_V120accelerator_selectorclERKNS0_6deviceE
4101-
_ZNK4sycl3_V13ext6oneapi12experimental13command_graphILNS3_11graph_stateE0EE8finalizeERKNS0_13property_listE
4101+
_ZNK4sycl3_V13ext6oneapi12experimental6detail24modifiable_command_graph8finalizeERKNS0_13property_listE
41024102
_ZNK4sycl3_V13ext6oneapi15filter_selector13select_deviceEv
41034103
_ZNK4sycl3_V13ext6oneapi15filter_selector5resetEv
41044104
_ZNK4sycl3_V13ext6oneapi15filter_selectorclERKNS0_6deviceE

0 commit comments

Comments
 (0)