From 76e023b94158d2f790d983fecc5809a087cbad17 Mon Sep 17 00:00:00 2001 From: Szymon Morek Date: Mon, 27 Jun 2022 14:58:29 +0000 Subject: [PATCH] Link build option with L1 cache policy helper Related-To: NEO-7003 Add L1CachePolicyHelper struct. This struct is resposible for L1 cache policy in build option, Surface State and stateless caching. Currently default option for all platforms is WBP (write by-pass) Signed-off-by: Szymon Morek --- .../unit_tests/sources/module/test_module.cpp | 22 +++++++++ .../test/unit_test/program/program_tests.cpp | 14 ++++++ shared/offline_compiler/source/CMakeLists.txt | 3 ++ .../command_stream_receiver.cpp | 2 +- shared/source/gen11/enable_gen11.cpp | 1 + shared/source/gen12lp/enable_gen12lp.cpp | 1 + shared/source/gen8/enable_gen8.cpp | 1 + shared/source/gen9/enable_gen9.cpp | 1 + .../source/gmm_helper/cache_settings_helper.h | 4 ++ shared/source/helpers/CMakeLists.txt | 2 + shared/source/helpers/cache_policy.h | 29 ++++++++++-- .../helpers/cache_policy_bdw_and_later.inl | 17 +++++++ .../helpers/cache_policy_dg2_and_later.inl | 30 ++++++++++++ .../helpers/compiler_hw_info_config_base.inl | 3 +- shared/source/os_interface/hw_info_config.h | 2 - shared/source/os_interface/hw_info_config.inl | 11 +---- .../source/xe_hp_core/enable_xe_hp_core.cpp | 1 + .../source/xe_hpc_core/enable_xe_hpc_core.cpp | 1 + ...os_agnostic_hw_info_config_xe_hpc_core.inl | 5 -- .../compiler_hw_info_config_dg2.inl | 12 ----- .../dg2/os_agnostic_hw_info_config_dg2.inl | 5 -- .../source/xe_hpg_core/enable_xe_hpg_core.cpp | 10 +++- .../dg2/test_hw_info_config_dg2.cpp | 8 ---- shared/test/unit_test/helpers/CMakeLists.txt | 1 + .../unit_test/helpers/cache_policy_tests.cpp | 46 +++++++++++++++++++ .../unit_test/helpers/test_hw_info_config.cpp | 27 ++++++++++- 26 files changed, 207 insertions(+), 52 deletions(-) create mode 100644 shared/source/helpers/cache_policy_bdw_and_later.inl create mode 100644 shared/source/helpers/cache_policy_dg2_and_later.inl delete mode 100644 shared/source/xe_hpg_core/compiler_hw_info_config_dg2.inl create mode 100644 shared/test/unit_test/helpers/cache_policy_tests.cpp diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 28a095fa18..6a630b8e31 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -2306,6 +2306,28 @@ HWTEST_F(ModuleTranslationUnitTest, givenInternalOptionsThenLSCCachePolicyIsSet) } } +HWTEST2_F(ModuleTranslationUnitTest, givenDebugFlagSetToWbWhenGetInternalOptionsThenCorrectBuildOptionIsSet, IsAtLeastXeHpgCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(2); + auto pMockCompilerInterface = new MockCompilerInterface; + auto &rootDeviceEnvironment = this->neoDevice->executionEnvironment->rootDeviceEnvironments[this->neoDevice->getRootDeviceIndex()]; + rootDeviceEnvironment->compilerInterface.reset(pMockCompilerInterface); + MockModuleTranslationUnit moduleTu(this->device); + auto ret = moduleTu.buildFromSpirV("", 0U, nullptr, "", nullptr); + EXPECT_TRUE(ret); + EXPECT_NE(pMockCompilerInterface->inputInternalOptions.find("-cl-store-cache-default=7 -cl-load-cache-default=4"), std::string::npos); +} + +HWTEST2_F(ModuleTranslationUnitTest, givenAtLeastDG2WhenGetInternalOptionsThenCorrectBuildOptionIsSet, IsAtLeastXeHpgCore) { + auto pMockCompilerInterface = new MockCompilerInterface; + auto &rootDeviceEnvironment = this->neoDevice->executionEnvironment->rootDeviceEnvironments[this->neoDevice->getRootDeviceIndex()]; + rootDeviceEnvironment->compilerInterface.reset(pMockCompilerInterface); + MockModuleTranslationUnit moduleTu(this->device); + auto ret = moduleTu.buildFromSpirV("", 0U, nullptr, "", nullptr); + EXPECT_TRUE(ret); + EXPECT_NE(pMockCompilerInterface->inputInternalOptions.find("-cl-store-cache-default=2 -cl-load-cache-default=4"), std::string::npos); +} + HWTEST_F(ModuleTranslationUnitTest, givenForceToStatelessRequiredWhenBuildingModuleThen4GbBuffersAreRequired) { auto mockCompilerInterface = new MockCompilerInterface; auto &rootDeviceEnvironment = neoDevice->executionEnvironment->rootDeviceEnvironments[neoDevice->getRootDeviceIndex()]; diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 479597616d..cbd704025f 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -1752,6 +1752,20 @@ TEST_F(ProgramTests, whenGetInternalOptionsThenLSCPolicyIsSet) { } } +HWTEST2_F(ProgramTests, givenDebugFlagSetToWbWhenGetInternalOptionsThenCorrectBuildOptionIsSet, IsAtLeastXeHpgCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(2); + MockProgram program(pContext, false, toClDeviceVector(*pClDevice)); + auto internalOptions = program.getInternalOptions(); + EXPECT_TRUE(CompilerOptions::contains(internalOptions, "-cl-store-cache-default=7 -cl-load-cache-default=4")); +} + +HWTEST2_F(ProgramTests, givenAtLeastDG2WhenGetInternalOptionsThenCorrectBuildOptionIsSet, IsAtLeastXeHpgCore) { + MockProgram program(pContext, false, toClDeviceVector(*pClDevice)); + auto internalOptions = program.getInternalOptions(); + EXPECT_TRUE(CompilerOptions::contains(internalOptions, "-cl-store-cache-default=2 -cl-load-cache-default=4")); +} + TEST_F(ProgramTests, WhenCreatingProgramThenBindlessIsEnabledOnlyIfDebugFlagIsEnabled) { using namespace testing; DebugManagerStateRestore restorer; diff --git a/shared/offline_compiler/source/CMakeLists.txt b/shared/offline_compiler/source/CMakeLists.txt index 36e1907cf8..03956965d4 100644 --- a/shared/offline_compiler/source/CMakeLists.txt +++ b/shared/offline_compiler/source/CMakeLists.txt @@ -38,6 +38,9 @@ set(CLOC_LIB_SRCS_LIB ${NEO_SHARED_DIRECTORY}/helpers/compiler_hw_info_config_bdw_and_later.inl ${NEO_SHARED_DIRECTORY}/helpers/compiler_options_parser.cpp ${NEO_SHARED_DIRECTORY}/helpers/compiler_options_parser.h + ${NEO_SHARED_DIRECTORY}/helpers/cache_policy.h + ${NEO_SHARED_DIRECTORY}/helpers/cache_policy_bdw_and_later.inl + ${NEO_SHARED_DIRECTORY}/helpers/cache_policy_dg2_and_later.inl ${NEO_SHARED_DIRECTORY}/helpers/debug_helpers.cpp ${NEO_SHARED_DIRECTORY}/helpers/file_io.cpp ${NEO_SHARED_DIRECTORY}/helpers/hw_info.cpp diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 3c40569862..0636120cc8 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -16,10 +16,10 @@ #include "shared/source/device/device.h" #include "shared/source/direct_submission/direct_submission_controller.h" #include "shared/source/execution_environment/root_device_environment.h" +#include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/gmm_helper/page_table_mngr.h" #include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/array_count.h" -#include "shared/source/helpers/cache_policy.h" #include "shared/source/helpers/flush_stamp.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/logical_state_helper.h" diff --git a/shared/source/gen11/enable_gen11.cpp b/shared/source/gen11/enable_gen11.cpp index 07c4f88b07..a64f7458bc 100644 --- a/shared/source/gen11/enable_gen11.cpp +++ b/shared/source/gen11/enable_gen11.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/gen11/hw_cmds.h" +#include "shared/source/helpers/cache_policy_bdw_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/gen12lp/enable_gen12lp.cpp b/shared/source/gen12lp/enable_gen12lp.cpp index 2417192801..ebde21b717 100644 --- a/shared/source/gen12lp/enable_gen12lp.cpp +++ b/shared/source/gen12lp/enable_gen12lp.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/gen12lp/hw_cmds.h" +#include "shared/source/helpers/cache_policy_bdw_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/gen8/enable_gen8.cpp b/shared/source/gen8/enable_gen8.cpp index 5c24bfa78a..555a611162 100644 --- a/shared/source/gen8/enable_gen8.cpp +++ b/shared/source/gen8/enable_gen8.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/gen8/hw_cmds.h" +#include "shared/source/helpers/cache_policy_bdw_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/gen9/enable_gen9.cpp b/shared/source/gen9/enable_gen9.cpp index ebfe3d0dff..d78ed807ab 100644 --- a/shared/source/gen9/enable_gen9.cpp +++ b/shared/source/gen9/enable_gen9.cpp @@ -6,6 +6,7 @@ */ #include "shared/source/gen9/hw_cmds.h" +#include "shared/source/helpers/cache_policy_bdw_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index d9e51a4b96..027c5b1de7 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -8,6 +8,10 @@ #pragma once #include "shared/source/gmm_helper/gmm_lib.h" +namespace CacheSettings { +constexpr uint32_t unknownMocs = GMM_RESOURCE_USAGE_UNKNOWN; +} // namespace CacheSettings + namespace NEO { enum class AllocationType; struct HardwareInfo; diff --git a/shared/source/helpers/CMakeLists.txt b/shared/source/helpers/CMakeLists.txt index 1fa413299f..913f7b6a18 100644 --- a/shared/source/helpers/CMakeLists.txt +++ b/shared/source/helpers/CMakeLists.txt @@ -29,6 +29,7 @@ set(NEO_CORE_HELPERS ${CMAKE_CURRENT_SOURCE_DIR}/cache_flush.inl ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy.h + ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy_bdw_and_later.inl ${CMAKE_CURRENT_SOURCE_DIR}/casts.h ${CMAKE_CURRENT_SOURCE_DIR}/common_types.h ${CMAKE_CURRENT_SOURCE_DIR}/compiler_hw_info_config.h @@ -152,6 +153,7 @@ endif() if(SUPPORT_DG2_AND_LATER) list(APPEND NEO_CORE_HELPERS ${CMAKE_CURRENT_SOURCE_DIR}/hw_helper_dg2_and_later.inl + ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy_dg2_and_later.inl ) endif() diff --git a/shared/source/helpers/cache_policy.h b/shared/source/helpers/cache_policy.h index b5b49d8446..3f613dfd23 100644 --- a/shared/source/helpers/cache_policy.h +++ b/shared/source/helpers/cache_policy.h @@ -1,19 +1,38 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once -#include "shared/source/gmm_helper/gmm_lib.h" +#include "shared/source/debug_settings/debug_settings_manager.h" -namespace CacheSettings { -constexpr uint32_t unknownMocs = GMM_RESOURCE_USAGE_UNKNOWN; -} // namespace CacheSettings +#include "igfxfmid.h" + +#include +#include namespace NEO { class GraphicsAllocation; bool isL3Capable(void *ptr, size_t size); bool isL3Capable(const GraphicsAllocation &graphicsAllocation); + +template +struct L1CachePolicyHelper { + + static const char *getCachingPolicyOptions(); + + static uint32_t getDefaultL1CachePolicy() { + return 0; + } + + static uint32_t getL1CachePolicy() { + if (DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.get() != -1) { + return DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.get(); + } + return L1CachePolicyHelper::getDefaultL1CachePolicy(); + } +}; + } // namespace NEO diff --git a/shared/source/helpers/cache_policy_bdw_and_later.inl b/shared/source/helpers/cache_policy_bdw_and_later.inl new file mode 100644 index 0000000000..a51cc498fa --- /dev/null +++ b/shared/source/helpers/cache_policy_bdw_and_later.inl @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/cache_policy.h" + +namespace NEO { + +template +const char *L1CachePolicyHelper::getCachingPolicyOptions() { + return nullptr; +} + +} // namespace NEO diff --git a/shared/source/helpers/cache_policy_dg2_and_later.inl b/shared/source/helpers/cache_policy_dg2_and_later.inl new file mode 100644 index 0000000000..f858daa4e3 --- /dev/null +++ b/shared/source/helpers/cache_policy_dg2_and_later.inl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/cache_policy.h" +#include "shared/source/helpers/hw_info.h" + +namespace NEO { + +template +const char *L1CachePolicyHelper::getCachingPolicyOptions() { + using GfxFamily = typename HwMapper::GfxFamily; + + static constexpr const char *writeBackCachingPolicy = "-cl-store-cache-default=7 -cl-load-cache-default=4"; + static constexpr const char *writeByPassCachingPolicy = "-cl-store-cache-default=2 -cl-load-cache-default=4"; + + switch (L1CachePolicyHelper::getL1CachePolicy()) { + case GfxFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP: + return writeByPassCachingPolicy; + case GfxFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WB: + return writeBackCachingPolicy; + default: + return nullptr; + } +} + +} // namespace NEO diff --git a/shared/source/helpers/compiler_hw_info_config_base.inl b/shared/source/helpers/compiler_hw_info_config_base.inl index a959557d20..6dcfe2fbc7 100644 --- a/shared/source/helpers/compiler_hw_info_config_base.inl +++ b/shared/source/helpers/compiler_hw_info_config_base.inl @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/helpers/cache_policy.h" #include "shared/source/helpers/compiler_hw_info_config.h" namespace NEO { @@ -26,7 +27,7 @@ void CompilerHwInfoConfigHw::adjustHwInfoForIgc(HardwareInfo &hwInfo template const char *CompilerHwInfoConfigHw::getCachingPolicyOptions() const { - return nullptr; + return L1CachePolicyHelper::getCachingPolicyOptions(); }; } // namespace NEO diff --git a/shared/source/os_interface/hw_info_config.h b/shared/source/os_interface/hw_info_config.h index 1fe50a3b1c..a585643ef9 100644 --- a/shared/source/os_interface/hw_info_config.h +++ b/shared/source/os_interface/hw_info_config.h @@ -119,7 +119,6 @@ class HwInfoConfig { virtual bool isCpuCopyNecessary(const void *ptr, MemoryManager *memoryManager) const = 0; virtual bool isAdjustWalkOrderAvailable(const HardwareInfo &hwInfo) const = 0; virtual bool isAssignEngineRoundRobinSupported() const = 0; - virtual uint32_t getDefaultL1CachePolicy() const = 0; virtual uint32_t getL1CachePolicy() const = 0; MOCKABLE_VIRTUAL ~HwInfoConfig() = default; @@ -218,7 +217,6 @@ class HwInfoConfigHw : public HwInfoConfig { bool isCpuCopyNecessary(const void *ptr, MemoryManager *memoryManager) const override; bool isAdjustWalkOrderAvailable(const HardwareInfo &hwInfo) const override; bool isAssignEngineRoundRobinSupported() const override; - uint32_t getDefaultL1CachePolicy() const override; uint32_t getL1CachePolicy() const override; protected: diff --git a/shared/source/os_interface/hw_info_config.inl b/shared/source/os_interface/hw_info_config.inl index 29ca0ce837..4313fa6c89 100644 --- a/shared/source/os_interface/hw_info_config.inl +++ b/shared/source/os_interface/hw_info_config.inl @@ -7,6 +7,7 @@ #include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/helpers/api_specific_config.h" +#include "shared/source/helpers/cache_policy.h" #include "shared/source/helpers/constants.h" #include "shared/source/helpers/driver_model_type.h" #include "shared/source/helpers/hw_helper.h" @@ -427,17 +428,9 @@ bool HwInfoConfigHw::isCpuCopyNecessary(const void *ptr, MemoryManag template bool HwInfoConfigHw::isAdjustWalkOrderAvailable(const HardwareInfo &hwInfo) const { return false; } -template -uint32_t HwInfoConfigHw::getDefaultL1CachePolicy() const { - return 0; -} - template uint32_t HwInfoConfigHw::getL1CachePolicy() const { - if (DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.get() != -1) { - return DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.get(); - } - return getDefaultL1CachePolicy(); + return L1CachePolicyHelper::getL1CachePolicy(); } } // namespace NEO diff --git a/shared/source/xe_hp_core/enable_xe_hp_core.cpp b/shared/source/xe_hp_core/enable_xe_hp_core.cpp index 2e55fda3fa..56294067d2 100644 --- a/shared/source/xe_hp_core/enable_xe_hp_core.cpp +++ b/shared/source/xe_hp_core/enable_xe_hp_core.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/helpers/cache_policy_bdw_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/xe_hpc_core/enable_xe_hpc_core.cpp b/shared/source/xe_hpc_core/enable_xe_hpc_core.cpp index c608579f17..5c91dd9d38 100644 --- a/shared/source/xe_hpc_core/enable_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/enable_xe_hpc_core.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/helpers/cache_policy_dg2_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" diff --git a/shared/source/xe_hpc_core/os_agnostic_hw_info_config_xe_hpc_core.inl b/shared/source/xe_hpc_core/os_agnostic_hw_info_config_xe_hpc_core.inl index 52b3021bc9..c0bc33ed75 100644 --- a/shared/source/xe_hpc_core/os_agnostic_hw_info_config_xe_hpc_core.inl +++ b/shared/source/xe_hpc_core/os_agnostic_hw_info_config_xe_hpc_core.inl @@ -53,8 +53,3 @@ void HwInfoConfigHw::getKernelExtendedProperties(uint32_t *fp16, uin *fp32 = (FP_ATOMIC_EXT_FLAG_GLOBAL_LOAD_STORE | FP_ATOMIC_EXT_FLAG_GLOBAL_ADD | FP_ATOMIC_EXT_FLAG_GLOBAL_MIN_MAX); *fp64 = (FP_ATOMIC_EXT_FLAG_GLOBAL_LOAD_STORE | FP_ATOMIC_EXT_FLAG_GLOBAL_ADD | FP_ATOMIC_EXT_FLAG_GLOBAL_MIN_MAX); } - -template <> -uint32_t HwInfoConfigHw::getDefaultL1CachePolicy() const { - return XE_HPC_COREFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP; -} \ No newline at end of file diff --git a/shared/source/xe_hpg_core/compiler_hw_info_config_dg2.inl b/shared/source/xe_hpg_core/compiler_hw_info_config_dg2.inl deleted file mode 100644 index d41fb8a774..0000000000 --- a/shared/source/xe_hpg_core/compiler_hw_info_config_dg2.inl +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) 2022 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -template <> -const char *CompilerHwInfoConfigHw::getCachingPolicyOptions() const { - static constexpr const char *cachingPolicy = "-cl-store-cache-default=7 -cl-load-cache-default=4"; - return cachingPolicy; -}; diff --git a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl index 7fbe136280..f2110e2574 100644 --- a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl +++ b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl @@ -210,8 +210,3 @@ bool HwInfoConfigHw::isStorageInfoAdjustmentRequired() const { return false; } } - -template <> -uint32_t HwInfoConfigHw::getDefaultL1CachePolicy() const { - return XE_HPG_COREFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP; -} diff --git a/shared/source/xe_hpg_core/enable_xe_hpg_core.cpp b/shared/source/xe_hpg_core/enable_xe_hpg_core.cpp index fb7358c767..8c02637122 100644 --- a/shared/source/xe_hpg_core/enable_xe_hpg_core.cpp +++ b/shared/source/xe_hpg_core/enable_xe_hpg_core.cpp @@ -5,6 +5,7 @@ * */ +#include "shared/source/helpers/cache_policy_dg2_and_later.inl" #include "shared/source/helpers/compiler_aot_config_bdw_and_later.inl" #include "shared/source/helpers/compiler_hw_info_config_base.inl" #include "shared/source/helpers/compiler_hw_info_config_bdw_and_later.inl" @@ -14,9 +15,14 @@ namespace NEO { #ifdef SUPPORT_DG2 -static EnableGfxProductHw enableGfxProductHwDG2; -#include "shared/source/xe_hpg_core/compiler_hw_info_config_dg2.inl" +template <> +uint32_t L1CachePolicyHelper::getDefaultL1CachePolicy() { + using GfxFamily = HwMapper::GfxFamily; + return GfxFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP; +} + +static EnableGfxProductHw enableGfxProductHwDG2; static EnableCompilerHwInfoConfig enableCompilerHwInfoConfigDG2; #endif } // namespace NEO diff --git a/shared/test/common/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp b/shared/test/common/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp index 9047161607..1091c6a65e 100644 --- a/shared/test/common/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp +++ b/shared/test/common/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp @@ -16,7 +16,6 @@ using TestDg2HwInfoConfig = Test; HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTestWindows, givenHardwareInfoWhenCallingIsAdditionalStateBaseAddressWARequiredThenFalseIsReturned, IGFX_DG2); HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTestWindows, givenHardwareInfoWhenCallingIsMaxThreadsForWorkgroupWARequiredThenFalseIsReturned, IGFX_DG2); -HWTEST_EXCLUDE_PRODUCT(HwInfoConfigTest, givenCompilerHwInfoConfigWhengetCachingPolicyOptionsThenReturnNullptr, IGFX_DG2); DG2TEST_F(TestDg2HwInfoConfig, givenDG2WithCSteppingThenAdditionalStateBaseAddressWAIsNotRequired) { const auto &hwInfoConfig = *HwInfoConfig::get(productFamily); @@ -69,10 +68,3 @@ DG2TEST_F(TestDg2HwInfoConfig, givenDG2HwInfoConfigWhenCheckDirectSubmissionSupp const auto &hwInfoConfig = *HwInfoConfig::get(hwInfo.platform.eProductFamily); EXPECT_TRUE(hwInfoConfig.isDirectSubmissionSupported(hwInfo)); } - -DG2TEST_F(TestDg2HwInfoConfig, givenDG2CompilerHwInfoConfigWhengetCachingPolicyOptionsThenReturnCorrectPolicies) { - auto hwInfo = *defaultHwInfo; - auto compilerHwInfoConfig = CompilerHwInfoConfig::get(hwInfo.platform.eProductFamily); - const char *expectedStr = "-cl-store-cache-default=7 -cl-load-cache-default=4"; - EXPECT_EQ(0, memcmp(compilerHwInfoConfig->getCachingPolicyOptions(), expectedStr, strlen(expectedStr))); -} diff --git a/shared/test/unit_test/helpers/CMakeLists.txt b/shared/test/unit_test/helpers/CMakeLists.txt index 176ed88883..cd81f52e77 100644 --- a/shared/test/unit_test/helpers/CMakeLists.txt +++ b/shared/test/unit_test/helpers/CMakeLists.txt @@ -29,6 +29,7 @@ set(SHARED_SRCS_tests_helpers ${CMAKE_CURRENT_SOURCE_DIR}/static_size3.h ${CMAKE_CURRENT_SOURCE_DIR}/test_debug_variables.inl ${CMAKE_CURRENT_SOURCE_DIR}/test_hw_info_config.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cache_policy_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/timestamp_packet_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ult_limits.h ) diff --git a/shared/test/unit_test/helpers/cache_policy_tests.cpp b/shared/test/unit_test/helpers/cache_policy_tests.cpp new file mode 100644 index 0000000000..3a5cd3ecf5 --- /dev/null +++ b/shared/test/unit_test/helpers/cache_policy_tests.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/helpers/cache_policy.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/test_macros/test.h" +#include "shared/test/unit_test/os_interface/hw_info_config_tests.h" + +using namespace NEO; + +HWTEST2_F(HwInfoConfigTest, givenL1CachePolicyHelperWhenUnsupportedL1PoliciesAndGetDefaultL1CachePolicyThenReturnZero, IsAtMostXeHpCore) { + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), 0u); +} + +HWTEST2_F(HwInfoConfigTest, givenAtLeastDG2WhenGetL1CachePolicyThenReturnCorrectValue, IsAtLeastXeHpgCore) { + using GfxFamily = typename HwMapper::GfxFamily; + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), GfxFamily::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP); +} + +HWTEST2_F(HwInfoConfigTest, givenAtLeastDG2AndWriteBackPolicyWhenGetL1CachePolicyThenReturnCorrectValue, IsAtLeastXeHpgCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(2); + + const char *expectedStr = "-cl-store-cache-default=7 -cl-load-cache-default=4"; + EXPECT_EQ(0, memcmp(L1CachePolicyHelper::getCachingPolicyOptions(), expectedStr, strlen(expectedStr))); +} + +HWTEST2_F(HwInfoConfigTest, givenL1CachePolicyHelperWhenDebugFlagSetAndGetL1CachePolicyThenReturnCorrectValue, MatchAny) { + DebugManagerStateRestore restorer; + + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(0); + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), 0u); + + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(2); + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), 2u); + + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(3); + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), 3u); + + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(4); + EXPECT_EQ(L1CachePolicyHelper::getL1CachePolicy(), 4u); +} diff --git a/shared/test/unit_test/helpers/test_hw_info_config.cpp b/shared/test/unit_test/helpers/test_hw_info_config.cpp index a85f3d26ce..369710b444 100644 --- a/shared/test/unit_test/helpers/test_hw_info_config.cpp +++ b/shared/test/unit_test/helpers/test_hw_info_config.cpp @@ -106,11 +106,34 @@ HWTEST_F(HwInfoConfigTest, givenHwInfoConfigWhenIsAdjustWalkOrderAvailableCallTh EXPECT_FALSE(hwInfoConfig.isAdjustWalkOrderAvailable(*defaultHwInfo)); } -HWTEST_F(HwInfoConfigTest, givenCompilerHwInfoConfigWhengetCachingPolicyOptionsThenReturnNullptr) { +HWTEST2_F(HwInfoConfigTest, givenAtMostXeHPWhenGetCachingPolicyOptionsThenReturnNullptr, IsAtMostXeHpCore) { auto compilerHwInfoConfig = CompilerHwInfoConfig::get(defaultHwInfo->platform.eProductFamily); EXPECT_EQ(compilerHwInfoConfig->getCachingPolicyOptions(), nullptr); } +HWTEST2_F(HwInfoConfigTest, givenAtLeastDG2WhenGetCachingPolicyOptionsThenReturnWriteByPassPolicyOption, IsAtLeastXeHpgCore) { + auto compilerHwInfoConfig = CompilerHwInfoConfig::get(defaultHwInfo->platform.eProductFamily); + const char *expectedStr = "-cl-store-cache-default=2 -cl-load-cache-default=4"; + EXPECT_EQ(0, memcmp(compilerHwInfoConfig->getCachingPolicyOptions(), expectedStr, strlen(expectedStr))); +} + +HWTEST2_F(HwInfoConfigTest, givenAtLeastDG2WhenGetCachingPolicyOptionsThenReturnWriteBackPolicyOption, IsAtLeastXeHpgCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(2); + + auto compilerHwInfoConfig = CompilerHwInfoConfig::get(defaultHwInfo->platform.eProductFamily); + const char *expectedStr = "-cl-store-cache-default=7 -cl-load-cache-default=4"; + EXPECT_EQ(0, memcmp(compilerHwInfoConfig->getCachingPolicyOptions(), expectedStr, strlen(expectedStr))); +} + +HWTEST2_F(HwInfoConfigTest, givenCachePolicyWithoutCorrespondingBuildOptionWhenGetCachingPolicyOptionsThenReturnNullptr, IsAtLeastXeHpgCore) { + DebugManagerStateRestore restorer; + DebugManager.flags.OverrideL1CachePolicyInSurfaceStateAndStateless.set(1); + + auto compilerHwInfoConfig = CompilerHwInfoConfig::get(defaultHwInfo->platform.eProductFamily); + EXPECT_EQ(nullptr, compilerHwInfoConfig->getCachingPolicyOptions()); +} + HWTEST2_F(HwInfoConfigTest, givenHwInfoConfigAndDebugFlagWhenGetL1CachePolicyThenReturnCorrectPolicy, IsAtLeastXeHpgCore) { DebugManagerStateRestore restorer; auto hwInfo = *defaultHwInfo; @@ -141,4 +164,4 @@ HWTEST2_F(HwInfoConfigTest, givenPlatformWithUnsupportedL1CachePoliciesWhenGetL1 auto hwInfoConfig = HwInfoConfig::get(hwInfo.platform.eProductFamily); EXPECT_EQ(0u, hwInfoConfig->getL1CachePolicy()); -} \ No newline at end of file +}