Enhance wait method in L0 command queue

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2021-06-30 09:10:41 +00:00 committed by Compute-Runtime-Automation
parent 234b2a748e
commit fffa22b17d
3 changed files with 35 additions and 11 deletions

View File

@ -66,7 +66,7 @@ void CommandQueueImp::submitBatchBuffer(size_t offset, NEO::ResidencyContainer &
commandStream->getGraphicsAllocation()->updateResidencyTaskCount(csr->peekTaskCount() + 1, csr->getOsContext().getContextId());
csr->submitBatchBuffer(batchBuffer, csr->getResidencyAllocations());
buffers.setCurrentFlushStamp(csr->obtainCurrentFlushStamp());
buffers.setCurrentFlushStamp(csr->peekTaskCount(), csr->obtainCurrentFlushStamp());
}
ze_result_t CommandQueueImp::synchronize(uint64_t timeout) {
@ -151,8 +151,8 @@ ze_result_t CommandQueueImp::CommandBufferManager::initialize(Device *device, si
memset(buffers[BUFFER_ALLOCATION::FIRST]->getUnderlyingBuffer(), 0, buffers[BUFFER_ALLOCATION::FIRST]->getUnderlyingBufferSize());
memset(buffers[BUFFER_ALLOCATION::SECOND]->getUnderlyingBuffer(), 0, buffers[BUFFER_ALLOCATION::SECOND]->getUnderlyingBufferSize());
flushId[BUFFER_ALLOCATION::FIRST] = 0u;
flushId[BUFFER_ALLOCATION::SECOND] = 0u;
flushId[BUFFER_ALLOCATION::FIRST] = std::make_pair(0u, 0u);
flushId[BUFFER_ALLOCATION::SECOND] = std::make_pair(0u, 0u);
return ZE_RESULT_SUCCESS;
}
@ -174,10 +174,10 @@ void CommandQueueImp::CommandBufferManager::switchBuffers(NEO::CommandStreamRece
bufferUse = BUFFER_ALLOCATION::FIRST;
}
NEO::FlushStamp completionId = flushId[bufferUse];
if (completionId != 0u) {
auto completionId = flushId[bufferUse];
if (completionId.second != 0u) {
UNRECOVERABLE_IF(csr == nullptr);
csr->waitForFlushStamp(completionId);
csr->waitForTaskCountWithKmdNotifyFallback(completionId.first, completionId.second, false, false);
}
}

View File

@ -43,13 +43,13 @@ struct CommandQueueImp : public CommandQueue {
return buffers[bufferUse];
}
void setCurrentFlushStamp(NEO::FlushStamp flushStamp) {
flushId[bufferUse] = flushStamp;
void setCurrentFlushStamp(uint32_t taskCount, NEO::FlushStamp flushStamp) {
flushId[bufferUse] = std::make_pair(taskCount, flushStamp);
}
private:
NEO::GraphicsAllocation *buffers[BUFFER_ALLOCATION::COUNT];
NEO::FlushStamp flushId[BUFFER_ALLOCATION::COUNT];
std::pair<uint32_t, NEO::FlushStamp> flushId[BUFFER_ALLOCATION::COUNT];
BUFFER_ALLOCATION bufferUse = BUFFER_ALLOCATION::FIRST;
};
static constexpr size_t defaultQueueCmdBufferSize = 128 * MemoryConstants::kiloByte;

View File

@ -98,7 +98,7 @@ TEST_F(CommandQueueCreate, whenSynchronizeByPollingTaskCountThenCallsPrintOutput
commandQueue->destroy();
}
TEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched) {
HWTEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched) {
const ze_command_queue_desc_t desc{};
ze_result_t returnValue;
@ -115,14 +115,38 @@ TEST_F(CommandQueueCreate, whenReserveLinearStreamThenBufferAllocationSwitched)
auto firstAllocation = commandQueue->commandStream->getGraphicsAllocation();
EXPECT_EQ(firstAllocation, commandQueue->buffers.getCurrentBufferAllocation());
uint32_t currentTaskCount = 33u;
auto &csr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
csr.latestWaitForCompletionWithTimeoutTaskCount = currentTaskCount;
commandQueue->commandStream->getSpace(maxSize - 16u);
commandQueue->buffers.setCurrentFlushStamp(121u, 121u);
size_t nextSize = 16u + 16u;
commandQueue->reserveLinearStreamSize(nextSize);
auto secondAllocation = commandQueue->commandStream->getGraphicsAllocation();
EXPECT_EQ(secondAllocation, commandQueue->buffers.getCurrentBufferAllocation());
EXPECT_NE(firstAllocation, secondAllocation);
EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, currentTaskCount);
commandQueue->commandStream->getSpace(maxSize - 16u);
commandQueue->buffers.setCurrentFlushStamp(244u, 244u);
commandQueue->reserveLinearStreamSize(nextSize);
auto thirdAllocation = commandQueue->commandStream->getGraphicsAllocation();
EXPECT_EQ(thirdAllocation, commandQueue->buffers.getCurrentBufferAllocation());
EXPECT_EQ(thirdAllocation, firstAllocation);
EXPECT_NE(thirdAllocation, secondAllocation);
EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, 121u);
commandQueue->commandStream->getSpace(maxSize - 16u);
commandQueue->reserveLinearStreamSize(nextSize);
auto fourthAllocation = commandQueue->commandStream->getGraphicsAllocation();
EXPECT_EQ(fourthAllocation, commandQueue->buffers.getCurrentBufferAllocation());
EXPECT_EQ(fourthAllocation, secondAllocation);
EXPECT_NE(fourthAllocation, firstAllocation);
EXPECT_EQ(csr.latestWaitForCompletionWithTimeoutTaskCount, 244u);
commandQueue->destroy();
}