From b496274d1ae293d032791be1e4a4ee32d1960ad8 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Wed, 21 May 2025 17:06:09 +0000 Subject: [PATCH] fix: enable single temporary allocations list mode Related-To: NEO-14641 Signed-off-by: Bartosz Dunajski --- shared/source/memory_manager/memory_manager.cpp | 16 +++++++++------- .../common/fixtures/memory_allocator_fixture.h | 9 +-------- .../memory_manager/host_ptr_manager_tests.cpp | 14 +++++++------- .../unit_test/utilities/tag_allocator_tests.cpp | 1 + 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 3cdd731cba..c916f47564 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -92,7 +92,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu supportsMultiStorageResources = !!debugManager.flags.EnableMultiStorageResources.get(); } - if (debugManager.flags.UseSingleListForTemporaryAllocations.get() == 1) { + if (debugManager.flags.UseSingleListForTemporaryAllocations.get() != 0) { singleTemporaryAllocationsList = true; temporaryAllocations = std::make_unique(AllocationUsage::TEMPORARY_ALLOCATION); } @@ -115,14 +115,16 @@ void MemoryManager::cleanTemporaryAllocations(const CommandStreamReceiver &csr, auto *nextAlloc = currentAlloc->next; bool freeAllocation = false; - if (currentAlloc->isUsedByOsContext(waitedOsContextId)) { - if (currentAlloc->hostPtrTaskCountAssignment == 0 && currentAlloc->getTaskCount(waitedOsContextId) <= waitedTaskCount) { - if (!currentAlloc->isUsedByManyOsContexts() || !allocInUse(*currentAlloc)) { - freeAllocation = true; + if (currentAlloc->hostPtrTaskCountAssignment == 0) { + if (currentAlloc->isUsedByOsContext(waitedOsContextId)) { + if (currentAlloc->getTaskCount(waitedOsContextId) <= waitedTaskCount) { + if (!currentAlloc->isUsedByManyOsContexts() || !allocInUse(*currentAlloc)) { + freeAllocation = true; + } } + } else if (!allocInUse(*currentAlloc)) { + freeAllocation = true; } - } else if (!allocInUse(*currentAlloc)) { - freeAllocation = true; } if (freeAllocation) { diff --git a/shared/test/common/fixtures/memory_allocator_fixture.h b/shared/test/common/fixtures/memory_allocator_fixture.h index c3e50ff771..0fee7006b3 100644 --- a/shared/test/common/fixtures/memory_allocator_fixture.h +++ b/shared/test/common/fixtures/memory_allocator_fixture.h @@ -31,15 +31,8 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { executionEnvironment->calculateMaxOsContextCount(); device.reset(MockDevice::createWithExecutionEnvironment(defaultHwInfo.get(), executionEnvironment, 0u)); - memoryManager = new MockMemoryManager(false, false, *executionEnvironment); - executionEnvironment->memoryManager.reset(memoryManager); + memoryManager = static_cast(device->getMemoryManager()); csr = &device->getGpgpuCommandStreamReceiver(); - - auto &gfxCoreHelper = device->getGfxCoreHelper(); - auto engineType = gfxCoreHelper.getGpgpuEngineInstances(device->getRootDeviceEnvironment())[0].first; - auto osContext = memoryManager->createAndRegisterOsContext(csr, EngineDescriptorHelper::getDefaultDescriptor({engineType, EngineUsage::regular}, - PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo))); - csr->setupContext(*osContext); } void tearDown() { diff --git a/shared/test/unit_test/memory_manager/host_ptr_manager_tests.cpp b/shared/test/unit_test/memory_manager/host_ptr_manager_tests.cpp index a2e29f6d37..dbc7b52a07 100644 --- a/shared/test/unit_test/memory_manager/host_ptr_manager_tests.cpp +++ b/shared/test/unit_test/memory_manager/host_ptr_manager_tests.cpp @@ -1129,18 +1129,18 @@ HWTEST_F(HostPtrAllocationTest, givenSingleTempAllocationsListWhenAddingToStorag TEST_F(HostPtrAllocationTest, givenDebugFlagSetWhenCreatingMemoryManagerThenEnableSingleTempAllocationsList) { DebugManagerStateRestore debugRestorer; - { - auto memoryManager = std::make_unique(executionEnvironment); - EXPECT_FALSE(memoryManager->isSingleTemporaryAllocationsListEnabled()); - EXPECT_EQ(nullptr, memoryManager->temporaryAllocations.get()); - } - - debugManager.flags.UseSingleListForTemporaryAllocations.set(1); { auto memoryManager = std::make_unique(executionEnvironment); EXPECT_TRUE(memoryManager->isSingleTemporaryAllocationsListEnabled()); EXPECT_NE(nullptr, memoryManager->temporaryAllocations.get()); } + + debugManager.flags.UseSingleListForTemporaryAllocations.set(0); + { + auto memoryManager = std::make_unique(executionEnvironment); + EXPECT_FALSE(memoryManager->isSingleTemporaryAllocationsListEnabled()); + EXPECT_EQ(nullptr, memoryManager->temporaryAllocations.get()); + } } TEST_F(HostPtrAllocationTest, whenOverlappedFragmentIsBiggerThenStoredAndStoredFragmentCannotBeDestroyedThenCheckForOverlappingReturnsError) { diff --git a/shared/test/unit_test/utilities/tag_allocator_tests.cpp b/shared/test/unit_test/utilities/tag_allocator_tests.cpp index 5ac1e583e9..caec5e01e3 100644 --- a/shared/test/unit_test/utilities/tag_allocator_tests.cpp +++ b/shared/test/unit_test/utilities/tag_allocator_tests.cpp @@ -179,6 +179,7 @@ TEST_F(TagAllocatorTest, WhenGettingAndReturningTagThenFreeAndUsedListsAreUpdate TEST_F(TagAllocatorTest, WhenTagAllocatorIsCreatedThenItPopulatesTagsWithProperDeviceBitfield) { size_t alignment = 64; + memoryManager->recentlyPassedDeviceBitfield = 0; EXPECT_NE(deviceBitfield, memoryManager->recentlyPassedDeviceBitfield); MockTagAllocator tagAllocator(memoryManager, 10, alignment, deviceBitfield); EXPECT_EQ(deviceBitfield, memoryManager->recentlyPassedDeviceBitfield);