From 6c75ec31164f5321528f0a6b613d06f2afe9e3a2 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Fri, 24 May 2024 13:34:24 +0000 Subject: [PATCH] fix: Defer MOCS to PAT Related-To: NEO-10556 Signed-off-by: Lukasz Jobczyk --- .../sources/cmdlist/test_cmdlist_2.cpp | 8 ++++++ .../cmdlist/test_cmdlist_xehp_and_later.cpp | 8 ++++++ .../test/unit_test/mem_obj/buffer_tests.cpp | 3 +++ .../command_stream/command_stream_receiver.h | 3 ++- .../source/gmm_helper/cache_settings_helper.h | 2 +- shared/source/gmm_helper/gmm_helper.cpp | 7 ++++- .../windows/wddm_memory_manager.cpp | 4 +++ .../command_stream_receiver_tests.cpp | 2 +- .../unit_test/gmm_helper/gmm_helper_tests.cpp | 27 +++++++++++++++++++ 9 files changed, 60 insertions(+), 4 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp index a3411fa37b..5b6e47a7e9 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_2.cpp @@ -1745,6 +1745,10 @@ HWTEST2_F(PrimaryBatchBufferPreamblelessCmdListTest, using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + if (device->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } + // command list 1 will have two kernels, transition from cached MOCS to uncached MOCS state ze_group_count_t groupCount{1, 1, 1}; CmdListKernelLaunchParams launchParams = {}; @@ -1919,6 +1923,10 @@ HWTEST2_F(PrimaryBatchBufferPreamblelessCmdListTest, using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + if (device->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } + auto ultCsr = static_cast *>(commandQueue->getCsr()); ultCsr->recordFlusheBatchBuffer = true; diff --git a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp index 2fb0f76e68..c2125657f1 100644 --- a/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdlist/test_cmdlist_xehp_and_later.cpp @@ -1914,6 +1914,10 @@ HWTEST2_F(ImmediateFlushTaskGlobalStatelessCmdListTest, IsAtLeastXeHpCore) { using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + if (neoDevice->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } + auto &csrImmediate = neoDevice->getUltCommandStreamReceiver(); auto &csrStream = csrImmediate.commandStream; @@ -2036,6 +2040,10 @@ HWTEST2_F(ImmediateFlushTaskCsrSharedHeapCmdListTest, IsAtLeastXeHpCore) { using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS; + if (neoDevice->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } + auto &csrImmediate = neoDevice->getUltCommandStreamReceiver(); auto &csrStream = csrImmediate.commandStream; diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index a824b20810..a1281c269b 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -2030,6 +2030,9 @@ HWTEST_P(BufferL3CacheTests, DISABLED_givenMisalignedAndAlignedBufferWhenClEnque HWTEST_P(BufferL3CacheTests, givenMisalignedAndAlignedBufferWhenClEnqueueWriteBufferRectThenL3CacheIsOn) { auto device = ctx.getDevice(0); + if (device->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } const auto &compilerProductHelper = device->getRootDeviceEnvironment().getHelper(); if (compilerProductHelper.isForceToStatelessRequired()) { GTEST_SKIP(); diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index e82400cdc3..c8c3834159 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -9,6 +9,7 @@ #include "shared/source/command_stream/csr_definitions.h" #include "shared/source/command_stream/linear_stream.h" #include "shared/source/command_stream/stream_properties.h" +#include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/helpers/blit_properties_container.h" #include "shared/source/helpers/cache_policy.h" #include "shared/source/helpers/common_types.h" @@ -600,7 +601,7 @@ class CommandStreamReceiver { std::chrono::microseconds gpuHangCheckPeriod{500'000}; uint32_t lastSentL3Config = 0; - uint32_t latestSentStatelessMocsConfig = 0; + uint32_t latestSentStatelessMocsConfig = CacheSettings::unknownMocs; uint64_t lastSentSliceCount = QueueSliceCount::defaultSliceCount; uint32_t requiredScratchSlot0Size = 0; diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index fb175c754d..c7684e6b4b 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -9,7 +9,7 @@ #include "shared/source/gmm_helper/gmm_lib.h" namespace CacheSettings { -inline constexpr uint32_t unknownMocs = GMM_RESOURCE_USAGE_UNKNOWN; +inline constexpr uint32_t unknownMocs = -1; } // namespace CacheSettings namespace NEO { diff --git a/shared/source/gmm_helper/gmm_helper.cpp b/shared/source/gmm_helper/gmm_helper.cpp index bc2508d03a..28f473b5d9 100644 --- a/shared/source/gmm_helper/gmm_helper.cpp +++ b/shared/source/gmm_helper/gmm_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 Intel Corporation + * Copyright (C) 2019-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,6 +15,7 @@ #include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/graphics_allocation.h" +#include "shared/source/os_interface/product_helper.h" #include @@ -37,6 +38,10 @@ uint32_t GmmHelper::getMOCS(uint32_t type) const { type = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; } + if (this->rootDeviceEnvironment.getProductHelper().isNewCoherencyModelSupported()) { + return 0u; + } + MEMORY_OBJECT_CONTROL_STATE mocs = gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast(type)); return static_cast(mocs.DwordValue); diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index e855cc3d3d..c5c41e83af 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -447,6 +447,10 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co GmmRequirements gmmRequirements{}; gmmRequirements.allowLargePages = true; gmmRequirements.preferCompressed = false; + if (productHelper.overrideAllocationCacheable(allocationData)) { + gmmRequirements.overriderCacheable.enableOverride = true; + gmmRequirements.overriderCacheable.value = true; + } auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmHelper(), alignedPtr, alignedSize, 0u, CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!allocationData.flags.uncacheable, productHelper), {}, gmmRequirements); diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index dcc59f1a5b..7632f01978 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -338,7 +338,7 @@ HWTEST_F(CommandStreamReceiverTest, WhenCreatingCsrThenFlagsAreSetCorrectly) { EXPECT_EQ(0u, csr.lastSentL3Config); EXPECT_EQ(-1, csr.lastMediaSamplerConfig); EXPECT_EQ(PreemptionMode::Initial, csr.lastPreemptionMode); - EXPECT_EQ(0u, csr.latestSentStatelessMocsConfig); + EXPECT_EQ(static_cast(-1), csr.latestSentStatelessMocsConfig); } TEST_F(CommandStreamReceiverTest, givenBaseDownloadAllocationCalledThenDoesNotChangeAnything) { diff --git a/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 66caccb3a2..6e49b3f01d 100644 --- a/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -1044,11 +1044,35 @@ TEST(GmmHelperTest, givenEnableFtrTile64OptimizationDebugKeyWhenSetThenProperVal } } +TEST(GmmHelperTest, givenNewCoherencyModelWhenGetMocsThenDeferToPat) { + decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc; + GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create; + + MockExecutionEnvironment executionEnvironment{}; + if (!executionEnvironment.rootDeviceEnvironments[0]->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } + auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); + + 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, givenGmmHelperAndL3CacheDisabledForDebugThenCorrectMOCSIsReturned) { decltype(GmmHelper::createGmmContextWrapperFunc) createGmmContextSave = GmmHelper::createGmmContextWrapperFunc; GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create; MockExecutionEnvironment executionEnvironment{}; + if (executionEnvironment.rootDeviceEnvironments[0]->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); auto uncachedMocs = gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED); @@ -1078,6 +1102,9 @@ TEST(GmmHelperTest, givenGmmHelperAndForceAllResourcesUncachedDebugVariableSetTh GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create; MockExecutionEnvironment executionEnvironment{}; + if (executionEnvironment.rootDeviceEnvironments[0]->getProductHelper().isNewCoherencyModelSupported()) { + GTEST_SKIP(); + } auto gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); auto uncachedMocs = gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED);