From b602cd2bb816ad99f5e3a0be92a15a7014e68922 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 1 Oct 2018 16:10:54 +0200 Subject: [PATCH] Pass execution environment to memory manager Change-Id: If43cf9d1353b4cbc02ea269fb9105c01cc4e0876 Signed-off-by: Mateusz Jablonski --- .../aub_command_stream_receiver_hw.h | 2 +- .../tbx_command_stream_receiver_hw.h | 4 +- runtime/device/device.cpp | 2 - runtime/mem_obj/mem_obj.cpp | 6 +- runtime/memory_manager/memory_manager.cpp | 28 ++-- runtime/memory_manager/memory_manager.h | 9 +- .../os_agnostic_memory_manager.h | 5 +- .../os_interface/linux/drm_command_stream.inl | 2 +- .../os_interface/linux/drm_memory_manager.cpp | 10 +- .../os_interface/linux/drm_memory_manager.h | 2 +- .../windows/wddm_device_command_stream.inl | 2 +- .../windows/wddm_memory_manager.cpp | 6 +- .../windows/wddm_memory_manager.h | 2 +- .../command_queue/command_queue_hw_tests.cpp | 14 +- .../read_write_buffer_cpu_copy.cpp | 2 +- .../aub_command_stream_receiver_tests.cpp | 5 +- ...mmand_stream_receiver_flush_task_tests.cpp | 14 +- .../command_stream_receiver_tests.cpp | 26 ++-- .../tbx_command_stream_tests.cpp | 3 +- unit_tests/d3d_sharing/d3d9_tests.cpp | 46 +++--- unit_tests/d3d_sharing/d3d_tests.cpp | 30 ++-- .../execution_environment_tests.cpp | 3 +- .../fixtures/memory_allocator_fixture.h | 11 +- .../fixtures/memory_manager_fixture.cpp | 5 +- unit_tests/fixtures/memory_manager_fixture.h | 4 +- unit_tests/gmm_helper/gmm_helper_tests.cpp | 10 +- unit_tests/gtpin/gtpin_tests.cpp | 11 +- unit_tests/helpers/timestamp_packet_tests.cpp | 8 +- unit_tests/kernel/kernel_image_arg_tests.cpp | 2 +- unit_tests/kernel/kernel_tests.cpp | 2 +- .../libult/ult_command_stream_receiver.h | 2 +- unit_tests/mem_obj/buffer_pin_tests.cpp | 7 +- unit_tests/mem_obj/buffer_tests.cpp | 15 +- unit_tests/mem_obj/image_tests.cpp | 7 +- .../mem_obj/mem_obj_destruction_tests.cpp | 2 +- unit_tests/mem_obj/mem_obj_tests.cpp | 15 +- ..._manager_allocate_in_device_pool_tests.cpp | 3 +- ..._manager_allocate_in_device_pool_tests.inl | 7 +- ...nager_allocate_in_preferred_pool_tests.inl | 20 ++- .../memory_manager/memory_manager_tests.cpp | 128 +++++++++++------ .../memory_manager/svm_memory_manager.cpp | 38 ++--- .../mocks/linux/mock_drm_memory_manager.h | 4 +- unit_tests/mocks/mock_device.cpp | 13 +- unit_tests/mocks/mock_memory_manager.cpp | 4 - unit_tests/mocks/mock_memory_manager.h | 20 +-- .../linux/drm_memory_manager_mt_tests.cpp | 8 +- .../linux/drm_command_stream_tests.cpp | 5 +- .../linux/drm_gem_close_worker_tests.cpp | 4 +- .../linux/drm_memory_manager_tests.cpp | 132 +++++++++--------- .../windows/device_command_stream_tests.cpp | 2 +- .../windows/mock_wddm_memory_manager.h | 4 +- .../os_interface/windows/wddm20_tests.cpp | 16 +-- ..._manager_allocate_in_device_pool_tests.inl | 2 +- .../windows/wddm_memory_manager_tests.cpp | 123 ++++++++-------- .../windows/wddm_memory_manager_tests.h | 4 +- unit_tests/program/kernel_info_tests.cpp | 8 +- .../sharings/gl/gl_arb_sync_event_tests.cpp | 2 +- .../gl/gl_create_from_texture_tests.cpp | 4 + unit_tests/sharings/gl/gl_texture_tests.cpp | 3 +- 59 files changed, 479 insertions(+), 399 deletions(-) diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 5499b704e9..0b0a65e57e 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -69,7 +69,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwmemoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true); + this->memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true, this->executionEnvironment); this->flatBatchBufferHelper->setMemoryManager(this->memoryManager); return this->memoryManager; } diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index c27051a94d..dd0d4dea0c 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -17,7 +17,7 @@ namespace OCLRT { class TbxMemoryManager : public OsAgnosticMemoryManager { public: - TbxMemoryManager(bool enable64kbPages, bool enableLocalMemory) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory) {} + TbxMemoryManager(bool enable64kbPages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment) {} uint64_t getSystemSharedMemory() override { return 1 * GB; } @@ -65,7 +65,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwexecutionEnvironment); return memoryManager; } TbxMemoryManager *getMemoryManager() { diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 5f540c5e61..35fd784ee2 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -123,8 +123,6 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { return false; } - executionEnvironment->memoryManager->csr = outDevice.commandStreamReceiver; - auto pDevice = &outDevice; if (!pDevice->osTime) { pDevice->osTime = OSTime::create(outDevice.commandStreamReceiver->getOSInterface()); diff --git a/runtime/mem_obj/mem_obj.cpp b/runtime/mem_obj/mem_obj.cpp index c2bd89b894..08e2c2d292 100644 --- a/runtime/mem_obj/mem_obj.cpp +++ b/runtime/mem_obj/mem_obj.cpp @@ -288,15 +288,13 @@ void MemObj::releaseAllocatedMapPtr() { void MemObj::waitForCsrCompletion() { if (graphicsAllocation) { - UNRECOVERABLE_IF(!memoryManager->csr); - memoryManager->csr->waitForCompletionWithTimeout(false, TimeoutControls::maxTimeout, graphicsAllocation->taskCount); + memoryManager->getCommandStreamReceiver(0)->waitForCompletionWithTimeout(false, TimeoutControls::maxTimeout, graphicsAllocation->taskCount); } } void MemObj::destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy) { if (asyncDestroy && allocation->taskCount != ObjectNotUsed) { - UNRECOVERABLE_IF(!memoryManager->csr); - auto currentTag = *memoryManager->csr->getTagAddress(); + auto currentTag = *memoryManager->getCommandStreamReceiver(0)->getTagAddress(); if (currentTag < allocation->taskCount) { memoryManager->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); return; diff --git a/runtime/memory_manager/memory_manager.cpp b/runtime/memory_manager/memory_manager.cpp index 64e6515b8b..78fc94c71b 100644 --- a/runtime/memory_manager/memory_manager.cpp +++ b/runtime/memory_manager/memory_manager.cpp @@ -58,8 +58,10 @@ GraphicsAllocation *AllocationsList::detachAllocationImpl(GraphicsAllocation *, return nullptr; } -MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory) : allocator32Bit(nullptr), enable64kbpages(enable64kbpages), - localMemorySupported(enableLocalMemory){}; +MemoryManager::MemoryManager(bool enable64kbpages, bool enableLocalMemory, + ExecutionEnvironment &executionEnvironment) : allocator32Bit(nullptr), enable64kbpages(enable64kbpages), + localMemorySupported(enableLocalMemory), + executionEnvironment(executionEnvironment){}; MemoryManager::~MemoryManager() { freeAllocationsList(-1, graphicsAllocations); @@ -175,8 +177,7 @@ void MemoryManager::storeAllocation(std::unique_ptr gfxAlloc uint32_t taskCount = gfxAllocation->taskCount; if (allocationUsage == REUSABLE_ALLOCATION) { - UNRECOVERABLE_IF(!csr); - taskCount = csr->peekTaskCount(); + taskCount = getCommandStreamReceiver(0)->peekTaskCount(); } storeAllocation(std::move(gfxAllocation), allocationUsage, taskCount); @@ -198,9 +199,8 @@ void MemoryManager::storeAllocation(std::unique_ptr gfxAlloc } std::unique_ptr MemoryManager::obtainReusableAllocation(size_t requiredSize, bool internalAllocation) { - UNRECOVERABLE_IF(!csr); std::lock_guard lock(mtx); - auto allocation = allocationsForReuse.detachAllocation(requiredSize, csr->getTagAddress(), internalAllocation); + auto allocation = allocationsForReuse.detachAllocation(requiredSize, getCommandStreamReceiver(0)->getTagAddress(), internalAllocation); return allocation; } @@ -282,7 +282,7 @@ void MemoryManager::freeGraphicsMemory(GraphicsAllocation *gfxAllocation) { //if not in use destroy in place //if in use pass to temporary allocation list that is cleaned on blocking calls void MemoryManager::checkGpuUsageAndDestroyGraphicsAllocations(GraphicsAllocation *gfxAllocation) { - if (gfxAllocation->taskCount == ObjectNotUsed || gfxAllocation->taskCount <= *csr->getTagAddress()) { + if (gfxAllocation->taskCount == ObjectNotUsed || gfxAllocation->taskCount <= *getCommandStreamReceiver(0)->getTagAddress()) { freeGraphicsMemory(gfxAllocation); } else { storeAllocation(std::unique_ptr(gfxAllocation), TEMPORARY_ALLOCATION); @@ -320,19 +320,19 @@ RequirementsStatus MemoryManager::checkAllocationsForOverlapping(AllocationRequi checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]); if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) { // clean temporary allocations - UNRECOVERABLE_IF(!csr); - uint32_t taskCount = *csr->getTagAddress(); + + uint32_t taskCount = *getCommandStreamReceiver(0)->getTagAddress(); cleanAllocationList(taskCount, TEMPORARY_ALLOCATION); // check overlapping again checkedFragments->fragments[i] = hostPtrManager.getFragmentAndCheckForOverlaps(requirements->AllocationFragments[i].allocationPtr, requirements->AllocationFragments[i].allocationSize, checkedFragments->status[i]); - if (checkedFragments->status[i] == OverlapStatus::FRAGMENT_OVERLAPING_AND_BIGGER_THEN_STORED_FRAGMENT) { + // Wait for completion - while (*csr->getTagAddress() < csr->peekLatestSentTaskCount()) { + while (*getCommandStreamReceiver(0)->getTagAddress() < getCommandStreamReceiver(0)->peekLatestSentTaskCount()) { } - taskCount = *csr->getTagAddress(); + taskCount = *getCommandStreamReceiver(0)->getTagAddress(); cleanAllocationList(taskCount, TEMPORARY_ALLOCATION); // check overlapping last time @@ -456,5 +456,9 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemory(const AllocationData & } return allocateGraphicsMemory(allocationData.size, MemoryConstants::pageSize, allocationData.flags.forcePin, allocationData.flags.uncacheable); } +CommandStreamReceiver *MemoryManager::getCommandStreamReceiver(uint32_t contextId) { + UNRECOVERABLE_IF(executionEnvironment.commandStreamReceivers.size() < 1); + return executionEnvironment.commandStreamReceivers[contextId].get(); +} } // namespace OCLRT diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 1fe4dc5575..4bde18c214 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -19,6 +19,7 @@ namespace OCLRT { class Device; class DeferredDeleter; +class ExecutionEnvironment; class GraphicsAllocation; class CommandStreamReceiver; class TimestampPacket; @@ -122,7 +123,7 @@ class MemoryManager { RetryInNonDevicePool }; - MemoryManager(bool enable64kbpages, bool enableLocalMemory); + MemoryManager(bool enable64kbpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment); virtual ~MemoryManager(); MOCKABLE_VIRTUAL void *allocateSystemMemory(size_t size, size_t alignment); @@ -220,15 +221,13 @@ class MemoryManager { TagAllocator *getEventPerfCountAllocator(); TagAllocator *getTimestampPacketAllocator(); - std::unique_ptr obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired); + MOCKABLE_VIRTUAL std::unique_ptr obtainReusableAllocation(size_t requiredSize, bool isInternalAllocationRequired); //intrusive list of allocation AllocationsList graphicsAllocations; //intrusive list of allocation for re-use AllocationsList allocationsForReuse; - - CommandStreamReceiver *csr = nullptr; HostPtrManager hostPtrManager; virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0; @@ -266,6 +265,7 @@ class MemoryManager { virtual void registerOsContext(OsContext *contextToRegister); size_t getOsContextCount() { return registeredOsContexts.size(); } + CommandStreamReceiver *getCommandStreamReceiver(uint32_t contextId); protected: static bool getAllocationData(AllocationData &allocationData, const AllocationFlags &flags, const DevicesBitfield devicesBitfield, @@ -284,6 +284,7 @@ class MemoryManager { bool asyncDeleterEnabled = false; bool enable64kbpages = false; bool localMemorySupported = false; + ExecutionEnvironment &executionEnvironment; std::vector registeredOsContexts; }; diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index fd2c089bcf..6f1906cf9d 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -37,10 +37,9 @@ class OsAgnosticMemoryManager : public MemoryManager { using MemoryManager::allocateGraphicsMemory; using MemoryManager::createGraphicsAllocationFromSharedHandle; - OsAgnosticMemoryManager() : OsAgnosticMemoryManager(false, false){}; - OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false){}; + OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false, executionEnvironment){}; - OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage) : MemoryManager(enable64kbPages, enableLocalMemory) { + OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment) { allocator32Bit = std::unique_ptr(create32BitAllocator(aubUsage)); }; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index ecfd0a3f47..0ba7d789d8 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -152,7 +152,7 @@ DrmMemoryManager *DrmCommandStreamReceiver::getMemoryManager() { template MemoryManager *DrmCommandStreamReceiver::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - memoryManager = new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true); + memoryManager = new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment); return memoryManager; } diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index afa065782b..7601cc0d3f 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -25,11 +25,11 @@ namespace OCLRT { -DrmMemoryManager::DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory) : MemoryManager(false, false), - drm(drm), - pinBB(nullptr), - forcePinEnabled(forcePinAllowed), - validateHostPtrMemory(validateHostPtrMemory) { +DrmMemoryManager::DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment) : MemoryManager(false, false, executionEnvironment), + drm(drm), + pinBB(nullptr), + forcePinEnabled(forcePinAllowed), + validateHostPtrMemory(validateHostPtrMemory) { MemoryManager::virtualPaddingAvailable = true; if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) { gemCloseWorker.reset(new DrmGemCloseWorker(*this)); diff --git a/runtime/os_interface/linux/drm_memory_manager.h b/runtime/os_interface/linux/drm_memory_manager.h index fd6f8d0517..b347fc9d57 100644 --- a/runtime/os_interface/linux/drm_memory_manager.h +++ b/runtime/os_interface/linux/drm_memory_manager.h @@ -22,7 +22,7 @@ class DrmMemoryManager : public MemoryManager { using MemoryManager::allocateGraphicsMemory; using MemoryManager::createGraphicsAllocationFromSharedHandle; - DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory); + DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment); ~DrmMemoryManager() override; BufferObject *getPinBB() const; diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index 111e3f02d2..00b3b5b589 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -155,7 +155,7 @@ WddmMemoryManager *WddmCommandStreamReceiver::getMemoryManager() { template MemoryManager *WddmCommandStreamReceiver::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - return memoryManager = new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm); + return memoryManager = new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment); } template diff --git a/runtime/os_interface/windows/wddm_memory_manager.cpp b/runtime/os_interface/windows/wddm_memory_manager.cpp index bf1435e91b..f4035813f7 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.cpp +++ b/runtime/os_interface/windows/wddm_memory_manager.cpp @@ -28,7 +28,7 @@ WddmMemoryManager::~WddmMemoryManager() { applyCommonCleanup(); } -WddmMemoryManager::WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm) : MemoryManager(enable64kbPages, enableLocalMemory), residencyLock(false) { +WddmMemoryManager::WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm, ExecutionEnvironment &executionEnvironment) : MemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment), residencyLock(false) { DEBUG_BREAK_IF(wddm == nullptr); this->wddm = wddm; allocator32Bit = std::unique_ptr(new Allocator32bit(wddm->getHeap32Base(), wddm->getHeap32Size())); @@ -301,8 +301,8 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation UNRECOVERABLE_IF(DebugManager.flags.CreateMultipleDevices.get() == 0 && gfxAllocation->taskCount != ObjectNotUsed && - this->csr && this->csr->getTagAddress() && - gfxAllocation->taskCount > *this->csr->getTagAddress()); + this->getCommandStreamReceiver(0) && this->getCommandStreamReceiver(0)->getTagAddress() && + gfxAllocation->taskCount > *this->getCommandStreamReceiver(0)->getTagAddress()); if (input->gmm) { if (input->gmm->isRenderCompressed) { diff --git a/runtime/os_interface/windows/wddm_memory_manager.h b/runtime/os_interface/windows/wddm_memory_manager.h index bec3abf89f..50a874fb28 100644 --- a/runtime/os_interface/windows/wddm_memory_manager.h +++ b/runtime/os_interface/windows/wddm_memory_manager.h @@ -28,7 +28,7 @@ class WddmMemoryManager : public MemoryManager { using MemoryManager::createGraphicsAllocationFromSharedHandle; ~WddmMemoryManager(); - WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm); + WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm, ExecutionEnvironment &executionEnvironment); WddmMemoryManager(const WddmMemoryManager &) = delete; WddmMemoryManager &operator=(const WddmMemoryManager &) = delete; diff --git a/unit_tests/command_queue/command_queue_hw_tests.cpp b/unit_tests/command_queue/command_queue_hw_tests.cpp index c06f3f72f5..a5c16f8d31 100644 --- a/unit_tests/command_queue/command_queue_hw_tests.cpp +++ b/unit_tests/command_queue/command_queue_hw_tests.cpp @@ -1017,11 +1017,11 @@ HWTEST_F(CommandQueueHwTest, givenKernelSplitEnqueueReadBufferWhenBlockedThenEnq } HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfaceWithPtrCopyAllowedIsCreatedThenCopyAllocationIsCreatedAndMemoryCopied) { - ::testing::NiceMock *gmockMemoryManager = new ::testing::NiceMock; - ASSERT_NE(nullptr, gmockMemoryManager); - std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); ASSERT_NE(nullptr, device.get()); + ::testing::NiceMock *gmockMemoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); + ASSERT_NE(nullptr, gmockMemoryManager); + device->injectMemoryManager(gmockMemoryManager); MockContext *mockContext = new MockContext(device.get()); ASSERT_NE(nullptr, mockContext); @@ -1058,11 +1058,11 @@ HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfac } HWTEST_F(CommandQueueHwTest, givenReadOnlyHostPointerWhenAllocationForHostSurfaceWithPtrCopyNotAllowedIsCreatedThenCopyAllocationIsNotCreated) { - ::testing::NiceMock *gmockMemoryManager = new ::testing::NiceMock; - ASSERT_NE(nullptr, gmockMemoryManager); - std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); ASSERT_NE(nullptr, device.get()); + ::testing::NiceMock *gmockMemoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); + ASSERT_NE(nullptr, gmockMemoryManager); + device->injectMemoryManager(gmockMemoryManager); MockContext *mockContext = new MockContext(device.get()); ASSERT_NE(nullptr, mockContext); @@ -1107,7 +1107,7 @@ struct ReducedAddrSpaceCommandQueueHwTest : public CommandQueueHwTest { hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress; device.reset(MockDevice::createWithNewExecutionEnvironment(&hwInfoToModify)); ASSERT_NE(nullptr, device.get()); - gmockMemoryManager = new ::testing::NiceMock; + gmockMemoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); ASSERT_NE(nullptr, gmockMemoryManager); device->injectMemoryManager(gmockMemoryManager); mockContext = new MockContext(device.get()); diff --git a/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp b/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp index 7ac81e7b3e..efb534e40c 100644 --- a/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp +++ b/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp @@ -295,7 +295,7 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, cpuCopyCriteriaNotMet) { TEST(ReadWriteBufferOnCpu, givenNoHostPtrAndAlignedSizeWhenMemoryAllocationIsInNonSystemMemoryPoolThenIsReadWriteOnCpuAllowedReturnsFalse) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - auto memoryManager = new MockMemoryManager; + auto memoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); diff --git a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp index 5d0932d89d..f637a9e15d 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -1364,7 +1364,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddBatc class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryManager { public: - OsAgnosticMemoryManagerForImagesWithNoHostPtr() : OsAgnosticMemoryManager(false, false) {} + OsAgnosticMemoryManagerForImagesWithNoHostPtr(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) {} GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override { auto imageAllocation = OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(imgInfo, gmm); @@ -1405,9 +1405,8 @@ class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryMan }; HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledOnImageWithNoHostPtrThenResourceShouldBeLockedToGetCpuAddress) { - std::unique_ptr memoryManager(nullptr); + auto memoryManager = std::make_unique(*pDevice->executionEnvironment); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - memoryManager.reset(new OsAgnosticMemoryManagerForImagesWithNoHostPtr); aubCsr->setMemoryManager(memoryManager.get()); cl_image_desc imgDesc = {}; diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp index ae6cc3e99a..9324eb2e9e 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_tests.cpp @@ -2582,7 +2582,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenSusbsequ } struct MockedMemoryManager : public OsAgnosticMemoryManager { - MockedMemoryManager() : OsAgnosticMemoryManager(false, false) {} + MockedMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) {} bool isMemoryBudgetExhausted() const override { return budgetExhausted; } bool budgetExhausted = false; }; @@ -2590,15 +2590,15 @@ struct MockedMemoryManager : public OsAgnosticMemoryManager { HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalResourceUsedExhaustsTheBudgetThenDoImplicitFlush) { CommandQueueHw commandQueue(nullptr, pDevice, 0); auto &commandStream = commandQueue.getCS(4096u); - - std::unique_ptr mockedMemoryManager(new MockedMemoryManager()); - std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment)); - - mockCsr->setMemoryManager(mockedMemoryManager.get()); + ExecutionEnvironment executionEnvironment; + auto mockedMemoryManager = new MockedMemoryManager(executionEnvironment); + executionEnvironment.memoryManager.reset(mockedMemoryManager); + auto mockCsr = new MockCsrHw2(*platformDevices[0], executionEnvironment); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(mockCsr)); + mockCsr->setMemoryManager(mockedMemoryManager); mockCsr->initializeTagAllocation(); mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation()); mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); - mockedMemoryManager->csr = mockCsr.get(); auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index 90a1fba439..dddb1a22f9 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -180,7 +180,7 @@ HWTEST_F(CommandStreamReceiverTest, givenCommandStreamerWhenPtrAndSizeDoNotMeetL TEST_F(CommandStreamReceiverTest, memoryManagerHasAccessToCSR) { auto *memoryManager = commandStreamReceiver->getMemoryManager(); - EXPECT_EQ(commandStreamReceiver, memoryManager->csr); + EXPECT_EQ(commandStreamReceiver, memoryManager->getCommandStreamReceiver(0)); } HWTEST_F(CommandStreamReceiverTest, storedAllocationsHaveCSRtaskCount) { @@ -317,32 +317,39 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye auto mockGraphicsAllocation = new MockGraphicsAllocation(nullptr, 1u); mockGraphicsAllocation->destructorCalled = &destructorCalled; - std::unique_ptr csr(new MockCommandStreamReceiver); - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false)); + ExecutionEnvironment executionEnvironment; + executionEnvironment.commandStreamReceivers.push_back(std::make_unique()); + auto csr = executionEnvironment.commandStreamReceivers[0].get(); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, executionEnvironment)); csr->setMemoryManager(memoryManager.get()); csr->setTagAllocation(mockGraphicsAllocation); EXPECT_FALSE(destructorCalled); - csr.reset(nullptr); + executionEnvironment.commandStreamReceivers[0].reset(nullptr); EXPECT_TRUE(destructorCalled); } TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocated) { - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false)); - std::unique_ptr csr(new MockCommandStreamReceiver); - csr->setMemoryManager(memoryManager.get()); + auto csr = new MockCommandStreamReceiver; + auto executionEnvironment = csr->mockExecutionEnvironment.get(); + executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr(csr)); + executionEnvironment->memoryManager.reset(new OsAgnosticMemoryManager(false, false, *executionEnvironment)); + csr->setMemoryManager(executionEnvironment->memoryManager.get()); EXPECT_EQ(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() == nullptr); csr->initializeTagAllocation(); EXPECT_NE(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() != nullptr); EXPECT_EQ(*csr->getTagAddress(), initialHardwareTag); + csr->mockExecutionEnvironment.reset(); } TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocatedAndinitialValueIsMinusOne) { DebugManagerStateRestore dbgRestore; DebugManager.flags.EnableNullHardware.set(true); - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false)); - std::unique_ptr csr(new MockCommandStreamReceiver); + auto csr = new MockCommandStreamReceiver; + auto executionEnvironment = csr->mockExecutionEnvironment.get(); + executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr(csr)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *executionEnvironment)); csr->setMemoryManager(memoryManager.get()); EXPECT_EQ(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() == nullptr); @@ -350,6 +357,7 @@ TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTa EXPECT_NE(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() != nullptr); EXPECT_EQ(*csr->getTagAddress(), static_cast(-1)); + csr->mockExecutionEnvironment.reset(); } TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) { diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 26294fbdde..14f10e1f67 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -284,7 +284,8 @@ HWTEST_F(TbxCommandStreamTests, givenTbxCommandStreamReceiverWhenFlushIsCalledTh } TEST(TbxMemoryManagerTest, givenTbxMemoryManagerWhenItIsQueriedForSystemSharedMemoryThen1GBIsReturned) { - TbxMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + TbxMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_EQ(1 * GB, memoryManager.getSystemSharedMemory()); } diff --git a/unit_tests/d3d_sharing/d3d9_tests.cpp b/unit_tests/d3d_sharing/d3d9_tests.cpp index e7a558ee4b..29f0346eee 100644 --- a/unit_tests/d3d_sharing/d3d9_tests.cpp +++ b/unit_tests/d3d_sharing/d3d9_tests.cpp @@ -40,6 +40,7 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { class MockMM : public OsAgnosticMemoryManager { public: + MockMM(const ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, const_cast(executionEnvironment)){}; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); alloc->gmm = forceGmm; @@ -71,15 +72,16 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { gmm = MockGmm::queryImgParams(imgInfo).release(); mockGmmResInfo = reinterpret_cast *>(gmm->gmmResourceInfo.get()); - mockMM.forceGmm = gmm; + mockMM->forceGmm = gmm; } void SetUp() override { dbgRestore = new DebugManagerStateRestore(); PlatformFixture::SetUp(); + mockMM = std::make_unique>(*pPlatform->peekExecutionEnvironment()); context = new MockContext(pPlatform->getDevice(0)); context->forcePreferD3dSharedResources(true); - context->setMemoryManager(&mockMM); + context->setMemoryManager(mockMM.get()); mockSharingFcns = new NiceMock>(); context->setSharingFunctions(mockSharingFcns); @@ -98,7 +100,7 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { void TearDown() override { delete cmdQ; delete context; - if (!mockMM.gmmOwnershipPassed) { + if (!mockMM->gmmOwnershipPassed) { delete gmm; } PlatformFixture::TearDown(); @@ -115,7 +117,7 @@ class D3D9Tests : public PlatformFixture, public ::testing::Test { Gmm *gmm = nullptr; NiceMock *mockGmmResInfo = nullptr; - NiceMock mockMM; + std::unique_ptr> mockMM; }; TEST_F(D3D9Tests, givenD3DDeviceParamWhenContextCreationThenSetProperValues) { @@ -518,9 +520,9 @@ TEST_F(D3D9Tests, acquireReleaseOnSharedResourceSurfaceAndEnabledInteropUserSync EXPECT_CALL(*mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(mockSharingFcns->mockTexture2dDesc)); EXPECT_CALL(*mockSharingFcns, getRenderTargetData(_, _)).Times(0); EXPECT_CALL(*mockSharingFcns, lockRect(_, _, _)).Times(0); - EXPECT_CALL(mockMM, lockResource(_)).Times(0); + EXPECT_CALL(*mockMM, lockResource(_)).Times(0); EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(0); - EXPECT_CALL(mockMM, unlockResource(_)).Times(0); + EXPECT_CALL(*mockMM, unlockResource(_)).Times(0); EXPECT_CALL(*mockSharingFcns, unlockRect(_)).Times(0); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(0); EXPECT_CALL(*mockSharingFcns, updateSurface(_, _)).Times(0); @@ -547,9 +549,9 @@ TEST_F(D3D9Tests, acquireReleaseOnSharedResourceSurfaceAndDisabledInteropUserSyn EXPECT_CALL(*mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(mockSharingFcns->mockTexture2dDesc)); EXPECT_CALL(*mockSharingFcns, getRenderTargetData(_, _)).Times(0); EXPECT_CALL(*mockSharingFcns, lockRect(_, _, _)).Times(0); - EXPECT_CALL(mockMM, lockResource(_)).Times(0); + EXPECT_CALL(*mockMM, lockResource(_)).Times(0); EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(0); - EXPECT_CALL(mockMM, unlockResource(_)).Times(0); + EXPECT_CALL(*mockMM, unlockResource(_)).Times(0); EXPECT_CALL(*mockSharingFcns, unlockRect(_)).Times(0); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(1); EXPECT_CALL(*mockSharingFcns, updateSurface(_, _)).Times(0); @@ -575,9 +577,9 @@ TEST_F(D3D9Tests, acquireReleaseOnSharedResourceSurfaceAndDisabledInteropUserSyn EXPECT_CALL(*mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(mockSharingFcns->mockTexture2dDesc)); EXPECT_CALL(*mockSharingFcns, getRenderTargetData(_, _)).Times(0); EXPECT_CALL(*mockSharingFcns, lockRect(_, _, _)).Times(0); - EXPECT_CALL(mockMM, lockResource(_)).Times(0); + EXPECT_CALL(*mockMM, lockResource(_)).Times(0); EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(0); - EXPECT_CALL(mockMM, unlockResource(_)).Times(0); + EXPECT_CALL(*mockMM, unlockResource(_)).Times(0); EXPECT_CALL(*mockSharingFcns, unlockRect(_)).Times(0); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(1); EXPECT_CALL(*mockSharingFcns, updateSurface(_, _)).Times(0); @@ -611,7 +613,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockable) { EXPECT_CALL(*mockSharingFcns, getRenderTargetData(_, _)).Times(0); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurface, _, D3DLOCK_READONLY)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); GMM_RES_COPY_BLT requestedResCopyBlt = {}; GMM_RES_COPY_BLT expectedResCopyBlt = {}; @@ -622,7 +624,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockable) { expectedResCopyBlt.Sys.BufferSize = lockedRect.Pitch * imgHeight; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurface)).Times(1); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(1); @@ -631,13 +633,13 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockable) { EXPECT_TRUE(memcmp(&requestedResCopyBlt, &expectedResCopyBlt, sizeof(GMM_RES_COPY_BLT)) == 0); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurface, _, 0u)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); requestedResCopyBlt = {}; expectedResCopyBlt.Blt.Upload = 0; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurface)).Times(1); EXPECT_CALL(*mockSharingFcns, updateSurface(_, _)).Times(0); @@ -663,7 +665,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockableIntel) { EXPECT_CALL(*mockSharingFcns, getRenderTargetData(_, _)).Times(0); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurface, _, D3DLOCK_READONLY)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); GMM_RES_COPY_BLT requestedResCopyBlt = {}; GMM_RES_COPY_BLT expectedResCopyBlt = {}; @@ -674,7 +676,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockableIntel) { expectedResCopyBlt.Sys.BufferSize = lockedRect.Pitch * imgHeight; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurface)).Times(1); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(1); @@ -683,13 +685,13 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndLockableIntel) { EXPECT_TRUE(memcmp(&requestedResCopyBlt, &expectedResCopyBlt, sizeof(GMM_RES_COPY_BLT)) == 0); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurface, _, 0u)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); requestedResCopyBlt = {}; expectedResCopyBlt.Blt.Upload = 0; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurface)).Times(1); EXPECT_CALL(*mockSharingFcns, updateSurface(_, _)).Times(0); @@ -717,7 +719,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndNonLockable) { EXPECT_CALL(*mockSharingFcns, getRenderTargetData((IDirect3DSurface9 *)&dummyD3DSurface, (IDirect3DSurface9 *)&dummyD3DSurfaceStaging)).Times(1); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurfaceStaging, _, D3DLOCK_READONLY)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); GMM_RES_COPY_BLT requestedResCopyBlt = {}; GMM_RES_COPY_BLT expectedResCopyBlt = {}; @@ -728,7 +730,7 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndNonLockable) { expectedResCopyBlt.Sys.BufferSize = lockedRect.Pitch * imgHeight; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurfaceStaging)).Times(1); EXPECT_CALL(*mockSharingFcns, flushAndWait(_)).Times(1); @@ -737,13 +739,13 @@ TEST_F(D3D9Tests, acquireReleaseOnNonSharedResourceSurfaceAndNonLockable) { EXPECT_TRUE(memcmp(&requestedResCopyBlt, &expectedResCopyBlt, sizeof(GMM_RES_COPY_BLT)) == 0); EXPECT_CALL(*mockSharingFcns, lockRect((IDirect3DSurface9 *)&dummyD3DSurfaceStaging, _, 0)).Times(1).WillOnce(SetArgPointee<1>(lockedRect)); - EXPECT_CALL(mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); + EXPECT_CALL(*mockMM, lockResource(sharedImg->getGraphicsAllocation())).Times(1).WillOnce(::testing::Return(returnedLockedRes)); requestedResCopyBlt = {}; expectedResCopyBlt.Blt.Upload = 0; EXPECT_CALL(*mockGmmResInfo, cpuBlt(_)).Times(1).WillOnce(::testing::Invoke([&](GMM_RES_COPY_BLT *arg) {requestedResCopyBlt = *arg; return 1; })); - EXPECT_CALL(mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); + EXPECT_CALL(*mockMM, unlockResource(sharedImg->getGraphicsAllocation())).Times(1); EXPECT_CALL(*mockSharingFcns, unlockRect((IDirect3DSurface9 *)&dummyD3DSurfaceStaging)).Times(1); EXPECT_CALL(*mockSharingFcns, updateSurface((IDirect3DSurface9 *)&dummyD3DSurfaceStaging, (IDirect3DSurface9 *)&dummyD3DSurface)).Times(1); diff --git a/unit_tests/d3d_sharing/d3d_tests.cpp b/unit_tests/d3d_sharing/d3d_tests.cpp index 6368d4b23d..7cdfe44735 100644 --- a/unit_tests/d3d_sharing/d3d_tests.cpp +++ b/unit_tests/d3d_sharing/d3d_tests.cpp @@ -56,6 +56,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { class MockMM : public OsAgnosticMemoryManager { public: + using OsAgnosticMemoryManager::OsAgnosticMemoryManager; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); alloc->gmm = forceGmm; @@ -88,7 +89,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { gmm = MockGmm::queryImgParams(imgInfo).release(); mockGmmResInfo = reinterpret_cast *>(gmm->gmmResourceInfo.get()); - mockMM.forceGmm = gmm; + mockMM->forceGmm = gmm; } void SetUp() override { @@ -96,10 +97,11 @@ class D3DTests : public PlatformFixture, public ::testing::Test { PlatformFixture::SetUp(); context = new MockContext(pPlatform->getDevice(0)); context->forcePreferD3dSharedResources(true); + mockMM = std::make_unique(false, false, *context->getDevice(0)->getExecutionEnvironment()); mockSharingFcns = new NiceMock>(); context->setSharingFunctions(mockSharingFcns); - context->setMemoryManager(&mockMM); + context->setMemoryManager(mockMM.get()); cmdQ = new MockCommandQueue(context, context->getDevice(0), 0); DebugManager.injectFcn = &mockSharingFcns->mockGetDxgiDesc; @@ -122,7 +124,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { void TearDown() override { delete cmdQ; delete context; - if (!mockMM.gmmOwnershipPassed) { + if (!mockMM->gmmOwnershipPassed) { delete gmm; } PlatformFixture::TearDown(); @@ -198,7 +200,7 @@ class D3DTests : public PlatformFixture, public ::testing::Test { NiceMock *mockGmmResInfo = nullptr; DebugManagerStateRestore *dbgRestore; - MockMM mockMM; + std::unique_ptr mockMM; uint8_t d3dMode = 0; }; @@ -1328,7 +1330,7 @@ TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithUnifiedAuxFlagsWhenCreatingT auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_TRUE(gmm->isRenderCompressed); } @@ -1340,11 +1342,11 @@ TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithUnifiedAuxFlagsWhenFailOnAux mockGmmResInfo->setUnifiedAuxTranslationCapable(); EXPECT_CALL(*this->mockSharingFcns, getTexture2dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture2dDesc)); - mockMM.mapAuxGpuVaRetValue = false; + mockMM->mapAuxGpuVaRetValue = false; auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_FALSE(gmm->isRenderCompressed); } @@ -1360,7 +1362,7 @@ TYPED_TEST_P(D3DAuxTests, given2dSharableTextureWithoutUnifiedAuxFlagsWhenCreati auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 4, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(0u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(0u, mockMM->mapAuxGpuVACalled); EXPECT_FALSE(gmm->isRenderCompressed); } @@ -1372,7 +1374,7 @@ TYPED_TEST_P(D3DAuxTests, given2dNonSharableTextureWithUnifiedAuxFlagsWhenCreati auto image = std::unique_ptr(D3DTexture::create2d(this->context, (D3DTexture2d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_TRUE(gmm->isRenderCompressed); } @@ -1385,7 +1387,7 @@ TYPED_TEST_P(D3DAuxTests, given3dSharableTextureWithUnifiedAuxFlagsWhenCreatingT std::unique_ptr image(D3DTexture::create3d(this->context, (D3DTexture3d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_TRUE(gmm->isRenderCompressed); } @@ -1395,11 +1397,11 @@ TYPED_TEST_P(D3DAuxTests, given3dSharableTextureWithUnifiedAuxFlagsWhenFailOnAux mockGmmResInfo->setUnifiedAuxTranslationCapable(); EXPECT_CALL(*this->mockSharingFcns, getTexture3dDesc(_, _)).Times(1).WillOnce(SetArgPointee<0>(this->mockSharingFcns->mockTexture3dDesc)); - mockMM.mapAuxGpuVaRetValue = false; + mockMM->mapAuxGpuVaRetValue = false; std::unique_ptr image(D3DTexture::create3d(this->context, (D3DTexture3d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_FALSE(gmm->isRenderCompressed); } @@ -1413,7 +1415,7 @@ TYPED_TEST_P(D3DAuxTests, given3dSharableTextureWithoutUnifiedAuxFlagsWhenCreati std::unique_ptr image(D3DTexture::create3d(this->context, (D3DTexture3d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(0u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(0u, mockMM->mapAuxGpuVACalled); EXPECT_FALSE(gmm->isRenderCompressed); } @@ -1425,7 +1427,7 @@ TYPED_TEST_P(D3DAuxTests, given3dNonSharableTextureWithUnifiedAuxFlagsWhenCreati std::unique_ptr image(D3DTexture::create3d(this->context, (D3DTexture3d *)&this->dummyD3DTexture, CL_MEM_READ_WRITE, 1, nullptr)); ASSERT_NE(nullptr, image.get()); - EXPECT_EQ(1u, mockMM.mapAuxGpuVACalled); + EXPECT_EQ(1u, mockMM->mapAuxGpuVACalled); EXPECT_TRUE(gmm->isRenderCompressed); } diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 4103ca2641..cbf19951bb 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -19,6 +19,7 @@ #include "test.h" #include "unit_tests/mocks/mock_csr.h" +#include "unit_tests/mocks/mock_memory_manager.h" #include "unit_tests/utilities/destructor_counted.h" using namespace OCLRT; @@ -155,7 +156,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe struct OsInterfaceMock : public DestructorCounted { OsInterfaceMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; - struct MemoryMangerMock : public DestructorCounted { + struct MemoryMangerMock : public DestructorCounted { MemoryMangerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; struct AubCenterMock : public DestructorCounted { diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index 7fe5173f08..86f8a32ad1 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -18,17 +18,18 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { public: void SetUp() override { MemoryManagementFixture::SetUp(); - memoryManager = new OsAgnosticMemoryManager(false, false); - memoryManager->csr = createCommandStream(*platformDevices, executionEnvironment); + executionEnvironment = std::make_unique(); + executionEnvironment->initializeCommandStreamReceiver(*platformDevices, 0u); + memoryManager = new OsAgnosticMemoryManager(false, false, *executionEnvironment); + executionEnvironment->memoryManager.reset(memoryManager); } void TearDown() override { - delete memoryManager->csr; - delete memoryManager; + executionEnvironment.reset(); MemoryManagementFixture::TearDown(); } protected: - ExecutionEnvironment executionEnvironment; + std::unique_ptr executionEnvironment; MemoryManager *memoryManager; }; diff --git a/unit_tests/fixtures/memory_manager_fixture.cpp b/unit_tests/fixtures/memory_manager_fixture.cpp index 33dd408c5d..d51eb27c95 100644 --- a/unit_tests/fixtures/memory_manager_fixture.cpp +++ b/unit_tests/fixtures/memory_manager_fixture.cpp @@ -13,14 +13,15 @@ using namespace OCLRT; using ::testing::NiceMock; void MemoryManagerWithCsrFixture::SetUp() { - gmockMemoryManager = new NiceMock; + csr = new MockCommandStreamReceiver(this->executionEnvironment); + gmockMemoryManager = new NiceMock(executionEnvironment); memoryManager = gmockMemoryManager; ON_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerCleanAllocationList)); ON_CALL(*gmockMemoryManager, populateOsHandles(::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerPopulateOsHandles)); csr->tagAddress = ¤tGpuTag; - memoryManager->csr = csr.get(); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(csr)); } void MemoryManagerWithCsrFixture::TearDown() { diff --git a/unit_tests/fixtures/memory_manager_fixture.h b/unit_tests/fixtures/memory_manager_fixture.h index b317f3846b..c774680512 100644 --- a/unit_tests/fixtures/memory_manager_fixture.h +++ b/unit_tests/fixtures/memory_manager_fixture.h @@ -20,12 +20,10 @@ class MemoryManagerWithCsrFixture { MemoryManager *memoryManager; GMockMemoryManager *gmockMemoryManager; ExecutionEnvironment executionEnvironment; - std::unique_ptr csr; + MockCommandStreamReceiver *csr; uint32_t taskCount = 0; uint32_t currentGpuTag = initialHardwareTag; - MemoryManagerWithCsrFixture() { csr = std::make_unique(this->executionEnvironment); } - ~MemoryManagerWithCsrFixture() = default; void SetUp(); diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 5ce3e2667f..0ff675aea6 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -24,7 +24,7 @@ using namespace ::testing; namespace OCLRT { -class GmmTests : public ::testing::Test { +struct GmmTests : public ::testing::Test { void SetUp() override { executionEnvironment.initGmm(*platformDevices); } @@ -49,7 +49,7 @@ TEST(GmmGlTests, givenGmmWhenAskedforCubeFaceIndexThenProperValueIsReturned) { } TEST_F(GmmTests, resourceCreation) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); @@ -63,7 +63,7 @@ TEST_F(GmmTests, resourceCreation) { } TEST_F(GmmTests, resourceCreationUncacheable) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, true)); @@ -79,7 +79,7 @@ TEST_F(GmmTests, resourceCreationUncacheable) { } TEST_F(GmmTests, resourceCleanupOnDelete) { - std::unique_ptr mm(new OsAgnosticMemoryManager(false, false)); + std::unique_ptr mm(new OsAgnosticMemoryManager(false, false, executionEnvironment)); void *pSysMem = mm->allocateSystemMemory(4096, 4096); std::unique_ptr gmm(new Gmm(pSysMem, 4096, false)); @@ -92,7 +92,7 @@ TEST_F(GmmTests, resourceCleanupOnDelete) { TEST_F(GmmTests, GivenBufferSizeLargerThenMaxPitchWhenAskedForGmmCreationThenGMMResourceIsCreatedWithNoRestrictionsFlag) { auto maxSize = GmmHelper::maxPossiblePitch; - MemoryManager *mm = new OsAgnosticMemoryManager(false, false); + MemoryManager *mm = new OsAgnosticMemoryManager(false, false, executionEnvironment); void *pSysMem = mm->allocateSystemMemory(4096, 4096); auto gmmRes = new Gmm(pSysMem, maxSize, false); diff --git a/unit_tests/gtpin/gtpin_tests.cpp b/unit_tests/gtpin/gtpin_tests.cpp index 2addd706a7..2d60d0740e 100644 --- a/unit_tests/gtpin/gtpin_tests.cpp +++ b/unit_tests/gtpin/gtpin_tests.cpp @@ -118,7 +118,7 @@ void OnCommandBufferComplete(command_buffer_handle_t cb) { class MockMemoryManagerWithFailures : public OsAgnosticMemoryManager { public: - using OsAgnosticMemoryManager::OsAgnosticMemoryManager; + MockMemoryManagerWithFailures(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){}; GraphicsAllocation *allocateGraphicsMemoryInPreferredPool(AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) override { if (failAllAllocationsInPreferredPool) { @@ -139,11 +139,11 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture { MemoryManagementFixture::SetUp(); constructPlatform(); pPlatform = platform(); - pPlatform->initialize(); - memoryManager = new MockMemoryManagerWithFailures(); - ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + auto executionEnvironment = pPlatform->peekExecutionEnvironment(); + memoryManager = new MockMemoryManagerWithFailures(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - pDevice = Device::create(platformDevices[0], executionEnvironment, 0u); + pPlatform->initialize(); + pDevice = pPlatform->getDevice(0); cl_device_id device = (cl_device_id)pDevice; ContextFixture::SetUp(1, &device); @@ -166,7 +166,6 @@ class GTPinFixture : public ContextFixture, public MemoryManagementFixture { void TearDown() override { ContextFixture::TearDown(); platformImpl.reset(nullptr); - delete pDevice; MemoryManagementFixture::TearDown(); OCLRT::isGTPinInitialized = false; } diff --git a/unit_tests/helpers/timestamp_packet_tests.cpp b/unit_tests/helpers/timestamp_packet_tests.cpp index 7e5943a3e8..bbf6a41176 100644 --- a/unit_tests/helpers/timestamp_packet_tests.cpp +++ b/unit_tests/helpers/timestamp_packet_tests.cpp @@ -292,7 +292,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, TimestampPacketTests, givenTimestampPacketWhenDispat } HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenEnqueueingThenObtainNewStampAndPassToEvent) { - auto mockMemoryManager = new MockMemoryManager(); + auto mockMemoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); device->injectMemoryManager(mockMemoryManager); context->setMemoryManager(mockMemoryManager); auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager); @@ -549,7 +549,7 @@ HWTEST_F(TimestampPacketTests, givenTimestampPacketWriteEnabledWhenDispatchingTh } TEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenObtainingThenGetNewBeforeReleasing) { - auto mockMemoryManager = new MockMemoryManager(); + auto mockMemoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); device->injectMemoryManager(mockMemoryManager); context->setMemoryManager(mockMemoryManager); auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager, 1); @@ -568,7 +568,7 @@ TEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenObtainingThenGetNewBefo } HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingNonBlockedThenMakeItResident) { - auto mockMemoryManager = new MockMemoryManager(); + auto mockMemoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); device->injectMemoryManager(mockMemoryManager); context->setMemoryManager(mockMemoryManager); auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager, 1); @@ -590,7 +590,7 @@ HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingNonBlockedT } HWTEST_F(TimestampPacketTests, givenAlreadyAssignedNodeWhenEnqueueingBlockedThenMakeItResident) { - auto mockMemoryManager = new MockMemoryManager(); + auto mockMemoryManager = new MockMemoryManager(*device->getExecutionEnvironment()); device->injectMemoryManager(mockMemoryManager); context->setMemoryManager(mockMemoryManager); auto mockTagAllocator = new MockTagAllocator<>(mockMemoryManager, 1); diff --git a/unit_tests/kernel/kernel_image_arg_tests.cpp b/unit_tests/kernel/kernel_image_arg_tests.cpp index f21e987c34..82480b7438 100644 --- a/unit_tests/kernel/kernel_image_arg_tests.cpp +++ b/unit_tests/kernel/kernel_image_arg_tests.cpp @@ -190,7 +190,7 @@ HWTEST_F(KernelImageArgTest, givenImgWithMcsAllocWhenMakeResidentThenMakeMcsAllo cl_mem memObj = img; pKernel->setArg(0, sizeof(memObj), &memObj); - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); std::unique_ptr> csr(new MockCsr(execStamp, *pDevice->executionEnvironment)); csr->setMemoryManager(memoryManager.get()); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index f0b1441b50..220ec3d3e5 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -485,7 +485,7 @@ TEST_F(KernelPrivateSurfaceTest, testPrivateSurface) { ASSERT_EQ(CL_SUCCESS, pKernel->initialize()); // Test it - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false)); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *context.getDevice(0)->getExecutionEnvironment())); std::unique_ptr csr(new CommandStreamReceiverMock()); csr->setMemoryManager(memoryManager.get()); csr->residency.clear(); diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index 87a89c0eb2..0c7457ac62 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -68,7 +68,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { } virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override { - memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory); + memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment); return memoryManager; } diff --git a/unit_tests/mem_obj/buffer_pin_tests.cpp b/unit_tests/mem_obj/buffer_pin_tests.cpp index da9d713a26..5c9fb9da1c 100644 --- a/unit_tests/mem_obj/buffer_pin_tests.cpp +++ b/unit_tests/mem_obj/buffer_pin_tests.cpp @@ -20,6 +20,7 @@ using namespace OCLRT; class TestedMemoryManager : public OsAgnosticMemoryManager { public: + using OsAgnosticMemoryManager::OsAgnosticMemoryManager; GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { EXPECT_NE(0u, expectedSize); if (expectedSize == size) { @@ -47,7 +48,8 @@ class TestedMemoryManager : public OsAgnosticMemoryManager { }; TEST(BufferTests, doPinIsSet) { - std::unique_ptr mm(new TestedMemoryManager()); + ExecutionEnvironment executionEnvironment; + std::unique_ptr mm(new TestedMemoryManager(false, false, executionEnvironment)); { MockContext context; auto size = MemoryConstants::pageSize * 32; @@ -69,7 +71,8 @@ TEST(BufferTests, doPinIsSet) { } } TEST(BufferTests, doPinIsSetForHostPtr) { - std::unique_ptr mm(new TestedMemoryManager()); + ExecutionEnvironment executionEnvironment; + std::unique_ptr mm(new TestedMemoryManager(false, false, executionEnvironment)); { MockContext context; auto retVal = CL_INVALID_OPERATION; diff --git a/unit_tests/mem_obj/buffer_tests.cpp b/unit_tests/mem_obj/buffer_tests.cpp index fdbf2d688d..fbbf3446f0 100644 --- a/unit_tests/mem_obj/buffer_tests.cpp +++ b/unit_tests/mem_obj/buffer_tests.cpp @@ -94,6 +94,7 @@ INSTANTIATE_TEST_CASE_P( class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager { public: + GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast(executionEnvironment)){}; MOCK_METHOD5(allocateGraphicsMemoryInPreferredPool, GraphicsAllocation *(AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type)); GraphicsAllocation *baseallocateGraphicsMemoryInPreferredPool(AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) { return MockMemoryManager::allocateGraphicsMemoryInPreferredPool(flags, devicesBitfield, hostPtr, size, type); @@ -107,7 +108,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsThenB memset(memory, 0xAA, MemoryConstants::pageSize); std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -137,7 +138,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsAndSe memset(memory, 0xAA, MemoryConstants::pageSize); std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -163,7 +164,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithKernelWriteFlagThe memset(memory, 0xAA, MemoryConstants::pageSize); std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -183,7 +184,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithKernelWriteFlagThe TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAllocationFailsAndReturnsNullptr) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -202,7 +203,7 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPoolThenBufferIsNotZeroCopy) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -227,7 +228,7 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPoolThenAllocationIsNotAddedToHostPtrManager) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); @@ -350,7 +351,7 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhen TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteBuffer) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - ::testing::NiceMock *memoryManager = new ::testing::NiceMock; + ::testing::NiceMock *memoryManager = new ::testing::NiceMock(*device->getExecutionEnvironment()); device->injectMemoryManager(memoryManager); MockContext ctx(device.get()); diff --git a/unit_tests/mem_obj/image_tests.cpp b/unit_tests/mem_obj/image_tests.cpp index 41d6e20e0d..be10d04f7f 100644 --- a/unit_tests/mem_obj/image_tests.cpp +++ b/unit_tests/mem_obj/image_tests.cpp @@ -45,7 +45,7 @@ class CreateImageTest : public DeviceFixture, protected: void SetUp() override { DeviceFixture::SetUp(); - memoryManager = new MockMemoryManager(); + memoryManager = new MockMemoryManager(*pDevice->getExecutionEnvironment()); pDevice->injectMemoryManager(memoryManager); @@ -892,6 +892,7 @@ class ImageCompressionTests : public ::testing::Test { public: class MyMemoryManager : public MockMemoryManager { public: + using MockMemoryManager::MockMemoryManager; GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override { mockMethodCalled = true; capturedImgInfo = imgInfo; @@ -902,8 +903,8 @@ class ImageCompressionTests : public ::testing::Test { }; void SetUp() override { - myMemoryManager = new MyMemoryManager(); mockDevice.reset(MockDevice::createWithNewExecutionEnvironment(*platformDevices)); + myMemoryManager = new MyMemoryManager(*mockDevice->getExecutionEnvironment()); mockDevice->injectMemoryManager(myMemoryManager); mockContext.reset(new MockContext(mockDevice.get())); } @@ -1195,8 +1196,8 @@ void MockImageHw::setClearColorParams(typename FamilyName::RENDER_SU using HwImageTest = ::testing::Test; HWTEST_F(HwImageTest, givenImageHwWhenSettingCCSParamsThenSetClearColorParamsIsCalled) { - OsAgnosticMemoryManager memoryManager; MockContext context; + OsAgnosticMemoryManager memoryManager(false, false, *context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); cl_image_desc imgDesc = {}; diff --git a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp index bbb7cc1057..0ce5b2df4f 100644 --- a/unit_tests/mem_obj/mem_obj_destruction_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_destruction_tests.cpp @@ -28,7 +28,7 @@ class MemObjDestructionTest : public ::testing::TestWithParam { public: void SetUp() override { context.reset(new MockContext()); - memoryManager = new MockMemoryManager; + memoryManager = new MockMemoryManager(*context->getDevice(0)->getExecutionEnvironment()); device = static_cast(context->getDevice(0)); device->injectMemoryManager(memoryManager); context->setMemoryManager(memoryManager); diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index aebf74f499..1435a5ef0f 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -155,15 +155,14 @@ TEST(MemObj, givenMemObjWhenReleaseAllocatedPtrIsCalledTwiceThenItDoesntCrash) { } TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsAddedToMemoryManagerAllocationList) { - MockMemoryManager memoryManager; MockContext context; + MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = 2; - memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver(); - *(memoryManager.csr->getTagAddress()) = 1; + *(memoryManager.getCommandStreamReceiver(0)->getTagAddress()) = 1; MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); @@ -174,11 +173,10 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe } TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) { - MockMemoryManager memoryManager; MockContext context; + MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); - memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver(); auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = 1; @@ -193,8 +191,8 @@ TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAl } TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) { - MockMemoryManager memoryManager; MockContext context; + MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); @@ -210,8 +208,8 @@ TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThen } TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThenAllocationIsNotAddedToMemoryManagerAllocationList) { - MockMemoryManager memoryManager; MockContext context; + MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); @@ -227,11 +225,10 @@ TEST(MemObj, givenMemoryManagerWithoutDeviceWhenMemObjDestroysAllocationAsyncThe } TEST(MemObj, givenMemObjWhenItDoesntHaveGraphicsAllocationThenWaitForCsrCompletionDoesntCrash) { - MockMemoryManager memoryManager; MockContext context; + MockMemoryManager memoryManager(*context.getDevice(0)->getExecutionEnvironment()); context.setMemoryManager(&memoryManager); - memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver(); MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index fca0f18d3a..456d48f399 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -8,7 +8,8 @@ #include "unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl" TEST(MemoryManagerTest, givenNotSetUseSystemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Error; AllocationData allocData; diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl index 6498c899c3..689719157a 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.inl @@ -6,6 +6,7 @@ */ #include "runtime/memory_manager/os_agnostic_memory_manager.h" +#include "runtime/execution_environment/execution_environment.h" #include "gtest/gtest.h" #include "test.h" @@ -13,7 +14,8 @@ using namespace OCLRT; TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; allocData.allFlags = 0; @@ -27,7 +29,8 @@ TEST(MemoryManagerTest, givenSetUseSytemMemoryWhenGraphicsAllocationInDevicePool } TEST(MemoryManagerTest, givenAllowed32BitAndFroce32BitWhenGraphicsAllocationInDevicePoolIsAllocatedThenNullptrIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl index f188cd6c6a..aad917a491 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl +++ b/unit_tests/memory_manager/memory_manager_allocate_in_preferred_pool_tests.inl @@ -5,6 +5,7 @@ * */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "unit_tests/mocks/mock_memory_manager.h" @@ -118,7 +119,6 @@ TEST_P(MemoryManagerGetAlloctionData32BitAnd64kbPagesAllowedTest, given64kbAllow MockMemoryManager::getAllocationData(allocData, flags, 0, nullptr, 10, allocType); bool bufferCompressedType = (allocType == GraphicsAllocation::AllocationType::BUFFER_COMPRESSED); EXPECT_TRUE(allocData.flags.allow64kbPages); - MockMemoryManager mockMemoryManager(true); auto allocation = mockMemoryManager.allocateGraphicsMemory(allocData); @@ -168,7 +168,8 @@ INSTANTIATE_TEST_CASE_P(Disallow32BitAnd64kbPagesTypes, ::testing::ValuesIn(allocationTypesWith32BitAnd64KbPagesNotAllowed)); TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedTypeIsAllocatedThen32BitAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; @@ -190,7 +191,8 @@ TEST(MemoryManagerTest, givenForced32BitSetWhenGraphicsMemoryFor32BitAllowedType } TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32BitFlagIsAllocatedThenNon32BitAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; @@ -207,7 +209,8 @@ TEST(MemoryManagerTest, givenForced32BitEnabledWhenGraphicsMemoryWihtoutAllow32B } TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagFor32BitAllowedTypeIsAllocatedThenNon32BitAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(false); AllocationData allocData; @@ -223,7 +226,8 @@ TEST(MemoryManagerTest, givenForced32BitDisabledWhenGraphicsMemoryWith32BitFlagF } TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen64kbAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); AllocationData allocData; AllocationFlags flags(true); @@ -272,7 +276,8 @@ TEST(MemoryManagerTest, givenDisabled64kbPagesWhenGraphicsMemoryMustBeHostMemory } TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMustBeHostMemoryAndIsAllocatedWithNullptrForBufferThen32BitAllocationOver64kbIsChosen) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); AllocationData allocData; @@ -292,7 +297,8 @@ TEST(MemoryManagerTest, givenForced32BitAndEnabled64kbPagesWhenGraphicsMemoryMus } TEST(MemoryManagerTest, givenEnabled64kbPagesWhenGraphicsMemoryIsAllocatedWithHostPtrForBufferThenExistingMemoryIsUsedForAllocation) { - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); AllocationData allocData; AllocationFlags flags(false); diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index ef7b272063..99d7c1a0fa 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -581,11 +581,12 @@ TEST_F(MemoryAllocatorTest, getEventPerfCountAllocator) { } TEST_F(MemoryAllocatorTest, givenTimestampPacketAllocatorWhenAskingForTagThenReturnValidObject) { + ExecutionEnvironment executionEnvironment; class MyMockMemoryManager : public OsAgnosticMemoryManager { public: using OsAgnosticMemoryManager::timestampPacketAllocator; - MyMockMemoryManager() : OsAgnosticMemoryManager(false, false){}; - } myMockMemoryManager; + MyMockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){}; + } myMockMemoryManager(executionEnvironment); EXPECT_EQ(nullptr, myMockMemoryManager.timestampPacketAllocator.get()); @@ -790,25 +791,27 @@ TEST_F(MemoryAllocatorTest, given32BitDeviceWhenPrintfSurfaceIsCreatedThen32BitA } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenForce32BitAllocationsIsFalse) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_FALSE(memoryManager.peekForce32BitAllocations()); } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenForce32bitallocationIsCalledWithTrueThenMemoryManagerForces32BitAlloactions) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.setForce32BitAllocations(true); EXPECT_TRUE(memoryManager.peekForce32BitAllocations()); } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemoryForImageIsCalledThenGraphicsAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); cl_image_desc imgDesc = {}; imgDesc.image_width = 512; imgDesc.image_height = 1; imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D; auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr); - ExecutionEnvironment executionEnvironment; executionEnvironment.initGmm(*platformDevices); auto queryGmm = MockGmm::queryImgParams(imgInfo); @@ -821,7 +824,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenAllocateGraphicsMemor } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAllocationWhenMappingThenReturnFalse) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto gmm = new Gmm(nullptr, 123, false); auto allocation = memoryManager.allocateGraphicsMemory(123); @@ -836,7 +840,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerAndUnifiedAuxCapableAlloc } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { - OsAgnosticMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto size = 4096u; auto allocation = memoryManager.allocateGraphicsMemory(size); @@ -851,7 +856,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCall } TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); auto size = 4096u; auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false); @@ -863,13 +869,14 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryFailsThenNullptrIsReturned) { class MockOsAgnosticManagerWithFailingAllocate : public OsAgnosticMemoryManager { public: - MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages) : OsAgnosticMemoryManager(enable64kbPages, false) {} + MockOsAgnosticManagerWithFailingAllocate(bool enable64kbPages, ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(enable64kbPages, false, executionEnvironment) {} GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { return nullptr; } }; - MockOsAgnosticManagerWithFailingAllocate memoryManager(true); + ExecutionEnvironment executionEnvironment; + MockOsAgnosticManagerWithFailingAllocate memoryManager(true, executionEnvironment); auto size = 4096u; auto allocation = memoryManager.allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false); @@ -878,7 +885,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - OsAgnosticMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -891,7 +899,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPt } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - OsAgnosticMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -904,7 +913,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithoutPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - OsAgnosticMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); void *ptr = nullptr; auto size = MemoryConstants::pageSize; @@ -916,7 +926,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryW } TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); auto size = 4096u; auto svmAllocation = memoryManager.allocateGraphicsMemoryForSVM(size, false); @@ -926,7 +937,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate } TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager(false, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto size = 4096u; auto isCoherent = true; @@ -963,7 +975,8 @@ TEST(OsAgnosticMemoryManager, givenDeviceWith64kbPagesDisbledWhenCreatingMemoryM } TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThen64KBGraphicsAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); auto size = 4096u; auto isCoherent = true; @@ -980,7 +993,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWith64KBPagesEnabledWhenAllocate } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledThenGraphicsAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); osHandle handle = 1; auto size = 4096u; auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, false); @@ -994,13 +1008,15 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenCreateAllocationFromNtHandleIsCalledThenReturnNullptr) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto graphicsAllocation = memoryManager.createGraphicsAllocationFromNTHandle((void *)1); EXPECT_EQ(nullptr, graphicsAllocation); } TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenDoNothing) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto allocation = memoryManager.allocateGraphicsMemory(1); ASSERT_NE(nullptr, allocation); @@ -1012,7 +1028,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenLockUnlockCalledThenDoNothin } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationContainsOffsetWhenAddressIsObtainedThenOffsetIsAdded) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); @@ -1031,7 +1048,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationCon } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsPaddedThenNewGraphicsAllocationIsCreated) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); auto sizeWithPadding = 8192; @@ -1049,7 +1067,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenGraphicsAllocationIsP } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenTwoGraphicsAllocationArePaddedThenOnlyOnePaddingBufferIsUsed) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto graphicsAllocation = memoryManager.allocateGraphicsMemory(4096u); auto sizeWithPadding = 8192; @@ -1072,7 +1091,8 @@ TEST(OsAgnosticMemoryManager, pleaseDetectLeak) { } TEST(OsAgnosticMemoryManager, alignmentIsCorrect) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); const size_t alignment = 0; auto ga = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize >> 1, alignment, false, false); uintptr_t ptr = reinterpret_cast(ga->getUnderlyingBuffer()); @@ -1083,7 +1103,8 @@ TEST(OsAgnosticMemoryManager, alignmentIsCorrect) { } TEST(OsAgnosticMemoryManager, givenCommonMemoryManagerWhenIsAskedIfApplicationMemoryBudgetIsExhaustedThenFalseIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted()); } @@ -1092,7 +1113,6 @@ class MemoryManagerWithAsyncDeleterTest : public ::testing::Test { void SetUp() override { memoryManager.overrideAsyncDeleterFlag(true); } - MockMemoryManager memoryManager; }; @@ -1147,7 +1167,8 @@ TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenIsAsyncDeleterEnabledCalledT } TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsFalse) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); } @@ -1155,7 +1176,8 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncD TEST(OsAgnosticMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) { bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -1164,7 +1186,8 @@ TEST(OsAgnosticMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCre TEST(OsAgnosticMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) { bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(false); - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -1173,7 +1196,8 @@ TEST(OsAgnosticMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCr TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCreatedThenAlignedto64KbAllocationIsReturned) { DebugManagerStateRestore dbgRestore; DebugManager.flags.Enable64kbpages.set(true); - OsAgnosticMemoryManager memoryManager(true, false); + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(true, false, executionEnvironment); GraphicsAllocation *galloc = memoryManager.allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, 64 * 1024, GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); EXPECT_NE(nullptr, galloc); @@ -1190,7 +1214,8 @@ TEST(OsAgnosticMemoryManager, GivenEnabled64kbPagesWhenHostMemoryAllocationIsCre } TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryManager) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); AllocationRequirements requirements; CheckedFragments checkedFragments; @@ -1205,7 +1230,8 @@ TEST(OsAgnosticMemoryManager, checkAllocationsForOverlappingWithNullCsrInMemoryM } TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsCalledThenGraphicsAllocationIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto ptr = (void *)0x100000; size_t allocationSize = 4096; auto graphicsAllocation = memoryManager.allocate32BitGraphicsMemory(allocationSize, ptr, AllocationOrigin::INTERNAL_ALLOCATION); @@ -1214,13 +1240,15 @@ TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsC memoryManager.freeGraphicsMemory(graphicsAllocation); } TEST(OsAgnosticMemoryManager, givenDefaultOsAgnosticMemoryManagerWhenItIsQueriedForInternalHeapBaseThen32BitAllocatorBaseIsReturned) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto heapBase = memoryManager.allocator32Bit->getBase(); EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress()); } TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledThenAllocationIsCreated) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto hostPtr = reinterpret_cast(0x5001); auto allocation = memoryManager.allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr); EXPECT_NE(nullptr, allocation); @@ -1231,7 +1259,8 @@ TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMe } TEST(OsAgnosticMemoryManager, givenReducedGpuAddressSpaceWhenAllocateGraphicsMemoryForHostPtrIsCalledThenAllocationWithoutFragmentsIsCreated) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto hostPtr = reinterpret_cast(0x5001); auto allocation = memoryManager.allocateGraphicsMemoryForHostPtr(13, hostPtr, false); @@ -1242,7 +1271,8 @@ TEST(OsAgnosticMemoryManager, givenReducedGpuAddressSpaceWhenAllocateGraphicsMem } TEST(OsAgnosticMemoryManager, givenFullGpuAddressSpaceWhenAllocateGraphicsMemoryForHostPtrIsCalledThenAllocationWithFragmentsIsCreated) { - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); auto hostPtr = reinterpret_cast(0x5001); auto allocation = memoryManager.allocateGraphicsMemoryForHostPtr(13, hostPtr, true); @@ -1253,7 +1283,8 @@ TEST(OsAgnosticMemoryManager, givenFullGpuAddressSpaceWhenAllocateGraphicsMemory } TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockMemoryManager memoryManager(false, false, false); + ExecutionEnvironment executionEnvironment; + MockMemoryManager memoryManager(false, false, false, executionEnvironment); uint64_t heap32Base = 0x80000000000ul; if (is32bit) { @@ -1263,7 +1294,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCre } TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockMemoryManager memoryManager(false, true, false); + ExecutionEnvironment executionEnvironment; + MockMemoryManager memoryManager(false, true, false, executionEnvironment); uint64_t heap32Base = 0x80000000000ul; if (is32bit) { @@ -1273,7 +1305,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryM } TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockMemoryManager memoryManager(false, false, true); + ExecutionEnvironment executionEnvironment; + MockMemoryManager memoryManager(false, false, true, executionEnvironment); uint64_t heap32Base = 0x80000000000ul; if (is32bit) { @@ -1283,7 +1316,8 @@ TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryM } TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockMemoryManager memoryManager(false, true, true); + ExecutionEnvironment executionEnvironment; + MockMemoryManager memoryManager(false, true, true, executionEnvironment); uint64_t heap32Base = 0x80000000000ul; if (is32bit) { @@ -1599,7 +1633,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasNotUsedWhencheckGpuUsageA TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsDestroyedInPlace) { auto usedAllocationButGpuCompleted = memoryManager->allocateGraphicsMemory(4096); - auto tagAddress = memoryManager->csr->getTagAddress(); + auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress(); ASSERT_NE(0u, *tagAddress); usedAllocationButGpuCompleted->taskCount = *tagAddress - 1; @@ -1611,7 +1645,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsCompletedWhenche TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhencheckGpuUsageAndDestroyGraphicsAllocationsIsCalledThenItIsAddedToTemporaryAllocationList) { auto usedAllocationAndNotGpuCompleted = memoryManager->allocateGraphicsMemory(4096); - auto tagAddress = memoryManager->csr->getTagAddress(); + auto tagAddress = memoryManager->getCommandStreamReceiver(0)->getTagAddress(); usedAllocationAndNotGpuCompleted->taskCount = *tagAddress + 1; @@ -1625,7 +1659,7 @@ TEST_F(MemoryManagerWithCsrTest, givenAllocationThatWasUsedAndIsNotCompletedWhen class MockAlignMallocMemoryManager : public MockMemoryManager { public: - MockAlignMallocMemoryManager() : MockMemoryManager() { + MockAlignMallocMemoryManager() { testMallocRestrictions.minAddress = 0; alignMallocRestrictions = nullptr; alignMallocCount = 0; @@ -1677,7 +1711,7 @@ class MockAlignMallocMemoryManagerTest : public MemoryAllocatorTest { void SetUp() override { MemoryAllocatorTest::SetUp(); - alignedMemoryManager = new (std::nothrow) MockAlignMallocMemoryManager(); + alignedMemoryManager = new (std::nothrow) MockAlignMallocMemoryManager; //assert we have memory manager ASSERT_NE(nullptr, memoryManager); } @@ -1786,7 +1820,8 @@ TEST(GraphicsAllocation, givenGraphicsAllocationCreatedWithDefaultConstructorThe TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) { auto osContext = new OsContext(nullptr, 0u); - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.registerOsContext(osContext); EXPECT_EQ(1u, memoryManager.getOsContextCount()); EXPECT_EQ(1, osContext->getRefInternalCount()); @@ -1795,7 +1830,8 @@ TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCo TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerThenProperSizeIsReturned) { auto osContext2 = new OsContext(nullptr, 1u); auto osContext = new OsContext(nullptr, 0u); - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); memoryManager.registerOsContext(osContext2); memoryManager.registerOsContext(osContext); EXPECT_EQ(2u, memoryManager.getOsContextCount()); diff --git a/unit_tests/memory_manager/svm_memory_manager.cpp b/unit_tests/memory_manager/svm_memory_manager.cpp index 9388c8ed2e..fd18fa1b89 100644 --- a/unit_tests/memory_manager/svm_memory_manager.cpp +++ b/unit_tests/memory_manager/svm_memory_manager.cpp @@ -28,9 +28,10 @@ TEST_F(SVMMemoryAllocatorTest, allocateSystem) { } TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateNullFreeNull) { - OsAgnosticMemoryManager umm; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); { - SVMAllocsManager svmM(&umm); + SVMAllocsManager svmM(&memoryManager); char *Ptr1 = (char *)svmM.createSVMAlloc(0); EXPECT_EQ(Ptr1, nullptr); svmM.freeSVMAlloc(nullptr); @@ -38,9 +39,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateNullFreeNull) { } TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateFree) { - OsAgnosticMemoryManager umm; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); { - SVMAllocsManager svmM(&umm); + SVMAllocsManager svmM(&memoryManager); char *Ptr1 = (char *)svmM.createSVMAlloc(4096); EXPECT_NE(Ptr1, nullptr); @@ -52,9 +54,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocCreateFree) { TEST_F(SVMMemoryAllocatorTest, SVMAllocGetNoSVMAdrees) { char array[100]; - OsAgnosticMemoryManager umm; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); { - SVMAllocsManager svmM(&umm); + SVMAllocsManager svmM(&memoryManager); char *Ptr1 = (char *)100; GraphicsAllocation *GA1 = svmM.getSVMAlloc(Ptr1); @@ -66,9 +69,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocGetNoSVMAdrees) { } TEST_F(SVMMemoryAllocatorTest, SVMAllocGetBeforeAndInside) { - OsAgnosticMemoryManager umm; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); { - SVMAllocsManager svmM(&umm); + SVMAllocsManager svmM(&memoryManager); char *Ptr1 = (char *)svmM.createSVMAlloc(4096); EXPECT_NE(Ptr1, nullptr); @@ -86,9 +90,10 @@ TEST_F(SVMMemoryAllocatorTest, SVMAllocGetBeforeAndInside) { } TEST_F(SVMMemoryAllocatorTest, SVMAllocgetAfterSVM) { - OsAgnosticMemoryManager umm; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); { - SVMAllocsManager svmM(&umm); + SVMAllocsManager svmM(&memoryManager); char *Ptr1 = (char *)svmM.createSVMAlloc(4096); EXPECT_NE(Ptr1, nullptr); @@ -105,6 +110,7 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul using OsAgnosticMemoryManager::allocateGraphicsMemory; public: + MockMemManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){}; GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override { return nullptr; } @@ -120,10 +126,10 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul return SVMAllocs; } }; - - MockMemManager mm; + ExecutionEnvironment executionEnvironment; + MockMemManager memoryManager(executionEnvironment); { - MockSVMAllocsManager svmM{&mm}; + MockSVMAllocsManager svmM{&memoryManager}; void *svmPtr = svmM.createSVMAlloc(512); EXPECT_EQ(nullptr, svmPtr); @@ -134,15 +140,15 @@ TEST_F(SVMMemoryAllocatorTest, WhenCouldNotAllocateInMemoryManagerThenReturnsNul TEST_F(SVMMemoryAllocatorTest, given64kbAllowedwhenAllocatingSvmMemoryThenDontPreferRenderCompression) { class MyMemoryManager : public OsAgnosticMemoryManager { public: - MyMemoryManager() { enable64kbpages = true; } + MyMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) { enable64kbpages = true; } GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override { preferRenderCompressedFlag = preferRenderCompressed; return nullptr; } bool preferRenderCompressedFlag = true; }; - - MyMemoryManager myMemoryManager; + ExecutionEnvironment executionEnvironment; + MyMemoryManager myMemoryManager(executionEnvironment); myMemoryManager.allocateGraphicsMemoryForSVM(1, false); EXPECT_FALSE(myMemoryManager.preferRenderCompressedFlag); } diff --git a/unit_tests/mocks/linux/mock_drm_memory_manager.h b/unit_tests/mocks/linux/mock_drm_memory_manager.h index 9beb8b16ae..1ec231d020 100644 --- a/unit_tests/mocks/linux/mock_drm_memory_manager.h +++ b/unit_tests/mocks/linux/mock_drm_memory_manager.h @@ -38,7 +38,7 @@ class TestedDrmMemoryManager : public DrmMemoryManager { using DrmMemoryManager::setDomainCpu; using DrmMemoryManager::sharingBufferObjects; - TestedDrmMemoryManager(Drm *drm) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, false, false) { + TestedDrmMemoryManager(Drm *drm, ExecutionEnvironment &executionEnvironment) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment) { this->lseekFunction = &lseekMock; this->mmapFunction = &mmapMock; this->munmapFunction = &munmapMock; @@ -48,7 +48,7 @@ class TestedDrmMemoryManager : public DrmMemoryManager { mmapMockCallCount = 0; munmapMockCallCount = 0; }; - TestedDrmMemoryManager(Drm *drm, bool allowForcePin, bool validateHostPtrMemory) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, allowForcePin, validateHostPtrMemory) { + TestedDrmMemoryManager(Drm *drm, bool allowForcePin, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment) : DrmMemoryManager(drm, gemCloseWorkerMode::gemCloseWorkerInactive, allowForcePin, validateHostPtrMemory, executionEnvironment) { this->lseekFunction = &lseekMock; this->mmapFunction = &mmapMock; this->munmapFunction = &munmapMock; diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 82b0fff18a..27510e2c34 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -28,7 +28,7 @@ MockDevice::MockDevice(const HardwareInfo &hwInfo) OCLRT::MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : Device(hwInfo, executionEnvironment, deviceIndex) { bool aubUsage = (testMode == TestMode::AubTests) || (testMode == TestMode::AubTestsWithTbx); - this->mockMemoryManager.reset(new OsAgnosticMemoryManager(false, this->getHardwareCapabilities().localMemorySupported, aubUsage)); + this->mockMemoryManager.reset(new OsAgnosticMemoryManager(false, this->getHardwareCapabilities().localMemorySupported, aubUsage, *executionEnvironment)); this->osTime = MockOSTime::create(); mockWaTable = *hwInfo.pWaTable; } @@ -55,7 +55,6 @@ bool MockDevice::hasDriverInfo() { }; void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { - memoryManager->setCommandStreamReceiver(executionEnvironment->commandStreamReceivers[getDeviceIndex()].get()); executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(memoryManager); setMemoryManager(memoryManager); } @@ -65,22 +64,22 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(executionEnvironment->memoryManager.get()); executionEnvironment->commandStreamReceivers[getDeviceIndex()]->initializeTagAllocation(); executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setPreemptionCsrAllocation(preemptionAllocation); - executionEnvironment->memoryManager->csr = executionEnvironment->commandStreamReceivers[getDeviceIndex()].get(); this->commandStreamReceiver = newCsr; + UNRECOVERABLE_IF(getDeviceIndex() != 0u); this->tagAddress = executionEnvironment->commandStreamReceivers[getDeviceIndex()]->getTagAddress(); } -OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() { +OCLRT::FailMemoryManager::FailMemoryManager() { agnostic = nullptr; fail = 0; } -OCLRT::FailMemoryManager::FailMemoryManager(int32_t fail) : MockMemoryManager() { +OCLRT::FailMemoryManager::FailMemoryManager(int32_t fail) { allocations.reserve(fail); - agnostic = new OsAgnosticMemoryManager(false, false); + agnostic = new OsAgnosticMemoryManager(false, false, executionEnvironment); this->fail = fail; } MockAlignedMallocManagerDevice::MockAlignedMallocManagerDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) { - this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager()); + this->mockMemoryManager.reset(new MockAllocSysMemAgnosticMemoryManager(*executionEnvironment)); } diff --git a/unit_tests/mocks/mock_memory_manager.cpp b/unit_tests/mocks/mock_memory_manager.cpp index 4fb491c170..b26e4ba908 100644 --- a/unit_tests/mocks/mock_memory_manager.cpp +++ b/unit_tests/mocks/mock_memory_manager.cpp @@ -33,10 +33,6 @@ GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForImage(ImageInfo return allocation; } -void MockMemoryManager::setCommandStreamReceiver(CommandStreamReceiver *csr) { - this->csr = csr; -} - bool MockMemoryManager::isAllocationListEmpty() { return graphicsAllocations.peekIsEmpty(); } diff --git a/unit_tests/mocks/mock_memory_manager.h b/unit_tests/mocks/mock_memory_manager.h index 6d3f36be7d..22641fad86 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -6,6 +6,7 @@ */ #pragma once +#include "runtime/execution_environment/execution_environment.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "gmock/gmock.h" @@ -18,17 +19,19 @@ class MockMemoryManager : public OsAgnosticMemoryManager { using MemoryManager::allocateGraphicsMemoryInPreferredPool; using MemoryManager::getAllocationData; using MemoryManager::timestampPacketAllocator; - - MockMemoryManager() : OsAgnosticMemoryManager(false, false){}; - MockMemoryManager(bool enable64pages) : OsAgnosticMemoryManager(enable64pages, false) {} - MockMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, aubUsage) {} - + using OsAgnosticMemoryManager::OsAgnosticMemoryManager; + MockMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment){}; + MockMemoryManager() : MockMemoryManager(*(new ExecutionEnvironment)) { + mockExecutionEnvironment.reset(&executionEnvironment); + }; + MockMemoryManager(bool enable64pages) : OsAgnosticMemoryManager(enable64pages, false, *(new ExecutionEnvironment)) { + mockExecutionEnvironment.reset(&executionEnvironment); + } GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override; void setDeferredDeleter(DeferredDeleter *deleter); void overrideAsyncDeleterFlag(bool newValue); GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; int redundancyRatio = 1; - void setCommandStreamReceiver(CommandStreamReceiver *csr); bool isAllocationListEmpty(); GraphicsAllocation *peekAllocationListHead(); @@ -42,10 +45,12 @@ class MockMemoryManager : public OsAgnosticMemoryManager { bool failInDevicePoolWithError = false; bool failInAllocateWithSizeAndAlignment = false; bool preferRenderCompressedFlagPassed = false; + std::unique_ptr mockExecutionEnvironment; }; class GMockMemoryManager : public MockMemoryManager { public: + GMockMemoryManager(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast(executionEnvironment)){}; MOCK_METHOD2(cleanAllocationList, bool(uint32_t waitTaskCount, uint32_t allocationUsage)); // cleanAllocationList call defined in MemoryManager. @@ -58,7 +63,7 @@ class GMockMemoryManager : public MockMemoryManager { class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager { public: - MockAllocSysMemAgnosticMemoryManager() : OsAgnosticMemoryManager(false, false) { + MockAllocSysMemAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, false, executionEnvironment) { ptrRestrictions = nullptr; testRestrictions.minAddress = 0; } @@ -76,5 +81,4 @@ class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager { AlignedMallocRestrictions testRestrictions; AlignedMallocRestrictions *ptrRestrictions; }; - } // namespace OCLRT diff --git a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp index 429ddb5842..ed101042e2 100644 --- a/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp +++ b/unit_tests/mt_tests/os_interface/linux/drm_memory_manager_mt_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/os_interface/linux/drm_memory_manager.h" #include "unit_tests/mocks/linux/mock_drm_memory_manager.h" #include "unit_tests/os_interface/linux/device_command_stream_fixture.h" @@ -30,9 +31,9 @@ TEST(DrmMemoryManagerTest, givenDrmMemoryManagerWhenSharedAllocationIsCreatedFro return 0; } }; - + ExecutionEnvironment executionEnvironment; auto mock = make_unique(0); - auto memoryManager = make_unique(mock.get()); + auto memoryManager = make_unique(mock.get(), executionEnvironment); osHandle handle = 3; constexpr size_t maxThreads = 10; @@ -92,8 +93,9 @@ TEST(DrmMemoryManagerTest, givenMultipleThreadsWhenSharedAllocationIsCreatedThen } }; + ExecutionEnvironment executionEnvironment; auto mock = make_unique(0); - auto memoryManager = make_unique(mock.get()); + auto memoryManager = make_unique(mock.get(), executionEnvironment); osHandle handle = 3; constexpr size_t maxThreads = 10; 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 289dbfc795..641e932a6b 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -55,12 +55,13 @@ class DrmCommandStreamFixture { csr = new DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, gemCloseWorkerMode::gemCloseWorkerActive); ASSERT_NE(nullptr, csr); + executionEnvironment.commandStreamReceivers.resize(1); + executionEnvironment.commandStreamReceivers[0].reset(csr); // Memory manager creates pinBB with ioctl, expect one call EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)) .Times(1); mm = static_cast(csr->createMemoryManager(false, false)); - mm->csr = csr; ::testing::Mock::VerifyAndClearExpectations(mock); //assert we have memory manager @@ -70,7 +71,7 @@ class DrmCommandStreamFixture { void TearDown() { mm->waitForDeletions(); mm->peekGemCloseWorker()->close(true); - delete csr; + executionEnvironment.commandStreamReceivers.clear(); ::testing::Mock::VerifyAndClearExpectations(mock); // Memory manager closes pinBB with ioctl, expect one call EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)) 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 2c4504e6ea..72eede18bc 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 @@ -13,6 +13,7 @@ #include #include "runtime/command_stream/device_command_stream.h" +#include "runtime/execution_environment/execution_environment.h" #include "hw_cmds.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/mem_obj/buffer.h" @@ -64,7 +65,7 @@ class DrmGemCloseWorkerFixture { this->drmMock->gem_close_cnt = 0; this->drmMock->gem_close_expected = 0; - this->mm = new DrmMemoryManager(this->drmMock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false); + this->mm = new DrmMemoryManager(this->drmMock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment); } void TearDown() { @@ -88,6 +89,7 @@ class DrmGemCloseWorkerFixture { DrmAllocationWrapper(BufferObject *bo) : DrmAllocation(bo, nullptr, 0, MemoryPool::MemoryNull) { } }; + ExecutionEnvironment executionEnvironment; }; typedef Test DrmGemCloseWorkerTests; 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 727ea53ef8..1f99467477 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -49,8 +49,9 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { void SetUp() override { MemoryManagementFixture::SetUp(); this->mock = new DrmMockCustom; - - memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock); + executionEnvironment = new ExecutionEnvironment; + executionEnvironment->incRefInternal(); + memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, *executionEnvironment); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); if (memoryManager->getgemCloseWorker()) { @@ -60,6 +61,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { void TearDown() override { delete memoryManager; + executionEnvironment->decRefInternal(); this->mock->testIoctls(); @@ -69,6 +71,7 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture { } protected: + ExecutionEnvironment *executionEnvironment; DrmMockCustom::IoctlResExt ioctlResExt = {0, 0}; }; @@ -80,7 +83,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagem void SetUp() override { MemoryManagementFixture::SetUp(); this->mock = new DrmMockCustom; - memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock); + memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, executionEnvironment); ASSERT_NE(nullptr, memoryManager); if (memoryManager->getgemCloseWorker()) { memoryManager->getgemCloseWorker()->close(true); @@ -95,6 +98,7 @@ class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation : public MemoryManagem } protected: + ExecutionEnvironment executionEnvironment; DrmMockCustom::IoctlResExt ioctlResExt = {0, 0}; }; @@ -144,29 +148,27 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenforcePinAllowedWhenMemoryManagerIsCreatedThenPinBbIsCreated) { - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, executionEnvironment); EXPECT_NE(nullptr, memoryManager->getPinBB()); - delete memoryManager; } TEST_F(DrmMemoryManagerTest, pinBBisCreated) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemClose = 1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); EXPECT_NE(nullptr, memoryManager->getPinBB()); - delete memoryManager; } TEST_F(DrmMemoryManagerTest, givenNotAllowedForcePinWhenMemoryManagerIsCreatedThenPinBBIsNotCreated) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false)); + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false, *executionEnvironment)); EXPECT_EQ(nullptr, memoryManager->getPinBB()); } TEST_F(DrmMemoryManagerTest, pinBBnotCreatedWhenIoctlFailed) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_res = -1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false, *executionEnvironment); EXPECT_EQ(nullptr, memoryManager->getPinBB()); delete memoryManager; } @@ -177,7 +179,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 2; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); auto alloc = memoryManager->allocateGraphicsMemory(10 * 1014 * 1024, 1024, true, false); @@ -185,8 +187,6 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - - delete memoryManager; } TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAllocation) { @@ -194,7 +194,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAll mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 2; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning @@ -203,8 +203,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedAndAllowedButSmallAll EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - - delete memoryManager; } TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) { @@ -212,7 +210,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) { mock->ioctl_expected.gemClose = 2; mock->ioctl_expected.gemWait = 1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, false, false); @@ -220,8 +218,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowed) { EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - - delete memoryManager; } TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowed) { @@ -229,15 +225,13 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowed) { mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false); + auto memoryManager = std::make_unique(this->mock, false, false, *executionEnvironment); auto alloc = memoryManager->allocateGraphicsMemory(1024, 1024, true, false); ASSERT_NE(nullptr, alloc); EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - - delete memoryManager; } // ---- HostPtr @@ -247,7 +241,7 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation mock->ioctl_expected.execbuffer2 = 1; mock->ioctl_expected.gemWait = 1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); size_t size = 10 * 1024 * 1024; @@ -257,8 +251,6 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation EXPECT_NE(nullptr, alloc->getBO()); memoryManager->freeGraphicsMemory(alloc); - - delete memoryManager; ::alignedFree(ptr); } @@ -267,7 +259,7 @@ TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIs mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 2; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning @@ -279,7 +271,6 @@ TEST_F(DrmMemoryManagerTest, givenSmallAllocationHostPtrAllocationWhenForcePinIs memoryManager->freeGraphicsMemory(alloc); - delete memoryManager; ::alignedFree(ptr); } @@ -288,7 +279,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr) mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 2; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false); + auto memoryManager = std::make_unique(this->mock, true, false, *executionEnvironment); ASSERT_NE(nullptr, memoryManager->getPinBB()); size_t size = 4 * 1024; @@ -299,7 +290,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenNotAskedButAllowedHostPtr) memoryManager->freeGraphicsMemory(alloc); - delete memoryManager; ::alignedFree(ptr); } @@ -308,7 +298,7 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr) mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - auto memoryManager = new (std::nothrow) TestedDrmMemoryManager(this->mock, false, false); + auto memoryManager = std::make_unique(this->mock, false, false, *executionEnvironment); size_t size = 4 * 1024; void *ptr = ::alignedMalloc(size, 4096); @@ -318,7 +308,6 @@ TEST_F(DrmMemoryManagerTest, doNotPinAfterAllocateWhenAskedButNotAllowedHostPtr) memoryManager->freeGraphicsMemory(alloc); - delete memoryManager; ::alignedFree(ptr); } @@ -335,12 +324,12 @@ TEST_F(DrmMemoryManagerTest, UnreferenceNullPtr) { } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerCreatedWithGemCloseWorkerModeInactiveThenGemCloseWorkerIsNotCreated) { - DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false); + DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerInactive, false, false, executionEnvironment); EXPECT_EQ(nullptr, drmMemoryManger.peekGemCloseWorker()); } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerCreatedWithGemCloseWorkerActiveThenGemCloseWorkerIsCreated) { - DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerActive, false, false); + DrmMemoryManager drmMemoryManger(this->mock, gemCloseWorkerMode::gemCloseWorkerActive, false, false, executionEnvironment); EXPECT_NE(nullptr, drmMemoryManger.peekGemCloseWorker()); } @@ -557,7 +546,7 @@ TEST_F(DrmMemoryManagerTest, NullOsHandleStorageAskedForPopulationReturnsFilledP } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesReturnsInvalidHostPointerError) { - std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); @@ -586,7 +575,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenPinningFailWithErrorDifferentThanEfaultThenPopulateOsHandlesReturnsError) { - std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); @@ -1227,9 +1216,9 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenTiledImageIsBeingCreatedFr mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; - MockContext context; + std::unique_ptr device(MockDevice::createWithExecutionEnvironment(*platformDevices, executionEnvironment, 0u)); + MockContext context(device.get()); context.setMemoryManager(memoryManager); - memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver(); cl_image_format imageFormat; imageFormat.image_channel_data_type = CL_UNORM_INT8; @@ -2235,60 +2224,69 @@ TEST(MmapFlags, givenVariousMmapParametersGetTimeDeltaForTheOperation) { } TEST(DrmMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) { - DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true); + ExecutionEnvironment executionEnvironment; + DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); } TEST(DrmMemoryManager, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) { + ExecutionEnvironment executionEnvironment; DebugManagerStateRestore dbgStateRestore; DebugManager.flags.EnableDeferredDeleter.set(true); - DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true); + DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); } TEST(DrmMemoryManager, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) { + ExecutionEnvironment executionEnvironment; DebugManagerStateRestore dbgStateRestore; DebugManager.flags.EnableDeferredDeleter.set(false); - DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true); + DrmMemoryManager memoryManager(Drm::get(0), gemCloseWorkerMode::gemCloseWorkerInactive, false, true, executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); } TEST(DrmMemoryManager, givenDefaultDrmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenInternalHeapBaseIsReturned) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true, executionEnvironment)); auto internalAllocator = memoryManager->getDrmInternal32BitAllocator(); auto heapBase = internalAllocator->getBase(); EXPECT_EQ(heapBase, memoryManager->getInternalHeapBaseAddress()); } TEST(DrmMemoryManager, givenMemoryManagerWithEnabledHostMemoryValidationWhenFeatureIsQueriedThenTrueIsReturned) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); ASSERT_NE(nullptr, memoryManager.get()); EXPECT_TRUE(memoryManager->isValidateHostMemoryEnabled()); } TEST(DrmMemoryManager, givenMemoryManagerWithDisabledHostMemoryValidationWhenFeatureIsQueriedThenFalseIsReturned) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, false)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, false, executionEnvironment)); ASSERT_NE(nullptr, memoryManager.get()); EXPECT_FALSE(memoryManager->isValidateHostMemoryEnabled()); } TEST(DrmMemoryManager, givenEnabledHostMemoryValidationWhenMemoryManagerIsCreatedThenPinBBIsCreated) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); ASSERT_NE(nullptr, memoryManager.get()); ASSERT_NE(nullptr, memoryManager->getPinBB()); } TEST(DrmMemoryManager, givenEnabledHostMemoryValidationAndForcePinWhenMemoryManagerIsCreatedThenPinBBIsCreated) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), true, true, executionEnvironment)); ASSERT_NE(nullptr, memoryManager.get()); ASSERT_NE(nullptr, memoryManager->getPinBB()); } TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size); @@ -2303,7 +2301,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenM } TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); @@ -2313,7 +2312,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCall } TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); memoryManager->setForce32BitAllocations(true); void *ptr = reinterpret_cast(0x1001); @@ -2328,7 +2328,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrI } TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -2338,7 +2339,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphi } TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); auto osHandle = 1u; auto allocation = memoryManager->createGraphicsAllocationFromSharedHandle(osHandle, false); EXPECT_NE(nullptr, allocation); @@ -2347,7 +2349,8 @@ TEST(DrmMemoryManager, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledT } TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false); ASSERT_NE(nullptr, allocation); @@ -2356,7 +2359,8 @@ TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAlloca } TEST(DrmMemoryManager, DISABLED_givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true)); + ExecutionEnvironment executionEnvironment; + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(Drm::get(0), false, true, executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -2370,7 +2374,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna this->mock->ioctl_expected.gemUserptr = 1; EXPECT_THROW( { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); EXPECT_NE(nullptr, testedMemoryManager.get()); }, std::exception); @@ -2380,7 +2384,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEnabledValidateHostMemoryWhenPopulateOsHandlesIsCalledThenHostMemoryIsValidated) { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager.get()); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); @@ -2420,7 +2424,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna size_t numberOfBosPinned; }; - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager.get()); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); @@ -2469,7 +2473,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 2; - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true)); + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true, executionEnvironment)); ASSERT_NE(nullptr, memoryManager->getPinBB()); size_t size = 10 * 1024 * 1024; @@ -2483,7 +2487,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenValidateHostPtrMemoryE } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenValidHostPointerIsPassedToPopulateThenSuccessIsReturned) { - std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); OsHandleStorage storage; storage.fragmentStorageData[0].cpuPtr = reinterpret_cast(0x1000); @@ -2502,7 +2506,7 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAndHostMemoryValidationEnabledWhenSmal mock->ioctl_expected.gemWait = 1; // in freeGraphicsAllocation mock->ioctl_expected.gemClose = 2; // 1 pinBB, 1 small allocation - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true)); + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, true, *executionEnvironment)); ASSERT_NE(nullptr, memoryManager->getPinBB()); // one page is too small for early pinning but pinning is used for host memory validation @@ -2521,7 +2525,7 @@ TEST_F(DrmMemoryManagerTest, givenForcePinAllowedAndNoPinBBInMemoryManagerWhenAl mock->ioctl_expected.gemWait = 1; mock->ioctl_expected.gemClose = 1; mock->ioctl_res = -1; - std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false)); + std::unique_ptr memoryManager(new (std::nothrow) TestedDrmMemoryManager(this->mock, true, false, *executionEnvironment)); EXPECT_EQ(nullptr, memoryManager->getPinBB()); mock->ioctl_res = 0; @@ -2535,7 +2539,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenAllocateGraphicsMemoryForN } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndHostMemoryValidationEnabledWhenAllocationIsCreatedThenBufferObjectIsPinnedOnlyOnce) { - std::unique_ptr memoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr memoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); mock->reset(); mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.execbuffer2 = 1; @@ -2555,7 +2559,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndHostMemoryValidationDisabledWhenAllocationIsCreatedThenBufferObjectIsNotPinned) { - std::unique_ptr memoryManager(new TestedDrmMemoryManager(this->mock, false, false)); + std::unique_ptr memoryManager(new TestedDrmMemoryManager(this->mock, false, false, executionEnvironment)); mock->reset(); mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemClose = 1; @@ -2574,7 +2578,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenForcePinNotAllowedAndH } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesMarksFragmentsToFree) { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager.get()); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); @@ -2620,7 +2624,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenReadOnlyPointerCausesPinningFailWithEfaultThenPopulateOsHandlesDoesNotStoreTheFragments) { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); mock->reset(); @@ -2662,7 +2666,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMemoryWhenPopulateOsHandlesSucceedsThenFragmentIsStoredInHostPtrManager) { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); mock->reset(); @@ -2687,7 +2691,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem } TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCleanOsHandlesDeletesHandleDataThenOsHandleStorageAndResidencyIsSetToNullptr) { - std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true)); + std::unique_ptr testedMemoryManager(new TestedDrmMemoryManager(this->mock, false, true, executionEnvironment)); ASSERT_NE(nullptr, testedMemoryManager->getPinBB()); OsHandleStorage handleStorage; diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index cf3484e6bc..6181941f3f 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -65,7 +65,7 @@ class WddmCommandStreamFixture { ASSERT_NE(nullptr, csr); - mockWddmMM = new MockWddmMemoryManager(wddm); + mockWddmMM = new MockWddmMemoryManager(wddm, *executionEnvironment); memManager.reset(mockWddmMM); csr->setMemoryManager(memManager.get()); 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 4883147ae9..a2bc3dc4b0 100644 --- a/unit_tests/os_interface/windows/mock_wddm_memory_manager.h +++ b/unit_tests/os_interface/windows/mock_wddm_memory_manager.h @@ -24,9 +24,9 @@ class MockWddmMemoryManager : public WddmMemoryManager { using BaseClass::trimCandidatesCount; using BaseClass::trimResidency; using BaseClass::trimResidencyToBudget; + using BaseClass::WddmMemoryManager; - MockWddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm) : WddmMemoryManager(enable64kbPages, enableLocalMemory, wddm){}; - MockWddmMemoryManager(Wddm *wddm) : WddmMemoryManager(false, false, wddm){}; + MockWddmMemoryManager(Wddm *wddm, ExecutionEnvironment &executionEnvironment) : WddmMemoryManager(false, false, wddm, executionEnvironment){}; 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 32e36f1d89..6cef8f0490 100644 --- a/unit_tests/os_interface/windows/wddm20_tests.cpp +++ b/unit_tests/os_interface/windows/wddm20_tests.cpp @@ -165,7 +165,7 @@ TEST_F(Wddm20Tests, whenInitializeWddmThenContextIsCreated) { } TEST_F(Wddm20Tests, allocation) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -313,7 +313,7 @@ TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocati } TEST_F(Wddm20Tests, mapAndFreeGpuVa) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -338,7 +338,7 @@ TEST_F(Wddm20Tests, mapAndFreeGpuVa) { } TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(nullptr, 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -358,7 +358,7 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) { } TEST_F(Wddm20Tests, makeResidentNonResident) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); Gmm *gmm = GmmHelperFunctions::getGmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize()); @@ -397,7 +397,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - WddmMemoryManager mm(false, false, wddm); + WddmMemoryManager mm(false, false, wddm, executionEnvironment); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; @@ -434,7 +434,7 @@ TEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocationF auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u); EXPECT_EQ(0u, status); - WddmMemoryManager mm(false, false, wddm); + WddmMemoryManager mm(false, false, wddm, executionEnvironment); auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false); auto wddmAllocation = (WddmAllocation *)graphicsAllocation; @@ -563,7 +563,7 @@ TEST(DebugFlagTest, givenDebugManagerWhenGetForUseNoRingFlushesKmdModeIsCalledTh } TEST_F(Wddm20Tests, makeResidentMultipleHandles) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; @@ -585,7 +585,7 @@ TEST_F(Wddm20Tests, makeResidentMultipleHandles) { } TEST_F(Wddm20Tests, makeResidentMultipleHandlesWithReturnBytesToTrim) { - OsAgnosticMemoryManager mm(false, false); + OsAgnosticMemoryManager mm(false, false, executionEnvironment); WddmAllocation allocation(mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull); allocation.handle = ALLOCATION_HANDLE; diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl index 44d7815728..c629961a1c 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl +++ b/unit_tests/os_interface/windows/wddm_memory_manager_allocate_in_device_pool_tests.inl @@ -12,7 +12,7 @@ using namespace OCLRT; using namespace ::testing; TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success; AllocationData allocData; allocData.allFlags = 0; 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 3a1f1d210d..6fd3e8ab2b 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.cpp @@ -16,6 +16,7 @@ #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_deferred_deleter.h" +#include "unit_tests/mocks/mock_device.h" #include "unit_tests/os_interface/windows/mock_wddm_allocation.h" #include "unit_tests/os_interface/windows/wddm_memory_manager_tests.h" @@ -39,7 +40,7 @@ void WddmMemoryManagerFixture::SetUp() { osInterface = std::make_unique(); osInterface->get()->setWddm(wddm); - memoryManager = std::make_unique(wddm); + memoryManager = std::make_unique(wddm, executionEnvironment); } TEST(WddmMemoryManager, NonCopyable) { @@ -71,12 +72,13 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenRegisteringOsContextThen } TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) { + ExecutionEnvironment executionEnvironment; std::unique_ptr wddm(static_cast(Wddm::createWddm())); uint64_t base = 0x56000; uint64_t size = 0x9000; wddm->setHeap32(base, size); - std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(false, false, wddm.get())); + std::unique_ptr memoryManager = std::unique_ptr(new WddmMemoryManager(false, false, wddm.get(), executionEnvironment)); ASSERT_NE(nullptr, memoryManager->allocator32Bit.get()); @@ -84,10 +86,11 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase } TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) { + ExecutionEnvironment executionEnvironment; auto wddm = std::make_unique(); bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); - MockWddmMemoryManager memoryManager(wddm.get()); + MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment); EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); memoryManager.waitForDeletions(); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); @@ -95,7 +98,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size); @@ -112,7 +115,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false); EXPECT_NE(nullptr, allocation); @@ -122,7 +125,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = 4096u; auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false); @@ -135,7 +138,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); void *ptr = reinterpret_cast(0x1001); auto size = MemoryConstants::pageSize; @@ -149,7 +152,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -160,7 +163,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) { - memoryManager.reset(new MockWddmMemoryManager(true, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(true, false, wddm, executionEnvironment)); auto size = MemoryConstants::pageSize; auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false); @@ -170,7 +173,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl } TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); auto osHandle = 1u; gdi->getQueryResourceInfoArgOut().NumAllocations = 1; std::unique_ptr gmm(new Gmm(nullptr, 0, false)); @@ -190,7 +193,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHa TEST_F(WddmMemoryManagerSimpleTest, givenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledWhenNotAlignedPtrIsPassedThenAlignedGraphicsAllocationIsCreated) { - memoryManager.reset(new MockWddmMemoryManager(false, false, wddm)); + memoryManager.reset(new MockWddmMemoryManager(false, false, wddm, executionEnvironment)); void *hostPtr = reinterpret_cast(0x5001); auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(13, hostPtr); @@ -482,9 +485,10 @@ TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageWithMipCountNo } TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedFromHostPtrThenallocateGraphicsMemoryForImageIsUsed) { - MockContext context; + executionEnvironment.incRefInternal(); // to prevent destrorying execution environment by destructor of device + std::unique_ptr device(MockDevice::createWithExecutionEnvironment(*platformDevices, &executionEnvironment, 0u)); + MockContext context(device.get()); context.setMemoryManager(memoryManager.get()); - memoryManager->csr = &context.getDevice(0)->getCommandStreamReceiver(); cl_image_format imageFormat; imageFormat.image_channel_data_type = CL_UNORM_INT8; @@ -1850,34 +1854,34 @@ TEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemory EXPECT_TRUE(memoryManager->isMemoryBudgetExhausted()); } -TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { - auto wddm = std::make_unique(); - wddm->callBaseDestroyAllocations = false; - MockDeferredDeleter *deleter = new MockDeferredDeleter; - MockWddmMemoryManager memoryManager(wddm.get()); - memoryManager.setDeferredDeleter(deleter); +struct WddmMemoryManagerWithAsyncDeleterTest : ::testing::Test { + void SetUp() { + wddm = std::make_unique(); + wddm->callBaseDestroyAllocations = false; + deleter = new MockDeferredDeleter; + memoryManager = std::make_unique(wddm.get(), executionEnvironment); + memoryManager->setDeferredDeleter(deleter); + } + MockDeferredDeleter *deleter = nullptr; + std::unique_ptr memoryManager; + ExecutionEnvironment executionEnvironment; + std::unique_ptr wddm; +}; + +TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { EXPECT_EQ(0, deleter->deferDeletionCalled); - memoryManager.tryDeferDeletions(nullptr, 0, 0); + memoryManager->tryDeferDeletions(nullptr, 0, 0); EXPECT_EQ(1, deleter->deferDeletionCalled); EXPECT_EQ(1u, wddm.get()->destroyAllocationResult.called); } -TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) { - auto wddm = std::make_unique(); - wddm->callBaseDestroyAllocations = false; - MockWddmMemoryManager memoryManager(wddm.get()); - memoryManager.setDeferredDeleter(nullptr); - memoryManager.tryDeferDeletions(nullptr, 0, 0); +TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) { + memoryManager->setDeferredDeleter(nullptr); + memoryManager->tryDeferDeletions(nullptr, 0, 0); EXPECT_EQ(1u, wddm->destroyAllocationResult.called); } -TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) { - auto wddm = std::make_unique(); - wddm->callBaseDestroyAllocations = false; - MockDeferredDeleter *deleter = new MockDeferredDeleter; - MockWddmMemoryManager memoryManager(wddm.get()); - memoryManager.setDeferredDeleter(deleter); - +TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) { cl_image_desc imgDesc; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; ImageInfo imgInfo; @@ -1886,18 +1890,12 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh EXPECT_EQ(0, deleter->drainCalled); EXPECT_EQ(0u, wddm->createAllocationResult.called); deleter->expectDrainBlockingValue(true); - memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr); + memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr); EXPECT_EQ(1, deleter->drainCalled); EXPECT_EQ(2u, wddm->createAllocationResult.called); } -TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) { - auto wddm = std::make_unique(); - wddm->callBaseDestroyAllocations = false; - MockDeferredDeleter *deleter = new MockDeferredDeleter; - MockWddmMemoryManager memoryManager(wddm.get()); - memoryManager.setDeferredDeleter(deleter); - +TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) { cl_image_desc imgDesc; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; ImageInfo imgInfo; @@ -1908,41 +1906,39 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh EXPECT_EQ(0, deleter->drainCalled); EXPECT_EQ(0u, wddm->createAllocationResult.called); EXPECT_EQ(0u, wddm->mapGpuVirtualAddressResult.called); - auto allocation = memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr); + auto allocation = memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr); EXPECT_EQ(0, deleter->drainCalled); EXPECT_EQ(1u, wddm->createAllocationResult.called); EXPECT_EQ(1u, wddm->mapGpuVirtualAddressResult.called); - memoryManager.freeGraphicsMemory(allocation); + memoryManager->freeGraphicsMemory(allocation); } -TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) { - auto wddm = std::make_unique(); - wddm->callBaseDestroyAllocations = false; - MockWddmMemoryManager memoryManager(wddm.get()); - memoryManager.setDeferredDeleter(nullptr); - +TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) { + memoryManager->setDeferredDeleter(nullptr); cl_image_desc imgDesc; imgDesc.image_type = CL_MEM_OBJECT_IMAGE3D; ImageInfo imgInfo; imgInfo.imgDesc = &imgDesc; wddm->createAllocationStatus = STATUS_GRAPHICS_NO_VIDEO_MEMORY; EXPECT_EQ(0u, wddm->createAllocationResult.called); - memoryManager.allocateGraphicsMemoryForImage(imgInfo, nullptr); + memoryManager->allocateGraphicsMemoryForImage(imgInfo, nullptr); EXPECT_EQ(1u, wddm->createAllocationResult.called); } TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeap1BaseIsReturned) { + ExecutionEnvironment executionEnvironment; auto wddm = std::make_unique(); wddm->callBaseDestroyAllocations = false; - MockWddmMemoryManager memoryManager(wddm.get()); + MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment); auto heapBase = wddm->getGfxPartition().Heap32[1].Base; EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress()); } TEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) { + ExecutionEnvironment executionEnvironment; auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); - MockWddmMemoryManager memoryManager(wddm.get()); + MockWddmMemoryManager memoryManager(wddm.get(), executionEnvironment); auto wddmAlloc = (WddmAllocation *)memoryManager.allocateGraphicsMemory(4096u, reinterpret_cast(0x1000)); @@ -1956,7 +1952,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemor auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); DebugManager.flags.Enable64kbpages.set(true); - WddmMemoryManager memoryManager64k(true, false, wddm.get()); + WddmMemoryManager memoryManager64k(true, false, wddm.get(), executionEnvironment); EXPECT_EQ(0, wddm->createAllocationResult.called); GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, static_cast(MemoryConstants::pageSize64k), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY); @@ -1974,7 +1970,7 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); DebugManager.flags.Enable64kbpages.set(true); - WddmMemoryManager memoryManager(true, false, wddm.get()); + WddmMemoryManager memoryManager(true, false, wddm.get(), executionEnvironment); auto graphicsAllocation = memoryManager.allocateGraphicsMemory64kb(1, MemoryConstants::pageSize64k, false, false); EXPECT_NE(nullptr, graphicsAllocation); @@ -1987,11 +1983,12 @@ TEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocation } TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) { + ExecutionEnvironment executionEnvironment; DebugManagerStateRestore dbgRestore; DebugManager.flags.Enable64kbpages.set(true); auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); - MockWddmMemoryManager memoryManager64k(wddm.get()); + MockWddmMemoryManager memoryManager64k(wddm.get(), executionEnvironment); uint32_t lockCount = wddm->lockResult.called; uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called; GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemory64kb(65536, 65536, true, false); @@ -2003,14 +2000,14 @@ TEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLoc TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) { auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled()); EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); } TEST_F(MockWddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenItIsCreatedThenMemoryBudgetIsNotExhausted) { auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted()); } @@ -2018,7 +2015,7 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerI bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(true); auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled()); EXPECT_NE(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -2028,7 +2025,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get(); DebugManager.flags.EnableDeferredDeleter.set(false); auto wddm = std::make_unique(); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled()); EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter()); DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag); @@ -2037,7 +2034,7 @@ TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManager TEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) { auto myWddm = std::make_unique(); EXPECT_TRUE(myWddm->init()); - WddmMemoryManager memoryManager(false, false, myWddm.get()); + WddmMemoryManager memoryManager(false, false, myWddm.get(), executionEnvironment); auto mockMngr = new NiceMock(); myWddm->resetPageTableManager(mockMngr); @@ -2097,7 +2094,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpuVa TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingThenUnmapAuxVa) { auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); D3DGPU_VIRTUAL_ADDRESS gpuVa = 123; auto mockMngr = new NiceMock(); @@ -2123,7 +2120,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingT TEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleaseingThenDontUnmapAuxVa) { auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); @@ -2167,7 +2164,7 @@ TEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnse D3DGPU_VIRTUAL_ADDRESS gpuVa = 0; auto wddm = std::make_unique(); EXPECT_TRUE(wddm->init()); - WddmMemoryManager memoryManager(false, false, wddm.get()); + WddmMemoryManager memoryManager(false, false, wddm.get(), executionEnvironment); auto mockMngr = new NiceMock(); wddm->resetPageTableManager(mockMngr); diff --git a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h index 9af8f2da1b..384b0a7703 100644 --- a/unit_tests/os_interface/windows/wddm_memory_manager_tests.h +++ b/unit_tests/os_interface/windows/wddm_memory_manager_tests.h @@ -58,7 +58,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture { osContext = new OsContext(osInterface.get(), 0u); osContext->incRefInternal(); - memoryManager = std::make_unique(wddm); + memoryManager = std::make_unique(wddm, executionEnvironment); memoryManager->registerOsContext(osContext); } @@ -120,7 +120,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture { osContext = new OsContext(osInterface.get(), 0u); osContext->incRefInternal(); wddm->init(); - memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm); + memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm, executionEnvironment); //assert we have memory manager ASSERT_NE(nullptr, memoryManager); diff --git a/unit_tests/program/kernel_info_tests.cpp b/unit_tests/program/kernel_info_tests.cpp index 68d7e7b3d7..e464879c00 100644 --- a/unit_tests/program/kernel_info_tests.cpp +++ b/unit_tests/program/kernel_info_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/program/kernel_info.h" #include "runtime/memory_manager/os_agnostic_memory_manager.h" #include "gtest/gtest.h" @@ -105,7 +106,8 @@ TEST(KernelInfo, decodeImageKernelArgument) { TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKernelHeapToKernelAllocation) { KernelInfo kernelInfo; - OsAgnosticMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + OsAgnosticMemoryManager memoryManager(false, false, executionEnvironment); SKernelBinaryHeaderCommon kernelHeader; const size_t heapSize = 0x40; char heap[heapSize]; @@ -127,12 +129,14 @@ TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationThenCopyWholeKerne class MyMemoryManager : public OsAgnosticMemoryManager { public: + using OsAgnosticMemoryManager::OsAgnosticMemoryManager; GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override { return nullptr; } }; TEST(KernelInfoTest, givenKernelInfoWhenCreateKernelAllocationAndCannotAllocateMemoryThenReturnsFalse) { KernelInfo kernelInfo; - MyMemoryManager memoryManager; + ExecutionEnvironment executionEnvironment; + MyMemoryManager memoryManager(false, false, executionEnvironment); SKernelBinaryHeaderCommon kernelHeader; kernelInfo.heapInfo.pKernelHeader = &kernelHeader; auto retVal = kernelInfo.createKernelAllocation(&memoryManager); diff --git a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp index 4c26d8ee44..78489e2c79 100644 --- a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp +++ b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp @@ -66,7 +66,7 @@ struct GlArbSyncEventTest : public ::testing::Test { executionEnvironment = new ExecutionEnvironment; auto mockCsr = new MockCommandStreamReceiver(); executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr(mockCsr)); - executionEnvironment->memoryManager = std::make_unique(false, false); + executionEnvironment->memoryManager = std::make_unique(false, false, *executionEnvironment); device.reset(MockDevice::create(nullptr, executionEnvironment, 0u)); ctx.reset(new MockContext); cmdQ.reset(new MockCommandQueue(ctx.get(), device.get(), nullptr)); diff --git a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp index 27ceb993e2..1d9b06db7b 100644 --- a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp @@ -22,6 +22,9 @@ class CreateFromGlTexture : public ::testing::Test { // temp solution - we need to query size from GMM: class TempMM : public OsAgnosticMemoryManager { public: + TempMM() : OsAgnosticMemoryManager(false, false, *(new ExecutionEnvironment)) { + mockExecutionEnvironment.reset(&executionEnvironment); + } GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); if (handle == CreateFromGlTexture::mcsHandle) { @@ -34,6 +37,7 @@ class CreateFromGlTexture : public ::testing::Test { size_t forceAllocationSize; Gmm *forceGmm = nullptr; Gmm *forceMcsGmm = nullptr; + std::unique_ptr mockExecutionEnvironment; }; void SetUp() override { diff --git a/unit_tests/sharings/gl/gl_texture_tests.cpp b/unit_tests/sharings/gl/gl_texture_tests.cpp index ee84279d94..c4d24eb6b1 100644 --- a/unit_tests/sharings/gl/gl_texture_tests.cpp +++ b/unit_tests/sharings/gl/gl_texture_tests.cpp @@ -22,6 +22,7 @@ class GlSharingTextureTests : public ::testing::Test { // temp solution - we need to query size from GMM: class TempMM : public MockMemoryManager { public: + using MockMemoryManager::MockMemoryManager; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override { auto alloc = OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(handle, requireSpecificBitness); if (useForcedGmm) { @@ -48,7 +49,7 @@ class GlSharingTextureTests : public ::testing::Test { glSharing = new MockGlSharing; clContext.setSharingFunctions(&glSharing->m_sharingFunctions); ASSERT_FALSE(overrideCommandStreamReceiverCreation); - tempMM = new TempMM; + tempMM = new TempMM(*clContext.getDevice(0)->getExecutionEnvironment()); tempMM->forceGmm = MockGmm::queryImgParams(imgInfo); tempMM->forceAllocationSize = textureSize; MockDevice *device = static_cast(clContext.getDevice(0));