From d0b009901cd5efad949a411d1b379828e44334cb Mon Sep 17 00:00:00 2001 From: Katarzyna Cencelewska Date: Wed, 31 Jan 2024 14:17:57 +0000 Subject: [PATCH] fix: use proper gmm resource type for uncache resources when new coherency model Resolves: NEO-9657 Signed-off-by: Katarzyna Cencelewska --- .../gmm_helper/cache_settings_helper.cpp | 16 +++---- .../source/gmm_helper/cache_settings_helper.h | 2 +- shared/source/os_interface/product_helper.h | 1 + shared/source/os_interface/product_helper.inl | 4 ++ .../source/os_interface/product_helper_hw.h | 1 + .../os_agnostic_product_helper_xe_lpg.inl | 5 +++ .../unit_test/gmm_helper/gmm_helper_tests.cpp | 43 ++++++++++++------- .../dg2/test_product_helper_dg2.cpp | 6 ++- ...s_agnostic_product_helper_xe_lpg_tests.cpp | 4 ++ 9 files changed, 57 insertions(+), 25 deletions(-) diff --git a/shared/source/gmm_helper/cache_settings_helper.cpp b/shared/source/gmm_helper/cache_settings_helper.cpp index 2d4e0d8a16..094cefef6f 100644 --- a/shared/source/gmm_helper/cache_settings_helper.cpp +++ b/shared/source/gmm_helper/cache_settings_helper.cpp @@ -26,7 +26,7 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType } if (forceUncached || debugManager.flags.ForceAllResourcesUncached.get()) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } else { return getDefaultUsageTypeWithCachingEnabled(allocationType, productHelper); } @@ -54,12 +54,12 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching case AllocationType::internalHeap: case AllocationType::linearStream: if (debugManager.flags.DisableCachingForHeaps.get()) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } return GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER; case AllocationType::constantSurface: if (debugManager.flags.ForceL1Caching.get() == 0) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } return GMM_RESOURCE_USAGE_OCL_BUFFER_CONST; case AllocationType::buffer: @@ -68,7 +68,7 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching case AllocationType::unifiedSharedMemory: case AllocationType::externalHostPtr: if (debugManager.flags.DisableCachingForStatefulBufferAccess.get()) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } return GMM_RESOURCE_USAGE_OCL_BUFFER; case AllocationType::bufferHostMemory: @@ -78,13 +78,13 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching case AllocationType::svmCpu: case AllocationType::svmZeroCopy: if (debugManager.flags.DisableCachingForStatefulBufferAccess.get()) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } return GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER; case AllocationType::gpuTimestampDeviceBuffer: case AllocationType::timestampPacketTagBuffer: if (productHelper.isDcFlushAllowed()) { - return getDefaultUsageTypeWithCachingDisabled(allocationType); + return getDefaultUsageTypeWithCachingDisabled(allocationType, productHelper); } return GMM_RESOURCE_USAGE_OCL_BUFFER; default: @@ -92,7 +92,7 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching } } -GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType) { +GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType, const ProductHelper &productHelper) { switch (allocationType) { case AllocationType::preemption: return GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; @@ -100,7 +100,7 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCaching case AllocationType::linearStream: return GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED; default: - return GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + return productHelper.isNewCoherencyModelSupported() ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC : GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; } } diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index 7f768f7c8a..fb175c754d 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -32,6 +32,6 @@ struct CacheSettingsHelper { protected: static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper); - static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType); + static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType, const ProductHelper &productHelper); }; } // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/product_helper.h b/shared/source/os_interface/product_helper.h index 96b062470d..617d12e21b 100644 --- a/shared/source/os_interface/product_helper.h +++ b/shared/source/os_interface/product_helper.h @@ -218,6 +218,7 @@ class ProductHelper { virtual void adjustEngineGroupType(EngineGroupType &engineGroupType) const = 0; virtual std::optional getPreferredAllocationMethod(AllocationType allocationType) const = 0; virtual bool isCachingOnCpuAvailable() const = 0; + virtual bool isNewCoherencyModelSupported() const = 0; virtual ~ProductHelper() = default; diff --git a/shared/source/os_interface/product_helper.inl b/shared/source/os_interface/product_helper.inl index d40a2e58f9..f24430e546 100644 --- a/shared/source/os_interface/product_helper.inl +++ b/shared/source/os_interface/product_helper.inl @@ -849,4 +849,8 @@ bool ProductHelperHw::isCachingOnCpuAvailable() const { return true; } +template +bool ProductHelperHw::isNewCoherencyModelSupported() const { + return false; +} } // namespace NEO diff --git a/shared/source/os_interface/product_helper_hw.h b/shared/source/os_interface/product_helper_hw.h index a1aad1ffdd..8d38599199 100644 --- a/shared/source/os_interface/product_helper_hw.h +++ b/shared/source/os_interface/product_helper_hw.h @@ -165,6 +165,7 @@ class ProductHelperHw : public ProductHelper { void adjustEngineGroupType(EngineGroupType &engineGroupType) const override; std::optional getPreferredAllocationMethod(AllocationType allocationType) const override; bool isCachingOnCpuAvailable() const override; + bool isNewCoherencyModelSupported() const override; ~ProductHelperHw() override = default; diff --git a/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl b/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl index b0e8c75701..4d09c9266a 100644 --- a/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl +++ b/shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl @@ -121,4 +121,9 @@ bool ProductHelperHw::isCachingOnCpuAvailable() const { return false; } +template <> +bool ProductHelperHw::isNewCoherencyModelSupported() const { + return true; +} + } // namespace NEO 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 4ac0703e5d..3a24a472fe 100644 --- a/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2023 Intel Corporation + * Copyright (C) 2018-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -684,17 +684,17 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) { const auto &productHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); for (uint32_t i = 0; i < static_cast(AllocationType::count); i++) { auto allocationType = static_cast(i); - + auto uncachedGmmUsageType = productHelper.isNewCoherencyModelSupported() ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC : GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; for (auto forceUncached : {true, false}) { auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, forceUncached, productHelper); auto expectedUsage = GMM_RESOURCE_USAGE_UNKNOWN; switch (allocationType) { case AllocationType::constantSurface: - expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_BUFFER_CONST; + expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_BUFFER_CONST; break; case AllocationType::image: - expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_IMAGE; + expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_IMAGE; break; case AllocationType::preemption: expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC : GMM_RESOURCE_USAGE_OCL_BUFFER; @@ -705,7 +705,7 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) { break; case AllocationType::gpuTimestampDeviceBuffer: case AllocationType::timestampPacketTagBuffer: - expectedUsage = (forceUncached || productHelper.isDcFlushAllowed()) ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED + expectedUsage = (forceUncached || productHelper.isDcFlushAllowed()) ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_BUFFER; break; case AllocationType::bufferHostMemory: @@ -714,10 +714,10 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) { case AllocationType::fillPattern: case AllocationType::svmCpu: case AllocationType::svmZeroCopy: - expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER; + expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER; break; default: - expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_BUFFER; + expectedUsage = forceUncached ? uncachedGmmUsageType : GMM_RESOURCE_USAGE_OCL_BUFFER; break; } @@ -736,8 +736,11 @@ TEST(GmmTest, givenForceAllResourcesUncachedFlagSetWhenGettingUsageTypeThenRetur auto allocationType = static_cast(i); auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, false, productHelper); - auto expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + auto expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + if (productHelper.isNewCoherencyModelSupported()) { + expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + } if (allocationType == AllocationType::preemption) { expectedUsage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; @@ -786,8 +789,11 @@ TEST(GmmTest, givenConstSurfaceWhenDebugFlagIsSetThenReturnUncachedType) { debugManager.flags.ForceL1Caching.set(false); MockExecutionEnvironment mockExecutionEnvironment{}; const auto &productHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); - - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, + auto expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + if (productHelper.isNewCoherencyModelSupported()) { + expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + } + EXPECT_EQ(expectedUncachedGmmUsageType, CacheSettingsHelper::getGmmUsageType(AllocationType::constantSurface, false, productHelper)); } @@ -801,14 +807,17 @@ TEST(GmmTest, givenUncachedDebugFlagMaskSetWhenAskingForUsageTypeThenReturnUncac constexpr int64_t imageMask = 1 << (static_cast(AllocationType::image) - 1); debugManager.flags.ForceUncachedGmmUsageType.set(bufferMask | imageMask); - - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, + auto expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + if (productHelper.isNewCoherencyModelSupported()) { + expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + } + EXPECT_EQ(expectedUncachedGmmUsageType, CacheSettingsHelper::getGmmUsageType(AllocationType::buffer, false, productHelper)); - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, + EXPECT_EQ(expectedUncachedGmmUsageType, CacheSettingsHelper::getGmmUsageType(AllocationType::image, false, productHelper)); - EXPECT_NE(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, + EXPECT_NE(expectedUncachedGmmUsageType, CacheSettingsHelper::getGmmUsageType(AllocationType::bufferHostMemory, false, productHelper)); } @@ -817,6 +826,10 @@ TEST(GmmTest, givenAllocationForStatefulAccessWhenDebugFlagIsSetThenReturnUncach debugManager.flags.DisableCachingForStatefulBufferAccess.set(true); MockExecutionEnvironment mockExecutionEnvironment{}; const auto &productHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + auto expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + if (productHelper.isNewCoherencyModelSupported()) { + expectedUncachedGmmUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + } for (auto allocType : {AllocationType::buffer, AllocationType::bufferHostMemory, AllocationType::externalHostPtr, @@ -829,7 +842,7 @@ TEST(GmmTest, givenAllocationForStatefulAccessWhenDebugFlagIsSetThenReturnUncach AllocationType::svmZeroCopy, AllocationType::unifiedSharedMemory}) { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, CacheSettingsHelper::getGmmUsageType(allocType, false, productHelper)); + EXPECT_EQ(expectedUncachedGmmUsageType, CacheSettingsHelper::getGmmUsageType(allocType, false, productHelper)); } } diff --git a/shared/test/unit_test/xe_hpg_core/dg2/test_product_helper_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/test_product_helper_dg2.cpp index ac8cf5eda1..12f1ed1097 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/test_product_helper_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/test_product_helper_dg2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -110,3 +110,7 @@ DG2TEST_F(Dg2ProductHelper, whenConfiguringHardwareInfoThenWa15010089951IsSet) { productHelper->configureHardwareCustom(&hwInfo, nullptr); EXPECT_TRUE(hwInfo.workaroundTable.flags.wa_15010089951); } + +DG2TEST_F(Dg2ProductHelper, givenProductHelperWhenCallIsNewCoherencyModelSupportedThenFalseIsReturned) { + EXPECT_FALSE(productHelper->isNewCoherencyModelSupported()); +} \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/os_agnostic_product_helper_xe_lpg_tests.cpp b/shared/test/unit_test/xe_hpg_core/os_agnostic_product_helper_xe_lpg_tests.cpp index 6a3d159235..9202131158 100644 --- a/shared/test/unit_test/xe_hpg_core/os_agnostic_product_helper_xe_lpg_tests.cpp +++ b/shared/test/unit_test/xe_hpg_core/os_agnostic_product_helper_xe_lpg_tests.cpp @@ -355,4 +355,8 @@ HWTEST2_F(XeLpgProductHelperTests, whenCheckPreferredAllocationMethodThenAllocat HWTEST2_F(XeLpgProductHelperTests, givenProductHelperWhenCallIsCachingOnCpuAvailableThenFalseIsReturned, IsXeLpg) { EXPECT_FALSE(productHelper->isCachingOnCpuAvailable()); +} + +HWTEST2_F(XeLpgProductHelperTests, givenProductHelperWhenCallIsNewCoherencyModelSupportedThenTrueIsReturned, IsXeLpg) { + EXPECT_TRUE(productHelper->isNewCoherencyModelSupported()); } \ No newline at end of file