Skip to content

Commit dcf708f

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Add proper ULTs to test createMultiGraphicsAllocation function
Related-To: NEO-4589 Change-Id: Ic78dee29f7715a6e5eff5b5c28f337452921d5b3 Signed-off-by: Krzysztof Gibala <[email protected]>
1 parent 067fea9 commit dcf708f

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

opencl/test/unit_test/command_queue/enqueue_svm_tests.cpp

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
14391537
struct MemoryAllocationTypeArray {
14401538
const InternalMemoryType allocationType[3] = {InternalMemoryType::HOST_UNIFIED_MEMORY,
14411539
InternalMemoryType::DEVICE_UNIFIED_MEMORY,

opencl/test/unit_test/mocks/mock_context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ class MockContext : public Context {
4848
struct MockDefaultContext : MockContext {
4949
MockDefaultContext();
5050

51-
UltClDeviceFactory ultClDeviceFactory{2, 0};
51+
UltClDeviceFactory ultClDeviceFactory{3, 0};
5252
MockClDevice *pRootDevice0;
5353
MockClDevice *pRootDevice1;
54+
MockClDevice *pRootDevice2;
5455
};
5556

5657
struct MockSpecializedContext : MockContext {

shared/source/memory_manager/unified_memory_manager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(uint32_t maxRootDevice
119119
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
120120

121121
std::vector<uint32_t> rootDeviceIndices;
122-
rootDeviceIndices.reserve(maxRootDeviceIndex);
122+
rootDeviceIndices.reserve(maxRootDeviceIndex + 1);
123123
for (auto rootDeviceIndex = 0u; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
124124
rootDeviceIndices.push_back(rootDeviceIndex);
125125
}

0 commit comments

Comments
 (0)