From abd90308f32842f049b6309de933791b03c61468 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Tue, 8 Feb 2022 17:15:22 +0000 Subject: [PATCH] CacheSettingsHelper - heaps support Signed-off-by: Bartosz Dunajski --- .../unit_test/gmm_helper/gmm_helper_tests.cpp | 46 +++++++++++-------- .../windows/wddm_memory_manager_tests.cpp | 30 ++++++++++++ .../gmm_helper/cache_settings_helper.cpp | 44 +++++++++++++----- .../source/gmm_helper/cache_settings_helper.h | 10 ++-- .../helpers/state_base_address_base.inl | 8 +++- .../state_base_address_xehp_and_later.inl | 23 ++++------ 6 files changed, 113 insertions(+), 48 deletions(-) diff --git a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp index 7f679245ae..992ad4a101 100644 --- a/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp +++ b/opencl/test/unit_test/gmm_helper/gmm_helper_tests.cpp @@ -840,30 +840,40 @@ TEST(GmmTest, givenAllocationTypeWhenGettingUsageTypeThenReturnCorrectValue) { for (auto forceUncached : {true, false}) { auto usage = CacheSettingsHelper::getGmmUsageType(allocationType, forceUncached); + auto expectedUsage = GMM_RESOURCE_USAGE_UNKNOWN; - if (allocationType == AllocationType::IMAGE) { - if (forceUncached) { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, usage); - } else { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_IMAGE, usage); - } - } else if (allocationType == AllocationType::PREEMPTION) { - if (forceUncached) { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC, usage); - } else { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER, usage); - } - } else { - if (forceUncached) { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED, usage); - } else { - EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_BUFFER, usage); - } + switch (allocationType) { + case AllocationType::IMAGE: + expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_IMAGE; + break; + case AllocationType::PREEMPTION: + expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC : GMM_RESOURCE_USAGE_OCL_BUFFER; + break; + case AllocationType::INTERNAL_HEAP: + case AllocationType::LINEAR_STREAM: + expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER; + break; + default: + expectedUsage = forceUncached ? GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED : GMM_RESOURCE_USAGE_OCL_BUFFER; + break; } + + EXPECT_EQ(expectedUsage, usage); } } } +TEST(GmmTest, givenInternalHeapOrLinearStreamWhenDebugFlagIsSetThenReturnUncachedType) { + DebugManagerStateRestore restore; + DebugManager.flags.DisableCachingForHeaps.set(true); + + auto usage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, false); + EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage); + + usage = CacheSettingsHelper::getGmmUsageType(AllocationType::LINEAR_STREAM, false); + EXPECT_EQ(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED, usage); +} + TEST_F(GmmTests, whenResourceIsCreatedThenHandleItsOwnership) { struct MyMockResourecInfo : public GmmResourceInfo { using GmmResourceInfo::resourceInfo; 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 445e0ad2b9..194cd331a8 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 @@ -794,6 +794,36 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemory memoryManager->freeGraphicsMemory(allocation); } +HWTEST_F(WddmMemoryManagerTest, givenInternalHeapOrLinearStreamTypeWhenAllocatingThenSetCorrectUsage) { + auto memoryManager = std::make_unique(true, false, *executionEnvironment); + + rootDeviceEnvironment->executionEnvironment.initializeMemoryManager(); + + { + MockAllocationProperties properties = {mockRootDeviceIndex, true, 1, AllocationType::INTERNAL_HEAP, mockDeviceBitfield}; + + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); + + ASSERT_NE(nullptr, allocation); + + EXPECT_TRUE(allocation->getDefaultGmm()->resourceParams.Usage == GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER); + + memoryManager->freeGraphicsMemory(allocation); + } + + { + MockAllocationProperties properties = {mockRootDeviceIndex, true, 1, AllocationType::LINEAR_STREAM, mockDeviceBitfield}; + + auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties, nullptr); + + ASSERT_NE(nullptr, allocation); + + EXPECT_TRUE(allocation->getDefaultGmm()->resourceParams.Usage == GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER); + + memoryManager->freeGraphicsMemory(allocation); + } +} + HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenAllocateGraphicsMemoryWithSetAllocattionPropertisWithAllocationTypeBufferIsCalledThenIsRendeCompressedFalseAndCorrectAddressRange) { void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; diff --git a/shared/source/gmm_helper/cache_settings_helper.cpp b/shared/source/gmm_helper/cache_settings_helper.cpp index 962b53ddd0..a297d39cf0 100644 --- a/shared/source/gmm_helper/cache_settings_helper.cpp +++ b/shared/source/gmm_helper/cache_settings_helper.cpp @@ -7,22 +7,44 @@ #include "shared/source/gmm_helper/cache_settings_helper.h" +#include "shared/source/debug_settings/debug_settings_manager.h" #include "shared/source/memory_manager/allocation_type.h" namespace NEO { -namespace CacheSettingsHelper { -GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached) { +GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getGmmUsageType(AllocationType allocationType, bool forceUncached) { if (forceUncached) { - return (allocationType == AllocationType::PREEMPTION) ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC - : GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + return getDefaultUsageTypeWithCachingDisabled(allocationType); + } else { + return getDefaultUsageTypeWithCachingEnabled(allocationType); } - - if (allocationType == AllocationType::IMAGE) { - return GMM_RESOURCE_USAGE_OCL_IMAGE; - } - - return GMM_RESOURCE_USAGE_OCL_BUFFER; } -} // namespace CacheSettingsHelper + +GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType) { + switch (allocationType) { + case AllocationType::IMAGE: + return GMM_RESOURCE_USAGE_OCL_IMAGE; + case AllocationType::INTERNAL_HEAP: + case AllocationType::LINEAR_STREAM: + if (DebugManager.flags.DisableCachingForHeaps.get()) { + return getDefaultUsageTypeWithCachingDisabled(allocationType); + } + return GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER; + default: + return GMM_RESOURCE_USAGE_OCL_BUFFER; + } +} + +GMM_RESOURCE_USAGE_TYPE_ENUM CacheSettingsHelper::getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType) { + switch (allocationType) { + case AllocationType::PREEMPTION: + return GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC; + case AllocationType::INTERNAL_HEAP: + case AllocationType::LINEAR_STREAM: + return GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED; + default: + return GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED; + } +} + } // namespace NEO \ No newline at end of file diff --git a/shared/source/gmm_helper/cache_settings_helper.h b/shared/source/gmm_helper/cache_settings_helper.h index dd82f47383..714aef1856 100644 --- a/shared/source/gmm_helper/cache_settings_helper.h +++ b/shared/source/gmm_helper/cache_settings_helper.h @@ -11,7 +11,11 @@ namespace NEO { enum class AllocationType; -namespace CacheSettingsHelper { -GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached); -} +struct CacheSettingsHelper { + static GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached); + + protected: + static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingEnabled(AllocationType allocationType); + static GMM_RESOURCE_USAGE_TYPE_ENUM getDefaultUsageTypeWithCachingDisabled(AllocationType allocationType); +}; } // namespace NEO \ No newline at end of file diff --git a/shared/source/helpers/state_base_address_base.inl b/shared/source/helpers/state_base_address_base.inl index ca78647b45..85cfd8b57f 100644 --- a/shared/source/helpers/state_base_address_base.inl +++ b/shared/source/helpers/state_base_address_base.inl @@ -1,11 +1,12 @@ /* - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2022 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/command_stream/memory_compression_state.h" +#include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/helpers/cache_policy.h" #include "shared/source/helpers/constants.h" @@ -75,7 +76,10 @@ void StateBaseAddressHelper::programStateBaseAddress( stateBaseAddress->setInstructionBaseAddress(instructionHeapBaseAddress); stateBaseAddress->setInstructionBufferSizeModifyEnable(true); stateBaseAddress->setInstructionBufferSize(MemoryConstants::sizeOf4GBinPageEntities); - stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER)); + + auto resourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get()); + + stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(resourceUsage)); } if (setGeneralStateBaseAddress) { diff --git a/shared/source/helpers/state_base_address_xehp_and_later.inl b/shared/source/helpers/state_base_address_xehp_and_later.inl index 3fe095a9e0..d509ebf8d0 100644 --- a/shared/source/helpers/state_base_address_xehp_and_later.inl +++ b/shared/source/helpers/state_base_address_xehp_and_later.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #include "shared/source/command_stream/csr_definitions.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/gmm_helper/cache_settings_helper.h" #include "shared/source/gmm_helper/client_context/gmm_client_context.h" #include "shared/source/helpers/api_specific_config.h" #include "shared/source/helpers/state_base_address_base.inl" @@ -52,20 +53,14 @@ void StateBaseAddressHelper::appendStateBaseAddressParameters( stateBaseAddress->setBindlessSamplerStateBaseAddressModifyEnable(true); - auto l3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_STATE_HEAP_BUFFER; - auto l1L3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_INLINE_CONST_HDC; + auto heapResourceUsage = CacheSettingsHelper::getGmmUsageType(AllocationType::INTERNAL_HEAP, DebugManager.flags.DisableCachingForHeaps.get()); + auto heapMocsValue = gmmHelper->getMOCS(heapResourceUsage); - if (DebugManager.flags.DisableCachingForHeaps.get()) { - l3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED; - l1L3CacheOnPolicy = GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED; - stateBaseAddress->setInstructionMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_SYSTEM_MEMORY_BUFFER_CACHELINE_MISALIGNED)); - } - - stateBaseAddress->setSurfaceStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy)); - stateBaseAddress->setDynamicStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy)); - stateBaseAddress->setGeneralStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy)); - stateBaseAddress->setBindlessSurfaceStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy)); - stateBaseAddress->setBindlessSamplerStateMemoryObjectControlState(gmmHelper->getMOCS(l3CacheOnPolicy)); + stateBaseAddress->setSurfaceStateMemoryObjectControlState(heapMocsValue); + stateBaseAddress->setDynamicStateMemoryObjectControlState(heapMocsValue); + stateBaseAddress->setGeneralStateMemoryObjectControlState(heapMocsValue); + stateBaseAddress->setBindlessSurfaceStateMemoryObjectControlState(heapMocsValue); + stateBaseAddress->setBindlessSamplerStateMemoryObjectControlState(heapMocsValue); bool enableMultiGpuAtomics = isMultiOsContextCapable; if (DebugManager.flags.EnableMultiGpuAtomicsOptimization.get()) {