From 7fa9cfd7fce1bccd8d7a25539e89b61224c70ff3 Mon Sep 17 00:00:00 2001 From: Dominik Dabek Date: Fri, 2 Sep 2022 16:54:57 +0000 Subject: [PATCH] Add missing cache policy isDebuggerActive values Cache policy was not kept as WBP in some cases with debugger Related-To: NEO-7003 Signed-off-by: Dominik Dabek --- .../cmdlist/cmdlist_hw_xehp_and_later.inl | 1 + level_zero/core/source/module/module_imp.cpp | 2 +- .../sources/debugger/test_l0_debugger_1.cpp | 29 +++++++++++++++++++ .../common/helpers/mock_hw_info_config_hw.h | 3 ++ .../common/helpers/mock_hw_info_config_hw.inl | 8 +++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl index 0f2470af65..92f7839b04 100644 --- a/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl +++ b/level_zero/core/source/cmdlist/cmdlist_hw_xehp_and_later.inl @@ -282,6 +282,7 @@ ze_result_t CommandListCoreFamily::appendLaunchKernelWithParams(K args.useGlobalAtomics = kernelImp->getKernelDescriptor().kernelAttributes.flags.useGlobalAtomics; args.areMultipleSubDevicesInContext = args.numAvailableDevices > 1; args.implicitScaling = this->partitionCount > 1; + args.isDebuggerActive = true; NEO::EncodeSurfaceState::encodeBuffer(args); *reinterpret_cast(surfaceStateSpace) = surfaceState; diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 353ebdd8f3..2bf3fd521e 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -139,7 +139,7 @@ std::string ModuleTranslationUnit::generateCompilerOptions(const char *buildOpti if (forceToStatelessRequired || statelessToStatefulOptimizationDisabled) { internalOptions = NEO::CompilerOptions::concatenate(internalOptions, NEO::CompilerOptions::greaterThan4gbBuffersRequired); } - + isDebuggerActive |= neoDevice.getDebugger() != nullptr; NEO::CompilerOptions::concatenateAppend(internalOptions, compilerHwInfoConfig.getCachingPolicyOptions(isDebuggerActive)); return internalOptions; } diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp index f700fc9469..33f0685d58 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger_1.cpp @@ -8,6 +8,7 @@ #include "shared/source/gen_common/reg_configs_common.h" #include "shared/source/helpers/preamble.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" +#include "shared/test/common/helpers/mock_hw_info_config_hw.h" #include "shared/test/common/mocks/mock_gmm_helper.h" #include "shared/test/common/test_macros/hw_test.h" @@ -530,6 +531,34 @@ HWTEST2_F(L0DebuggerSimpleTest, givenUseCsrImmediateSubmissionDisabledCommandLis commandList->destroy(); } +HWTEST2_F(L0DebuggerTest, givenDebuggerEnabledAndL1CachePolicyWBWhenAppendingThenDebugSurfaceHasCachePolicyWBP, IsAtLeastXeHpgCore) { + using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE; + + MockHwInfoConfigHw hwInfoConfig; + VariableBackup hwInfoConfigFactoryBackup{&NEO::hwInfoConfigFactory[static_cast(hwInfo.platform.eProductFamily)]}; + hwInfoConfigFactoryBackup = &hwInfoConfig; + hwInfoConfig.returnedL1CachePolicy = RENDER_SURFACE_STATE::L1_CACHE_POLICY_WB; + hwInfoConfig.returnedL1CachePolicyIfDebugger = RENDER_SURFACE_STATE::L1_CACHE_POLICY_WBP; + + Mock<::L0::Kernel> kernel; + ze_result_t returnValue; + std::unique_ptr commandList(L0::CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, 0u, returnValue)); + ze_group_count_t groupCount{1, 1, 1}; + CmdListKernelLaunchParams launchParams = {}; + returnValue = commandList->appendLaunchKernel(kernel.toHandle(), &groupCount, nullptr, 0, nullptr, launchParams); + ASSERT_EQ(ZE_RESULT_SUCCESS, returnValue); + commandList->close(); + + auto *ssh = commandList->commandContainer.getIndirectHeap(NEO::HeapType::SURFACE_STATE); + ASSERT_NE(ssh, nullptr); + auto debugSurfaceState = reinterpret_cast(ssh->getCpuBase()); + ASSERT_NE(debugSurfaceState, nullptr); + auto debugSurface = static_cast(device)->getDebugSurface(); + ASSERT_NE(debugSurface, nullptr); + ASSERT_EQ(debugSurface->getGpuAddress(), debugSurfaceState->getSurfaceBaseAddress()); + EXPECT_EQ(debugSurfaceState->getL1CachePolicyL1CacheControl(), RENDER_SURFACE_STATE::L1_CACHE_POLICY_WBP); +} + HWTEST2_F(L0DebuggerTest, givenNotXeHpOrXeHpgCoreAndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, IsNotXeHpOrXeHpgCore) { EXPECT_FALSE(static_cast(neoDevice->getGmmHelper())->allResourcesUncached); } diff --git a/shared/test/common/helpers/mock_hw_info_config_hw.h b/shared/test/common/helpers/mock_hw_info_config_hw.h index 69c4f2c8bf..062dca6a5f 100644 --- a/shared/test/common/helpers/mock_hw_info_config_hw.h +++ b/shared/test/common/helpers/mock_hw_info_config_hw.h @@ -20,6 +20,7 @@ struct MockHwInfoConfigHw : NEO::HwInfoConfigHw { int configureHardwareCustom(HardwareInfo *hwInfo, OSInterface *osIface) override; uint64_t getDeviceMemoryPhysicalSizeInBytes(const OSInterface *osIface, uint32_t subDeviceIndex) override; uint32_t getDeviceMemoryMaxClkRate(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) override; + uint32_t getL1CachePolicy(bool isDebuggerActive) const override; bool use128MbEdram = false; bool enableMidThreadPreemption = false; @@ -28,6 +29,8 @@ struct MockHwInfoConfigHw : NEO::HwInfoConfigHw { bool failOnConfigureHardwareCustom = false; bool isCooperativeEngineSupportedValue = true; uint32_t returnedStepping = 0; + uint32_t returnedL1CachePolicy = 0; + uint32_t returnedL1CachePolicyIfDebugger = 0; std::vector threadArbPolicies = {}; }; } // namespace NEO \ No newline at end of file diff --git a/shared/test/common/helpers/mock_hw_info_config_hw.inl b/shared/test/common/helpers/mock_hw_info_config_hw.inl index f8e100f959..0f3c3cf3c4 100644 --- a/shared/test/common/helpers/mock_hw_info_config_hw.inl +++ b/shared/test/common/helpers/mock_hw_info_config_hw.inl @@ -56,3 +56,11 @@ template <> uint32_t MockHwInfoConfigHw::getDeviceMemoryMaxClkRate(const HardwareInfo &hwInfo, const OSInterface *osIface, uint32_t subDeviceIndex) { return 800u; } + +template <> +uint32_t MockHwInfoConfigHw::getL1CachePolicy(bool isDebuggerActive) const { + if (isDebuggerActive) { + return this->returnedL1CachePolicyIfDebugger; + } + return this->returnedL1CachePolicy; +} \ No newline at end of file