Skip to content

Commit 01e439b

Browse files
authored
[SYCL][Graph] Reuse recording queue when available for finalize (#20106)
There are two issues with the current implementation: - Creating a placeholder queue is adding overhead at `finalize()` to common path. - Queue properties are set to default when no queue can be reused at Graph `finalize()`.
1 parent 255a740 commit 01e439b

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@ graph_impl::add(std::shared_ptr<dynamic_command_group_impl> &DynCGImpl,
549549
return NodeImpl;
550550
}
551551

552+
std::shared_ptr<sycl::detail::queue_impl> graph_impl::getQueue() const {
553+
std::shared_ptr<sycl::detail::queue_impl> Return{};
554+
if (!MRecordingQueues.empty())
555+
Return = MRecordingQueues.begin()->lock();
556+
return Return;
557+
}
558+
552559
void graph_impl::addQueue(sycl::detail::queue_impl &RecordingQueue) {
553560
MRecordingQueues.insert(RecordingQueue.weak_from_this());
554561
}
@@ -870,10 +877,6 @@ exec_graph_impl::exec_graph_impl(sycl::context Context,
870877
const std::shared_ptr<graph_impl> &GraphImpl,
871878
const property_list &PropList)
872879
: MSchedule(), MGraphImpl(GraphImpl), MSyncPoints(),
873-
MQueueImpl(sycl::detail::queue_impl::create(
874-
*sycl::detail::getSyclObjImpl(GraphImpl->getDevice()),
875-
*sycl::detail::getSyclObjImpl(Context), sycl::async_handler{},
876-
sycl::property_list{})),
877880
MDevice(GraphImpl->getDevice()), MContext(Context), MRequirements(),
878881
MSchedulerDependencies(),
879882
MIsUpdatable(PropList.has_property<property::graph::updatable>()),
@@ -893,6 +896,15 @@ exec_graph_impl::exec_graph_impl(sycl::context Context,
893896
}
894897
// Copy nodes from GraphImpl and merge any subgraph nodes into this graph.
895898
duplicateNodes();
899+
900+
if (auto PlaceholderQueuePtr = GraphImpl->getQueue()) {
901+
MQueueImpl = PlaceholderQueuePtr;
902+
} else {
903+
MQueueImpl = sycl::detail::queue_impl::create(
904+
*sycl::detail::getSyclObjImpl(GraphImpl->getDevice()),
905+
*sycl::detail::getSyclObjImpl(Context), sycl::async_handler{},
906+
sycl::property_list{});
907+
}
896908
}
897909

898910
exec_graph_impl::~exec_graph_impl() {

sycl/source/detail/graph/graph_impl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class graph_impl : public std::enable_shared_from_this<graph_impl> {
172172
node_impl &add(std::shared_ptr<dynamic_command_group_impl> &DynCGImpl,
173173
nodes_range Deps);
174174

175+
std::shared_ptr<sycl::detail::queue_impl> getQueue() const;
176+
175177
/// Add a queue to the set of queues which are currently recording to this
176178
/// graph.
177179
/// @param RecordingQueue Queue to add to set.

sycl/source/interop_handle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ ur_native_handle_t interop_handle::getNativeContext() const {
6060

6161
ur_native_handle_t
6262
interop_handle::getNativeQueue(int32_t &NativeHandleDesc) const {
63-
return MQueue->getNative(NativeHandleDesc);
63+
if (MQueue != nullptr)
64+
return MQueue->getNative(NativeHandleDesc);
65+
return 0;
6466
}
6567

6668
ur_native_handle_t interop_handle::getNativeGraph() const {

0 commit comments

Comments
 (0)