From f5575a13709d8f3ef2e9ff438fe51ea48a767159 Mon Sep 17 00:00:00 2001 From: Compute-Runtime-Validation Date: Fri, 23 Sep 2022 20:04:46 +0200 Subject: [PATCH] Revert "Remove fallback path for PAT index programming" This reverts commit faf8d51f6db4fb395a9b2d6a7cf2a93340aed542. Signed-off-by: Compute-Runtime-Validation --- .../unit_test/helpers/hw_helper_tests.cpp | 6 ++ .../xe_hpc_core/excludes_ocl_xe_hpc_core.cpp | 1 + .../hw_helper_tests_xe_hpc_core.cpp | 6 ++ shared/source/gmm_helper/CMakeLists.txt | 1 + .../client_context/gmm_client_context.cpp | 4 -- .../gmm_client_context_extra.cpp | 16 +++++ shared/source/helpers/hw_helper.h | 2 + shared/source/helpers/hw_helper_base.inl | 6 ++ shared/source/os_interface/linux/drm_neo.cpp | 4 +- .../xe_hpc_core/hw_helper_xe_hpc_core.cpp | 5 ++ .../drm_residency_handler_prelim_tests.cpp | 67 ++++++++++++++++++- 11 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp diff --git a/opencl/test/unit_test/helpers/hw_helper_tests.cpp b/opencl/test/unit_test/helpers/hw_helper_tests.cpp index 32d2b9e257a2f..da97a84bcc353 100644 --- a/opencl/test/unit_test/helpers/hw_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hw_helper_tests.cpp @@ -1456,6 +1456,12 @@ HWTEST_F(HwHelperTest, GivenHwInfoWhenGetBatchBufferEndReferenceCalledThenCorrec EXPECT_EQ(hwHelper.getBatchBufferEndReference(), reinterpret_cast(&FamilyType::cmdInitBatchBufferEnd)); } +HWTEST_F(HwHelperTest, givenHwHelperWhenAskingForPatIndexWaThenReturnFalse) { + const auto &hwHelper = HwHelper::get(renderCoreFamily); + + EXPECT_FALSE(hwHelper.isPatIndexFallbackWaRequired()); +} + HWTEST_F(HwHelperTest, givenHwHelperWhenPassingCopyEngineTypeThenItsCopyOnly) { EXPECT_TRUE(EngineHelper::isCopyOnlyEngineType(EngineGroupType::Copy)); } diff --git a/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp b/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp index 4871c2b594fe8..8b114e9d31feb 100644 --- a/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp +++ b/opencl/test/unit_test/xe_hpc_core/excludes_ocl_xe_hpc_core.cpp @@ -52,3 +52,4 @@ HWTEST_EXCLUDE_PRODUCT(CommandStreamReceiverFlushTaskTests, givenOverrideThreadA HWTEST_EXCLUDE_PRODUCT(XeHPAndLaterAubCommandStreamReceiverWithoutFixtureTests, GivenCopyHostPtrAndHostNoAccessAndReadOnlyFlagsWhenAllocatingBufferThenAllocationIsCopiedToEveryTile, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenRingBufferAllocationWhenGetAllocationDataIsCalledThenItHasProperFieldsSet, IGFX_XE_HPC_CORE); HWTEST_EXCLUDE_PRODUCT(GetAllocationDataTestHw, givenSemaphoreBufferAllocationWhenGetAllocationDataIsCalledThenItHasProperFieldsSet, IGFX_XE_HPC_CORE); +HWTEST_EXCLUDE_PRODUCT(HwHelperTest, givenHwHelperWhenAskingForPatIndexWaThenReturnFalse, IGFX_XE_HPC_CORE); diff --git a/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp b/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp index e0fbe125001a2..970dd12f2a93c 100644 --- a/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp +++ b/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp @@ -826,3 +826,9 @@ XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, givenCommandBufferAllocationWhenSetExt XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, WhenGettingDeviceIpVersionThenMakeCorrectDeviceIpVersion) { EXPECT_EQ(ClHwHelperMock::makeDeviceIpVersion(12, 8, 1), ClHwHelper::get(renderCoreFamily).getDeviceIpVersion(*defaultHwInfo)); } + +XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, givenHwHelperWhenAskingForPatIndexWaThenReturnTrue) { + const auto &hwHelper = HwHelper::get(renderCoreFamily); + + EXPECT_TRUE(hwHelper.isPatIndexFallbackWaRequired()); +} diff --git a/shared/source/gmm_helper/CMakeLists.txt b/shared/source/gmm_helper/CMakeLists.txt index d7f59ddcaf290..57381ebf00ac8 100644 --- a/shared/source/gmm_helper/CMakeLists.txt +++ b/shared/source/gmm_helper/CMakeLists.txt @@ -7,6 +7,7 @@ set(NEO_CORE_GMM_HELPER ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}resource_info_${DRIVER_MODEL}.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/client_context${BRANCH_DIR_SUFFIX}/gmm_client_context_extra.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.h ${CMAKE_CURRENT_SOURCE_DIR}/cache_settings_helper.cpp diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.cpp b/shared/source/gmm_helper/client_context/gmm_client_context.cpp index fe20c3a70e170..37e6c22113581 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context.cpp @@ -79,8 +79,4 @@ void GmmClientContext::setGmmDeviceInfo(GMM_DEVICE_INFO *deviceInfo) { clientContext->GmmSetDeviceInfo(deviceInfo); } -uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage) { - return clientContext->CachePolicyGetPATIndex(gmmResourceInfo, usage, nullptr, false); -} - } // namespace NEO diff --git a/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp b/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp new file mode 100644 index 0000000000000..f89c8631541b8 --- /dev/null +++ b/shared/source/gmm_helper/client_context/gmm_client_context_extra.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/client_context/gmm_client_context.h" + +namespace NEO { + +uint32_t GmmClientContext::cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage) { + return 0; +} + +} // namespace NEO diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index fc4bf7ab19d05..6e8736c209907 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -156,6 +156,7 @@ class HwHelper { virtual size_t getBatchBufferEndSize() const = 0; virtual const void *getBatchBufferEndReference() const = 0; virtual bool isPlatformFlushTaskEnabled(const NEO::HardwareInfo &hwInfo) const = 0; + virtual bool isPatIndexFallbackWaRequired() const = 0; virtual uint32_t getMinimalScratchSpaceSize() const = 0; protected: @@ -396,6 +397,7 @@ class HwHelperHw : public HwHelper { size_t getBatchBufferEndSize() const override; const void *getBatchBufferEndReference() const override; bool isPlatformFlushTaskEnabled(const NEO::HardwareInfo &hwInfo) const override; + bool isPatIndexFallbackWaRequired() const override; uint32_t getMinimalScratchSpaceSize() const override; protected: diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index b9acd380ae781..5c4c4940af438 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -712,4 +712,10 @@ uint64_t HwHelperHw::getPatIndex(CacheRegion cacheRegion, CachePolicy return -1; } + +template +bool HwHelperHw::isPatIndexFallbackWaRequired() const { + return false; +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index ff0b0611c29a8..1b6f19efbbdde 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -1304,13 +1304,11 @@ uint64_t Drm::getPatIndex(Gmm *gmm, AllocationType allocationType, CacheRegion c uint64_t patIndex = rootDeviceEnvironment.getGmmClientContext()->cachePolicyGetPATIndex(resourceInfo, usageType); - UNRECOVERABLE_IF(patIndex == static_cast(GMM_PAT_ERROR)); - if (DebugManager.flags.ClosEnabled.get() != -1) { closEnabled = !!DebugManager.flags.ClosEnabled.get(); } - if (closEnabled) { + if (patIndex == static_cast(GMM_PAT_ERROR) || closEnabled || hwHelper.isPatIndexFallbackWaRequired()) { patIndex = hwHelper.getPatIndex(cacheRegion, cachePolicy); } diff --git a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp index 9cd74a743c8ca..ecf5755265100 100644 --- a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp @@ -437,6 +437,11 @@ uint64_t HwHelperHw::getPatIndex(CacheRegion cacheRegion, CachePolicy ca return (static_cast(cachePolicy) + (static_cast(cacheRegion) * 2)); } +template <> +bool HwHelperHw::isPatIndexFallbackWaRequired() const { + return true; +} + } // namespace NEO #include "shared/source/helpers/hw_helper_pvc_and_later.inl" diff --git a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp b/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp index 2dc0eeffeb95c..8042a8b6cc345 100644 --- a/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/drm_residency_handler_prelim_tests.cpp @@ -739,6 +739,9 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen if (debugFlag == 0 || !closSupported || debugFlag == -1) { auto expectedIndex = static_cast(MockGmmClientContextBase::MockPatIndex::cached); + if (hwHelper.isPatIndexFallbackWaRequired()) { + expectedIndex = hwHelper.getPatIndex(CacheRegion::Default, CachePolicy::WriteBack); + } EXPECT_EQ(expectedIndex, mock->context.receivedVmBindPatIndex.value()); @@ -753,7 +756,51 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexProgrammingEnabledWhen } } -HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorAndUncachedDebugFlagSetWhenGetPatIndexCalledThenAbort) { +HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorWhenVmBindCalledThenSetDefaultPatIndexExtension) { + DebugManager.flags.UseVmBind.set(1); + mock->bindAvailable = true; + + auto csr = std::make_unique>(*executionEnvironment, 0, DeviceBitfield(1)); + auto osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor()); + csr->setupContext(*osContext); + + auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); + auto hwInfoConfig = HwInfoConfig::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily); + + bool closSupported = (hwHelper.getNumCacheRegions() > 0); + bool patIndexProgrammingSupported = hwInfoConfig->isVmBindPatIndexProgrammingSupported(); + + if (!closSupported || !patIndexProgrammingSupported) { + GTEST_SKIP(); + } + + uint64_t gpuAddress = 0x123000; + size_t size = 1; + BufferObject bo(mock, static_cast(MockGmmClientContextBase::MockPatIndex::cached), 0, 1, 1); + DrmAllocation allocation(0, 1, AllocationType::BUFFER, &bo, nullptr, gpuAddress, size, MemoryPool::System4KBPages); + + auto allocationPtr = static_cast(&allocation); + + static_cast(executionEnvironment->rootDeviceEnvironments[0]->getGmmClientContext())->returnErrorOnPatIndexQuery = true; + + for (int32_t debugFlag : {-1, 0, 1}) { + DebugManager.flags.ClosEnabled.set(debugFlag); + + mock->context.receivedVmBindPatIndex.reset(); + mock->context.receivedVmUnbindPatIndex.reset(); + + bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false)); + + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); + + EXPECT_EQ(3u, mock->context.receivedVmBindPatIndex.value()); + + operationHandler->evict(device, allocation); + EXPECT_EQ(3u, mock->context.receivedVmUnbindPatIndex.value()); + } +} + +HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorAndUncachedDebugFlagSetWhenVmBindCalledThenSetDefaultPatIndexExtension) { DebugManager.flags.UseVmBind.set(1); DebugManager.flags.ForceAllResourcesUncached.set(1); mock->bindAvailable = true; @@ -774,12 +821,24 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenPatIndexErrorAndUncachedDebugF static_cast(executionEnvironment->rootDeviceEnvironments[0]->getGmmClientContext())->returnErrorOnPatIndexQuery = true; + mock->context.receivedVmBindPatIndex.reset(); + mock->context.receivedVmUnbindPatIndex.reset(); + uint64_t gpuAddress = 0x123000; size_t size = 1; BufferObject bo(mock, static_cast(MockGmmClientContextBase::MockPatIndex::cached), 0, 1, 1); DrmAllocation allocation(0, 1, AllocationType::BUFFER, &bo, nullptr, gpuAddress, size, MemoryPool::System4KBPages); - EXPECT_ANY_THROW(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false)); + bo.setPatIndex(mock->getPatIndex(allocation.getDefaultGmm(), allocation.getAllocationType(), CacheRegion::Default, CachePolicy::WriteBack, false)); + + auto allocationPtr = static_cast(&allocation); + + operationHandler->makeResident(device, ArrayRef(&allocationPtr, 1)); + + EXPECT_EQ(0u, mock->context.receivedVmBindPatIndex.value()); + + operationHandler->evict(device, allocation); + EXPECT_EQ(0u, mock->context.receivedVmUnbindPatIndex.value()); } HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenUncachedDebugFlagSetWhenVmBindCalledThenSetCorrectPatIndexExtension) { @@ -793,6 +852,7 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenUncachedDebugFlagSetWhenVmBind auto timestampStorageAlloc = csr->getTimestampPacketAllocator()->getTag()->getBaseGraphicsAllocation()->getDefaultGraphicsAllocation(); + auto &hwHelper = HwHelper::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eRenderCoreFamily); auto hwInfoConfig = HwInfoConfig::get(executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo()->platform.eProductFamily); if (!hwInfoConfig->isVmBindPatIndexProgrammingSupported()) { @@ -805,6 +865,9 @@ HWTEST_F(DrmMemoryOperationsHandlerBindTest, givenUncachedDebugFlagSetWhenVmBind operationHandler->makeResident(device, ArrayRef(×tampStorageAlloc, 1)); auto expectedIndex = static_cast(MockGmmClientContextBase::MockPatIndex::uncached); + if (hwHelper.isPatIndexFallbackWaRequired()) { + expectedIndex = hwHelper.getPatIndex(CacheRegion::Default, CachePolicy::Uncached); + } EXPECT_EQ(expectedIndex, mock->context.receivedVmBindPatIndex.value());