fix: device usm alloc reuse

Do not put into usm reuse if is internal.
Set new isInternalAllocation flag for globals allocations.

Use actual size on device for tracking memory usage.

Related-To: NEO-6893

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-05-27 14:15:05 +00:00
committed by Compute-Runtime-Automation
parent 2c2ff5e369
commit 7cb1819b22
6 changed files with 16 additions and 11 deletions

View File

@@ -298,7 +298,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
if (memoryProperties.memoryType == InternalMemoryType::deviceUnifiedMemory) {
unifiedMemoryProperties.flags.isUSMDeviceAllocation = true;
if (this->usmDeviceAllocationsCacheEnabled &&
false == memoryProperties.needZeroedOutAllocation) {
false == memoryProperties.isInternalAllocation) {
void *allocationFromCache = this->usmDeviceAllocationsCache.get(size, memoryProperties, this);
if (allocationFromCache) {
return allocationFromCache;
@@ -332,6 +332,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
allocData.allocationFlagsProperty = memoryProperties.allocationFlags;
allocData.device = memoryProperties.device;
allocData.setAllocId(++this->allocationsCounter);
allocData.isInternalAllocation = memoryProperties.isInternalAllocation;
auto retPtr = reinterpret_cast<void *>(unifiedMemoryAllocation->getGpuAddress());
insertSVMAlloc(retPtr, allocData);
@@ -445,8 +446,9 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
SvmAllocationData *svmData = getSVMAlloc(ptr);
if (svmData) {
if (InternalMemoryType::deviceUnifiedMemory == svmData->memoryType &&
false == svmData->isInternalAllocation &&
this->usmDeviceAllocationsCacheEnabled) {
if (this->usmDeviceAllocationsCache.insert(svmData->size, ptr)) {
if (this->usmDeviceAllocationsCache.insert(svmData->gpuAllocations.getDefaultGraphicsAllocation()->getUnderlyingBufferSize(), ptr)) {
return true;
}
}

View File

@@ -41,6 +41,7 @@ struct SvmAllocationData {
this->allocId = svmAllocData.allocId;
this->pageSizeForAlignment = svmAllocData.pageSizeForAlignment;
this->isImportedAllocation = svmAllocData.isImportedAllocation;
this->isInternalAllocation = svmAllocData.isInternalAllocation;
for (auto allocation : svmAllocData.gpuAllocations.getGraphicsAllocations()) {
if (allocation) {
this->gpuAllocations.addAllocation(allocation);
@@ -63,6 +64,7 @@ struct SvmAllocationData {
allocId = id;
}
bool mappedAllocData = false;
bool isInternalAllocation = false;
uint32_t getAllocId() const {
return allocId;
@@ -138,7 +140,7 @@ class SVMAllocsManager {
const RootDeviceIndicesContainer &rootDeviceIndices;
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields;
AllocationType requestedAllocationType = AllocationType::unknown;
bool needZeroedOutAllocation = false;
bool isInternalAllocation = false;
};
struct SvmCacheAllocationInfo {