@@ -1401,12 +1401,14 @@ struct createHostUnifiedMemoryAllocationTest : public ::testing::Test {
14011401 void SetUp () override {
14021402 device0 = context.pRootDevice0 ;
14031403 device1 = context.pRootDevice1 ;
1404+ device2 = context.pRootDevice2 ;
14041405 svmManager = context.getSVMAllocsManager ();
14051406 EXPECT_EQ (0u , svmManager->getNumAllocs ());
14061407 }
14071408 const size_t allocationSize = 4096u ;
1408- const uint32_t numDevices = 2u ;
1409+ const uint32_t numDevices = 3u ;
14091410 MockDefaultContext context;
1411+ MockClDevice *device2;
14101412 MockClDevice *device1;
14111413 MockClDevice *device0;
14121414 SVMAllocsManager *svmManager = nullptr ;
@@ -1436,6 +1438,102 @@ HWTEST_F(createHostUnifiedMemoryAllocationTest,
14361438 svmManager->freeSVMAlloc (unifiedMemoryPtr);
14371439}
14381440
1441+ HWTEST_F (createHostUnifiedMemoryAllocationTest,
1442+ whenCreatingMultiGraphicsAllocationThenGraphicsAllocationPerDeviceIsCreated) {
1443+
1444+ NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties (InternalMemoryType::HOST_UNIFIED_MEMORY);
1445+ unifiedMemoryProperties.subdeviceBitfield = device0->getDevice ().getDeviceBitfield ();
1446+
1447+ auto alignedSize = alignUp<size_t >(allocationSize, MemoryConstants::pageSize64k);
1448+ auto memoryManager = context.getMemoryManager ();
1449+ auto allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
1450+ auto maxRootDeviceIndex = numDevices - 1u ;
1451+
1452+ std::vector<uint32_t > rootDeviceIndices;
1453+ rootDeviceIndices.reserve (numDevices);
1454+ rootDeviceIndices.push_back (0u );
1455+ rootDeviceIndices.push_back (1u );
1456+ rootDeviceIndices.push_back (2u );
1457+
1458+ auto rootDeviceIndex = rootDeviceIndices.at (0 );
1459+ AllocationProperties allocationProperties{rootDeviceIndex,
1460+ true ,
1461+ alignedSize,
1462+ allocationType,
1463+ unifiedMemoryProperties.subdeviceBitfield .count () > 1 ,
1464+ unifiedMemoryProperties.subdeviceBitfield .count () > 1 ,
1465+ unifiedMemoryProperties.subdeviceBitfield };
1466+ allocationProperties.flags .shareable = unifiedMemoryProperties.allocationFlags .flags .shareable ;
1467+
1468+ SvmAllocationData allocData (maxRootDeviceIndex);
1469+
1470+ void *unifiedMemoryPtr = memoryManager->createMultiGraphicsAllocation (rootDeviceIndices, allocationProperties, allocData.gpuAllocations );
1471+
1472+ EXPECT_NE (nullptr , unifiedMemoryPtr);
1473+ EXPECT_EQ (numDevices, allocData.gpuAllocations .getGraphicsAllocations ().size ());
1474+
1475+ for (auto rootDeviceIndex = 0u ; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
1476+ auto alloc = allocData.gpuAllocations .getGraphicsAllocation (rootDeviceIndex);
1477+
1478+ EXPECT_NE (nullptr , alloc);
1479+ EXPECT_EQ (rootDeviceIndex, alloc->getRootDeviceIndex ());
1480+ }
1481+
1482+ for (auto gpuAllocation : allocData.gpuAllocations .getGraphicsAllocations ()) {
1483+ memoryManager->freeGraphicsMemory (gpuAllocation);
1484+ }
1485+ }
1486+
1487+ HWTEST_F (createHostUnifiedMemoryAllocationTest,
1488+ whenCreatingMultiGraphicsAllocationForSpecificRootDeviceIndicesThenOnlyGraphicsAllocationPerSpecificRootDeviceIndexIsCreated) {
1489+
1490+ NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties (InternalMemoryType::HOST_UNIFIED_MEMORY);
1491+ unifiedMemoryProperties.subdeviceBitfield = device0->getDevice ().getDeviceBitfield ();
1492+
1493+ auto alignedSize = alignUp<size_t >(allocationSize, MemoryConstants::pageSize64k);
1494+ auto memoryManager = context.getMemoryManager ();
1495+ auto allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
1496+ auto maxRootDeviceIndex = numDevices - 1u ;
1497+
1498+ std::vector<uint32_t > rootDeviceIndices;
1499+ rootDeviceIndices.reserve (numDevices);
1500+ rootDeviceIndices.push_back (0u );
1501+ rootDeviceIndices.push_back (2u );
1502+
1503+ auto noProgramedRootDeviceIndex = 1u ;
1504+ auto rootDeviceIndex = rootDeviceIndices.at (0 );
1505+ AllocationProperties allocationProperties{rootDeviceIndex,
1506+ true ,
1507+ alignedSize,
1508+ allocationType,
1509+ unifiedMemoryProperties.subdeviceBitfield .count () > 1 ,
1510+ unifiedMemoryProperties.subdeviceBitfield .count () > 1 ,
1511+ unifiedMemoryProperties.subdeviceBitfield };
1512+ allocationProperties.flags .shareable = unifiedMemoryProperties.allocationFlags .flags .shareable ;
1513+
1514+ SvmAllocationData allocData (maxRootDeviceIndex);
1515+
1516+ void *unifiedMemoryPtr = memoryManager->createMultiGraphicsAllocation (rootDeviceIndices, allocationProperties, allocData.gpuAllocations );
1517+
1518+ EXPECT_NE (nullptr , unifiedMemoryPtr);
1519+ EXPECT_EQ (numDevices, allocData.gpuAllocations .getGraphicsAllocations ().size ());
1520+
1521+ for (auto rootDeviceIndex = 0u ; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
1522+ auto alloc = allocData.gpuAllocations .getGraphicsAllocation (rootDeviceIndex);
1523+
1524+ if (rootDeviceIndex == noProgramedRootDeviceIndex) {
1525+ EXPECT_EQ (nullptr , alloc);
1526+ } else {
1527+ EXPECT_NE (nullptr , alloc);
1528+ EXPECT_EQ (rootDeviceIndex, alloc->getRootDeviceIndex ());
1529+ }
1530+ }
1531+
1532+ for (auto gpuAllocation : allocData.gpuAllocations .getGraphicsAllocations ()) {
1533+ memoryManager->freeGraphicsMemory (gpuAllocation);
1534+ }
1535+ }
1536+
14391537struct MemoryAllocationTypeArray {
14401538 const InternalMemoryType allocationType[3 ] = {InternalMemoryType::HOST_UNIFIED_MEMORY,
14411539 InternalMemoryType::DEVICE_UNIFIED_MEMORY,
0 commit comments