Skip to content

Commit d94af16

Browse files
feature: add waitWithKmdNotifyFallback to immediate cmdlist
- hostSynchronize() with infinite timeout may fallback to KmdNotify when kmdNotify is enabled Related-To: NEO-2024 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 0afcec9 commit d94af16

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,20 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::hostSynchronize(uint6
12421242
if (inOrderWaitAllowed) {
12431243
status = synchronizeInOrderExecution(timeout, (waitQueue == this->cmdQImmediateCopyOffload));
12441244
} else {
1245-
const int64_t timeoutInMicroSeconds = timeout / 1000;
1245+
12461246
const auto indefinitelyPoll = timeout == std::numeric_limits<uint64_t>::max();
1247-
const auto waitStatus = waitCsr->waitForCompletionWithTimeout(NEO::WaitParams{indefinitelyPoll, !indefinitelyPoll, false, timeoutInMicroSeconds}, waitTaskCount);
1247+
auto waitStatus = NEO::WaitStatus::notReady;
1248+
1249+
if (indefinitelyPoll) {
1250+
waitStatus = waitCsr->waitForTaskCountWithKmdNotifyFallback(waitTaskCount,
1251+
waitCsr->obtainCurrentFlushStamp(),
1252+
true,
1253+
NEO::QueueThrottle::MEDIUM);
1254+
} else {
1255+
const int64_t timeoutInMicroSeconds = timeout / 1000;
1256+
waitStatus = waitCsr->waitForCompletionWithTimeout(NEO::WaitParams{indefinitelyPoll, !indefinitelyPoll, false, timeoutInMicroSeconds}, waitTaskCount);
1257+
}
1258+
12481259
if (waitStatus == NEO::WaitStatus::gpuHang) {
12491260
status = ZE_RESULT_ERROR_DEVICE_LOST;
12501261
} else if (waitStatus == NEO::WaitStatus::notReady) {

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_1.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,6 +2414,7 @@ TEST_F(CommandListCreateTests, GivenGpuHangWhenCreatingImmCmdListWithSyncModeAnd
24142414

24152415
MockCommandStreamReceiver mockCommandStreamReceiver(*neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
24162416
mockCommandStreamReceiver.waitForCompletionWithTimeoutReturnValue = WaitStatus::gpuHang;
2417+
mockCommandStreamReceiver.waitForCompletionWithKmdNotifyFallbackReturnValue = WaitStatus::gpuHang;
24172418

24182419
auto queue = static_cast<WhiteBox<::L0::CommandQueue> *>(whiteBoxCmdList->cmdQImmediate);
24192420

@@ -2486,6 +2487,7 @@ HWTEST_F(CommandListCreateTests, GivenGpuHangWhenCreatingImmediateCommandListAnd
24862487

24872488
MockCommandStreamReceiver mockCommandStreamReceiver(*neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
24882489
mockCommandStreamReceiver.waitForCompletionWithTimeoutReturnValue = WaitStatus::gpuHang;
2490+
mockCommandStreamReceiver.waitForCompletionWithKmdNotifyFallbackReturnValue = WaitStatus::gpuHang;
24892491

24902492
auto queue = static_cast<WhiteBox<::L0::CommandQueue> *>(whiteBoxCmdList->cmdQImmediate);
24912493

@@ -2605,6 +2607,7 @@ HWTEST_F(CommandListCreateTests, GivenGpuHangWhenCreatingImmediateCommandListAnd
26052607

26062608
MockCommandStreamReceiver mockCommandStreamReceiver(*neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
26072609
mockCommandStreamReceiver.waitForCompletionWithTimeoutReturnValue = WaitStatus::gpuHang;
2610+
mockCommandStreamReceiver.waitForCompletionWithKmdNotifyFallbackReturnValue = WaitStatus::gpuHang;
26082611

26092612
auto queue = static_cast<WhiteBox<::L0::CommandQueue> *>(whiteBoxCmdList->cmdQImmediate);
26102613

@@ -2674,6 +2677,7 @@ HWTEST_F(CommandListCreateTests, GivenGpuHangAndEnabledFlushTaskSubmissionFlagWh
26742677

26752678
MockCommandStreamReceiver mockCommandStreamReceiver(*neoDevice->executionEnvironment, neoDevice->getRootDeviceIndex(), neoDevice->getDeviceBitfield());
26762679
mockCommandStreamReceiver.waitForCompletionWithTimeoutReturnValue = WaitStatus::gpuHang;
2680+
mockCommandStreamReceiver.waitForCompletionWithKmdNotifyFallbackReturnValue = WaitStatus::gpuHang;
26772681

26782682
auto queue = static_cast<WhiteBox<::L0::CommandQueue> *>(whiteBoxCmdList->cmdQImmediate);
26792683

level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_8.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,14 +1616,18 @@ HWTEST_F(ImmediateCommandListHostSynchronize, givenMaxTimeoutIsProvidedWaitParam
16161616

16171617
auto cmdList = createCmdList<FamilyType::gfxCoreFamily>(csr);
16181618

1619+
csr->captureWaitForTaskCountWithKmdNotifyInputParams = true;
1620+
16191621
csr->callBaseWaitForCompletionWithTimeout = false;
16201622
csr->returnWaitForCompletionWithTimeout = WaitStatus::ready;
16211623

16221624
EXPECT_EQ(cmdList->hostSynchronize(std::numeric_limits<uint64_t>::max()), ZE_RESULT_SUCCESS);
16231625

16241626
auto waitParams = csr->latestWaitForCompletionWithTimeoutWaitParams;
16251627
EXPECT_FALSE(waitParams.enableTimeout);
1626-
EXPECT_TRUE(waitParams.indefinitelyPoll);
1628+
EXPECT_FALSE(waitParams.indefinitelyPoll);
1629+
1630+
EXPECT_NE(0u, csr->waitForTaskCountWithKmdNotifyInputParams.size());
16271631
}
16281632

16291633
using CommandListHostSynchronize = Test<DeviceFixture>;

shared/test/common/mocks/mock_command_stream_receiver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
185185
}
186186

187187
WaitStatus waitForTaskCountWithKmdNotifyFallback(TaskCountType taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, QueueThrottle throttle) override {
188-
return WaitStatus::ready;
188+
return waitForCompletionWithKmdNotifyFallbackReturnValue;
189189
}
190190

191191
WaitStatus waitForTaskCountWithKmdNotifyFallback(TaskCountType taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) {
192-
return WaitStatus::ready;
192+
return waitForCompletionWithKmdNotifyFallbackReturnValue;
193193
}
194194

195195
TaskCountType flushBcsTask(const BlitPropertiesContainer &blitPropertiesContainer, bool blocking, Device &device) override { return taskCount; };
@@ -320,6 +320,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver {
320320
std::optional<bool> isGpuHangDetectedReturnValue{};
321321
std::optional<bool> testTaskCountReadyReturnValue{};
322322
WaitStatus waitForCompletionWithTimeoutReturnValue{WaitStatus::ready};
323+
WaitStatus waitForCompletionWithKmdNotifyFallbackReturnValue{WaitStatus::ready};
323324
CommandStreamReceiverType commandStreamReceiverType = CommandStreamReceiverType::hardware;
324325
BatchBuffer latestFlushedBatchBuffer = {};
325326
QueueThrottle getLastDirectSubmissionThrottleReturnValue = QueueThrottle::MEDIUM;

0 commit comments

Comments
 (0)