From 407227959a8c26d8a0019395e8c0637aa1e62165 Mon Sep 17 00:00:00 2001 From: "Hoppe, Mateusz" Date: Fri, 13 Jul 2018 18:50:55 +0200 Subject: [PATCH] Add memoryPool to GraphicsAllocation - new ExtendableEnum struct that serves as enum but can be extended with values - decrease dependencies on graphics_allocation.h header - use forward class declaration when possible - memoryPool indicates what kind of memory is allocated for a given GraphicsAllocation Change-Id: I7a707c28dc4544cc73abc5f0ed5263ba5be17452 --- .../experimental_command_buffer.inl | 1 + runtime/command_stream/linear_stream.h | 2 +- .../command_stream/submissions_aggregator.cpp | 1 + .../command_stream/submissions_aggregator.h | 3 +- runtime/helpers/CMakeLists.txt | 1 + runtime/helpers/extendable_enum.h | 35 ++++ runtime/helpers/flat_batch_buffer_helper.cpp | 1 + runtime/indirect_heap/indirect_heap.cpp | 2 + runtime/indirect_heap/indirect_heap.h | 32 +-- runtime/memory_manager/CMakeLists.txt | 2 + runtime/memory_manager/graphics_allocation.h | 28 +-- runtime/memory_manager/memory_pool.h | 37 ++++ .../os_agnostic_memory_manager.cpp | 18 +- .../os_agnostic_memory_manager.h | 10 +- runtime/memory_manager/residency_container.h | 30 +++ runtime/os_interface/linux/drm_allocation.h | 9 +- .../os_interface/linux/drm_memory_manager.cpp | 20 +- .../os_interface/windows/wddm_allocation.h | 21 +- .../windows/wddm_memory_manager.cpp | 16 +- .../api/cl_enqueue_svm_migrate_mem_tests.cpp | 1 + unit_tests/helpers/CMakeLists.txt | 1 + .../helpers/dirty_state_helpers_tests.cpp | 1 + unit_tests/helpers/extendable_enum_tests.cpp | 52 +++++ ...nager_allocate_in_preferred_pool_tests.cpp | 5 + .../memory_manager/memory_manager_tests.cpp | 94 +++++++++ unit_tests/mocks/mock_wddm20.cpp | 29 +++ unit_tests/mocks/mock_wddm20.h | 2 + .../linux/drm_command_stream_tests.cpp | 32 +-- .../linux/drm_gem_close_worker_tests.cpp | 2 +- .../linux/drm_memory_manager_tests.cpp | 80 +++++++- .../os_interface/windows/mock_gdi_interface.h | 42 +++- .../windows/mock_wddm_allocation.h | 34 ++++ .../windows/mock_wddm_memory_manager.h | 1 + .../os_interface/windows/wddm20_tests.cpp | 28 +-- .../windows/wddm_kmdaf_listener_tests.cpp | 19 +- .../windows/wddm_memory_manager_tests.cpp | 192 +++++++++++++----- 36 files changed, 724 insertions(+), 160 deletions(-) create mode 100644 runtime/helpers/extendable_enum.h create mode 100644 runtime/memory_manager/memory_pool.h create mode 100644 runtime/memory_manager/residency_container.h create mode 100644 unit_tests/helpers/extendable_enum_tests.cpp create mode 100644 unit_tests/os_interface/windows/mock_wddm_allocation.h diff --git a/runtime/command_stream/experimental_command_buffer.inl b/runtime/command_stream/experimental_command_buffer.inl index 2772b6d9f8..a4caf46f05 100644 --- a/runtime/command_stream/experimental_command_buffer.inl +++ b/runtime/command_stream/experimental_command_buffer.inl @@ -23,6 +23,7 @@ #include "runtime/command_stream/command_stream_receiver_hw.h" #include "runtime/command_stream/experimental_command_buffer.h" #include "runtime/command_stream/linear_stream.h" +#include "runtime/memory_manager/graphics_allocation.h" namespace OCLRT { diff --git a/runtime/command_stream/linear_stream.h b/runtime/command_stream/linear_stream.h index 556961ad6d..c231710335 100644 --- a/runtime/command_stream/linear_stream.h +++ b/runtime/command_stream/linear_stream.h @@ -23,12 +23,12 @@ #pragma once #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/ptr_math.h" -#include "runtime/memory_manager/graphics_allocation.h" #include #include #include namespace OCLRT { +class GraphicsAllocation; class LinearStream { public: diff --git a/runtime/command_stream/submissions_aggregator.cpp b/runtime/command_stream/submissions_aggregator.cpp index 080db1420e..cfc64828f6 100644 --- a/runtime/command_stream/submissions_aggregator.cpp +++ b/runtime/command_stream/submissions_aggregator.cpp @@ -21,6 +21,7 @@ */ #include "submissions_aggregator.h" #include "runtime/helpers/flush_stamp.h" +#include "runtime/memory_manager/graphics_allocation.h" void OCLRT::SubmissionAggregator::recordCommandBuffer(CommandBuffer *commandBuffer) { this->cmdBuffers.pushTailOne(*commandBuffer); diff --git a/runtime/command_stream/submissions_aggregator.h b/runtime/command_stream/submissions_aggregator.h index 871442005d..9100523d8a 100644 --- a/runtime/command_stream/submissions_aggregator.h +++ b/runtime/command_stream/submissions_aggregator.h @@ -20,15 +20,16 @@ * OTHER DEALINGS IN THE SOFTWARE. */ #pragma once -#include "runtime/memory_manager/graphics_allocation.h" #include "runtime/utilities/idlist.h" #include "runtime/utilities/stackvec.h" #include "runtime/command_stream/linear_stream.h" #include "runtime/helpers/properties_helper.h" +#include "runtime/memory_manager/residency_container.h" #include namespace OCLRT { class Event; class FlushStampTracker; +class GraphicsAllocation; struct BatchBuffer { BatchBuffer(GraphicsAllocation *commandBufferAllocation, diff --git a/runtime/helpers/CMakeLists.txt b/runtime/helpers/CMakeLists.txt index 95d9c9028d..f47f6dc141 100644 --- a/runtime/helpers/CMakeLists.txt +++ b/runtime/helpers/CMakeLists.txt @@ -43,6 +43,7 @@ set(RUNTIME_SRCS_HELPERS_BASE ${CMAKE_CURRENT_SOURCE_DIR}/enable_product.inl ${CMAKE_CURRENT_SOURCE_DIR}/engine_node.h ${CMAKE_CURRENT_SOURCE_DIR}/error_mappers.h + ${CMAKE_CURRENT_SOURCE_DIR}/extendable_enum.h ${CMAKE_CURRENT_SOURCE_DIR}/file_io.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_io.h ${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper.h diff --git a/runtime/helpers/extendable_enum.h b/runtime/helpers/extendable_enum.h new file mode 100644 index 0000000000..5f9c0af242 --- /dev/null +++ b/runtime/helpers/extendable_enum.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include + +struct ExtendableEnum { + constexpr operator uint32_t() const { + return value; + } + + protected: + constexpr ExtendableEnum(uint32_t val) : value(val) {} + uint32_t value; +}; diff --git a/runtime/helpers/flat_batch_buffer_helper.cpp b/runtime/helpers/flat_batch_buffer_helper.cpp index 6223e37aa8..beb224a6b8 100644 --- a/runtime/helpers/flat_batch_buffer_helper.cpp +++ b/runtime/helpers/flat_batch_buffer_helper.cpp @@ -21,6 +21,7 @@ */ #include "runtime/helpers/flat_batch_buffer_helper.h" +#include "runtime/memory_manager/graphics_allocation.h" namespace OCLRT { diff --git a/runtime/indirect_heap/indirect_heap.cpp b/runtime/indirect_heap/indirect_heap.cpp index 779896b533..2f0d3b80bf 100644 --- a/runtime/indirect_heap/indirect_heap.cpp +++ b/runtime/indirect_heap/indirect_heap.cpp @@ -21,6 +21,7 @@ */ #include "indirect_heap.h" +#include "runtime/memory_manager/graphics_allocation.h" namespace OCLRT { @@ -32,4 +33,5 @@ IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation, bool canBeUtilized IndirectHeap::IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize) { } + } // namespace OCLRT diff --git a/runtime/indirect_heap/indirect_heap.h b/runtime/indirect_heap/indirect_heap.h index ce05ec6389..59844c1e30 100644 --- a/runtime/indirect_heap/indirect_heap.h +++ b/runtime/indirect_heap/indirect_heap.h @@ -25,6 +25,7 @@ #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/basic_math.h" +#include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/memory_constants.h" namespace OCLRT { @@ -66,20 +67,7 @@ inline void IndirectHeap::align(size_t alignment) { auto address = alignUp(ptrOffset(buffer, sizeUsed), alignment); sizeUsed = ptrDiff(address, buffer); } -inline uint64_t IndirectHeap::getHeapGpuStartOffset() const { - if (this->canBeUtilizedAs4GbHeap) { - return this->graphicsAllocation->getGpuAddressToPatch(); - } else { - return 0llu; - } -} -inline uint64_t IndirectHeap::getHeapGpuBase() const { - if (this->canBeUtilizedAs4GbHeap) { - return this->graphicsAllocation->gpuBaseAddress; - } else { - return this->graphicsAllocation->getGpuAddress(); - } -} + inline uint32_t IndirectHeap::getHeapSizeInPages() const { if (this->canBeUtilizedAs4GbHeap) { return MemoryConstants::sizeOf4GBinPageEntities; @@ -87,4 +75,20 @@ inline uint32_t IndirectHeap::getHeapSizeInPages() const { return (static_cast(getMaxAvailableSpace()) + MemoryConstants::pageMask) / MemoryConstants::pageSize; } } + +inline uint64_t IndirectHeap::getHeapGpuStartOffset() const { + if (this->canBeUtilizedAs4GbHeap) { + return this->graphicsAllocation->getGpuAddressToPatch(); + } else { + return 0llu; + } +} + +inline uint64_t IndirectHeap::getHeapGpuBase() const { + if (this->canBeUtilizedAs4GbHeap) { + return this->graphicsAllocation->gpuBaseAddress; + } else { + return this->graphicsAllocation->getGpuAddress(); + } +} } // namespace OCLRT diff --git a/runtime/memory_manager/CMakeLists.txt b/runtime/memory_manager/CMakeLists.txt index f8411f602c..8a950264ee 100644 --- a/runtime/memory_manager/CMakeLists.txt +++ b/runtime/memory_manager/CMakeLists.txt @@ -33,10 +33,12 @@ set(RUNTIME_SRCS_MEMORY_MANAGER ${CMAKE_CURRENT_SOURCE_DIR}/memory_constants.h ${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}/memory_pool.h ${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/page_table.cpp ${CMAKE_CURRENT_SOURCE_DIR}/page_table.h + ${CMAKE_CURRENT_SOURCE_DIR}/residency_container.h ${CMAKE_CURRENT_SOURCE_DIR}/surface.h ${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.h diff --git a/runtime/memory_manager/graphics_allocation.h b/runtime/memory_manager/graphics_allocation.h index 14bbe7675c..4bced097b3 100644 --- a/runtime/memory_manager/graphics_allocation.h +++ b/runtime/memory_manager/graphics_allocation.h @@ -28,6 +28,8 @@ #include "runtime/helpers/debug_helpers.h" #include "runtime/helpers/ptr_math.h" #include "runtime/memory_manager/host_ptr_defines.h" +#include "runtime/memory_manager/memory_pool.h" +#include "runtime/memory_manager/residency_container.h" #include "runtime/utilities/idlist.h" namespace OCLRT { @@ -52,8 +54,18 @@ class GraphicsAllocation : public IDNode { bool locked = false; uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources bool evictable = true; + MemoryPool::Type memoryPool = MemoryPool::MemoryNull; public: + uint32_t taskCount = ObjectNotUsed; + OsHandleStorage fragmentsStorage; + bool is32BitAllocation = false; + uint64_t gpuBaseAddress = 0; + Gmm *gmm = nullptr; + uint64_t allocationOffset = 0u; + int residencyTaskCount = ObjectNotResident; + bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated + enum AllocationType { UNKNOWN = 0, BUFFER, @@ -132,16 +144,7 @@ class GraphicsAllocation : public IDNode { void clearTypeAubNonWritable() { this->allocationType &= ~GraphicsAllocation::AllocationType::NON_AUB_WRITABLE; } bool isTypeAubNonWritable() const { return !!(this->allocationType & GraphicsAllocation::AllocationType::NON_AUB_WRITABLE); } - uint32_t taskCount = ObjectNotUsed; - OsHandleStorage fragmentsStorage; bool isL3Capable(); - bool is32BitAllocation = false; - uint64_t gpuBaseAddress = 0; - Gmm *gmm = nullptr; - uint64_t allocationOffset = 0u; - - int residencyTaskCount = ObjectNotResident; - void setEvictable(bool evictable) { this->evictable = evictable; } bool peekEvictable() const { return evictable; } @@ -152,7 +155,9 @@ class GraphicsAllocation : public IDNode { void incReuseCount() { reuseCount++; } void decReuseCount() { reuseCount--; } uint32_t peekReuseCount() const { return reuseCount; } - bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated + MemoryPool::Type getMemoryPool() { + return memoryPool; + } protected: //this variable can only be modified from SubmissionAggregator @@ -162,7 +167,4 @@ class GraphicsAllocation : public IDNode { private: uint32_t allocationType; }; - -using ResidencyContainer = std::vector; - } // namespace OCLRT diff --git a/runtime/memory_manager/memory_pool.h b/runtime/memory_manager/memory_pool.h new file mode 100644 index 0000000000..186e2596ce --- /dev/null +++ b/runtime/memory_manager/memory_pool.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include "runtime/helpers/extendable_enum.h" + +namespace MemoryPool { +struct Type : ExtendableEnum { + constexpr Type(uint32_t val) : ExtendableEnum(val) {} +}; +constexpr Type MemoryNull{0}; +constexpr Type System4KBPages{1}; +constexpr Type System64KBPages{2}; +constexpr Type System4KBPagesWith32BitGpuAddressing{3}; +constexpr Type System64KBPagesWith32BitGpuAddressing{4}; +constexpr Type SystemCpuInaccessible{5}; +} // namespace MemoryPool diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 5c836836ec..406465b238 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -45,14 +45,14 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size, MemoryAllocation *memoryAllocation = nullptr; if (fakeBigAllocations && size > bigAllocation) { - memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast(dummyAddress), size, counter); + memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast(dummyAddress), size, counter, MemoryPool::System4KBPages); counter++; memoryAllocation->uncacheable = uncacheable; return memoryAllocation; } auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize); if (ptr != nullptr) { - memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast(ptr), size, counter); + memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast(ptr), size, counter, MemoryPool::System4KBPages); if (!memoryAllocation) { alignedFreeWrapper(ptr); return nullptr; @@ -64,7 +64,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size, } GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) { - return allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false); + auto memoryAllocation = allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false); + if (memoryAllocation) { + reinterpret_cast(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages); + } + return memoryAllocation; } GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) { @@ -75,7 +79,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t return nullptr; } uint64_t offset = static_cast(reinterpret_cast(ptr) & MemoryConstants::pageMask); - MemoryAllocation *memAlloc = new MemoryAllocation(false, const_cast(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter); + MemoryAllocation *memAlloc = new MemoryAllocation(false, const_cast(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing); memAlloc->is32BitAllocation = true; memAlloc->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase()); memAlloc->sizeToFree = allocationSize; @@ -93,7 +97,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t MemoryAllocation *memoryAllocation = nullptr; if (ptrAlloc != nullptr) { - memoryAllocation = new MemoryAllocation(true, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter); + memoryAllocation = new MemoryAllocation(true, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing); memoryAllocation->is32BitAllocation = true; memoryAllocation->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase()); memoryAllocation->sizeToFree = allocationSize; @@ -104,7 +108,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t } GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) { - auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast(1), 1, 4096u, static_cast(handle)); + auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast(1), 1, 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible); graphicsAllocation->setSharedHandle(handle); graphicsAllocation->is32BitAllocation = requireSpecificBitness; return graphicsAllocation; @@ -171,7 +175,7 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() { } GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) { - auto allocation = new MemoryAllocation(false, const_cast(hostPtr), reinterpret_cast(hostPtr), hostPtrSize, counter++); + auto allocation = new MemoryAllocation(false, const_cast(hostPtr), reinterpret_cast(hostPtr), hostPtrSize, counter++, MemoryPool::System4KBPages); allocation->fragmentsStorage = handleStorage; return allocation; } diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index 1719697441..54d35187b3 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -26,7 +26,6 @@ #include namespace OCLRT { - constexpr size_t bigAllocation = 1 * MB; constexpr uintptr_t dummyAddress = 0xFFFFF000u; class MemoryAllocation : public GraphicsAllocation { @@ -37,9 +36,14 @@ class MemoryAllocation : public GraphicsAllocation { void setSharedHandle(osHandle handle) { this->sharedHandle = handle; } - MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize), - id(count) { + MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize), + id(count) { this->cpuPtrAllocated = cpuPtrAllocated; + this->memoryPool = pool; + } + + void overrideMemoryPool(MemoryPool::Type pool) { + memoryPool = pool; } }; diff --git a/runtime/memory_manager/residency_container.h b/runtime/memory_manager/residency_container.h new file mode 100644 index 0000000000..7ed9990b7c --- /dev/null +++ b/runtime/memory_manager/residency_container.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once +#include + +namespace OCLRT { +class GraphicsAllocation; +using ResidencyContainer = std::vector; + +} // namespace OCLRT diff --git a/runtime/os_interface/linux/drm_allocation.h b/runtime/os_interface/linux/drm_allocation.h index 431796118c..5e476a51ea 100644 --- a/runtime/os_interface/linux/drm_allocation.h +++ b/runtime/os_interface/linux/drm_allocation.h @@ -32,11 +32,14 @@ struct OsHandle { class DrmAllocation : public GraphicsAllocation { public: - DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn) : GraphicsAllocation(ptrIn, sizeIn), bo(bo) { + DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, sizeIn), bo(bo) { + this->memoryPool = pool; } - DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle) : GraphicsAllocation(ptrIn, sizeIn, sharedHandle), bo(bo) { + DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, sizeIn, sharedHandle), bo(bo) { + this->memoryPool = pool; } - DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn) : GraphicsAllocation(ptrIn, gpuAddress, 0, sizeIn), bo(bo) { + DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, gpuAddress, 0, sizeIn), bo(bo) { + this->memoryPool = pool; } BufferObject *getBO() const { diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 9be92de0d3..617b3076ec 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -162,7 +162,7 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si } DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) { - auto allocation = new DrmAllocation(nullptr, const_cast(hostPtr), hostPtrSize); + auto allocation = new DrmAllocation(nullptr, const_cast(hostPtr), hostPtrSize, MemoryPool::System4KBPages); allocation->fragmentsStorage = handleStorage; return allocation; } @@ -170,6 +170,7 @@ DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handl DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) { const size_t minAlignment = MemoryConstants::allocationAlignment; size_t cAlignment = alignUp(std::max(alignment, minAlignment), minAlignment); + DrmAllocation *allocation = nullptr; // When size == 0 allocate allocationAlignment // It's needed to prevent overlapping pages with user pointers size_t cSize = std::max(alignUp(size, minAlignment), minAlignment); @@ -190,8 +191,8 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alig if (forcePinEnabled && pinBB != nullptr && forcePin && size >= this->pinThreshold) { pinBB->pin(&bo, 1); } - - return new DrmAllocation(bo, res, cSize); + allocation = new DrmAllocation(bo, res, cSize, MemoryPool::System4KBPages); + return allocation; } DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) { @@ -242,7 +243,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo & bo->setUnmapSize(imgInfo.size); - auto allocation = new DrmAllocation(bo, nullptr, (uint64_t)gpuRange, imgInfo.size); + auto allocation = new DrmAllocation(bo, nullptr, (uint64_t)gpuRange, imgInfo.size, MemoryPool::SystemCpuInaccessible); bo->setAllocationType(MMAP_ALLOCATOR); allocation->gmm = gmm; return allocation; @@ -275,7 +276,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const uintptr_t offset = (uintptr_t)bo->address; bo->softPin((uint64_t)offset); bo->setAllocationType(allocatorType); - auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize); + auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing); drmAllocation->is32BitAllocation = true; drmAllocation->gpuBaseAddress = allocatorToUse->getBase(); return drmAllocation; @@ -307,7 +308,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const bo->setAllocationType(allocatorType); - auto drmAllocation = new DrmAllocation(bo, reinterpret_cast(res), alignedAllocationSize); + auto drmAllocation = new DrmAllocation(bo, reinterpret_cast(res), alignedAllocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing); drmAllocation->is32BitAllocation = true; drmAllocation->gpuBaseAddress = allocatorToUse->getBase(); return drmAllocation; @@ -383,17 +384,17 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o } } - auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle); + auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle, MemoryPool::SystemCpuInaccessible); if (requireSpecificBitness && this->force32bitAllocations) { drmAllocation->is32BitAllocation = true; drmAllocation->gpuBaseAddress = allocator32Bit->getBase(); } - return drmAllocation; } GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) { + DrmAllocation *drmAllocation = nullptr; void *gpuRange = mmapFunction(nullptr, sizeWithPadding, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer(); @@ -410,7 +411,8 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation bo->softPin(reinterpret_cast(gpuRange)); bo->setUnmapSize(sizeWithPadding); bo->setAllocationType(MMAP_ALLOCATOR); - return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding); + drmAllocation = new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding, inputGraphicsAllocation->getMemoryPool()); + return drmAllocation; } void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) { diff --git a/runtime/os_interface/windows/wddm_allocation.h b/runtime/os_interface/windows/wddm_allocation.h index 0b39c3718e..91d58085f0 100644 --- a/runtime/os_interface/windows/wddm_allocation.h +++ b/runtime/os_interface/windows/wddm_allocation.h @@ -45,7 +45,7 @@ class WddmAllocation : public GraphicsAllocation { D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA - WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr) + WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr, MemoryPool::Type pool) : GraphicsAllocation(cpuPtrIn, sizeIn), handle(0), gpuPtr(0), @@ -53,22 +53,21 @@ class WddmAllocation : public GraphicsAllocation { alignedSize(alignedSize) { trimListPosition = trimListUnusedPosition; reservedAddressSpace = reservedAddr; + this->memoryPool = pool; } - WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle) : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle), - handle(0), - gpuPtr(0), - alignedCpuPtr(nullptr), - alignedSize(sizeIn) { + WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool) : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle), + handle(0), + gpuPtr(0), + alignedCpuPtr(nullptr), + alignedSize(sizeIn) { trimListPosition = trimListUnusedPosition; reservedAddressSpace = nullptr; + this->memoryPool = pool; } - WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress) - : WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, sizeIn, reservedAddress) { - } - - WddmAllocation() : WddmAllocation(nullptr, 0, nullptr, 0, nullptr) { + WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress, MemoryPool::Type pool) + : WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, sizeIn, reservedAddress, pool) { } void *getAlignedCpuPtr() const { diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index 5dff17d114..85315189f3 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -65,7 +65,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo delete gmm; return allocateGraphicsMemory(imgInfo.size); } - auto allocation = new WddmAllocation(nullptr, imgInfo.size, nullptr); + auto allocation = new WddmAllocation(nullptr, imgInfo.size, nullptr, MemoryPool::SystemCpuInaccessible); allocation->gmm = gmm; if (!WddmMemoryManager::createWddmAllocation(allocation, AllocationOrigin::EXTERNAL_ALLOCATION)) { @@ -79,7 +79,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s size_t sizeAligned = alignUp(size, MemoryConstants::pageSize64k); Gmm *gmm = nullptr; - auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr); + auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr, MemoryPool::System64KBPages); gmm = new Gmm(nullptr, sizeAligned, false); wddmAllocation->gmm = gmm; @@ -112,7 +112,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_ return nullptr; } - auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr); + auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages); wddmAllocation->cpuPtrAllocated = true; gmm = new Gmm(pSysMem, sizeAligned, uncacheable); @@ -125,7 +125,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_ freeSystemMemory(pSysMem); return nullptr; } - return wddmAllocation; } @@ -147,7 +146,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const return nullptr; } - auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve); + auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve, MemoryPool::System4KBPages); allocation->allocationOffset = offset; Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false); @@ -184,7 +183,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, cpuPtrAllocated = true; } - auto wddmAllocation = new WddmAllocation(const_cast(ptrAligned), sizeAligned, const_cast(ptrAligned), sizeAligned, nullptr); + auto wddmAllocation = new WddmAllocation(const_cast(ptrAligned), sizeAligned, const_cast(ptrAligned), sizeAligned, nullptr, MemoryPool::System4KBPagesWith32BitGpuAddressing); wddmAllocation->cpuPtrAllocated = cpuPtrAllocated; wddmAllocation->is32BitAllocation = true; wddmAllocation->allocationOffset = offset; @@ -207,7 +206,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size, } GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle) { - auto allocation = new WddmAllocation(nullptr, 0, handle); + auto allocation = new WddmAllocation(nullptr, 0, handle, MemoryPool::SystemCpuInaccessible); bool is32BitAllocation = false; bool status = ntHandle ? wddm->openNTHandle((HANDLE)((UINT_PTR)handle), allocation) @@ -237,7 +236,6 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl status = wddm->mapGpuVirtualAddress(allocation, ptr, is32BitAllocation, false, false); DEBUG_BREAK_IF(!status); allocation->setGpuAddress(allocation->gpuPtr); - return allocation; } @@ -430,7 +428,7 @@ void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation, } GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) { - auto allocation = new WddmAllocation(const_cast(hostPtr), hostPtrSize, const_cast(hostPtr), hostPtrSize, nullptr); + auto allocation = new WddmAllocation(const_cast(hostPtr), hostPtrSize, const_cast(hostPtr), hostPtrSize, nullptr, MemoryPool::System4KBPages); allocation->fragmentsStorage = handleStorage; obtainGpuAddresFromFragments(allocation, handleStorage); return allocation; diff --git a/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp b/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp index f3c8680479..aa62ea4a7f 100644 --- a/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp +++ b/unit_tests/api/cl_enqueue_svm_migrate_mem_tests.cpp @@ -24,6 +24,7 @@ #include "unit_tests/mocks/mock_context.h" #include "runtime/command_queue/command_queue.h" #include "runtime/device/device.h" +#include "runtime/memory_manager/graphics_allocation.h" #include "runtime/memory_manager/svm_memory_manager.h" using namespace OCLRT; diff --git a/unit_tests/helpers/CMakeLists.txt b/unit_tests/helpers/CMakeLists.txt index 057b0d3a3c..012bc8c244 100644 --- a/unit_tests/helpers/CMakeLists.txt +++ b/unit_tests/helpers/CMakeLists.txt @@ -31,6 +31,7 @@ set(IGDRCL_SRCS_tests_helpers ${CMAKE_CURRENT_SOURCE_DIR}/dirty_state_helpers_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dispatch_info_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/dispatch_info_builder_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/extendable_enum_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/file_io_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/flush_stamp_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/get_info_tests.cpp diff --git a/unit_tests/helpers/dirty_state_helpers_tests.cpp b/unit_tests/helpers/dirty_state_helpers_tests.cpp index 89f3d49201..b01c32b494 100644 --- a/unit_tests/helpers/dirty_state_helpers_tests.cpp +++ b/unit_tests/helpers/dirty_state_helpers_tests.cpp @@ -23,6 +23,7 @@ #include "runtime/helpers/dirty_state_helpers.h" #include "runtime/helpers/ptr_math.h" #include "runtime/indirect_heap/indirect_heap.h" +#include "runtime/memory_manager/graphics_allocation.h" #include "gtest/gtest.h" #include diff --git a/unit_tests/helpers/extendable_enum_tests.cpp b/unit_tests/helpers/extendable_enum_tests.cpp new file mode 100644 index 0000000000..2f7118ece2 --- /dev/null +++ b/unit_tests/helpers/extendable_enum_tests.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "runtime/helpers/extendable_enum.h" +#include "gtest/gtest.h" + +namespace ExtendableEnumTest { +struct Type : ExtendableEnum { + public: + constexpr Type(uint32_t val) : ExtendableEnum(val) {} +}; +constexpr Type testEnum0{0}; +constexpr Type testEnum1{1}; +} // namespace ExtendableEnumTest + +TEST(ExtendableEnumTest, givenExtendableEnumWhenValuesAreCheckedThenCorrectValuesAreCorrect) { + EXPECT_EQ(0u, ExtendableEnumTest::testEnum0); + EXPECT_EQ(1u, ExtendableEnumTest::testEnum1); +} + +TEST(ExtendableEnumTest, givenExtendableEnumVariableWhenValueIsAssignedThenCorrectValueIsStored) { + ExtendableEnumTest::Type enumVal0 = ExtendableEnumTest::testEnum0; + + EXPECT_EQ(ExtendableEnumTest::testEnum0, enumVal0); +} + +namespace ExtendableEnumTest { +constexpr Type testEnum2{2}; +} + +TEST(ExtendableEnumTest, givenExtendableEnumWhenNewValuesAreAddedThenCorrectValuesAreAssigned) { + EXPECT_EQ(2u, ExtendableEnumTest::testEnum2); +} diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp index 37cce1f180..5eea517f36 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.cpp @@ -156,8 +156,10 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType ASSERT_NE(nullptr, allocation); if (is64bit) { EXPECT_TRUE(allocation->is32BitAllocation); + EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); } else { EXPECT_FALSE(allocation->is32BitAllocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); } memoryManager.freeGraphicsMemory(allocation); @@ -202,6 +204,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeZeroCopyAnd EXPECT_EQ(0u, reinterpret_cast(allocation->getUnderlyingBuffer()) & MemoryConstants::page64kMask); EXPECT_EQ(0u, allocation->getGpuAddress() & MemoryConstants::page64kMask); EXPECT_EQ(0u, allocation->getUnderlyingBufferSize() & MemoryConstants::page64kMask); + EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); } @@ -229,6 +232,7 @@ TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeZeroCopyAn ASSERT_NE(nullptr, allocation); EXPECT_FALSE(memoryManager.allocation64kbPageCreated); EXPECT_TRUE(memoryManager.allocationCreated); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); } @@ -260,6 +264,7 @@ TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHo auto allocation = memoryManager.allocateGraphicsMemory(allocData); ASSERT_NE(nullptr, allocation); EXPECT_EQ(1u, allocation->fragmentsStorage.fragmentCount); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); memoryManager.freeGraphicsMemory(allocation); } diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 6514a06515..d851ff0b2f 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -849,6 +849,97 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAlloc memoryManager.freeGraphicsMemory(allocation); } +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { + OsAgnosticMemoryManager memoryManager(false); + auto size = 4096u; + + auto allocation = memoryManager.allocateGraphicsMemory(size); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager.freeGraphicsMemory(allocation); + + allocation = memoryManager.allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { + OsAgnosticMemoryManager memoryManager(true); + auto size = 4096u; + + auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryFailsThenNullptrIsReturned) { + class MockOsAgnosticManagerWithFailingAllocate : public OsAgnosticMemoryManager { + public: + MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages) : OsAgnosticMemoryManager(enable64kbPages) {} + + GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { + return nullptr; + } + }; + MockOsAgnosticManagerWithFailingAllocate memoryManager(true); + auto size = 4096u; + + auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false); + EXPECT_EQ(nullptr, allocation); + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { + OsAgnosticMemoryManager memoryManager(false); + void *ptr = reinterpret_cast(0x1001); + auto size = MemoryConstants::pageSize; + + auto allocation = memoryManager.allocateGraphicsMemory(size, ptr, false); + + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { + OsAgnosticMemoryManager memoryManager(false); + void *ptr = reinterpret_cast(0x1001); + auto size = MemoryConstants::pageSize; + + auto allocation = memoryManager.allocate32BitGraphicsMemory(size, ptr, AllocationOrigin::EXTERNAL_ALLOCATION); + + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithoutPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { + OsAgnosticMemoryManager memoryManager(false); + void *ptr = nullptr; + auto size = MemoryConstants::pageSize; + + auto allocation = memoryManager.allocate32BitGraphicsMemory(size, ptr, AllocationOrigin::EXTERNAL_ALLOCATION); + + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(allocation); +} + +TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { + OsAgnosticMemoryManager memoryManager(true); + auto size = 4096u; + + auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, false); + EXPECT_NE(nullptr, svmAllocation); + EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool()); + memoryManager.freeGraphicsMemory(svmAllocation); +} + TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { OsAgnosticMemoryManager memoryManager(false); auto size = 4096u; @@ -857,6 +948,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocat auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, isCoherent); EXPECT_NE(nullptr, svmAllocation); EXPECT_TRUE(svmAllocation->isCoherent()); + EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool()); EXPECT_EQ(size, svmAllocation->getUnderlyingBufferSize()); @@ -893,6 +985,7 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, isCoherent); EXPECT_NE(nullptr, svmAllocation); EXPECT_TRUE(svmAllocation->isCoherent()); + EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool()); EXPECT_EQ(MemoryConstants::pageSize64k, svmAllocation->getUnderlyingBufferSize()); @@ -910,6 +1003,7 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat EXPECT_FALSE(sharedAllocation->isCoherent()); EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); EXPECT_EQ(size, sharedAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, sharedAllocation->getMemoryPool()); memoryManager.freeGraphicsMemory(sharedAllocation); } diff --git a/unit_tests/mocks/mock_wddm20.cpp b/unit_tests/mocks/mock_wddm20.cpp index 73f5ff1e60..e82ce87eb8 100644 --- a/unit_tests/mocks/mock_wddm20.cpp +++ b/unit_tests/mocks/mock_wddm20.cpp @@ -21,6 +21,7 @@ */ #include "runtime/helpers/aligned_memory.h" +#include "runtime/os_interface/windows/gdi_interface.h" #include "runtime/os_interface/windows/wddm_allocation.h" #include "unit_tests/mocks/mock_wddm20.h" #include "unit_tests/mock_gdi/mock_gdi.h" @@ -241,3 +242,31 @@ bool WddmMock::reserveValidAddressRange(size_t size, void *&reservedMem) { GmmMemory *WddmMock::getGmmMemory() const { return gmmMemory.get(); } + +bool WddmMock::initializeWithoutConfiguringAddressSpace() { + if (gdi != nullptr && gdi->isInitialized() && !initialized) { + if (!openAdapter()) { + return false; + } + if (!queryAdapterInfo()) { + return false; + } + if (!createDevice()) { + return false; + } + if (!createPagingQueue()) { + return false; + } + if (!createContext()) { + return false; + } + if (hwQueuesSupported() && !createHwQueue()) { + return false; + } + if (!createMonitoredFence()) { + return false; + } + initialized = true; + } + return initialized; +} diff --git a/unit_tests/mocks/mock_wddm20.h b/unit_tests/mocks/mock_wddm20.h index ed840ad710..fdf3b9c142 100644 --- a/unit_tests/mocks/mock_wddm20.h +++ b/unit_tests/mocks/mock_wddm20.h @@ -105,6 +105,8 @@ class WddmMock : public Wddm20 { } } + bool initializeWithoutConfiguringAddressSpace(); + WddmMockHelpers::MakeResidentCall makeResidentResult; WddmMockHelpers::CallResult makeNonResidentResult; WddmMockHelpers::CallResult mapGpuVirtualAddressResult; diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index e5034ec858..074e90badc 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -123,7 +123,7 @@ TEST_F(DrmCommandStreamTest, makeResident) { .Times(0); EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(0); - DrmAllocation graphicsAllocation(nullptr, nullptr, 1024); + DrmAllocation graphicsAllocation(nullptr, nullptr, 1024, MemoryPool::MemoryNull); csr->makeResident(graphicsAllocation); } @@ -137,7 +137,7 @@ TEST_F(DrmCommandStreamTest, makeResidentTwiceTheSame) { EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(0); - DrmAllocation graphicsAllocation(nullptr, nullptr, 1024); + DrmAllocation graphicsAllocation(nullptr, nullptr, 1024, MemoryPool::MemoryNull); csr->makeResident(graphicsAllocation); csr->makeResident(graphicsAllocation); @@ -153,7 +153,7 @@ TEST_F(DrmCommandStreamTest, makeResidentSizeZero) { EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(0); - DrmAllocation graphicsAllocation(nullptr, nullptr, 0); + DrmAllocation graphicsAllocation(nullptr, nullptr, 0, MemoryPool::MemoryNull); csr->makeResident(graphicsAllocation); } @@ -168,8 +168,8 @@ TEST_F(DrmCommandStreamTest, makeResidentResized) { EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(0); - DrmAllocation graphicsAllocation(nullptr, nullptr, 1024); - DrmAllocation graphicsAllocation2(nullptr, nullptr, 8192); + DrmAllocation graphicsAllocation(nullptr, nullptr, 1024, MemoryPool::MemoryNull); + DrmAllocation graphicsAllocation2(nullptr, nullptr, 8192, MemoryPool::MemoryNull); csr->makeResident(graphicsAllocation); csr->makeResident(graphicsAllocation2); @@ -275,7 +275,7 @@ TEST_F(DrmCommandStreamTest, FlushInvalidAddress) { //allocate command buffer manually char *commandBuffer = new (std::nothrow) char[1024]; ASSERT_NE(nullptr, commandBuffer); - DrmAllocation commandBufferAllocation(nullptr, commandBuffer, 1024); + DrmAllocation commandBufferAllocation(nullptr, commandBuffer, 1024, MemoryPool::MemoryNull); LinearStream cs(&commandBufferAllocation); csr->addBatchBufferEnd(cs, nullptr); @@ -417,8 +417,8 @@ TEST_F(DrmCommandStreamTest, FlushCheckFlags) { .Times(1) .WillRepeatedly(::testing::Return(0)); - DrmAllocation allocation(nullptr, (void *)0x7FFFFFFF, 1024); - DrmAllocation allocation2(nullptr, (void *)0x307FFFFFFF, 1024); + DrmAllocation allocation(nullptr, (void *)0x7FFFFFFF, 1024, MemoryPool::MemoryNull); + DrmAllocation allocation2(nullptr, (void *)0x307FFFFFFF, 1024, MemoryPool::MemoryNull); csr->makeResident(allocation); csr->makeResident(allocation2); csr->addBatchBufferEnd(cs, nullptr); @@ -451,7 +451,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFree) { EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(2); - DrmAllocation allocation(nullptr, nullptr, 1024); + DrmAllocation allocation(nullptr, nullptr, 1024, MemoryPool::MemoryNull); csr->makeResident(allocation); csr->addBatchBufferEnd(cs, nullptr); @@ -492,7 +492,7 @@ TEST_F(DrmCommandStreamTest, CheckDrmFreeCloseFailed) { .WillOnce(::testing::Return(-1)); EXPECT_CALL(*mock, ioctl(DRM_IOCTL_I915_GEM_WAIT, ::testing::_)) .Times(2); - DrmAllocation allocation(nullptr, nullptr, 1024); + DrmAllocation allocation(nullptr, nullptr, 1024, MemoryPool::MemoryNull); csr->makeResident(allocation); csr->addBatchBufferEnd(cs, nullptr); @@ -1107,7 +1107,7 @@ typedef Test DrmCommandStreamLeaksTest; TEST_F(DrmCommandStreamLeaksTest, makeResident) { auto buffer = this->createBO(1024); - auto allocation = new DrmAllocation(buffer, nullptr, buffer->peekSize()); + auto allocation = new DrmAllocation(buffer, nullptr, buffer->peekSize(), MemoryPool::MemoryNull); EXPECT_EQ(nullptr, allocation->getUnderlyingBuffer()); csr->makeResident(*allocation); @@ -1129,8 +1129,8 @@ TEST_F(DrmCommandStreamLeaksTest, makeResident) { TEST_F(DrmCommandStreamLeaksTest, makeResidentOnly) { BufferObject *buffer1 = this->createBO(4096); BufferObject *buffer2 = this->createBO(4096); - auto allocation1 = new DrmAllocation(buffer1, nullptr, buffer1->peekSize()); - auto allocation2 = new DrmAllocation(buffer2, nullptr, buffer2->peekSize()); + auto allocation1 = new DrmAllocation(buffer1, nullptr, buffer1->peekSize(), MemoryPool::MemoryNull); + auto allocation2 = new DrmAllocation(buffer2, nullptr, buffer2->peekSize(), MemoryPool::MemoryNull); EXPECT_EQ(nullptr, allocation1->getUnderlyingBuffer()); EXPECT_EQ(nullptr, allocation2->getUnderlyingBuffer()); @@ -1157,7 +1157,7 @@ TEST_F(DrmCommandStreamLeaksTest, makeResidentOnly) { TEST_F(DrmCommandStreamLeaksTest, makeResidentTwice) { auto buffer = this->createBO(1024); - auto allocation = new DrmAllocation(buffer, nullptr, buffer->peekSize()); + auto allocation = new DrmAllocation(buffer, nullptr, buffer->peekSize(), MemoryPool::MemoryNull); csr->makeResident(*allocation); csr->processResidency(nullptr); @@ -1442,7 +1442,7 @@ TEST_F(DrmCommandStreamLeaksTest, GivenTwoAllocationsWhenBackingStorageIsDiffere TEST_F(DrmCommandStreamLeaksTest, makeResidentSizeZero) { std::unique_ptr buffer(this->createBO(0)); - DrmAllocation allocation(buffer.get(), nullptr, buffer->peekSize()); + DrmAllocation allocation(buffer.get(), nullptr, buffer->peekSize(), MemoryPool::MemoryNull); EXPECT_EQ(nullptr, allocation.getUnderlyingBuffer()); EXPECT_EQ(buffer->peekSize(), allocation.getUnderlyingBufferSize()); @@ -1667,7 +1667,7 @@ class DrmMockBuffer : public Buffer { public: static DrmMockBuffer *create() { char *data = static_cast(::alignedMalloc(128, 64)); - DrmAllocation *alloc = new (std::nothrow) DrmAllocation(nullptr, &data, sizeof(data)); + DrmAllocation *alloc = new (std::nothrow) DrmAllocation(nullptr, &data, sizeof(data), MemoryPool::MemoryNull); return new DrmMockBuffer(data, 128, alloc); } diff --git a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp index 15885fe751..ab376eb6ae 100644 --- a/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp +++ b/unit_tests/os_interface/linux/drm_gem_close_worker_tests.cpp @@ -100,7 +100,7 @@ class DrmGemCloseWorkerFixture { }; class DrmAllocationWrapper : public DrmAllocation { public: - DrmAllocationWrapper(BufferObject *bo) : DrmAllocation(bo, nullptr, 0) { + DrmAllocationWrapper(BufferObject *bo) : DrmAllocation(bo, nullptr, 0, MemoryPool::MemoryNull) { } }; }; diff --git a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp index 11e2442656..d556e845bd 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -187,7 +187,7 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo void *cpuPtr = (void *)0x30000; size_t size = 0x1000; - DrmAllocation gfxAllocation(nullptr, cpuPtr, size); + DrmAllocation gfxAllocation(nullptr, cpuPtr, size, MemoryPool::MemoryNull); memoryManager->addAllocationToHostPtrManager(&gfxAllocation); auto fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer()); EXPECT_NE(fragment, nullptr); @@ -2404,6 +2404,84 @@ TEST(DrmMemoryManager, givenEnabledHostMemoryValidationAndForcePinWhenMemoryMana ASSERT_NE(nullptr, memoryManager->getPinBB()); } +TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + auto size = 4096u; + + auto allocation = memoryManager->allocateGraphicsMemory(size); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); + + allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + void *ptr = reinterpret_cast(0x1001); + auto size = 4096u; + auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + memoryManager->setForce32BitAllocations(true); + + void *ptr = reinterpret_cast(0x1001); + auto size = MemoryConstants::pageSize; + + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, AllocationOrigin::EXTERNAL_ALLOCATION); + + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); + + memoryManager->freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + auto size = MemoryConstants::pageSize; + + auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); + EXPECT_NE(nullptr, svmAllocation); + EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(svmAllocation); +} + +TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + auto osHandle = 1u; + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + auto size = 4096u; + auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false); + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + auto size = MemoryConstants::pageSize; + + auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); + EXPECT_NE(nullptr, svmAllocation); + EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(svmAllocation); +} + TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEnabledValidateHostMemoryWhenPinBBAllocationFailsThenUnrecoverableIsCalled) { this->mock->ioctl_res = -1; this->mock->ioctl_expected.gemUserptr = 1; diff --git a/unit_tests/os_interface/windows/mock_gdi_interface.h b/unit_tests/os_interface/windows/mock_gdi_interface.h index e4d6245c5f..9321459ca7 100644 --- a/unit_tests/os_interface/windows/mock_gdi_interface.h +++ b/unit_tests/os_interface/windows/mock_gdi_interface.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2017, Intel Corporation +* Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -76,6 +76,24 @@ class MockGdi : public Gdi { return 0; } + static NTSTATUS __stdcall queryResourceInfoMock(IN OUT D3DKMT_QUERYRESOURCEINFO *arg) { + getQueryResourceInfoArgIn() = *arg; + arg->NumAllocations = getQueryResourceInfoArgOut().NumAllocations; + arg->ResourcePrivateDriverDataSize = getQueryResourceInfoArgOut().ResourcePrivateDriverDataSize; + arg->TotalPrivateDriverDataSize = getQueryResourceInfoArgOut().TotalPrivateDriverDataSize; + return 0; + } + + static NTSTATUS __stdcall openResourceMock(IN OUT D3DKMT_OPENRESOURCE *arg) { + getOpenResourceArgIn() = *arg; + if (arg->NumAllocations > 0) { + arg->pOpenAllocationInfo[0].hAllocation = getOpenResourceArgOut().pOpenAllocationInfo->hAllocation; + arg->pOpenAllocationInfo[0].PrivateDriverDataSize = getOpenResourceArgOut().pOpenAllocationInfo->PrivateDriverDataSize; + arg->pOpenAllocationInfo[0].pPrivateDriverData = getOpenResourceArgOut().pOpenAllocationInfo->pPrivateDriverData; + } + return 0; + } + bool getAllProcAddresses() override { makeResident = reinterpret_cast(makeResidentMock); if (nonZeroNumBytesToTrim) { @@ -86,6 +104,8 @@ class MockGdi : public Gdi { registerTrimNotification = reinterpret_cast(registerTimNotificationMock); destroyAllocation2 = reinterpret_cast(destroyAllocation2Mock); waitForSynchronizationObjectFromCpu = reinterpret_cast(waitFromCpuMock); + queryResourceInfo = reinterpret_cast(queryResourceInfoMock); + openResource = reinterpret_cast(openResourceMock); return true; } @@ -118,6 +138,26 @@ class MockGdi : public Gdi { static D3DKMT_CREATESYNCHRONIZATIONOBJECT2 createSynchronizationObject2; return createSynchronizationObject2; } + + static D3DKMT_QUERYRESOURCEINFO &getQueryResourceInfoArgIn() { + static D3DKMT_QUERYRESOURCEINFO queryResourceInfo; + return queryResourceInfo; + } + + static D3DKMT_QUERYRESOURCEINFO &getQueryResourceInfoArgOut() { + static D3DKMT_QUERYRESOURCEINFO queryResourceInfo; + return queryResourceInfo; + } + + static D3DKMT_OPENRESOURCE &getOpenResourceArgIn() { + static D3DKMT_OPENRESOURCE openResource; + return openResource; + } + + static D3DKMT_OPENRESOURCE &getOpenResourceArgOut() { + static D3DKMT_OPENRESOURCE openResource; + return openResource; + } }; } // namespace OCLRT diff --git a/unit_tests/os_interface/windows/mock_wddm_allocation.h b/unit_tests/os_interface/windows/mock_wddm_allocation.h new file mode 100644 index 0000000000..37f0c660d4 --- /dev/null +++ b/unit_tests/os_interface/windows/mock_wddm_allocation.h @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2018, Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#pragma once +#include "runtime/os_interface/windows/wddm_allocation.h" + +namespace OCLRT { + +class MockWddmAllocation : public WddmAllocation { + public: + MockWddmAllocation() : WddmAllocation(nullptr, 0, nullptr, 0, nullptr, MemoryPool::MemoryNull) { + } +}; + +} // namespace OCLRT diff --git a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h index 433a1a99cf..4c4e9cbc8a 100644 --- a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h +++ b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h @@ -40,6 +40,7 @@ class MockWddmMemoryManager : public WddmMemoryManager { using BaseClass::trimResidency; using BaseClass::trimResidencyToBudget; + MockWddmMemoryManager(bool enable64kbPages, Wddm *wddm) : WddmMemoryManager(enable64kbPages, wddm){}; MockWddmMemoryManager(Wddm *wddm) : WddmMemoryManager(false, wddm){}; void setDeferredDeleter(DeferredDeleter *deleter) { this->deferredDeleter.reset(deleter); diff --git a/unit_tests/os_interface/windows/wddm20_tests.cpp b/unit_tests/os_interface/windows/wddm20_tests.cpp index f09ef20abe..2b144324b9 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -189,7 +189,7 @@ HWTEST_F(Wddm20Tests, allocation) { wddm->init(); ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); + WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = gmm; @@ -216,7 +216,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenAllocationSmallerUnderlyingThanAlignedS size_t underlyingPages = underlyingSize / MemoryConstants::pageSize; size_t alignedPages = alignedSize / MemoryConstants::pageSize; - WddmAllocation allocation(ptr, 0x2100, ptr, 0x3000, nullptr); + WddmAllocation allocation(ptr, 0x2100, ptr, 0x3000, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize()); allocation.gmm = gmm; @@ -241,7 +241,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenWddmAllocationWhenMappingGpuVaThenUseGm wddm->init(); void *fakePtr = reinterpret_cast(0x123); - WddmAllocation allocation(fakePtr, 100, fakePtr, 200, nullptr); + WddmAllocation allocation(fakePtr, 100, fakePtr, 200, nullptr, MemoryPool::MemoryNull); std::unique_ptr gmm(GmmHelperFunctions::getGmm(allocation.getAlignedCpuPtr(), allocation.getAlignedSize())); allocation.gmm = gmm.get(); @@ -267,7 +267,7 @@ HWTEST_F(Wddm20Tests, createAllocation32bit) { void *alignedPtr = (void *)0x12000; size_t alignedSize = 0x2000; - WddmAllocation allocation(alignedPtr, alignedSize, nullptr); + WddmAllocation allocation(alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = gmm; @@ -296,7 +296,7 @@ HWTEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap1ThenItHasGpuAd wddm->init(); void *alignedPtr = (void *)0x12000; size_t alignedSize = 0x2000; - WddmAllocation allocation(alignedPtr, alignedSize, nullptr); + WddmAllocation allocation(alignedPtr, alignedSize, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; allocation.gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -350,7 +350,7 @@ HWTEST_F(Wddm20Tests, mapAndFreeGpuVa) { ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); + WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = gmm; @@ -378,7 +378,7 @@ HWTEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(nullptr, 100, nullptr); + WddmAllocation allocation(nullptr, 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = gmm; @@ -400,7 +400,7 @@ HWTEST_F(Wddm20Tests, makeResidentNonResident) { ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); + WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); allocation.gmm = gmm; @@ -701,7 +701,7 @@ HWTEST_F(Wddm20Tests, makeResidentMultipleHandles) { ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); + WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; D3DKMT_HANDLE handles[2] = {0}; @@ -726,7 +726,7 @@ HWTEST_F(Wddm20Tests, makeResidentMultipleHandlesWithReturnBytesToTrim) { ASSERT_TRUE(wddm->isInitialized()); OsAgnosticMemoryManager mm(false); - WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr); + WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; D3DKMT_HANDLE handles[2] = {0}; @@ -770,7 +770,7 @@ HWTEST_F(Wddm20Tests, makeNonResidentCallsEvict) { HWTEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueGreaterThanCurrentValueCallsWaitFromCpu) { wddm->init(); - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.getResidencyData().lastFence = 20; allocation.handle = ALLOCATION_HANDLE; @@ -805,7 +805,7 @@ HWTEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueGreaterThanCurrentValue HWTEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueLessEqualToCurrentValueDoesNotCallWaitFromCpu) { wddm->init(); - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; @@ -840,7 +840,7 @@ HWTEST_F(Wddm20Tests, destroyAllocationWithLastFenceValueLessEqualToCurrentValue HWTEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCalled) { wddm->init(); - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; @@ -865,7 +865,7 @@ HWTEST_F(Wddm20Tests, WhenLastFenceLessEqualThanMonitoredThenWaitFromCpuIsNotCal HWTEST_F(Wddm20Tests, WhenLastFenceGreaterThanMonitoredThenWaitFromCpuIsCalled) { wddm->init(); - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.getResidencyData().lastFence = 10; allocation.handle = ALLOCATION_HANDLE; diff --git a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 5f4a43c77b..941f0c6654 100644 --- a/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -26,6 +26,7 @@ #include "runtime/os_interface/windows/wddm_allocation.h" #include "unit_tests/os_interface/windows/mock_kmdaf_listener.h" #include "unit_tests/os_interface/windows/mock_gdi_interface.h" +#include "unit_tests/os_interface/windows/mock_wddm_allocation.h" #include "unit_tests/mock_gdi/mock_gdi.h" #include "test.h" @@ -65,7 +66,7 @@ class WddmKmDafListenerTest : public ::testing::Test { }; HWTEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) { - WddmAllocation allocation; + MockWddmAllocation allocation; allocation.handle = ALLOCATION_HANDLE; wddmWithKmDafMock->lockResource(&allocation); @@ -79,7 +80,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListen } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafListenerNotifyUnlockIsFedWithCorrectParams) { - WddmAllocation allocation; + MockWddmAllocation allocation; allocation.handle = ALLOCATION_HANDLE; wddmWithKmDafMock->unlockResource(&allocation); @@ -93,7 +94,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafList } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmDafListenerNotifyMapGpuVAIsFedWithCorrectParams) { - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); @@ -109,7 +110,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMapGpuVirtualAddressIsCalledThenKmD } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenFreeGpuVirtualAddressIsCalledThenKmDafListenerNotifyUnmapGpuVAIsFedWithCorrectParams) { - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); allocation.gpuPtr = GPUVA; wddmWithKmDafMock->freeGpuVirtualAddres(allocation.gpuPtr, allocation.getUnderlyingBufferSize()); @@ -122,7 +123,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenFreeGpuVirtualAddressIsCalledThenKm } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMakeResidentIsCalledThenKmDafListenerNotifyMakeResidentIsFedWithCorrectParams) { - WddmAllocation allocation; + MockWddmAllocation allocation; wddmWithKmDafMock->makeResident(&allocation.handle, 1, false, nullptr); @@ -135,7 +136,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenMakeResidentIsCalledThenKmDafListen } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotifyEvictIsFedWithCorrectParams) { - WddmAllocation allocation; + MockWddmAllocation allocation; uint64_t sizeToTrim; wddmWithKmDafMock->evict(&allocation.handle, 1, sizeToTrim); @@ -149,7 +150,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotif } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafListenerNotifyWriteTargetIsFedWithCorrectParams) { - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); @@ -163,7 +164,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafLi } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDafListenerNotifyWriteTargetIsFedWithCorrectParams) { - WddmAllocation allocation((void *)0x23000, 0x1000, nullptr); + WddmAllocation allocation((void *)0x23000, 0x1000, nullptr, MemoryPool::MemoryNull); auto gmm = std::unique_ptr(new Gmm(nullptr, 1, false)); allocation.gmm = gmm.get(); @@ -201,7 +202,7 @@ HWTEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationsAndMapGpuVaIsCalle } HWTEST_F(WddmKmDafListenerTest, givenWddmWhenKmDafLockIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) { - WddmAllocation allocation; + MockWddmAllocation allocation; allocation.handle = ALLOCATION_HANDLE; wddmWithKmDafMock->kmDafLock(&allocation); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp index 254b0ae38f..38ab204bef 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -29,6 +29,7 @@ #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_deferred_deleter.h" +#include "unit_tests/os_interface/windows/mock_wddm_allocation.h" #include "unit_tests/os_interface/windows/wddm_memory_manager_tests.h" using namespace OCLRT; @@ -69,6 +70,103 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled DebugManager.flags.EnableDeferredDeleter.set(actualDeleterFlag); } +class WddmMemoryManagerSimpleTest : public MockWddmMemoryManagerFixture, public ::testing::Test { + public: + void SetUp() override { + MockWddmMemoryManagerFixture::SetUp(); + wddm->initializeWithoutConfiguringAddressSpace(); + } + void TearDown() override { + MockWddmMemoryManagerFixture::TearDown(); + } +}; + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + auto size = 4096u; + + auto allocation = memoryManager->allocateGraphicsMemory(size); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); + + allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::preferredAlignment, false, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + auto size = 4096u; + auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System64KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + void *ptr = reinterpret_cast(0x1001); + auto size = 4096u; + auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPages, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + void *ptr = reinterpret_cast(0x1001); + auto size = MemoryConstants::pageSize; + + auto allocation = memoryManager->allocate32BitGraphicsMemory(size, ptr, AllocationOrigin::EXTERNAL_ALLOCATION); + + ASSERT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::System4KBPagesWith32BitGpuAddressing, allocation->getMemoryPool()); + + memoryManager->freeGraphicsMemory(allocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + auto size = MemoryConstants::pageSize; + + auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); + EXPECT_NE(nullptr, svmAllocation); + EXPECT_EQ(MemoryPool::System4KBPages, svmAllocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(svmAllocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { + memoryManager.reset(new MockWddmMemoryManager(true, wddm)); + auto size = MemoryConstants::pageSize; + + auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); + EXPECT_NE(nullptr, svmAllocation); + EXPECT_EQ(MemoryPool::System64KBPages, svmAllocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(svmAllocation); +} + +TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { + memoryManager.reset(new MockWddmMemoryManager(false, wddm)); + auto osHandle = 1u; + gdi->getQueryResourceInfoArgOut().NumAllocations = 1; + std::unique_ptr gmm(new Gmm(nullptr, 0, false)); + + D3DDDI_OPENALLOCATIONINFO allocationInfo; + allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); + allocationInfo.hAllocation = static_cast(0x4000); + allocationInfo.PrivateDriverDataSize = sizeof(GMM_RESOURCE_INFO); + + gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; + + auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false, false); + EXPECT_NE(nullptr, allocation); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, allocation->getMemoryPool()); + memoryManager->freeGraphicsMemory(allocation); +} + HWTEST_F(WddmMemoryManagerTest, AllocateAndFree) { SetUpMm(); auto *ptr = memoryManager->allocateGraphicsMemory(0x1000); @@ -86,7 +184,7 @@ TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationT void *cpuPtr = (void *)0x30000; size_t size = 0x1000; - WddmAllocation gfxAllocation(cpuPtr, size, nullptr); + WddmAllocation gfxAllocation(cpuPtr, size, nullptr, MemoryPool::MemoryNull); memoryManager->addAllocationToHostPtrManager(&gfxAllocation); auto fragment = memoryManager->hostPtrManager.getFragment(gfxAllocation.getUnderlyingBuffer()); EXPECT_NE(fragment, nullptr); @@ -443,7 +541,7 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenNonTiledImgWithMipCoun HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { SetUpMm(); - WddmAllocation alloc, allocOffseted; + MockWddmAllocation alloc, allocOffseted; bool success = false; // three pages void *ptr = alignedMalloc(4 * 4096, 4096); @@ -498,7 +596,7 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtrOffseted) { HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemCheckGmm) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; bool success = false; // three pages void *ptr = alignedMalloc(3 * 4096, 4096); @@ -520,7 +618,7 @@ HWTEST_F(WddmMemoryManagerTest, AllocateGpuMemCheckGmm) { HWTEST_F(WddmMemoryManagerTest, GivenAlignedPointerWhenAllocate32BitMemoryThenGmmCalledWithCorrectPointerAndSize) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; bool success = false; uint32_t size = 4096; void *ptr = reinterpret_cast(4096); @@ -532,7 +630,7 @@ HWTEST_F(WddmMemoryManagerTest, GivenAlignedPointerWhenAllocate32BitMemoryThenGm HWTEST_F(WddmMemoryManagerTest, GivenUnAlignedPointerAndSizeWhenAllocate32BitMemoryThenGmmCalledWithCorrectPointerAndSize) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; bool success = false; uint32_t size = 0x1001; void *ptr = reinterpret_cast(0x1001); @@ -681,7 +779,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithDisabledDeferredDeleterWhenMapGp memoryManager->setDeferredDeleter(nullptr); setMapGpuVaFailConfigFcn(0, 1); - WddmAllocation allocation(ptr, size, nullptr); + WddmAllocation allocation(ptr, size, nullptr, MemoryPool::MemoryNull); allocation.gmm = gmm.get(); bool ret = memoryManager->createWddmAllocation(&allocation, AllocationOrigin::EXTERNAL_ALLOCATION); EXPECT_FALSE(ret); @@ -698,7 +796,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstM setMapGpuVaFailConfigFcn(0, 1); - WddmAllocation allocation(ptr, size, nullptr); + WddmAllocation allocation(ptr, size, nullptr, MemoryPool::MemoryNull); allocation.gmm = gmm.get(); bool ret = memoryManager->createWddmAllocation(&allocation, AllocationOrigin::EXTERNAL_ALLOCATION); EXPECT_TRUE(ret); @@ -716,7 +814,7 @@ HWTEST_F(WddmMemoryManagerTest, givenManagerWithEnabledDeferredDeleterWhenFirstA setMapGpuVaFailConfigFcn(0, 2); - WddmAllocation allocation(ptr, size, nullptr); + WddmAllocation allocation(ptr, size, nullptr, MemoryPool::MemoryNull); allocation.gmm = gmm.get(); bool ret = memoryManager->createWddmAllocation(&allocation, AllocationOrigin::EXTERNAL_ALLOCATION); EXPECT_FALSE(ret); @@ -763,7 +861,7 @@ HWTEST_F(WddmMemoryManagerTest, givenPtrAndSizePassedToCreateInternalAllocationW HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListPlacesAllocationInContainerAndAssignsPosition) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; memoryManager->addToTrimCandidateList(&allocation); @@ -778,7 +876,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListPlacesAllocationI HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListDoesNotInsertAllocationAlreadyOnTheList) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; memoryManager->trimCandidateList.resize(0); @@ -800,7 +898,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, addToTrimCandidateListDoesNotInsertAllo HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListAssignsUnusedPosition) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; memoryManager->addToTrimCandidateList(&allocation); memoryManager->removeFromTrimCandidateList(&allocation); @@ -810,7 +908,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListAssignsUnuse HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesAllocationInAssignedPosition) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; memoryManager->addToTrimCandidateList(&allocation); size_t position = allocation.getTrimCandidateListPosition(); @@ -824,7 +922,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesAlloc HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastAllocation) { SetUpMm(); - WddmAllocation allocation; + MockWddmAllocation allocation; memoryManager->trimCandidateList.resize(0); @@ -837,7 +935,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastA HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastAllocationAndAllPreviousEmptyEntries) { SetUpMm(); - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; memoryManager->trimCandidateList.resize(0); @@ -858,7 +956,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removeFromTrimCandidateListRemovesLastA HWTEST_F(WddmMemoryManagerResidencyTest, successiveAddingToTrimCandidateListAssignsNewPositions) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3; + MockWddmAllocation allocation1, allocation2, allocation3; memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation2); @@ -871,7 +969,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, successiveAddingToTrimCandidateListAssi HWTEST_F(WddmMemoryManagerResidencyTest, DISABLED_removingNotLastAllocationFromTrimCandidateListSubstituesLastPositionAllocation) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3; + MockWddmAllocation allocation1, allocation2, allocation3; memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation2); @@ -887,7 +985,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, DISABLED_removingNotLastAllocationFromT HWTEST_F(WddmMemoryManagerResidencyTest, removingNotLastAllocationFromTrimCandidateListPutsNullEntry) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3; + MockWddmAllocation allocation1, allocation2, allocation3; memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation2); @@ -904,7 +1002,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, removingNotLastAllocationFromTrimCandid HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListRemovesInitialNullEntriesAndUpdatesPositions) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation2); @@ -932,7 +1030,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListRemovesInitialN HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListWithNonNullEntries) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; memoryManager->addToTrimCandidateList(&allocation1); memoryManager->addToTrimCandidateList(&allocation2); @@ -948,7 +1046,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, compactTrimCandidateListWithNonNullEntr HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAllocationsResident) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; memoryManager->pushAllocationForResidency(&allocation1); memoryManager->pushAllocationForResidency(&allocation2); @@ -965,7 +1063,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksAl HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdatesLastFence) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; memoryManager->pushAllocationForResidency(&allocation1); memoryManager->pushAllocationForResidency(&allocation2); @@ -984,7 +1082,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsUpdates HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTripleAllocationsResident) { SetUpMm(); - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1500); WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, ptr); @@ -1006,7 +1104,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsMarksTr HWTEST_F(WddmMemoryManagerResidencyTest, makeResidentResidencyAllocationsSetsLastFencePLusOneForTripleAllocations) { SetUpMm(); - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; WddmAllocation *allocationTriple = (WddmAllocation *)memoryManager->allocateGraphicsMemory(8196, reinterpret_cast(0x1500)); @@ -1039,7 +1137,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeri trimNotification.NumBytesToTrim = 0; // allocations have fence value == 0 by default - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; allocation1.getResidencyData().resident = true; allocation2.getResidencyData().resident = true; @@ -1073,7 +1171,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPerio trimNotification.NumBytesToTrim = 0; // allocations have fence value == 0 by default - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; allocation1.getResidencyData().resident = true; // mark allocation used from last periodic trim allocation2.getResidencyData().lastFence = 11; @@ -1192,7 +1290,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetAllDoneAllocations) { SetUpMm(); gdi->setNonZeroNumBytesToTrimInEvict(); - WddmAllocation allocation1, allocation2, allocation3; + MockWddmAllocation allocation1, allocation2, allocation3; allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1231,7 +1329,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToT SetUpMm(); gdi->setNonZeroNumBytesToTrimInEvict(); - WddmAllocation allocation1; + MockWddmAllocation allocation1; allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1253,9 +1351,9 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetReturnsFalseWhenNumBytesToT HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetStopsEvictingWhenNumBytesToTrimIsZero) { SetUpMm(); - WddmAllocation allocation1(reinterpret_cast(0x1000), 0x1000, reinterpret_cast(0x1000), 0x1000, nullptr), - allocation2(reinterpret_cast(0x1000), 0x3000, reinterpret_cast(0x1000), 0x3000, nullptr), - allocation3(reinterpret_cast(0x1000), 0x1000, reinterpret_cast(0x1000), 0x1000, nullptr); + WddmAllocation allocation1(reinterpret_cast(0x1000), 0x1000, reinterpret_cast(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull), + allocation2(reinterpret_cast(0x1000), 0x3000, reinterpret_cast(0x1000), 0x3000, nullptr, MemoryPool::MemoryNull), + allocation3(reinterpret_cast(0x1000), 0x1000, reinterpret_cast(0x1000), 0x1000, nullptr, MemoryPool::MemoryNull); allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1293,7 +1391,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetMarksEvictedAllocationNonRe SetUpMm(); gdi->setNonZeroNumBytesToTrimInEvict(); - WddmAllocation allocation1, allocation2, allocation3; + MockWddmAllocation allocation1, allocation2, allocation3; allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1326,7 +1424,7 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWaitsFromCpuWhenLastFenceIs SetUpMm(); gdi->setNonZeroNumBytesToTrimInEvict(); - WddmAllocation allocation1; + MockWddmAllocation allocation1; allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 2; @@ -1355,8 +1453,8 @@ HWTEST_F(WddmMemoryManagerResidencyTest, trimToBudgetEvictsDoneFragmentsOnly) { SetUpMm(); gdi->setNonZeroNumBytesToTrimInEvict(); void *ptr = reinterpret_cast(wddm->virtualAllocAddress + 0x1000); - WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr); - WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr); + WddmAllocation allocation1(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull); + WddmAllocation allocation2(ptr, 0x1000, ptr, 0x1000, nullptr, MemoryPool::MemoryNull); allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1440,9 +1538,9 @@ HWTEST_F(WddmMemoryManagerResidencyTest, givenThreeAllocationsAlignedSizeBiggerT void *ptr2 = reinterpret_cast(wddm->virtualAllocAddress + 0x3000); void *ptr3 = reinterpret_cast(wddm->virtualAllocAddress + 0x5000); - WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr); - WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr); - WddmAllocation allocation3(ptr3, underlyingSize, ptr3, alignedSize, nullptr); + WddmAllocation allocation1(ptr1, underlyingSize, ptr1, alignedSize, nullptr, MemoryPool::MemoryNull); + WddmAllocation allocation2(ptr2, underlyingSize, ptr2, alignedSize, nullptr, MemoryPool::MemoryNull); + WddmAllocation allocation3(ptr3, underlyingSize, ptr3, alignedSize, nullptr, MemoryPool::MemoryNull); allocation1.getResidencyData().resident = true; allocation1.getResidencyData().lastFence = 0; @@ -1643,7 +1741,7 @@ HWTEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAlloca HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllocationsResidentWhenMakeResidentFails) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; }; @@ -1667,7 +1765,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkAllo HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTripleAllocationsResidentWhenMakeResidentFails) { SetUpMm(); - WddmAllocation allocation1, allocation2; + MockWddmAllocation allocation1, allocation2; void *ptr = reinterpret_cast(wddm->getWddmMinAddress() + 0x1500); WddmAllocation *allocationTriple = static_cast(memoryManager->allocateGraphicsMemory(8196, ptr)); ASSERT_NE(nullptr, allocationTriple); @@ -1694,7 +1792,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsDoesNotMarkTrip HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeResidentFailsAndCantTrimFurther) { SetUpMm(); - WddmAllocation allocation1, allocation2, allocation3, allocation4; + MockWddmAllocation allocation1, allocation2, allocation3, allocation4; auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; }; @@ -1718,7 +1816,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsFailsWhenMakeRe HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeResidentWithCantTrimFurtherSetToTrueWhenTrimToBudgetReturnsFalse) { SetUpMm(); - WddmAllocation allocation1; + MockWddmAllocation allocation1; auto makeResidentWithOutBytesToTrim = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { *numberOfBytesToTrim = 4 * 4096; return false; }; @@ -1735,9 +1833,9 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsCallsMakeReside HWTEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResidentThenTheyAreUsedInsteadOfMemoryManagerMembers) { SetUpMm(); - WddmAllocation allocation1; - WddmAllocation allocation2; - WddmAllocation allocation3; + MockWddmAllocation allocation1; + MockWddmAllocation allocation2; + MockWddmAllocation allocation3; allocation1.handle = 1; allocation2.handle = 2; allocation3.handle = 3; @@ -1761,10 +1859,10 @@ HWTEST_F(WddmMemoryManagerTest2, givenAllocationPackWhenTheyArePassedToMakeResid HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMakeResidentFailsAndTrimToBudgetSucceeds) { SetUpMm(); - WddmAllocation allocation1; + MockWddmAllocation allocation1; void *cpuPtr = reinterpret_cast(wddm->getWddmMinAddress() + 0x1000); size_t allocationSize = 0x1000; - WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr); + WddmAllocation allocationToTrim(cpuPtr, allocationSize, cpuPtr, allocationSize, nullptr, MemoryPool::MemoryNull); allocationToTrim.getResidencyData().lastFence = wddm->getMonitoredFence().lastSubmittedFence; @@ -1785,7 +1883,7 @@ HWTEST_F(WddmMemoryManagerTest2, makeResidentResidencyAllocationsSucceedsWhenMak HWTEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemoryBudgetExhaustedIsReturnedAsTrue) { SetUpMm(); - WddmAllocation allocation1; + MockWddmAllocation allocation1; auto makeResidentThatFails = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return false; }; auto makeResidentThatSucceds = [](D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim) -> bool { return true; };