refactor: pass root device environment to CacheSettingsHelper::preferNoCpuAccess

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2023-09-13 08:37:04 +00:00 committed by Compute-Runtime-Automation
parent 413365a7bf
commit f94ed7cd28
6 changed files with 16 additions and 16 deletions

View File

@ -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/execution_environment/root_device_environment.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/memory_manager/allocation_type.h"
@ -29,14 +30,14 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType
}
}
bool CacheSettingsHelper::preferNoCpuAccess(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const ProductHelper &productHelper, bool isWsl) {
bool CacheSettingsHelper::preferNoCpuAccess(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const RootDeviceEnvironment &rootDeviceEnvironment) {
if (DebugManager.flags.EnableCpuCacheForResources.get()) {
return false;
}
if (isWsl) {
if (rootDeviceEnvironment.isWddmOnLinux()) {
return false;
}
if (productHelper.isCachingOnCpuAvailable()) {
if (rootDeviceEnvironment.getProductHelper().isCachingOnCpuAvailable()) {
return false;
}
return (gmmResourceUsageType != GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER);

View File

@ -16,6 +16,7 @@ namespace NEO {
enum class AllocationType;
struct HardwareInfo;
class ProductHelper;
struct RootDeviceEnvironment;
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 preferNoCpuAccess(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const ProductHelper &productHelper, bool isWsl);
static bool preferNoCpuAccess(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType, const RootDeviceEnvironment &rootDeviceEnvironment);
protected:
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper);

View File

@ -39,8 +39,7 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_
resourceParams.Usage = gmmResourceUsage;
resourceParams.Flags.Info.Linear = 1;
auto &productHelper = gmmHelper->getRootDeviceEnvironment().getHelper<ProductHelper>();
this->preferNoCpuAccess = CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsage, productHelper, gmmHelper->getRootDeviceEnvironment().isWddmOnLinux());
this->preferNoCpuAccess = CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsage, gmmHelper->getRootDeviceEnvironment());
resourceParams.Flags.Info.Cacheable = !this->preferNoCpuAccess && !CacheSettingsHelper::isUncachedType(gmmResourceUsage);
resourceParams.Flags.Gpu.Texture = 1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -20,9 +20,8 @@ class MockExecutionEnvironmentGmmFixture {
void setUp();
void tearDown();
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
public:
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
GmmHelper *getGmmHelper();
GmmClientContext *getGmmClientContext();
};

View File

@ -15,6 +15,7 @@ namespace NEO {
struct MockRootDeviceEnvironment : public RootDeviceEnvironment {
using RootDeviceEnvironment::hwInfo;
using RootDeviceEnvironment::isDummyAllocationInitialized;
using RootDeviceEnvironment::isWddmOnLinuxEnable;
using RootDeviceEnvironment::RootDeviceEnvironment;
~MockRootDeviceEnvironment() override = default;

View File

@ -20,13 +20,12 @@ TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCa
DebugManagerStateRestore restore;
DebugManager.flags.EnableCpuCacheForResources.set(1);
StorageInfo storageInfo{};
auto &productHelper = getGmmHelper()->getRootDeviceEnvironment().getHelper<ProductHelper>();
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<Gmm>(getGmmHelper(), nullptr, 0, 0, resourceUsageType, false, storageInfo, false);
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(resourceUsageType, productHelper, false));
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(resourceUsageType, getGmmHelper()->getRootDeviceEnvironment()));
EXPECT_TRUE(gmm->resourceParams.Flags.Info.Cacheable);
}
}
@ -41,7 +40,7 @@ TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCa
GMM_RESOURCE_USAGE_OCL_BUFFER_CONST,
GMM_RESOURCE_USAGE_OCL_BUFFER}) {
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, resourceUsageType, false, storageInfo, false);
EXPECT_EQ(productHelper.isCachingOnCpuAvailable(), !CacheSettingsHelper::preferNoCpuAccess(resourceUsageType, productHelper, false));
EXPECT_EQ(productHelper.isCachingOnCpuAvailable(), !CacheSettingsHelper::preferNoCpuAccess(resourceUsageType, getGmmHelper()->getRootDeviceEnvironment()));
EXPECT_EQ(productHelper.isCachingOnCpuAvailable(), !gmm->getPreferNoCpuAccess());
}
}
@ -60,17 +59,17 @@ HWTEST_F(GmmTests, givenIsResourceCacheableOnCpuWhenWslFlagThenReturnProperValue
DebugManagerStateRestore restore;
DebugManager.flags.EnableCpuCacheForResources.set(false);
StorageInfo storageInfo{};
auto &productHelper = executionEnvironment->rootDeviceEnvironments[0]->getProductHelper();
bool isWsl = true;
auto rootDeviceEnvironment = static_cast<MockRootDeviceEnvironment *>(executionEnvironment->rootDeviceEnvironments[0].get());
rootDeviceEnvironment->isWddmOnLinuxEnable = true;
GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER;
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, gmmResourceUsageType, false, storageInfo, false);
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsageType, productHelper, isWsl));
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsageType, *rootDeviceEnvironment));
EXPECT_TRUE(gmm->resourceParams.Flags.Info.Cacheable);
gmmResourceUsageType = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, gmmResourceUsageType, false, storageInfo, false);
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsageType, productHelper, isWsl));
EXPECT_FALSE(CacheSettingsHelper::preferNoCpuAccess(gmmResourceUsageType, *rootDeviceEnvironment));
EXPECT_FALSE(gmm->resourceParams.Flags.Info.Cacheable);
}