From 140f787b11055a1ac48b8641bca734838f556433 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Wed, 29 Oct 2025 11:25:05 +0000 Subject: [PATCH] performance: enable l0 host usm growing pools Related-To: NEO-16084 Signed-off-by: Dominik Dabek --- .../core/source/context/context_imp.cpp | 30 +++++++---- .../core/source/driver/driver_handle_imp.cpp | 29 +++++++++-- .../core/source/driver/driver_handle_imp.h | 2 + level_zero/core/test/common/ult_helpers_l0.h | 4 ++ .../unit_tests/sources/memory/test_memory.cpp | 2 +- .../sources/memory/test_memory_wddm.cpp | 7 +-- shared/source/dll/pool_info.cpp | 8 +++ shared/source/memory_manager/pool_info.h | 2 + .../memory_manager/unified_memory_pooling.cpp | 16 ++++-- .../memory_manager/unified_memory_pooling.h | 2 + shared/test/common/mocks/mock_pool_info.cpp | 8 +++ .../test/common/mocks/mock_usm_memory_pool.h | 1 + .../unified_memory_pooling_tests.cpp | 50 +++++++++++-------- 13 files changed, 116 insertions(+), 45 deletions(-) diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index bbee16ddff..35170bc69e 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -177,10 +177,17 @@ ze_result_t ContextImp::allocHostMem(const ze_host_mem_alloc_desc_t *hostMemDesc return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY; } - if (false == lookupTable.exportMemory && this->driverHandle->usmHostMemAllocPool) { - if (auto usmPtrFromPool = this->driverHandle->usmHostMemAllocPool->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) { - *ptr = usmPtrFromPool; - return ZE_RESULT_SUCCESS; + if (false == lookupTable.exportMemory) { + if (this->driverHandle->usmHostMemAllocPoolManager) { + if (auto usmPtrFromPool = this->driverHandle->usmHostMemAllocPoolManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) { + *ptr = usmPtrFromPool; + return ZE_RESULT_SUCCESS; + } + } else if (this->driverHandle->usmHostMemAllocPool) { + if (auto usmPtrFromPool = this->driverHandle->usmHostMemAllocPool->createUnifiedMemoryAllocation(size, unifiedMemoryProperties)) { + *ptr = usmPtrFromPool; + return ZE_RESULT_SUCCESS; + } } } @@ -487,10 +494,8 @@ NEO::UsmMemAllocPool *ContextImp::getUsmPoolOwningPtr(const void *ptr, NEO::SvmA DEBUG_BREAK_IF(nullptr == svmData); NEO::UsmMemAllocPool *usmPool = nullptr; - if (InternalMemoryType::hostUnifiedMemory == svmData->memoryType && - driverHandle->usmHostMemAllocPool && - driverHandle->usmHostMemAllocPool->isInPool(ptr)) { - usmPool = driverHandle->usmHostMemAllocPool.get(); + if (InternalMemoryType::hostUnifiedMemory == svmData->memoryType) { + usmPool = driverHandle->getHostUsmPoolOwningPtr(ptr); } else if (InternalMemoryType::deviceUnifiedMemory == svmData->memoryType) { usmPool = svmData->device->getUsmPoolOwningPtr(ptr); } @@ -499,10 +504,13 @@ NEO::UsmMemAllocPool *ContextImp::getUsmPoolOwningPtr(const void *ptr, NEO::SvmA } bool ContextImp::tryFreeViaPooling(const void *ptr, NEO::SvmAllocationData *svmData, NEO::UsmMemAllocPool *usmPool) { - if (svmData->device && svmData->device->getUsmMemAllocPoolsManager()) { - return svmData->device->getUsmMemAllocPoolsManager()->freeSVMAlloc(ptr, false); - } if (usmPool) { + if (svmData->device && svmData->device->getUsmMemAllocPoolsManager()) { + return svmData->device->getUsmMemAllocPoolsManager()->freeSVMAlloc(ptr, false); + } + if (!svmData->device && driverHandle->usmHostMemAllocPoolManager) { + return driverHandle->usmHostMemAllocPoolManager->freeSVMAlloc(ptr, false); + } [[maybe_unused]] auto status = usmPool->freeSVMAlloc(ptr, false); DEBUG_BREAK_IF(false == status); return true; diff --git a/level_zero/core/source/driver/driver_handle_imp.cpp b/level_zero/core/source/driver/driver_handle_imp.cpp index 0581556634..947fb7bae4 100644 --- a/level_zero/core/source/driver/driver_handle_imp.cpp +++ b/level_zero/core/source/driver/driver_handle_imp.cpp @@ -243,6 +243,9 @@ DriverHandleImp::~DriverHandleImp() { if (this->usmHostMemAllocPool) { this->usmHostMemAllocPool->cleanup(); } + if (this->usmHostMemAllocPoolManager) { + this->usmHostMemAllocPoolManager->cleanup(); + } } } @@ -372,6 +375,10 @@ DriverHandle *DriverHandle::create(std::vector> dev } void DriverHandleImp::initHostUsmAllocPool() { + bool useUsmPoolManager = true; + if (NEO::debugManager.flags.EnableUsmAllocationPoolManager.get() != -1) { + useUsmPoolManager = !!NEO::debugManager.flags.EnableUsmAllocationPoolManager.get(); + } auto usmHostAllocPoolingEnabled = NEO::ApiSpecificConfig::isHostUsmPoolingEnabled(); for (auto device : this->devices) { usmHostAllocPoolingEnabled &= device->getNEODevice()->getProductHelper().isHostUsmPoolAllocatorSupported() && @@ -384,10 +391,15 @@ void DriverHandleImp::initHostUsmAllocPool() { poolParams.poolSize = NEO::debugManager.flags.EnableHostUsmAllocationPool.get() * MemoryConstants::megaByte; } if (usmHostAllocPoolingEnabled) { - NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M, - rootDeviceIndices, deviceBitfields); - usmHostMemAllocPool.reset(new NEO::UsmMemAllocPool); - usmHostMemAllocPool->initialize(svmAllocsManager, memoryProperties, poolParams.poolSize, poolParams.minServicedSize, poolParams.maxServicedSize); + if (useUsmPoolManager) { + usmHostMemAllocPoolManager.reset(new NEO::UsmMemAllocPoolsManager(InternalMemoryType::hostUnifiedMemory, rootDeviceIndices, deviceBitfields, nullptr)); + usmHostMemAllocPoolManager->initialize(this->svmAllocsManager); + } else { + NEO::SVMAllocsManager::UnifiedMemoryProperties memoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M, + rootDeviceIndices, deviceBitfields); + usmHostMemAllocPool.reset(new NEO::UsmMemAllocPool); + usmHostMemAllocPool->initialize(svmAllocsManager, memoryProperties, poolParams.poolSize, poolParams.minServicedSize, poolParams.maxServicedSize); + } } } @@ -439,6 +451,15 @@ void DriverHandleImp::initDeviceUsmAllocPool(NEO::Device &device, bool multiDevi } } +NEO::UsmMemAllocPool *DriverHandleImp::getHostUsmPoolOwningPtr(const void *ptr) { + if (usmHostMemAllocPoolManager) { + return usmHostMemAllocPoolManager->getPoolContainingAlloc(ptr); + } else if (usmHostMemAllocPool && usmHostMemAllocPool->isInPool(ptr)) { + return usmHostMemAllocPool.get(); + } + return nullptr; +} + void DriverHandleImp::setupDevicesToExpose() { // If the user has requested FLAT or COMBINED device hierarchy model, then report all the sub devices as devices. diff --git a/level_zero/core/source/driver/driver_handle_imp.h b/level_zero/core/source/driver/driver_handle_imp.h index be44139f76..ef3516b834 100644 --- a/level_zero/core/source/driver/driver_handle_imp.h +++ b/level_zero/core/source/driver/driver_handle_imp.h @@ -115,6 +115,7 @@ struct DriverHandleImp : public DriverHandle { [[nodiscard]] std::unique_lock lockIPCHandleMap() { return std::unique_lock(this->ipcHandleMapMutex); }; void initHostUsmAllocPool(); void initDeviceUsmAllocPool(NEO::Device &device, bool multiDevice); + NEO::UsmMemAllocPool *getHostUsmPoolOwningPtr(const void *ptr); std::unique_ptr hostPointerManager; @@ -138,6 +139,7 @@ struct DriverHandleImp : public DriverHandle { NEO::MemoryManager *memoryManager = nullptr; NEO::SVMAllocsManager *svmAllocsManager = nullptr; std::unique_ptr usmHostMemAllocPool; + std::unique_ptr usmHostMemAllocPoolManager; ze_context_handle_t defaultContext = nullptr; std::unique_ptr stagingBufferManager; diff --git a/level_zero/core/test/common/ult_helpers_l0.h b/level_zero/core/test/common/ult_helpers_l0.h index ffe822c73c..917a3c04f9 100644 --- a/level_zero/core/test/common/ult_helpers_l0.h +++ b/level_zero/core/test/common/ult_helpers_l0.h @@ -18,6 +18,10 @@ struct L0UltHelper { driverHandle->usmHostMemAllocPool->cleanup(); driverHandle->usmHostMemAllocPool.reset(nullptr); } + if (driverHandle->usmHostMemAllocPoolManager) { + driverHandle->usmHostMemAllocPoolManager->cleanup(); + driverHandle->usmHostMemAllocPoolManager.reset(nullptr); + } for (auto device : driverHandle->devices) { device->getNEODevice()->cleanupUsmAllocationPool(); } diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp index a9f3c09eee..61ce8d954b 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory.cpp @@ -540,7 +540,7 @@ TEST_F(MemoryTest, givenHostPointerThenDriverGetAllocPropertiesReturnsExpectedPr EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_EQ(memoryProperties.type, ZE_MEMORY_TYPE_HOST); - auto usmPool = driverHandle->usmHostMemAllocPool.get(); + auto usmPool = driverHandle->getHostUsmPoolOwningPtr(ptr); auto alloc = context->getDriverHandle()->getSvmAllocsManager()->getSVMAlloc(ptr); EXPECT_NE(alloc, nullptr); EXPECT_NE(alloc->pageSizeForAlignment, 0u); diff --git a/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp b/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp index 8917607e63..331e0b0999 100644 --- a/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp +++ b/level_zero/core/test/unit_tests/sources/memory/test_memory_wddm.cpp @@ -387,9 +387,6 @@ struct HostUsmPoolMemoryOpenIpcHandleTest : public MemoryIPCTests { TEST_F(HostUsmPoolMemoryOpenIpcHandleTest, givenCallToOpenIpcMemHandleItIsSuccessfullyOpenedAndClosed) { - ASSERT_NE(nullptr, driverHandle->usmHostMemAllocPool.get()); - auto mockHostMemAllocPool = reinterpret_cast(driverHandle->usmHostMemAllocPool.get()); - EXPECT_TRUE(driverHandle->usmHostMemAllocPool->isInitialized()); size_t size = 1; size_t alignment = 0u; void *ptr = nullptr; @@ -399,9 +396,9 @@ TEST_F(HostUsmPoolMemoryOpenIpcHandleTest, size, alignment, &ptr); EXPECT_EQ(ZE_RESULT_SUCCESS, result); EXPECT_NE(nullptr, ptr); - EXPECT_TRUE(driverHandle->usmHostMemAllocPool->isInPool(ptr)); + auto mockHostMemAllocPool = reinterpret_cast(driverHandle->getHostUsmPoolOwningPtr(ptr)); + ASSERT_NE(nullptr, mockHostMemAllocPool); const auto pooledAllocationOffset = ptrDiff(mockHostMemAllocPool->allocations.get(ptr)->address, castToUint64(mockHostMemAllocPool->pool)); - EXPECT_GT(pooledAllocationOffset, 0u); ze_ipc_mem_handle_t ipcHandle = {}; result = context->getIpcMemHandle(ptr, &ipcHandle); diff --git a/shared/source/dll/pool_info.cpp b/shared/source/dll/pool_info.cpp index 4212071e5c..ba2e655ed4 100644 --- a/shared/source/dll/pool_info.cpp +++ b/shared/source/dll/pool_info.cpp @@ -32,10 +32,18 @@ const std::array PoolInfo::getPoolInfos(const GfxCoreHelper & return poolInfos; } +const std::array PoolInfo::getHostPoolInfos() { + return extendedPoolInfos; +} + size_t PoolInfo::getMaxPoolableSize(const GfxCoreHelper &gfxCoreHelper) { if (gfxCoreHelper.isExtendedUsmPoolSizeEnabled()) { return 2 * MB; } return 1 * MB; } + +size_t PoolInfo::getHostMaxPoolableSize() { + return 2 * MB; +} } // namespace NEO diff --git a/shared/source/memory_manager/pool_info.h b/shared/source/memory_manager/pool_info.h index 22f643bca8..f8ac4f4e90 100644 --- a/shared/source/memory_manager/pool_info.h +++ b/shared/source/memory_manager/pool_info.h @@ -21,7 +21,9 @@ class PoolInfo { } static const std::array getPoolInfos(const GfxCoreHelper &gfxCoreHelper); + static const std::array getHostPoolInfos(); static size_t getMaxPoolableSize(const GfxCoreHelper &gfxCoreHelper); + static size_t getHostMaxPoolableSize(); private: static const std::array poolInfos; diff --git a/shared/source/memory_manager/unified_memory_pooling.cpp b/shared/source/memory_manager/unified_memory_pooling.cpp index f575dae2fd..9e53c58b2d 100644 --- a/shared/source/memory_manager/unified_memory_pooling.cpp +++ b/shared/source/memory_manager/unified_memory_pooling.cpp @@ -197,12 +197,20 @@ MemoryOperationsStatus UsmMemAllocPool::makePoolResident() { return memoryOperationsIface->makeResident(device, ArrayRef(&allocation, 1), true, true); } +const std::array UsmMemAllocPoolsManager::getPoolInfos() { + return (device ? PoolInfo::getPoolInfos(device->getGfxCoreHelper()) : PoolInfo::getHostPoolInfos()); +} + +size_t UsmMemAllocPoolsManager::getMaxPoolableSize() { + return (device ? PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()) : PoolInfo::getHostMaxPoolableSize()); +} + bool UsmMemAllocPoolsManager::initialize(SVMAllocsManager *svmMemoryManager) { DEBUG_BREAK_IF(poolMemoryType != InternalMemoryType::deviceUnifiedMemory && poolMemoryType != InternalMemoryType::hostUnifiedMemory); DEBUG_BREAK_IF(device == nullptr && poolMemoryType == InternalMemoryType::deviceUnifiedMemory); this->svmMemoryManager = svmMemoryManager; - for (const auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (const auto &poolInfo : getPoolInfos()) { this->pools[poolInfo] = std::vector>(); auto pool = tryAddPool(poolInfo); if (nullptr == pool) { @@ -234,7 +242,7 @@ void *UsmMemAllocPoolsManager::createUnifiedMemoryAllocation(size_t size, const } std::unique_lock lock(mtx); void *ptr = nullptr; - for (const auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (const auto &poolInfo : getPoolInfos()) { if (size <= poolInfo.maxServicedSize) { for (auto &pool : this->pools[poolInfo]) { if (nullptr != (ptr = pool->createUnifiedMemoryAllocation(size, memoryProperties))) { @@ -273,7 +281,7 @@ bool UsmMemAllocPoolsManager::canAddPool(PoolInfo poolInfo) { } bool UsmMemAllocPoolsManager::canBePooled(size_t size, const UnifiedMemoryProperties &memoryProperties) { - return size <= PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()) && + return size <= getMaxPoolableSize() && UsmMemAllocPool::alignmentIsAllowed(memoryProperties.alignment) && UsmMemAllocPool::flagsAreAllowed(memoryProperties); } @@ -328,7 +336,7 @@ size_t UsmMemAllocPoolsManager::getOffsetInPool(const void *ptr) { UsmMemAllocPool *UsmMemAllocPoolsManager::getPoolContainingAlloc(const void *ptr) { std::unique_lock lock(mtx); - for (const auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (const auto &poolInfo : getPoolInfos()) { for (auto &pool : this->pools[poolInfo]) { if (pool->isInPool(ptr)) { return pool.get(); diff --git a/shared/source/memory_manager/unified_memory_pooling.h b/shared/source/memory_manager/unified_memory_pooling.h index 2f4be1f1e5..50e740876e 100644 --- a/shared/source/memory_manager/unified_memory_pooling.h +++ b/shared/source/memory_manager/unified_memory_pooling.h @@ -118,6 +118,8 @@ class UsmMemAllocPoolsManager : NEO::NonCopyableAndNonMovableClass { bool isInitialized() const; void cleanup(); void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties); + const std::array getPoolInfos(); + size_t getMaxPoolableSize(); UsmMemAllocPool *tryAddPool(PoolInfo poolInfo); MOCKABLE_VIRTUAL bool canAddPool(PoolInfo poolInfo); void trimEmptyPools(PoolInfo poolInfo); diff --git a/shared/test/common/mocks/mock_pool_info.cpp b/shared/test/common/mocks/mock_pool_info.cpp index cb10ae6d0d..11b09357c0 100644 --- a/shared/test/common/mocks/mock_pool_info.cpp +++ b/shared/test/common/mocks/mock_pool_info.cpp @@ -24,7 +24,15 @@ const std::array PoolInfo::getPoolInfos(const GfxCoreHelper & return poolInfos; } +const std::array PoolInfo::getHostPoolInfos() { + return poolInfos; +} + size_t PoolInfo::getMaxPoolableSize(const GfxCoreHelper &gfxCoreHelper) { return MemoryConstants::pageSize; } + +size_t PoolInfo::getHostMaxPoolableSize() { + return MemoryConstants::pageSize; +} } // namespace NEO \ No newline at end of file diff --git a/shared/test/common/mocks/mock_usm_memory_pool.h b/shared/test/common/mocks/mock_usm_memory_pool.h index 97e70d2866..86f5a08fba 100644 --- a/shared/test/common/mocks/mock_usm_memory_pool.h +++ b/shared/test/common/mocks/mock_usm_memory_pool.h @@ -63,6 +63,7 @@ class MockUsmMemAllocPoolsManager : public UsmMemAllocPoolsManager { using UsmMemAllocPoolsManager::canBePooled; using UsmMemAllocPoolsManager::device; using UsmMemAllocPoolsManager::getPoolContainingAlloc; + using UsmMemAllocPoolsManager::getPoolInfos; using UsmMemAllocPoolsManager::memoryManager; using UsmMemAllocPoolsManager::pools; using UsmMemAllocPoolsManager::totalSize; diff --git a/shared/test/unit_test/memory_manager/unified_memory_pooling_tests.cpp b/shared/test/unit_test/memory_manager/unified_memory_pooling_tests.cpp index d53c9b92cd..cb78defbcc 100644 --- a/shared/test/unit_test/memory_manager/unified_memory_pooling_tests.cpp +++ b/shared/test/unit_test/memory_manager/unified_memory_pooling_tests.cpp @@ -432,6 +432,8 @@ class UnifiedMemoryPoolingManagerTest : public SVMMemoryAllocatorFixture, REQUIRE_64BIT_OR_SKIP(); SVMMemoryAllocatorFixture::setUp(); poolMemoryType = std::get<0>(GetParam()); + ASSERT_TRUE(InternalMemoryType::deviceUnifiedMemory == poolMemoryType || + InternalMemoryType::hostUnifiedMemory == poolMemoryType); deviceFactory = std::unique_ptr(new UltDeviceFactory(1, 1)); device = deviceFactory->rootDevices[0]; @@ -439,17 +441,17 @@ class UnifiedMemoryPoolingManagerTest : public SVMMemoryAllocatorFixture, usmMemAllocPoolsManager.reset(new MockUsmMemAllocPoolsManager(poolMemoryType, rootDeviceIndices, deviceBitfields, - device)); + isDevicePool() ? device : nullptr)); ASSERT_NE(nullptr, usmMemAllocPoolsManager); EXPECT_FALSE(usmMemAllocPoolsManager->isInitialized()); svmManager = std::make_unique(device->getMemoryManager()); mockMemoryManager = static_cast(device->getMemoryManager()); - if (InternalMemoryType::deviceUnifiedMemory == poolMemoryType) { + if (isDevicePool()) { mockMemoryManager->localMemorySupported[mockRootDeviceIndex] = true; } poolMemoryProperties = std::make_unique(poolMemoryType, MemoryConstants::preferredAlignment, rootDeviceIndices, deviceBitfields); - poolMemoryProperties->device = poolMemoryType == InternalMemoryType::deviceUnifiedMemory ? device : nullptr; + poolMemoryProperties->device = isDevicePool() ? device : nullptr; } void TearDown() override { SVMMemoryAllocatorFixture::tearDown(); @@ -460,15 +462,14 @@ class UnifiedMemoryPoolingManagerTest : public SVMMemoryAllocatorFixture, auto mockGa = std::make_unique(mockRootDeviceIndex, nullptr, size); mockGa->gpuAddress = nextMockGraphicsAddress; mockGa->cpuPtr = reinterpret_cast(nextMockGraphicsAddress); - if (InternalMemoryType::deviceUnifiedMemory == poolMemoryType) { - mockGa->setAllocationType(AllocationType::svmGpu); + if (isDevicePool()) { + mockGa->setAllocationType(AllocationType::buffer); mockMemoryManager->mockGa = mockGa.release(); mockMemoryManager->returnMockGAFromDevicePool = true; ptr = svmManager->createUnifiedMemoryAllocation(size, unifiedMemoryProperties); mockMemoryManager->returnMockGAFromDevicePool = false; - } - if (InternalMemoryType::hostUnifiedMemory == poolMemoryType) { - mockGa->setAllocationType(AllocationType::svmCpu); + } else { + mockGa->setAllocationType(AllocationType::bufferHostMemory); mockMemoryManager->mockGa = mockGa.release(); mockMemoryManager->returnMockGAFromHostPool = true; ptr = svmManager->createHostUnifiedMemoryAllocation(size, unifiedMemoryProperties); @@ -478,6 +479,9 @@ class UnifiedMemoryPoolingManagerTest : public SVMMemoryAllocatorFixture, nextMockGraphicsAddress = alignUp(nextMockGraphicsAddress + size + 1, MemoryConstants::pageSize2M); return ptr; } + bool isDevicePool() { + return InternalMemoryType::deviceUnifiedMemory == poolMemoryType; + } const size_t poolSize = 2 * MemoryConstants::megaByte; std::unique_ptr usmMemAllocPoolsManager; std::unique_ptr deviceFactory; @@ -498,27 +502,33 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(UnifiedMemoryPoolingManagerTest, givenUsmMemAllocPoolsManagerWhenCallingCanBePooledThenCorrectValueIsReturned) { const RootDeviceIndicesContainer rootDeviceIndices; const std::map deviceBitfields; - SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::hostUnifiedMemory, MemoryConstants::pageSize2M, rootDeviceIndices, deviceBitfields); - EXPECT_TRUE(usmMemAllocPoolsManager->canBePooled(PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()), unifiedMemoryProperties)); - EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()) + 1, unifiedMemoryProperties)); + SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(poolMemoryType, MemoryConstants::pageSize2M, rootDeviceIndices, deviceBitfields); + size_t maxPoolableSize = 0u; + if (this->isDevicePool()) { + maxPoolableSize = PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()); + } else { + maxPoolableSize = PoolInfo::getHostMaxPoolableSize(); + } + EXPECT_TRUE(usmMemAllocPoolsManager->canBePooled(maxPoolableSize, unifiedMemoryProperties)); + EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(maxPoolableSize + 1, unifiedMemoryProperties)); unifiedMemoryProperties.alignment = UsmMemAllocPool::chunkAlignment / 2; - EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()), unifiedMemoryProperties)); + EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(maxPoolableSize, unifiedMemoryProperties)); unifiedMemoryProperties.alignment = UsmMemAllocPool::chunkAlignment; unifiedMemoryProperties.allocationFlags.allFlags = 1u; - EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()), unifiedMemoryProperties)); + EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(maxPoolableSize, unifiedMemoryProperties)); unifiedMemoryProperties.allocationFlags.allFlags = 0u; unifiedMemoryProperties.allocationFlags.allAllocFlags = 1u; - EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(PoolInfo::getMaxPoolableSize(device->getGfxCoreHelper()), unifiedMemoryProperties)); + EXPECT_FALSE(usmMemAllocPoolsManager->canBePooled(maxPoolableSize, unifiedMemoryProperties)); } TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializationFailsForOneOfTheSmallPoolsWhenInitializingPoolsManagerThenPoolsAreCleanedUp) { mockMemoryManager->maxSuccessAllocatedGraphicsMemoryIndex = mockMemoryManager->successAllocatedGraphicsMemoryIndex + 2; EXPECT_FALSE(usmMemAllocPoolsManager->initialize(svmManager.get())); EXPECT_FALSE(usmMemAllocPoolsManager->isInitialized()); - for (auto poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (auto poolInfo : usmMemAllocPoolsManager->getPoolInfos()) { EXPECT_EQ(0u, usmMemAllocPoolsManager->pools[poolInfo].size()); } } @@ -556,7 +566,7 @@ TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializedPoolsManagerWhenAllocati } TEST_P(UnifiedMemoryPoolingManagerTest, whenGetPoolInfosCalledThenCorrectInfoIsReturned) { - auto &poolInfos = PoolInfo::getPoolInfos(device->getGfxCoreHelper()); + auto &poolInfos = usmMemAllocPoolsManager->getPoolInfos(); EXPECT_EQ(3u, poolInfos.size()); EXPECT_EQ(2 * MemoryConstants::kiloByte, poolInfos[0].poolSize); @@ -596,12 +606,12 @@ TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializedPoolsManagerWhenAllocati ASSERT_TRUE(usmMemAllocPoolsManager->isInitialized()); size_t totalSize = 0u; - for (auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (auto &poolInfo : usmMemAllocPoolsManager->getPoolInfos()) { totalSize += poolInfo.poolSize; } EXPECT_EQ(totalSize, usmMemAllocPoolsManager->totalSize); - for (auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (auto &poolInfo : usmMemAllocPoolsManager->getPoolInfos()) { auto &pool = usmMemAllocPoolsManager->pools[poolInfo][0]; ASSERT_EQ(1u, usmMemAllocPoolsManager->pools[poolInfo].size()); @@ -615,7 +625,7 @@ TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializedPoolsManagerWhenAllocati EXPECT_FALSE(pool->sizeIsAllowed(poolInfo.maxServicedSize + 1)); } - for (auto &poolInfo : PoolInfo::getPoolInfos(device->getGfxCoreHelper())) { + for (auto &poolInfo : usmMemAllocPoolsManager->getPoolInfos()) { size_t minServicedSize = poolInfo.minServicedSize ? poolInfo.minServicedSize : 1; auto poolAllocMinSize = usmMemAllocPoolsManager->createUnifiedMemoryAllocation(minServicedSize, *poolMemoryProperties.get()); @@ -637,7 +647,7 @@ TEST_P(UnifiedMemoryPoolingManagerTest, givenInitializedPoolsManagerWhenAllocati usmMemAllocPoolsManager->canAddPools = false; std::vector ptrsToFree; - auto thirdPoolInfo = PoolInfo::getPoolInfos(device->getGfxCoreHelper())[2]; + auto thirdPoolInfo = usmMemAllocPoolsManager->getPoolInfos()[2]; auto allocationsToOverfillThirdPool = thirdPoolInfo.poolSize / thirdPoolInfo.maxServicedSize + 1; for (auto i = 0u; i < allocationsToOverfillThirdPool; ++i) { auto ptr = usmMemAllocPoolsManager->createUnifiedMemoryAllocation(thirdPoolInfo.maxServicedSize, *poolMemoryProperties.get());