From 421b1861e54f971a664fc3db515610358932f533 Mon Sep 17 00:00:00 2001 From: "Chandio, Bibrak Qamar" Date: Fri, 17 Oct 2025 06:06:32 +0000 Subject: [PATCH] fix: madvise order and reset Related-To: NEO-16173, NEO-13715 Signed-off-by: Chandio, Bibrak Qamar --- level_zero/core/source/cmdlist/cmdlist_hw.inl | 1 + .../core/source/cmdqueue/cmdqueue_hw.inl | 24 ++++++++++--------- .../cmdlist/test_cmdlist_append_memory.cpp | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw.inl b/level_zero/core/source/cmdlist/cmdlist_hw.inl index cc1e883719..0da6963592 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw.inl @@ -107,6 +107,7 @@ ze_result_t CommandListCoreFamily::reset() { this->storeFillPatternResourcesForReuse(); removeDeallocationContainerData(); removeHostPtrAllocations(); + this->memAdviseOperations.clear(); removeMemoryPrefetchAllocations(); commandContainer.reset(); clearCommandsToPatch(); diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl index af068ad0bf..f34fc1e159 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw.inl @@ -55,6 +55,14 @@ ze_result_t CommandQueueHw::createFence(const ze_fence_desc_t *de return ZE_RESULT_SUCCESS; } +template +void CommandQueueHw::processMemAdviseOperations(CommandList *commandList) { + auto &memAdviseOperations = commandList->getMemAdviseOperations(); + for (auto &operation : memAdviseOperations) { + commandList->executeMemAdvise(operation.hDevice, operation.ptr, operation.size, operation.advice); + } +} + template ze_result_t CommandQueueHw::executeCommandLists( uint32_t numCommandLists, @@ -83,6 +91,11 @@ ze_result_t CommandQueueHw::executeCommandLists( auto neoDevice = device->getNEODevice(); + for (auto i = 0u; i < numCommandLists; ++i) { + auto commandList = CommandList::fromHandle(phCommandLists[i]); + this->processMemAdviseOperations(commandList); + } + if (NEO::ApiSpecificConfig::isSharedAllocPrefetchEnabled()) { auto svmAllocMgr = device->getDriverHandle()->getSvmAllocsManager(); svmAllocMgr->prefetchSVMAllocs(*neoDevice, *csr); @@ -131,15 +144,6 @@ ze_result_t CommandQueueHw::executeCommandLists( return ret; } -template -void CommandQueueHw::processMemAdviseOperations(CommandList *commandList) { - auto &memAdviseOperations = commandList->getMemAdviseOperations(); - for (auto &operation : memAdviseOperations) { - commandList->executeMemAdvise(operation.hDevice, operation.ptr, operation.size, operation.advice); - } - memAdviseOperations.clear(); -} - template ze_result_t CommandQueueHw::executeCommandListsRegularHeapless( CommandListExecutionContext &ctx, @@ -217,7 +221,6 @@ ze_result_t CommandQueueHw::executeCommandListsRegularHeapless( cmdListWithAssertExecuted.exchange(true); } - this->processMemAdviseOperations(commandList); this->collectPrintfContentsFromCommandsList(commandList); this->dispatchPatchPreambleInOrderNoop(ctx, commandList); } @@ -442,7 +445,6 @@ ze_result_t CommandQueueHw::executeCommandListsRegular( cmdListWithAssertExecuted.exchange(true); } - this->processMemAdviseOperations(commandList); this->collectPrintfContentsFromCommandsList(commandList); this->dispatchPatchPreambleInOrderNoop(ctx, commandList); } diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp index b52be73cc8..5d9fe2ce7d 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_append_memory.cpp @@ -1202,7 +1202,7 @@ HWTEST2_F(AppendMemoryCopyFenceTest, givenAppendMemAdviseWithRegularAndHeapLessC cmdList.close(); mockCmdQHw->executeCommandLists(1, &cmdListHandle, nullptr, false, nullptr, nullptr); EXPECT_EQ(1u, cmdList.executeMemAdviseCallCount); - EXPECT_EQ(0u, cmdList.getMemAdviseOperations().size()); + EXPECT_EQ(1u, cmdList.getMemAdviseOperations().size()); } { @@ -1212,7 +1212,7 @@ HWTEST2_F(AppendMemoryCopyFenceTest, givenAppendMemAdviseWithRegularAndHeapLessC cmdList.close(); mockCmdQHw->executeCommandLists(1, &cmdListHandle, nullptr, false, nullptr, nullptr); EXPECT_EQ(2u, cmdList.executeMemAdviseCallCount); - EXPECT_EQ(0u, cmdList.getMemAdviseOperations().size()); + EXPECT_EQ(1u, cmdList.getMemAdviseOperations().size()); } context->freeMem(deviceBuffer);