Do not reuse mem obj's allocation

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2022-07-13 15:05:42 +00:00
committed by Compute-Runtime-Automation
parent 69269b9aed
commit 4ac6e09117
14 changed files with 55 additions and 32 deletions

View File

@@ -724,6 +724,7 @@ std::unique_lock<CommandStreamReceiver::MutexType> CommandStreamReceiver::obtain
}
AllocationsList &CommandStreamReceiver::getTemporaryAllocations() { return internalAllocationStorage->getTemporaryAllocations(); }
AllocationsList &CommandStreamReceiver::getAllocationsForReuse() { return internalAllocationStorage->getAllocationsForReuse(); }
AllocationsList &CommandStreamReceiver::getDeferredAllocations() { return internalAllocationStorage->getDeferredAllocations(); }
bool CommandStreamReceiver::createAllocationForHostSurface(HostPtrSurface &surface, bool requiresL3Flush) {
std::unique_lock<decltype(hostPtrSurfaceCreationMutex)> lock = this->obtainHostPtrSurfaceCreationLock();

View File

@@ -206,6 +206,7 @@ class CommandStreamReceiver {
AllocationsList &getTemporaryAllocations();
AllocationsList &getAllocationsForReuse();
AllocationsList &getDeferredAllocations();
InternalAllocationStorage *getInternalAllocationStorage() const { return internalAllocationStorage.get(); }
MOCKABLE_VIRTUAL bool createAllocationForHostSurface(HostPtrSurface &surface, bool requiresL3Flush);
virtual size_t getPreferredTagPoolSize() const;

View File

@@ -14,9 +14,7 @@
namespace NEO {
InternalAllocationStorage::InternalAllocationStorage(CommandStreamReceiver &commandStreamReceiver)
: commandStreamReceiver(commandStreamReceiver),
temporaryAllocations(TEMPORARY_ALLOCATION),
allocationsForReuse(REUSABLE_ALLOCATION){};
: commandStreamReceiver(commandStreamReceiver){};
void InternalAllocationStorage::storeAllocation(std::unique_ptr<GraphicsAllocation> &&gfxAllocation, uint32_t allocationUsage) {
uint32_t taskCount = gfxAllocation->getTaskCount(commandStreamReceiver.getOsContext().getContextId());
@@ -34,13 +32,17 @@ void InternalAllocationStorage::storeAllocationWithTaskCount(std::unique_ptr<Gra
return;
}
}
auto &allocationsList = (allocationUsage == TEMPORARY_ALLOCATION) ? temporaryAllocations : allocationsForReuse;
auto &allocationsList = allocationLists[allocationUsage];
gfxAllocation->updateTaskCount(taskCount, commandStreamReceiver.getOsContext().getContextId());
allocationsList.pushTailOne(*gfxAllocation.release());
}
void InternalAllocationStorage::cleanAllocationList(uint32_t waitTaskCount, uint32_t allocationUsage) {
freeAllocationsList(waitTaskCount, (allocationUsage == TEMPORARY_ALLOCATION) ? temporaryAllocations : allocationsForReuse);
freeAllocationsList(waitTaskCount, allocationLists[allocationUsage]);
if (allocationUsage == TEMPORARY_ALLOCATION) {
freeAllocationsList(waitTaskCount, allocationLists[DEFERRED_DEALLOCATION]);
}
}
void InternalAllocationStorage::freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList) {
@@ -66,12 +68,12 @@ void InternalAllocationStorage::freeAllocationsList(uint32_t waitTaskCount, Allo
}
std::unique_ptr<GraphicsAllocation> InternalAllocationStorage::obtainReusableAllocation(size_t requiredSize, AllocationType allocationType) {
auto allocation = allocationsForReuse.detachAllocation(requiredSize, nullptr, &commandStreamReceiver, allocationType);
auto allocation = allocationLists[REUSABLE_ALLOCATION].detachAllocation(requiredSize, nullptr, &commandStreamReceiver, allocationType);
return allocation;
}
std::unique_ptr<GraphicsAllocation> InternalAllocationStorage::obtainTemporaryAllocationWithPtr(size_t requiredSize, const void *requiredPtr, AllocationType allocationType) {
auto allocation = temporaryAllocations.detachAllocation(requiredSize, requiredPtr, &commandStreamReceiver, allocationType);
auto allocation = allocationLists[TEMPORARY_ALLOCATION].detachAllocation(requiredSize, requiredPtr, &commandStreamReceiver, allocationType);
return allocation;
}

View File

@@ -9,6 +9,8 @@
#include "shared/source/helpers/common_types.h"
#include "shared/source/memory_manager/allocations_list.h"
#include <array>
namespace NEO {
class InternalAllocationStorage {
@@ -20,15 +22,15 @@ class InternalAllocationStorage {
void storeAllocationWithTaskCount(std::unique_ptr<GraphicsAllocation> &&gfxAllocation, uint32_t allocationUsage, uint32_t taskCount);
std::unique_ptr<GraphicsAllocation> obtainReusableAllocation(size_t requiredSize, AllocationType allocationType);
std::unique_ptr<GraphicsAllocation> obtainTemporaryAllocationWithPtr(size_t requiredSize, const void *requiredPtr, AllocationType allocationType);
AllocationsList &getTemporaryAllocations() { return temporaryAllocations; }
AllocationsList &getAllocationsForReuse() { return allocationsForReuse; }
AllocationsList &getTemporaryAllocations() { return allocationLists[TEMPORARY_ALLOCATION]; }
AllocationsList &getAllocationsForReuse() { return allocationLists[REUSABLE_ALLOCATION]; }
AllocationsList &getDeferredAllocations() { return allocationLists[DEFERRED_DEALLOCATION]; }
DeviceBitfield getDeviceBitfield() const;
protected:
void freeAllocationsList(uint32_t waitTaskCount, AllocationsList &allocationsList);
CommandStreamReceiver &commandStreamReceiver;
AllocationsList temporaryAllocations;
AllocationsList allocationsForReuse;
std::array<AllocationsList, 3> allocationLists = {AllocationsList(TEMPORARY_ALLOCATION), AllocationsList(REUSABLE_ALLOCATION), AllocationsList(DEFERRED_DEALLOCATION)};
};
} // namespace NEO

View File

@@ -227,7 +227,7 @@ void MemoryManager::checkGpuUsageAndDestroyGraphicsAllocations(GraphicsAllocatio
if (gfxAllocation->isUsedByOsContext(osContextId) &&
allocationTaskCount > *engine.commandStreamReceiver->getTagAddress()) {
engine.commandStreamReceiver->getInternalAllocationStorage()->storeAllocation(std::unique_ptr<GraphicsAllocation>(gfxAllocation),
TEMPORARY_ALLOCATION);
DEFERRED_DEALLOCATION);
return;
}
}

View File

@@ -40,7 +40,8 @@ class OsContext;
enum AllocationUsage {
TEMPORARY_ALLOCATION,
REUSABLE_ALLOCATION
REUSABLE_ALLOCATION,
DEFERRED_DEALLOCATION
};
struct AlignedMallocRestrictions {