From b64210d3dbb0ff02da1071744949c9b9dab1a4b8 Mon Sep 17 00:00:00 2001 From: Pawel Wilma Date: Fri, 10 May 2019 11:30:07 +0200 Subject: [PATCH] Add local memory usage selector in memory manager Related-To: NEO-2906 Change-Id: I3172e9551b8d06437c273b122dc6e9d529155b5c Signed-off-by: Pawel Wilma --- runtime/memory_manager/CMakeLists.txt | 1 + .../memory_manager/definitions/storage_info.h | 1 + runtime/memory_manager/local_memory_usage.cpp | 14 ++ runtime/memory_manager/local_memory_usage.h | 13 +- runtime/memory_manager/memory_manager.cpp | 13 +- runtime/memory_manager/memory_manager.h | 7 +- .../memory_manager_banks_count.cpp | 14 ++ unit_tests/helpers/hw_helper_tests.cpp | 8 -- unit_tests/helpers/hw_helper_tests.h | 9 +- .../local_memory_usage_tests.cpp | 57 +++++++- ...nager_allocate_in_preferred_pool_tests.inl | 127 ++++++++++++------ .../memory_manager/memory_manager_tests.cpp | 5 +- .../mocks/linux/mock_drm_memory_manager.h | 3 +- unit_tests/mocks/mock_allocation_properties.h | 1 - unit_tests/mocks/mock_memory_manager.cpp | 3 +- unit_tests/mocks/mock_memory_manager.h | 2 + .../windows/mock_wddm_memory_manager.h | 3 +- 17 files changed, 205 insertions(+), 76 deletions(-) create mode 100644 runtime/memory_manager/memory_manager_banks_count.cpp diff --git a/runtime/memory_manager/CMakeLists.txt b/runtime/memory_manager/CMakeLists.txt index e032b91cb4..f19ed8890f 100644 --- a/runtime/memory_manager/CMakeLists.txt +++ b/runtime/memory_manager/CMakeLists.txt @@ -33,6 +33,7 @@ set(RUNTIME_SRCS_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/memory_constants.h ${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/memory_manager_banks_count.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_pool.h ${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.h diff --git a/runtime/memory_manager/definitions/storage_info.h b/runtime/memory_manager/definitions/storage_info.h index b8287704ad..17269972f8 100644 --- a/runtime/memory_manager/definitions/storage_info.h +++ b/runtime/memory_manager/definitions/storage_info.h @@ -10,5 +10,6 @@ namespace NEO { struct StorageInfo { uint32_t getNumHandles() const; + uint32_t getMemoryBanks() const { return 0u; } }; } // namespace NEO diff --git a/runtime/memory_manager/local_memory_usage.cpp b/runtime/memory_manager/local_memory_usage.cpp index 9fa6b6fda6..d6506a297a 100644 --- a/runtime/memory_manager/local_memory_usage.cpp +++ b/runtime/memory_manager/local_memory_usage.cpp @@ -8,6 +8,7 @@ #include "runtime/memory_manager/local_memory_usage.h" #include +#include #include namespace NEO { @@ -35,4 +36,17 @@ void LocalMemoryUsageBankSelector::reserveOnBank(uint32_t bankIndex, uint64_t al memorySizes[bankIndex] += allocationSize; } +void LocalMemoryUsageBankSelector::updateUsageInfo(uint32_t memoryBanks, uint64_t allocationSize, bool reserve) { + auto banks = std::bitset<32>(memoryBanks); + for (uint32_t bankIndex = 0; bankIndex < banks.size() && bankIndex < banksCount; bankIndex++) { + if (banks.test(bankIndex)) { + if (reserve) { + reserveOnBank(bankIndex, allocationSize); + } else { + freeOnBank(bankIndex, allocationSize); + } + } + } +} + } // namespace NEO diff --git a/runtime/memory_manager/local_memory_usage.h b/runtime/memory_manager/local_memory_usage.h index 724ca6260a..977a391c53 100644 --- a/runtime/memory_manager/local_memory_usage.h +++ b/runtime/memory_manager/local_memory_usage.h @@ -19,10 +19,14 @@ class LocalMemoryUsageBankSelector : public NonCopyableOrMovableClass { LocalMemoryUsageBankSelector() = delete; LocalMemoryUsageBankSelector(uint32_t banksCount); uint32_t getLeastOccupiedBank(); - void freeOnBank(uint32_t bankIndex, uint64_t allocationSize); - void reserveOnBank(uint32_t bankIndex, uint64_t allocationSize); + void reserveOnBanks(uint32_t memoryBanks, uint64_t allocationSize) { + updateUsageInfo(memoryBanks, allocationSize, true); + } + void freeOnBanks(uint32_t memoryBanks, uint64_t allocationSize) { + updateUsageInfo(memoryBanks, allocationSize, false); + } - MOCKABLE_VIRTUAL uint64_t getOccupiedMemorySizeForBank(uint32_t bankIndex) { + uint64_t getOccupiedMemorySizeForBank(uint32_t bankIndex) { UNRECOVERABLE_IF(bankIndex >= banksCount); return memorySizes[bankIndex].load(); } @@ -30,5 +34,8 @@ class LocalMemoryUsageBankSelector : public NonCopyableOrMovableClass { protected: uint32_t banksCount = 0; std::unique_ptr[]> memorySizes = nullptr; + void updateUsageInfo(uint32_t memoryBanks, uint64_t allocationSize, bool reserve); + void freeOnBank(uint32_t bankIndex, uint64_t allocationSize); + void reserveOnBank(uint32_t bankIndex, uint64_t allocationSize); }; } // namespace NEO diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 6542603eb3..279362c17f 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -25,6 +25,7 @@ #include "runtime/memory_manager/deferred_deleter.h" #include "runtime/memory_manager/host_ptr_manager.h" #include "runtime/memory_manager/internal_allocation_storage.h" +#include "runtime/memory_manager/local_memory_usage.h" #include "runtime/os_interface/os_context.h" #include "runtime/os_interface/os_interface.h" #include "runtime/utilities/stackvec.h" @@ -40,6 +41,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu if (DebugManager.flags.Enable64kbpages.get() > -1) { this->enable64kbpages = DebugManager.flags.Enable64kbpages.get() != 0; } + localMemoryUsageBankSelector.reset(new LocalMemoryUsageBankSelector(getBanksCount())); } MemoryManager::~MemoryManager() { @@ -147,6 +149,8 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) { if (isLocked) { freeAssociatedResourceImpl(*gfxAllocation); } + + localMemoryUsageBankSelector->freeOnBanks(gfxAllocation->storageInfo.getMemoryBanks(), gfxAllocation->getUnderlyingBufferSize()); freeGraphicsMemoryImpl(gfxAllocation); } //if not in use destroy in place @@ -201,7 +205,7 @@ OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *comm return osContext; } -bool MemoryManager::getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr) { +bool MemoryManager::getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo) { UNRECOVERABLE_IF(hostPtr == nullptr && !properties.flags.allocateMemory); UNRECOVERABLE_IF(properties.allocationType == GraphicsAllocation::AllocationType::UNKNOWN); @@ -298,7 +302,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.hostPtr = hostPtr; allocationData.size = properties.size; allocationData.type = properties.allocationType; - allocationData.storageInfo = MemoryManager::createStorageInfoFromProperties(properties); + allocationData.storageInfo = storageInfo; allocationData.alignment = properties.alignment ? properties.alignment : MemoryConstants::preferredAlignment; allocationData.imgInfo = properties.imgInfo; @@ -310,10 +314,13 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const AllocationProperties &properties, const void *hostPtr) { AllocationData allocationData; - getAllocationData(allocationData, properties, hostPtr); + getAllocationData(allocationData, properties, hostPtr, createStorageInfoFromProperties(properties)); AllocationStatus status = AllocationStatus::Error; GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status); + if (allocation) { + localMemoryUsageBankSelector->reserveOnBanks(allocationData.storageInfo.getMemoryBanks(), allocation->getUnderlyingBufferSize()); + } if (!allocation && status == AllocationStatus::RetryInNonDevicePool) { allocation = allocateGraphicsMemory(allocationData); } diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 7e51d796d2..496ad750b5 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -15,6 +15,7 @@ #include "runtime/memory_manager/gfx_partition.h" #include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/host_ptr_defines.h" +#include "runtime/memory_manager/local_memory_usage.h" #include "runtime/os_interface/32bit_memory.h" #include "engine_node.h" @@ -183,12 +184,12 @@ class MemoryManager { ImageInfo *imgInfo = nullptr; }; - static bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr); + static bool getAllocationData(AllocationData &allocationData, const AllocationProperties &properties, const void *hostPtr, const StorageInfo &storageInfo); static bool useInternal32BitAllocator(GraphicsAllocation::AllocationType allocationType) { return allocationType == GraphicsAllocation::AllocationType::KERNEL_ISA || allocationType == GraphicsAllocation::AllocationType::INTERNAL_HEAP; } - static StorageInfo createStorageInfoFromProperties(const AllocationProperties &properties); + StorageInfo createStorageInfoFromProperties(const AllocationProperties &properties); virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) = 0; virtual GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) = 0; @@ -243,6 +244,7 @@ class MemoryManager { virtual void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0; virtual void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) = 0; virtual void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { return unlockResourceImpl(graphicsAllocation); }; + uint32_t getBanksCount(); bool force32bitAllocations = false; bool virtualPaddingAvailable = false; @@ -260,6 +262,7 @@ class MemoryManager { std::unique_ptr multiContextResourceDestructor; std::unique_ptr allocator32Bit; GfxPartition gfxPartition; + std::unique_ptr localMemoryUsageBankSelector; }; std::unique_ptr createDeferredDeleter(); diff --git a/runtime/memory_manager/memory_manager_banks_count.cpp b/runtime/memory_manager/memory_manager_banks_count.cpp new file mode 100644 index 0000000000..cc4dee2b00 --- /dev/null +++ b/runtime/memory_manager/memory_manager_banks_count.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/memory_manager/memory_manager.h" + +namespace NEO { +uint32_t MemoryManager::getBanksCount() { + return 1u; +} +} // namespace NEO diff --git a/unit_tests/helpers/hw_helper_tests.cpp b/unit_tests/helpers/hw_helper_tests.cpp index 85b32e3946..61237d33e3 100644 --- a/unit_tests/helpers/hw_helper_tests.cpp +++ b/unit_tests/helpers/hw_helper_tests.cpp @@ -26,14 +26,6 @@ using namespace NEO; -void HwHelperFixture::SetUp() { - hardwareInfo = *platformDevices[0]; - DeviceFixture::SetUp(); -} -void HwHelperFixture::TearDown() { - DeviceFixture::TearDown(); -} - TEST(HwHelperSimpleTest, givenDebugVariableWhenAskingForRenderCompressionThenReturnCorrectValue) { DebugManagerStateRestore restore; HardwareInfo localHwInfo = **platformDevices; diff --git a/unit_tests/helpers/hw_helper_tests.h b/unit_tests/helpers/hw_helper_tests.h index 2b4a5e8ee3..28e4734b9f 100644 --- a/unit_tests/helpers/hw_helper_tests.h +++ b/unit_tests/helpers/hw_helper_tests.h @@ -14,13 +14,6 @@ using namespace NEO; -class HwHelperFixture : public DeviceFixture { - protected: - void SetUp(); - void TearDown(); - HardwareInfo hardwareInfo; -}; - -using HwHelperTest = Test; +using HwHelperTest = Test; void testDefaultImplementationOfSetupHardwareCapabilities(HwHelper &hwHelper, const HardwareInfo &hwInfo); diff --git a/unit_tests/memory_manager/local_memory_usage_tests.cpp b/unit_tests/memory_manager/local_memory_usage_tests.cpp index 752098d47a..93acfef9e4 100644 --- a/unit_tests/memory_manager/local_memory_usage_tests.cpp +++ b/unit_tests/memory_manager/local_memory_usage_tests.cpp @@ -14,7 +14,10 @@ namespace NEO { struct MockLocalMemoryUsageBankSelector : public LocalMemoryUsageBankSelector { using LocalMemoryUsageBankSelector::banksCount; + using LocalMemoryUsageBankSelector::freeOnBank; using LocalMemoryUsageBankSelector::LocalMemoryUsageBankSelector; + using LocalMemoryUsageBankSelector::reserveOnBank; + using LocalMemoryUsageBankSelector::updateUsageInfo; std::atomic *getMemorySizes() { return memorySizes.get(); } }; @@ -27,7 +30,7 @@ TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenItsCreatedAllVal } TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMemoryIsReservedOnGivenBankThenValueStoredInTheArrayIsCorrect) { - LocalMemoryUsageBankSelector selector(4u); + MockLocalMemoryUsageBankSelector selector(4u); uint64_t allocationSize = 1024u; auto bankIndex = selector.getLeastOccupiedBank(); @@ -37,7 +40,7 @@ TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMemoryIsReserved } TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMemoryIsReleasedThenValueIsCorrectlyAllocated) { - LocalMemoryUsageBankSelector selector(1u); + MockLocalMemoryUsageBankSelector selector(1u); uint64_t allocationSize = 1024u; auto bankIndex = selector.getLeastOccupiedBank(); @@ -75,7 +78,7 @@ TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMemoryAllocatedS } TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenIndexIsInvalidThenErrorIsReturned) { - LocalMemoryUsageBankSelector selector(3u); + MockLocalMemoryUsageBankSelector selector(3u); EXPECT_THROW(selector.reserveOnBank(8u, 1024u), std::exception); EXPECT_THROW(selector.freeOnBank(8u, 1024u), std::exception); EXPECT_THROW(selector.getOccupiedMemorySizeForBank(8u), std::exception); @@ -84,4 +87,52 @@ TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenIndexIsInvalidTh TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenItsCreatedWithZeroBanksThenErrorIsReturned) { EXPECT_THROW(LocalMemoryUsageBankSelector(0u), std::exception); } + +TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMultipleBanksAreUsedThenMemoryIsReservedOnEachOfThem) { + MockLocalMemoryUsageBankSelector selector(6u); + uint32_t banks = 5u; + uint64_t allocationSize = 1024u; + + selector.reserveOnBanks(banks, allocationSize); + EXPECT_EQ(allocationSize, selector.getOccupiedMemorySizeForBank(0u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(1u)); + EXPECT_EQ(allocationSize, selector.getOccupiedMemorySizeForBank(2u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(3u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(4u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(5u)); +} + +TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenMultipleBanksAreUsedThenMemoryIsReleasedOnEachOfThem) { + MockLocalMemoryUsageBankSelector selector(6u); + uint32_t banks = 5u; + uint64_t allocationSize = 1024u; + + selector.reserveOnBanks(banks, allocationSize); + selector.reserveOnBanks(banks, allocationSize); + + EXPECT_EQ(2 * allocationSize, selector.getOccupiedMemorySizeForBank(0u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(1u)); + EXPECT_EQ(2 * allocationSize, selector.getOccupiedMemorySizeForBank(2u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(3)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(4)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(5)); + + selector.freeOnBanks(banks, allocationSize); + EXPECT_EQ(allocationSize, selector.getOccupiedMemorySizeForBank(0u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(1u)); + EXPECT_EQ(allocationSize, selector.getOccupiedMemorySizeForBank(2u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(3u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(4u)); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(5u)); +} + +TEST(localMemoryUsageTest, givenLocalMemoryUsageBankSelectorWhenThereAreMoreThan32BanksThenOnly32AreUpdated) { + MockLocalMemoryUsageBankSelector selector(33u); + uint32_t banks = ~0u; + uint64_t allocationSize = 1024u; + + selector.reserveOnBanks(banks, allocationSize); + EXPECT_EQ(0u, selector.getOccupiedMemorySizeForBank(32)); +} + } // namespace NEO diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index 24d8c82cde..cca88e70e7 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -24,7 +24,8 @@ class MemoryManagerGetAlloctionDataTest : public testing::TestWithParam memoryManager(false, false, executionEnvironment); + MockMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -184,13 +193,13 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32BitFlagIsAllocatedThenNon32BitAllocationIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); - MemoryManagerCreate memoryManager(executionEnvironment); + MockMemoryManager memoryManager(executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); allocData.flags.allow32Bit = false; auto allocation = memoryManager.allocateGraphicsMemory(allocData); @@ -202,13 +211,13 @@ TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32B TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagFor32BitAllowedTypeIsAllocatedThenNon32BitAllocationIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); - MemoryManagerCreate memoryManager(executionEnvironment); + MockMemoryManager memoryManager(executionEnvironment); memoryManager.setForce32BitAllocations(false); AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -219,11 +228,11 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen64kbAllocationIsReturned) { MockExecutionEnvironment executionEnvironment(*platformDevices); - MemoryManagerCreate memoryManager(true, false, executionEnvironment); + MockMemoryManager memoryManager(true, false, executionEnvironment); AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -241,7 +250,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryWithoutAllow64kbP AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); allocData.flags.allow64kbPages = false; auto allocation = memoryManager.allocateGraphicsMemory(allocData); @@ -258,7 +267,7 @@ TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemory AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -271,13 +280,13 @@ TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemory TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen32BitAllocationOver64kbIsChosen) { MockExecutionEnvironment executionEnvironment(*platformDevices); - MemoryManagerCreate memoryManager(false, false, executionEnvironment); + MockMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; AllocationProperties properties(true, 10, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -292,12 +301,12 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHostPtrForBufferThenExistingMemoryIsUsedForAllocation) { MockExecutionEnvironment executionEnvironment(*platformDevices); - MemoryManagerCreate memoryManager(true, false, executionEnvironment); + MockMemoryManager memoryManager(true, false, executionEnvironment); AllocationData allocData; AllocationProperties properties(false, 1, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); char memory[1]; - MockMemoryManager::getAllocationData(allocData, properties, &memory); + MockMemoryManager::getAllocationData(allocData, properties, &memory, memoryManager.createStorageInfoFromProperties(properties)); auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); @@ -345,76 +354,100 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenBufferTypeIsPassedAndAllocateInDev TEST(MemoryManagerTest, givenSvmAllocationTypeWhenGetAllocationDataIsCalledThenAllocatingMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.allocateMemory); } TEST(MemoryManagerTest, givenSvmAllocationTypeWhenGetAllocationDataIsCalledThen64kbPagesAreAllowedAnd32BitAllocationIsDisallowed) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::SVM_ZERO_COPY}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.allow64kbPages); EXPECT_FALSE(allocData.flags.allow32Bit); } TEST(MemoryManagerTest, givenTagBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TAG_BUFFER}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::TAG_BUFFER}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenPreemptionTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::PREEMPTION}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::PREEMPTION}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenSharedContextImageTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::SHARED_CONTEXT_IMAGE}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenMCSTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::MCS}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::MCS}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenDeviceQueueBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::DEVICE_QUEUE_BUFFER}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenInternalHostMemoryTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenFillPatternTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::FILL_PATTERN}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::FILL_PATTERN}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenLinearStreamTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::LINEAR_STREAM}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::LINEAR_STREAM}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.useSystemMemory); EXPECT_TRUE(allocData.flags.requiresCpuAccess); } TEST(MemoryManagerTest, givenTimestampPacketTagBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequestedAndRequireCpuAccess) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER}; + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.useSystemMemory); EXPECT_TRUE(allocData.flags.requiresCpuAccess); } TEST(MemoryManagerTest, givenProfilingTagBufferTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::PROFILING_TAG_BUFFER}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); EXPECT_FALSE(allocData.flags.requiresCpuAccess); } @@ -426,7 +459,7 @@ TEST(MemoryManagerTest, givenAllocationPropertiesWithMultiOsContextCapableFlagEn properties.flags.multiOsContextCapable = true; AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.multiOsContextCapable); auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties); @@ -441,7 +474,7 @@ TEST(MemoryManagerTest, givenAllocationPropertiesWithMultiOsContextCapableFlagDi properties.flags.multiOsContextCapable = false; AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, memoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.multiOsContextCapable); auto allocation = memoryManager.allocateGraphicsMemoryWithProperties(properties); @@ -455,20 +488,26 @@ TEST(MemoryManagerTest, givenInternalHeapTypeThenUseInternal32BitAllocator) { TEST(MemoryManagerTest, givenInternalHeapTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::INTERNAL_HEAP}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::INTERNAL_HEAP}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.useSystemMemory); EXPECT_TRUE(allocData.flags.requiresCpuAccess); } TEST(MemoryManagerTest, givenKernelIsaTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::KERNEL_ISA}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::KERNEL_ISA}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.useSystemMemory); } TEST(MemoryManagerTest, givenLinearStreamWhenGetAllocationDataIsCalledThenSystemMemoryIsNotRequested) { AllocationData allocData; - MockMemoryManager::getAllocationData(allocData, {1, GraphicsAllocation::AllocationType::LINEAR_STREAM}, nullptr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{1, GraphicsAllocation::AllocationType::LINEAR_STREAM}; + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.useSystemMemory); EXPECT_TRUE(allocData.flags.requiresCpuAccess); } @@ -480,7 +519,9 @@ TEST(MemoryManagerTest, givenKernelIsaTypeThenUseInternal32BitAllocator) { TEST(MemoryManagerTest, givenExternalHostMemoryWhenGetAllocationDataIsCalledThenItHasProperFieldsSet) { AllocationData allocData; auto hostPtr = reinterpret_cast(0x1234); - MockMemoryManager::getAllocationData(allocData, {false, 1, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR}, hostPtr); + MockMemoryManager mockMemoryManager; + AllocationProperties properties{false, 1, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR}; + MockMemoryManager::getAllocationData(allocData, properties, hostPtr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.useSystemMemory); EXPECT_FALSE(allocData.flags.allocateMemory); EXPECT_FALSE(allocData.flags.allow32Bit); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 4dbbe2e001..dcb275beaa 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -1660,9 +1660,10 @@ TEST(MemoryManagerTest, givenAllocationTypesThatMayNeedL3FlushWhenCallingGetAllo GraphicsAllocation::AllocationType::SVM_ZERO_COPY, GraphicsAllocation::AllocationType::SVM_GPU, GraphicsAllocation::AllocationType::SVM_CPU}; + MockMemoryManager mockMemoryManager; for (auto allocationType : allocationTypesThatMayNeedL3Flush) { properties.allocationType = allocationType; - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_TRUE(allocData.flags.flushL3); } @@ -1671,7 +1672,7 @@ TEST(MemoryManagerTest, givenAllocationTypesThatMayNeedL3FlushWhenCallingGetAllo for (auto allocationType : allocationTypesThatMayNeedL3Flush) { properties.allocationType = allocationType; - MockMemoryManager::getAllocationData(allocData, properties, nullptr); + MockMemoryManager::getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); EXPECT_FALSE(allocData.flags.flushL3); } } diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index 7769af8334..5fffffdc5a 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -108,7 +108,8 @@ class TestedDrmMemoryManager : public MemoryManagerCreate { DrmAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; - getAllocationData(allocationData, MockAllocationProperties(allocateMemory, size, allocationType), ptr); + MockAllocationProperties properties(allocateMemory, size, allocationType); + getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); } }; diff --git a/unit_tests/mocks/mock_allocation_properties.h b/unit_tests/mocks/mock_allocation_properties.h index fcdd9a0474..782e1b4245 100644 --- a/unit_tests/mocks/mock_allocation_properties.h +++ b/unit_tests/mocks/mock_allocation_properties.h @@ -10,7 +10,6 @@ namespace NEO { struct MockAllocationProperties : public AllocationProperties { - public: MockAllocationProperties(size_t size, GraphicsAllocation::AllocationType allocationType) : AllocationProperties(size, allocationType) {} MockAllocationProperties(size_t size) : AllocationProperties(size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY) {} MockAllocationProperties(bool allocateMemory, size_t size) : AllocationProperties(allocateMemory, size, GraphicsAllocation::AllocationType::INTERNAL_HOST_MEMORY) {} diff --git a/unit_tests/mocks/mock_memory_manager.cpp b/unit_tests/mocks/mock_memory_manager.cpp index 37a17028c9..cdda0c45c5 100644 --- a/unit_tests/mocks/mock_memory_manager.cpp +++ b/unit_tests/mocks/mock_memory_manager.cpp @@ -93,7 +93,8 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryWithAlignment(const GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; - getAllocationData(allocationData, MockAllocationProperties(allocateMemory, size, allocationType), ptr); + MockAllocationProperties properties(allocateMemory, size, allocationType); + getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); } diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index 9f6817da3f..e47974a17e 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -37,6 +37,8 @@ class MockMemoryManager : public MemoryManagerCreate { using MemoryManager::createGraphicsAllocation; using MemoryManager::createStorageInfoFromProperties; using MemoryManager::getAllocationData; + using MemoryManager::getBanksCount; + using MemoryManager::localMemoryUsageBankSelector; using MemoryManager::multiContextResourceDestructor; using MemoryManager::registeredEngines; using MemoryManager::useInternal32BitAllocator; diff --git a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h index a1d5f0c18f..fcd81fd3b5 100644 --- a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h +++ b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h @@ -41,7 +41,8 @@ class MockWddmMemoryManager : public MemoryManagerCreate { GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType) { bool allocateMemory = ptr == nullptr; AllocationData allocationData; - getAllocationData(allocationData, MockAllocationProperties(allocateMemory, size, allocationType), ptr); + MockAllocationProperties properties(allocateMemory, size, allocationType); + getAllocationData(allocationData, properties, ptr, createStorageInfoFromProperties(properties)); return allocate32BitGraphicsMemoryImpl(allocationData); }