|
10 | 10 | #include "SchedulerTestUtils.hpp" |
11 | 11 |
|
12 | 12 | using namespace cl::sycl; |
| 13 | +using namespace testing; |
13 | 14 |
|
14 | 15 | TEST_F(SchedulerTest, BlockedCommands) { |
15 | 16 | MockCommand MockCmd(detail::getSyclObjImpl(MQueue)); |
@@ -45,3 +46,87 @@ TEST_F(SchedulerTest, BlockedCommands) { |
45 | 46 | Res.MResult == detail::EnqueueResultT::SyclEnqueueSuccess) |
46 | 47 | << "The command is expected to be successfully enqueued.\n"; |
47 | 48 | } |
| 49 | + |
| 50 | +TEST_F(SchedulerTest, DontEnqueueDepsIfOneOfThemIsBlocked) { |
| 51 | + MockCommand A(detail::getSyclObjImpl(MQueue)); |
| 52 | + A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; |
| 53 | + A.MIsBlockable = true; |
| 54 | + A.MRetVal = CL_SUCCESS; |
| 55 | + |
| 56 | + MockCommand B(detail::getSyclObjImpl(MQueue)); |
| 57 | + B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; |
| 58 | + B.MIsBlockable = true; |
| 59 | + B.MRetVal = CL_SUCCESS; |
| 60 | + |
| 61 | + MockCommand C(detail::getSyclObjImpl(MQueue)); |
| 62 | + C.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; |
| 63 | + C.MIsBlockable = true; |
| 64 | + |
| 65 | + MockCommand D(detail::getSyclObjImpl(MQueue)); |
| 66 | + D.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; |
| 67 | + D.MIsBlockable = true; |
| 68 | + D.MRetVal = CL_SUCCESS; |
| 69 | + |
| 70 | + addEdge(&A, &B, nullptr); |
| 71 | + addEdge(&A, &C, nullptr); |
| 72 | + addEdge(&A, &D, nullptr); |
| 73 | + |
| 74 | + // We have such a graph: |
| 75 | + // |
| 76 | + // A |
| 77 | + // / | \ |
| 78 | + // B C D |
| 79 | + // |
| 80 | + // If C is blocked, we should not try to enqueue D. |
| 81 | + |
| 82 | + EXPECT_CALL(A, enqueue(_, _)).Times(0); |
| 83 | + EXPECT_CALL(B, enqueue(_, _)).Times(1); |
| 84 | + EXPECT_CALL(C, enqueue(_, _)).Times(0); |
| 85 | + EXPECT_CALL(D, enqueue(_, _)).Times(0); |
| 86 | + |
| 87 | + detail::EnqueueResultT Res; |
| 88 | + bool Enqueued = MockScheduler::enqueueCommand(&A, Res, detail::NON_BLOCKING); |
| 89 | + ASSERT_FALSE(Enqueued) << "Blocked command should not be enqueued\n"; |
| 90 | + ASSERT_EQ(detail::EnqueueResultT::SyclEnqueueBlocked, Res.MResult) |
| 91 | + << "Result of enqueueing blocked command should be BLOCKED.\n"; |
| 92 | + ASSERT_EQ(&C, Res.MCmd) << "Expected different failed command.\n"; |
| 93 | +} |
| 94 | + |
| 95 | +TEST_F(SchedulerTest, EnqueueBlockedCommandEarlyExit) { |
| 96 | + MockCommand A(detail::getSyclObjImpl(MQueue)); |
| 97 | + A.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueBlocked; |
| 98 | + A.MIsBlockable = true; |
| 99 | + |
| 100 | + MockCommand B(detail::getSyclObjImpl(MQueue)); |
| 101 | + B.MEnqueueStatus = detail::EnqueueResultT::SyclEnqueueReady; |
| 102 | + B.MRetVal = CL_OUT_OF_RESOURCES; |
| 103 | + |
| 104 | + addEdge(&A, &B, nullptr); |
| 105 | + |
| 106 | + // We have such a graph: |
| 107 | + // |
| 108 | + // A -> B |
| 109 | + // |
| 110 | + // If A is blocked, we should not try to enqueue B. |
| 111 | + |
| 112 | + EXPECT_CALL(A, enqueue(_, _)).Times(0); |
| 113 | + EXPECT_CALL(B, enqueue(_, _)).Times(0); |
| 114 | + |
| 115 | + detail::EnqueueResultT Res; |
| 116 | + bool Enqueued = MockScheduler::enqueueCommand(&A, Res, detail::NON_BLOCKING); |
| 117 | + ASSERT_FALSE(Enqueued) << "Blocked command should not be enqueued\n"; |
| 118 | + ASSERT_EQ(detail::EnqueueResultT::SyclEnqueueBlocked, Res.MResult) |
| 119 | + << "Result of enqueueing blocked command should be BLOCKED.\n"; |
| 120 | + ASSERT_EQ(&A, Res.MCmd) << "Expected different failed command.\n"; |
| 121 | + |
| 122 | + // But if the enqueue type is blocking we should not exit early. |
| 123 | + |
| 124 | + EXPECT_CALL(A, enqueue(_, _)).Times(0); |
| 125 | + EXPECT_CALL(B, enqueue(_, _)).Times(1); |
| 126 | + |
| 127 | + Enqueued = MockScheduler::enqueueCommand(&A, Res, detail::BLOCKING); |
| 128 | + ASSERT_FALSE(Enqueued) << "Blocked command should not be enqueued\n"; |
| 129 | + ASSERT_EQ(detail::EnqueueResultT::SyclEnqueueFailed, Res.MResult) |
| 130 | + << "Result of enqueueing blocked command should be BLOCKED.\n"; |
| 131 | + ASSERT_EQ(&B, Res.MCmd) << "Expected different failed command.\n"; |
| 132 | +} |
0 commit comments