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 538b4f5963..7b91664856 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 @@ -1853,10 +1853,11 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor memoryManager64k.freeGraphicsMemory(galloc); } -TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocationIsCreatedWithSizeSmallerThan64kbThenGraphicsAllocationsHas64kbAlignedUnderlyingSize) { +HWTEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocationIsCreatedWithSizeSmallerThan64kbThenGraphicsAllocationsHas64kbAlignedUnderlyingSize) { DebugManagerStateRestore dbgRestore; wddm->init(); DebugManager.flags.Enable64kbpages.set(true); + DebugManager.flags.EnableCpuCacheForResources.set(0); MockWddmMemoryManager memoryManager(true, false, *executionEnvironment); AllocationData allocationData; allocationData.size = 1u; @@ -1866,7 +1867,8 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation EXPECT_EQ(MemoryConstants::pageSize64k, graphicsAllocation->getUnderlyingBufferSize()); EXPECT_NE(0llu, graphicsAllocation->getGpuAddress()); EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); - EXPECT_TRUE(graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable); + auto &gfxCoreHelper = executionEnvironment->rootDeviceEnvironments[rootDeviceIndex]->getHelper(); + EXPECT_EQ(gfxCoreHelper.isCachingOnCpuAvailable(), graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable); memoryManager.freeGraphicsMemory(graphicsAllocation); } diff --git a/shared/source/gmm_helper/cache_settings_helper.cpp b/shared/source/gmm_helper/cache_settings_helper.cpp index c736d93750..1bf5b501fc 100644 --- a/shared/source/gmm_helper/cache_settings_helper.cpp +++ b/shared/source/gmm_helper/cache_settings_helper.cpp @@ -8,6 +8,7 @@ #include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/helpers/gfx_core_helper.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/allocation_type.h" #include "shared/source/os_interface/product_helper.h" @@ -28,11 +29,12 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType } } -bool CacheSettingsHelper::isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType) { +bool CacheSettingsHelper::isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const GfxCoreHelper &gfxCoreHelper) { + bool isCachingOnCpuAvailable = gfxCoreHelper.isCachingOnCpuAvailable(); if (DebugManager.flags.EnableCpuCacheForResources.get()) { - return !CacheSettingsHelper::isUncachedType(gmmResourceUsageType); + isCachingOnCpuAvailable = true; } - return false; + return isCachingOnCpuAvailable && !CacheSettingsHelper::isUncachedType(gmmResourceUsageType); } GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper) { diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index e62fee6308..bf0ae60d97 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -16,6 +16,7 @@ namespace NEO { enum class AllocationType; struct HardwareInfo; class ProductHelper; +class GfxCoreHelper; struct CacheSettingsHelper { static GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached, const ProductHelper &productHelper); @@ -26,7 +27,7 @@ struct CacheSettingsHelper { (gmmResourceUsageType == GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED)); } - static bool isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType); + static bool isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const GfxCoreHelper &gfxCoreHelper); protected: static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper); diff --git a/shared/source/gmm_helper/gmm.cpp b/shared/source/gmm_helper/gmm.cpp index e8dfb3d9bd..6e051e504d 100644 --- a/shared/source/gmm_helper/gmm.cpp +++ b/shared/source/gmm_helper/gmm.cpp @@ -39,7 +39,8 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_ resourceParams.Usage = gmmResourceUsage; resourceParams.Flags.Info.Linear = 1; - resourceParams.Flags.Info.Cacheable = CacheSettingsHelper::isResourceCacheableOnCpu(gmmResourceUsage); + auto &gfxCoreHelper = gmmHelper->getRootDeviceEnvironment().getHelper(); + resourceParams.Flags.Info.Cacheable = CacheSettingsHelper::isResourceCacheableOnCpu(gmmResourceUsage, gfxCoreHelper); resourceParams.Flags.Gpu.Texture = 1; if (alignedPtr) { diff --git a/shared/source/helpers/gfx_core_helper.h b/shared/source/helpers/gfx_core_helper.h index 7f919e3631..8d420afccb 100644 --- a/shared/source/helpers/gfx_core_helper.h +++ b/shared/source/helpers/gfx_core_helper.h @@ -171,7 +171,7 @@ class GfxCoreHelper { virtual bool isTimestampShiftRequired() const = 0; virtual bool isRelaxedOrderingSupported() const = 0; static bool isWorkaroundRequired(uint32_t lowestSteppingWithBug, uint32_t steppingWithFix, const HardwareInfo &hwInfo, const ProductHelper &productHelper); - + virtual bool isCachingOnCpuAvailable() const = 0; virtual ~GfxCoreHelper() = default; protected: @@ -386,6 +386,7 @@ class GfxCoreHelperHw : public GfxCoreHelper { bool isChipsetUniqueUUIDSupported() const override; bool isTimestampShiftRequired() const override; bool isRelaxedOrderingSupported() const override; + bool isCachingOnCpuAvailable() const override; ~GfxCoreHelperHw() override = default; diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 5366195cf7..9f58ec029c 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -695,4 +695,9 @@ template uint32_t GfxCoreHelperHw::getMinimalGrfSize() const { return 128u; } + +template +bool GfxCoreHelperHw::isCachingOnCpuAvailable() const { + return true; +} } // namespace NEO diff --git a/shared/source/helpers/gfx_core_helper_xehp_and_later.inl b/shared/source/helpers/gfx_core_helper_xehp_and_later.inl index d768963fab..cc622425df 100644 --- a/shared/source/helpers/gfx_core_helper_xehp_and_later.inl +++ b/shared/source/helpers/gfx_core_helper_xehp_and_later.inl @@ -232,4 +232,9 @@ bool GfxCoreHelperHw::isChipsetUniqueUUIDSupported() const { return true; } +template <> +bool GfxCoreHelperHw::isCachingOnCpuAvailable() const { + return false; +} + } // namespace NEO diff --git a/shared/test/unit_test/gmm_helper/gmm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_tests.cpp index 9103c143a7..234ee39aca 100644 --- a/shared/test/unit_test/gmm_helper/gmm_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/helpers/gfx_core_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" @@ -28,16 +29,17 @@ TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCa } } -TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesNotSetThenFlagCachcableIsAlwaysFalse) { +TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesNotSetThenFlagCachcableIsRelatedToValueFromHelperIsCachingOnCpuAvailable) { DebugManagerStateRestore restore; DebugManager.flags.EnableCpuCacheForResources.set(0); StorageInfo storageInfo{}; + auto &gfxCoreHelper = getGmmHelper()->getRootDeviceEnvironment().getHelper(); 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); + EXPECT_EQ(gfxCoreHelper.isCachingOnCpuAvailable(), gmm->resourceParams.Flags.Info.Cacheable); } } diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index 8895697bd8..d7253569fa 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -1585,3 +1585,13 @@ HWTEST_F(GfxCoreHelperTest, givenNumGrfAndSimdSizeWhenAdjustingMaxWorkGroupSizeT numGrfRequired = GrfConfig::DefaultGrfNumber; EXPECT_EQ(defaultMaxGroupSize, gfxCoreHelper.adjustMaxWorkGroupSize(numGrfRequired, simdSize, defaultMaxGroupSize)); } + +HWTEST2_F(GfxCoreHelperTest, givenAtLeastXeHpWhenCheckIsCachingOnCpuAvailableThenAlwaysFalse, IsAtLeastXeHpCore) { + const auto &gfxCoreHelper = getHelper(); + EXPECT_FALSE(gfxCoreHelper.isCachingOnCpuAvailable()); +} + +HWTEST2_F(GfxCoreHelperTest, givenAtMostGen12lpWhenCheckIsCachingOnCpuAvailableThenAlwaysTrue, IsAtMostGen12lp) { + const auto &gfxCoreHelper = getHelper(); + EXPECT_TRUE(gfxCoreHelper.isCachingOnCpuAvailable()); +}