From e52fa32271fabf4d6d7c7f733d320149481191b4 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Tue, 1 Jul 2025 10:20:14 +0000 Subject: [PATCH] fix: disable usm reuse if debugger enabled Related-To: NEO-6893 Signed-off-by: Dominik Dabek --- .../memory_manager/unified_memory_manager.cpp | 9 +++-- .../unified_memory_manager_cache_tests.cpp | 36 ++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index 64bcbc1aac..d1d6a1197e 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -929,7 +929,10 @@ void SVMAllocsManager::initUsmHostAllocationsCache() { } void SVMAllocsManager::initUsmAllocationsCaches(Device &device) { - bool usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled() && device.getProductHelper().isDeviceUsmAllocationReuseSupported(); + const bool debuggerEnabled = nullptr != device.getDebugger(); + bool usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled() && + device.getProductHelper().isDeviceUsmAllocationReuseSupported() && + !debuggerEnabled; if (debugManager.flags.ExperimentalEnableDeviceAllocationCache.get() != -1) { usmDeviceAllocationsCacheEnabled = !!debugManager.flags.ExperimentalEnableDeviceAllocationCache.get(); } @@ -938,7 +941,9 @@ void SVMAllocsManager::initUsmAllocationsCaches(Device &device) { this->initUsmDeviceAllocationsCache(device); } - bool usmHostAllocationsCacheEnabled = NEO::ApiSpecificConfig::isHostAllocationCacheEnabled() && device.getProductHelper().isHostUsmAllocationReuseSupported(); + bool usmHostAllocationsCacheEnabled = NEO::ApiSpecificConfig::isHostAllocationCacheEnabled() && + device.getProductHelper().isHostUsmAllocationReuseSupported() && + !debuggerEnabled; if (debugManager.flags.ExperimentalEnableHostAllocationCache.get() != -1) { usmHostAllocationsCacheEnabled = !!debugManager.flags.ExperimentalEnableHostAllocationCache.get(); } 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 e4b4df8b7e..ae1c799e9c 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 @@ -10,6 +10,7 @@ #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/raii_product_helper.h" #include "shared/test/common/mocks/mock_ail_configuration.h" +#include "shared/test/common/mocks/mock_debugger.h" #include "shared/test/common/mocks/mock_deferred_deleter.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" @@ -242,10 +243,10 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledAndMaxSizeZeroWh svmManager->cleanupUSMAllocCaches(); } -HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEnabledItIsEnabledIfProductHelperMethodReturnsTrue) { +HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigAndProductHelperAndDebuggerWhenCheckingIfEnabledThenEnableCorrectly) { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); auto deviceFactory = std::make_unique(1, 1); - auto device = deviceFactory->rootDevices[0]; + MockDevice *device = deviceFactory->rootDevices[0]; RAIIProductHelperFactory raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]); MockAILConfiguration mockAilConfigurationHelper; device->mockAilConfigurationHelper = &mockAilConfigurationHelper; @@ -279,6 +280,20 @@ HWTEST_F(SvmDeviceAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEn EXPECT_EQ(nullptr, svmManager->usmDeviceAllocationsCache); EXPECT_EQ(0u, device->usmReuseInfo.getMaxAllocationsSavedForReuseSize()); } + { + device->getRootDeviceEnvironmentRef().debugger.reset(new MockDebugger); + raii.mockProductHelper->isDeviceUsmAllocationReuseSupportedResult = true; + mockAilConfigurationHelper.limitAmountOfDeviceMemoryForRecyclingReturn = false; + device->initUsmReuseLimits(); + auto svmManager = std::make_unique(device->getMemoryManager()); + EXPECT_EQ(nullptr, svmManager->usmDeviceAllocationsCache); + svmManager->initUsmAllocationsCaches(*device); + EXPECT_EQ(nullptr, svmManager->usmDeviceAllocationsCache); + + device->getRootDeviceEnvironmentRef().debugger.reset(nullptr); + svmManager->initUsmAllocationsCaches(*device); + EXPECT_NE(nullptr, svmManager->usmDeviceAllocationsCache); + } } TEST_F(SvmDeviceAllocationCacheTest, givenAllocationCacheEnabledWhenDirectSubmissionLightActiveThenCleanerDisabled) { @@ -1249,10 +1264,10 @@ TEST_F(SvmHostAllocationCacheTest, givenAllocationCacheDisabledWhenCheckingIfEna EXPECT_EQ(nullptr, svmManager->usmHostAllocationsCache); } -HWTEST_F(SvmHostAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEnabledItIsEnabledIfProductHelperMethodReturnsTrue) { +HWTEST_F(SvmHostAllocationCacheTest, givenOclApiSpecificConfigAndProductHelperAndDebuggerWhenCheckingIfEnabledThenEnableCorrectly) { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); auto deviceFactory = std::make_unique(1, 1); - auto device = deviceFactory->rootDevices[0]; + MockDevice *device = deviceFactory->rootDevices[0]; device->initUsmReuseLimits(); RAIIProductHelperFactory raii(*device->getExecutionEnvironment()->rootDeviceEnvironments[0]); const auto expectedMaxSize = static_cast(0.02 * device->getMemoryManager()->getSystemSharedMemory(0u)); @@ -1274,6 +1289,19 @@ HWTEST_F(SvmHostAllocationCacheTest, givenOclApiSpecificConfigWhenCheckingIfEnab svmManager->initUsmAllocationsCaches(*device); EXPECT_NE(nullptr, svmManager->usmHostAllocationsCache); } + { + device->getRootDeviceEnvironmentRef().debugger.reset(new MockDebugger); + raii.mockProductHelper->isHostUsmAllocationReuseSupportedResult = true; + device->getMemoryManager()->initUsmReuseLimits(); + auto svmManager = std::make_unique(device->getMemoryManager()); + EXPECT_EQ(nullptr, svmManager->usmHostAllocationsCache); + svmManager->initUsmAllocationsCaches(*device); + EXPECT_EQ(nullptr, svmManager->usmHostAllocationsCache); + + device->getRootDeviceEnvironmentRef().debugger.reset(nullptr); + svmManager->initUsmAllocationsCaches(*device); + EXPECT_NE(nullptr, svmManager->usmHostAllocationsCache); + } } TEST_F(SvmHostAllocationCacheTest, givenReuseLimitFlagWhenInitUsmReuseLimitCalledThenLimitThresholdSetCorrectly) {