From bdf8cf5e2356391aeca48ed953cf507b8056a24c Mon Sep 17 00:00:00 2001 From: Krzysztof Gibala Date: Tue, 23 Mar 2021 12:10:21 +0000 Subject: [PATCH] Add crossRootDeviceAccess flag Add flag to AllocationProperties for setup system memory allocation path for buffers Related-To: NEO-5508 Signed-off-by: Krzysztof Gibala --- opencl/source/mem_obj/buffer.cpp | 3 +++ .../test/unit_test/mem_obj/buffer_tests.cpp | 9 ++++++++ ...nager_allocate_in_preferred_pool_tests.inl | 22 +++++++++++++++++++ .../memory_manager/allocation_properties.h | 3 ++- .../source/memory_manager/memory_manager.cpp | 2 ++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/opencl/source/mem_obj/buffer.cpp b/opencl/source/mem_obj/buffer.cpp index 7b913a5fd1..074ca09568 100644 --- a/opencl/source/mem_obj/buffer.cpp +++ b/opencl/source/mem_obj/buffer.cpp @@ -274,11 +274,13 @@ Buffer *Buffer::create(Context *context, AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(), *hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex)); + allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1; allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, ptr); } else { AllocationProperties allocProperties = MemoryPropertiesHelper::getAllocationProperties(rootDeviceIndex, memoryProperties, allocationInfo[rootDeviceIndex].allocateMemory, size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(), *hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex)); + allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1; allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties, hostPtr); if (allocationInfo[rootDeviceIndex].memory) { ptr = reinterpret_cast(allocationInfo[rootDeviceIndex].memory->getUnderlyingBuffer()); @@ -299,6 +301,7 @@ Buffer *Buffer::create(Context *context, true, // allocateMemory size, allocationInfo[rootDeviceIndex].allocationType, context->areMultiStorageAllocationsPreferred(), *hwInfo, context->getDeviceBitfieldForAllocation(rootDeviceIndex)); + allocProperties.flags.crossRootDeviceAccess = context->getRootDeviceIndices().size() > 1; allocationInfo[rootDeviceIndex].memory = memoryManager->allocateGraphicsMemoryWithProperties(allocProperties); } diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index d173fd8a79..a95a09b0b0 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -2135,6 +2135,15 @@ TEST_F(MultiRootDeviceBufferTest, WhenBuffersAreCreatedAndEnqueueCopyBufferRectC EXPECT_EQ(buffer2->getMultiGraphicsAllocation().getLastUsedRootDeviceIndex(), 2u); } +TEST_F(MultiRootDeviceBufferTest, WhenBufferIsCreatedThenBufferMultiGraphicsAllocationIsCreatedInSystemMemoryPool) { + cl_int retVal = 0; + + std::unique_ptr buffer1(Buffer::create(context.get(), 0, MemoryConstants::pageSize, nullptr, retVal)); + + EXPECT_TRUE(MemoryPool::isSystemMemoryPool(buffer1->getMultiGraphicsAllocation().getGraphicsAllocation(1u)->getMemoryPool())); + EXPECT_TRUE(MemoryPool::isSystemMemoryPool(buffer1->getMultiGraphicsAllocation().getGraphicsAllocation(2u)->getMemoryPool())); +} + TEST_F(MultiRootDeviceBufferTest, givenBufferWhenGetSurfaceSizeCalledWithoutAlignSizeForAuxTranslationThenCorrectValueReturned) { cl_int retVal = 0; cl_mem_flags flags = CL_MEM_READ_WRITE; diff --git a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index fbbb96a50f..680baef064 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/opencl/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -50,6 +50,28 @@ TEST_F(MemoryManagerGetAlloctionDataTests, givenNonHostMemoryAllocatoinTypeWhenA EXPECT_EQ(nullptr, allocData.hostPtr); } +TEST_F(MemoryManagerGetAlloctionDataTests, givenMultiRootDeviceIndexAllocationPropertiesWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsSet) { + AllocationData allocData; + AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield); + properties.flags.crossRootDeviceAccess = true; + + MockMemoryManager mockMemoryManager; + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + + EXPECT_TRUE(allocData.flags.useSystemMemory); +} + +TEST_F(MemoryManagerGetAlloctionDataTests, givenDisabledCrossRootDeviceAccsessFlagInAllocationPropertiesWhenAllocationDataIsQueriedThenUseSystemMemoryFlagsIsNotSet) { + AllocationData allocData; + AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::BUFFER, false, mockDeviceBitfield); + properties.flags.crossRootDeviceAccess = false; + + MockMemoryManager mockMemoryManager; + mockMemoryManager.getAllocationData(allocData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + + EXPECT_FALSE(allocData.flags.useSystemMemory); +} + HWTEST_F(MemoryManagerGetAlloctionDataTests, givenCommandBufferAllocationTypeWhenGetAllocationDataIsCalledThenSystemMemoryIsRequested) { AllocationData allocData; AllocationProperties properties(mockRootDeviceIndex, true, 10, GraphicsAllocation::AllocationType::COMMAND_BUFFER, false, mockDeviceBitfield); diff --git a/shared/source/memory_manager/allocation_properties.h b/shared/source/memory_manager/allocation_properties.h index 14365afb63..7903732f62 100644 --- a/shared/source/memory_manager/allocation_properties.h +++ b/shared/source/memory_manager/allocation_properties.h @@ -26,7 +26,8 @@ struct AllocationProperties { uint32_t isUSMHostAllocation : 1; uint32_t isUSMDeviceAllocation : 1; uint32_t use32BitFrontWindow : 1; - uint32_t reserved : 20; + uint32_t crossRootDeviceAccess : 1; + uint32_t reserved : 19; } flags; uint32_t allFlags = 0; }; diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index 3153448a42..fa54fd06a8 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -424,6 +424,8 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo allocationData.rootDeviceIndex = properties.rootDeviceIndex; allocationData.useMmapObject = properties.useMmapObject; + allocationData.flags.useSystemMemory |= properties.flags.crossRootDeviceAccess; + hwHelper.setExtraAllocationData(allocationData, properties, *hwInfo); return true;