From be7c202ca19c8be029f437c7fe6456684b170d13 Mon Sep 17 00:00:00 2001 From: Julian Miller Date: Mon, 26 Jun 2023 15:34:27 +0200 Subject: [PATCH] Merge pull request #237 from reble/julianmi/fix-double-root-nodes Fix adding empty nodes to the graph results in two root nodes --- sycl/source/detail/graph_impl.cpp | 3 --- sycl/source/detail/graph_impl.hpp | 9 +++------ sycl/source/handler.cpp | 13 +++++-------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/sycl/source/detail/graph_impl.cpp b/sycl/source/detail/graph_impl.cpp index 9cd1c0d6ab1b6..e0a1b48d9a746 100644 --- a/sycl/source/detail/graph_impl.cpp +++ b/sycl/source/detail/graph_impl.cpp @@ -146,9 +146,6 @@ graph_impl::add(const std::shared_ptr &Impl, if (Handler.MSubgraphNode) { return Handler.MSubgraphNode; } - if (Handler.MCGType == sycl::detail::CG::None) { - return this->add(Dep); - } return this->add(Handler.MCGType, std::move(Handler.MGraphNodeCG), Dep); } diff --git a/sycl/source/detail/graph_impl.hpp b/sycl/source/detail/graph_impl.hpp index 8ffa5d047570e..525852290e2cf 100644 --- a/sycl/source/detail/graph_impl.hpp +++ b/sycl/source/detail/graph_impl.hpp @@ -43,9 +43,6 @@ class node_impl { /// Command group object which stores all args etc needed to enqueue the node std::unique_ptr MCommandGroup; - /// True if an empty node, false otherwise. - bool MIsEmpty = false; - /// Add successor to the node. /// @param Node Node to add as a successor. /// @param Prev Predecessor to \p node being added as successor. @@ -65,7 +62,7 @@ class node_impl { } /// Construct an empty node. - node_impl() : MIsEmpty(true) {} + node_impl() {} /// Construct a node representing a command-group. /// @param CGType Type of the command-group. @@ -106,7 +103,7 @@ class node_impl { /// Query if this is an empty node. /// @return True if this is an empty node, false otherwise. - bool isEmpty() const { return MIsEmpty; } + bool isEmpty() const { return MCGType == sycl::detail::CG::None; } /// Get a deep copy of this node's command group /// @return A unique ptr to the new command group object. @@ -366,7 +363,7 @@ class exec_graph_impl { /// Turns the internal graph representation into UR command-buffers for a /// device. - /// @param D Device to create backend command-buffers for. + /// @param Device Device to create backend command-buffers for. void createURCommandBuffers(sycl::device Device); /// Query for the context tied to this graph. diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index c72219d1a463d..20905d5d10f2d 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -380,23 +380,20 @@ event handler::finalize() { if (detail::pi::trace(detail::pi::TraceLevel::PI_TRACE_ALL)) { std::cout << "WARNING: An empty command group is submitted." << std::endl; } - std::shared_ptr GraphImpl; if (MGraph) { - GraphImpl = MGraph; + CommandGroup.reset( + new detail::CG(detail::CG::None, std::move(CGData), MCodeLoc)); + MGraphNodeCG = std::move(CommandGroup); } else if (auto QueueGraph = MQueue->getCommandGraph(); QueueGraph) { - GraphImpl = QueueGraph; - } - - if (GraphImpl) { auto EventImpl = std::make_shared(); // Extract relevant data from the handler and pass to graph to create a // new node representing this command group. std::shared_ptr NodeImpl = - GraphImpl->add(CGData.MEvents); + QueueGraph->add(CGData.MEvents); // Associate an event with this new node and return the event. - GraphImpl->addEventForNode(EventImpl, NodeImpl); + QueueGraph->addEventForNode(EventImpl, NodeImpl); return detail::createSyclObjFromImpl(EventImpl); }