From c76edaba4e83427aeee7aa24e4cba7aad22dcd13 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Thu, 27 Mar 2025 13:38:30 +0000 Subject: [PATCH] fix: enable usm reuse limit based on memory usage Related-To: NEO-14160, NEO-6893 Signed-off-by: Dominik Dabek --- shared/source/device/device.cpp | 2 +- .../source/memory_manager/memory_manager.cpp | 4 ++-- .../unified_memory_manager_cache_tests.cpp | 20 +++++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index c9689ad6c8..9c84c11a9f 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -223,7 +223,7 @@ void Device::initUsmReuseLimits() { const auto totalDeviceMemory = this->getGlobalMemorySize(static_cast(this->getDeviceBitfield().to_ulong())); auto maxAllocationsSavedForReuseSize = static_cast(fractionOfTotalMemoryForRecycling * totalDeviceMemory); - auto limitAllocationsReuseThreshold = UsmReuseInfo::notLimited; + auto limitAllocationsReuseThreshold = static_cast(0.8 * totalDeviceMemory); const auto limitFlagValue = debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.get(); if (limitFlagValue != -1) { if (limitFlagValue == 0) { diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 6b3e3064d4..ce7372daf5 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -397,11 +397,11 @@ void MemoryManager::initUsmReuseLimits() { } auto maxAllocationsSavedForReuseSize = static_cast(fractionOfTotalMemoryForReuse * systemSharedMemorySize); - auto limitAllocationsReuseThreshold = std::numeric_limits::max(); + auto limitAllocationsReuseThreshold = static_cast(0.8 * systemSharedMemorySize); const auto limitFlagValue = debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.get(); if (limitFlagValue != -1) { if (limitFlagValue == 0) { - limitAllocationsReuseThreshold = std::numeric_limits::max(); + limitAllocationsReuseThreshold = UsmReuseInfo::notLimited; } else { const auto fractionOfTotalMemoryToLimitReuse = limitFlagValue / 100.0; limitAllocationsReuseThreshold = static_cast(fractionOfTotalMemoryToLimitReuse * systemSharedMemorySize); diff --git a/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp b/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp index 0ecd971e90..a6630e47f3 100644 --- a/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp +++ b/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp @@ -242,22 +242,22 @@ TEST_F(SvmDeviceAllocationCacheTest, givenReuseLimitFlagWhenInitUsmReuseLimitCal DebugManagerStateRestore restore; debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(0); device->initUsmReuseLimits(); - const auto expectedLimitThreshold = std::numeric_limits::max(); - EXPECT_EQ(expectedLimitThreshold, device->usmReuseInfo.getLimitAllocationsReuseThreshold()); + EXPECT_EQ(UsmReuseInfo::notLimited, device->usmReuseInfo.getLimitAllocationsReuseThreshold()); } { DebugManagerStateRestore restore; - debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(80); + debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(70); device->initUsmReuseLimits(); const auto totalDeviceMemory = device->getGlobalMemorySize(static_cast(device->getDeviceBitfield().to_ulong())); - const auto expectedLimitThreshold = static_cast(0.8 * totalDeviceMemory); + const auto expectedLimitThreshold = static_cast(0.7 * totalDeviceMemory); EXPECT_EQ(expectedLimitThreshold, device->usmReuseInfo.getLimitAllocationsReuseThreshold()); } { DebugManagerStateRestore restore; debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(-1); device->initUsmReuseLimits(); - const auto expectedLimitThreshold = std::numeric_limits::max(); + const auto totalDeviceMemory = device->getGlobalMemorySize(static_cast(device->getDeviceBitfield().to_ulong())); + const auto expectedLimitThreshold = static_cast(0.8 * totalDeviceMemory); EXPECT_EQ(expectedLimitThreshold, device->usmReuseInfo.getLimitAllocationsReuseThreshold()); } } @@ -1091,22 +1091,22 @@ TEST_F(SvmHostAllocationCacheTest, givenReuseLimitFlagWhenInitUsmReuseLimitCalle DebugManagerStateRestore restore; debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(0); memoryManager->initUsmReuseLimits(); - const auto expectedLimitThreshold = std::numeric_limits::max(); - EXPECT_EQ(expectedLimitThreshold, memoryManager->usmReuseInfo.getLimitAllocationsReuseThreshold()); + EXPECT_EQ(UsmReuseInfo::notLimited, memoryManager->usmReuseInfo.getLimitAllocationsReuseThreshold()); } { DebugManagerStateRestore restore; - debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(80); + debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(70); memoryManager->initUsmReuseLimits(); const auto systemSharedMemory = memoryManager->getSystemSharedMemory(device->getRootDeviceIndex()); - const auto expectedLimitThreshold = static_cast(0.8 * systemSharedMemory); + const auto expectedLimitThreshold = static_cast(0.7 * systemSharedMemory); EXPECT_EQ(expectedLimitThreshold, memoryManager->usmReuseInfo.getLimitAllocationsReuseThreshold()); } { DebugManagerStateRestore restore; debugManager.flags.ExperimentalUSMAllocationReuseLimitThreshold.set(-1); memoryManager->initUsmReuseLimits(); - const auto expectedLimitThreshold = std::numeric_limits::max(); + const auto systemSharedMemory = memoryManager->getSystemSharedMemory(device->getRootDeviceIndex()); + const auto expectedLimitThreshold = static_cast(0.8 * systemSharedMemory); EXPECT_EQ(expectedLimitThreshold, memoryManager->usmReuseInfo.getLimitAllocationsReuseThreshold()); } }