1111#include " shared/source/memory_manager/allocations_list.h"
1212#include " shared/source/memory_manager/surface.h"
1313#include " shared/source/memory_manager/unified_memory_manager.h"
14+ #include " shared/source/os_interface/device_factory.h"
1415#include " shared/test/unit_test/cmd_parse/hw_parse.h"
1516#include " shared/test/unit_test/helpers/debug_manager_state_restore.h"
1617#include " shared/test/unit_test/page_fault_manager/mock_cpu_page_fault_manager.h"
2425#include " opencl/test/unit_test/libult/ult_command_stream_receiver.h"
2526#include " opencl/test/unit_test/mocks/mock_command_queue.h"
2627#include " opencl/test/unit_test/mocks/mock_context.h"
28+ #include " opencl/test/unit_test/mocks/mock_graphics_allocation.h"
2729#include " opencl/test/unit_test/mocks/mock_kernel.h"
2830#include " opencl/test/unit_test/mocks/mock_svm_manager.h"
2931#include " opencl/test/unit_test/test_macros/test_checks_ocl.h"
@@ -1331,6 +1333,7 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreMadeResidentThenOnlyNonSvmAll
13311333 SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
13321334 unifiedMemoryProperties.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
13331335 unifiedMemoryProperties.subdeviceBitfield = pDevice->getDeviceBitfield ();
1336+ unifiedMemoryProperties.device = pDevice;
13341337 auto allocationSize = 4096u ;
13351338 auto svmManager = this ->context ->getSVMAllocsManager ();
13361339 EXPECT_NE (0u , svmManager->getNumAllocs ());
@@ -1356,6 +1359,7 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen
13561359 SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
13571360 unifiedMemoryProperties.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
13581361 unifiedMemoryProperties.subdeviceBitfield = pDevice->getDeviceBitfield ();
1362+ unifiedMemoryProperties.device = pDevice;
13591363 auto allocationSize = 4096u ;
13601364 auto svmManager = this ->context ->getSVMAllocsManager ();
13611365 EXPECT_NE (0u , svmManager->getNumAllocs ());
@@ -1366,7 +1370,9 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen
13661370 ResidencyContainer residencyContainer;
13671371 EXPECT_EQ (0u , residencyContainer.size ());
13681372
1369- svmManager->addInternalAllocationsToResidencyContainer (residencyContainer, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1373+ svmManager->addInternalAllocationsToResidencyContainer (pDevice->getRootDeviceIndex (),
1374+ residencyContainer,
1375+ InternalMemoryType::DEVICE_UNIFIED_MEMORY);
13701376
13711377 // only unified memory allocation is added to residency container
13721378 EXPECT_EQ (1u , residencyContainer.size ());
@@ -1375,6 +1381,171 @@ HWTEST_F(EnqueueSvmTest, whenInternalAllocationsAreAddedToResidencyContainerThen
13751381 svmManager->freeSVMAlloc (unifiedMemoryPtr);
13761382}
13771383
1384+ struct MemoryAllocationTypeArray {
1385+ const InternalMemoryType allocationType[3 ] = {InternalMemoryType::HOST_UNIFIED_MEMORY,
1386+ InternalMemoryType::DEVICE_UNIFIED_MEMORY,
1387+ InternalMemoryType::SHARED_UNIFIED_MEMORY};
1388+ };
1389+
1390+ struct UpdateResidencyContainerMultipleDevicesTest : public ::testing::WithParamInterface<std::tuple<InternalMemoryType, InternalMemoryType>>,
1391+ public ::testing::Test {
1392+ void SetUp () override {
1393+ device = context.pRootDevice0 ;
1394+ subDevice0 = context.pSubDevice00 ;
1395+ subDevice1 = context.pSubDevice01 ;
1396+
1397+ peerDevice = context.pRootDevice1 ;
1398+ peerSubDevice0 = context.pSubDevice10 ;
1399+ peerSubDevice1 = context.pSubDevice11 ;
1400+
1401+ svmManager = context.getSVMAllocsManager ();
1402+ EXPECT_EQ (0u , svmManager->getNumAllocs ());
1403+ }
1404+ MockUnrestrictiveContextMultiGPU context;
1405+ MockClDevice *device;
1406+ ClDevice *subDevice0 = nullptr ;
1407+ ClDevice *subDevice1 = nullptr ;
1408+ MockClDevice *peerDevice;
1409+ ClDevice *peerSubDevice0 = nullptr ;
1410+ ClDevice *peerSubDevice1 = nullptr ;
1411+ SVMAllocsManager *svmManager = nullptr ;
1412+ };
1413+
1414+ HWTEST_F (UpdateResidencyContainerMultipleDevicesTest,
1415+ givenNoAllocationsCreatedThenNoInternalAllocationsAreAddedToResidencyContainer) {
1416+ ResidencyContainer residencyContainer;
1417+ EXPECT_EQ (0u , residencyContainer.size ());
1418+ svmManager->addInternalAllocationsToResidencyContainer (device->getDevice ().getRootDeviceIndex (),
1419+ residencyContainer,
1420+ InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1421+ EXPECT_EQ (0u , residencyContainer.size ());
1422+ }
1423+
1424+ HWTEST_P (UpdateResidencyContainerMultipleDevicesTest, givenAllocationItIsAddedToContainerOnlyIfMaskMatches) {
1425+ uint32_t pCmdBuffer[1024 ];
1426+ MockGraphicsAllocation gfxAllocation (static_cast <void *>(pCmdBuffer), sizeof (pCmdBuffer));
1427+
1428+ InternalMemoryType type = std::get<0 >(GetParam ());
1429+ uint32_t mask = std::get<1 >(GetParam ());
1430+
1431+ SvmAllocationData allocData;
1432+ allocData.gpuAllocation = &gfxAllocation;
1433+ allocData.memoryType = type;
1434+ allocData.device = &device->getDevice ();
1435+
1436+ svmManager->insertSVMAlloc (allocData);
1437+ EXPECT_EQ (1u , svmManager->getNumAllocs ());
1438+
1439+ ResidencyContainer residencyContainer;
1440+ EXPECT_EQ (0u , residencyContainer.size ());
1441+
1442+ svmManager->addInternalAllocationsToResidencyContainer (device->getDevice ().getRootDeviceIndex (),
1443+ residencyContainer,
1444+ mask);
1445+
1446+ if (mask == static_cast <uint32_t >(type)) {
1447+ EXPECT_EQ (1u , residencyContainer.size ());
1448+ EXPECT_EQ (residencyContainer[0 ]->getGpuAddress (), gfxAllocation.getGpuAddress ());
1449+ } else {
1450+ EXPECT_EQ (0u , residencyContainer.size ());
1451+ }
1452+ }
1453+
1454+ MemoryAllocationTypeArray memoryTypeArray;
1455+ INSTANTIATE_TEST_SUITE_P (UpdateResidencyContainerMultipleDevicesTests,
1456+ UpdateResidencyContainerMultipleDevicesTest,
1457+ ::testing::Combine (
1458+ ::testing::ValuesIn (memoryTypeArray.allocationType),
1459+ ::testing::ValuesIn(memoryTypeArray.allocationType)));
1460+
1461+ HWTEST_F (UpdateResidencyContainerMultipleDevicesTest,
1462+ whenInternalAllocationsAreAddedToResidencyContainerThenOnlyAllocationsFromSameDeviceAreAdded) {
1463+
1464+ uint32_t pCmdBuffer[1024 ];
1465+ MockGraphicsAllocation gfxAllocation (static_cast <void *>(pCmdBuffer), sizeof (pCmdBuffer));
1466+ SvmAllocationData allocData;
1467+ allocData.gpuAllocation = &gfxAllocation;
1468+ allocData.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1469+ allocData.device = &device->getDevice ();
1470+
1471+ uint32_t pCmdBufferPeer[1024 ];
1472+ MockGraphicsAllocation gfxAllocationPeer ((void *)pCmdBufferPeer, sizeof (pCmdBufferPeer));
1473+ SvmAllocationData allocDataPeer;
1474+ allocDataPeer.gpuAllocation = &gfxAllocationPeer;
1475+ allocDataPeer.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1476+ allocDataPeer.device = &peerDevice->getDevice ();
1477+
1478+ svmManager->insertSVMAlloc (allocData);
1479+ svmManager->insertSVMAlloc (allocDataPeer);
1480+ EXPECT_EQ (2u , svmManager->getNumAllocs ());
1481+
1482+ ResidencyContainer residencyContainer;
1483+ EXPECT_EQ (0u , residencyContainer.size ());
1484+ svmManager->addInternalAllocationsToResidencyContainer (device->getDevice ().getRootDeviceIndex (),
1485+ residencyContainer,
1486+ InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1487+ EXPECT_EQ (1u , residencyContainer.size ());
1488+ EXPECT_EQ (residencyContainer[0 ]->getGpuAddress (), gfxAllocation.getGpuAddress ());
1489+ }
1490+
1491+ HWTEST_F (UpdateResidencyContainerMultipleDevicesTest,
1492+ givenAllocationsFromSubDevicesBelongingTheTargetDeviceThenTheyAreAddedToTheResidencyContainer) {
1493+
1494+ uint32_t pCmdBuffer[1024 ];
1495+ MockGraphicsAllocation gfxAllocation (static_cast <void *>(pCmdBuffer), sizeof (pCmdBuffer));
1496+ SvmAllocationData allocData0;
1497+ allocData0.gpuAllocation = &gfxAllocation;
1498+ allocData0.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1499+ allocData0.device = &subDevice0->getDevice ();
1500+
1501+ uint32_t pCmdBufferPeer[1024 ];
1502+ MockGraphicsAllocation gfxAllocationPeer ((void *)pCmdBufferPeer, sizeof (pCmdBufferPeer));
1503+ SvmAllocationData allocData1;
1504+ allocData1.gpuAllocation = &gfxAllocationPeer;
1505+ allocData1.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1506+ allocData1.device = &subDevice1->getDevice ();
1507+
1508+ svmManager->insertSVMAlloc (allocData0);
1509+ svmManager->insertSVMAlloc (allocData1);
1510+ EXPECT_EQ (2u , svmManager->getNumAllocs ());
1511+
1512+ ResidencyContainer residencyContainer;
1513+ EXPECT_EQ (0u , residencyContainer.size ());
1514+ svmManager->addInternalAllocationsToResidencyContainer (device->getDevice ().getRootDeviceIndex (),
1515+ residencyContainer,
1516+ InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1517+ EXPECT_EQ (2u , residencyContainer.size ());
1518+ }
1519+
1520+ HWTEST_F (UpdateResidencyContainerMultipleDevicesTest,
1521+ givenAllocationsFromSubDevicesNotBelongingTheTargetDeviceThenTheyAreNotAddedToTheResidencyContainer) {
1522+
1523+ uint32_t pCmdBuffer[1024 ];
1524+ MockGraphicsAllocation gfxAllocation (static_cast <void *>(pCmdBuffer), sizeof (pCmdBuffer));
1525+ SvmAllocationData allocData0;
1526+ allocData0.gpuAllocation = &gfxAllocation;
1527+ allocData0.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1528+ allocData0.device = &subDevice0->getDevice ();
1529+
1530+ uint32_t pCmdBufferPeer[1024 ];
1531+ MockGraphicsAllocation gfxAllocationPeer ((void *)pCmdBufferPeer, sizeof (pCmdBufferPeer));
1532+ SvmAllocationData allocData1;
1533+ allocData1.gpuAllocation = &gfxAllocationPeer;
1534+ allocData1.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
1535+ allocData1.device = &subDevice1->getDevice ();
1536+
1537+ svmManager->insertSVMAlloc (allocData0);
1538+ svmManager->insertSVMAlloc (allocData1);
1539+ EXPECT_EQ (2u , svmManager->getNumAllocs ());
1540+
1541+ ResidencyContainer residencyContainer;
1542+ EXPECT_EQ (0u , residencyContainer.size ());
1543+ svmManager->addInternalAllocationsToResidencyContainer (peerDevice->getDevice ().getRootDeviceIndex (),
1544+ residencyContainer,
1545+ InternalMemoryType::DEVICE_UNIFIED_MEMORY);
1546+ EXPECT_EQ (0u , residencyContainer.size ());
1547+ }
1548+
13781549HWTEST_F (EnqueueSvmTest, GivenDstHostPtrWhenHostPtrAllocationCreationFailsThenReturnOutOfResource) {
13791550 char dstHostPtr[260 ];
13801551 void *pDstSVM = dstHostPtr;
0 commit comments