mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 09:14:47 +08:00
Separate local memory usage tracking for internal and external
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
30151a8f02
commit
890eec6105
@@ -564,10 +564,10 @@ TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevice
|
|||||||
auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);
|
auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);
|
||||||
EXPECT_NE(nullptr, allocation);
|
EXPECT_NE(nullptr, allocation);
|
||||||
EXPECT_EQ(MemoryPool::LocalMemory, allocation->getMemoryPool());
|
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);
|
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) {
|
TEST(MemoryManagerTest, givenSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenlocalMemoryUsageIsNotUpdated) {
|
||||||
@@ -577,8 +577,29 @@ TEST(MemoryManagerTest, givenSetUseSystemMemoryWhenGraphicsAllocationInDevicePoo
|
|||||||
AllocationProperties allocProperties(mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, mockDeviceBitfield);
|
AllocationProperties allocProperties(mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, mockDeviceBitfield);
|
||||||
auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);
|
auto allocation = memoryManager.allocateGraphicsMemoryInPreferredPool(allocProperties, nullptr);
|
||||||
EXPECT_NE(nullptr, allocation);
|
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);
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ TEST_F(MultiDeviceStorageInfoTest, givenReadOnlyBufferToBeCopiedAcrossTilesWhenD
|
|||||||
|
|
||||||
TEST_F(MultiDeviceStorageInfoTest, givenLeastOccupiedBankAndOtherBitsEnabledInSubDeviceBitfieldWhenCreateStorageInfoThenTakeLeastOccupiedBankAsMemoryBank) {
|
TEST_F(MultiDeviceStorageInfoTest, givenLeastOccupiedBankAndOtherBitsEnabledInSubDeviceBitfieldWhenCreateStorageInfoThenTakeLeastOccupiedBankAsMemoryBank) {
|
||||||
AllocationProperties properties{mockRootDeviceIndex, false, 1u, GraphicsAllocation::AllocationType::UNKNOWN, false, singleTileMask};
|
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);
|
||||||
properties.subDevicesBitfield.set(leastOccupiedBank + 1);
|
properties.subDevicesBitfield.set(leastOccupiedBank + 1);
|
||||||
EXPECT_EQ(2u, properties.subDevicesBitfield.count());
|
EXPECT_EQ(2u, properties.subDevicesBitfield.count());
|
||||||
@@ -422,7 +422,7 @@ TEST_F(MultiDeviceStorageInfoTest,
|
|||||||
allTilesMask};
|
allTilesMask};
|
||||||
auto storageInfo = memoryManager->createStorageInfoFromProperties(properties);
|
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;
|
DeviceBitfield allocationMask;
|
||||||
allocationMask.set(leastOccupiedBank);
|
allocationMask.set(leastOccupiedBank);
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
|||||||
using MemoryManager::createGraphicsAllocation;
|
using MemoryManager::createGraphicsAllocation;
|
||||||
using MemoryManager::createStorageInfoFromProperties;
|
using MemoryManager::createStorageInfoFromProperties;
|
||||||
using MemoryManager::defaultEngineIndex;
|
using MemoryManager::defaultEngineIndex;
|
||||||
|
using MemoryManager::externalLocalMemoryUsageBankSelector;
|
||||||
using MemoryManager::getAllocationData;
|
using MemoryManager::getAllocationData;
|
||||||
using MemoryManager::gfxPartitions;
|
using MemoryManager::gfxPartitions;
|
||||||
using MemoryManager::localMemoryUsageBankSelector;
|
using MemoryManager::internalLocalMemoryUsageBankSelector;
|
||||||
using MemoryManager::multiContextResourceDestructor;
|
using MemoryManager::multiContextResourceDestructor;
|
||||||
using MemoryManager::overrideAllocationData;
|
using MemoryManager::overrideAllocationData;
|
||||||
using MemoryManager::pageFaultManager;
|
using MemoryManager::pageFaultManager;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto deviceCount = HwHelper::getSubDevicesCount(executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->getHardwareInfo());
|
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 auto subDevicesMask = executionEnvironment.rootDeviceEnvironments[properties.rootDeviceIndex]->deviceAffinityMask.getGenericSubDevicesMask().to_ulong();
|
||||||
|
|
||||||
const DeviceBitfield allTilesValue(properties.subDevicesBitfield.count() == 1
|
const DeviceBitfield allTilesValue(properties.subDevicesBitfield.count() == 1
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu
|
|||||||
|
|
||||||
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < rootEnvCount; ++rootDeviceIndex) {
|
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < rootEnvCount; ++rootDeviceIndex) {
|
||||||
auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo();
|
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->localMemorySupported.push_back(HwHelper::get(hwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*hwInfo));
|
||||||
this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages && !!DebugManager.flags.Enable64kbpages.get());
|
this->enable64kbpages.push_back(OSInterface::osEnabled64kbPages && hwInfo->capabilityTable.ftr64KBpages && !!DebugManager.flags.Enable64kbpages.get());
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) {
|
|||||||
freeAssociatedResourceImpl(*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);
|
freeGraphicsMemoryImpl(gfxAllocation);
|
||||||
}
|
}
|
||||||
//if not in use destroy in place
|
//if not in use destroy in place
|
||||||
@@ -458,7 +459,7 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A
|
|||||||
AllocationStatus status = AllocationStatus::Error;
|
AllocationStatus status = AllocationStatus::Error;
|
||||||
GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
|
GraphicsAllocation *allocation = allocateGraphicsMemoryInDevicePool(allocationData, status);
|
||||||
if (allocation) {
|
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);
|
this->registerLocalMemAlloc(allocation, properties.rootDeviceIndex);
|
||||||
}
|
}
|
||||||
if (!allocation && status == AllocationStatus::RetryInNonDevicePool) {
|
if (!allocation && status == AllocationStatus::RetryInNonDevicePool) {
|
||||||
@@ -556,6 +557,21 @@ EngineControlContainer &MemoryManager::getRegisteredEngines() {
|
|||||||
return registeredEngines;
|
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 *MemoryManager::getRegisteredEngineForCsr(CommandStreamReceiver *commandStreamReceiver) {
|
||||||
EngineControl *engineCtrl = nullptr;
|
EngineControl *engineCtrl = nullptr;
|
||||||
for (auto &engine : registeredEngines) {
|
for (auto &engine : registeredEngines) {
|
||||||
|
|||||||
@@ -210,6 +210,9 @@ class MemoryManager {
|
|||||||
virtual void registerSysMemAlloc(GraphicsAllocation *allocation){};
|
virtual void registerSysMemAlloc(GraphicsAllocation *allocation){};
|
||||||
virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){};
|
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);
|
bool isLocalMemoryUsedForIsa(uint32_t rootDeviceIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -258,7 +261,8 @@ class MemoryManager {
|
|||||||
uint32_t latestContextId = std::numeric_limits<uint32_t>::max();
|
uint32_t latestContextId = std::numeric_limits<uint32_t>::max();
|
||||||
std::unique_ptr<DeferredDeleter> multiContextResourceDestructor;
|
std::unique_ptr<DeferredDeleter> multiContextResourceDestructor;
|
||||||
std::vector<std::unique_ptr<GfxPartition>> gfxPartitions;
|
std::vector<std::unique_ptr<GfxPartition>> gfxPartitions;
|
||||||
std::vector<std::unique_ptr<LocalMemoryUsageBankSelector>> localMemoryUsageBankSelector;
|
std::vector<std::unique_ptr<LocalMemoryUsageBankSelector>> internalLocalMemoryUsageBankSelector;
|
||||||
|
std::vector<std::unique_ptr<LocalMemoryUsageBankSelector>> externalLocalMemoryUsageBankSelector;
|
||||||
void *reservedMemory = nullptr;
|
void *reservedMemory = nullptr;
|
||||||
std::unique_ptr<PageFaultManager> pageFaultManager;
|
std::unique_ptr<PageFaultManager> pageFaultManager;
|
||||||
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
|
OSMemory::ReservedCpuAddressRange reservedCpuAddressRange;
|
||||||
|
|||||||
Reference in New Issue
Block a user