From ddf75b8d23a4e1b8d3840ab49e8c330262cab609 Mon Sep 17 00:00:00 2001 From: Jaime Arteaga Date: Wed, 9 Jun 2021 00:12:25 +0000 Subject: [PATCH] Add IPC events support (2/N) Fix shared allocation on multi DG1 systems Signed-off-by: Jaime Arteaga --- ...ager_allocate_in_device_pool_tests_dg1.cpp | 22 +------------------ .../os_interface/linux/drm_memory_manager.cpp | 4 ++-- .../os_interface/linux/drm_memory_manager.h | 2 +- ...memory_manager_allocate_in_device_pool.cpp | 2 +- ...ry_manager_allocate_in_device_pool_dg1.cpp | 2 +- 5 files changed, 6 insertions(+), 26 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp index acf4b0bc30..3de479ddfa 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_allocate_in_device_pool_tests_dg1.cpp @@ -335,26 +335,6 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMultiRootDeviceEnvironmentAndMemory using DrmMemoryManagerUsmSharedHandleTest = DrmMemoryManagerLocalMemoryTest; -TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledWithTagBufferAllocationTypeThenGraphicsAllocationIsReturned) { - osHandle handle = 1u; - this->mock->outputHandle = 2u; - size_t size = 4096u; - AllocationProperties properties(rootDeviceIndex, false, size, GraphicsAllocation::AllocationType::TAG_BUFFER, false, {}); - - auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true); - ASSERT_NE(nullptr, graphicsAllocation); - - EXPECT_EQ(this->mock->inputFd, (int)handle); - - DrmAllocation *drmAllocation = static_cast(graphicsAllocation); - auto bo = drmAllocation->getBO(); - EXPECT_EQ(bo->peekHandle(), (int)this->mock->outputHandle); - EXPECT_EQ(1u, bo->getRefCount()); - EXPECT_EQ(size, bo->peekSize()); - - memoryManager->freeGraphicsMemory(graphicsAllocation); -} - TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenDrmMemoryManagerAndOsHandleWhenCreateIsCalledWithBufferHostMemoryAllocationTypeThenGraphicsAllocationIsReturned) { osHandle handle = 1u; this->mock->outputHandle = 2u; @@ -405,7 +385,7 @@ TEST_F(DrmMemoryManagerUsmSharedHandleTest, givenMultiRootDeviceEnvironmentAndMe size_t size = 4096u; AllocationProperties properties(rootDeviceIndex, true, size, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, false, {}); - auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties); + auto ptr = memoryManager->createUSMHostAllocationFromSharedHandle(1, properties, false); EXPECT_EQ(ptr, nullptr); diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 5bb5c69588..f75b60b46e 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -593,7 +593,7 @@ BufferObject *DrmMemoryManager::findAndReferenceSharedBufferObject(int boHandle) GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) { if (isHostIpcAllocation) { - return createUSMHostAllocationFromSharedHandle(handle, properties); + return createUSMHostAllocationFromSharedHandle(handle, properties, false); } std::unique_lock lock(mtx); @@ -774,7 +774,7 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorag properties.gpuAddress = castToUint64(ptr); auto internalHandle = defaultAlloc->peekInternalHandle(this); - return createUSMHostAllocationFromSharedHandle(static_cast(internalHandle), properties); + return createUSMHostAllocationFromSharedHandle(static_cast(internalHandle), properties, true); } else { return allocateGraphicsMemoryWithProperties(properties, ptr); } diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index 3f6dc1cef2..87e810e1f9 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -75,7 +75,7 @@ class DrmMemoryManager : public MemoryManager { static std::unique_ptr create(ExecutionEnvironment &executionEnvironment); - DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties); + DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr); protected: BufferObject *findAndReferenceSharedBufferObject(int boHandle); diff --git a/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp b/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp index e0070e7663..67727a51fc 100644 --- a/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool.cpp @@ -17,7 +17,7 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, uint6 return nullptr; } -DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties) { +DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) { drm_prime_handle openFd = {0, 0, 0}; openFd.fd = handle; diff --git a/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool_dg1.cpp b/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool_dg1.cpp index 7660f67cd2..ae2473c268 100644 --- a/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool_dg1.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager_allocate_in_device_pool_dg1.cpp @@ -68,7 +68,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const return nullptr; } -DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties) { +DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool hasMappedPtr) { drm_prime_handle openFd = {0, 0, 0}; openFd.fd = handle;