From 92f4144661e9f732eb3743dd1c578877a2159bc7 Mon Sep 17 00:00:00 2001 From: Slawomir Milczarek Date: Thu, 21 May 2020 14:15:01 +0200 Subject: [PATCH] Amendments in GPU address acquisition for media sharing on Linux Related-To: NEO-3774 Change-Id: If3dbf1a63c4a56d8a97d6a16eb08d2ba06d8ed88 Signed-off-by: Slawomir Milczarek --- .../linux/drm_memory_manager_tests.cpp | 34 +++++++++++++++++++ .../os_interface/linux/drm_memory_manager.cpp | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index eb43b12cca..0dcbaa378c 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -57,6 +57,7 @@ AllocationProperties createAllocationProperties(uint32_t rootDeviceIndex, size_t } typedef Test DrmMemoryManagerTest; +typedef Test DrmMemoryManagerWithLocalMemoryTest; typedef Test DrmMemoryManagerWithExplicitExpectationsTest; TEST_F(DrmMemoryManagerTest, whenCreatingDrmMemoryManagerThenSupportsMultiStorageResourcesFlagIsSetToFalse) { @@ -1734,6 +1735,39 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledT memoryManager->freeGraphicsMemory(graphicsAllocation); } +TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenCreateGraphicsAllocationFromSharedHandleIsCalledThenAcquireGpuAddressFromStandardHeap64KB) { + mock->ioctl_expected.primeFdToHandle = 1; + mock->ioctl_expected.gemWait = 1; + mock->ioctl_expected.gemClose = 1; + + osHandle handle = 1u; + this->mock->outputHandle = 2u; + size_t size = 4096u; + AllocationProperties properties(rootDeviceIndex, false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER, false, {}); + + auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false); + ASSERT_NE(nullptr, graphicsAllocation); + + EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(size, graphicsAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, graphicsAllocation->getMemoryPool()); + EXPECT_EQ(this->mock->inputFd, static_cast(handle)); + + auto gpuAddress = graphicsAllocation->getGpuAddress(); + EXPECT_LT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), gpuAddress); + EXPECT_GT(GmmHelper::canonize(memoryManager->getGfxPartition(rootDeviceIndex)->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), gpuAddress); + + DrmAllocation *drmAllocation = static_cast(graphicsAllocation); + auto bo = drmAllocation->getBO(); + EXPECT_EQ(this->mock->outputHandle, static_cast(bo->peekHandle())); + EXPECT_EQ(gpuAddress, bo->peekAddress()); + EXPECT_EQ(size, bo->peekSize()); + + EXPECT_EQ(handle, graphicsAllocation->peekSharedHandle()); + + memoryManager->freeGraphicsMemory(graphicsAllocation); +} + TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledAndRootDeviceIndexIsSpecifiedThenGraphicsAllocationIsReturnedWithCorrectRootDeviceIndex) { mock->ioctl_expected.primeFdToHandle = 1; mock->ioctl_expected.gemWait = 1; diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 104d3f8951..9c3cc46171 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -441,7 +441,7 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle) BufferObject *DrmMemoryManager::createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex) { uint64_t gpuRange = 0llu; - gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, false); + gpuRange = acquireGpuRange(size, requireSpecificBitness, rootDeviceIndex, isLocalMemorySupported(rootDeviceIndex)); auto bo = new (std::nothrow) BufferObject(&getDrm(rootDeviceIndex), boHandle, size); if (!bo) {