diff --git a/level_zero/core/source/debugger/debugger_l0.cpp b/level_zero/core/source/debugger/debugger_l0.cpp index 82038a9718..ae98d0cf2f 100644 --- a/level_zero/core/source/debugger/debugger_l0.cpp +++ b/level_zero/core/source/debugger/debugger_l0.cpp @@ -79,7 +79,7 @@ void DebuggerL0::initialize() { *device, moduleDebugArea, 0, &debugArea, sizeof(DebugAreaHeader)); if (hwHelper.disableL3CacheForDebug(hwInfo)) { - device->getGmmHelper()->disableL3CacheForDebug(); + device->getGmmHelper()->forceAllResourcesUncached(); } } } 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 671b3ebf3f..f3c76cdad8 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 @@ -1178,12 +1178,12 @@ TEST(Debugger, givenNonLegacyDebuggerWhenInitializingDeviceCapsThenUnrecoverable using NotATSOrDG2 = AreNotGfxCores; HWTEST2_F(L0DebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsNotSet, NotATSOrDG2) { - EXPECT_FALSE(static_cast(neoDevice->getGmmHelper())->l3CacheForDebugDisabled); + EXPECT_FALSE(static_cast(neoDevice->getGmmHelper())->allResourcesUncached); } using ATSOrDG2 = IsWithinGfxCore; HWTEST2_F(L0DebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInGmmHelperIsSet, ATSOrDG2) { - EXPECT_TRUE(static_cast(neoDevice->getGmmHelper())->l3CacheForDebugDisabled); + EXPECT_TRUE(static_cast(neoDevice->getGmmHelper())->allResourcesUncached); } } // 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 55394c27ae..232fa510f8 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -912,6 +912,25 @@ TEST(GmmTest, givenAllocationForStatefulAccessWhenDebugFlagIsSetThenReturnUncach } } +TEST_F(GmmTests, whenGmmIsCreatedAndForceAllResourcesUncachedIsSetThenResourceUsageIsSetToUncachedSurface) { + DebugManagerStateRestore restorer; + DebugManager.flags.ForceAllResourcesUncached = true; + + auto size = 4096u; + void *incomingPtr = (void *)0x1000; + auto gmm1 = std::make_unique(getGmmClientContext(), incomingPtr, size, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, false, StorageInfo{}, true); + EXPECT_EQ(GMM_RESOURCE_USAGE_SURFACE_UNCACHED, gmm1->resourceParams.Usage); + + ImageDescriptor imgDesc = {}; + imgDesc.imageType = ImageType::Image1D; + auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); + auto gmm2 = MockGmm::queryImgParams(getGmmClientContext(), imgInfo, false); + EXPECT_EQ(GMM_RESOURCE_USAGE_SURFACE_UNCACHED, gmm2->resourceParams.Usage); + + auto gmm3 = std::make_unique(getGmmClientContext(), gmm1->gmmResourceInfo->peekGmmResourceInfo()); + EXPECT_EQ(GMM_RESOURCE_USAGE_SURFACE_UNCACHED, gmm3->resourceParams.Usage); +} + TEST_F(GmmTests, whenResourceIsCreatedThenHandleItsOwnership) { struct MyMockResourecInfo : public GmmResourceInfo { using GmmResourceInfo::resourceInfo; @@ -1022,7 +1041,36 @@ TEST(GmmHelperTest, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsRet EXPECT_EQ(16u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER)); EXPECT_EQ(32u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC)); - gmmHelper->disableL3CacheForDebug(); + gmmHelper->forceAllResourcesUncached(); + + 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; +} + +TEST(GmmHelperTest, givenGmmHelperAndForceAllResourcesUncachedDebugVariableSetThenCorrectMOCSIsReturned) { + 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)); + + DebugManagerStateRestore restore; + DebugManager.flags.ForceAllResourcesUncached.set(true); EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); EXPECT_EQ(0u, gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); 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 c410587835..538b6a36d9 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -887,7 +887,7 @@ HWTEST2_F(LegacyDebuggerTest, givenNotAtsOrDg2AndDebugIsActiveThenDisableL3Cache MockPlatform platform(*executionEnvironment); platform.initializeWithNewDevices(); - EXPECT_FALSE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled); + EXPECT_FALSE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->allResourcesUncached); } using ATSOrDG2 = IsWithinGfxCore; @@ -898,5 +898,5 @@ HWTEST2_F(LegacyDebuggerTest, givenAtsOrDg2AndDebugIsActiveThenDisableL3CacheInG MockPlatform platform(*executionEnvironment); platform.initializeWithNewDevices(); - EXPECT_TRUE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->l3CacheForDebugDisabled); + EXPECT_TRUE(static_cast(platform.getClDevice(0)->getDevice().getGmmHelper())->allResourcesUncached); } diff --git a/opencl/test/unit_test/test_files/igdrcl.config b/opencl/test/unit_test/test_files/igdrcl.config index c3069cfb3b..c35611d4ff 100644 --- a/opencl/test/unit_test/test_files/igdrcl.config +++ b/opencl/test/unit_test/test_files/igdrcl.config @@ -389,3 +389,4 @@ AccessCountersGranularity = -1 OverridePatIndex = -1 UseTileMemoryBankInVirtualMemoryCreation = -1 DisableScratchPages = 0 +ForceAllResourcesUncached = 0 diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 947d2b8783..e2f7b1f6b7 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -406,6 +406,7 @@ DECLARE_DEBUG_VARIABLE(bool, SkipFlushingEventsOnGetStatusCalls, false, "When se DECLARE_DEBUG_VARIABLE(bool, AllowUnrestrictedSize, false, "Allow allocating memory with greater size than MAX_MEM_ALLOC_SIZE") DECLARE_DEBUG_VARIABLE(int32_t, ProgramExtendedPipeControlPriorToNonPipelinedStateCommand, -1, "-1: default, 0: disable, 1: enable, Program additional extended version of PIPE CONTROL command before non pipelined state command") DECLARE_DEBUG_VARIABLE(int32_t, OverrideDrmRegion, -1, "-1: disable, 0+: override to given memory region for all allocations") +DECLARE_DEBUG_VARIABLE(bool, ForceAllResourcesUncached, false, "When set, all memory operations ifor all resources are forced to UC. This overrides all caching-related debug variables and globally disables all caches") /* Binary Cache */ DECLARE_DEBUG_VARIABLE(bool, BinaryCacheTrace, false, "enable cl_cache to produce .trace files with information about hash computation") diff --git a/shared/source/device/device.cpp b/shared/source/device/device.cpp index 856bb1cdb6..f2281e333c 100644 --- a/shared/source/device/device.cpp +++ b/shared/source/device/device.cpp @@ -220,7 +220,7 @@ bool Device::createDeviceImpl() { auto &hwHelper = HwHelper::get(hwInfo.platform.eRenderCoreFamily); if (getDebugger() && hwHelper.disableL3CacheForDebug(hwInfo)) { - getGmmHelper()->disableL3CacheForDebug(); + getGmmHelper()->forceAllResourcesUncached(); } if (!createEngines()) { diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index e2fcdc7c49..4a5af7d230 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -376,5 +376,9 @@ void Gmm::applyDebugOverrides() { if (-1 != DebugManager.flags.OverrideGmmResourceUsageField.get()) { resourceParams.Usage = static_cast(DebugManager.flags.OverrideGmmResourceUsageField.get()); } + + if (true == (DebugManager.flags.ForceAllResourcesUncached.get())) { + resourceParams.Usage = GMM_RESOURCE_USAGE_SURFACE_UNCACHED; + } } } // namespace NEO diff --git a/shared/source/gmm_helper/gmm_helper.cpp b/shared/source/gmm_helper/gmm_helper.cpp index 14eb566be6..5b13fdd4fd 100644 --- a/shared/source/gmm_helper/gmm_helper.cpp +++ b/shared/source/gmm_helper/gmm_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,7 +30,7 @@ const HardwareInfo *GmmHelper::getHardwareInfo() { } uint32_t GmmHelper::getMOCS(uint32_t type) const { - if (l3CacheForDebugDisabled) { + if (allResourcesUncached || (DebugManager.flags.ForceAllResourcesUncached.get() == true)) { type = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; } diff --git a/shared/source/gmm_helper/gmm_helper.h b/shared/source/gmm_helper/gmm_helper.h index 34da2ef620..b19b67979c 100644 --- a/shared/source/gmm_helper/gmm_helper.h +++ b/shared/source/gmm_helper/gmm_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,7 +23,7 @@ class GmmHelper { const HardwareInfo *getHardwareInfo(); uint32_t getMOCS(uint32_t type) const; - void disableL3CacheForDebug() { l3CacheForDebugDisabled = true; }; + void forceAllResourcesUncached() { allResourcesUncached = true; }; static constexpr uint64_t maxPossiblePitch = (1ull << 31); @@ -45,6 +45,6 @@ class GmmHelper { static uint32_t addressWidth; const HardwareInfo *hwInfo = nullptr; std::unique_ptr gmmClientContext; - bool l3CacheForDebugDisabled = false; + bool allResourcesUncached = false; }; } // namespace NEO diff --git a/shared/source/os_interface/linux/clos_helper.h b/shared/source/os_interface/linux/clos_helper.h index 4b2633d6c7..b44b4c35dd 100644 --- a/shared/source/os_interface/linux/clos_helper.h +++ b/shared/source/os_interface/linux/clos_helper.h @@ -27,9 +27,13 @@ namespace ClosHelper { 7 2 WB (11) */ -constexpr uint64_t getPatIndex(CacheRegion closIndex, CachePolicy memType) { - UNRECOVERABLE_IF((closIndex > CacheRegion::Default) && (memType < CachePolicy::WriteThrough)); +static inline uint64_t getPatIndex(CacheRegion closIndex, CachePolicy memType) { + if ((DebugManager.flags.ForceAllResourcesUncached.get() == true)) { + closIndex = CacheRegion::Default; + memType = CachePolicy::Uncached; + } + UNRECOVERABLE_IF((closIndex > CacheRegion::Default) && (memType < CachePolicy::WriteThrough)); return (static_cast(memType) + (static_cast(closIndex) * 2)); } } // namespace ClosHelper diff --git a/shared/test/common/mocks/mock_gmm_helper.h b/shared/test/common/mocks/mock_gmm_helper.h index 08062fea9d..0016940fab 100644 --- a/shared/test/common/mocks/mock_gmm_helper.h +++ b/shared/test/common/mocks/mock_gmm_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,6 @@ namespace NEO { struct MockGmmHelper : GmmHelper { using GmmHelper::addressWidth; - using GmmHelper::l3CacheForDebugDisabled; + using GmmHelper::allResourcesUncached; }; } // namespace NEO