Skip to content

Commit 1b4ceb3

Browse files
Use KMD wait function for infinite timeout synchronization
Related-To: NEO-5845 Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
1 parent 6486b35 commit 1b4ceb3

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

level_zero/core/source/cmdqueue/cmdqueue.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ void CommandQueueImp::submitBatchBuffer(size_t offset, NEO::ResidencyContainer &
7878
}
7979

8080
ze_result_t CommandQueueImp::synchronize(uint64_t timeout) {
81-
return synchronizeByPollingForTaskCount(timeout);
81+
if (timeout == std::numeric_limits<uint64_t>::max()) {
82+
auto &waitPair = buffers.getCurrentFlushStamp();
83+
csr->waitForTaskCountWithKmdNotifyFallback(waitPair.first, waitPair.second, false, false);
84+
return ZE_RESULT_SUCCESS;
85+
} else {
86+
return synchronizeByPollingForTaskCount(timeout);
87+
}
8288
}
8389

8490
ze_result_t CommandQueueImp::synchronizeByPollingForTaskCount(uint64_t timeout) {
@@ -87,10 +93,6 @@ ze_result_t CommandQueueImp::synchronizeByPollingForTaskCount(uint64_t timeout)
8793
auto taskCountToWait = getTaskCount();
8894
bool enableTimeout = true;
8995
int64_t timeoutMicroseconds = static_cast<int64_t>(timeout);
90-
if (timeout == std::numeric_limits<uint64_t>::max()) {
91-
enableTimeout = false;
92-
timeoutMicroseconds = NEO::TimeoutControls::maxTimeout;
93-
}
9496

9597
csr->waitForCompletionWithTimeout(enableTimeout, timeoutMicroseconds, this->taskCount);
9698

level_zero/core/source/cmdqueue/cmdqueue_imp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct CommandQueueImp : public CommandQueue {
4646
void setCurrentFlushStamp(uint32_t taskCount, NEO::FlushStamp flushStamp) {
4747
flushId[bufferUse] = std::make_pair(taskCount, flushStamp);
4848
}
49+
std::pair<uint32_t, NEO::FlushStamp> &getCurrentFlushStamp() {
50+
return flushId[bufferUse];
51+
}
4952

5053
private:
5154
NEO::GraphicsAllocation *buffers[BUFFER_ALLOCATION::COUNT];

level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,20 +1402,28 @@ HWTEST_F(CommandQueueSynchronizeTest, givenCallToSynchronizeThenCorrectEnableTim
14021402
~SynchronizeCsr() override {
14031403
delete tagAddress;
14041404
}
1405+
14051406
SynchronizeCsr(const NEO::ExecutionEnvironment &executionEnvironment, const DeviceBitfield deviceBitfield)
14061407
: NEO::UltCommandStreamReceiver<FamilyType>(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment), 0, deviceBitfield) {
14071408
tagAddress = new uint32_t;
14081409
}
1410+
14091411
bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) override {
14101412
waitForComplitionCalledTimes++;
14111413
return true;
14121414
}
14131415

1416+
void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool quickKmdSleep, bool forcePowerSavingMode) override {
1417+
waitForTaskCountWithKmdNotifyFallbackCalled++;
1418+
NEO::UltCommandStreamReceiver<FamilyType>::waitForTaskCountWithKmdNotifyFallback(taskCountToWait, flushStampToWait, quickKmdSleep, forcePowerSavingMode);
1419+
}
1420+
14141421
volatile uint32_t *getTagAddress() const override {
14151422
return tagAddress;
14161423
}
1417-
uint32_t waitForComplitionCalledTimes = 0;
14181424
uint32_t *tagAddress;
1425+
uint32_t waitForComplitionCalledTimes = 0;
1426+
uint32_t waitForTaskCountWithKmdNotifyFallbackCalled = 0;
14191427
};
14201428

14211429
auto csr = std::unique_ptr<SynchronizeCsr>(new SynchronizeCsr(*device->getNEODevice()->getExecutionEnvironment(),
@@ -1435,14 +1443,17 @@ HWTEST_F(CommandQueueSynchronizeTest, givenCallToSynchronizeThenCorrectEnableTim
14351443

14361444
queue->synchronize(timeout);
14371445

1438-
EXPECT_EQ(csr->waitForComplitionCalledTimes, 1u);
1446+
EXPECT_EQ(1u, csr->waitForComplitionCalledTimes);
1447+
EXPECT_EQ(0u, csr->waitForTaskCountWithKmdNotifyFallbackCalled);
1448+
14391449
timeout = std::numeric_limits<uint64_t>::max();
14401450
enableTimeoutExpected = false;
14411451
timeoutMicrosecondsExpected = NEO::TimeoutControls::maxTimeout;
14421452

14431453
queue->synchronize(timeout);
14441454

1445-
EXPECT_EQ(csr->waitForComplitionCalledTimes, 2u);
1455+
EXPECT_EQ(2u, csr->waitForComplitionCalledTimes);
1456+
EXPECT_EQ(1u, csr->waitForTaskCountWithKmdNotifyFallbackCalled);
14461457

14471458
L0::CommandQueue::fromHandle(commandQueue)->destroy();
14481459
}

0 commit comments

Comments
 (0)