Skip to content

Commit abd9030

Browse files
CacheSettingsHelper - heaps support
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent d6eaab1 commit abd9030

File tree

6 files changed

+110
-45
lines changed

6 files changed

+110
-45
lines changed

opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -840,30 +840,40 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) {
840840

841841
for (auto forceUncached : {true, false}) {
842842
auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, forceUncached);
843-
844-
if (allocationType == AllocationType::IMAGE) {
845-
if (forceUncached) {
846-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, usage);
847-
} else {
848-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_IMAGE, usage);
849-
}
850-
} else if (allocationType == AllocationType::PREEMPTION) {
851-
if (forceUncached) {
852-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC, usage);
853-
} else {
854-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER, usage);
855-
}
856-
} else {
857-
if (forceUncached) {
858-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, usage);
859-
} else {
860-
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER, usage);
861-
}
843+
auto expectedUsage = GMM_RESOURCE_USAGE_UNKNOWN;
844+
845+
switch (allocationType) {
846+
case AllocationType::IMAGE:
847+
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_IMAGE;
848+
break;
849+
case AllocationType::PREEMPTION:
850+
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC : GMM_RESOURCE_USAGE_OCL_BUFFER;
851+
break;
852+
case AllocationType::INTERNAL_HEAP:
853+
case AllocationType::LINEAR_STREAM:
854+
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER;
855+
break;
856+
default:
857+
expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_BUFFER;
858+
break;
862859
}
860+
861+
EXPECT_EQ(expectedUsage, usage);
863862
}
864863
}
865864
}
866865

866+
TEST(GmmTest, givenInternalHeapOrLinearStreamWhenDebugFlagIsSetThenReturnUncachedType) {
867+
DebugManagerStateRestore restore;
868+
DebugManager.flags.DisableCachingForHeaps.set(true);
869+
870+
auto usage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, false);
871+
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage);
872+
873+
usage = CacheSettingsHelper::getGmmUsageType(AllocationType::LINEAR_STREAM, false);
874+
EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage);
875+
}
876+
867877
TEST_F(GmmTests, whenResourceIsCreatedThenHandleItsOwnership) {
868878
struct MyMockResourecInfo : public GmmResourceInfo {
869879
using GmmResourceInfo::resourceInfo;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,36 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemory
794794
memoryManager->freeGraphicsMemory(allocation);
795795
}
796796

797+
HWTEST_F(WddmMemoryManagerTest, givenInternalHeapOrLinearStreamTypeWhenAllocatingThenSetCorrectUsage) {
798+
auto memoryManager = std::make_unique<MockWddmMemoryManager>(true, false, *executionEnvironment);
799+
800+
rootDeviceEnvironment->executionEnvironment.initializeMemoryManager();
801+
802+
{
803+
MockAllocationProperties properties = {mockRootDeviceIndex, true, 1, AllocationType::INTERNAL_HEAP, mockDeviceBitfield};
804+
805+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr);
806+
807+
ASSERT_NE(nullptr, allocation);
808+
809+
EXPECT_TRUE(allocation->getDefaultGmm()->resourceParams.Usage == GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER);
810+
811+
memoryManager->freeGraphicsMemory(allocation);
812+
}
813+
814+
{
815+
MockAllocationProperties properties = {mockRootDeviceIndex, true, 1, AllocationType::LINEAR_STREAM, mockDeviceBitfield};
816+
817+
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr);
818+
819+
ASSERT_NE(nullptr, allocation);
820+
821+
EXPECT_TRUE(allocation->getDefaultGmm()->resourceParams.Usage == GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER);
822+
823+
memoryManager->freeGraphicsMemory(allocation);
824+
}
825+
}
826+
797827
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemoryWithSetAllocattionPropertisWithAllocationTypeBufferIsCalledThenIsRendeCompressedFalseAndCorrectAddressRange) {
798828
void *ptr = reinterpret_cast<void *>(0x1001);
799829
auto size = MemoryConstants::pageSize;

shared/source/gmm_helper/cache_settings_helper.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,44 @@
77

88
#include "shared/source/gmm_helper/cache_settings_helper.h"
99

10+
#include "shared/source/debug_settings/debug_settings_manager.h"
1011
#include "shared/source/memory_manager/allocation_type.h"
1112

1213
namespace NEO {
1314

14-
namespace CacheSettingsHelper {
15-
GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached) {
15+
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType allocationType, bool forceUncached) {
1616
if (forceUncached) {
17-
return (allocationType == AllocationType::PREEMPTION) ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC
18-
: GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
17+
return getDefaultUsageTypeWithCachingDisabled(allocationType);
18+
} else {
19+
return getDefaultUsageTypeWithCachingEnabled(allocationType);
1920
}
21+
}
2022

21-
if (allocationType == AllocationType::IMAGE) {
23+
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType) {
24+
switch (allocationType) {
25+
case AllocationType::IMAGE:
2226
return GMM_RESOURCE_USAGE_OCL_IMAGE;
27+
case AllocationType::INTERNAL_HEAP:
28+
case AllocationType::LINEAR_STREAM:
29+
if (DebugManager.flags.DisableCachingForHeaps.get()) {
30+
return getDefaultUsageTypeWithCachingDisabled(allocationType);
31+
}
32+
return GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER;
33+
default:
34+
return GMM_RESOURCE_USAGE_OCL_BUFFER;
2335
}
36+
}
2437

25-
return GMM_RESOURCE_USAGE_OCL_BUFFER;
38+
GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType) {
39+
switch (allocationType) {
40+
case AllocationType::PREEMPTION:
41+
return GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
42+
case AllocationType::INTERNAL_HEAP:
43+
case AllocationType::LINEAR_STREAM:
44+
return GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED;
45+
default:
46+
return GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
47+
}
2648
}
27-
} // namespace CacheSettingsHelper
49+
2850
} // namespace NEO

shared/source/gmm_helper/cache_settings_helper.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
namespace NEO {
1212
enum class AllocationType;
1313

14-
namespace CacheSettingsHelper {
15-
GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached);
16-
}
14+
struct CacheSettingsHelper {
15+
static GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached);
16+
17+
protected:
18+
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType);
19+
static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType);
20+
};
1721
} // namespace NEO

shared/source/helpers/state_base_address_base.inl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "shared/source/command_stream/memory_compression_state.h"
9+
#include "shared/source/gmm_helper/cache_settings_helper.h"
910
#include "shared/source/gmm_helper/gmm_helper.h"
1011
#include "shared/source/helpers/cache_policy.h"
1112
#include "shared/source/helpers/constants.h"
@@ -75,7 +76,10 @@ void StateBaseAddressHelper<GfxFamily>::programStateBaseAddress(
7576
stateBaseAddress->setInstructionBaseAddress(instructionHeapBaseAddress);
7677
stateBaseAddress->setInstructionBufferSizeModifyEnable(true);
7778
stateBaseAddress->setInstructionBufferSize(MemoryConstants::sizeOf4GBinPageEntities);
78-
stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER));
79+
80+
auto resourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get());
81+
82+
stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(resourceUsage));
7983
}
8084

8185
if (setGeneralStateBaseAddress) {

shared/source/helpers/state_base_address_xehp_and_later.inl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* Copyright (C) 2021 Intel Corporation
2+
* Copyright (C) 2021-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "shared/source/command_stream/csr_definitions.h"
99
#include "shared/source/debug_settings/debug_settings_manager.h"
10+
#include "shared/source/gmm_helper/cache_settings_helper.h"
1011
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
1112
#include "shared/source/helpers/api_specific_config.h"
1213
#include "shared/source/helpers/state_base_address_base.inl"
@@ -52,20 +53,14 @@ void StateBaseAddressHelper<GfxFamily>::appendStateBaseAddressParameters(
5253

5354
stateBaseAddress->setBindlessSamplerStateBaseAddressModifyEnable(true);
5455

55-
auto l3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER;
56-
auto l1L3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC;
56+
auto heapResourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get());
57+
auto heapMocsValue = gmmHelper->getMOCS(heapResourceUsage);
5758

58-
if (DebugManager.flags.DisableCachingForHeaps.get()) {
59-
l3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED;
60-
l1L3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED;
61-
stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED));
62-
}
63-
64-
stateBaseAddress->setSurfaceStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy));
65-
stateBaseAddress->setDynamicStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy));
66-
stateBaseAddress->setGeneralStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy));
67-
stateBaseAddress->setBindlessSurfaceStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy));
68-
stateBaseAddress->setBindlessSamplerStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy));
59+
stateBaseAddress->setSurfaceStateMemoryObjectControlState(heapMocsValue);
60+
stateBaseAddress->setDynamicStateMemoryObjectControlState(heapMocsValue);
61+
stateBaseAddress->setGeneralStateMemoryObjectControlState(heapMocsValue);
62+
stateBaseAddress->setBindlessSurfaceStateMemoryObjectControlState(heapMocsValue);
63+
stateBaseAddress->setBindlessSamplerStateMemoryObjectControlState(heapMocsValue);
6964

7065
bool enableMultiGpuAtomics = isMultiOsContextCapable;
7166
if (DebugManager.flags.EnableMultiGpuAtomicsOptimization.get()) {

0 commit comments

Comments
 (0)