Use correct heap when opening device memory IPC handle

This change extends the logic of opening IPC
memory handles and fills the gap between this
logic and allocation of USM device buffers.

When HEAP_EXTENDED is available, then it is
preferred.

Signed-off-by: Wrobel, Patryk <patryk.wrobel@intel.com>
This commit is contained in:
Wrobel, Patryk
2022-11-07 18:39:23 +00:00
committed by Compute-Runtime-Automation
parent eafea5e2fe
commit 4c05a54c2b
3 changed files with 41 additions and 10 deletions

View File

@@ -1731,7 +1731,7 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl
memoryManager->freeGraphicsMemory(graphicsAllocationFromReferencedHandle);
}
TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandlesWithOneHandleThenAllocationSucceeds) {
TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandlesWithOneHandleThenAllocationSucceedsAndGpuAddressIsFromTheExpectedHeap) {
mock->ioctl_expected.primeFdToHandle = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
@@ -1744,6 +1744,15 @@ TEST_F(DrmMemoryManagerTestPrelim, whenCreatingAllocationFromMultipleSharedHandl
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromMultipleSharedHandles(handles, properties, false, false);
ASSERT_NE(nullptr, graphicsAllocation);
const bool prefer57bitAddressing = memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0;
const auto expectedHeap = prefer57bitAddressing ? HeapIndex::HEAP_EXTENDED : HeapIndex::HEAP_STANDARD2MB;
auto gpuAddress = graphicsAllocation->getGpuAddress();
auto gmmHelper = device->getGmmHelper();
EXPECT_LT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(expectedHeap)), gpuAddress);
EXPECT_GT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(expectedHeap)), gpuAddress);
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
auto bo = drmAllocation->getBO();
EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle);

View File

@@ -1480,7 +1480,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenAcquireGpuAddressFromStandardHeap64KB) {
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenAcquireGpuAddressFromExpectedHeap) {
mock->ioctl_expected.primeFdToHandle = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
@@ -1498,18 +1498,23 @@ TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemory
EXPECT_EQ(MemoryPool::SystemCpuInaccessible, graphicsAllocation->getMemoryPool());
EXPECT_EQ(this->mock->inputFd, static_cast<int32_t>(handle));
const bool prefer57bitAddressing = memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_EXTENDED) > 0;
const auto expectedHeap = prefer57bitAddressing ? HeapIndex::HEAP_EXTENDED : HeapIndex::HEAP_STANDARD2MB;
auto gpuAddress = graphicsAllocation->getGpuAddress();
auto gmmHelper = device->getGmmHelper();
EXPECT_LT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD2MB)), gpuAddress);
EXPECT_GT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD2MB)), gpuAddress);
EXPECT_LT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(expectedHeap)), gpuAddress);
EXPECT_GT(gmmHelper->canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(expectedHeap)), gpuAddress);
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(graphicsAllocation);
auto bo = drmAllocation->getBO();
EXPECT_EQ(this->mock->outputHandle, static_cast<uint32_t>(bo->peekHandle()));
EXPECT_EQ(gpuAddress, bo->peekAddress());
EXPECT_EQ(size, bo->peekSize());
EXPECT_EQ(alignUp(size, 2 * MemoryConstants::megaByte), bo->peekUnmapSize());
const auto expectedUnmapSize = prefer57bitAddressing ? alignUp(size, MemoryConstants::pageSize) : alignUp(size, 2 * MemoryConstants::megaByte);
EXPECT_EQ(expectedUnmapSize, bo->peekUnmapSize());
EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle());
memoryManager->freeGraphicsMemory(graphicsAllocation);