From 00921d0929718032a6a6ec7950840c2eb6d9f491 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Tue, 17 Jun 2025 12:11:06 +0000 Subject: [PATCH] performance: enable l0 usm host pool disable in sysman ults, pooling breaks in tests that simulate device error Related-To: NEO-6893 Signed-off-by: Dominik Dabek --- .../source/helpers/api_specific_config_l0.cpp | 2 +- .../fixtures/memory_ipc_fixture.cpp | 3 +- .../sources/cmdqueue/test_cmdqueue_3.cpp | 1 + .../helper/api_specific_config_l0_tests.cpp | 2 +- .../sources/memory/test_memory_pooling.cpp | 32 +++++++++++++------ .../sysman/linux/mock_sysman_fixture.h | 4 ++- .../dg2/os_agnostic_product_helper_dg2.inl | 5 +++ .../lnl/product_helper_tests_lnl.cpp | 13 ++------ .../xe3_core/ptl/product_helper_tests_ptl.cpp | 15 ++------- .../dg2/product_config_helper_tests_dg2.cpp | 6 ++-- .../mtl/product_helper_tests_mtl.cpp | 13 ++------ 11 files changed, 46 insertions(+), 50 deletions(-) diff --git a/level_zero/core/source/helpers/api_specific_config_l0.cpp b/level_zero/core/source/helpers/api_specific_config_l0.cpp index 0244efe8ac..37ec0a99ad 100644 --- a/level_zero/core/source/helpers/api_specific_config_l0.cpp +++ b/level_zero/core/source/helpers/api_specific_config_l0.cpp @@ -64,7 +64,7 @@ bool ApiSpecificConfig::isDeviceUsmPoolingEnabled() { } bool ApiSpecificConfig::isHostUsmPoolingEnabled() { - return false; + return true; } ApiSpecificConfig::ApiType ApiSpecificConfig::getApiType() { diff --git a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp index 5a346b3b08..3a2a4e6c94 100644 --- a/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp +++ b/level_zero/core/test/unit_tests/fixtures/memory_ipc_fixture.cpp @@ -197,11 +197,12 @@ void MemoryExportImportWSLTest::SetUp() { } void MemoryExportImportWSLTest::TearDown() { - // cleanup pool before restoring memory manager + // cleanup pools before restoring memory manager for (auto device : driverHandle->devices) { device->getNEODevice()->cleanupUsmAllocationPool(); device->getNEODevice()->resetUsmAllocationPool(nullptr); } + driverHandle->usmHostMemAllocPool.cleanup(); driverHandle->setMemoryManager(prevMemoryManager); delete currMemoryManager; } diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_3.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_3.cpp index 2666885786..5f43de5ff2 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_3.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_3.cpp @@ -462,6 +462,7 @@ HWTEST_F(CommandQueueIndirectAllocations, givenDebugModeToTreatIndirectAllocatio device->getDriverHandle()->getSvmAllocsManager()->freeSVMAlloc(deviceAlloc); commandQueue->destroy(); + L0UltHelper::cleanupUsmAllocPools(driverHandle.get()); } HWTEST_F(CommandQueueIndirectAllocations, givenDeviceThatSupportsSubmittingIndirectAllocationsAsPackWhenIndirectAccessIsUsedThenWholePackIsMadeResident) { diff --git a/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp b/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp index b19dfcc24d..bb6ddb5d1c 100644 --- a/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp +++ b/level_zero/core/test/unit_tests/sources/helper/api_specific_config_l0_tests.cpp @@ -49,7 +49,7 @@ TEST(ApiSpecificConfigL0Tests, WhenCheckingIfHostDeviceAllocationCacheIsEnabledT } TEST(ApiSpecificConfigL0Tests, WhenCheckingIfUsmAllocPoolingIsEnabledThenReturnCorrectValue) { - EXPECT_FALSE(ApiSpecificConfig::isHostUsmPoolingEnabled()); + EXPECT_TRUE(ApiSpecificConfig::isHostUsmPoolingEnabled()); EXPECT_TRUE(ApiSpecificConfig::isDeviceUsmPoolingEnabled()); } diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory_pooling.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory_pooling.cpp index 9c694bc843..877e6f2ff6 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory_pooling.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory_pooling.cpp @@ -44,7 +44,7 @@ struct AllocUsmPoolMemoryTest : public ::testing::Test { mockProductHelpers[i]->isDeviceUsmPoolAllocatorSupportedResult = true; } } - + std::vector> devices; for (auto i = 0u; i < executionEnvironment->rootDeviceEnvironments.size(); i++) { auto device = std::unique_ptr(NEO::MockDevice::createWithExecutionEnvironment(NEO::defaultHwInfo.get(), executionEnvironment, i)); @@ -80,7 +80,6 @@ struct AllocUsmPoolMemoryTest : public ::testing::Test { std::unique_ptr> driverHandle; const uint32_t numRootDevices = 2u; L0::ContextImp *context = nullptr; - std::vector> devices; std::vector mockProductHelpers; NEO::ExecutionEnvironment *executionEnvironment; L0::Device *l0Devices[2]; @@ -88,17 +87,30 @@ struct AllocUsmPoolMemoryTest : public ::testing::Test { }; using AllocUsmHostDefaultMemoryTest = AllocUsmPoolMemoryTest<-1, -1>; +TEST_F(AllocUsmHostDefaultMemoryTest, givenDriverHandleWhenCallinginitHostUsmAllocPoolThenInitIfEnabledForAllDevicesAndNoDebugger) { + driverHandle->usmHostMemAllocPool.cleanup(); + mockProductHelpers[0]->isHostUsmPoolAllocatorSupportedResult = false; + mockProductHelpers[1]->isHostUsmPoolAllocatorSupportedResult = false; + driverHandle->initHostUsmAllocPool(); + EXPECT_FALSE(driverHandle->usmHostMemAllocPool.isInitialized()); -TEST_F(AllocUsmHostDefaultMemoryTest, givenDriverHandleWhenCallingAllocHostMemThenDoNotUsePool) { + driverHandle->usmHostMemAllocPool.cleanup(); + mockProductHelpers[0]->isHostUsmPoolAllocatorSupportedResult = true; + mockProductHelpers[1]->isHostUsmPoolAllocatorSupportedResult = false; + driverHandle->initHostUsmAllocPool(); EXPECT_FALSE(driverHandle->usmHostMemAllocPool.isInitialized()); - void *ptr = nullptr; - ze_host_mem_alloc_desc_t hostDesc = {}; - ze_result_t result = context->allocHostMem(&hostDesc, 1u, 0u, &ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); - EXPECT_NE(nullptr, ptr); + + driverHandle->usmHostMemAllocPool.cleanup(); + mockProductHelpers[0]->isHostUsmPoolAllocatorSupportedResult = true; + mockProductHelpers[1]->isHostUsmPoolAllocatorSupportedResult = true; + driverHandle->initHostUsmAllocPool(); + EXPECT_TRUE(driverHandle->usmHostMemAllocPool.isInitialized()); + + driverHandle->usmHostMemAllocPool.cleanup(); + auto debuggerL0 = DebuggerL0::create(l0Devices[1]->getNEODevice()); + executionEnvironment->rootDeviceEnvironments[1]->debugger.reset(debuggerL0.release()); + driverHandle->initHostUsmAllocPool(); EXPECT_FALSE(driverHandle->usmHostMemAllocPool.isInitialized()); - result = context->freeMem(ptr); - EXPECT_EQ(ZE_RESULT_SUCCESS, result); } using AllocUsmHostDisabledMemoryTest = AllocUsmPoolMemoryTest<0, -1>; diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h b/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h index 432415df51..0cb34f2e36 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/mock_sysman_fixture.h @@ -57,6 +57,8 @@ class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test { if (!sysmanUltsEnable) { GTEST_SKIP(); } + debugManager.flags.EnableHostUsmAllocationPool.set(0); + debugManager.flags.EnableDeviceUsmAllocationPool.set(0); DeviceFixture::setUp(); neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[device->getRootDeviceIndex()]->osInterface = std::make_unique(); auto &osInterface = *device->getOsInterface(); @@ -95,7 +97,7 @@ class SysmanDeviceFixture : public DeviceFixture, public ::testing::Test { DeviceFixture::tearDown(); unsetenv("ZES_ENABLE_SYSMAN"); } - + DebugManagerStateRestore restorer; SysmanDevice *pSysmanDevice = nullptr; SysmanDeviceImp *pSysmanDeviceImp = nullptr; OsSysman *pOsSysman = nullptr; diff --git a/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl b/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl index 46dbdf1342..c3e45b0181 100644 --- a/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl +++ b/shared/source/xe_hpg_core/dg2/os_agnostic_product_helper_dg2.inl @@ -255,4 +255,9 @@ bool ProductHelperHw::isDeviceUsmPoolAllocatorSupported() const { return ApiSpecificConfig::OCL == ApiSpecificConfig::getApiType(); } +template <> +bool ProductHelperHw::isHostUsmPoolAllocatorSupported() const { + return ApiSpecificConfig::OCL == ApiSpecificConfig::getApiType(); +} + } // namespace NEO diff --git a/shared/test/unit_test/xe2_hpg_core/lnl/product_helper_tests_lnl.cpp b/shared/test/unit_test/xe2_hpg_core/lnl/product_helper_tests_lnl.cpp index 961a1540c1..78c80acc52 100644 --- a/shared/test/unit_test/xe2_hpg_core/lnl/product_helper_tests_lnl.cpp +++ b/shared/test/unit_test/xe2_hpg_core/lnl/product_helper_tests_lnl.cpp @@ -140,24 +140,15 @@ LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckingIsBufferPoolAllocatorS EXPECT_TRUE(productHelper->isBufferPoolAllocatorSupported()); } -LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckingIsHostUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { +LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckingIsHostDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); EXPECT_TRUE(productHelper->isHostUsmPoolAllocatorSupported()); - } - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); - EXPECT_FALSE(productHelper->isHostUsmPoolAllocatorSupported()); - } -} - -LNLTEST_F(LnlProductHelper, givenProductHelperWhenCheckingIsDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); } { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); + EXPECT_FALSE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_FALSE(productHelper->isDeviceUsmPoolAllocatorSupported()); } } diff --git a/shared/test/unit_test/xe3_core/ptl/product_helper_tests_ptl.cpp b/shared/test/unit_test/xe3_core/ptl/product_helper_tests_ptl.cpp index d1ce3fce98..7550d04235 100644 --- a/shared/test/unit_test/xe3_core/ptl/product_helper_tests_ptl.cpp +++ b/shared/test/unit_test/xe3_core/ptl/product_helper_tests_ptl.cpp @@ -124,24 +124,15 @@ PTLTEST_F(PtlProductHelper, givenResolveDependenciesByPipeControllsNotSupportedW EXPECT_FALSE(productHelper->isResolveDependenciesByPipeControlsSupported(pInHwInfo, false, 2, csrRelaxed)); } -PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckingIsHostUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); - EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); - } - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); - EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); - } -} - -PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckingIsDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { +PTLTEST_F(PtlProductHelper, givenProductHelperWhenCheckingIsHostDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); + EXPECT_TRUE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); } { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); + EXPECT_TRUE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); } } \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/dg2/product_config_helper_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/product_config_helper_tests_dg2.cpp index 4b2f7c3bc2..26369a1535 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/product_config_helper_tests_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/product_config_helper_tests_dg2.cpp @@ -831,13 +831,15 @@ DG2TEST_F(ProductHelperTestDg2, givenProductHelperWhenGettingUseLocalPreferredFo EXPECT_TRUE(productHelper->useLocalPreferredForCacheableBuffers()); } -DG2TEST_F(ProductHelperTestDg2, givenProductHelperWhenCheckingIsDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { +DG2TEST_F(ProductHelperTestDg2, givenProductHelperWhenCheckingIsHostDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); + EXPECT_TRUE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); } { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); + EXPECT_FALSE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_FALSE(productHelper->isDeviceUsmPoolAllocatorSupported()); } -} \ No newline at end of file +} diff --git a/shared/test/unit_test/xe_hpg_core/mtl/product_helper_tests_mtl.cpp b/shared/test/unit_test/xe_hpg_core/mtl/product_helper_tests_mtl.cpp index 1cbd7ebc4f..60f79e0e79 100644 --- a/shared/test/unit_test/xe_hpg_core/mtl/product_helper_tests_mtl.cpp +++ b/shared/test/unit_test/xe_hpg_core/mtl/product_helper_tests_mtl.cpp @@ -87,24 +87,15 @@ MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckoverrideAllocationCpuCach EXPECT_FALSE(productHelper->overrideAllocationCpuCacheable(allocationData)); } -MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckingIsHostUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { +MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckingIsHostDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); EXPECT_TRUE(productHelper->isHostUsmPoolAllocatorSupported()); - } - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); - EXPECT_FALSE(productHelper->isHostUsmPoolAllocatorSupported()); - } -} - -MTLTEST_F(MtlProductHelper, givenProductHelperWhenCheckingIsDeviceUsmPoolAllocatorSupportedThenCorrectValueIsReturned) { - { - VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::OCL); EXPECT_TRUE(productHelper->isDeviceUsmPoolAllocatorSupported()); } { VariableBackup backup(&apiTypeForUlts, ApiSpecificConfig::L0); + EXPECT_FALSE(productHelper->isHostUsmPoolAllocatorSupported()); EXPECT_FALSE(productHelper->isDeviceUsmPoolAllocatorSupported()); } }