diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index 3cb78ffebb..adef558716 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1866,7 +1866,7 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation EXPECT_EQ(MemoryConstants::pageSize64k, graphicsAllocation->getUnderlyingBufferSize()); EXPECT_NE(0llu, graphicsAllocation->getGpuAddress()); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); - EXPECT_EQ(1u, graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable); + EXPECT_EQ(0u, graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable); memoryManager.freeGraphicsMemory(graphicsAllocation); } diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 7afcbf618d..ddc7913335 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -490,6 +490,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(bool, ForceDefaultThreadArbitrationPolicyIfNotSpecified, false, "When executing kernel without thread arbitration hint specified, ensure the default setting is used") DECLARE_DEBUG_VARIABLE(bool, ForceAllResourcesUncached, false, "When set, all memory operations for all resources are forced to UC. This overrides all caching-related debug variables and globally disables all caches") +DECLARE_DEBUG_VARIABLE(bool, EnableCpuCacheForResources, false, "When true, driver will set gmm flag cacheable related to caching on cpu, for resources where it is allowed") DECLARE_DEBUG_VARIABLE(bool, EnableDebuggerMmapMemoryAccess, false, "Mmap used to access memory by debug api, valid only on Linux OS") DECLARE_DEBUG_VARIABLE(bool, ForceDefaultGrfCompilationMode, false, "Adds build option -cl-intel-128-GRF-per-thread to force kernel compilation in Default-GRF mode") DECLARE_DEBUG_VARIABLE(bool, ForceLargeGrfCompilationMode, false, "Adds build option -cl-intel-256-GRF-per-thread to force kernel compilation in Large-GRF mode") diff --git a/shared/source/gmm_helper/cache_settings_helper.cpp b/shared/source/gmm_helper/cache_settings_helper.cpp index e277db7571..c736d93750 100644 --- a/shared/source/gmm_helper/cache_settings_helper.cpp +++ b/shared/source/gmm_helper/cache_settings_helper.cpp @@ -28,6 +28,13 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType } } +bool CacheSettingsHelper::isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType) { + if (DebugManager.flags.EnableCpuCacheForResources.get()) { + return !CacheSettingsHelper::isUncachedType(gmmResourceUsageType); + } + return false; +} + GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper) { switch (allocationType) { diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index f64f2e9b15..e62fee6308 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -26,6 +26,8 @@ struct CacheSettingsHelper { (gmmResourceUsageType == GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); } + static bool isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType); + protected: static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper); static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType); diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index e3ac619ebd..e8dfb3d9bd 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -39,7 +39,7 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_ resourceParams.Usage = gmmResourceUsage; resourceParams.Flags.Info.Linear = 1; - resourceParams.Flags.Info.Cacheable = !CacheSettingsHelper::isUncachedType(gmmResourceUsage); + resourceParams.Flags.Info.Cacheable = CacheSettingsHelper::isResourceCacheableOnCpu(gmmResourceUsage); resourceParams.Flags.Gpu.Texture = 1; if (alignedPtr) { diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index af49ca0f0d..cbe6463759 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -521,4 +521,5 @@ ExitOnSubmissionNumber = -1 ExitOnSubmissionMode = 0 ForceInOrderImmediateCmdListExecution = -1 ForceTlbFlush = -1 -DebugSetMemoryDiagnosticsDelay = -1 \ No newline at end of file +DebugSetMemoryDiagnosticsDelay = -1 +EnableCpuCacheForResources = 0 \ No newline at end of file diff --git a/shared/test/unit_test/gmm_helper/gmm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_tests.cpp index 39f625369d..9103c143a7 100644 --- a/shared/test/unit_test/gmm_helper/gmm_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Intel Corporation + * Copyright (C) 2022-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,13 +8,16 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/test/common/fixtures/mock_execution_environment_gmm_fixture.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_gmm.h" #include "shared/test/common/test_macros/test.h" namespace NEO { using GmmTests = Test; -TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenGreateGmmThenFlagCachcableIsTrue) { +TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesSetThenFlagCachcableIsTrue) { + DebugManagerStateRestore restore; + DebugManager.flags.EnableCpuCacheForResources.set(1); StorageInfo storageInfo{}; for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_IMAGE, GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER, @@ -25,6 +28,19 @@ TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenGreateGmmThenFlagCachcableI } } +TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesNotSetThenFlagCachcableIsAlwaysFalse) { + DebugManagerStateRestore restore; + DebugManager.flags.EnableCpuCacheForResources.set(0); + StorageInfo storageInfo{}; + for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_IMAGE, + GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER, + GMM_RESOURCE_USAGE_OCL_BUFFER_CONST, + GMM_RESOURCE_USAGE_OCL_BUFFER}) { + auto gmm = std::make_unique(getGmmHelper(), nullptr, 0, 0, resourceUsageType, false, storageInfo, false); + EXPECT_FALSE(gmm->resourceParams.Flags.Info.Cacheable); + } +} + TEST_F(GmmTests, givenResourceUsageTypesUnCachedWhenGreateGmmThenFlagCachcableIsFalse) { StorageInfo storageInfo{}; for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC,