From 797807bea8cb4b24fe8a58045a273655c998225c Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Tue, 23 Sep 2025 13:14:01 +0000 Subject: [PATCH] fix: reduce USM pool size for platforms prior Xe2 Related-To: NEO-16192 Signed-off-by: Szymon Morek --- level_zero/core/source/driver/driver_handle_imp.cpp | 4 ++-- opencl/source/context/context.cpp | 2 +- opencl/source/platform/platform.cpp | 2 +- opencl/test/unit_test/context/context_tests.cpp | 8 ++++---- opencl/test/unit_test/linux/main_linux_dll.cpp | 5 ++++- opencl/test/unit_test/mem_obj/usm_memory_pool_tests.cpp | 4 ++-- shared/source/dll/usm_pool_size.cpp | 5 +++-- shared/source/helpers/gfx_core_helper.h | 4 ++++ shared/source/helpers/gfx_core_helper_base.inl | 5 +++++ shared/source/helpers/gfx_core_helper_xe2_and_later.inl | 5 +++++ shared/source/memory_manager/usm_pool_params.cpp | 7 ++++--- shared/source/memory_manager/usm_pool_params.h | 5 +++-- shared/test/common/mocks/mock_usm_pool_size.cpp | 2 +- shared/test/unit_test/helpers/gfx_core_helper_tests.cpp | 5 +++++ .../unit_test/helpers/gfx_core_helper_xe2_and_later.cpp | 6 ++++++ 15 files changed, 50 insertions(+), 19 deletions(-) diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 811b39c8c2..6fa249bcc8 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -393,7 +393,7 @@ void DriverHandleImp::initHostUsmAllocPool() { nullptr == device->getL0Debugger() && NEO::DeviceFactory::isHwModeSelected(); } - auto poolParams = NEO::UsmPoolParams::getUsmPoolParams(); + auto poolParams = NEO::UsmPoolParams::getUsmPoolParams(this->devices[0]->getNEODevice()->getGfxCoreHelper()); if (NEO::debugManager.flags.EnableHostUsmAllocationPool.get() != -1) { usmHostAllocPoolingEnabled = NEO::debugManager.flags.EnableHostUsmAllocationPool.get() > 0; poolParams.poolSize = NEO::debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte; @@ -411,7 +411,7 @@ void DriverHandleImp::initDeviceUsmAllocPool(NEO::Device &device, bool multiDevi nullptr == device.getL0Debugger() && NEO::DeviceFactory::isHwModeSelected() && !multiDevice; - auto poolParams = NEO::UsmPoolParams::getUsmPoolParams(); + auto poolParams = NEO::UsmPoolParams::getUsmPoolParams(device.getGfxCoreHelper()); if (NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) { enabled = NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0; poolParams.poolSize = NEO::debugManager.flags.EnableDeviceUsmAllocationPool.get() * MemoryConstants::megaByte; diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index 7b60b50ec2..eaaf4ff361 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -523,7 +523,7 @@ void Context::initializeDeviceUsmAllocationPool() { productHelper.isDeviceUsmPoolAllocatorSupported() && DeviceFactory::isHwModeSelected(); - auto usmDevicePoolParams = UsmPoolParams::getUsmPoolParams(); + auto usmDevicePoolParams = UsmPoolParams::getUsmPoolParams(getDevices()[0]->getGfxCoreHelper()); if (debugManager.flags.EnableDeviceUsmAllocationPool.get() != -1) { enabled = debugManager.flags.EnableDeviceUsmAllocationPool.get() > 0; usmDevicePoolParams.poolSize = debugManager.flags.EnableDeviceUsmAllocationPool.get() * MemoryConstants::megaByte; diff --git a/opencl/source/platform/platform.cpp b/opencl/source/platform/platform.cpp index 3d0e708696..ba0c9740f2 100644 --- a/opencl/source/platform/platform.cpp +++ b/opencl/source/platform/platform.cpp @@ -325,7 +325,7 @@ void Platform::initializeHostUsmAllocationPool() { usmHostAllocPoolingEnabled &= device->getProductHelper().isHostUsmPoolAllocatorSupported() && DeviceFactory::isHwModeSelected(); } - auto usmHostPoolParams = UsmPoolParams::getUsmPoolParams(); + auto usmHostPoolParams = UsmPoolParams::getUsmPoolParams(this->clDevices[0]->getGfxCoreHelper()); if (debugManager.flags.EnableHostUsmAllocationPool.get() != -1) { usmHostAllocPoolingEnabled = debugManager.flags.EnableHostUsmAllocationPool.get() > 0; usmHostPoolParams.poolSize = debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte; diff --git a/opencl/test/unit_test/context/context_tests.cpp b/opencl/test/unit_test/context/context_tests.cpp index 26e698d483..f61973475c 100644 --- a/opencl/test/unit_test/context/context_tests.cpp +++ b/opencl/test/unit_test/context/context_tests.cpp @@ -805,10 +805,10 @@ TEST_F(ContextUsmPoolParamsTest, whenGettingUsmPoolParamsThenReturnCorrectValues EXPECT_EQ(CL_SUCCESS, retVal); const UsmPoolParams expectedPoolParams{ - .poolSize = UsmPoolParams::getUsmPoolSize(), + .poolSize = UsmPoolParams::getUsmPoolSize(context->getDevice(0)->getGfxCoreHelper()), .minServicedSize = 0u, - .maxServicedSize = 2 * MemoryConstants::megaByte}; - EXPECT_TRUE(compareUsmPoolParams(expectedPoolParams, UsmPoolParams::getUsmPoolParams())); + .maxServicedSize = context->getDevice(0)->getGfxCoreHelper().isExtendedUsmPoolSizeEnabled() ? 2 * MemoryConstants::megaByte : MemoryConstants::megaByte}; + EXPECT_TRUE(compareUsmPoolParams(expectedPoolParams, UsmPoolParams::getUsmPoolParams(context->getDevice(0)->getGfxCoreHelper()))); } TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingUsmPoolsThenPoolsAreInitializedWithCorrectParams) { @@ -833,7 +833,7 @@ TEST_F(ContextUsmPoolParamsTest, GivenUsmPoolAllocatorSupportedWhenInitializingU .poolSize = mockHostUsmMemAllocPool->poolSize, .minServicedSize = mockHostUsmMemAllocPool->minServicedSize, .maxServicedSize = mockHostUsmMemAllocPool->maxServicedSize}; - const UsmPoolParams expectedUsmHostPoolParams = UsmPoolParams::getUsmPoolParams(); + const UsmPoolParams expectedUsmHostPoolParams = UsmPoolParams::getUsmPoolParams(context->getDevice(0)->getGfxCoreHelper()); EXPECT_TRUE(compareUsmPoolParams(expectedUsmHostPoolParams, givenUsmHostPoolParams)); } diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index 38bab4c87d..e364a0f156 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -643,7 +643,10 @@ TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenEx } TEST(UsmPoolTest, whenGetUsmPoolSizeCalledThenReturnCorrectSize) { - EXPECT_EQ(32 * MemoryConstants::megaByte, NEO::UsmPoolParams::getUsmPoolSize()); + MockExecutionEnvironment mockExecutionEnvironment; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + auto usmPoolSize = gfxCoreHelper.isExtendedUsmPoolSizeEnabled() ? 32 * MemoryConstants::megaByte : 2 * MemoryConstants::megaByte; + EXPECT_EQ(usmPoolSize, NEO::UsmPoolParams::getUsmPoolSize(gfxCoreHelper)); } TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) { diff --git a/opencl/test/unit_test/mem_obj/usm_memory_pool_tests.cpp b/opencl/test/unit_test/mem_obj/usm_memory_pool_tests.cpp index e4f66d39a7..9822c69653 100644 --- a/opencl/test/unit_test/mem_obj/usm_memory_pool_tests.cpp +++ b/opencl/test/unit_test/mem_obj/usm_memory_pool_tests.cpp @@ -103,8 +103,8 @@ TEST_F(UsmPoolTest, givenUsmPoolsSupportedWhenCreatingAllocationsThenPoolsAreIni EXPECT_NE(nullptr, pooledHostAlloc); clMemFreeINTEL(mockContext.get(), pooledHostAlloc); - EXPECT_EQ(UsmPoolParams::getUsmPoolSize(), mockDeviceUsmMemAllocPool->poolSize); - EXPECT_EQ(UsmPoolParams::getUsmPoolSize(), mockHostUsmMemAllocPool->poolSize); + EXPECT_EQ(UsmPoolParams::getUsmPoolSize(deviceFactory->rootDevices[0]->getGfxCoreHelper()), mockDeviceUsmMemAllocPool->poolSize); + EXPECT_EQ(UsmPoolParams::getUsmPoolSize(deviceFactory->rootDevices[0]->getGfxCoreHelper()), mockHostUsmMemAllocPool->poolSize); EXPECT_TRUE(mockDeviceUsmMemAllocPool->isInitialized()); EXPECT_TRUE(mockHostUsmMemAllocPool->isInitialized()); } diff --git a/shared/source/dll/usm_pool_size.cpp b/shared/source/dll/usm_pool_size.cpp index 821dded802..df08c55063 100644 --- a/shared/source/dll/usm_pool_size.cpp +++ b/shared/source/dll/usm_pool_size.cpp @@ -6,10 +6,11 @@ */ #include "shared/source/helpers/constants.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/memory_manager/usm_pool_params.h" namespace NEO { -size_t UsmPoolParams::getUsmPoolSize() { - return 32 * MemoryConstants::megaByte; +size_t UsmPoolParams::getUsmPoolSize(const GfxCoreHelper &gfxCoreHelper) { + return gfxCoreHelper.isExtendedUsmPoolSizeEnabled() ? 32 * MemoryConstants::megaByte : 2 * MemoryConstants::megaByte; } } // namespace NEO diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index b4e5bfc46c..1027747c6a 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -221,6 +221,8 @@ class GfxCoreHelper { virtual uintptr_t getSurfaceBaseAddressAlignmentMask() const = 0; virtual uintptr_t getSurfaceBaseAddressAlignment() const = 0; + virtual bool isExtendedUsmPoolSizeEnabled() const = 0; + virtual ~GfxCoreHelper() = default; protected: @@ -489,6 +491,8 @@ class GfxCoreHelperHw : public GfxCoreHelper { uint32_t getQueuePriorityLevels() const override; + bool isExtendedUsmPoolSizeEnabled() const override; + ~GfxCoreHelperHw() override = default; protected: diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 4092427d05..603f26fa59 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -942,4 +942,9 @@ uintptr_t GfxCoreHelperHw::getSurfaceBaseAddressAlignment() const { return EncodeSurfaceState::getSurfaceBaseAddressAlignment(); } +template +bool GfxCoreHelperHw::isExtendedUsmPoolSizeEnabled() const { + return false; +} + } // namespace NEO diff --git a/shared/source/helpers/gfx_core_helper_xe2_and_later.inl b/shared/source/helpers/gfx_core_helper_xe2_and_later.inl index eaf08d089f..41655fbc04 100644 --- a/shared/source/helpers/gfx_core_helper_xe2_and_later.inl +++ b/shared/source/helpers/gfx_core_helper_xe2_and_later.inl @@ -109,4 +109,9 @@ bool GfxCoreHelperHw::isCacheFlushPriorImageReadRequired() const { return true; } +template <> +bool GfxCoreHelperHw::isExtendedUsmPoolSizeEnabled() const { + return true; +} + } // namespace NEO diff --git a/shared/source/memory_manager/usm_pool_params.cpp b/shared/source/memory_manager/usm_pool_params.cpp index 301583f2b5..a68b214f60 100644 --- a/shared/source/memory_manager/usm_pool_params.cpp +++ b/shared/source/memory_manager/usm_pool_params.cpp @@ -8,12 +8,13 @@ #include "shared/source/memory_manager/usm_pool_params.h" #include "shared/source/helpers/constants.h" +#include "shared/source/helpers/gfx_core_helper.h" namespace NEO { -UsmPoolParams UsmPoolParams::getUsmPoolParams() { +UsmPoolParams UsmPoolParams::getUsmPoolParams(const GfxCoreHelper &gfxCoreHelper) { return { - .poolSize = UsmPoolParams::getUsmPoolSize(), + .poolSize = UsmPoolParams::getUsmPoolSize(gfxCoreHelper), .minServicedSize = 0u, - .maxServicedSize = 2 * MemoryConstants::megaByte}; + .maxServicedSize = gfxCoreHelper.isExtendedUsmPoolSizeEnabled() ? 2 * MemoryConstants::megaByte : MemoryConstants::megaByte}; } } // namespace NEO diff --git a/shared/source/memory_manager/usm_pool_params.h b/shared/source/memory_manager/usm_pool_params.h index c966397082..661423699c 100644 --- a/shared/source/memory_manager/usm_pool_params.h +++ b/shared/source/memory_manager/usm_pool_params.h @@ -9,12 +9,13 @@ #include namespace NEO { +class GfxCoreHelper; struct UsmPoolParams { size_t poolSize{0}; size_t minServicedSize{0}; size_t maxServicedSize{0}; - static UsmPoolParams getUsmPoolParams(); - static size_t getUsmPoolSize(); + static UsmPoolParams getUsmPoolParams(const GfxCoreHelper &gfxCoreHelper); + static size_t getUsmPoolSize(const GfxCoreHelper &gfxCoreHelper); }; } // namespace NEO diff --git a/shared/test/common/mocks/mock_usm_pool_size.cpp b/shared/test/common/mocks/mock_usm_pool_size.cpp index 9863190e9f..57d45fafc1 100644 --- a/shared/test/common/mocks/mock_usm_pool_size.cpp +++ b/shared/test/common/mocks/mock_usm_pool_size.cpp @@ -9,7 +9,7 @@ #include "shared/source/memory_manager/usm_pool_params.h" namespace NEO { -size_t UsmPoolParams::getUsmPoolSize() { +size_t UsmPoolParams::getUsmPoolSize(const GfxCoreHelper &gfxCoreHelper) { return MemoryConstants::pageSize; } } // namespace NEO diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index 514fe708fc..1fa51eaf1e 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -1996,6 +1996,11 @@ HWTEST2_F(GfxCoreHelperTest, whenIsCacheFlushPriorImageReadRequiredCalledThenFal EXPECT_FALSE(helper.isCacheFlushPriorImageReadRequired()); } +HWTEST2_F(GfxCoreHelperTest, whenIsExtendedUsmPoolSizeEnabledRequiredCalledThenFalseIsReturned, IsAtMostXeCore) { + auto &helper = getHelper(); + EXPECT_FALSE(helper.isExtendedUsmPoolSizeEnabled()); +} + HWTEST2_F(GfxCoreHelperTest, givenAtLeastXe2HpgWhenSetStallOnlyBarrierThenPipeControlProgrammed, IsAtMostXeCore) { using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; constexpr static auto bufferSize = sizeof(PIPE_CONTROL); diff --git a/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp b/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp index 3afaaac8e6..26548d3de8 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_xe2_and_later.cpp @@ -122,6 +122,12 @@ HWTEST2_F(GfxCoreHelperXe2AndLaterTests, givenAtLeastXe2HpgWhenIsCacheFlushPrior EXPECT_TRUE(gfxCoreHelper.isCacheFlushPriorImageReadRequired()); } +HWTEST2_F(GfxCoreHelperXe2AndLaterTests, givenAtLeastXe2HpgWhenIsExtendedUsmPoolSizeEnabledThenTrueIsReturned, IsAtLeastXe2HpgCore) { + MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + EXPECT_TRUE(gfxCoreHelper.isExtendedUsmPoolSizeEnabled()); +} + class MockGmmResourceInfoWithDenyCompression : public MockGmmResourceInfo { public: MockGmmResourceInfoWithDenyCompression(GMM_RESCREATE_PARAMS *resourceCreateParams) : MockGmmResourceInfo(resourceCreateParams) {}