From 6992cb8aeb2e7feee27cf15f437b81c80747fe9d Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Thu, 27 Jun 2024 14:13:43 +0000 Subject: [PATCH] fix: Add experimental debug toggle to force 2M local memory size alignment Signed-off-by: Filip Hazubski --- .../debug_settings/debug_variables_base.inl | 1 + .../os_interface/linux/drm_memory_manager.cpp | 3 ++ .../windows/wddm_memory_manager.cpp | 5 +++ shared/test/common/test_files/igdrcl.config | 1 + .../linux/drm_memory_manager_tests.cpp | 36 +++++++++++++++++++ .../windows/wddm_memory_manager_tests.cpp | 11 ++++++ 6 files changed, 57 insertions(+) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index d83b60a73e..a643227d8b 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -551,6 +551,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalSmallBufferPoolAllocator, -1, "Exper DECLARE_DEBUG_VARIABLE(int32_t, ExperimentalCopyThroughLockWaitlistSizeThreshold, -1, "If less than given value, driver will wait for Waitlist on host, instead of sending appendBarrier. If 0, always use barrier.") DECLARE_DEBUG_VARIABLE(bool, ExperimentalEnableL0DebuggerForOpenCL, false, "Experimentally enable debugging OCL with L0 Debug API. When enabled - Level Zero debugging is disabled.") DECLARE_DEBUG_VARIABLE(bool, ExperimentalEnableTileAttach, true, "Experimentally enable attaching to tiles (subdevices).") +DECLARE_DEBUG_VARIABLE(bool, ExperimentalAlignLocalMemorySizeTo2MB, false, "Experimentally align all local memory allocations size to 2MB.") /*DRIVER TOGGLES*/ DECLARE_DEBUG_VARIABLE(bool, UseMaxSimdSizeToDeduceMaxWorkgroupSize, false, "With this flag on, max workgroup size is deduced using SIMD32 instead of SIMD8, this causes the max wkg size to be 4 times bigger") diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index a98ce935f9..7e0d16c89e 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -1872,6 +1872,9 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A } else { sizeAligned = alignUp(allocationData.size, MemoryConstants::pageSize64k); } + if (debugManager.flags.ExperimentalAlignLocalMemorySizeTo2MB.get()) { + sizeAligned = alignUp(sizeAligned, MemoryConstants::pageSize2M); + } gmm = this->makeGmmIfSingleHandle(allocationData, sizeAligned); } diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 37a5585378..9ee19be9dc 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -1389,6 +1389,11 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const alignment = alignmentSelector.selectAlignment(allocationData.size).alignment; sizeAligned = alignUp(allocationData.size, alignment); + if (debugManager.flags.ExperimentalAlignLocalMemorySizeTo2MB.get()) { + alignment = alignUp(alignment, MemoryConstants::pageSize2M); + sizeAligned = alignUp(sizeAligned, MemoryConstants::pageSize2M); + } + if (singleBankAllocation) { auto &productHelper = rootDeviceEnvironment.getHelper(); diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 7db94ef746..92a6f8ff35 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -502,6 +502,7 @@ ForceImagesSupport = -1 RemoveUserFenceInCmdlistResetAndDestroy = -1 ForceCsrLockInBcsEnqueueOnlyForGpgpuSubmission = -1 ExperimentalEnableTileAttach = 1 +ExperimentalAlignLocalMemorySizeTo2MB = 0 DirectSubmissionDisablePrefetcher = -1 ForceDefaultGrfCompilationMode = 0 ForceLargeGrfCompilationMode = 0 diff --git a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index c402253226..bb3096c146 100644 --- a/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -6674,6 +6674,42 @@ TEST_F(DrmMemoryManagerLocalMemoryAlignmentTest, givenCustomAlignmentWhenAllocat } } +TEST_F(DrmMemoryManagerLocalMemoryAlignmentTest, givenForced2MBSizeAlignmentWhenAllocatingAllocationThenUseProperAlignment) { + debugManager.flags.ExperimentalAlignLocalMemorySizeTo2MB.set(true); + + AllocationData allocationData; + allocationData.allFlags = 0; + allocationData.flags.allocateMemory = true; + allocationData.rootDeviceIndex = rootDeviceIndex; + allocationData.type = AllocationType::buffer; + allocationData.flags.resource48Bit = true; + MemoryManager::AllocationStatus allocationStatus; + + { + allocationData.size = 1; + auto memoryManager = createMemoryManager(); + auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocationData, allocationStatus); + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryManager::AllocationStatus::Success, allocationStatus); + EXPECT_TRUE(isAllocationWithinHeap(*memoryManager, *allocation, HeapIndex::heapStandard2MB)); + EXPECT_EQ(2 * MemoryConstants::megaByte, allocation->getUnderlyingBufferSize()); + EXPECT_EQ(2 * MemoryConstants::megaByte, allocation->getReservedAddressSize()); + memoryManager->freeGraphicsMemory(allocation); + } + + { + allocationData.size = 2 * MemoryConstants::megaByte + 1; + auto memoryManager = createMemoryManager(); + auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocationData, allocationStatus); + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryManager::AllocationStatus::Success, allocationStatus); + EXPECT_TRUE(isAllocationWithinHeap(*memoryManager, *allocation, HeapIndex::heapStandard2MB)); + EXPECT_EQ(4 * MemoryConstants::megaByte, allocation->getUnderlyingBufferSize()); + EXPECT_EQ(4 * MemoryConstants::megaByte, allocation->getReservedAddressSize()); + memoryManager->freeGraphicsMemory(allocation); + } +} + TEST_F(DrmMemoryManagerWithLocalMemoryAndExplicitExpectationsTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedForBufferThenLocalMemoryAllocationIsReturnedFromStandard64KbHeap) { MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; 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 faf5c15d53..f33deb7529 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 @@ -1941,6 +1941,17 @@ TEST_F(WddmMemoryManagerSimpleTest, givenCustomAlignmentBiggerThan2MbAndAllocati testAlignment(size, expectedAlignment); } +TEST_F(WddmMemoryManagerSimpleTest, givenForced2MBSizeAlignmentWhenAllocationInDevicePoolIsCreatedThenUseProperAlignment) { + debugManager.flags.ExperimentalAlignLocalMemorySizeTo2MB.set(true); + + uint32_t size = 1; + uint32_t expectedAlignment = MemoryConstants::pageSize2M; + testAlignment(size, expectedAlignment); + + size = 1 + MemoryConstants::pageSize2M; + testAlignment(size, expectedAlignment); +} + TEST_F(WddmMemoryManagerSimpleTest, givenAllocationLessThen2MbWhenAllocationInDevicePoolIsCreatedThenUse64KbAlignment) { const uint32_t expectedAlignment = MemoryConstants::pageSize64k; const uint32_t size = 2 * MemoryConstants::megaByte - 1;