Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Only add indirect USM allocations to container once
Browse files Browse the repository at this point in the history
Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
  • Loading branch information
Jaime Arteaga authored and Compute-Runtime-Automation committed Nov 6, 2020
1 parent 9af7b3d commit 6f582ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 30 additions & 0 deletions opencl/test/unit_test/command_queue/enqueue_svm_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,36 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen

svmManager->freeSVMAlloc(unifiedMemoryPtr);
}

HWTEST_F(EnqueueSvmTest, whenInternalAllocationIsTriedToBeAddedTwiceToResidencyContainerThenOnlyOnceIsAdded) {
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, pDevice->getDeviceBitfield());
unifiedMemoryProperties.device = pDevice;
auto allocationSize = 4096u;
auto svmManager = this->context->getSVMAllocsManager();
EXPECT_NE(0u, svmManager->getNumAllocs());
auto unifiedMemoryPtr = svmManager->createUnifiedMemoryAllocation(pDevice->getRootDeviceIndex(), allocationSize, unifiedMemoryProperties);
EXPECT_NE(nullptr, unifiedMemoryPtr);
EXPECT_EQ(2u, svmManager->getNumAllocs());

ResidencyContainer residencyContainer;
EXPECT_EQ(0u, residencyContainer.size());

svmManager->addInternalAllocationsToResidencyContainer(pDevice->getRootDeviceIndex(),
residencyContainer,
InternalMemoryType::DEVICE_UNIFIED_MEMORY);

//only unified memory allocation is added to residency container
EXPECT_EQ(1u, residencyContainer.size());
EXPECT_EQ(residencyContainer[0]->getGpuAddress(), castToUint64(unifiedMemoryPtr));

svmManager->addInternalAllocationsToResidencyContainer(pDevice->getRootDeviceIndex(),
residencyContainer,
InternalMemoryType::DEVICE_UNIFIED_MEMORY);
EXPECT_EQ(1u, residencyContainer.size());

svmManager->freeSVMAlloc(unifiedMemoryPtr);
}

struct createHostUnifiedMemoryAllocationTest : public ::testing::Test {
void SetUp() override {
device0 = context.pRootDevice0;
Expand Down
6 changes: 5 additions & 1 deletion shared/source/memory_manager/unified_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ void SVMAllocsManager::addInternalAllocationsToResidencyContainer(uint32_t rootD
(nullptr == allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex))) {
continue;
}
residencyContainer.push_back(allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex));

auto alloc = allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
if (residencyContainer.end() == std::find(residencyContainer.begin(), residencyContainer.end(), alloc)) {
residencyContainer.push_back(alloc);
}
}
}

Expand Down

0 comments on commit 6f582ad

Please sign in to comment.