Add proper ULTs to test createMultiGraphicsAllocation function

Related-To: NEO-4589
Change-Id: Ic78dee29f7715a6e5eff5b5c28f337452921d5b3
Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
Krzysztof Gibala
2020-08-28 14:44:18 +02:00
committed by sys_ocldev
parent 067fea96ca
commit dcf708f2d2
3 changed files with 102 additions and 3 deletions

View File

@ -1401,12 +1401,14 @@ struct createHostUnifiedMemoryAllocationTest : public ::testing::Test {
void SetUp() override {
device0 = context.pRootDevice0;
device1 = context.pRootDevice1;
device2 = context.pRootDevice2;
svmManager = context.getSVMAllocsManager();
EXPECT_EQ(0u, svmManager->getNumAllocs());
}
const size_t allocationSize = 4096u;
const uint32_t numDevices = 2u;
const uint32_t numDevices = 3u;
MockDefaultContext context;
MockClDevice *device2;
MockClDevice *device1;
MockClDevice *device0;
SVMAllocsManager *svmManager = nullptr;
@ -1436,6 +1438,102 @@ HWTEST_F(createHostUnifiedMemoryAllocationTest,
svmManager->freeSVMAlloc(unifiedMemoryPtr);
}
HWTEST_F(createHostUnifiedMemoryAllocationTest,
whenCreatingMultiGraphicsAllocationThenGraphicsAllocationPerDeviceIsCreated) {
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY);
unifiedMemoryProperties.subdeviceBitfield = device0->getDevice().getDeviceBitfield();
auto alignedSize = alignUp<size_t>(allocationSize, MemoryConstants::pageSize64k);
auto memoryManager = context.getMemoryManager();
auto allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
auto maxRootDeviceIndex = numDevices - 1u;
std::vector<uint32_t> rootDeviceIndices;
rootDeviceIndices.reserve(numDevices);
rootDeviceIndices.push_back(0u);
rootDeviceIndices.push_back(1u);
rootDeviceIndices.push_back(2u);
auto rootDeviceIndex = rootDeviceIndices.at(0);
AllocationProperties allocationProperties{rootDeviceIndex,
true,
alignedSize,
allocationType,
unifiedMemoryProperties.subdeviceBitfield.count() > 1,
unifiedMemoryProperties.subdeviceBitfield.count() > 1,
unifiedMemoryProperties.subdeviceBitfield};
allocationProperties.flags.shareable = unifiedMemoryProperties.allocationFlags.flags.shareable;
SvmAllocationData allocData(maxRootDeviceIndex);
void *unifiedMemoryPtr = memoryManager->createMultiGraphicsAllocation(rootDeviceIndices, allocationProperties, allocData.gpuAllocations);
EXPECT_NE(nullptr, unifiedMemoryPtr);
EXPECT_EQ(numDevices, allocData.gpuAllocations.getGraphicsAllocations().size());
for (auto rootDeviceIndex = 0u; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
auto alloc = allocData.gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
EXPECT_NE(nullptr, alloc);
EXPECT_EQ(rootDeviceIndex, alloc->getRootDeviceIndex());
}
for (auto gpuAllocation : allocData.gpuAllocations.getGraphicsAllocations()) {
memoryManager->freeGraphicsMemory(gpuAllocation);
}
}
HWTEST_F(createHostUnifiedMemoryAllocationTest,
whenCreatingMultiGraphicsAllocationForSpecificRootDeviceIndicesThenOnlyGraphicsAllocationPerSpecificRootDeviceIndexIsCreated) {
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY);
unifiedMemoryProperties.subdeviceBitfield = device0->getDevice().getDeviceBitfield();
auto alignedSize = alignUp<size_t>(allocationSize, MemoryConstants::pageSize64k);
auto memoryManager = context.getMemoryManager();
auto allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
auto maxRootDeviceIndex = numDevices - 1u;
std::vector<uint32_t> rootDeviceIndices;
rootDeviceIndices.reserve(numDevices);
rootDeviceIndices.push_back(0u);
rootDeviceIndices.push_back(2u);
auto noProgramedRootDeviceIndex = 1u;
auto rootDeviceIndex = rootDeviceIndices.at(0);
AllocationProperties allocationProperties{rootDeviceIndex,
true,
alignedSize,
allocationType,
unifiedMemoryProperties.subdeviceBitfield.count() > 1,
unifiedMemoryProperties.subdeviceBitfield.count() > 1,
unifiedMemoryProperties.subdeviceBitfield};
allocationProperties.flags.shareable = unifiedMemoryProperties.allocationFlags.flags.shareable;
SvmAllocationData allocData(maxRootDeviceIndex);
void *unifiedMemoryPtr = memoryManager->createMultiGraphicsAllocation(rootDeviceIndices, allocationProperties, allocData.gpuAllocations);
EXPECT_NE(nullptr, unifiedMemoryPtr);
EXPECT_EQ(numDevices, allocData.gpuAllocations.getGraphicsAllocations().size());
for (auto rootDeviceIndex = 0u; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
auto alloc = allocData.gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
if (rootDeviceIndex == noProgramedRootDeviceIndex) {
EXPECT_EQ(nullptr, alloc);
} else {
EXPECT_NE(nullptr, alloc);
EXPECT_EQ(rootDeviceIndex, alloc->getRootDeviceIndex());
}
}
for (auto gpuAllocation : allocData.gpuAllocations.getGraphicsAllocations()) {
memoryManager->freeGraphicsMemory(gpuAllocation);
}
}
struct MemoryAllocationTypeArray {
const InternalMemoryType allocationType[3] = {InternalMemoryType::HOST_UNIFIED_MEMORY,
InternalMemoryType::DEVICE_UNIFIED_MEMORY,

View File

@ -48,9 +48,10 @@ class MockContext : public Context {
struct MockDefaultContext : MockContext {
MockDefaultContext();
UltClDeviceFactory ultClDeviceFactory{2, 0};
UltClDeviceFactory ultClDeviceFactory{3, 0};
MockClDevice *pRootDevice0;
MockClDevice *pRootDevice1;
MockClDevice *pRootDevice2;
};
struct MockSpecializedContext : MockContext {

View File

@ -119,7 +119,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(uint32_t maxRootDevice
GraphicsAllocation::AllocationType allocationType = GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
std::vector<uint32_t> rootDeviceIndices;
rootDeviceIndices.reserve(maxRootDeviceIndex);
rootDeviceIndices.reserve(maxRootDeviceIndex + 1);
for (auto rootDeviceIndex = 0u; rootDeviceIndex <= maxRootDeviceIndex; rootDeviceIndex++) {
rootDeviceIndices.push_back(rootDeviceIndex);
}