From 61ca84e94b84f62efae8a252f84d40ae21b8d63e Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Wed, 9 Feb 2022 13:14:31 +0000 Subject: [PATCH] Pass memory placement info to StorageInfo Signed-off-by: Bartosz Dunajski --- .../unit_test/gmm_helper/gmm_helper_tests.cpp | 12 ++++++++ .../memory_manager/memory_manager_tests.cpp | 30 +++++++++++++++++++ ..._manager_allocate_in_device_pool_tests.cpp | 1 + shared/source/gmm_helper/gmm.cpp | 5 ++-- .../memory_manager/definitions/storage_info.h | 3 +- .../source/memory_manager/memory_manager.cpp | 3 ++ ..._device_address_space_drm_or_wddm_test.cpp | 1 + 7 files changed, 51 insertions(+), 4 deletions(-) diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 992ad4a101..60d4a004a2 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -1303,6 +1303,7 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUsingLocalMemoryAndAllocation StorageInfo storageInfo{}; storageInfo.isLockable = true; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; auto gmm = std::make_unique(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NonLocalOnly); EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.LocalOnly); @@ -1313,6 +1314,7 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUsingLocalMemoryFalseAndAlloc StorageInfo storageInfo{}; storageInfo.isLockable = false; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; auto gmm = std::make_unique(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NonLocalOnly); EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.LocalOnly); @@ -1324,6 +1326,7 @@ TEST_F(GmmLocalMemoryTests, givenLocalMemoryAndNotLockableAllocationAndStorageIn storageInfo.localOnlyRequired = true; storageInfo.isLockable = false; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; auto gmm = std::make_unique(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); @@ -1336,6 +1339,7 @@ TEST_F(GmmLocalMemoryTests, givenLocalMemoryAndStorageInfoWithLocalOnlyRequiredW storageInfo.localOnlyRequired = true; storageInfo.isLockable = false; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; DebugManagerStateRestore restorer; @@ -1368,6 +1372,7 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryAndCompressionEnabledWhenUsingLoc DebugManager.flags.RenderCompressedBuffersEnabled.set(1); StorageInfo storageInfo{}; storageInfo.isLockable = false; + storageInfo.systemMemoryPlacement = false; storageInfo.memoryBanks.set(1); auto gmm = std::make_unique(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, true, storageInfo, true); @@ -1383,6 +1388,7 @@ TEST_F(GmmLocalMemoryTests, givenFtrLocalMemoryWhenUseSystemMemoryIsFalseAndAllo DebugManager.flags.SetCommandStreamReceiver.set(csrMode); StorageInfo storageInfo{}; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; storageInfo.isLockable = false; auto gmm = std::make_unique(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); EXPECT_EQ(0u, gmm->resourceParams.Flags.Info.NonLocalOnly); @@ -1406,6 +1412,7 @@ TEST_F(GmmLocalMemoryTests, givenUseLocalMemoryInImageInfoTrueWhenGmmIsCreatedTh imgInfo.useLocalMemory = true; StorageInfo storageInfo = {}; + storageInfo.systemMemoryPlacement = false; storageInfo.memoryBanks.set(1); auto gmm = std::make_unique(getGmmClientContext(), imgInfo, storageInfo, false); @@ -1433,6 +1440,7 @@ TEST_F(GmmLocalMemoryTests, givenUseCompressionAndLocalMemoryInImageInfoTrueWhen StorageInfo storageInfo = {}; storageInfo.memoryBanks.set(1); + storageInfo.systemMemoryPlacement = false; auto gmm = std::make_unique(getGmmClientContext(), imgInfo, storageInfo, true); EXPECT_TRUE(gmm->isCompressionEnabled); @@ -1498,6 +1506,7 @@ TEST_F(MultiTileGmmTests, givenMultiTileAllocationWithoutCloningWhenGmmIsCreated StorageInfo storageInfo; storageInfo.memoryBanks = 1; storageInfo.cloningOfPageTables = false; + storageInfo.systemMemoryPlacement = false; Gmm gmm(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); @@ -1522,6 +1531,7 @@ TEST_F(MultiTileGmmTests, givenMultiTileWhenGmmIsCreatedWithNonLocalMemoryThenMu TEST_F(MultiTileGmmTests, givenMultiTileWhenGmmIsCreatedWithSpecificMemoryBanksThenMultitileArchIsEnabled) { StorageInfo storageInfo; + storageInfo.systemMemoryPlacement = false; storageInfo.memoryBanks = 1u; storageInfo.cloningOfPageTables = false; @@ -1538,6 +1548,7 @@ TEST_F(MultiTileGmmTests, givenMultiTileWhenGmmIsCreatedWithCloningEnabledThenGp StorageInfo storageInfo; storageInfo.memoryBanks = 2u; storageInfo.cloningOfPageTables = true; + storageInfo.systemMemoryPlacement = false; storageInfo.pageTablesVisibility = 3u; Gmm gmm(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); @@ -1554,6 +1565,7 @@ TEST_F(MultiTileGmmTests, whenAllocationIsTileInstancedWithoutClonningPageTables storageInfo.cloningOfPageTables = false; storageInfo.tileInstanced = true; storageInfo.memoryBanks = 2u; + storageInfo.systemMemoryPlacement = false; Gmm gmm(getGmmClientContext(), nullptr, 1, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, storageInfo, true); diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index afca3c3136..cc3c5b348e 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -3022,6 +3022,36 @@ TEST(MemoryManagerTest, givenDebugModuleAreaAllocationTypeWhenCallingGetAllocati EXPECT_EQ(1u, allocData.flags.use32BitFrontWindow); } +TEST(MemoryManagerTest, givenStorageInfoWithParamsWhenGettingAllocDataForSystemMemoryThenSetSystemMemoryFlag) { + AllocationData allocData; + AllocationProperties properties(mockRootDeviceIndex, 1, AllocationType::BUFFER_HOST_MEMORY, mockDeviceBitfield); + + EXPECT_NE(0lu, mockDeviceBitfield.to_ulong()); + + MockMemoryManager mockMemoryManager; + auto storageInfo = mockMemoryManager.createStorageInfoFromProperties(properties); + EXPECT_NE(0lu, storageInfo.memoryBanks.to_ulong()); + + mockMemoryManager.getAllocationData(allocData, properties, nullptr, storageInfo); + EXPECT_EQ(1u, allocData.flags.useSystemMemory); + EXPECT_TRUE(allocData.storageInfo.systemMemoryPlacement); +} + +TEST(MemoryManagerTest, givenStorageInfoWithParamsWhenGettingAllocDataForLocalMemoryThenClearSystemMemoryFlag) { + AllocationData allocData; + AllocationProperties properties(mockRootDeviceIndex, 1, AllocationType::BUFFER, mockDeviceBitfield); + + EXPECT_NE(0lu, mockDeviceBitfield.to_ulong()); + + MockMemoryManager mockMemoryManager; + auto storageInfo = mockMemoryManager.createStorageInfoFromProperties(properties); + EXPECT_NE(0lu, storageInfo.memoryBanks.to_ulong()); + + mockMemoryManager.getAllocationData(allocData, properties, nullptr, storageInfo); + EXPECT_EQ(0u, allocData.flags.useSystemMemory); + EXPECT_FALSE(allocData.storageInfo.systemMemoryPlacement); +} + TEST(MemoryManagerTest, WhenCallingIsAllocationTypeToCaptureThenScratchAndPrivateTypesReturnTrue) { MockMemoryManager mockMemoryManager; diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp index 74ab8629c5..6e517ea698 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.cpp @@ -66,6 +66,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenShareableAllocationWhenAllocateInDevice allocData.flags.allocateMemory = true; allocData.flags.shareable = true; allocData.storageInfo.memoryBanks = 2; + allocData.storageInfo.systemMemoryPlacement = false; auto allocation = memoryManager->allocateGraphicsMemoryInDevicePool(allocData, status); EXPECT_NE(nullptr, allocation); diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index 008da1edaa..e601761287 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -333,10 +333,9 @@ uint32_t Gmm::getAuxQPitch() { void Gmm::applyMemoryFlags(StorageInfo &storageInfo) { auto hardwareInfo = clientContext->getHardwareInfo(); - bool systemMemoryPool = (storageInfo.getMemoryBanks() == 0); if (hardwareInfo->featureTable.flags.ftrLocalMemory) { - if (systemMemoryPool) { + if (storageInfo.systemMemoryPlacement) { resourceParams.Flags.Info.NonLocalOnly = 1; } else { if (extraMemoryFlagsRequired()) { @@ -352,7 +351,7 @@ void Gmm::applyMemoryFlags(StorageInfo &storageInfo) { if (hardwareInfo->featureTable.flags.ftrMultiTileArch) { resourceParams.MultiTileArch.Enable = 1; - if (systemMemoryPool) { + if (storageInfo.systemMemoryPlacement) { resourceParams.MultiTileArch.GpuVaMappingSet = hardwareInfo->gtSystemInfo.MultiTileArchInfo.TileMask; resourceParams.MultiTileArch.LocalMemPreferredSet = 0; resourceParams.MultiTileArch.LocalMemEligibilitySet = 0; diff --git a/shared/source/memory_manager/definitions/storage_info.h b/shared/source/memory_manager/definitions/storage_info.h index 73c4977f6b..71cc6784eb 100644 --- a/shared/source/memory_manager/definitions/storage_info.h +++ b/shared/source/memory_manager/definitions/storage_info.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -31,6 +31,7 @@ struct StorageInfo { bool cpuVisibleSegment = false; bool isLockable = false; bool localOnlyRequired = false; + bool systemMemoryPlacement = true; char resourceTag[AppResourceDefines::maxStrLen + 1] = ""; uint32_t getMemoryBanks() const { return static_cast(memoryBanks.to_ulong()); } uint32_t getTotalBanksCnt() const { return Math::log2(getMemoryBanks()) + 1; } diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index f2f527b0b8..44815ad589 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -464,6 +464,9 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo overrideAllocationData(allocationData, properties); allocationData.flags.isUSMHostAllocation = properties.flags.isUSMHostAllocation; + + allocationData.storageInfo.systemMemoryPlacement = allocationData.flags.useSystemMemory; + return true; } diff --git a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp index 60e41ba49c..02708cd602 100644 --- a/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp +++ b/shared/test/unit_test/os_interface/wddm_linux/configure_device_address_space_drm_or_wddm_test.cpp @@ -255,6 +255,7 @@ HWTEST2_F(GmmTestsDG2, givenGmmForImageWithForceLocalMemThenNonLocalIsSetToFalse NEO::StorageInfo storageInfo = {}; storageInfo.localOnlyRequired = true; storageInfo.memoryBanks = 2; + storageInfo.systemMemoryPlacement = false; std::unique_ptr gmm(new NEO::Gmm(mockExecEnv.rootDeviceEnvironments[0]->getGmmClientContext(), imgInfo, storageInfo, false));