feature: track used memory by allocations

Track memory used by memory allocations. System and local per device.
Will be used for heuristics in memory pooling.

Related-To: NEO-11356

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-08-02 15:49:47 +00:00
committed by Compute-Runtime-Automation
parent 6103ab1dae
commit 26428d5af3
7 changed files with 93 additions and 0 deletions

View File

@@ -413,6 +413,36 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenSmallSizeAndGpuAddress
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenAllocationSizeIsRegistered) {
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(true, false, false, *executionEnvironment);
auto osContext = device->getDefaultEngine().osContext;
const auto allocationSize = MemoryConstants::pageSize;
auto allocationProperties = MockAllocationProperties{device->getRootDeviceIndex(), allocationSize};
allocationProperties.osContext = osContext;
allocationProperties.allocationType = AllocationType::buffer;
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
auto localAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, localAllocation);
EXPECT_EQ(localAllocation->getUnderlyingBufferSize(), memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
allocationProperties.allocationType = AllocationType::bufferHostMemory;
auto systemAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, systemAllocation);
EXPECT_EQ(localAllocation->getUnderlyingBufferSize(), memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex()));
EXPECT_EQ(systemAllocation->getUnderlyingBufferSize(), memoryManager->getUsedSystemMemorySize());
memoryManager->freeGraphicsMemory(localAllocation);
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex()));
EXPECT_EQ(systemAllocation->getUnderlyingBufferSize(), memoryManager->getUsedSystemMemorySize());
memoryManager->freeGraphicsMemory(systemAllocation);
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(device->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
}
TEST_F(DrmMemoryManagerTest, givenInjectedFailuresWhenGraphicsMemoryWithGpuVaIsAllocatedThenNullptrIsReturned) {
mock->ioctlExpected.total = -1; // don't care

View File

@@ -747,6 +747,34 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenAllocationSizeIsRegistered) {
memoryManager.reset(new MockWddmMemoryManager(false, true, executionEnvironment));
const auto allocationSize = MemoryConstants::pageSize;
auto allocationProperties = MockAllocationProperties{csr->getRootDeviceIndex(), allocationSize};
allocationProperties.allocationType = AllocationType::buffer;
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(csr->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
auto localAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, localAllocation);
EXPECT_EQ(localAllocation->getUnderlyingBufferSize(), memoryManager->getUsedLocalMemorySize(csr->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
allocationProperties.allocationType = AllocationType::bufferHostMemory;
auto systemAllocation = memoryManager->allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, systemAllocation);
EXPECT_EQ(localAllocation->getUnderlyingBufferSize(), memoryManager->getUsedLocalMemorySize(csr->getRootDeviceIndex()));
EXPECT_EQ(systemAllocation->getUnderlyingBufferSize(), memoryManager->getUsedSystemMemorySize());
memoryManager->freeGraphicsMemory(localAllocation);
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(csr->getRootDeviceIndex()));
EXPECT_EQ(systemAllocation->getUnderlyingBufferSize(), memoryManager->getUsedSystemMemorySize());
memoryManager->freeGraphicsMemory(systemAllocation);
EXPECT_EQ(0u, memoryManager->getUsedLocalMemorySize(csr->getRootDeviceIndex()));
EXPECT_EQ(0u, memoryManager->getUsedSystemMemorySize());
}
class MockCreateWddmAllocationMemoryManager : public MockWddmMemoryManager {
public:
MockCreateWddmAllocationMemoryManager(NEO::ExecutionEnvironment &execEnv) : MockWddmMemoryManager(execEnv) {}