diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index e8f2a94947..1ce98bf56f 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -78,6 +78,9 @@ void DebuggerL0::initialize() { NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *moduleDebugArea), *device, moduleDebugArea, 0, &debugArea, sizeof(DebugAreaHeader)); + if (hwHelper.disableL3CacheForDebug()) { + device->getGmmHelper()->disableL3CacheForDebug(); + } } } diff --git a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp index 465e602c8a..7915e76807 100644 --- a/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp +++ b/level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp @@ -7,13 +7,13 @@ #include "shared/source/command_stream/linear_stream.h" #include "shared/source/gen_common/reg_configs_common.h" -#include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/blit_commands_helper.h" #include "shared/source/helpers/preamble.h" #include "shared/source/memory_manager/graphics_allocation.h" #include "shared/source/os_interface/os_context.h" #include "shared/test/common/cmd_parse/gen_cmd_parse.h" #include "shared/test/common/helpers/variable_backup.h" +#include "shared/test/common/mocks/mock_gmm_helper.h" #include "test.h" @@ -1634,5 +1634,14 @@ TEST(Debugger, givenNonLegacyDebuggerWhenInitializingDeviceCapsThenUnrecoverable EXPECT_THROW(NEO::MockDevice::create(executionEnvironment, 0u), std::exception); } +using NotATSOrDG2 = AreNotGfxCores; +HWTEST2_F(L0DebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, NotATSOrDG2) { + EXPECT_FALSE(static_cast(neoDevice->getGmmHelper())->l3CacheForDebugDisabled); +} + +using ATSOrDG2 = IsWithinGfxCore; +HWTEST2_F(L0DebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsSet, ATSOrDG2) { + EXPECT_TRUE(static_cast(neoDevice->getGmmHelper())->l3CacheForDebugDisabled); +} } // namespace ult } // namespace L0 diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 871c53fa55..184a6f17e8 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -865,6 +865,34 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceT EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType); } +TEST(GmmHelperTest, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsReturned) { + decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc; + GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create; + + std::unique_ptr gmmHelper; + auto hwInfo = defaultHwInfo.get(); + gmmHelper.reset(new GmmHelper(nullptr, hwInfo)); + + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); + EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); + EXPECT_EQ(4u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE)); + EXPECT_EQ(4u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE_FROM_BUFFER)); + EXPECT_EQ(8u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST)); + EXPECT_EQ(16u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); + EXPECT_EQ(32u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC)); + + gmmHelper->disableL3CacheForDebug(); + + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE_FROM_BUFFER)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); + EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC)); + GmmHelper::createGmmContextWrapperFunc = createGmmContextSave; +} + struct GmmCompressionTests : public MockExecutionEnvironmentGmmFixtureTest { void SetUp() override { MockExecutionEnvironmentGmmFixtureTest::SetUp(); diff --git a/opencl/test/unit_test/helpers/hw_helper_tests.cpp b/opencl/test/unit_test/helpers/hw_helper_tests.cpp index 97c858ab0e..0574d75617 100644 --- a/opencl/test/unit_test/helpers/hw_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hw_helper_tests.cpp @@ -1397,3 +1397,15 @@ TEST(HwHelperTests, whenBlitterSupportIsDisabledThenDontExposeAnyBcsEngine) { EXPECT_FALSE(EngineHelpers::isBcs(engineUsageType.first)); } } + +using NotATSOrDG2 = AreNotGfxCores; +HWTEST2_F(HwHelperTest, givenNotAtsOrDg2WhenDisableL3ForDebugCalledThenFalseIsReturned, NotATSOrDG2) { + const auto &hwHelper = HwHelper::get(renderCoreFamily); + EXPECT_FALSE(hwHelper.disableL3CacheForDebug()); +} + +using ATSOrDG2 = IsWithinGfxCore; +HWTEST2_F(HwHelperTest, givenAtsOrDg2WhenDisableL3ForDebugCalledThenTrueIsReturned, ATSOrDG2) { + const auto &hwHelper = HwHelper::get(renderCoreFamily); + EXPECT_TRUE(hwHelper.disableL3CacheForDebug()); +} diff --git a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp index 7578a83426..3837427960 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp @@ -15,6 +15,7 @@ #include "shared/test/common/mocks/linux/mock_drm_allocation.h" #include "shared/test/common/mocks/mock_device.h" #include "shared/test/common/mocks/mock_execution_environment.h" +#include "shared/test/common/mocks/mock_gmm_helper.h" #include "shared/test/common/os_interface/linux/device_command_stream_fixture.h" #include "test.h" @@ -501,10 +502,6 @@ TEST_F(DrmBufferObjectTest, givenAsyncDebugFlagWhenFillingExecObjectThenFlagIsSe EXPECT_TRUE(execObject.flags & EXEC_OBJECT_ASYNC); } -struct MockGmmHelper : GmmHelper { - using GmmHelper::addressWidth; -}; - TEST_F(DrmBufferObjectTest, given47bitAddressWhenSetThenIsAddressNotCanonized) { VariableBackup backup(&MockGmmHelper::addressWidth, 48); diff --git a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp index 356e46be66..2740f7fb2e 100644 --- a/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp +++ b/opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp @@ -15,14 +15,14 @@ #include "shared/test/common/helpers/ult_hw_config.h" #include "shared/test/common/helpers/variable_backup.h" #include "shared/test/common/libult/source_level_debugger_library.h" +#include "shared/test/common/mocks/mock_gmm_helper.h" #include "shared/test/common/mocks/mock_source_level_debugger.h" #include "opencl/source/platform/platform.h" #include "opencl/test/unit_test/helpers/execution_environment_helper.h" #include "opencl/test/unit_test/mocks/mock_cl_device.h" #include "opencl/test/unit_test/mocks/mock_platform.h" - -#include +#include "test.h" #include #include @@ -700,7 +700,6 @@ TEST(SourceLevelDebugger, givenEnableMockSourceLevelDebuggerWhenInitializingExec DebuggerLibrary::setLibraryAvailable(false); DebugManager.flags.EnableMockSourceLevelDebugger.set(1); - auto executionEnvironment = new ExecutionEnvironment(); MockPlatform platform(*executionEnvironment); platform.initializeWithNewDevices(); @@ -856,4 +855,28 @@ TEST(SourceLevelDebugger, givenDebuggerLibraryAvailableAndExperimentalEnableSour auto debugger = std::unique_ptr(Debugger::create(&hwInfo)); ASSERT_NE(nullptr, debugger.get()); EXPECT_TRUE(debugger->isLegacy()); -} \ No newline at end of file +} + +using LegacyDebuggerTest = ::testing::Test; + +using NotATSOrDG2 = AreNotGfxCores; +HWTEST2_F(LegacyDebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, NotATSOrDG2) { + DebugManagerStateRestore stateRestore; + DebugManager.flags.EnableMockSourceLevelDebugger.set(1); + auto executionEnvironment = new ExecutionEnvironment(); + MockPlatform platform(*executionEnvironment); + platform.initializeWithNewDevices(); + + EXPECT_FALSE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled); +} + +using ATSOrDG2 = IsWithinGfxCore; +HWTEST2_F(LegacyDebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsSet, ATSOrDG2) { + DebugManagerStateRestore stateRestore; + DebugManager.flags.EnableMockSourceLevelDebugger.set(1); + auto executionEnvironment = new ExecutionEnvironment(); + MockPlatform platform(*executionEnvironment); + platform.initializeWithNewDevices(); + + EXPECT_TRUE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled); +} diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 30a4eadd06..635f799243 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -222,6 +222,11 @@ bool Device::createDeviceImpl() { this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger(); } + auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); + if (getDebugger() && hwHelper.disableL3CacheForDebug()) { + getGmmHelper()->disableL3CacheForDebug(); + } + if (!createEngines()) { return false; } diff --git a/shared/source/gmm_helper/gmm_helper.cpp b/shared/source/gmm_helper/gmm_helper.cpp index 104e56ac6d..9dadae98c1 100644 --- a/shared/source/gmm_helper/gmm_helper.cpp +++ b/shared/source/gmm_helper/gmm_helper.cpp @@ -30,6 +30,10 @@ const HardwareInfo *GmmHelper::getHardwareInfo() { } uint32_t GmmHelper::getMOCS(uint32_t type) const { + if (l3CacheForDebugDisabled) { + type = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + } + MEMORY_OBJECT_CONTROL_STATE mocs = gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast(type)); return static_cast(mocs.DwordValue); diff --git a/shared/source/gmm_helper/gmm_helper.h b/shared/source/gmm_helper/gmm_helper.h index 5abaae2fef..b4c5b4b42b 100644 --- a/shared/source/gmm_helper/gmm_helper.h +++ b/shared/source/gmm_helper/gmm_helper.h @@ -23,6 +23,7 @@ class GmmHelper { const HardwareInfo *getHardwareInfo(); uint32_t getMOCS(uint32_t type) const; + void disableL3CacheForDebug() { l3CacheForDebugDisabled = true; }; static constexpr uint64_t maxPossiblePitch = (1ull << 31); @@ -42,5 +43,6 @@ class GmmHelper { static uint32_t addressWidth; const HardwareInfo *hwInfo = nullptr; std::unique_ptr gmmClientContext; + bool l3CacheForDebugDisabled = false; }; } // namespace NEO diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index dd4e7a2650..39c85471e8 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -150,6 +150,7 @@ class HwHelper { virtual uint64_t getMaxMemAllocSize() const = 0; virtual bool isStatelesToStatefullWithOffsetSupported() const = 0; virtual void encodeBufferSurfaceState(EncodeSurfaceStateArgs &args) = 0; + virtual bool disableL3CacheForDebug() const = 0; protected: HwHelper() = default; @@ -381,6 +382,7 @@ class HwHelperHw : public HwHelper { uint64_t getMaxMemAllocSize() const override; bool isStatelesToStatefullWithOffsetSupported() const override; void encodeBufferSurfaceState(EncodeSurfaceStateArgs &args) override; + bool disableL3CacheForDebug() const override; protected: static const AuxTranslationMode defaultAuxTranslationMode; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 62434f74ae..bea9ed80ee 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -700,4 +700,8 @@ void HwHelperHw::encodeBufferSurfaceState(EncodeSurfaceStateArgs &arg EncodeSurfaceState::encodeBuffer(args); } +template +bool HwHelperHw::disableL3CacheForDebug() const { + return false; +} } // namespace NEO diff --git a/shared/source/xe_hp_core/hw_helper_xe_hp_core.cpp b/shared/source/xe_hp_core/hw_helper_xe_hp_core.cpp index e4ac8d0fb1..e9687e2ecc 100644 --- a/shared/source/xe_hp_core/hw_helper_xe_hp_core.cpp +++ b/shared/source/xe_hp_core/hw_helper_xe_hp_core.cpp @@ -154,6 +154,11 @@ uint32_t HwHelperHw::getDefaultRevisionId(const HardwareInfo &hwInfo) co return HwInfoConfig::get(hwInfo.platform.eProductFamily)->getHwRevIdFromStepping(REVISION_B, hwInfo); } +template <> +bool HwHelperHw::disableL3CacheForDebug() const { + return true; +} + template class HwHelperHw; template class FlatBatchBufferHelperHw; template struct MemorySynchronizationCommands; diff --git a/shared/source/xe_hpg_core/hw_helper_xe_hpg_core.cpp b/shared/source/xe_hpg_core/hw_helper_xe_hpg_core.cpp index f92cff4dee..4308adbe18 100644 --- a/shared/source/xe_hpg_core/hw_helper_xe_hpg_core.cpp +++ b/shared/source/xe_hpg_core/hw_helper_xe_hpg_core.cpp @@ -113,6 +113,11 @@ uint32_t HwHelperHw::computeSlmValues(const HardwareInfo &hwInfo, uint32 return slmValue; } +template <> +bool HwHelperHw::disableL3CacheForDebug() const { + return true; +} + template class HwHelperHw; template class FlatBatchBufferHelperHw; template struct MemorySynchronizationCommands; diff --git a/shared/test/common/mocks/mock_gmm_helper.h b/shared/test/common/mocks/mock_gmm_helper.h new file mode 100644 index 0000000000..08062fea9d --- /dev/null +++ b/shared/test/common/mocks/mock_gmm_helper.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include "shared/source/gmm_helper/gmm_helper.h" + +namespace NEO { +struct MockGmmHelper : GmmHelper { + using GmmHelper::addressWidth; + using GmmHelper::l3CacheForDebugDisabled; +}; +} // namespace NEO