mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-28 08:37:12 +08:00
[16/n] Internal 4GB allocator.
- simplify os agnostic memory manager - remove pointer map - move cpuPtr allocate logic to graphics allocation - do not release tag allocation while injecting memory manager - remove not needed ref count from Memory Allocation Change-Id: I6ad81ee919c9cde939bc754a9dfc2db7568397d2
This commit is contained in:
committed by
sys_ocldev
parent
ca86fe2461
commit
5d3d3ff0e7
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@@ -2,4 +2,4 @@
|
||||
neoDependenciesRev='748020-806'
|
||||
strategy='EQUAL'
|
||||
allowedF=40
|
||||
allowedCD=337
|
||||
allowedCD=336
|
||||
|
||||
@@ -127,6 +127,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
void incReuseCount() { reuseCount++; }
|
||||
void decReuseCount() { reuseCount--; }
|
||||
uint32_t peekReuseCount() const { return reuseCount; }
|
||||
bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated
|
||||
|
||||
private:
|
||||
int allocationType;
|
||||
|
||||
@@ -44,22 +44,20 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
|
||||
MemoryAllocation *memoryAllocation = nullptr;
|
||||
|
||||
if (fakeBigAllocations && size > bigAllocation) {
|
||||
memoryAllocation = new MemoryAllocation(true, 1, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter);
|
||||
counter++;
|
||||
memoryAllocation->dummyAllocation = true;
|
||||
memoryAllocation->uncacheable = uncacheable;
|
||||
return memoryAllocation;
|
||||
}
|
||||
auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
|
||||
DEBUG_BREAK_IF(allocationMap.find(ptr) != allocationMap.end());
|
||||
if (ptr != nullptr) {
|
||||
memoryAllocation = new MemoryAllocation(true, 1, ptr, reinterpret_cast<uint64_t>(ptr), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), size, counter);
|
||||
if (!memoryAllocation) {
|
||||
alignedFreeWrapper(ptr);
|
||||
return nullptr;
|
||||
}
|
||||
memoryAllocation->uncacheable = uncacheable;
|
||||
allocationMap.emplace(ptr, memoryAllocation);
|
||||
}
|
||||
counter++;
|
||||
return memoryAllocation;
|
||||
@@ -77,12 +75,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr) & MemoryConstants::pageMask);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(false, 1, reinterpret_cast<void *>(ptr), Gmm::canonize(reinterpret_cast<uint64_t>(gpuVirtualAddress) + offset), size, counter);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(false, reinterpret_cast<void *>(ptr), Gmm::canonize(reinterpret_cast<uint64_t>(gpuVirtualAddress) + offset), size, counter);
|
||||
memAlloc->is32BitAllocation = true;
|
||||
memAlloc->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
memAlloc->sizeToFree = allocationSize;
|
||||
|
||||
allocationMap.emplace(const_cast<void *>(ptr), memAlloc);
|
||||
counter++;
|
||||
return memAlloc;
|
||||
}
|
||||
@@ -94,22 +91,20 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
ptrAlloc = alignedMallocWrapper(allocationSize, MemoryConstants::allocationAlignment);
|
||||
void *gpuPointer = allocator32Bit->allocate(allocationSize);
|
||||
|
||||
DEBUG_BREAK_IF(allocationMap.find(ptrAlloc) != allocationMap.end());
|
||||
MemoryAllocation *memoryAllocation = nullptr;
|
||||
if (ptrAlloc != nullptr) {
|
||||
memoryAllocation = new MemoryAllocation(true, 1, ptrAlloc, Gmm::canonize(reinterpret_cast<uint64_t>(gpuPointer)), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, ptrAlloc, Gmm::canonize(reinterpret_cast<uint64_t>(gpuPointer)), size, counter);
|
||||
memoryAllocation->is32BitAllocation = true;
|
||||
memoryAllocation->gpuBaseAddress = Gmm::canonize(allocator32Bit->getBase());
|
||||
memoryAllocation->sizeToFree = allocationSize;
|
||||
memoryAllocation->cpuPtrAllocated = true;
|
||||
allocationMap.emplace(ptrAlloc, memoryAllocation);
|
||||
}
|
||||
counter++;
|
||||
return memoryAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) {
|
||||
auto graphicsAllocation = new MemoryAllocation(false, 1, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle));
|
||||
auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle));
|
||||
graphicsAllocation->setSharedHandle(handle);
|
||||
graphicsAllocation->is32BitAllocation = requireSpecificBitness;
|
||||
return graphicsAllocation;
|
||||
@@ -131,29 +126,13 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo
|
||||
return;
|
||||
}
|
||||
|
||||
bool freeMemory = false;
|
||||
bool is32BitAllocation = false;
|
||||
void *ptr = gfxAllocation->getUnderlyingBuffer();
|
||||
void *gpuPtrToFree = nullptr;
|
||||
size_t sizeToFree = 0;
|
||||
auto it = allocationMap.find(ptr);
|
||||
|
||||
if (it != allocationMap.end()) {
|
||||
it->second->refCount--;
|
||||
if (it->second->refCount == 0) {
|
||||
freeMemory = it->second->cpuPtrAllocated;
|
||||
is32BitAllocation = it->second->is32BitAllocation;
|
||||
gpuPtrToFree = reinterpret_cast<void *>(it->second->getGpuAddress() & ~MemoryConstants::pageMask);
|
||||
sizeToFree = it->second->sizeToFree;
|
||||
allocationMap.erase(it);
|
||||
}
|
||||
if (gfxAllocation->is32BitAllocation) {
|
||||
void *gpuPtrToFree = reinterpret_cast<void *>(gfxAllocation->getGpuAddress() & ~MemoryConstants::pageMask);
|
||||
allocator32Bit->free(gpuPtrToFree, static_cast<MemoryAllocation *>(gfxAllocation)->sizeToFree);
|
||||
}
|
||||
if (is32BitAllocation) {
|
||||
allocator32Bit->free(gpuPtrToFree, sizeToFree);
|
||||
if (freeMemory) {
|
||||
alignedFreeWrapper(ptr);
|
||||
}
|
||||
} else if (freeMemory) {
|
||||
if (gfxAllocation->cpuPtrAllocated) {
|
||||
alignedFreeWrapper(ptr);
|
||||
}
|
||||
delete gfxAllocation;
|
||||
@@ -172,7 +151,7 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() {
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
|
||||
auto allocation = new MemoryAllocation(false, 0, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++);
|
||||
auto allocation = new MemoryAllocation(false, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++);
|
||||
allocation->fragmentsStorage = handleStorage;
|
||||
return allocation;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,6 @@ constexpr size_t bigAllocation = 1 * MB;
|
||||
constexpr uintptr_t dummyAddress = 0xFFFFF000u;
|
||||
class MemoryAllocation : public GraphicsAllocation {
|
||||
public:
|
||||
bool cpuPtrAllocated;
|
||||
unsigned int refCount;
|
||||
unsigned long long id;
|
||||
size_t sizeToFree = 0;
|
||||
bool dummyAllocation = false;
|
||||
@@ -40,10 +38,10 @@ class MemoryAllocation : public GraphicsAllocation {
|
||||
|
||||
void setSharedHandle(osHandle handle) { this->sharedHandle = handle; }
|
||||
|
||||
MemoryAllocation(bool cpuPtrAllocated, int refCount, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
|
||||
cpuPtrAllocated(cpuPtrAllocated),
|
||||
refCount(refCount),
|
||||
id(count) {}
|
||||
MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
|
||||
id(count) {
|
||||
this->cpuPtrAllocated = cpuPtrAllocated;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<void *, MemoryAllocation *> PointerMap;
|
||||
@@ -83,7 +81,6 @@ class OsAgnosticMemoryManager : public MemoryManager {
|
||||
void turnOnFakingBigAllocations();
|
||||
|
||||
private:
|
||||
PointerMap allocationMap;
|
||||
unsigned long long counter = 0;
|
||||
bool fakeBigAllocations = false;
|
||||
};
|
||||
|
||||
@@ -40,9 +40,6 @@ const size_t trimListUnusedPosition = (size_t)-1;
|
||||
|
||||
class WddmAllocation : public GraphicsAllocation {
|
||||
public:
|
||||
// runtime assigned fields
|
||||
bool cpuPtrAllocated; // flag indicating if cpuPtr is driver-allocated
|
||||
|
||||
// OS assigned fields
|
||||
D3DKMT_HANDLE handle; // set by createAllocation
|
||||
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
||||
@@ -50,7 +47,6 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr)
|
||||
: GraphicsAllocation(cpuPtrIn, sizeIn),
|
||||
cpuPtrAllocated(false),
|
||||
handle(0),
|
||||
gpuPtr(0),
|
||||
alignedCpuPtr(alignedCpuPtr),
|
||||
@@ -60,7 +56,6 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
}
|
||||
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle) : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle),
|
||||
cpuPtrAllocated(false),
|
||||
handle(0),
|
||||
gpuPtr(0),
|
||||
alignedCpuPtr(nullptr),
|
||||
|
||||
@@ -56,13 +56,7 @@ bool MockDevice::hasDriverInfo() {
|
||||
|
||||
void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) {
|
||||
memoryManager->setCommandStreamReceiver(commandStreamReceiver);
|
||||
this->memoryManager->freeGraphicsMemory(tagAllocation);
|
||||
tagAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t));
|
||||
auto pTagMemory = reinterpret_cast<uint32_t *>(tagAllocation->getUnderlyingBuffer());
|
||||
*pTagMemory = initialHardwareTag;
|
||||
tagAddress = pTagMemory;
|
||||
commandStreamReceiver->setMemoryManager(memoryManager);
|
||||
commandStreamReceiver->setTagAllocation(tagAllocation);
|
||||
setMemoryManager(memoryManager);
|
||||
memoryManager->setDevice(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user