From 4704cd49a3af9f0e33e010c6aead43e21e237970 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Fri, 26 Jan 2024 08:53:09 +0000 Subject: [PATCH] fix: Remove fence handling when reuse cmd buffer Resolves: NEO-10163 Related-To: NEO-7116 Signed-off-by: Lukasz Jobczyk --- .../core/source/cmdlist/cmdlist_imp.cpp | 2 - .../source/command_container/cmdcontainer.cpp | 21 +----- .../source/command_container/cmdcontainer.h | 3 - .../command_container_tests.cpp | 74 ------------------- 4 files changed, 1 insertion(+), 99 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_imp.cpp b/level_zero/core/source/cmdlist/cmdlist_imp.cpp index 6d004eac30..f8c8edd4e5 100644 --- a/level_zero/core/source/cmdlist/cmdlist_imp.cpp +++ b/level_zero/core/source/cmdlist/cmdlist_imp.cpp @@ -119,8 +119,6 @@ CommandList *CommandList::create(uint32_t productFamily, Device *device, NEO::En if (returnValue != ZE_RESULT_SUCCESS) { commandList->destroy(); commandList = nullptr; - } else { - commandList->getCmdContainer().setHandleFenceCompletionRequired(); } } diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index ee15720931..d314e50683 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -296,28 +296,9 @@ void CommandContainer::handleCmdBufferAllocations(size_t startIndex) { } for (size_t i = startIndex; i < cmdBufferAllocations.size(); i++) { if (this->reusableAllocationList) { - bool allocationHandled = false; - for (auto &engine : this->device->getMemoryManager()->getRegisteredEngines(cmdBufferAllocations[i]->getRootDeviceIndex())) { - auto osContextId = engine.osContext->getContextId(); - if (cmdBufferAllocations[i]->isUsedByOsContext(osContextId) && engine.commandStreamReceiver->isAnyDirectSubmissionEnabled()) { - auto lock = engine.commandStreamReceiver->obtainUniqueOwnership(); - auto taskCount = engine.commandStreamReceiver->peekTaskCount() + 1; - cmdBufferAllocations[i]->updateTaskCount(taskCount, osContextId); - cmdBufferAllocations[i]->updateResidencyTaskCount(taskCount, osContextId); - engine.commandStreamReceiver->flushTagUpdate(); - engine.commandStreamReceiver->waitForTaskCount(taskCount); - allocationHandled = true; - } - } - if (!allocationHandled && isHandleFenceCompletionRequired) { + if (isHandleFenceCompletionRequired) { this->device->getMemoryManager()->handleFenceCompletion(cmdBufferAllocations[i]); } - - for (auto &engine : this->device->getMemoryManager()->getRegisteredEngines(cmdBufferAllocations[i]->getRootDeviceIndex())) { - auto osContextId = engine.osContext->getContextId(); - cmdBufferAllocations[i]->releaseUsageInOsContext(osContextId); - } - reusableAllocationList->pushFrontOne(*cmdBufferAllocations[i]); } else { this->device->getMemoryManager()->freeGraphicsMemory(cmdBufferAllocations[i]); diff --git a/shared/source/command_container/cmdcontainer.h b/shared/source/command_container/cmdcontainer.h index 7a80305c0f..d38cbfe8fd 100644 --- a/shared/source/command_container/cmdcontainer.h +++ b/shared/source/command_container/cmdcontainer.h @@ -202,9 +202,6 @@ class CommandContainer : public NonCopyableOrMovableClass { return this->alignedPrimarySize; } void endAlignedPrimaryBuffer(); - void setHandleFenceCompletionRequired() { - this->isHandleFenceCompletionRequired = true; - } protected: size_t getAlignedCmdBufferSize() const; diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index d92c0e1599..28103231f2 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -302,66 +302,6 @@ TEST_F(CommandContainerTest, givenCmdContainerWithAllocsListWhenAllocateAndReset allocList.freeAllGraphicsAllocations(pDevice); } -HWTEST_F(CommandContainerTest, givenCmdContainerAndHandleFenceWithAllocsListWhenAllocateAndResetThenCmdBufferAllocIsReused) { - AllocationsList allocList; - auto cmdContainer = std::make_unique(); - cmdContainer->setHandleFenceCompletionRequired(); - cmdContainer->initialize(pDevice, &allocList, true, HeapSize::defaultHeapSize, false); - auto &cmdBufferAllocs = cmdContainer->getCmdBufferAllocations(); - auto memoryManager = static_cast(pDevice->getMemoryManager()); - auto csr = reinterpret_cast *>(memoryManager->getRegisteredEngines(0u)[0].commandStreamReceiver); - csr->directSubmissionAvailable = true; - csr->callFlushTagUpdate = false; - EXPECT_EQ(memoryManager->handleFenceCompletionCalled, 0u); - EXPECT_EQ(cmdBufferAllocs.size(), 1u); - EXPECT_TRUE(allocList.peekIsEmpty()); - - cmdContainer->allocateNextCommandBuffer(); - EXPECT_EQ(cmdBufferAllocs.size(), 2u); - - auto cmdBuffer0 = cmdBufferAllocs[0]; - auto cmdBuffer1 = cmdBufferAllocs[1]; - - cmdContainer->reset(); - EXPECT_EQ(memoryManager->handleFenceCompletionCalled, 1u); - EXPECT_EQ(cmdBufferAllocs.size(), 1u); - EXPECT_EQ(cmdBufferAllocs[0], cmdBuffer0); - EXPECT_FALSE(allocList.peekIsEmpty()); - EXPECT_FALSE(csr->stopDirectSubmissionCalled); - EXPECT_FALSE(csr->stopDirectSubmissionCalledBlocking); - - cmdContainer->allocateNextCommandBuffer(); - EXPECT_EQ(cmdBufferAllocs.size(), 2u); - cmdContainer->reset(); - EXPECT_EQ(memoryManager->handleFenceCompletionCalled, 2u); - EXPECT_EQ(cmdBufferAllocs.size(), 1u); - EXPECT_EQ(cmdBufferAllocs[0], cmdBuffer0); - EXPECT_FALSE(allocList.peekIsEmpty()); - EXPECT_FALSE(csr->stopDirectSubmissionCalled); - EXPECT_FALSE(csr->stopDirectSubmissionCalledBlocking); - - cmdContainer->allocateNextCommandBuffer(); - EXPECT_EQ(cmdBufferAllocs.size(), 2u); - EXPECT_EQ(cmdBufferAllocs[0], cmdBuffer0); - EXPECT_EQ(cmdBufferAllocs[1], cmdBuffer1); - EXPECT_TRUE(allocList.peekIsEmpty()); - EXPECT_FALSE(csr->stopDirectSubmissionCalled); - EXPECT_FALSE(csr->stopDirectSubmissionCalledBlocking); - cmdBuffer1->updateTaskCount(1u, 0u); - - cmdContainer.reset(); - - EXPECT_FALSE(csr->stopDirectSubmissionCalled); - EXPECT_FALSE(csr->stopDirectSubmissionCalledBlocking); - csr = reinterpret_cast *>(memoryManager->getRegisteredEngines(0u)[1].commandStreamReceiver); - EXPECT_FALSE(csr->stopDirectSubmissionCalled); - EXPECT_FALSE(csr->stopDirectSubmissionCalledBlocking); - EXPECT_EQ(memoryManager->handleFenceCompletionCalled, 3u); - EXPECT_FALSE(allocList.peekIsEmpty()); - cmdBuffer1->releaseUsageInOsContext(0u); - allocList.freeAllGraphicsAllocations(pDevice); -} - TEST_F(CommandContainerTest, givenReusableAllocationsAndRemoveUserFenceInCmdlistResetAndDestroyFlagWhenAllocateAndResetThenHandleFenceCompletionIsCalled) { DebugManagerStateRestore restore; debugManager.flags.RemoveUserFenceInCmdlistResetAndDestroy.set(0); @@ -375,21 +315,14 @@ TEST_F(CommandContainerTest, givenReusableAllocationsAndRemoveUserFenceInCmdlist EXPECT_EQ(cmdBufferAllocs.size(), 1u); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - cmdContainer->reset(); EXPECT_EQ(1u, memoryManager->handleFenceCompletionCalled); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - - cmdBufferAllocs[1]->updateTaskCount(2u, 0u); cmdContainer->reset(); EXPECT_EQ(2u, memoryManager->handleFenceCompletionCalled); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - EXPECT_FALSE(cmdBufferAllocs[1]->isUsedByOsContext(0u)); - - cmdBufferAllocs[0]->updateTaskCount(5u, 0u); - cmdBufferAllocs[1]->updateTaskCount(5u, 0u); cmdContainer.reset(); EXPECT_EQ(4u, memoryManager->handleFenceCompletionCalled); allocList.freeAllGraphicsAllocations(pDevice); @@ -408,21 +341,14 @@ TEST_F(CommandContainerTest, givenReusableAllocationsAndRemoveUserFenceInCmdlist EXPECT_EQ(cmdBufferAllocs.size(), 1u); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - cmdContainer->reset(); EXPECT_EQ(0u, memoryManager->handleFenceCompletionCalled); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - - cmdBufferAllocs[1]->updateTaskCount(2u, 0u); cmdContainer->reset(); EXPECT_EQ(0u, memoryManager->handleFenceCompletionCalled); cmdContainer->allocateNextCommandBuffer(); EXPECT_EQ(cmdBufferAllocs.size(), 2u); - EXPECT_FALSE(cmdBufferAllocs[1]->isUsedByOsContext(0u)); - - cmdBufferAllocs[0]->updateTaskCount(5u, 0u); - cmdBufferAllocs[1]->updateTaskCount(5u, 0u); cmdContainer.reset(); EXPECT_EQ(0u, memoryManager->handleFenceCompletionCalled); allocList.freeAllGraphicsAllocations(pDevice);