From d7b6f11cedff8315cd7f7908e2f8d439c4ffcbc4 Mon Sep 17 00:00:00 2001 From: "Dunajski, Bartosz" Date: Thu, 28 Dec 2023 14:18:34 +0000 Subject: [PATCH] refactor: improve creating 48b resources Signed-off-by: Dunajski, Bartosz --- shared/source/helpers/gfx_core_helper.h | 4 +++ .../source/helpers/gfx_core_helper_base.inl | 5 +++ .../source/memory_manager/memory_manager.cpp | 6 ++-- .../helpers/gfx_core_helper_tests.cpp | 6 +++- ...nager_allocate_in_preferred_pool_tests.cpp | 34 +++++++++++++++++-- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index bf7bf42732..36a42f0ad9 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -176,6 +176,8 @@ class GfxCoreHelper { virtual bool areSecondaryContextsSupported() const = 0; virtual uint32_t getContextGroupContextsCount() const = 0; + virtual bool is48ResourceNeededForCmdBuffer() const = 0; + virtual ~GfxCoreHelper() = default; protected: @@ -390,6 +392,8 @@ class GfxCoreHelperHw : public GfxCoreHelper { bool areSecondaryContextsSupported() const override; uint32_t getContextGroupContextsCount() const override; + bool is48ResourceNeededForCmdBuffer() const override; + ~GfxCoreHelperHw() override = default; protected: diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 3db5252048..d7f29980f6 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -730,4 +730,9 @@ uint32_t GfxCoreHelperHw::getContextGroupContextsCount() const { return 0; } +template +bool GfxCoreHelperHw::is48ResourceNeededForCmdBuffer() const { + return true; +} + } // namespace NEO diff --git a/shared/source/memory_manager/memory_manager.cpp b/shared/source/memory_manager/memory_manager.cpp index cdf996116a..fb5c70c8eb 100644 --- a/shared/source/memory_manager/memory_manager.cpp +++ b/shared/source/memory_manager/memory_manager.cpp @@ -476,8 +476,11 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo } switch (properties.allocationType) { - case AllocationType::deferredTasksList: case AllocationType::commandBuffer: + case AllocationType::ringBuffer: + allocationData.flags.resource48Bit = helper.is48ResourceNeededForCmdBuffer(); + break; + case AllocationType::deferredTasksList: case AllocationType::image: case AllocationType::indirectObjectHeap: case AllocationType::instructionHeap: @@ -495,7 +498,6 @@ bool MemoryManager::getAllocationData(AllocationData &allocationData, const Allo case AllocationType::timestampPacketTagBuffer: case AllocationType::debugModuleArea: case AllocationType::gpuTimestampDeviceBuffer: - case AllocationType::ringBuffer: case AllocationType::semaphoreBuffer: allocationData.flags.resource48Bit = true; break; diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index f0ecb963d2..17be5783eb 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -1609,4 +1609,8 @@ TEST_F(GfxCoreHelperTest, givenContextGroupEnabledWithDebugKeyWhenContextGroupCo debugManager.flags.ContextGroupSize.set(2); EXPECT_EQ(2u, gfxCoreHelper.getContextGroupContextsCount()); EXPECT_TRUE(gfxCoreHelper.areSecondaryContextsSupported()); -} \ No newline at end of file +} + +HWTEST_F(GfxCoreHelperTest, whenAskingIf48bResourceNeededForCmdBufferThenReturnTrue) { + EXPECT_TRUE(getHelper().is48ResourceNeededForCmdBuffer()); +} diff --git a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp index 315dbe2da6..92debe67f4 100644 --- a/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp +++ b/shared/test/unit_test/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp @@ -1034,6 +1034,27 @@ TEST_P(MemoryManagerGetAlloctionDataHaveToBeForcedTo48BitTest, givenAllocationTy EXPECT_TRUE(allocationData.flags.resource48Bit); } +using MemoryManagerGetAlloctionDataOptionallyForcedTo48BitTest = testing::TestWithParam>; + +TEST_P(MemoryManagerGetAlloctionDataOptionallyForcedTo48BitTest, givenAllocationTypesOptionalFor48BitThenAllocationDataResource48BitIsSet) { + MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + + AllocationType allocationType; + bool propertiesFlag48Bit; + + std::tie(allocationType, propertiesFlag48Bit) = GetParam(); + + AllocationProperties properties(mockRootDeviceIndex, 0, allocationType, mockDeviceBitfield); + properties.flags.resource48Bit = propertiesFlag48Bit; + + AllocationData allocationData; + MockMemoryManager mockMemoryManager; + mockMemoryManager.getAllocationData(allocationData, properties, nullptr, mockMemoryManager.createStorageInfoFromProperties(properties)); + + EXPECT_EQ(gfxCoreHelper.is48ResourceNeededForCmdBuffer(), allocationData.flags.resource48Bit); +} + using MemoryManagerGetAlloctionDataHaveNotToBeForcedTo48BitTest = testing::TestWithParam>; TEST_P(MemoryManagerGetAlloctionDataHaveNotToBeForcedTo48BitTest, givenAllocationTypesHaveNotToBeForcedTo48BitThenAllocationDataResource48BitIsSetProperly) { @@ -1052,7 +1073,6 @@ TEST_P(MemoryManagerGetAlloctionDataHaveNotToBeForcedTo48BitTest, givenAllocatio } static const AllocationType allocationHaveToBeForcedTo48Bit[] = { - AllocationType::commandBuffer, AllocationType::image, AllocationType::indirectObjectHeap, AllocationType::instructionHeap, @@ -1066,11 +1086,15 @@ static const AllocationType allocationHaveToBeForcedTo48Bit[] = { AllocationType::sharedResourceCopy, AllocationType::surfaceStateHeap, AllocationType::timestampPacketTagBuffer, - AllocationType::ringBuffer, AllocationType::semaphoreBuffer, AllocationType::deferredTasksList, }; +static const AllocationType allocationsOptionallyForcedTo48Bit[] = { + AllocationType::commandBuffer, + AllocationType::ringBuffer, +}; + static const AllocationType allocationHaveNotToBeForcedTo48Bit[] = { AllocationType::buffer, AllocationType::bufferHostMemory, @@ -1105,3 +1129,9 @@ INSTANTIATE_TEST_CASE_P(NotForceTo48Bit, ::testing::Combine( ::testing::ValuesIn(allocationHaveNotToBeForcedTo48Bit), ::testing::Bool())); + +INSTANTIATE_TEST_CASE_P(OptionallyForceTo48Bit, + MemoryManagerGetAlloctionDataOptionallyForcedTo48BitTest, + ::testing::Combine( + ::testing::ValuesIn(allocationsOptionallyForcedTo48Bit), + ::testing::Bool()));