Skip to content

Commit 2527015

Browse files
Jaime ArteagaCompute-Runtime-Automation
authored andcommitted
Validate rootDeviceIndex before retrieving multiGraphicsAllocation
Change-Id: I4a5f6e8ae333e8daed13053fb2049fc5757736b5 Signed-off: Gengbin Zheng <[email protected]> Signed-off: Jaime Arteaga <[email protected]>
1 parent 5823450 commit 2527015

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

opencl/test/unit_test/command_queue/enqueue_svm_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,42 @@ HWTEST_P(UpdateResidencyContainerMultipleDevicesTest, givenAllocationItIsAddedTo
16071607
}
16081608
}
16091609

1610+
HWTEST_P(UpdateResidencyContainerMultipleDevicesTest,
1611+
whenUsingRootDeviceIndexGreaterThanMultiGraphicsAllocationSizeThenNoAllocationsAreAdded) {
1612+
uint32_t pCmdBuffer[1024];
1613+
MockGraphicsAllocation gfxAllocation(device->getDevice().getRootDeviceIndex(),
1614+
static_cast<void *>(pCmdBuffer), sizeof(pCmdBuffer));
1615+
SvmAllocationData allocData(maxRootDeviceIndex);
1616+
allocData.gpuAllocations.addAllocation(&gfxAllocation);
1617+
allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1618+
allocData.device = &device->getDevice();
1619+
1620+
uint32_t pCmdBufferPeer[1024];
1621+
MockGraphicsAllocation gfxAllocationPeer(peerDevice->getDevice().getRootDeviceIndex(),
1622+
(void *)pCmdBufferPeer, sizeof(pCmdBufferPeer));
1623+
SvmAllocationData allocDataPeer(maxRootDeviceIndex);
1624+
allocDataPeer.gpuAllocations.addAllocation(&gfxAllocationPeer);
1625+
allocDataPeer.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1626+
allocDataPeer.device = &peerDevice->getDevice();
1627+
1628+
svmManager->insertSVMAlloc(allocData);
1629+
svmManager->insertSVMAlloc(allocDataPeer);
1630+
EXPECT_EQ(2u, svmManager->getNumAllocs());
1631+
1632+
ResidencyContainer residencyContainer;
1633+
EXPECT_EQ(0u, residencyContainer.size());
1634+
svmManager->addInternalAllocationsToResidencyContainer(numRootDevices + 1,
1635+
residencyContainer,
1636+
InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1637+
EXPECT_EQ(0u, residencyContainer.size());
1638+
1639+
svmManager->addInternalAllocationsToResidencyContainer(device->getDevice().getRootDeviceIndex(),
1640+
residencyContainer,
1641+
InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1642+
EXPECT_EQ(1u, residencyContainer.size());
1643+
EXPECT_EQ(residencyContainer[0]->getGpuAddress(), gfxAllocation.getGpuAddress());
1644+
}
1645+
16101646
MemoryAllocationTypeArray memoryTypeArray;
16111647
INSTANTIATE_TEST_SUITE_P(UpdateResidencyContainerMultipleDevicesTests,
16121648
UpdateResidencyContainerMultipleDevicesTest,

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ void SVMAllocsManager::addInternalAllocationsToResidencyContainer(uint32_t rootD
7575
uint32_t requestedTypesMask) {
7676
std::unique_lock<SpinLock> lock(mtx);
7777
for (auto &allocation : this->SVMAllocs.allocations) {
78+
if (rootDeviceIndex >= allocation.second.gpuAllocations.getGraphicsAllocations().size()) {
79+
continue;
80+
}
81+
7882
if (!(allocation.second.memoryType & requestedTypesMask) ||
7983
(nullptr == allocation.second.gpuAllocations.getGraphicsAllocation(rootDeviceIndex))) {
8084
continue;

0 commit comments

Comments
 (0)