Correct createMultiGraphicsAllocationInSystemMemoryPool method

force system memory placement
skip duplicated root device indices

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2021-05-13 10:28:30 +00:00 committed by Compute-Runtime-Automation
parent 00db4dd3f0
commit b7c7bc0a24
4 changed files with 74 additions and 1 deletions

View File

@ -50,6 +50,18 @@ TEST_F(MemoryManagerGetAlloctionDataTests, givenNonHostMemoryAllocatoinTypeWhenA
EXPECT_EQ(nullptr, allocData.hostPtr);
}
TEST_F(MemoryManagerGetAlloctionDataTests, givenForceSystemMemoryFlagWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsSet) {
AllocationData allocData;
AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield);
properties.flags.forceSystemMemory = true;
MockMemoryManager mockMemoryManager;
mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties));
EXPECT_TRUE(allocData.flags.useSystemMemory);
EXPECT_EQ(10u, allocData.size);
EXPECT_EQ(nullptr, allocData.hostPtr);
}
TEST_F(MemoryManagerGetAlloctionDataTests, givenMultiRootDeviceIndexAllocationPropertiesWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsSet) {
{
AllocationData allocData;

View File

@ -2621,4 +2621,59 @@ TEST(MemoryTransferHelperTest, WhenBlitterIsSelectedButBlitCopyFailsThenFallback
auto result = MemoryTransferHelper::transferMemoryToAllocation(true, *device, &graphicsAllocation, 0u, srcData, dataSize);
EXPECT_TRUE(result);
EXPECT_EQ(0, memcmp(destData, srcData, dataSize));
}
TEST(MemoryManagerTest, givenMemoryManagerWithLocalMemoryWhenCreatingMultiGraphicsAllocationInSystemMemoryThenForceSystemMemoryPlacement) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MockMemoryManager memoryManager(true, true, executionEnvironment);
AllocationProperties allocationProperties{mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM_GPU, systemMemoryBitfield};
auto localMemoryAllocation = memoryManager.allocateGraphicsMemoryWithProperties(allocationProperties);
EXPECT_NE(nullptr, localMemoryAllocation);
EXPECT_TRUE(localMemoryAllocation->isAllocatedInLocalMemoryPool());
memoryManager.freeGraphicsMemory(localMemoryAllocation);
std::vector<uint32_t> rootDeviceIndices{};
rootDeviceIndices.push_back(mockRootDeviceIndex);
MultiGraphicsAllocation multiGraphicsAllocation(mockRootDeviceIndex);
auto ptr = memoryManager.createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, allocationProperties, multiGraphicsAllocation);
EXPECT_NE(nullptr, ptr);
auto systemMemoryAllocation = multiGraphicsAllocation.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, systemMemoryAllocation);
EXPECT_FALSE(systemMemoryAllocation->isAllocatedInLocalMemoryPool());
memoryManager.freeGraphicsMemory(systemMemoryAllocation);
}
TEST(MemoryManagerTest, givenDuplicateRootDeviceIndicesWhenCreatingMultiGraphicsAllocationInSystemMemoryThenDontLeakMemory) {
MockExecutionEnvironment executionEnvironment(defaultHwInfo.get());
executionEnvironment.initGmm();
MockMemoryManager memoryManager(true, true, executionEnvironment);
AllocationProperties allocationProperties{mockRootDeviceIndex, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::SVM_GPU, systemMemoryBitfield};
std::vector<uint32_t> rootDeviceIndices{};
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.push_back(mockRootDeviceIndex);
rootDeviceIndices.push_back(mockRootDeviceIndex);
EXPECT_EQ(3u, rootDeviceIndices.size());
MultiGraphicsAllocation multiGraphicsAllocation(mockRootDeviceIndex);
auto ptr = memoryManager.createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, allocationProperties, multiGraphicsAllocation);
EXPECT_NE(nullptr, ptr);
auto allocation = multiGraphicsAllocation.getGraphicsAllocation(mockRootDeviceIndex);
EXPECT_NE(nullptr, allocation);
EXPECT_EQ(mockRootDeviceIndex, allocation->getRootDeviceIndex());
memoryManager.freeGraphicsMemory(allocation);
}

View File

@ -27,7 +27,8 @@ struct AllocationProperties {
uint32_t isUSMDeviceAllocation : 1;
uint32_t use32BitFrontWindow : 1;
uint32_t crossRootDeviceAccess : 1;
uint32_t reserved : 19;
uint32_t forceSystemMemory : 1;
uint32_t reserved : 18;
} flags;
uint32_t allFlags = 0;
};

View File

@ -143,7 +143,11 @@ GraphicsAllocation *MemoryManager::createPaddedAllocation(GraphicsAllocation *in
void *MemoryManager::createMultiGraphicsAllocationInSystemMemoryPool(std::vector<uint32_t> &rootDeviceIndices, AllocationProperties &properties, MultiGraphicsAllocation &multiGraphicsAllocation) {
void *ptr = nullptr;
properties.flags.forceSystemMemory = true;
for (auto &rootDeviceIndex : rootDeviceIndices) {
if (multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)) {
continue;
}
properties.rootDeviceIndex = rootDeviceIndex;
properties.flags.isUSMHostAllocation = true;
@ -432,6 +436,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo
allocationData.flags.crossRootDeviceAccess = properties.flags.crossRootDeviceAccess;
allocationData.flags.useSystemMemory |= properties.flags.crossRootDeviceAccess;
allocationData.flags.useSystemMemory |= properties.flags.forceSystemMemory;
hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo);