From 98fd9f5687826cd5974a761850ce5022c8c54998 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 31 Jul 2023 09:41:13 +0000 Subject: [PATCH] performance: change preferred allocation method on MTL devices prefer allocating resources by KMD Related-To: NEO-7194 Signed-off-by: Mateusz Jablonski --- shared/source/memory_manager/allocation_type.h | 6 ++++++ shared/source/memory_manager/memory_manager.h | 4 ---- .../mtl/os_agnostic_product_helper_mtl.inl | 5 +++++ .../windows/wddm_memory_manager_tests.cpp | 14 ++++++++++---- .../windows/wddm_special_heap_test.cpp | 2 +- .../xe_hpg_core/mtl/product_helper_tests_mtl.cpp | 7 +++++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/shared/source/memory_manager/allocation_type.h b/shared/source/memory_manager/allocation_type.h index 244f2824b9..b13d025ee0 100644 --- a/shared/source/memory_manager/allocation_type.h +++ b/shared/source/memory_manager/allocation_type.h @@ -6,6 +6,7 @@ */ #pragma once +#include namespace NEO { enum class AllocationType { @@ -58,4 +59,9 @@ enum class AllocationType { ASSERT_BUFFER, COUNT }; + +enum class GfxMemoryAllocationMethod : uint32_t { + UseUmdSystemPtr, + AllocateByKmd +}; } // namespace NEO diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 02a8cdfd46..6d09bd4bb1 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -43,10 +43,6 @@ class HostPtrManager; class OsContext; class PrefetchManager; -enum class GfxMemoryAllocationMethod : uint32_t { - UseUmdSystemPtr, - AllocateByKmd -}; enum AllocationUsage { TEMPORARY_ALLOCATION, REUSABLE_ALLOCATION, diff --git a/shared/source/xe_hpg_core/mtl/os_agnostic_product_helper_mtl.inl b/shared/source/xe_hpg_core/mtl/os_agnostic_product_helper_mtl.inl index 731f1cef9d..00dc3ba754 100644 --- a/shared/source/xe_hpg_core/mtl/os_agnostic_product_helper_mtl.inl +++ b/shared/source/xe_hpg_core/mtl/os_agnostic_product_helper_mtl.inl @@ -22,6 +22,11 @@ void ProductHelperHw::adjustSamplerState(void *sampler, const Hardwa } } +template <> +std::optional ProductHelperHw::getPreferredAllocationMethod() const { + return GfxMemoryAllocationMethod::AllocateByKmd; +} + template <> uint64_t ProductHelperHw::getHostMemCapabilitiesValue() const { return (UNIFIED_SHARED_MEMORY_ACCESS | UNIFIED_SHARED_MEMORY_ATOMIC_ACCESS); diff --git a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 8ff6088851..39b57aa3f5 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -110,7 +110,7 @@ TEST_F(WddmMemoryManagerTests, GivenAllocDataWithSVMCPUSetWhenAllocateGraphicsMe allocData.makeGPUVaDifferentThanCPUPtr = true; memoryManager->allocateGraphicsMemoryWithAlignment(allocData); - if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) { + if (memoryManager->getPreferredAllocationMethod(allocData.rootDeviceIndex) == GfxMemoryAllocationMethod::AllocateByKmd) { EXPECT_TRUE(memoryManager->allocateGraphicsMemoryUsingKmdAndMapItToCpuVACalled); } else { EXPECT_TRUE(memoryManager->allocateSystemMemoryAndCreateGraphicsAllocationFromItCalled); @@ -185,6 +185,7 @@ class MockAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWddm : public MemoryManag using WddmMemoryManager::adjustGpuPtrToHostAddressSpace; using WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToCpuVA; using WddmMemoryManager::allocateMemoryByKMD; + using WddmMemoryManager::getPreferredAllocationMethod; using WddmMemoryManager::mapGpuVirtualAddress; MockAllocateGraphicsMemoryUsingKmdAndMapItToCpuVAWddm(ExecutionEnvironment &executionEnvironment) : MemoryManagerCreate(false, false, executionEnvironment) {} @@ -239,7 +240,7 @@ TEST_F(WddmMemoryManagerAllocPathTests, givenAllocateGraphicsMemoryUsingKmdAndMa allocData.makeGPUVaDifferentThanCPUPtr = true; auto graphicsAllocation = memoryManager->allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(allocData, false); - if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) { + if (memoryManager->getPreferredAllocationMethod(allocData.rootDeviceIndex) == GfxMemoryAllocationMethod::AllocateByKmd && is64bit) { EXPECT_FALSE(memoryManager->mapGpuVirtualAddressWithCpuPtr); } else { EXPECT_TRUE(memoryManager->mapGpuVirtualAddressWithCpuPtr); @@ -510,7 +511,12 @@ TEST_F(WddmMemoryManagerTests, givenTypeWhenCallIsStatelessAccessRequiredThenPro TEST_F(WddmMemoryManagerTests, givenForcePreferredAllocationMethodFlagSetWhenGettingPreferredAllocationMethodThenValueFlagIsReturned) { DebugManagerStateRestore restorer; - EXPECT_EQ(preferredAllocationMethod, memoryManager->getPreferredAllocationMethod(0)); + auto &productHelper = executionEnvironment->rootDeviceEnvironments[0]->getProductHelper(); + if (productHelper.getPreferredAllocationMethod()) { + EXPECT_EQ(*productHelper.getPreferredAllocationMethod(), memoryManager->getPreferredAllocationMethod(0)); + } else { + EXPECT_EQ(preferredAllocationMethod, memoryManager->getPreferredAllocationMethod(0)); + } for (const auto &allocationMethod : {GfxMemoryAllocationMethod::UseUmdSystemPtr, GfxMemoryAllocationMethod::AllocateByKmd}) { DebugManager.flags.ForcePreferredAllocationMethod.set(static_cast(allocationMethod)); @@ -1460,7 +1466,7 @@ TEST_F(WddmMemoryManagerSimpleTest, whenAlignmentRequirementExceedsPageSizeThenA allocData.size = 1024; allocData.alignment = MemoryConstants::pageSize; memoryManager.allocateGraphicsMemoryWithAlignment(allocData); - if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) { + if (memoryManager.getPreferredAllocationMethod(allocData.rootDeviceIndex) == GfxMemoryAllocationMethod::AllocateByKmd) { EXPECT_EQ(0, memoryManager.callCount.allocateSystemMemoryAndCreateGraphicsAllocationFromIt); EXPECT_EQ(1, memoryManager.callCount.allocateGraphicsMemoryUsingKmdAndMapItToCpuVA); } else { diff --git a/shared/test/unit_test/os_interface/windows/wddm_special_heap_test.cpp b/shared/test/unit_test/os_interface/windows/wddm_special_heap_test.cpp index e3a03df781..5aa867ba91 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_special_heap_test.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_special_heap_test.cpp @@ -56,7 +56,7 @@ TEST_F(WddmFrontWindowPoolAllocatorTests, givenAllocateInFrontWindowPoolFlagWhen auto gmmHelper = memManager->getGmmHelper(allocData.rootDeviceIndex); EXPECT_EQ(allocation->getGpuBaseAddress(), gmmHelper->canonize(allocation->getGpuAddress())); - if (preferredAllocationMethod == GfxMemoryAllocationMethod::AllocateByKmd) { + if (memManager->getPreferredAllocationMethod(allocData.rootDeviceIndex) == GfxMemoryAllocationMethod::AllocateByKmd) { EXPECT_TRUE(allocation->isAllocationLockable()); } else { EXPECT_FALSE(allocation->isAllocationLockable()); 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 2bef74e1e1..b23e656fd6 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 @@ -364,3 +364,10 @@ MTLTEST_F(ProductHelperTestMtl, givenMtlWhenCheckIsCachingOnCpuAvailableThenAlwa const auto &productHelper = getHelper(); EXPECT_FALSE(productHelper.isCachingOnCpuAvailable()); } + +MTLTEST_F(ProductHelperTestMtl, givenMtlWhenCheckPreferredAllocationMethodThenAllocateByKmdIsReturned) { + const auto &productHelper = getHelper(); + auto preferredAllocationMethod = productHelper.getPreferredAllocationMethod(); + EXPECT_TRUE(preferredAllocationMethod.has_value()); + EXPECT_EQ(GfxMemoryAllocationMethod::AllocateByKmd, preferredAllocationMethod.value()); +} \ No newline at end of file