diff --git a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index a6b49a522c..0f1abf6321 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -564,10 +564,10 @@ TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevice auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_NE(nullptr, allocation); EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool()); - EXPECT_EQ(allocation->getUnderlyingBufferSize(), memoryManager.localMemoryUsageBankSelector[allocProperties.rootDeviceIndex]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(allocation->getUnderlyingBufferSize(), memoryManager.getLocalMemoryUsageBankSelector(allocation->getAllocationType(), allocation->getRootDeviceIndex())->getOccupiedMemorySizeForBank(0)); memoryManager.freeGraphicsMemory(allocation); - EXPECT_EQ(0u, memoryManager.localMemoryUsageBankSelector[allocProperties.rootDeviceIndex]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(0u, memoryManager.getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, mockRootDeviceIndex)->getOccupiedMemorySizeForBank(0)); } TEST(MemoryManagerTest, givenSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenlocalMemoryUsageIsNotUpdated) { @@ -577,8 +577,29 @@ TEST(MemoryManagerTest, givenSetUseSystemMemoryWhenGraphicsAllocationInDevicePoo AllocationProperties allocProperties(mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, mockDeviceBitfield); auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); EXPECT_NE(nullptr, allocation); - EXPECT_EQ(0u, memoryManager.localMemoryUsageBankSelector[allocProperties.rootDeviceIndex]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(0u, memoryManager.getLocalMemoryUsageBankSelector(allocation->getAllocationType(), allocation->getRootDeviceIndex())->getOccupiedMemorySizeForBank(0)); memoryManager.freeGraphicsMemory(allocation); - EXPECT_EQ(0u, memoryManager.localMemoryUsageBankSelector[allocProperties.rootDeviceIndex]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(0u, memoryManager.getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, mockRootDeviceIndex)->getOccupiedMemorySizeForBank(0)); +} + +TEST(MemoryManagerTest, givenInternalAllocationTypeWhenIsAllocatedInDevicePoolThenIntenalUsageBankSelectorIsUpdated) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + MockMemoryManager memoryManager(false, true, executionEnvironment); + + AllocationProperties allocProperties(mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SEMAPHORE_BUFFER, mockDeviceBitfield); + auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr); + + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(0u, memoryManager.externalLocalMemoryUsageBankSelector[allocation->getRootDeviceIndex()]->getOccupiedMemorySizeForBank(0)); + + if (allocation->getMemoryPool() == MemoryPool::LocalMemory) { + EXPECT_EQ(allocation->getUnderlyingBufferSize(), memoryManager.internalLocalMemoryUsageBankSelector[allocation->getRootDeviceIndex()]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(memoryManager.getLocalMemoryUsageBankSelector(allocation->getAllocationType(), allocation->getRootDeviceIndex()), memoryManager.internalLocalMemoryUsageBankSelector[allocation->getRootDeviceIndex()].get()); + } + + memoryManager.freeGraphicsMemory(allocation); + + EXPECT_EQ(0u, memoryManager.externalLocalMemoryUsageBankSelector[mockRootDeviceIndex]->getOccupiedMemorySizeForBank(0)); + EXPECT_EQ(0u, memoryManager.internalLocalMemoryUsageBankSelector[mockRootDeviceIndex]->getOccupiedMemorySizeForBank(0)); } diff --git a/opencl/test/unit_test/memory_manager/storage_info_tests.cpp b/opencl/test/unit_test/memory_manager/storage_info_tests.cpp index f002d3cf3f..bb44038493 100644 --- a/opencl/test/unit_test/memory_manager/storage_info_tests.cpp +++ b/opencl/test/unit_test/memory_manager/storage_info_tests.cpp @@ -348,7 +348,7 @@ TEST_F(MultiDeviceStorageInfoTest, givenReadOnlyBufferToBeCopiedAcrossTilesWhenD TEST_F(MultiDeviceStorageInfoTest, givenLeastOccupiedBankAndOtherBitsEnabledInSubDeviceBitfieldWhenCreateStorageInfoThenTakeLeastOccupiedBankAsMemoryBank) { AllocationProperties properties{mockRootDeviceIndex, false, 1u, GraphicsAllocation::AllocationType::UNKNOWN, false, singleTileMask}; - auto leastOccupiedBank = memoryManager->localMemoryUsageBankSelector[properties.rootDeviceIndex]->getLeastOccupiedBank(properties.subDevicesBitfield); + auto leastOccupiedBank = memoryManager->getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->getLeastOccupiedBank(properties.subDevicesBitfield); properties.subDevicesBitfield.set(leastOccupiedBank); properties.subDevicesBitfield.set(leastOccupiedBank + 1); EXPECT_EQ(2u, properties.subDevicesBitfield.count()); @@ -422,7 +422,7 @@ TEST_F(MultiDeviceStorageInfoTest, allTilesMask}; auto storageInfo = memoryManager->createStorageInfoFromProperties(properties); - auto leastOccupiedBank = memoryManager->localMemoryUsageBankSelector[properties.rootDeviceIndex]->getLeastOccupiedBank(properties.subDevicesBitfield); + auto leastOccupiedBank = memoryManager->getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->getLeastOccupiedBank(properties.subDevicesBitfield); DeviceBitfield allocationMask; allocationMask.set(leastOccupiedBank); diff --git a/opencl/test/unit_test/mocks/mock_memory_manager.h b/opencl/test/unit_test/mocks/mock_memory_manager.h index 0e4abcdf96..6a61cfebb7 100644 --- a/opencl/test/unit_test/mocks/mock_memory_manager.h +++ b/opencl/test/unit_test/mocks/mock_memory_manager.h @@ -38,9 +38,10 @@ class MockMemoryManager : public MemoryManagerCreate { using MemoryManager::createGraphicsAllocation; using MemoryManager::createStorageInfoFromProperties; using MemoryManager::defaultEngineIndex; + using MemoryManager::externalLocalMemoryUsageBankSelector; using MemoryManager::getAllocationData; using MemoryManager::gfxPartitions; - using MemoryManager::localMemoryUsageBankSelector; + using MemoryManager::internalLocalMemoryUsageBankSelector; using MemoryManager::multiContextResourceDestructor; using MemoryManager::overrideAllocationData; using MemoryManager::pageFaultManager; diff --git a/shared/source/memory_manager/definitions/storage_info.cpp b/shared/source/memory_manager/definitions/storage_info.cpp index b819f0d752..42a50a0cec 100644 --- a/shared/source/memory_manager/definitions/storage_info.cpp +++ b/shared/source/memory_manager/definitions/storage_info.cpp @@ -19,7 +19,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope } const auto deviceCount = HwHelper::getSubDevicesCount(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getHardwareInfo()); - const auto leastOccupiedBank = localMemoryUsageBankSelector[properties.rootDeviceIndex]->getLeastOccupiedBank(properties.subDevicesBitfield); + const auto leastOccupiedBank = getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->getLeastOccupiedBank(properties.subDevicesBitfield); const auto subDevicesMask = executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->deviceAffinityMask.getGenericSubDevicesMask().to_ulong(); const DeviceBitfield allTilesValue(properties.subDevicesBitfield.count() == 1 diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 97ddd5b6dc..be7e0c5a50 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -49,7 +49,8 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < rootEnvCount; ++rootDeviceIndex) { auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); - localMemoryUsageBankSelector.emplace_back(new LocalMemoryUsageBankSelector(HwHelper::getSubDevicesCount(hwInfo))); + internalLocalMemoryUsageBankSelector.emplace_back(new LocalMemoryUsageBankSelector(HwHelper::getSubDevicesCount(hwInfo))); + externalLocalMemoryUsageBankSelector.emplace_back(new LocalMemoryUsageBankSelector(HwHelper::getSubDevicesCount(hwInfo))); this->localMemorySupported.push_back(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo)); this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages && !!DebugManager.flags.Enable64kbpages.get()); @@ -212,7 +213,7 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) { freeAssociatedResourceImpl(*gfxAllocation); } - localMemoryUsageBankSelector[gfxAllocation->getRootDeviceIndex()]->freeOnBanks(gfxAllocation->storageInfo.getMemoryBanks(), gfxAllocation->getUnderlyingBufferSize()); + getLocalMemoryUsageBankSelector(gfxAllocation->getAllocationType(), gfxAllocation->getRootDeviceIndex())->freeOnBanks(gfxAllocation->storageInfo.getMemoryBanks(), gfxAllocation->getUnderlyingBufferSize()); freeGraphicsMemoryImpl(gfxAllocation); } //if not in use destroy in place @@ -458,7 +459,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A AllocationStatus status = AllocationStatus::Error; GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status); if (allocation) { - localMemoryUsageBankSelector[properties.rootDeviceIndex]->reserveOnBanks(allocationData.storageInfo.getMemoryBanks(), allocation->getUnderlyingBufferSize()); + getLocalMemoryUsageBankSelector(properties.allocationType, properties.rootDeviceIndex)->reserveOnBanks(allocationData.storageInfo.getMemoryBanks(), allocation->getUnderlyingBufferSize()); this->registerLocalMemAlloc(allocation, properties.rootDeviceIndex); } if (!allocation && status == AllocationStatus::RetryInNonDevicePool) { @@ -556,6 +557,21 @@ EngineControlContainer &MemoryManager::getRegisteredEngines() { return registeredEngines; } +bool MemoryManager::isInternalAllocation(GraphicsAllocation::AllocationType allocationType) { + if (allocationType == GraphicsAllocation::AllocationType::SEMAPHORE_BUFFER || + allocationType == GraphicsAllocation::AllocationType::RING_BUFFER) { + return true; + } + return false; +} + +LocalMemoryUsageBankSelector *MemoryManager::getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex) { + if (isInternalAllocation(allocationType)) { + return internalLocalMemoryUsageBankSelector[rootDeviceIndex].get(); + } + return externalLocalMemoryUsageBankSelector[rootDeviceIndex].get(); +} + EngineControl *MemoryManager::getRegisteredEngineForCsr(CommandStreamReceiver *commandStreamReceiver) { EngineControl *engineCtrl = nullptr; for (auto &engine : registeredEngines) { diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 1660bd156f..3da16eca4b 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -210,6 +210,9 @@ class MemoryManager { virtual void registerSysMemAlloc(GraphicsAllocation *allocation){}; virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){}; + bool isInternalAllocation(GraphicsAllocation::AllocationType allocationType); + LocalMemoryUsageBankSelector *getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex); + bool isLocalMemoryUsedForIsa(uint32_t rootDeviceIndex); protected: @@ -258,7 +261,8 @@ class MemoryManager { uint32_t latestContextId = std::numeric_limits::max(); std::unique_ptr multiContextResourceDestructor; std::vector> gfxPartitions; - std::vector> localMemoryUsageBankSelector; + std::vector> internalLocalMemoryUsageBankSelector; + std::vector> externalLocalMemoryUsageBankSelector; void *reservedMemory = nullptr; std::unique_ptr pageFaultManager; OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;