Skip to content

Commit 6f582ad

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Only add indirect USM allocations to container once
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
1 parent 9af7b3d commit 6f582ad

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

opencl/test/unit_test/command_queue/enqueue_svm_tests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,36 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen
13911391

13921392
svmManager->freeSVMAlloc(unifiedMemoryPtr);
13931393
}
1394+
1395+
HWTEST_F(EnqueueSvmTest, whenInternalAllocationIsTriedToBeAddedTwiceToResidencyContainerThenOnlyOnceIsAdded) {
1396+
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, pDevice->getDeviceBitfield());
1397+
unifiedMemoryProperties.device = pDevice;
1398+
auto allocationSize = 4096u;
1399+
auto svmManager = this->context->getSVMAllocsManager();
1400+
EXPECT_NE(0u, svmManager->getNumAllocs());
1401+
auto unifiedMemoryPtr = svmManager->createUnifiedMemoryAllocation(pDevice->getRootDeviceIndex(), allocationSize, unifiedMemoryProperties);
1402+
EXPECT_NE(nullptr, unifiedMemoryPtr);
1403+
EXPECT_EQ(2u, svmManager->getNumAllocs());
1404+
1405+
ResidencyContainer residencyContainer;
1406+
EXPECT_EQ(0u, residencyContainer.size());
1407+
1408+
svmManager->addInternalAllocationsToResidencyContainer(pDevice->getRootDeviceIndex(),
1409+
residencyContainer,
1410+
InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1411+
1412+
//only unified memory allocation is added to residency container
1413+
EXPECT_EQ(1u, residencyContainer.size());
1414+
EXPECT_EQ(residencyContainer[0]->getGpuAddress(), castToUint64(unifiedMemoryPtr));
1415+
1416+
svmManager->addInternalAllocationsToResidencyContainer(pDevice->getRootDeviceIndex(),
1417+
residencyContainer,
1418+
InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1419+
EXPECT_EQ(1u, residencyContainer.size());
1420+
1421+
svmManager->freeSVMAlloc(unifiedMemoryPtr);
1422+
}
1423+
13941424
struct createHostUnifiedMemoryAllocationTest : public ::testing::Test {
13951425
void SetUp() override {
13961426
device0 = context.pRootDevice0;

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ void SVMAllocsManager::addInternalAllocationsToResidencyContainer(uint32_t rootD
8383
(nullptr == allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex))) {
8484
continue;
8585
}
86-
residencyContainer.push_back(allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex));
86+
87+
auto alloc = allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
88+
if (residencyContainer.end() == std::find(residencyContainer.begin(), residencyContainer.end(), alloc)) {
89+
residencyContainer.push_back(alloc);
90+
}
8791
}
8892
}
8993

0 commit comments

Comments
 (0)