Skip to content

Commit 66d1b6b

Browse files
authored
Improve code location and replace shared ptr aliases (#82)
1 parent 62d6b15 commit 66d1b6b

File tree

6 files changed

+92
-87
lines changed

6 files changed

+92
-87
lines changed

sycl/include/sycl/detail/common.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,20 @@ struct code_location {
104104

105105
#ifndef DISABLE_SYCL_INSTRUMENTATION_METADATA
106106
#define _CODELOCONLYPARAM(a) \
107-
const detail::code_location a = detail::code_location::current()
107+
const ::sycl::detail::code_location a = \
108+
::sycl::detail::code_location::current()
108109
#define _CODELOCPARAM(a) \
109-
, const detail::code_location a = detail::code_location::current()
110-
#define _CODELOCPARAMDEF(a) , const detail::code_location a
110+
, const ::sycl::detail::code_location a = \
111+
::sycl::detail::code_location::current()
112+
#define _CODELOCPARAMDEF(a) , const ::sycl::detail::code_location a
111113

112114
#define _CODELOCARG(a)
113115
#define _CODELOCFW(a) , a
114116
#else
115117
#define _CODELOCONLYPARAM(a)
116118
#define _CODELOCPARAM(a)
117119

118-
#define _CODELOCARG(a) const detail::code_location a = {}
120+
#define _CODELOCARG(a) const ::sycl::detail::code_location a = {}
119121
#define _CODELOCFW(a)
120122
#endif
121123

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ namespace detail {
2828
struct node_impl;
2929
struct graph_impl;
3030

31-
using node_ptr = std::shared_ptr<node_impl>;
32-
using graph_ptr = std::shared_ptr<graph_impl>;
3331
} // namespace detail
3432

3533
enum class graph_state {
@@ -39,16 +37,16 @@ enum class graph_state {
3937

4038
class __SYCL_EXPORT node {
4139
private:
42-
node(detail::node_ptr Impl) : impl(Impl) {}
40+
node(const std::shared_ptr<detail::node_impl> &Impl) : impl(Impl) {}
4341

4442
template <class Obj>
4543
friend decltype(Obj::impl)
4644
sycl::detail::getSyclObjImpl(const Obj &SyclObject);
4745
template <class T>
4846
friend T sycl::detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
4947

50-
detail::node_ptr impl;
51-
detail::graph_ptr MGraph;
48+
std::shared_ptr<detail::node_impl> impl;
49+
std::shared_ptr<detail::graph_impl> MGraph;
5250
};
5351

5452
template <graph_state State = graph_state::modifiable>
@@ -106,7 +104,7 @@ class __SYCL_EXPORT command_graph {
106104
bool end_recording(const std::vector<queue> &recordingQueues);
107105

108106
private:
109-
command_graph(detail::graph_ptr Impl) : impl(Impl) {}
107+
command_graph(const std::shared_ptr<detail::graph_impl> &Impl) : impl(Impl) {}
110108

111109
// Template-less implementation of add()
112110
node add_impl(std::function<void(handler &)> cgf,
@@ -118,14 +116,15 @@ class __SYCL_EXPORT command_graph {
118116
template <class T>
119117
friend T sycl::detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
120118

121-
detail::graph_ptr impl;
119+
std::shared_ptr<detail::graph_impl> impl;
122120
};
123121

124122
template <> class __SYCL_EXPORT command_graph<graph_state::executable> {
125123
public:
126124
command_graph() = delete;
127125

128-
command_graph(detail::graph_ptr g, const sycl::context &ctx)
126+
command_graph(const std::shared_ptr<detail::graph_impl> &g,
127+
const sycl::context &ctx)
129128
: MTag(rand()), MCtx(ctx), impl(g) {}
130129

131130
private:
@@ -135,7 +134,7 @@ template <> class __SYCL_EXPORT command_graph<graph_state::executable> {
135134

136135
int MTag;
137136
const sycl::context &MCtx;
138-
detail::graph_ptr impl;
137+
std::shared_ptr<detail::graph_impl> impl;
139138
};
140139
} // namespace experimental
141140
} // namespace oneapi

sycl/include/sycl/queue.hpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <sycl/property_list.hpp>
2424
#include <sycl/stl.hpp>
2525

26-
2726
// Explicitly request format macros
2827
#ifndef __STDC_FORMAT_MACROS
2928
#define __STDC_FORMAT_MACROS 1
@@ -1075,9 +1074,9 @@ class __SYCL_EXPORT queue {
10751074
/// \return an event representing graph execution operation.
10761075
event ext_oneapi_graph(ext::oneapi::experimental::command_graph<
10771076
ext::oneapi::experimental::graph_state::executable>
1078-
Graph) {
1079-
const detail::code_location CodeLoc = {};
1080-
return submit([&](handler &CGH) { CGH.ext_oneapi_graph(Graph); }, CodeLoc);
1077+
Graph _CODELOCPARAM(&CodeLoc)) {
1078+
return submit(
1079+
[&](handler &CGH) { CGH.ext_oneapi_graph(Graph); } _CODELOCFW(CodeLoc));
10811080
}
10821081

10831082
/// Shortcut for executing a graph of commands.
@@ -1090,11 +1089,10 @@ class __SYCL_EXPORT queue {
10901089
ext::oneapi::experimental::graph_state::executable>
10911090
Graph,
10921091
event DepEvent _CODELOCPARAM(&CodeLoc)) {
1093-
return submit(
1094-
[&](handler &CGH) {
1095-
CGH.depends_on(DepEvent);
1096-
CGH.ext_oneapi_graph(Graph);
1097-
} _CODELOCFW(CodeLoc));
1092+
return submit([&](handler &CGH) {
1093+
CGH.depends_on(DepEvent);
1094+
CGH.ext_oneapi_graph(Graph);
1095+
} _CODELOCFW(CodeLoc));
10981096
}
10991097

11001098
/// Shortcut for executing a graph of commands.
@@ -1106,14 +1104,12 @@ class __SYCL_EXPORT queue {
11061104
event ext_oneapi_graph(ext::oneapi::experimental::command_graph<
11071105
ext::oneapi::experimental::graph_state::executable>
11081106
Graph,
1109-
const std::vector<event> &DepEvents) {
1110-
const detail::code_location CodeLoc = {};
1111-
return submit(
1112-
[&](handler &CGH) {
1113-
CGH.depends_on(DepEvents);
1114-
CGH.ext_oneapi_graph(Graph);
1115-
},
1116-
CodeLoc);
1107+
const std::vector<event> &DepEvents
1108+
_CODELOCPARAM(&CodeLoc)) {
1109+
return submit([&](handler &CGH) {
1110+
CGH.depends_on(DepEvents);
1111+
CGH.ext_oneapi_graph(Graph);
1112+
} _CODELOCFW(CodeLoc));
11171113
}
11181114

11191115
/// Returns whether the queue is in order or OoO

sycl/source/detail/graph_impl.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,12 @@
1313
namespace sycl {
1414
__SYCL_INLINE_VER_NAMESPACE(_V1) {
1515

16-
namespace detail {
17-
struct queue_impl;
18-
using queue_ptr = std::shared_ptr<queue_impl>;
19-
} // namespace detail
20-
2116
namespace ext {
2217
namespace oneapi {
2318
namespace experimental {
2419
namespace detail {
2520

26-
void graph_impl::exec(const sycl::detail::queue_ptr &q) {
21+
void graph_impl::exec(const std::shared_ptr<sycl::detail::queue_impl> &q) {
2722
if (MSchedule.empty()) {
2823
for (auto n : MRoots) {
2924
n->topology_sort(MSchedule);
@@ -33,7 +28,8 @@ void graph_impl::exec(const sycl::detail::queue_ptr &q) {
3328
n->exec(q);
3429
}
3530

36-
void graph_impl::exec_and_wait(const sycl::detail::queue_ptr &q) {
31+
void graph_impl::exec_and_wait(
32+
const std::shared_ptr<sycl::detail::queue_impl> &q) {
3733
bool isSubGraph = q->getIsGraphSubmitting();
3834
if (!isSubGraph) {
3935
q->setIsGraphSubmitting(true);
@@ -48,14 +44,14 @@ void graph_impl::exec_and_wait(const sycl::detail::queue_ptr &q) {
4844
}
4945
}
5046

51-
void graph_impl::add_root(node_ptr n) {
47+
void graph_impl::add_root(const std::shared_ptr<node_impl> &n) {
5248
MRoots.insert(n);
5349
for (auto n : MSchedule)
5450
n->MScheduled = false;
5551
MSchedule.clear();
5652
}
5753

58-
void graph_impl::remove_root(node_ptr n) {
54+
void graph_impl::remove_root(const std::shared_ptr<node_impl> &n) {
5955
MRoots.erase(n);
6056
for (auto n : MSchedule)
6157
n->MScheduled = false;
@@ -74,8 +70,10 @@ void graph_impl::remove_root(node_ptr n) {
7470
//
7571
// @returns True if a dependency was added in this node of any of its
7672
// successors.
77-
bool check_for_arg(const sycl::detail::ArgDesc &arg, node_ptr currentNode,
78-
std::set<node_ptr> &deps, bool dereferencePtr = false) {
73+
bool check_for_arg(const sycl::detail::ArgDesc &arg,
74+
const std::shared_ptr<node_impl> &currentNode,
75+
std::set<std::shared_ptr<node_impl>> &deps,
76+
bool dereferencePtr = false) {
7977
bool successorAddedDep = false;
8078
for (auto &successor : currentNode->MSuccessors) {
8179
successorAddedDep |= check_for_arg(arg, successor, deps, dereferencePtr);
@@ -90,14 +88,16 @@ bool check_for_arg(const sycl::detail::ArgDesc &arg, node_ptr currentNode,
9088
}
9189

9290
template <typename T>
93-
node_ptr graph_impl::add(graph_ptr impl, T cgf,
94-
const std::vector<sycl::detail::ArgDesc> &args,
95-
const std::vector<node_ptr> &dep) {
96-
node_ptr nodeImpl = std::make_shared<node_impl>(impl, cgf, args);
91+
std::shared_ptr<node_impl>
92+
graph_impl::add(const std::shared_ptr<graph_impl> &impl, T cgf,
93+
const std::vector<sycl::detail::ArgDesc> &args,
94+
const std::vector<std::shared_ptr<node_impl>> &dep) {
95+
std::shared_ptr<node_impl> nodeImpl =
96+
std::make_shared<node_impl>(impl, cgf, args);
9797
// Copy deps so we can modify them
9898
auto deps = dep;
9999
// A unique set of dependencies obtained by checking kernel arguments
100-
std::set<node_ptr> uniqueDeps;
100+
std::set<std::shared_ptr<node_impl>> uniqueDeps;
101101
for (auto &arg : args) {
102102
if (arg.MType != sycl::detail::kernel_param_kind_t::kind_pointer) {
103103
continue;
@@ -133,13 +133,13 @@ bool graph_impl::clear_queues() {
133133
return anyQueuesCleared;
134134
}
135135

136-
void node_impl::exec(sycl::detail::queue_ptr q) {
136+
void node_impl::exec(const std::shared_ptr<sycl::detail::queue_impl> &q
137+
_CODELOCPARAMDEF(&CodeLoc)) {
137138
std::vector<sycl::event> deps;
138139
for (auto i : MPredecessors)
139140
deps.push_back(i->get_event());
140141

141-
const sycl::detail::code_location CodeLoc;
142-
MEvent = q->submit(wrapper{MBody, deps}, q, CodeLoc);
142+
MEvent = q->submit(wrapper{MBody, deps}, q _CODELOCFW(CodeLoc));
143143
}
144144
} // namespace detail
145145

@@ -151,23 +151,26 @@ command_graph<graph_state::modifiable>::command_graph(
151151
template <>
152152
node command_graph<graph_state::modifiable>::add_impl(
153153
std::function<void(handler &)> cgf, const std::vector<node> &dep) {
154-
std::vector<detail::node_ptr> depImpls;
154+
std::vector<std::shared_ptr<detail::node_impl>> depImpls;
155155
for (auto &d : dep) {
156156
depImpls.push_back(sycl::detail::getSyclObjImpl(d));
157157
}
158158

159-
auto nodeImpl = impl->add(impl, cgf, {}, depImpls);
159+
std::shared_ptr<detail::node_impl> nodeImpl =
160+
impl->add(impl, cgf, {}, depImpls);
160161
return sycl::detail::createSyclObjFromImpl<node>(nodeImpl);
161162
}
162163

163164
template <>
164165
void command_graph<graph_state::modifiable>::make_edge(node sender,
165166
node receiver) {
166-
auto sender_impl = sycl::detail::getSyclObjImpl(sender);
167-
auto receiver_impl = sycl::detail::getSyclObjImpl(receiver);
167+
std::shared_ptr<detail::node_impl> senderImpl =
168+
sycl::detail::getSyclObjImpl(sender);
169+
std::shared_ptr<detail::node_impl> receiverImpl =
170+
sycl::detail::getSyclObjImpl(receiver);
168171

169-
sender_impl->register_successor(receiver_impl); // register successor
170-
impl->remove_root(receiver_impl); // remove receiver from root node list
172+
senderImpl->register_successor(receiverImpl); // register successor
173+
impl->remove_root(receiverImpl); // remove receiver from root node list
171174
}
172175

173176
template <>

0 commit comments

Comments
 (0)