refactor: move memory tracking to memory manager

- remove wddm specific code
- improve total size reported to be in decimal

Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2024-09-12 15:38:44 +00:00
committed by Compute-Runtime-Automation
parent c0d9cb4d84
commit dd631610b3
7 changed files with 18 additions and 20 deletions

View File

@@ -150,6 +150,16 @@ HeapIndex MemoryManager::selectExternalHeap(bool useLocalMemory) {
return useLocalMemory ? HeapIndex::heapExternalDeviceMemory : HeapIndex::heapExternal;
}
inline MemoryManager::AllocationStatus MemoryManager::registerSysMemAlloc(GraphicsAllocation *allocation) {
this->sysMemAllocsSize += allocation->getUnderlyingBufferSize();
return AllocationStatus::Success;
}
inline MemoryManager::AllocationStatus MemoryManager::registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) {
this->localMemAllocsSize[rootDeviceIndex] += allocation->getUnderlyingBufferSize();
return AllocationStatus::Success;
}
void MemoryManager::zeroCpuMemoryIfRequested(const AllocationData &allocationData, void *cpuPtr, size_t size) {
if (allocationData.flags.zeroMemory) {
memset(cpuPtr, 0, size);

View File

@@ -262,8 +262,8 @@ class MemoryManager {
virtual bool isCpuCopyRequired(const void *ptr) { return false; }
virtual bool isWCMemory(const void *ptr) { return false; }
virtual AllocationStatus registerSysMemAlloc(GraphicsAllocation *allocation) { return AllocationStatus::Success; };
virtual AllocationStatus registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) { return AllocationStatus::Success; };
virtual AllocationStatus registerSysMemAlloc(GraphicsAllocation *allocation);
virtual AllocationStatus registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex);
virtual bool setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags, uint32_t rootDeviceIndex) { return true; }
virtual bool setMemPrefetch(GraphicsAllocation *gfxAllocation, SubDeviceIdsVec &subDeviceIds, uint32_t rootDeviceIndex) { return true; }

View File

@@ -955,16 +955,6 @@ double WddmMemoryManager::getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceI
return 0.94;
}
AllocationStatus WddmMemoryManager::registerSysMemAlloc(GraphicsAllocation *allocation) {
this->sysMemAllocsSize += allocation->getUnderlyingBufferSize();
return AllocationStatus::Success;
}
AllocationStatus WddmMemoryManager::registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) {
this->localMemAllocsSize[rootDeviceIndex] += allocation->getUnderlyingBufferSize();
return AllocationStatus::Success;
}
AlignedMallocRestrictions *WddmMemoryManager::getAlignedMallocRestrictions() {
return &mallocRestrictions;
}

View File

@@ -50,8 +50,6 @@ class WddmMemoryManager : public MemoryManager {
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override;
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override;
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) override;
AllocationStatus registerSysMemAlloc(GraphicsAllocation *allocation) override;
AllocationStatus registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex) override;
bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle, uint32_t rootDeviceIndex);

View File

@@ -118,8 +118,8 @@ void FileLogger<debugLevel>::logAllocation(GraphicsAllocation const *graphicsAll
ss << graphicsAllocation->getPatIndexInfoString();
if (memoryManager) {
ss << " Total sys mem allocated: " << memoryManager->getUsedSystemMemorySize();
ss << " Total lmem allocated: " << memoryManager->getUsedLocalMemorySize(graphicsAllocation->getRootDeviceIndex());
ss << " Total sys mem allocated: " << std::dec << memoryManager->getUsedSystemMemorySize();
ss << " Total lmem allocated: " << std::dec << memoryManager->getUsedLocalMemorySize(graphicsAllocation->getRootDeviceIndex());
}
ss << std::endl;