diff --git a/sycl/source/detail/graph/graph_impl.cpp b/sycl/source/detail/graph/graph_impl.cpp index 9f878f0e8ea66..4a3534b59c518 100644 --- a/sycl/source/detail/graph/graph_impl.cpp +++ b/sycl/source/detail/graph/graph_impl.cpp @@ -705,6 +705,14 @@ void graph_impl::beginRecording(sycl::detail::queue_impl &Queue) { addQueue(Queue); } } +void graph_impl::endRecording() { + // Collect attribute(s) for recorded Graph + if (MRecordingQueues.size() == 1) { + if (auto ValidQueue = MRecordingQueues.begin()->lock(); ValidQueue) { + MIsLinearRecorded = ValidQueue->isInOrder(); + } + } +} // Check if nodes do not require enqueueing and if so loop back through // predecessors until we find the real dependency. @@ -1262,6 +1270,11 @@ exec_graph_impl::enqueue(sycl::detail::queue_impl &Queue, } void exec_graph_impl::duplicateNodes() { + if (MGraphImpl->isLinearRecorded() && !MGraphImpl->hasSubGraph()) { + MNodeStorage = MGraphImpl->MNodeStorage; + return; + } + // Map of original modifiable nodes (keys) to new duplicated nodes (values) std::map NodesMap; @@ -1965,6 +1978,7 @@ void modifiable_command_graph::begin_recording( void modifiable_command_graph::end_recording() { graph_impl::WriteLock Lock(impl->MMutex); + impl->endRecording(); impl->clearQueues(); } diff --git a/sycl/source/detail/graph/graph_impl.hpp b/sycl/source/detail/graph/graph_impl.hpp index 10cbbfab0282c..ff827f507dfc0 100644 --- a/sycl/source/detail/graph/graph_impl.hpp +++ b/sycl/source/detail/graph/graph_impl.hpp @@ -474,6 +474,11 @@ class graph_impl : public std::enable_shared_from_this { /// of recording queues associated with this graph. /// @param[in] Queue The queue to be recorded from. void beginRecording(sycl::detail::queue_impl &Queue); + void endRecording(); + + bool isLinearRecorded() const { return MIsLinearRecorded; } + void setHasSubGraph() { MOriginGraphHasSubGraph = true; } + bool hasSubGraph() const { return MOriginGraphHasSubGraph; } /// Store the last barrier node that was submitted to the queue. /// @param[in] Queue The queue the barrier was recorded from. @@ -600,6 +605,11 @@ class graph_impl : public std::enable_shared_from_this { // The number of live executable graphs that have been created from this // modifiable graph std::atomic MExecGraphCount = 0; + + // True if the graph is recorded from a single in-order queue + bool MIsLinearRecorded = false; + // True if the graph contains subgraph when constructed by recording + bool MOriginGraphHasSubGraph = false; }; /// Class representing the implementation of command_graph. diff --git a/sycl/source/handler.cpp b/sycl/source/handler.cpp index fbcd88f1bd42a..fe61f823964df 100644 --- a/sycl/source/handler.cpp +++ b/sycl/source/handler.cpp @@ -788,6 +788,7 @@ event handler::finalize() { ParentLock = ext::oneapi::experimental::detail::graph_impl::WriteLock( ParentGraph->MMutex); } + ParentGraph->setHasSubGraph(); impl->CGData.MRequirements = impl->MExecGraph->getRequirements(); // Here we are using the CommandGroup without passing a CommandBuffer to // pass the exec_graph_impl and event dependencies. Since this subgraph CG