Skip to content

Commit fe250d9

Browse files
Disable L3 caches for debug on ATS and DG2
Resolves: NEO-6320 Signed-off-by: Igor Venevtsev <[email protected]>
1 parent 21f6e7e commit fe250d9

File tree

14 files changed

+124
-9
lines changed

14 files changed

+124
-9
lines changed

level_zero/core/source/debugger/debugger_l0.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ void DebuggerL0::initialize() {
7878
NEO::MemoryTransferHelper::transferMemoryToAllocation(hwHelper.isBlitCopyRequiredForLocalMemory(hwInfo, *moduleDebugArea),
7979
*device, moduleDebugArea, 0, &debugArea,
8080
sizeof(DebugAreaHeader));
81+
if (hwHelper.disableL3CacheForDebug()) {
82+
device->getGmmHelper()->disableL3CacheForDebug();
83+
}
8184
}
8285
}
8386

level_zero/core/test/unit_tests/sources/debugger/test_l0_debugger.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
#include "shared/source/command_stream/linear_stream.h"
99
#include "shared/source/gen_common/reg_configs_common.h"
10-
#include "shared/source/gmm_helper/gmm_helper.h"
1110
#include "shared/source/helpers/blit_commands_helper.h"
1211
#include "shared/source/helpers/preamble.h"
1312
#include "shared/source/memory_manager/graphics_allocation.h"
1413
#include "shared/source/os_interface/os_context.h"
1514
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
1615
#include "shared/test/common/helpers/variable_backup.h"
16+
#include "shared/test/common/mocks/mock_gmm_helper.h"
1717

1818
#include "test.h"
1919

@@ -1634,5 +1634,14 @@ TEST(Debugger, givenNonLegacyDebuggerWhenInitializingDeviceCapsThenUnrecoverable
16341634
EXPECT_THROW(NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, 0u), std::exception);
16351635
}
16361636

1637+
using NotATSOrDG2 = AreNotGfxCores<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
1638+
HWTEST2_F(L0DebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, NotATSOrDG2) {
1639+
EXPECT_FALSE(static_cast<MockGmmHelper *>(neoDevice->getGmmHelper())->l3CacheForDebugDisabled);
1640+
}
1641+
1642+
using ATSOrDG2 = IsWithinGfxCore<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
1643+
HWTEST2_F(L0DebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsSet, ATSOrDG2) {
1644+
EXPECT_TRUE(static_cast<MockGmmHelper *>(neoDevice->getGmmHelper())->l3CacheForDebugDisabled);
1645+
}
16371646
} // namespace ult
16381647
} // namespace L0

opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,34 @@ TEST(GmmHelperTest, givenValidGmmFunctionsWhenCreateGmmHelperWithoutOsInterfaceT
865865
EXPECT_EQ(GMM_CLIENT::GMM_OCL_VISTA, passedInputArgs.ClientType);
866866
}
867867

868+
TEST(GmmHelperTest, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsReturned) {
869+
decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc;
870+
GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<MockGmmClientContext>;
871+
872+
std::unique_ptr<GmmHelper> gmmHelper;
873+
auto hwInfo = defaultHwInfo.get();
874+
gmmHelper.reset(new GmmHelper(nullptr, hwInfo));
875+
876+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
877+
EXPECT_EQ(2u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));
878+
EXPECT_EQ(4u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE));
879+
EXPECT_EQ(4u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE_FROM_BUFFER));
880+
EXPECT_EQ(8u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST));
881+
EXPECT_EQ(16u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER));
882+
EXPECT_EQ(32u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC));
883+
884+
gmmHelper->disableL3CacheForDebug();
885+
886+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
887+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));
888+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE));
889+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_IMAGE_FROM_BUFFER));
890+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST));
891+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER));
892+
EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC));
893+
GmmHelper::createGmmContextWrapperFunc = createGmmContextSave;
894+
}
895+
868896
struct GmmCompressionTests : public MockExecutionEnvironmentGmmFixtureTest {
869897
void SetUp() override {
870898
MockExecutionEnvironmentGmmFixtureTest::SetUp();

opencl/test/unit_test/helpers/hw_helper_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,3 +1397,15 @@ TEST(HwHelperTests, whenBlitterSupportIsDisabledThenDontExposeAnyBcsEngine) {
13971397
EXPECT_FALSE(EngineHelpers::isBcs(engineUsageType.first));
13981398
}
13991399
}
1400+
1401+
using NotATSOrDG2 = AreNotGfxCores<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
1402+
HWTEST2_F(HwHelperTest, givenNotAtsOrDg2WhenDisableL3ForDebugCalledThenFalseIsReturned, NotATSOrDG2) {
1403+
const auto &hwHelper = HwHelper::get(renderCoreFamily);
1404+
EXPECT_FALSE(hwHelper.disableL3CacheForDebug());
1405+
}
1406+
1407+
using ATSOrDG2 = IsWithinGfxCore<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
1408+
HWTEST2_F(HwHelperTest, givenAtsOrDg2WhenDisableL3ForDebugCalledThenTrueIsReturned, ATSOrDG2) {
1409+
const auto &hwHelper = HwHelper::get(renderCoreFamily);
1410+
EXPECT_TRUE(hwHelper.disableL3CacheForDebug());
1411+
}

opencl/test/unit_test/os_interface/linux/drm_buffer_object_tests.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "shared/test/common/mocks/linux/mock_drm_allocation.h"
1616
#include "shared/test/common/mocks/mock_device.h"
1717
#include "shared/test/common/mocks/mock_execution_environment.h"
18+
#include "shared/test/common/mocks/mock_gmm_helper.h"
1819
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
1920

2021
#include "test.h"
@@ -501,10 +502,6 @@ TEST_F(DrmBufferObjectTest, givenAsyncDebugFlagWhenFillingExecObjectThenFlagIsSe
501502
EXPECT_TRUE(execObject.flags & EXEC_OBJECT_ASYNC);
502503
}
503504

504-
struct MockGmmHelper : GmmHelper {
505-
using GmmHelper::addressWidth;
506-
};
507-
508505
TEST_F(DrmBufferObjectTest, given47bitAddressWhenSetThenIsAddressNotCanonized) {
509506
VariableBackup<uint32_t> backup(&MockGmmHelper::addressWidth, 48);
510507

opencl/test/unit_test/source_level_debugger/source_level_debugger_tests.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
#include "shared/test/common/helpers/ult_hw_config.h"
1616
#include "shared/test/common/helpers/variable_backup.h"
1717
#include "shared/test/common/libult/source_level_debugger_library.h"
18+
#include "shared/test/common/mocks/mock_gmm_helper.h"
1819
#include "shared/test/common/mocks/mock_source_level_debugger.h"
1920

2021
#include "opencl/source/platform/platform.h"
2122
#include "opencl/test/unit_test/helpers/execution_environment_helper.h"
2223
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
2324
#include "opencl/test/unit_test/mocks/mock_platform.h"
24-
25-
#include <gtest/gtest.h>
25+
#include "test.h"
2626

2727
#include <memory>
2828
#include <string>
@@ -700,7 +700,6 @@ TEST(SourceLevelDebugger, givenEnableMockSourceLevelDebuggerWhenInitializingExec
700700
DebuggerLibrary::setLibraryAvailable(false);
701701

702702
DebugManager.flags.EnableMockSourceLevelDebugger.set(1);
703-
704703
auto executionEnvironment = new ExecutionEnvironment();
705704
MockPlatform platform(*executionEnvironment);
706705
platform.initializeWithNewDevices();
@@ -856,4 +855,28 @@ TEST(SourceLevelDebugger, givenDebuggerLibraryAvailableAndExperimentalEnableSour
856855
auto debugger = std::unique_ptr<Debugger>(Debugger::create(&hwInfo));
857856
ASSERT_NE(nullptr, debugger.get());
858857
EXPECT_TRUE(debugger->isLegacy());
859-
}
858+
}
859+
860+
using LegacyDebuggerTest = ::testing::Test;
861+
862+
using NotATSOrDG2 = AreNotGfxCores<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
863+
HWTEST2_F(LegacyDebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, NotATSOrDG2) {
864+
DebugManagerStateRestore stateRestore;
865+
DebugManager.flags.EnableMockSourceLevelDebugger.set(1);
866+
auto executionEnvironment = new ExecutionEnvironment();
867+
MockPlatform platform(*executionEnvironment);
868+
platform.initializeWithNewDevices();
869+
870+
EXPECT_FALSE(static_cast<MockGmmHelper *>(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled);
871+
}
872+
873+
using ATSOrDG2 = IsWithinGfxCore<IGFX_XE_HP_CORE, IGFX_XE_HPG_CORE>;
874+
HWTEST2_F(LegacyDebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsSet, ATSOrDG2) {
875+
DebugManagerStateRestore stateRestore;
876+
DebugManager.flags.EnableMockSourceLevelDebugger.set(1);
877+
auto executionEnvironment = new ExecutionEnvironment();
878+
MockPlatform platform(*executionEnvironment);
879+
platform.initializeWithNewDevices();
880+
881+
EXPECT_TRUE(static_cast<MockGmmHelper *>(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled);
882+
}

shared/source/device/device.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ bool Device::createDeviceImpl() {
222222
this->executionEnvironment->rootDeviceEnvironments[getRootDeviceIndex()]->initDebugger();
223223
}
224224

225+
auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily);
226+
if (getDebugger() && hwHelper.disableL3CacheForDebug()) {
227+
getGmmHelper()->disableL3CacheForDebug();
228+
}
229+
225230
if (!createEngines()) {
226231
return false;
227232
}

shared/source/gmm_helper/gmm_helper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const HardwareInfo *GmmHelper::getHardwareInfo() {
3030
}
3131

3232
uint32_t GmmHelper::getMOCS(uint32_t type) const {
33+
if (l3CacheForDebugDisabled) {
34+
type = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
35+
}
36+
3337
MEMORY_OBJECT_CONTROL_STATE mocs = gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
3438

3539
return static_cast<uint32_t>(mocs.DwordValue);

shared/source/gmm_helper/gmm_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class GmmHelper {
2323

2424
const HardwareInfo *getHardwareInfo();
2525
uint32_t getMOCS(uint32_t type) const;
26+
void disableL3CacheForDebug() { l3CacheForDebugDisabled = true; };
2627

2728
static constexpr uint64_t maxPossiblePitch = (1ull << 31);
2829

@@ -42,5 +43,6 @@ class GmmHelper {
4243
static uint32_t addressWidth;
4344
const HardwareInfo *hwInfo = nullptr;
4445
std::unique_ptr<GmmClientContext> gmmClientContext;
46+
bool l3CacheForDebugDisabled = false;
4547
};
4648
} // namespace NEO

shared/source/helpers/hw_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class HwHelper {
150150
virtual uint64_t getMaxMemAllocSize() const = 0;
151151
virtual bool isStatelesToStatefullWithOffsetSupported() const = 0;
152152
virtual void encodeBufferSurfaceState(EncodeSurfaceStateArgs &args) = 0;
153+
virtual bool disableL3CacheForDebug() const = 0;
153154

154155
protected:
155156
HwHelper() = default;
@@ -381,6 +382,7 @@ class HwHelperHw : public HwHelper {
381382
uint64_t getMaxMemAllocSize() const override;
382383
bool isStatelesToStatefullWithOffsetSupported() const override;
383384
void encodeBufferSurfaceState(EncodeSurfaceStateArgs &args) override;
385+
bool disableL3CacheForDebug() const override;
384386

385387
protected:
386388
static const AuxTranslationMode defaultAuxTranslationMode;

0 commit comments

Comments
 (0)