diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index 104a991464..0d1c0041f4 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -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(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; } } diff --git a/shared/source/memory_manager/unified_memory_manager.h b/shared/source/memory_manager/unified_memory_manager.h index c8de902c15..abce9ebefd 100644 --- a/shared/source/memory_manager/unified_memory_manager.h +++ b/shared/source/memory_manager/unified_memory_manager.h @@ -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 &subdeviceBitfields; AllocationType requestedAllocationType = AllocationType::unknown; - bool needZeroedOutAllocation = false; + bool isInternalAllocation = false; }; struct SvmCacheAllocationInfo { diff --git a/shared/source/program/program_initialization.cpp b/shared/source/program/program_initialization.cpp index b42f2624a8..81e9665c46 100644 --- a/shared/source/program/program_initialization.cpp +++ b/shared/source/program/program_initialization.cpp @@ -38,7 +38,7 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, subDeviceBitfields); unifiedMemoryProperties.device = &device; unifiedMemoryProperties.requestedAllocationType = allocationType; - unifiedMemoryProperties.needZeroedOutAllocation = true; + unifiedMemoryProperties.isInternalAllocation = true; auto ptr = svmAllocManager->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties); DEBUG_BREAK_IF(ptr == nullptr); if (ptr == nullptr) { diff --git a/shared/test/common/mocks/mock_svm_manager.h b/shared/test/common/mocks/mock_svm_manager.h index 3ee522d43e..640a0f4a26 100644 --- a/shared/test/common/mocks/mock_svm_manager.h +++ b/shared/test/common/mocks/mock_svm_manager.h @@ -34,7 +34,7 @@ struct MockSVMAllocsManager : public SVMAllocsManager { bool prefetchMemoryCalled = false; void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties) override { - requestedZeroedOutAllocation = memoryProperties.needZeroedOutAllocation; + requestedZeroedOutAllocation = memoryProperties.isInternalAllocation; return SVMAllocsManager::createUnifiedMemoryAllocation(size, memoryProperties); } bool requestedZeroedOutAllocation = false; diff --git a/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp b/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp index 8885ba0f13..2d19e23a49 100644 --- a/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp +++ b/shared/test/unit_test/memory_manager/unified_memory_manager_cache_tests.cpp @@ -291,11 +291,8 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationsWithDifferentSizesWhenAlloc auto testDataset = std::vector( { {(allocationSizeBasis << 0), nullptr}, - {(allocationSizeBasis << 0) + 1, nullptr}, {(allocationSizeBasis << 1), nullptr}, - {(allocationSizeBasis << 1) + 1, nullptr}, {(allocationSizeBasis << 2), nullptr}, - {(allocationSizeBasis << 2) + 1, nullptr}, }); SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields); @@ -519,7 +516,7 @@ TEST_F(SvmDeviceAllocationCacheTest, givenDeviceOutOfMemoryWhenAllocatingThenCac ASSERT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u); } -TEST_F(SvmDeviceAllocationCacheTest, givenAllocationWithNeedZeroedOutAllocationWhenAllocatingAfterFreeThenDoNotReuseAllocation) { +TEST_F(SvmDeviceAllocationCacheTest, givenAllocationWithIsInternalAllocationSetWhenAllocatingAfterFreeThenDoNotReuseAllocation) { std::unique_ptr deviceFactory(new UltDeviceFactory(1, 1)); RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex}; std::map deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}}; @@ -538,13 +535,15 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationWithNeedZeroedOutAllocationW svmManager->freeSVMAlloc(allocation); EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 1u); - unifiedMemoryProperties.needZeroedOutAllocation = true; + unifiedMemoryProperties.isInternalAllocation = true; auto testedAllocation = svmManager->createUnifiedMemoryAllocation(10u, unifiedMemoryProperties); EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 1u); auto svmData = svmManager->getSVMAlloc(testedAllocation); EXPECT_NE(nullptr, svmData); + EXPECT_TRUE(svmData->isInternalAllocation); svmManager->freeSVMAlloc(testedAllocation); + EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 1u); svmManager->trimUSMDeviceAllocCache(); } diff --git a/shared/test/unit_test/program/program_initialization_tests.cpp b/shared/test/unit_test/program/program_initialization_tests.cpp index cd3bc49b5f..4db761a568 100644 --- a/shared/test/unit_test/program/program_initialization_tests.cpp +++ b/shared/test/unit_test/program/program_initialization_tests.cpp @@ -90,7 +90,9 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size())); ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast(static_cast(alloc->getGpuAddress())))); EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags()); - EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, svmAllocsManager.getSVMAlloc(reinterpret_cast(alloc->getGpuAddress()))->memoryType); + auto svmData = svmAllocsManager.getSVMAlloc(reinterpret_cast(alloc->getGpuAddress())); + EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, svmData->memoryType); + EXPECT_TRUE(svmData->isInternalAllocation); EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType()); EXPECT_FALSE(alloc->getDefaultGmm()->resourceParams.Flags.Info.NotLockable); EXPECT_TRUE(svmAllocsManager.requestedZeroedOutAllocation);