From 298fcb868b1f64dda960560d89529c059779a1ca Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 8 Oct 2025 12:28:37 +0000 Subject: [PATCH] fix: Set init zero flag for preemption buffer Related-To: HSD-16028003349 Signed-off-by: Maciej Plewka Signed-off-by: Mateusz Jablonski --- .../source/debug_settings/debug_variables_base.inl | 1 + .../memory_manager/definitions/storage_info.cpp | 12 ++++++++++++ .../source/memory_manager/definitions/storage_info.h | 1 + shared/source/memory_manager/graphics_allocation.h | 3 +++ shared/test/common/test_files/igdrcl.config | 1 + .../memory_manager/graphics_allocation_tests.cpp | 9 +++++++++ .../unit_test/memory_manager/storage_info_tests.cpp | 11 +++++++++++ 7 files changed, 38 insertions(+) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index b513609b55..4accddd491 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -654,6 +654,7 @@ DECLARE_DEBUG_VARIABLE(int64_t, ForceNonSystemMemoryPlacement, 0, "0: default, DECLARE_DEBUG_VARIABLE(int64_t, ForceUncachedGmmUsageType, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force uncached gmm resource type") DECLARE_DEBUG_VARIABLE(int64_t, ForceMultiTileAllocPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force allocation to be replicated across all tiles") DECLARE_DEBUG_VARIABLE(int64_t, ForceSingleTileAllocPlacement, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, force allocation to NOT be replicated") +DECLARE_DEBUG_VARIABLE(int64_t, InitAllocWithZeros, 0, "0: default, >0: (bitmask) for given Graphics Allocation Type, set zero init flag to GMM") DECLARE_DEBUG_VARIABLE(int64_t, DisableIndirectAccess, -1, "0: default, 0: Use indirect access settings provided by application, 1: Disable indirect access and ignore settings provided by application") DECLARE_DEBUG_VARIABLE(int32_t, UseVmBind, -1, "Use new residency model on Linux (requires kernel support), -1: default, 0: disabled, 1: enabled") DECLARE_DEBUG_VARIABLE(int32_t, EnableStaticPartitioning, -1, "Divide workload into partitions during dispatch, -1: default, 0: disabled, 1: enabled") diff --git a/shared/source/memory_manager/definitions/storage_info.cpp b/shared/source/memory_manager/definitions/storage_info.cpp index b37e74809c..2d72c273d9 100644 --- a/shared/source/memory_manager/definitions/storage_info.cpp +++ b/shared/source/memory_manager/definitions/storage_info.cpp @@ -10,6 +10,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/app_resource_helper.h" #include "shared/source/helpers/basic_math.h" +#include "shared/source/helpers/bit_helpers.h" #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/memory_manager/allocation_properties.h" #include "shared/source/memory_manager/local_memory_usage.h" @@ -144,6 +145,17 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope rootDeviceEnv->getReleaseHelper(), properties.flags.preferCompressed); + storageInfo.needsToBeZeroedAtInit = [](NEO::AllocationType allocType) { + auto out = GraphicsAllocation::isZeroInitRequired(allocType); + + auto initWithZerosMask = debugManager.flags.InitAllocWithZeros.get(); + if (initWithZerosMask) { + out = isBitSet(initWithZerosMask, static_cast(allocType) - 1); + } + + return out; + }(properties.allocationType); + if (debugManager.flags.ForceMultiTileAllocPlacement.get()) { UNRECOVERABLE_IF(properties.allocationType == AllocationType::unknown); if ((1llu << (static_cast(properties.allocationType) - 1)) & debugManager.flags.ForceMultiTileAllocPlacement.get()) { diff --git a/shared/source/memory_manager/definitions/storage_info.h b/shared/source/memory_manager/definitions/storage_info.h index b79023d40f..82178d862a 100644 --- a/shared/source/memory_manager/definitions/storage_info.h +++ b/shared/source/memory_manager/definitions/storage_info.h @@ -36,5 +36,6 @@ struct StorageInfo { bool systemMemoryForced = false; char resourceTag[AppResourceDefines::maxStrLen + 1] = ""; bool isChunked = false; + bool needsToBeZeroedAtInit = false; }; } // namespace NEO diff --git a/shared/source/memory_manager/graphics_allocation.h b/shared/source/memory_manager/graphics_allocation.h index e9fd5a7092..0dc2b2eef0 100644 --- a/shared/source/memory_manager/graphics_allocation.h +++ b/shared/source/memory_manager/graphics_allocation.h @@ -269,6 +269,9 @@ class GraphicsAllocation : public IDNode, NEO::NonCopyableAn allocationType == AllocationType::ringBuffer || allocationType == AllocationType::semaphoreBuffer; } + static bool isZeroInitRequired(AllocationType allocationType) { + return allocationType == AllocationType::preemption; + } static uint32_t getNumHandlesForKmdSharedAllocation(uint32_t numBanks); diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index f2ccd5367f..3fc066e2b6 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -309,6 +309,7 @@ DisablePipeControlPrecedingPostSyncCommand = -1 OverrideMultiStoragePlacement = -1 ForceMultiTileAllocPlacement = 0 ForceSingleTileAllocPlacement = 0 +InitAllocWithZeros = 0 FormatForStatelessCompressionWithUnifiedMemory = 0xF BcsCompressionFormatForXe2Plus = -1 ForceBufferCompressionFormat = -1 diff --git a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp index 9e94324dc7..ddaa51df0d 100644 --- a/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp +++ b/shared/test/unit_test/memory_manager/graphics_allocation_tests.cpp @@ -537,3 +537,12 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationsWhenAllocationTypeIsRingBuf graphicsAllocation.allocationType = AllocationType::ringBuffer; EXPECT_TRUE(graphicsAllocation.hasAllocationReadOnlyType()); } +TEST(GraphicsAllocationTest, givenOtherThanPreemptionAllocationTypeWhenIsZeroInitRequiredIsCalledThenFalseReturned) { + for (std::underlying_type_t allocType = 0; allocType < static_cast>(AllocationType::count); allocType++) { + if (static_cast(allocType) == AllocationType::preemption) { + EXPECT_TRUE(GraphicsAllocation::isZeroInitRequired(static_cast(allocType))); + } else { + EXPECT_FALSE(GraphicsAllocation::isZeroInitRequired(static_cast(allocType))); + } + } +} diff --git a/shared/test/unit_test/memory_manager/storage_info_tests.cpp b/shared/test/unit_test/memory_manager/storage_info_tests.cpp index a6a5d7751c..e0a799d090 100644 --- a/shared/test/unit_test/memory_manager/storage_info_tests.cpp +++ b/shared/test/unit_test/memory_manager/storage_info_tests.cpp @@ -110,6 +110,17 @@ TEST_F(MultiDeviceStorageInfoTest, givenEnabledFlagForForceSingleTileAllocPlacem } } +TEST_F(MultiDeviceStorageInfoTest, givenEnabledFlagForInitAllocWithZerosWhenCreatingStorageInfoForAllocationThenZeroedNeededIsSet) { + DebugManagerStateRestore restorer; + + for (std::underlying_type_t allocType = 1; allocType < static_cast>(AllocationType::count); allocType++) { + debugManager.flags.InitAllocWithZeros.set(1ull << (allocType - 1)); + AllocationProperties properties{mockRootDeviceIndex, false, 0u, static_cast(allocType), false, false, singleTileMask}; + auto storageInfo = memoryManager->createStorageInfoFromProperties(properties); + EXPECT_TRUE(storageInfo.needsToBeZeroedAtInit); + } +} + TEST_F(MultiDeviceStorageInfoTest, whenCreatingStorageInfoForPrivateSurfaceWithOneTileThenOnlySingleBankIsUsed) { AllocationProperties properties{mockRootDeviceIndex, false, 0u, AllocationType::privateSurface, false, false, singleTileMask}; auto storageInfo = memoryManager->createStorageInfoFromProperties(properties);