Skip to content

Commit 004a3d8

Browse files
fix: Remove default setting of gmm flag Cacheable to true
- add debug flag EnableCpuCacheForResources to be able to allow coherency when resources could be cacheable Resolves: NEO-7194 Signed-off-by: Katarzyna Cencelewska <[email protected]>
1 parent af2c61c commit 004a3d8

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation
18661866
EXPECT_EQ(MemoryConstants::pageSize64k, graphicsAllocation->getUnderlyingBufferSize());
18671867
EXPECT_NE(0llu, graphicsAllocation->getGpuAddress());
18681868
EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer());
1869-
EXPECT_EQ(1u, graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable);
1869+
EXPECT_EQ(0u, graphicsAllocation->getDefaultGmm()->resourceParams.Flags.Info.Cacheable);
18701870

18711871
memoryManager.freeGraphicsMemory(graphicsAllocation);
18721872
}

shared/source/debug_settings/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ DECLARE_DEBUG_VARIABLE(bool, SkipFlushingEventsOnGetStatusCalls, false, "When se
490490
DECLARE_DEBUG_VARIABLE(bool, AllowUnrestrictedSize, false, "Allow allocating memory with greater size than MAX_MEM_ALLOC_SIZE")
491491
DECLARE_DEBUG_VARIABLE(bool, ForceDefaultThreadArbitrationPolicyIfNotSpecified, false, "When executing kernel without thread arbitration hint specified, ensure the default setting is used")
492492
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")
493+
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")
493494
DECLARE_DEBUG_VARIABLE(bool, EnableDebuggerMmapMemoryAccess, false, "Mmap used to access memory by debug api, valid only on Linux OS")
494495
DECLARE_DEBUG_VARIABLE(bool, ForceDefaultGrfCompilationMode, false, "Adds build option -cl-intel-128-GRF-per-thread to force kernel compilation in Default-GRF mode")
495496
DECLARE_DEBUG_VARIABLE(bool, ForceLargeGrfCompilationMode, false, "Adds build option -cl-intel-256-GRF-per-thread to force kernel compilation in Large-GRF mode")

shared/source/gmm_helper/cache_settings_helper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType
2828
}
2929
}
3030

31+
bool CacheSettingsHelper::isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType) {
32+
if (DebugManager.flags.EnableCpuCacheForResources.get()) {
33+
return !CacheSettingsHelper::isUncachedType(gmmResourceUsageType);
34+
}
35+
return false;
36+
}
37+
3138
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper) {
3239

3340
switch (allocationType) {

shared/source/gmm_helper/cache_settings_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct CacheSettingsHelper {
2626
(gmmResourceUsageType == GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));
2727
}
2828

29+
static bool isResourceCacheableOnCpu(GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsageType);
30+
2931
protected:
3032
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType, const ProductHelper &productHelper);
3133
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType);

shared/source/gmm_helper/gmm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Gmm::Gmm(GmmHelper *gmmHelper, const void *alignedPtr, size_t alignedSize, size_
3939

4040
resourceParams.Usage = gmmResourceUsage;
4141
resourceParams.Flags.Info.Linear = 1;
42-
resourceParams.Flags.Info.Cacheable = !CacheSettingsHelper::isUncachedType(gmmResourceUsage);
42+
resourceParams.Flags.Info.Cacheable = CacheSettingsHelper::isResourceCacheableOnCpu(gmmResourceUsage);
4343
resourceParams.Flags.Gpu.Texture = 1;
4444

4545
if (alignedPtr) {

shared/test/common/test_files/igdrcl.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,5 @@ ExitOnSubmissionNumber = -1
521521
ExitOnSubmissionMode = 0
522522
ForceInOrderImmediateCmdListExecution = -1
523523
ForceTlbFlush = -1
524-
DebugSetMemoryDiagnosticsDelay = -1
524+
DebugSetMemoryDiagnosticsDelay = -1
525+
EnableCpuCacheForResources = 0

shared/test/unit_test/gmm_helper/gmm_tests.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022 Intel Corporation
2+
* Copyright (C) 2022-2023 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -8,13 +8,16 @@
88
#include "shared/source/gmm_helper/gmm.h"
99
#include "shared/source/gmm_helper/gmm_helper.h"
1010
#include "shared/test/common/fixtures/mock_execution_environment_gmm_fixture.h"
11+
#include "shared/test/common/helpers/debug_manager_state_restore.h"
1112
#include "shared/test/common/mocks/mock_execution_environment.h"
1213
#include "shared/test/common/mocks/mock_gmm.h"
1314
#include "shared/test/common/test_macros/test.h"
1415

1516
namespace NEO {
1617
using GmmTests = Test<MockExecutionEnvironmentGmmFixture>;
17-
TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenGreateGmmThenFlagCachcableIsTrue) {
18+
TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesSetThenFlagCachcableIsTrue) {
19+
DebugManagerStateRestore restore;
20+
DebugManager.flags.EnableCpuCacheForResources.set(1);
1821
StorageInfo storageInfo{};
1922
for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_IMAGE,
2023
GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER,
@@ -25,6 +28,19 @@ TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenGreateGmmThenFlagCachcableI
2528
}
2629
}
2730

31+
TEST_F(GmmTests, givenResourceUsageTypesCacheableWhenCreateGmmAndFlagEnableCpuCacheForResourcesNotSetThenFlagCachcableIsAlwaysFalse) {
32+
DebugManagerStateRestore restore;
33+
DebugManager.flags.EnableCpuCacheForResources.set(0);
34+
StorageInfo storageInfo{};
35+
for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_IMAGE,
36+
GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER,
37+
GMM_RESOURCE_USAGE_OCL_BUFFER_CONST,
38+
GMM_RESOURCE_USAGE_OCL_BUFFER}) {
39+
auto gmm = std::make_unique<Gmm>(getGmmHelper(), nullptr, 0, 0, resourceUsageType, false, storageInfo, false);
40+
EXPECT_FALSE(gmm->resourceParams.Flags.Info.Cacheable);
41+
}
42+
}
43+
2844
TEST_F(GmmTests, givenResourceUsageTypesUnCachedWhenGreateGmmThenFlagCachcableIsFalse) {
2945
StorageInfo storageInfo{};
3046
for (auto resourceUsageType : {GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC,

0 commit comments

Comments
 (0)