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

@@ -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;

View File

@@ -291,11 +291,8 @@ TEST_F(SvmDeviceAllocationCacheTest, givenAllocationsWithDifferentSizesWhenAlloc
auto testDataset = std::vector<SvmDeviceAllocationCacheSimpleTestDataType>(
{
{(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<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
std::map<uint32_t, DeviceBitfield> 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();
}

View File

@@ -90,7 +90,9 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
EXPECT_EQ(0, memcmp(alloc->getUnderlyingBuffer(), initData.data(), initData.size()));
ASSERT_NE(nullptr, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress()))));
EXPECT_TRUE(alloc->isMemObjectsAllocationWithWritableFlags());
EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
auto svmData = svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(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);