Skip to content

Commit

Permalink
[SYCL][Graph] Fix queue recording barrier to different graphs
Browse files Browse the repository at this point in the history
Recording barrier submissions to from the same queue to a different
graph current produces the following error with added regression test:

```
Terminate called after throwing an instance of 'sycl::_V1::exception'
  what():  Graph nodes cannot depend on events from another graph.
```

This is because the queue implementation doesn't clear all the
state around what the last queue submission was between graph
recordings.

Fixed by clearing all members of the barrier book keeping struct
in the queue.
  • Loading branch information
EwanC committed Jun 18, 2024
1 parent 57b8401 commit 7b85fb2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ class queue_impl {
std::shared_ptr<ext::oneapi::experimental::detail::graph_impl> Graph) {
std::lock_guard<std::mutex> Lock(MMutex);
MGraph = Graph;
MExtGraphDeps.LastEventPtr = nullptr;
MExtGraphDeps.reset();
}

std::shared_ptr<ext::oneapi::experimental::detail::graph_impl>
Expand Down Expand Up @@ -938,6 +938,12 @@ class queue_impl {
// ordering
std::vector<EventImplPtr> UnenqueuedCmdEvents;
EventImplPtr LastBarrier;

void reset() {
LastEventPtr = nullptr;
UnenqueuedCmdEvents.clear();
LastBarrier = nullptr;
}
} MDefaultGraphDeps, MExtGraphDeps;

const bool MIsInorder;
Expand Down
27 changes: 27 additions & 0 deletions sycl/unittests/Extensions/CommandGraph/Regressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,30 @@ TEST_F(CommandGraphTest, AccessorModeRegression) {
EXPECT_EQ(NodeC.get_predecessors().size(), 0ul);
EXPECT_EQ(NodeC.get_successors().size(), 0ul);
}

TEST_F(CommandGraphTest, QueueRecordBarrierMultipleGraph) {
// Test that using barriers recorded from the same queue to
// different graphs.

Graph.begin_recording(Queue);
auto NodeKernel = Queue.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
Queue.ext_oneapi_submit_barrier({NodeKernel});
Graph.end_recording(Queue);

experimental::command_graph<experimental::graph_state::modifiable> GraphB{
Queue};
GraphB.begin_recording(Queue);
auto NodeKernelB = Queue.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
Queue.ext_oneapi_submit_barrier({NodeKernelB});
GraphB.end_recording(Queue);

experimental::command_graph<experimental::graph_state::modifiable> GraphC{
Queue};
GraphC.begin_recording(Queue);
auto NodeKernelC = Queue.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<>>([]() {}); });
Queue.ext_oneapi_submit_barrier();
GraphC.end_recording(Queue);
}

0 comments on commit 7b85fb2

Please sign in to comment.