From 03d9a205590add1829ca72ba09136e5d84e0ed36 Mon Sep 17 00:00:00 2001 From: "Warchulski, Jaroslaw" Date: Wed, 31 May 2023 13:55:08 +0000 Subject: [PATCH] feature: add debug flag to wait for release memory Related-To: NEO-6766 Signed-off-by: Warchulski, Jaroslaw --- .../debug_settings/debug_variables_base.inl | 1 + .../windows/wddm_residency_controller.cpp | 6 ++- shared/test/common/test_files/igdrcl.config | 1 + .../wddm_residency_controller_tests.cpp | 51 +++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index 8fd1c1ac3d..40f2f9dffe 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -81,6 +81,7 @@ DECLARE_DEBUG_VARIABLE(bool, DontDisableZebinIfVmeUsed, false, "When enabled, dr DECLARE_DEBUG_VARIABLE(bool, AppendMemoryPrefetchForKmdMigratedSharedAllocations, true, "Allow prefetching shared memory to the device associated with the specified command list") DECLARE_DEBUG_VARIABLE(bool, ForceMemoryPrefetchForKmdMigratedSharedAllocations, false, "Force prefetch of shared memory in command queue execute command lists") DECLARE_DEBUG_VARIABLE(bool, ClKhrExternalMemoryExtension, false, "Enable cl_khr_external_memory extension") +DECLARE_DEBUG_VARIABLE(bool, WaitForMemoryRelease, false, "Wait for memory release when out of memory") DECLARE_DEBUG_VARIABLE(std::string, ForceDeviceId, std::string("unk"), "Override device id in AUB/TBX mode") DECLARE_DEBUG_VARIABLE(std::string, FilterDeviceId, std::string("unk"), "Device id filter, adapter matching device id will be opened; ignored when unk") DECLARE_DEBUG_VARIABLE(std::string, FilterBdfPath, std::string("unk"), "Linux-only, BDF path filter, only matching paths will be opened; ignored when unk") diff --git a/shared/source/os_interface/windows/wddm_residency_controller.cpp b/shared/source/os_interface/windows/wddm_residency_controller.cpp index 4565c8849b..8c01ed3fc4 100644 --- a/shared/source/os_interface/windows/wddm_residency_controller.cpp +++ b/shared/source/os_interface/windows/wddm_residency_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -235,7 +235,9 @@ bool WddmResidencyController::makeResidentResidencyAllocations(const ResidencyCo continue; } DEBUG_BREAK_IF(evictionStatus != MemoryOperationsStatus::MEMORY_NOT_FOUND); - result = wddm.makeResident(&handlesForResidency[0], totalHandlesCount, true, &bytesToTrim, totalSize); + do { + result = wddm.makeResident(&handlesForResidency[0], totalHandlesCount, true, &bytesToTrim, totalSize); + } while (DebugManager.flags.WaitForMemoryRelease.get() && result == false); break; } } diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index d782ee9386..f675122c65 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -441,6 +441,7 @@ ForceRunAloneContext = -1 AppendMemoryPrefetchForKmdMigratedSharedAllocations = 1 ForceMemoryPrefetchForKmdMigratedSharedAllocations = 0 ClKhrExternalMemoryExtension = 0 +WaitForMemoryRelease = 0 KMDSupportForCrossTileMigrationPolicy = -1 CreateContextWithAccessCounters = -1 AccessCountersTrigger = -1 diff --git a/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp index d54f08b61e..209d41c5bb 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp @@ -1135,3 +1135,54 @@ TEST_F(WddmResidencyControllerWithMockWddmTest, givenMakeResidentFailsWhenCallin EXPECT_TRUE(residencyController->isMemoryBudgetExhausted()); EXPECT_EQ(2u, wddm->makeResidentResult.called); } + +struct WddmMakeResidentMock : public WddmMock { + WddmMakeResidentMock::WddmMakeResidentMock(RootDeviceEnvironment &rootDeviceEnvironment) : WddmMock(rootDeviceEnvironment){}; + + bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override { + *numberOfBytesToTrim = makeResidentNumberOfBytesToTrim; + makeResidentResult.called++; + + if (makeResidentResult.called > 2) { + return true; + } else { + return false; + } + } +}; + +struct WddmResidencyControllerWithMockWddmMakeResidentTest : public WddmResidencyControllerWithMockWddmTest { + void SetUp() override { + wddm = new WddmMakeResidentMock(*executionEnvironment.rootDeviceEnvironments[0].get()); + auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo); + wddm->init(); + + executionEnvironment.initializeMemoryManager(); + + memoryManager = std::make_unique(executionEnvironment); + + csr.reset(createCommandStream(executionEnvironment, 0u, 1)); + auto &gfxCoreHelper = executionEnvironment.rootDeviceEnvironments[0]->getHelper(); + osContext = memoryManager->createAndRegisterOsContext(csr.get(), EngineDescriptorHelper::getDefaultDescriptor(gfxCoreHelper.getGpgpuEngineInstances(*executionEnvironment.rootDeviceEnvironments[0])[0], + preemptionMode)); + + osContext->incRefInternal(); + residencyController = &static_cast(osContext)->getResidencyController(); + gmmHelper = executionEnvironment.rootDeviceEnvironments[0]->getGmmHelper(); + } +}; + +TEST_F(WddmResidencyControllerWithMockWddmMakeResidentTest, givenMakeResidentFailsWhenCallingMakeResidentResidencyAllocationsThenCallItAgainWithWaitForMemoryReleaseSetToTrue) { + DebugManagerStateRestore restorer{}; + DebugManager.flags.WaitForMemoryRelease.set(1); + + wddm->makeResidentNumberOfBytesToTrim = 4 * 4096; + + MockWddmAllocation allocation1(gmmHelper); + ResidencyContainer residencyPack{&allocation1}; + + bool result = residencyController->makeResidentResidencyAllocations(residencyPack); + + EXPECT_TRUE(result); + EXPECT_EQ(3u, wddm->makeResidentResult.called); +}