From b6d86d2648c8a01199536c51d8741bd75d118f32 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Tue, 18 Jun 2024 10:14:25 +0000 Subject: [PATCH] refactor: tests for buffer pool add support for future AIL Related-To: NEO-11694 Signed-off-by: Dominik Dabek --- opencl/source/context/context.cpp | 5 +- .../mem_obj/buffer_pool_alloc_tests.cpp | 73 +++++++------------ shared/source/ail/ail_configuration.h | 4 + shared/source/ail/ail_configuration_base.inl | 5 ++ shared/source/ail/ail_configuration_extra.cpp | 2 + .../xe_hpg_core/dg2/ail_configuration_dg2.cpp | 6 ++ .../common/helpers/mock_product_helper_hw.h | 2 + .../common/helpers/mock_product_helper_hw.inl | 5 ++ .../common/mocks/mock_ail_configuration.h | 5 ++ 9 files changed, 59 insertions(+), 48 deletions(-) diff --git a/opencl/source/context/context.cpp b/opencl/source/context/context.cpp index bc5457c335..82a664e71a 100644 --- a/opencl/source/context/context.cpp +++ b/opencl/source/context/context.cpp @@ -7,11 +7,13 @@ #include "opencl/source/context/context.h" +#include "shared/source/ail/ail_configuration.h" #include "shared/source/built_ins/built_ins.h" #include "shared/source/command_stream/command_stream_receiver.h" #include "shared/source/compiler_interface/compiler_interface.h" #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/device/sub_device.h" +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/get_info.h" #include "shared/source/helpers/hw_info.h" @@ -539,8 +541,9 @@ bool Context::BufferPoolAllocator::isAggregatedSmallBuffersEnabled(Context *cont bool isSupportedForSingleDeviceContexts = false; bool isSupportedForAllContexts = false; if (context->getNumDevices() > 0) { + auto ailConfiguration = context->getDevices()[0]->getRootDeviceEnvironment().getAILConfigurationHelper(); auto &productHelper = context->getDevices()[0]->getProductHelper(); - isSupportedForSingleDeviceContexts = productHelper.isBufferPoolAllocatorSupported(); + isSupportedForSingleDeviceContexts = productHelper.isBufferPoolAllocatorSupported() && (ailConfiguration ? ailConfiguration->isBufferPoolEnabled() : true); } if (debugManager.flags.ExperimentalSmallBufferPoolAllocator.get() != -1) { diff --git a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp index e19cc4984d..f1e6f51987 100644 --- a/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_pool_alloc_tests.cpp @@ -9,6 +9,9 @@ #include "shared/source/utilities/buffer_pool_allocator.inl" #include "shared/source/utilities/heap_allocator.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/mock_product_helper_hw.h" +#include "shared/test/common/helpers/raii_product_helper.h" +#include "shared/test/common/mocks/mock_ail_configuration.h" #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/test_macros/hw_test.h" #include "shared/test/common/test_macros/test.h" @@ -99,13 +102,9 @@ class AggregatedSmallBuffersKernelTest : public AggregatedSmallBuffersTestTempla using AggregatedSmallBuffersDefaultTest = AggregatedSmallBuffersTestTemplate<-1>; -HWTEST2_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOrMultiDeviceContextWhenCheckIfEnabledThenReturnCorrectValue, IsBeforeXeHpgCore) { +HWTEST_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOrMultiDeviceContextWhenCheckIfEnabledThenReturnCorrectValue) { DebugManagerStateRestore restore; // Single device context - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(-1); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } { debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(0); EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); @@ -120,10 +119,6 @@ HWTEST2_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOr } // Multi device context context->devices.push_back(nullptr); - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(-1); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } { debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(0); EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); @@ -139,44 +134,28 @@ HWTEST2_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOr context->devices.pop_back(); } -HWTEST2_F(AggregatedSmallBuffersDefaultTest, givenDifferentFlagValuesAndSingleOrMultiDeviceContextWhenCheckIfEnabledThenReturnCorrectValue, IsXeHpcCore) { - DebugManagerStateRestore restore; - // Single device context - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(-1); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(0); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(1); - EXPECT_TRUE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(2); - EXPECT_TRUE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - // Multi device context - context->devices.push_back(nullptr); - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(-1); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(0); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(1); - EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - { - debugManager.flags.ExperimentalSmallBufferPoolAllocator.set(2); - EXPECT_TRUE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); - } - context->devices.pop_back(); +HWTEST2_F(AggregatedSmallBuffersDefaultTest, givenSupportsOclBufferPoolCapabilityWhenCheckIfEnabledThenReturnCorrectValue, MatchAny) { + auto &rootDeviceEnvironment = *device->getExecutionEnvironment()->rootDeviceEnvironments[1]; + NEO::RAIIProductHelperFactory> raii(rootDeviceEnvironment); + + rootDeviceEnvironment.ailConfiguration.reset(new MockAILConfiguration()); + auto mockAIL = static_cast(rootDeviceEnvironment.ailConfiguration.get()); + + raii.mockProductHelper->isBufferPoolAllocatorSupportedValue = true; + mockAIL->isBufferPoolEnabledReturn = true; + EXPECT_TRUE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); + + raii.mockProductHelper->isBufferPoolAllocatorSupportedValue = true; + mockAIL->isBufferPoolEnabledReturn = false; + EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); + + raii.mockProductHelper->isBufferPoolAllocatorSupportedValue = false; + mockAIL->isBufferPoolEnabledReturn = true; + EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); + + raii.mockProductHelper->isBufferPoolAllocatorSupportedValue = false; + mockAIL->isBufferPoolEnabledReturn = false; + EXPECT_FALSE(context->getBufferPoolAllocator().isAggregatedSmallBuffersEnabled(context.get())); } using AggregatedSmallBuffersDisabledTest = AggregatedSmallBuffersTestTemplate<0>; diff --git a/shared/source/ail/ail_configuration.h b/shared/source/ail/ail_configuration.h index 48a34fbaaa..634bfc9cc1 100644 --- a/shared/source/ail/ail_configuration.h +++ b/shared/source/ail/ail_configuration.h @@ -68,6 +68,8 @@ class AILConfiguration { virtual bool isContextSyncFlagRequired() = 0; + virtual bool isBufferPoolEnabled() = 0; + virtual ~AILConfiguration() = default; virtual bool useLegacyValidationLogic() = 0; @@ -84,6 +86,7 @@ class AILConfiguration { extern const std::set applicationsContextSyncFlag; extern const std::set applicationsForceRcsDg2; +extern const std::set applicationsBufferPoolDisabledDG2; template class AILConfigurationHw : public AILConfiguration { @@ -98,6 +101,7 @@ class AILConfigurationHw : public AILConfiguration { void modifyKernelIfRequired(std::string &kernel) override; bool isFallbackToPatchtokensRequired(const std::string &kernelSources) override; bool isContextSyncFlagRequired() override; + bool isBufferPoolEnabled() override; bool useLegacyValidationLogic() override; bool forceRcs() override; diff --git a/shared/source/ail/ail_configuration_base.inl b/shared/source/ail/ail_configuration_base.inl index 98643c29ca..c4ccafe60f 100644 --- a/shared/source/ail/ail_configuration_base.inl +++ b/shared/source/ail/ail_configuration_base.inl @@ -45,6 +45,11 @@ inline bool AILConfigurationHw::isContextSyncFlagRequired() { return false; } +template +inline bool AILConfigurationHw::isBufferPoolEnabled() { + return true; +} + template inline bool AILConfigurationHw::useLegacyValidationLogic() { return false; diff --git a/shared/source/ail/ail_configuration_extra.cpp b/shared/source/ail/ail_configuration_extra.cpp index 9b3ed66290..617e07a933 100644 --- a/shared/source/ail/ail_configuration_extra.cpp +++ b/shared/source/ail/ail_configuration_extra.cpp @@ -30,6 +30,8 @@ const std::set applicationsForceRcsDg2 = {}; const std::set applicationsContextSyncFlag = {}; +const std::set applicationsBufferPoolDisabledDG2 = {}; + AILConfigurationCreateFunctionType ailConfigurationFactory[IGFX_MAX_PRODUCT]; void AILConfiguration::apply(RuntimeCapabilityTable &runtimeCapabilityTable) { diff --git a/shared/source/ail/xe_hpg_core/dg2/ail_configuration_dg2.cpp b/shared/source/ail/xe_hpg_core/dg2/ail_configuration_dg2.cpp index 605f4815ff..1ec1d52802 100644 --- a/shared/source/ail/xe_hpg_core/dg2/ail_configuration_dg2.cpp +++ b/shared/source/ail/xe_hpg_core/dg2/ail_configuration_dg2.cpp @@ -64,6 +64,12 @@ inline void AILConfigurationHw::applyExt(RuntimeCapabilityTable &runti } } +template <> +bool AILConfigurationHw::isBufferPoolEnabled() { + auto iterator = applicationsBufferPoolDisabledDG2.find(processName); + return iterator == applicationsBufferPoolDisabledDG2.end(); +} + template class AILConfigurationHw; } // namespace NEO diff --git a/shared/test/common/helpers/mock_product_helper_hw.h b/shared/test/common/helpers/mock_product_helper_hw.h index fb97e1be1b..610dad7f10 100644 --- a/shared/test/common/helpers/mock_product_helper_hw.h +++ b/shared/test/common/helpers/mock_product_helper_hw.h @@ -26,6 +26,7 @@ struct MockProductHelperHw : NEO::ProductHelperHw { bool isUnlockingLockedPtrNecessary(const HardwareInfo &hwInfo) const override; std::vector getSupportedNumGrfs(const ReleaseHelper *releaseHelper) const override; aub_stream::EngineType getDefaultCopyEngine() const override; + bool isBufferPoolAllocatorSupported() const override; bool use128MbEdram = false; bool enableMidThreadPreemption = false; @@ -34,6 +35,7 @@ struct MockProductHelperHw : NEO::ProductHelperHw { bool failOnConfigureHardwareCustom = false; bool isCooperativeEngineSupportedValue = true; bool returnedIsUnlockingLockedPtrNecessary = false; + bool isBufferPoolAllocatorSupportedValue = true; uint32_t returnedStepping = 0; uint32_t returnedL1CachePolicy = 0; uint32_t returnedL1CachePolicyIfDebugger = 0; diff --git a/shared/test/common/helpers/mock_product_helper_hw.inl b/shared/test/common/helpers/mock_product_helper_hw.inl index 765f6a4bfc..acfdae0610 100644 --- a/shared/test/common/helpers/mock_product_helper_hw.inl +++ b/shared/test/common/helpers/mock_product_helper_hw.inl @@ -75,6 +75,11 @@ bool MockProductHelperHw::isUnlockingLockedPtrNecessary(const Hardwa return this->returnedIsUnlockingLockedPtrNecessary; } +template <> +bool MockProductHelperHw::isBufferPoolAllocatorSupported() const { + return this->isBufferPoolAllocatorSupportedValue; +} + template <> std::vector MockProductHelperHw::getSupportedNumGrfs(const ReleaseHelper *releaseHelper) const { if (releaseHelper) { diff --git a/shared/test/common/mocks/mock_ail_configuration.h b/shared/test/common/mocks/mock_ail_configuration.h index 2fe7f9bfd7..09213ca387 100644 --- a/shared/test/common/mocks/mock_ail_configuration.h +++ b/shared/test/common/mocks/mock_ail_configuration.h @@ -27,6 +27,11 @@ class MockAILConfiguration : public AILConfiguration { return contextSyncFlagReturn; } + bool isBufferPoolEnabledReturn = true; + bool isBufferPoolEnabled() override { + return isBufferPoolEnabledReturn; + } + bool fallbackToLegacyValidationLogic = false; bool useLegacyValidationLogic() override { return fallbackToLegacyValidationLogic;