From be9775891c2cb63b789d3727917f13b759eef621 Mon Sep 17 00:00:00 2001 From: Andrzej Koska Date: Tue, 3 Jan 2023 18:44:33 +0000 Subject: [PATCH] Narrowing the usDeviceID range for WA This patch narrows down the scope covered by WA to G10 machines only Related-To: NEO-7475 Signed-off-by: Andrzej Koska andrzej.koska@intel.com --- .../dg2/os_agnostic_hw_info_config_dg2.inl | 2 +- .../xe_hpg_core/dg2/hw_helper_tests_dg2.cpp | 20 ++ .../dg2/test_hw_info_config_dg2.cpp | 16 +- .../xe_hpg_core/dg2/windows/CMakeLists.txt | 12 ++ .../windows/wddm_memory_manager_tests_dg2.cpp | 172 ++++++++++++++++++ 5 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 shared/test/unit_test/xe_hpg_core/dg2/windows/CMakeLists.txt create mode 100644 shared/test/unit_test/xe_hpg_core/dg2/windows/wddm_memory_manager_tests_dg2.cpp diff --git a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl index bea86a6d69..446a576c2e 100644 --- a/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl +++ b/shared/source/xe_hpg_core/dg2/os_agnostic_hw_info_config_dg2.inl @@ -123,7 +123,7 @@ bool ProductHelperHw::allowCompression(const HardwareInfo &hwInfo) c template <> LocalMemoryAccessMode ProductHelperHw::getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const { - if (GfxCoreHelper::isWorkaroundRequired(REVISION_A0, REVISION_B, hwInfo, *this)) { + if (DG2::isG10(hwInfo) && GfxCoreHelper::isWorkaroundRequired(REVISION_A0, REVISION_B, hwInfo, *this)) { return LocalMemoryAccessMode::CpuAccessDisallowed; } return LocalMemoryAccessMode::Default; diff --git a/shared/test/unit_test/xe_hpg_core/dg2/hw_helper_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/hw_helper_tests_dg2.cpp index b12dbf1e9e..d0084f7e75 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/hw_helper_tests_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/hw_helper_tests_dg2.cpp @@ -6,6 +6,8 @@ */ #include "shared/source/helpers/hw_helper.h" +#include "shared/source/memory_manager/allocation_properties.h" +#include "shared/source/memory_manager/allocation_type.h" #include "shared/source/xe_hpg_core/hw_cmds_dg2.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/default_hw_info.h" @@ -84,3 +86,21 @@ DG2TEST_F(GfxCoreHelperTestDg2, givenRcsDisabledButDebugVariableSetWhenGetGpgpuE EXPECT_EQ(aub_stream::ENGINE_BCS, engines[7].first); EXPECT_EQ(aub_stream::ENGINE_BCS, engines[8].first); } + +using GfxCoreHelperTests = Test; +DG2TEST_F(GfxCoreHelperTests, givenAllocationTypeInternalHeapWhenSetExtraAllocationDataThenUseSystemMemory) { + HardwareInfo hwInfo = *defaultHwInfo; + + hwInfo.platform.usDeviceID = dg2G10DeviceIds[0]; + auto &gfxCoreHelper = getHelper(); + + constexpr DeviceBitfield singleTileBitfield = 0b0100; + + const AllocationProperties singleTileAllocProperties(0, 1, AllocationType::INTERNAL_HEAP, singleTileBitfield); + + AllocationData allocData; + allocData.flags.useSystemMemory = false; + + gfxCoreHelper.setExtraAllocationData(allocData, singleTileAllocProperties, hwInfo); + EXPECT_TRUE(allocData.flags.useSystemMemory); +} \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp index 0a8c7b6a59..e760b20398 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp +++ b/shared/test/unit_test/xe_hpg_core/dg2/test_hw_info_config_dg2.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Intel Corporation + * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -45,6 +45,7 @@ DG2TEST_F(Dg2ProductHelper, givenDG2WithBSteppingThenMaxThreadsForWorkgroupWAIsN } DG2TEST_F(Dg2ProductHelper, givenSteppingWhenAskingForLocalMemoryAccessModeThenDisallowOnA0) { + pInHwInfo.platform.usDeviceID = dg2G10DeviceIds[0]; pInHwInfo.platform.usRevId = productHelper->getHwRevIdFromStepping(REVISION_A0, pInHwInfo); EXPECT_EQ(LocalMemoryAccessMode::CpuAccessDisallowed, productHelper->getLocalMemoryAccessMode(pInHwInfo)); @@ -85,3 +86,16 @@ DG2TEST_F(Dg2ProductHelper, givenProductHelperWhenGetCommandsStreamPropertiesSup EXPECT_FALSE(productHelper->getPipelineSelectPropertyMediaSamplerDopClockGateSupport()); EXPECT_TRUE(productHelper->getPipelineSelectPropertySystolicModeSupport()); } + +DG2TEST_F(Dg2ProductHelper, givenDG2WhenGettingLocalMemoryAccessModeThenCorrectValueIsReturned) { + + pInHwInfo.platform.usRevId = REVISION_A0; + pInHwInfo.platform.usDeviceID = dg2G10DeviceIds[0]; + EXPECT_EQ(LocalMemoryAccessMode::CpuAccessDisallowed, productHelper->getLocalMemoryAccessMode(pInHwInfo)); + + pInHwInfo.platform.usDeviceID = dg2G11DeviceIds[0]; + EXPECT_EQ(LocalMemoryAccessMode::Default, productHelper->getLocalMemoryAccessMode(pInHwInfo)); + + pInHwInfo.platform.usDeviceID = dg2G12DeviceIds[0]; + EXPECT_EQ(LocalMemoryAccessMode::Default, productHelper->getLocalMemoryAccessMode(pInHwInfo)); +} \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/dg2/windows/CMakeLists.txt b/shared/test/unit_test/xe_hpg_core/dg2/windows/CMakeLists.txt new file mode 100644 index 0000000000..87044c7d4c --- /dev/null +++ b/shared/test/unit_test/xe_hpg_core/dg2/windows/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2023 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(WIN32) + target_sources(neo_shared_tests PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/wddm_memory_manager_tests_dg2.cpp + ) +endif() \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/dg2/windows/wddm_memory_manager_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/windows/wddm_memory_manager_tests_dg2.cpp new file mode 100644 index 0000000000..479dff26a7 --- /dev/null +++ b/shared/test/unit_test/xe_hpg_core/dg2/windows/wddm_memory_manager_tests_dg2.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2020-2023 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/gmm_helper/gmm_helper.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" +#include "shared/test/common/mocks/mock_wddm.h" +#include "shared/test/common/mocks/windows/mock_gmm_memory_base.h" +#include "shared/test/common/os_interface/windows/gdi_dll_fixture.h" +#include "shared/test/common/os_interface/windows/mock_wddm_memory_manager.h" +#include "shared/test/common/test_macros/hw_test.h" + +using namespace NEO; + +using Dg2WddmTest = ::testing::Test; + +DG2TEST_F(Dg2WddmTest, givenG10A0WhenGettingLocalMemoryAccessModeThenCorrectValueIsReturned) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment *rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initGmm(); + WddmMock *wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); + MockGmmMemoryBase *gmmMemory = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); + wddm->init(); + + wddm->gmmMemory.reset(gmmMemory); + + constexpr uint16_t REV_ID_A0 = 0; + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usRevId = REV_ID_A0; + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usDeviceID = dg2G10DeviceIds[0]; + + MockWddmMemoryManager memoryManager = MockWddmMemoryManager(false, true, executionEnvironment); + + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, 4096u, AllocationType::LINEAR_STREAM, mockDeviceBitfield}); + + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(graphicsAllocation->getAllocationType(), AllocationType::LINEAR_STREAM); + auto gpuAddress = graphicsAllocation->getGpuAddress(); + auto gpuAddressEnd = gpuAddress + 4096u; + auto gmmHelper = memoryManager.getGmmHelper(graphicsAllocation->getRootDeviceIndex()); + + EXPECT_NE(MemoryPool::LocalMemory, graphicsAllocation->getMemoryPool()); + EXPECT_FALSE(graphicsAllocation->isLocked()); + auto &partition = wddm->getGfxPartition(); + + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.SVM.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.SVM.Limit)); + + memoryManager.freeGraphicsMemory(graphicsAllocation); +} + +DG2TEST_F(Dg2WddmTest, givenG10B0WhenGettingLocalMemoryAccessModeThenCorrectValueIsReturned) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment *rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initGmm(); + WddmMock *wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); + MockGmmMemoryBase *gmmMemory = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); + wddm->init(); + wddm->gmmMemory.reset(gmmMemory); + + constexpr uint16_t REV_ID_B0 = 4; + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usRevId = REV_ID_B0; + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usDeviceID = dg2G10DeviceIds[0]; + + MockWddmMemoryManager memoryManager = MockWddmMemoryManager(false, true, executionEnvironment); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, 4096u, AllocationType::LINEAR_STREAM, mockDeviceBitfield}); + + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(graphicsAllocation->getAllocationType(), AllocationType::LINEAR_STREAM); + auto gpuAddress = graphicsAllocation->getGpuAddress(); + auto gpuAddressEnd = gpuAddress + 4096u; + auto gmmHelper = memoryManager.getGmmHelper(graphicsAllocation->getRootDeviceIndex()); + + EXPECT_EQ(MemoryPool::LocalMemory, graphicsAllocation->getMemoryPool()); + EXPECT_TRUE(graphicsAllocation->isLocked()); + auto &partition = wddm->getGfxPartition(); + + if (is64bit) { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.Standard64KB.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.Standard64KB.Limit)); + } else { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.SVM.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.SVM.Limit)); + } + + memoryManager.freeGraphicsMemory(graphicsAllocation); +} + +DG2TEST_F(Dg2WddmTest, givenG11WhenGettingLocalMemoryAccessModeThenCorrectValueIsReturned) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment *rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initGmm(); + WddmMock *wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); + MockGmmMemoryBase *gmmMemory = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); + wddm->init(); + wddm->gmmMemory.reset(gmmMemory); + + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usDeviceID = dg2G11DeviceIds[0]; + + MockWddmMemoryManager memoryManager = MockWddmMemoryManager(false, true, executionEnvironment); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, 4096u, AllocationType::LINEAR_STREAM, mockDeviceBitfield}); + + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(graphicsAllocation->getAllocationType(), AllocationType::LINEAR_STREAM); + auto gpuAddress = graphicsAllocation->getGpuAddress(); + auto gpuAddressEnd = gpuAddress + 4096u; + auto gmmHelper = memoryManager.getGmmHelper(graphicsAllocation->getRootDeviceIndex()); + + EXPECT_EQ(MemoryPool::LocalMemory, graphicsAllocation->getMemoryPool()); + EXPECT_TRUE(graphicsAllocation->isLocked()); + auto &partition = wddm->getGfxPartition(); + + if (is64bit) { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.Standard64KB.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.Standard64KB.Limit)); + } else { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.SVM.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.SVM.Limit)); + } + + memoryManager.freeGraphicsMemory(graphicsAllocation); +} + +DG2TEST_F(Dg2WddmTest, givenG12WhenGettingLocalMemoryAccessModeThenCorrectValueIsReturned) { + MockExecutionEnvironment executionEnvironment; + RootDeviceEnvironment *rootDeviceEnvironment = executionEnvironment.rootDeviceEnvironments[0].get(); + rootDeviceEnvironment->initGmm(); + WddmMock *wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); + MockGmmMemoryBase *gmmMemory = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); + rootDeviceEnvironment->osInterface = std::make_unique(); + rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); + wddm->init(); + wddm->gmmMemory.reset(gmmMemory); + + rootDeviceEnvironment->getMutableHardwareInfo()->platform.usDeviceID = dg2G12DeviceIds[0]; + + MockWddmMemoryManager memoryManager = MockWddmMemoryManager(false, true, executionEnvironment); + auto graphicsAllocation = memoryManager.allocateGraphicsMemoryWithProperties({mockRootDeviceIndex, 4096u, AllocationType::LINEAR_STREAM, mockDeviceBitfield}); + + ASSERT_NE(nullptr, graphicsAllocation); + EXPECT_NE(nullptr, graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(graphicsAllocation->getAllocationType(), AllocationType::LINEAR_STREAM); + auto gpuAddress = graphicsAllocation->getGpuAddress(); + auto gpuAddressEnd = gpuAddress + 4096u; + auto gmmHelper = memoryManager.getGmmHelper(graphicsAllocation->getRootDeviceIndex()); + + EXPECT_EQ(MemoryPool::LocalMemory, graphicsAllocation->getMemoryPool()); + EXPECT_TRUE(graphicsAllocation->isLocked()); + auto &partition = wddm->getGfxPartition(); + + if (is64bit) { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.Standard64KB.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.Standard64KB.Limit)); + } else { + EXPECT_GE(gpuAddress, gmmHelper->canonize(partition.SVM.Base)); + EXPECT_LE(gpuAddressEnd, gmmHelper->canonize(partition.SVM.Limit)); + } + + memoryManager.freeGraphicsMemory(graphicsAllocation); +}