diff --git a/core/memory_manager/memory_operations_handler.h b/core/memory_manager/memory_operations_handler.h index fd238667d0..afd54db5ca 100644 --- a/core/memory_manager/memory_operations_handler.h +++ b/core/memory_manager/memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once #include "core/memory_manager/memory_operations_status.h" +#include "core/utilities/arrayref.h" namespace NEO { @@ -17,7 +18,7 @@ class MemoryOperationsHandler { MemoryOperationsHandler() = default; virtual ~MemoryOperationsHandler() = default; - virtual MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) = 0; + virtual MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) = 0; virtual MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) = 0; virtual MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) = 0; }; diff --git a/core/os_interface/aub_memory_operations_handler.cpp b/core/os_interface/aub_memory_operations_handler.cpp index f542303b08..dbf250907e 100644 --- a/core/os_interface/aub_memory_operations_handler.cpp +++ b/core/os_interface/aub_memory_operations_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,14 +18,21 @@ AubMemoryOperationsHandler::AubMemoryOperationsHandler(aub_stream::AubManager *a this->aubManager = aubManager; } -MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(ArrayRef gfxAllocations) { if (!aubManager) { return MemoryOperationsStatus::DEVICE_UNINITIALIZED; } auto lock = acquireLock(resourcesLock); int hint = AubMemDump::DataTypeHintValues::TraceNotype; - aubManager->writeMemory(gfxAllocation.getGpuAddress(), gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize(), gfxAllocation.storageInfo.getMemoryBanks(), hint, gfxAllocation.getUsedPageSize()); - residentAllocations.push_back(&gfxAllocation); + for (const auto &allocation : gfxAllocations) { + aubManager->writeMemory(allocation->getGpuAddress(), + allocation->getUnderlyingBuffer(), + allocation->getUnderlyingBufferSize(), + allocation->storageInfo.getMemoryBanks(), + hint, + allocation->getUsedPageSize()); + residentAllocations.push_back(allocation); + } return MemoryOperationsStatus::SUCCESS; } diff --git a/core/os_interface/aub_memory_operations_handler.h b/core/os_interface/aub_memory_operations_handler.h index 22f1fcd41b..bdd9633908 100644 --- a/core/os_interface/aub_memory_operations_handler.h +++ b/core/os_interface/aub_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -21,7 +21,7 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler { AubMemoryOperationsHandler(aub_stream::AubManager *aubManager); ~AubMemoryOperationsHandler() override = default; - MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; void setAubManager(aub_stream::AubManager *aubManager); diff --git a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp index 2c13ffa911..eaa658e57d 100644 --- a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp +++ b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,7 +13,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) { getMemoryOperationsHandler()->setAubManager(nullptr); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(allocation); + auto result = memoryOperationsInterface->makeResident(ArrayRef(&allocPtr, 1)); EXPECT_EQ(result, MemoryOperationsStatus::DEVICE_UNINITIALIZED); } @@ -21,7 +21,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - auto result = memoryOperationsInterface->makeResident(allocation); + auto result = memoryOperationsInterface->makeResident(ArrayRef(&allocPtr, 1)); EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); EXPECT_TRUE(aubManager.writeMemoryCalled); } @@ -30,7 +30,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAllocationWhenMakeResidentCalledThe MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(allocation); + memoryOperationsInterface->makeResident(ArrayRef(&allocPtr, 1)); EXPECT_EQ(aubManager.hintToWriteMemory, AubMemDump::DataTypeHintValues::TraceNotype); } TEST_F(AubMemoryOperationsHandlerTests, givenNonResidentAllocationWhenIsResidentCalledThenFalseReturned) { @@ -44,7 +44,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenIsResidentCal MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(allocation); + memoryOperationsInterface->makeResident(ArrayRef(&allocPtr, 1)); auto result = memoryOperationsInterface->isResident(allocation); EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); } @@ -59,7 +59,7 @@ TEST_F(AubMemoryOperationsHandlerTests, givenResidentAllocationWhenEvictCalledTh MockAubManager aubManager; getMemoryOperationsHandler()->setAubManager(&aubManager); auto memoryOperationsInterface = getMemoryOperationsHandler(); - memoryOperationsInterface->makeResident(allocation); + memoryOperationsInterface->makeResident(ArrayRef(&allocPtr, 1)); auto result = memoryOperationsInterface->evict(allocation); EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); } \ No newline at end of file diff --git a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h index f11b73fd3b..ed3f44b4ba 100644 --- a/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h +++ b/core/unit_tests/os_interface/aub_memory_operations_handler_tests.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -23,6 +23,8 @@ class AubMemoryOperationsHandlerTests : public ::testing::Test { void SetUp() override { DebugManager.flags.SetCommandStreamReceiver.set(2); residencyHandler = std::unique_ptr(new AubMemoryOperationsHandler(nullptr)); + + allocPtr = &allocation; } AubMemoryOperationsHandler *getMemoryOperationsHandler() { @@ -30,6 +32,7 @@ class AubMemoryOperationsHandlerTests : public ::testing::Test { } MockGraphicsAllocation allocation; + GraphicsAllocation *allocPtr; DebugManagerStateRestore dbgRestore; std::unique_ptr residencyHandler; }; diff --git a/runtime/os_interface/linux/drm_memory_operations_handler.cpp b/runtime/os_interface/linux/drm_memory_operations_handler.cpp index 2d9c25b379..e00d4e07f7 100644 --- a/runtime/os_interface/linux/drm_memory_operations_handler.cpp +++ b/runtime/os_interface/linux/drm_memory_operations_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,7 +12,7 @@ namespace NEO { DrmMemoryOperationsHandler::DrmMemoryOperationsHandler() { } -MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { +MemoryOperationsStatus DrmMemoryOperationsHandler::makeResident(ArrayRef gfxAllocations) { return MemoryOperationsStatus::UNSUPPORTED; } diff --git a/runtime/os_interface/linux/drm_memory_operations_handler.h b/runtime/os_interface/linux/drm_memory_operations_handler.h index 8f60ad1f93..bc623af277 100644 --- a/runtime/os_interface/linux/drm_memory_operations_handler.h +++ b/runtime/os_interface/linux/drm_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -15,7 +15,7 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler { DrmMemoryOperationsHandler(); ~DrmMemoryOperationsHandler() override = default; - MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; }; diff --git a/runtime/os_interface/windows/wddm_memory_operations_handler.cpp b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp index 35ce65f203..f523fdfdbc 100644 --- a/runtime/os_interface/windows/wddm_memory_operations_handler.cpp +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #include "runtime/os_interface/windows/wddm_memory_operations_handler.h" +#include "core/memory_manager/host_ptr_defines.h" +#include "core/utilities/stackvec.h" #include "runtime/os_interface/windows/wddm_allocation.h" #include "runtime/os_interface/windows/wddm_residency_allocations_container.h" @@ -16,19 +18,62 @@ WddmMemoryOperationsHandler::WddmMemoryOperationsHandler(Wddm *wddm) : wddm(wddm residentAllocations = std::make_unique(wddm); } -MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(GraphicsAllocation &gfxAllocation) { - WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); - return residentAllocations->makeResidentResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); +MemoryOperationsStatus WddmMemoryOperationsHandler::makeResident(ArrayRef gfxAllocations) { + uint32_t totalHandlesCount = 0; + constexpr uint32_t stackAllocations = 64; + constexpr uint32_t stackHandlesCount = NEO::maxFragmentsCount * EngineLimits::maxHandleCount * stackAllocations; + StackVec handlesForResidency; + + for (const auto &allocation : gfxAllocations) { + WddmAllocation *wddmAllocation = reinterpret_cast(allocation); + + if (wddmAllocation->fragmentsStorage.fragmentCount > 0) { + for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) { + handlesForResidency[totalHandlesCount++] = wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle; + } + } else { + memcpy_s(&handlesForResidency[totalHandlesCount], + wddmAllocation->getNumHandles() * sizeof(D3DKMT_HANDLE), + wddmAllocation->getHandles().data(), + wddmAllocation->getNumHandles() * sizeof(D3DKMT_HANDLE)); + totalHandlesCount += wddmAllocation->getNumHandles(); + } + } + return residentAllocations->makeResidentResources(handlesForResidency.begin(), totalHandlesCount); } MemoryOperationsStatus WddmMemoryOperationsHandler::evict(GraphicsAllocation &gfxAllocation) { + constexpr uint32_t stackHandlesCount = NEO::maxFragmentsCount * EngineLimits::maxHandleCount; + StackVec handlesForEviction; WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); - return residentAllocations->evictResources(wddmAllocation.getHandles().data(), wddmAllocation.getNumHandles()); + uint32_t totalHandleCount = 0; + if (wddmAllocation.fragmentsStorage.fragmentCount > 0) { + OsHandleStorage &fragmentStorage = wddmAllocation.fragmentsStorage; + + for (uint32_t allocId = 0; allocId < fragmentStorage.fragmentCount; allocId++) { + handlesForEviction.push_back(fragmentStorage.fragmentStorageData[allocId].osHandleStorage->handle); + totalHandleCount++; + } + } else { + const D3DKMT_HANDLE *handlePtr = wddmAllocation.getHandles().data(); + size_t handleCount = wddmAllocation.getNumHandles(); + for (uint32_t i = 0; i < handleCount; i++, totalHandleCount++) { + handlesForEviction.push_back(*handlePtr); + handlePtr++; + } + } + return residentAllocations->evictResources(handlesForEviction.begin(), totalHandleCount); } MemoryOperationsStatus WddmMemoryOperationsHandler::isResident(GraphicsAllocation &gfxAllocation) { WddmAllocation &wddmAllocation = reinterpret_cast(gfxAllocation); - return residentAllocations->isAllocationResident(wddmAllocation.getDefaultHandle()); + D3DKMT_HANDLE defaultHandle = 0u; + if (wddmAllocation.fragmentsStorage.fragmentCount > 0) { + defaultHandle = wddmAllocation.fragmentsStorage.fragmentStorageData[0].osHandleStorage->handle; + } else { + defaultHandle = wddmAllocation.getDefaultHandle(); + } + return residentAllocations->isAllocationResident(defaultHandle); } } // namespace NEO diff --git a/runtime/os_interface/windows/wddm_memory_operations_handler.h b/runtime/os_interface/windows/wddm_memory_operations_handler.h index 22dd00c4e2..d3811ce0ff 100644 --- a/runtime/os_interface/windows/wddm_memory_operations_handler.h +++ b/runtime/os_interface/windows/wddm_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -20,7 +20,7 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler { WddmMemoryOperationsHandler(Wddm *wddm); ~WddmMemoryOperationsHandler() override = default; - MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) override; + MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) override; MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) override; MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) override; diff --git a/unit_tests/mocks/mock_memory_operations_handler.h b/unit_tests/mocks/mock_memory_operations_handler.h index a3203800d2..be334f1d1d 100644 --- a/unit_tests/mocks/mock_memory_operations_handler.h +++ b/unit_tests/mocks/mock_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,7 +16,7 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler { public: MockMemoryOperationsHandler() {} virtual ~MockMemoryOperationsHandler() {} - MemoryOperationsStatus makeResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } + MemoryOperationsStatus makeResident(ArrayRef gfxAllocations) { return MemoryOperationsStatus::UNSUPPORTED; } MemoryOperationsStatus evict(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } MemoryOperationsStatus isResident(GraphicsAllocation &gfxAllocation) { return MemoryOperationsStatus::UNSUPPORTED; } }; diff --git a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp index 4d184f8e40..85c98928c7 100644 --- a/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/linux/drm_residency_handler_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Intel Corporation + * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,19 +16,22 @@ using namespace NEO; struct DrmMemoryOperationsHandlerTest : public ::testing::Test { void SetUp() override { drmMemoryOperationsHandler = std::make_unique(); + + allocationPtr = &graphicsAllocation; } MockGraphicsAllocation graphicsAllocation; + GraphicsAllocation *allocationPtr; std::unique_ptr drmMemoryOperationsHandler; }; TEST_F(DrmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentFail) { - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::UNSUPPORTED); EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); } TEST_F(DrmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictFalse) { - EXPECT_EQ(drmMemoryOperationsHandler->makeResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); + EXPECT_EQ(drmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::UNSUPPORTED); EXPECT_EQ(drmMemoryOperationsHandler->evict(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); EXPECT_EQ(drmMemoryOperationsHandler->isResident(graphicsAllocation), MemoryOperationsStatus::UNSUPPORTED); } diff --git a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp index aace714bbf..12d46c5da2 100644 --- a/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_residency_handler_tests.cpp @@ -1,10 +1,11 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "core/utilities/stackvec.h" #include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "test.h" #include "unit_tests/mocks/mock_allocation_properties.h" @@ -18,20 +19,68 @@ struct WddmMemoryOperationsHandlerTest : public WddmTest { void SetUp() override { WddmTest::SetUp(); wddmMemoryOperationsHandler = std::make_unique(wddm); - wddmAllocation.handle = 0x2; + wddmAllocation.handle = 0x2u; + + osHandleStorageFirst = std::make_unique(); + osHandleStorageSecond = std::make_unique(); + + wddmFragmentedAllocation.fragmentsStorage.fragmentCount = 2; + wddmFragmentedAllocation.fragmentsStorage.fragmentStorageData[0].osHandleStorage = osHandleStorageFirst.get(); + wddmFragmentedAllocation.fragmentsStorage.fragmentStorageData[0].osHandleStorage->handle = 0x3u; + wddmFragmentedAllocation.fragmentsStorage.fragmentStorageData[1].osHandleStorage = osHandleStorageSecond.get(); + wddmFragmentedAllocation.fragmentsStorage.fragmentStorageData[1].osHandleStorage->handle = 0x4u; + + allocationPtr = &wddmAllocation; + + allocationData.push_back(&wddmAllocation); + allocationData.push_back(&wddmFragmentedAllocation); } std::unique_ptr wddmMemoryOperationsHandler; MockWddmAllocation wddmAllocation; + MockWddmAllocation wddmFragmentedAllocation; + std::unique_ptr osHandleStorageFirst; + std::unique_ptr osHandleStorageSecond; + GraphicsAllocation *allocationPtr; + StackVec allocationData; }; -TEST_F(WddmMemoryOperationsHandlerTest, whenMakingResidentAllocaionExpectMakeResidentCalled) { - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); +TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocatioWhenMakingResidentAllocaionExpectMakeResidentCalled) { + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); } -TEST_F(WddmMemoryOperationsHandlerTest, whenEvictingResidentAllocationExpectEvictCalled) { - EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); +TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenMakingResidentAllocaionExpectMakeResidentCalled) { + allocationPtr = &wddmFragmentedAllocation; + + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS); +} + +TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenMakingResidentAllocaionExpectMakeResidentCalled) { + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(allocationData)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS); +} + +TEST_F(WddmMemoryOperationsHandlerTest, givenRegularAllocatioWhenEvictingResidentAllocationExpectEvictCalled) { + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS); EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); } + +TEST_F(WddmMemoryOperationsHandlerTest, givenFragmentedAllocationWhenEvictingResidentAllocationExpectEvictCalled) { + allocationPtr = &wddmFragmentedAllocation; + + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(&allocationPtr, 1)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); +} + +TEST_F(WddmMemoryOperationsHandlerTest, givenVariousAllocationsWhenEvictingResidentAllocationExpectEvictCalled) { + EXPECT_EQ(wddmMemoryOperationsHandler->makeResident(ArrayRef(allocationData)), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); + EXPECT_EQ(wddmMemoryOperationsHandler->evict(wddmFragmentedAllocation), MemoryOperationsStatus::SUCCESS); + EXPECT_EQ(wddmMemoryOperationsHandler->isResident(wddmFragmentedAllocation), MemoryOperationsStatus::MEMORY_NOT_FOUND); +}