From 3a7d7e022c96a66d7da131f02f07dc06b12dfe18 Mon Sep 17 00:00:00 2001 From: Aravind Gopalakrishnan Date: Tue, 1 Apr 2025 23:47:02 +0000 Subject: [PATCH] fix: Add platform support for reservation on svm heap Related-To: GSD-10816 Signed-off-by: Aravind Gopalakrishnan --- level_zero/core/source/context/context_imp.cpp | 7 +++++++ .../test/unit_tests/sources/context/test_context.cpp | 12 ++++++------ shared/source/os_interface/product_helper.h | 1 + shared/source/os_interface/product_helper.inl | 5 +++++ shared/source/os_interface/product_helper_hw.h | 1 + .../xe_hpg_core/windows/product_helper_mtl.cpp | 11 ++++++++++- .../test/common/test_macros/header/common_matchers.h | 1 + .../unit_test/os_interface/product_helper_tests.cpp | 4 ++++ .../windows/product_helper_win_tests.cpp | 4 ++++ 9 files changed, 39 insertions(+), 7 deletions(-) diff --git a/level_zero/core/source/context/context_imp.cpp b/level_zero/core/source/context/context_imp.cpp index 3c8ed6461c..b48a4f74b1 100644 --- a/level_zero/core/source/context/context_imp.cpp +++ b/level_zero/core/source/context/context_imp.cpp @@ -1067,6 +1067,13 @@ ze_result_t ContextImp::reserveVirtualMem(const void *pStart, if (castToUint64(pStart) <= maxCpuVa) { reserveOnSvmHeap = true; } + + bool platformSupportSvmHeapReservation = true; + for (auto &device : this->driverHandle->devices) { + auto &productHelper = device->getNEODevice()->getProductHelper(); + platformSupportSvmHeapReservation &= productHelper.isSvmHeapReservationSupported(); + } + reserveOnSvmHeap &= platformSupportSvmHeapReservation; reserveOnSvmHeap &= NEO::debugManager.flags.EnableReservingInSvmRange.get(); NEO::AddressRange addressRange{}; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index 8c7c986567..6c2dd64502 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1559,7 +1559,7 @@ class ReserveMemoryManagerMock : public NEO::MemoryManager { std::unique_ptr mockAllocation; }; -TEST_F(ContextTest, whenCallingVirtualMemReserveWithPStartInSvmRangeWithSuccessfulAllocationThenSuccessReturned) { +HWTEST2_F(ContextTest, whenCallingVirtualMemReserveWithPStartInSvmRangeWithSuccessfulAllocationThenSuccessReturned, IsNotMTL) { ze_context_handle_t hContext{}; ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; @@ -1763,7 +1763,7 @@ TEST_F(ContextTest, whenUsingOffsetsIntoReservedVirtualMemoryWithMultiplePhysica EXPECT_EQ(ZE_RESULT_SUCCESS, res); } -TEST_F(ContextTest, whenCallingVirtualMemoryReservationWhenOutOfMemoryThenOutOfMemoryReturned) { +HWTEST2_F(ContextTest, whenCallingVirtualMemoryReservationWhenOutOfMemoryThenOutOfMemoryReturned, IsNotMTL) { ze_context_handle_t hContext; ze_context_desc_t desc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr, 0}; @@ -1955,7 +1955,7 @@ class MockCpuInfoOverrideVirtualAddressSize { uint32_t virtualAddressSizeSave = 0; }; -TEST_F(ContextTest, Given32BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) { +HWTEST2_F(ContextTest, Given32BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected, IsNotMTL) { MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(32); ze_context_handle_t hContext; @@ -2000,7 +2000,7 @@ TEST_F(ContextTest, Given32BitCpuAddressWidthWhenCallingVirtualMemoryReservation EXPECT_EQ(ZE_RESULT_SUCCESS, res); } -TEST_F(ContextTest, Given48BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) { +HWTEST2_F(ContextTest, Given48BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected, IsNotMTL) { MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(48); ze_context_handle_t hContext; @@ -2044,7 +2044,7 @@ TEST_F(ContextTest, Given48BitCpuAddressWidthWhenCallingVirtualMemoryReservation EXPECT_EQ(ZE_RESULT_SUCCESS, res); } -TEST_F(ContextTest, Given57BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected) { +HWTEST2_F(ContextTest, Given57BitCpuAddressWidthWhenCallingVirtualMemoryReservationCorrectAllocationMethodIsSelected, IsNotMTL) { MockCpuInfoOverrideVirtualAddressSize overrideCpuInfo(57); ze_context_handle_t hContext; diff --git a/shared/source/os_interface/product_helper.h b/shared/source/os_interface/product_helper.h index 250c8e0b82..6c7fc58cb1 100644 --- a/shared/source/os_interface/product_helper.h +++ b/shared/source/os_interface/product_helper.h @@ -268,6 +268,7 @@ class ProductHelper { virtual bool isL3FlushAfterPostSyncRequired(bool heaplessEnabled) const = 0; virtual void overrideDirectSubmissionTimeouts(std::chrono::microseconds &timeout, std::chrono::microseconds &maxTimeout) const = 0; virtual bool isMisalignedUserPtr2WayCoherent() const = 0; + virtual bool isSvmHeapReservationSupported() const = 0; virtual ~ProductHelper() = default; diff --git a/shared/source/os_interface/product_helper.inl b/shared/source/os_interface/product_helper.inl index 7c24282479..58a1b26257 100644 --- a/shared/source/os_interface/product_helper.inl +++ b/shared/source/os_interface/product_helper.inl @@ -1034,6 +1034,11 @@ bool ProductHelperHw::isMisalignedUserPtr2WayCoherent() const { return false; } +template +bool ProductHelperHw::isSvmHeapReservationSupported() const { + return true; +} + template bool ProductHelperHw::isTimestampWaitSupportedForQueues(bool heaplessEnabled) const { return false; diff --git a/shared/source/os_interface/product_helper_hw.h b/shared/source/os_interface/product_helper_hw.h index bebccef8da..6844e2cc63 100644 --- a/shared/source/os_interface/product_helper_hw.h +++ b/shared/source/os_interface/product_helper_hw.h @@ -205,6 +205,7 @@ class ProductHelperHw : public ProductHelper { bool isL3FlushAfterPostSyncRequired(bool heaplessEnabled) const override; void overrideDirectSubmissionTimeouts(std::chrono::microseconds &timeout, std::chrono::microseconds &maxTimeout) const override; bool isMisalignedUserPtr2WayCoherent() const override; + bool isSvmHeapReservationSupported() const override; ~ProductHelperHw() override = default; diff --git a/shared/source/xe_hpg_core/windows/product_helper_mtl.cpp b/shared/source/xe_hpg_core/windows/product_helper_mtl.cpp index 3beae7b2e0..8f48c6b91c 100644 --- a/shared/source/xe_hpg_core/windows/product_helper_mtl.cpp +++ b/shared/source/xe_hpg_core/windows/product_helper_mtl.cpp @@ -14,4 +14,13 @@ constexpr static auto gfxProduct = IGFX_METEORLAKE; #include "shared/source/xe_hpg_core/xe_lpg/os_agnostic_product_helper_xe_lpg.inl" #include "shared/source/xe_hpg_core/xe_lpg/windows/product_helper_xe_lpg_windows.inl" -template class NEO::ProductHelperHw; +namespace NEO { + +template <> +bool ProductHelperHw::isSvmHeapReservationSupported() const { + return false; +} + +template class ProductHelperHw; + +} // namespace NEO \ No newline at end of file diff --git a/shared/test/common/test_macros/header/common_matchers.h b/shared/test/common/test_macros/header/common_matchers.h index f729701ef2..66da291f01 100644 --- a/shared/test/common/test_macros/header/common_matchers.h +++ b/shared/test/common/test_macros/header/common_matchers.h @@ -79,6 +79,7 @@ using IsAtLeastPVC = IsAtLeastProduct; using IsAtMostPVC = IsAtMostProduct; using IsNotPVC = IsNotWithinProducts; using IsNotDG2 = IsNotWithinProducts; +using IsNotMTL = IsNotWithinProducts; using IsNotPvcOrDg2 = IsNotWithinProducts; using IsAtMostArl = IsAtMostProduct; diff --git a/shared/test/unit_test/os_interface/product_helper_tests.cpp b/shared/test/unit_test/os_interface/product_helper_tests.cpp index 6a6d2e4def..0c1b2b1aef 100644 --- a/shared/test/unit_test/os_interface/product_helper_tests.cpp +++ b/shared/test/unit_test/os_interface/product_helper_tests.cpp @@ -475,6 +475,10 @@ HWTEST2_F(ProductHelperTest, givenProductHelperWhenAskedIfDisableScratchPagesIsS EXPECT_TRUE(productHelper->isDisableScratchPagesRequiredForDebugger()); } +HWTEST2_F(ProductHelperTest, givenProductHelperWhenAskedIfPlatformSupportsSvmHeapReservationThenReturnTrue, IsXeHpcCore) { + EXPECT_TRUE(productHelper->isSvmHeapReservationSupported()); +} + HWTEST_F(ProductHelperTest, givenProductHelperWhenCheckBlitEnqueuePreferredThenReturnTrue) { EXPECT_TRUE(productHelper->blitEnqueuePreferred(false)); } diff --git a/shared/test/unit_test/os_interface/windows/product_helper_win_tests.cpp b/shared/test/unit_test/os_interface/windows/product_helper_win_tests.cpp index d2601c2e2d..9b16d3ba63 100644 --- a/shared/test/unit_test/os_interface/windows/product_helper_win_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/product_helper_win_tests.cpp @@ -93,4 +93,8 @@ HWTEST_F(ProductHelperTestWindows, givenFtrIaCoherencyFlagWhenConfiguringHwInfoT productHelper->configureHwInfoWddm(&initialHwInfo, &outHwInfo, *rootDeviceEnvironment.get()); EXPECT_EQ(initialCoherencyStatus, outHwInfo.capabilityTable.ftrSupportsCoherency); } + +HWTEST2_F(ProductHelperTestWindows, givenProductHelperWhenAskedIfPlatformSupportsSvmHeapReservationThenReturnFalseForMTL, IsMTL) { + EXPECT_FALSE(productHelper->isSvmHeapReservationSupported()); +} } // namespace NEO