From 2d781e59342b8401d332cfaf0523f8bfd6c375e3 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Thu, 15 Oct 2020 08:53:36 +0200 Subject: [PATCH] Add missing USM host allocation flag Change-Id: I5658d5574fd522cff072adcc679f04805daabf12 Signed-off-by: Lukasz Jobczyk --- ...ager_allocate_in_device_pool_tests_dg1.cpp | 23 +++++++++++++++++++ .../memory_manager/allocation_properties.h | 2 ++ .../source/memory_manager/memory_manager.cpp | 3 +++ ...ry_manager_allocate_in_device_pool_dg1.cpp | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) 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 145db7dd8f..0cd7546864 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 @@ -268,6 +268,29 @@ TEST_F(DrmMemoryManagerLocalMemoryTest, givenMemoryInfoWhenAllocateWithAlignment memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerLocalMemoryTest, givenMemoryInfoAndNotUseObjectMmapPropertyWhenAllocateWithAlignmentThenUserptrIsUsed) { + DebugManagerStateRestore restorer; + DebugManager.flags.EnableBOMmapCreate.set(0); + + drm_i915_memory_region_info regionInfo[2] = {}; + regionInfo[0].region = {I915_MEMORY_CLASS_SYSTEM, 0}; + regionInfo[1].region = {I915_MEMORY_CLASS_DEVICE, 0}; + + mock->memoryInfo.reset(new MemoryInfoImpl(regionInfo, 2)); + mock->mmapOffsetRetVal = -1; + + AllocationData allocationData; + allocationData.size = MemoryConstants::pageSize64k; + allocationData.useMmapObject = false; + + auto allocation = memoryManager->allocateGraphicsMemoryWithAlignment(allocationData); + + EXPECT_NE(allocation, nullptr); + EXPECT_EQ(static_cast(mock->returnHandle), allocation->getBO()->peekHandle() + 1); + + memoryManager->freeGraphicsMemory(allocation); +} + TEST_F(DrmMemoryManagerLocalMemoryTest, givenMemoryInfoAndFailedMmapOffsetWhenAllocateWithAlignmentThenNullptr) { DebugManagerStateRestore restorer; DebugManager.flags.EnableBOMmapCreate.set(-1); diff --git a/shared/source/memory_manager/allocation_properties.h b/shared/source/memory_manager/allocation_properties.h index 71efef6e2c..b7875ebcaf 100644 --- a/shared/source/memory_manager/allocation_properties.h +++ b/shared/source/memory_manager/allocation_properties.h @@ -40,6 +40,7 @@ struct AllocationProperties { DeviceBitfield subDevicesBitfield{}; uint64_t gpuAddress = 0; OsContext *osContext = nullptr; + bool useMmapObject = true; AllocationProperties(uint32_t rootDeviceIndex, size_t size, GraphicsAllocation::AllocationType allocationType, DeviceBitfield subDevicesBitfieldParam) @@ -112,5 +113,6 @@ struct AllocationData { ImageInfo *imgInfo = nullptr; uint32_t rootDeviceIndex = 0; OsContext *osContext = nullptr; + bool useMmapObject = true; }; } // namespace NEO diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 0921dd6fd9..a8ec09b925 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -139,11 +139,13 @@ GraphicsAllocation *MemoryManager::createPaddedAllocation(GraphicsAllocation *in void *MemoryManager::createMultiGraphicsAllocation(std::vector &rootDeviceIndices, AllocationProperties &properties, MultiGraphicsAllocation &multiGraphicsAllocation) { void *ptr = nullptr; + properties.useMmapObject = rootDeviceIndices.size() == 1u; for (auto &rootDeviceIndex : rootDeviceIndices) { properties.rootDeviceIndex = rootDeviceIndex; if (!ptr) { + properties.flags.isUSMHostAllocation = true; auto graphicsAllocation = allocateGraphicsMemoryWithProperties(properties); if (!graphicsAllocation) { return nullptr; @@ -395,6 +397,7 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.gpuAddress = properties.gpuAddress; allocationData.osContext = properties.osContext; allocationData.rootDeviceIndex = properties.rootDeviceIndex; + allocationData.useMmapObject = properties.useMmapObject; hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo); 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 3856f3f91c..6069fb1cc0 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 @@ -66,7 +66,7 @@ BufferObject *DrmMemoryManager::createBufferObjectInMemoryRegion(Drm *drm, } DrmAllocation *DrmMemoryManager::createAllocWithAlignment(const AllocationData &allocationData, size_t size, size_t alignment, size_t alignedSize, uint64_t gpuAddress) { - bool useBooMmap = this->getDrm(allocationData.rootDeviceIndex).getMemoryInfo() != nullptr; + bool useBooMmap = this->getDrm(allocationData.rootDeviceIndex).getMemoryInfo() && allocationData.useMmapObject; if (DebugManager.flags.EnableBOMmapCreate.get() != -1) { useBooMmap = DebugManager.flags.EnableBOMmapCreate.get();