Skip to content

Commit

Permalink
[SYCL][Graph] Fix In-order queue unitests single context bug (#249)
Browse files Browse the repository at this point in the history
Changes In-order queue unitests to use the same context
for the recorded Queue and the Graph.
  • Loading branch information
mfrancepillois authored Jul 6, 2023
1 parent d624663 commit 39bd68a
Showing 1 changed file with 56 additions and 36 deletions.
92 changes: 56 additions & 36 deletions sycl/unittests/Extensions/CommandGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,22 +365,26 @@ TEST_F(CommandGraphTest, RecordSubGraph) {
TEST_F(CommandGraphTest, InOrderQueue) {
sycl::property_list Properties{sycl::property::queue::in_order()};
sycl::queue InOrderQueue{Dev, Properties};
experimental::command_graph<experimental::graph_state::modifiable>
InOrderGraph{InOrderQueue.get_context(), InOrderQueue.get_device()};

// Record in-order queue with three nodes
Graph.begin_recording(InOrderQueue);
InOrderGraph.begin_recording(InOrderQueue);
auto Node1Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode1 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode1 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode1, nullptr);
ASSERT_TRUE(PtrNode1->MPredecessors.empty());

auto Node2Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode2 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode2 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode2, nullptr);
ASSERT_NE(PtrNode2, PtrNode1);
ASSERT_EQ(PtrNode1->MSuccessors.size(), 1lu);
Expand All @@ -391,19 +395,20 @@ TEST_F(CommandGraphTest, InOrderQueue) {
auto Node3Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode3 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode3 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode3, nullptr);
ASSERT_NE(PtrNode3, PtrNode2);
ASSERT_EQ(PtrNode2->MSuccessors.size(), 1lu);
ASSERT_EQ(PtrNode2->MSuccessors.front(), PtrNode3);
ASSERT_EQ(PtrNode3->MPredecessors.size(), 1lu);
ASSERT_EQ(PtrNode3->MPredecessors.front().lock(), PtrNode2);

Graph.end_recording(InOrderQueue);
InOrderGraph.end_recording(InOrderQueue);

// Finalize main graph and check schedule
auto GraphExec = Graph.finalize();
auto GraphExec = InOrderGraph.finalize();
auto GraphExecImpl = sycl::detail::getSyclObjImpl(GraphExec);
auto Schedule = GraphExecImpl->getSchedule();
auto ScheduleIt = Schedule.begin();
Expand All @@ -419,22 +424,26 @@ TEST_F(CommandGraphTest, InOrderQueue) {
TEST_F(CommandGraphTest, InOrderQueueWithEmpty) {
sycl::property_list Properties{sycl::property::queue::in_order()};
sycl::queue InOrderQueue{Dev, Properties};
experimental::command_graph<experimental::graph_state::modifiable>
InOrderGraph{InOrderQueue.get_context(), InOrderQueue.get_device()};

// Record in-order queue with a regular node then empty node then a regular
// node
Graph.begin_recording(InOrderQueue);
InOrderGraph.begin_recording(InOrderQueue);
auto Node1Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode1 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode1 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode1, nullptr);
ASSERT_TRUE(PtrNode1->MPredecessors.empty());

auto Node2Graph = InOrderQueue.submit([&](sycl::handler &cgh) {});

auto PtrNode2 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode2 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode2, nullptr);
ASSERT_NE(PtrNode2, PtrNode1);
ASSERT_EQ(PtrNode1->MSuccessors.size(), 1lu);
Expand All @@ -445,20 +454,21 @@ TEST_F(CommandGraphTest, InOrderQueueWithEmpty) {
auto Node3Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode3 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode3 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode3, nullptr);
ASSERT_NE(PtrNode3, PtrNode2);
ASSERT_EQ(PtrNode2->MSuccessors.size(), 1lu);
ASSERT_EQ(PtrNode2->MSuccessors.front(), PtrNode3);
ASSERT_EQ(PtrNode3->MPredecessors.size(), 1lu);
ASSERT_EQ(PtrNode3->MPredecessors.front().lock(), PtrNode2);

Graph.end_recording(InOrderQueue);
InOrderGraph.end_recording(InOrderQueue);

// Finalize main graph and check schedule
// Note that empty nodes are not scheduled
auto GraphExec = Graph.finalize();
auto GraphExec = InOrderGraph.finalize();
auto GraphExecImpl = sycl::detail::getSyclObjImpl(GraphExec);
auto Schedule = GraphExecImpl->getSchedule();
auto ScheduleIt = Schedule.begin();
Expand All @@ -472,21 +482,25 @@ TEST_F(CommandGraphTest, InOrderQueueWithEmpty) {
TEST_F(CommandGraphTest, InOrderQueueWithEmptyFirst) {
sycl::property_list Properties{sycl::property::queue::in_order()};
sycl::queue InOrderQueue{Dev, Properties};
experimental::command_graph<experimental::graph_state::modifiable>
InOrderGraph{InOrderQueue.get_context(), InOrderQueue.get_device()};

// Record in-order queue with an empty node then two regular nodes
Graph.begin_recording(InOrderQueue);
InOrderGraph.begin_recording(InOrderQueue);
auto Node1Graph = InOrderQueue.submit([&](sycl::handler &cgh) {});

auto PtrNode1 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode1 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode1, nullptr);
ASSERT_TRUE(PtrNode1->MPredecessors.empty());

auto Node2Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode2 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode2 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode2, nullptr);
ASSERT_NE(PtrNode2, PtrNode1);
ASSERT_EQ(PtrNode1->MSuccessors.size(), 1lu);
Expand All @@ -497,20 +511,21 @@ TEST_F(CommandGraphTest, InOrderQueueWithEmptyFirst) {
auto Node3Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode3 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode3 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode3, nullptr);
ASSERT_NE(PtrNode3, PtrNode2);
ASSERT_EQ(PtrNode2->MSuccessors.size(), 1lu);
ASSERT_EQ(PtrNode2->MSuccessors.front(), PtrNode3);
ASSERT_EQ(PtrNode3->MPredecessors.size(), 1lu);
ASSERT_EQ(PtrNode3->MPredecessors.front().lock(), PtrNode2);

Graph.end_recording(InOrderQueue);
InOrderGraph.end_recording(InOrderQueue);

// Finalize main graph and check schedule
// Note that empty nodes are not scheduled
auto GraphExec = Graph.finalize();
auto GraphExec = InOrderGraph.finalize();
auto GraphExecImpl = sycl::detail::getSyclObjImpl(GraphExec);
auto Schedule = GraphExecImpl->getSchedule();
auto ScheduleIt = Schedule.begin();
Expand All @@ -524,22 +539,26 @@ TEST_F(CommandGraphTest, InOrderQueueWithEmptyFirst) {
TEST_F(CommandGraphTest, InOrderQueueWithEmptyLast) {
sycl::property_list Properties{sycl::property::queue::in_order()};
sycl::queue InOrderQueue{Dev, Properties};
experimental::command_graph<experimental::graph_state::modifiable>
InOrderGraph{InOrderQueue.get_context(), InOrderQueue.get_device()};

// Record in-order queue with two regular nodes then an empty node
Graph.begin_recording(InOrderQueue);
InOrderGraph.begin_recording(InOrderQueue);
auto Node1Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode1 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode1 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode1, nullptr);
ASSERT_TRUE(PtrNode1->MPredecessors.empty());

auto Node2Graph = InOrderQueue.submit(
[&](sycl::handler &cgh) { cgh.single_task<class TestKernel>([]() {}); });

auto PtrNode2 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode2 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode2, nullptr);
ASSERT_NE(PtrNode2, PtrNode1);
ASSERT_EQ(PtrNode1->MSuccessors.size(), 1lu);
Expand All @@ -549,20 +568,21 @@ TEST_F(CommandGraphTest, InOrderQueueWithEmptyLast) {

auto Node3Graph = InOrderQueue.submit([&](sycl::handler &cgh) {});

auto PtrNode3 = sycl::detail::getSyclObjImpl(Graph)->getLastInorderNode(
sycl::detail::getSyclObjImpl(InOrderQueue));
auto PtrNode3 =
sycl::detail::getSyclObjImpl(InOrderGraph)
->getLastInorderNode(sycl::detail::getSyclObjImpl(InOrderQueue));
ASSERT_NE(PtrNode3, nullptr);
ASSERT_NE(PtrNode3, PtrNode2);
ASSERT_EQ(PtrNode2->MSuccessors.size(), 1lu);
ASSERT_EQ(PtrNode2->MSuccessors.front(), PtrNode3);
ASSERT_EQ(PtrNode3->MPredecessors.size(), 1lu);
ASSERT_EQ(PtrNode3->MPredecessors.front().lock(), PtrNode2);

Graph.end_recording(InOrderQueue);
InOrderGraph.end_recording(InOrderQueue);

// Finalize main graph and check schedule
// Note that empty nodes are not scheduled
auto GraphExec = Graph.finalize();
auto GraphExec = InOrderGraph.finalize();
auto GraphExecImpl = sycl::detail::getSyclObjImpl(GraphExec);
auto Schedule = GraphExecImpl->getSchedule();
auto ScheduleIt = Schedule.begin();
Expand Down

0 comments on commit 39bd68a

Please sign in to comment.