Skip to content

Commit d19cab1

Browse files
Add new wddm eviction parameter
Related-To: NEO-7179 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent a12c138 commit d19cab1

File tree

10 files changed

+50
-18
lines changed

10 files changed

+50
-18
lines changed

opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ TEST_F(Wddm20Tests, WhenMakingResidentAndEvictingThenReturnIsCorrect) {
520520
EXPECT_TRUE(error);
521521

522522
uint64_t sizeToTrim;
523-
error = wddm->evict(&allocation.getHandles()[0], allocation.getNumGmms(), sizeToTrim);
523+
error = wddm->evict(&allocation.getHandles()[0], allocation.getNumGmms(), sizeToTrim, true);
524524
EXPECT_TRUE(error);
525525

526526
auto monitoredFence = osContext->getResidencyController().getMonitoredFence();
@@ -814,7 +814,7 @@ TEST_F(Wddm20Tests, GivenMultipleHandlesWhenMakingResidentThenBytesToTrimIsCorre
814814
EXPECT_EQ(gdi->getMakeResidentArg().NumBytesToTrim, bytesToTrim);
815815
}
816816

817-
TEST_F(Wddm20Tests, WhenMakingNonResidentThenEvictIsCalled) {
817+
TEST_F(Wddm20Tests, WhenMakingNonResidentAndEvictNotNeededThenEvictIsCalledWithProperFlagSet) {
818818
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
819819

820820
gdi->getEvictArg().AllocationList = nullptr;
@@ -825,12 +825,33 @@ TEST_F(Wddm20Tests, WhenMakingNonResidentThenEvictIsCalled) {
825825
wddm->callBaseEvict = true;
826826

827827
uint64_t sizeToTrim = 10;
828-
wddm->evict(&handle, 1, sizeToTrim);
828+
wddm->evict(&handle, 1, sizeToTrim, false);
829829

830830
EXPECT_EQ(1u, gdi->getEvictArg().NumAllocations);
831831
EXPECT_EQ(&handle, gdi->getEvictArg().AllocationList);
832832
EXPECT_EQ(wddm->getDeviceHandle(), gdi->getEvictArg().hDevice);
833833
EXPECT_EQ(0u, gdi->getEvictArg().NumBytesToTrim);
834+
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
835+
}
836+
837+
TEST_F(Wddm20Tests, WhenMakingNonResidentAndEvictNeededThenEvictIsCalledWithProperFlagSet) {
838+
D3DKMT_HANDLE handle = (D3DKMT_HANDLE)0x1234;
839+
840+
gdi->getEvictArg().AllocationList = nullptr;
841+
gdi->getEvictArg().Flags.Value = 0;
842+
gdi->getEvictArg().hDevice = 0;
843+
gdi->getEvictArg().NumAllocations = 0;
844+
gdi->getEvictArg().NumBytesToTrim = 20;
845+
wddm->callBaseEvict = true;
846+
847+
uint64_t sizeToTrim = 10;
848+
wddm->evict(&handle, 1, sizeToTrim, true);
849+
850+
EXPECT_EQ(1u, gdi->getEvictArg().NumAllocations);
851+
EXPECT_EQ(&handle, gdi->getEvictArg().AllocationList);
852+
EXPECT_EQ(wddm->getDeviceHandle(), gdi->getEvictArg().hDevice);
853+
EXPECT_EQ(0u, gdi->getEvictArg().NumBytesToTrim);
854+
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
834855
}
835856

836857
TEST_F(Wddm20Tests, givenDestroyAllocationWhenItIsCalledThenAllocationIsPassedToDestroyAllocation) {
@@ -1072,11 +1093,13 @@ TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryR
10721093
allocation.handle = 0x3;
10731094
WddmMock mockWddm(*executionEnvironment->rootDeviceEnvironments[0]);
10741095
mockWddm.makeResidentStatus = false;
1096+
mockWddm.callBaseEvict = true;
10751097
auto mockTemporaryResources = static_cast<MockWddmResidentAllocationsContainer *>(mockWddm.temporaryResources.get());
10761098
mockTemporaryResources->resourceHandles.push_back(allocation.handle);
10771099
mockWddm.temporaryResources->makeResidentResource(allocation.handle, 0x1000);
10781100
EXPECT_EQ(2u, mockTemporaryResources->evictAllResourcesResult.called);
10791101
EXPECT_EQ(1u, mockWddm.evictResult.called);
1102+
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
10801103
EXPECT_EQ(allocation.handle, mockWddm.makeResidentResult.handlePack[0]);
10811104
EXPECT_EQ(3u, mockWddm.makeResidentResult.called);
10821105
}

opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotifyE
128128
MockWddmAllocation allocation(rootDeviceEnvironment->getGmmHelper());
129129
uint64_t sizeToTrim;
130130

131-
wddmWithKmDafMock->evict(&allocation.handle, 1, sizeToTrim);
131+
wddmWithKmDafMock->evict(&allocation.handle, 1, sizeToTrim, true);
132132

133133
EXPECT_EQ(wddmWithKmDafMock->featureTable->flags.ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyEvictParametrization.ftrKmdDaf);
134134
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyEvictParametrization.hAdapter);

opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
516516
residencyController->getMonitoredFence().currentFenceValue = 20;
517517

518518
wddm->evictResult.called = 0;
519+
wddm->callBaseEvict = true;
519520

520521
residencyController->addToTrimCandidateList(&allocation1);
521522
residencyController->addToTrimCandidateList(&allocation2);
@@ -524,6 +525,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, givenNotUsedAllocationsFromPreviousPe
524525

525526
// 2 allocations evicted
526527
EXPECT_EQ(2u, wddm->evictResult.called);
528+
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
527529
// removed from trim candidate list
528530
EXPECT_EQ(0u, residencyController->peekTrimCandidateList().size());
529531
// marked nonresident
@@ -601,13 +603,15 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, givenTripleAllocation
601603
residencyController->getMonitoredFence().currentFenceValue = 20;
602604

603605
wddm->evictResult.called = 0;
606+
wddm->callBaseEvict = true;
604607

605608
residencyController->addToTrimCandidateList(allocationTriple);
606609

607610
residencyController->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
608611

609612
// 2 fragments evicted with one call
610613
EXPECT_EQ(1u, wddm->evictResult.called);
614+
EXPECT_EQ(1u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
611615
// marked nonresident
612616
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
613617
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]);
@@ -672,6 +676,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
672676
residencyController->getMonitoredFence().currentFenceValue = 1;
673677

674678
wddm->evictResult.called = 0;
679+
wddm->callBaseEvict = true;
675680

676681
residencyController->addToTrimCandidateList(&allocation1);
677682
residencyController->addToTrimCandidateList(&allocation2);
@@ -680,6 +685,7 @@ TEST_F(WddmResidencyControllerWithGdiTest, WhenTrimmingToBudgetThenAllDoneAlloca
680685
residencyController->trimResidencyToBudget(3 * 4096);
681686

682687
EXPECT_EQ(2u, wddm->evictResult.called);
688+
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
683689

684690
EXPECT_EQ(1u, residencyController->peekTrimCandidatesCount());
685691
residencyController->compactTrimCandidateList();
@@ -853,11 +859,11 @@ TEST_F(WddmResidencyControllerWithGdiAndMemoryManagerTest, WhenTrimmingToBudgetT
853859
residencyController->getMonitoredFence().currentFenceValue = 2;
854860

855861
wddm->evictResult.called = 0;
856-
862+
wddm->callBaseEvict = true;
857863
residencyController->trimResidencyToBudget(3 * 4096);
858864

859865
EXPECT_EQ(2u, wddm->evictResult.called);
860-
866+
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
861867
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[0].residency->resident[osContextId]);
862868
EXPECT_TRUE(allocationTriple->fragmentsStorage.fragmentStorageData[1].residency->resident[osContextId]);
863869
EXPECT_FALSE(allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident[osContextId]);

opencl/test/unit_test/os_interface/windows/wddm_residency_handler_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenMakingResiden
7575
}
7676

7777
TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocationWhenEvictingResidentAllocationThenEvictCalled) {
78+
wddm->callBaseEvict = true;
7879
EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS);
7980
EXPECT_EQ(wddmMemoryOperationsHandler->evict(nullptr, *wddmAllocation), MemoryOperationsStatus::SUCCESS);
81+
EXPECT_EQ(0u, gdi->getEvictArg().Flags.EvictOnlyIfNecessary);
8082
EXPECT_EQ(wddmMemoryOperationsHandler->isResident(nullptr, *wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND);
8183
}
8284

shared/source/os_interface/windows/trim_callback.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS
7070

7171
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
7272
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict allocation: default handle =", wddmAllocation->getDefaultHandle(), "lastFence =", wddmAllocation->getResidencyData().getFenceValueForContextId(osContextId));
73-
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim);
73+
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim, false);
7474
}
7575

7676
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
@@ -84,7 +84,7 @@ void WddmResidencyController::trimResidency(const D3DDDI_TRIMRESIDENCYSET_FLAGS
8484
}
8585
}
8686
if (fragmentsToEvict != 0) {
87-
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim);
87+
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim, false);
8888
}
8989
wddmAllocation->getResidencyData().resident[osContextId] = false;
9090

@@ -129,7 +129,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) {
129129
}
130130

131131
if (wddmAllocation->fragmentsStorage.fragmentCount == 0) {
132-
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim);
132+
this->wddm.evict(&wddmAllocation->getHandles()[0], wddmAllocation->getNumGmms(), sizeToTrim, true);
133133
sizeEvicted = wddmAllocation->getAlignedSize();
134134
} else {
135135
auto &fragmentStorageData = wddmAllocation->fragmentsStorage.fragmentStorageData;
@@ -140,7 +140,7 @@ bool WddmResidencyController::trimResidencyToBudget(uint64_t bytes) {
140140
}
141141

142142
if (fragmentsToEvict != 0) {
143-
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim);
143+
this->wddm.evict((D3DKMT_HANDLE *)fragmentEvictHandles, fragmentsToEvict, sizeToTrim, true);
144144

145145
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
146146
if (fragmentStorageData[allocationId].residency->getFenceValueForContextId(osContextId) <= monitoredFence.lastSubmittedFence) {

shared/source/os_interface/windows/wddm/wddm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,14 @@ std::vector<std::unique_ptr<HwDeviceId>> Wddm::discoverDevices(ExecutionEnvironm
359359
return hwDeviceIds;
360360
}
361361

362-
bool Wddm::evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim) {
362+
bool Wddm::evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim, bool evictNeeded) {
363363
NTSTATUS status = STATUS_SUCCESS;
364364
D3DKMT_EVICT evict = {};
365365
evict.AllocationList = handleList;
366366
evict.hDevice = device;
367367
evict.NumAllocations = numOfHandles;
368368
evict.NumBytesToTrim = 0;
369+
evict.Flags.EvictOnlyIfNecessary = evictNeeded ? 0 : 1;
369370

370371
status = getGdi()->evict(&evict);
371372

shared/source/os_interface/windows/wddm/wddm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Wddm : public DriverModel {
7070
static Wddm *createWddm(std::unique_ptr<HwDeviceIdWddm> &&hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
7171
bool init();
7272

73-
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim);
73+
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim, bool evictNeeded);
7474
MOCKABLE_VIRTUAL bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize);
7575
MOCKABLE_VIRTUAL bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr);
7676
bool mapGpuVirtualAddress(AllocationStorageData *allocationStorageData);

shared/source/os_interface/windows/wddm_residency_allocations_container.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 Intel Corporation
2+
* Copyright (C) 2019-2022 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -36,7 +36,7 @@ MemoryOperationsStatus WddmResidentAllocationsContainer::evictAllResourcesNoLock
3636
}
3737
uint64_t sizeToTrim = 0;
3838
uint32_t evictedResources = static_cast<uint32_t>(resourcesToEvict.size());
39-
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim);
39+
bool success = wddm->evict(resourcesToEvict.data(), evictedResources, sizeToTrim, true);
4040
return success ? MemoryOperationsStatus::SUCCESS : MemoryOperationsStatus::FAILED;
4141
}
4242

@@ -54,7 +54,7 @@ MemoryOperationsStatus WddmResidentAllocationsContainer::evictResources(const D3
5454
UNRECOVERABLE_IF(distance + count > resourceHandles.size());
5555
resourceHandles.erase(position, position + count);
5656
uint64_t sizeToTrim = 0;
57-
if (!wddm->evict(handles, count, sizeToTrim)) {
57+
if (!wddm->evict(handles, count, sizeToTrim, true)) {
5858
return MemoryOperationsStatus::FAILED;
5959
}
6060
return MemoryOperationsStatus::SUCCESS;

shared/test/common/mocks/mock_wddm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ bool WddmMock::makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool c
5959
}
6060
return makeResidentStatus;
6161
}
62-
bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) {
62+
bool WddmMock::evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim, bool evictNeeded) {
6363
evictResult.called++;
6464
if (callBaseEvict) {
65-
evictStatus = Wddm::evict(handles, num, sizeToTrim);
65+
evictStatus = Wddm::evict(handles, num, sizeToTrim, evictNeeded);
6666
}
6767
return evictStatus;
6868
}

shared/test/common/mocks/mock_wddm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class WddmMock : public Wddm {
124124

125125
void resetGdi(Gdi *gdi);
126126
bool makeResident(const D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim, size_t totalSize) override;
127-
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim) override;
127+
bool evict(const D3DKMT_HANDLE *handles, uint32_t num, uint64_t &sizeToTrim, bool evictNeeded) override;
128128
NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) override;
129129

130130
WddmMockHelpers::MakeResidentCall makeResidentResult;

0 commit comments

Comments
 (0)