From 1ad70dfebe0690f82d37a67fd87dd5ce4b93fe15 Mon Sep 17 00:00:00 2001 From: "Stefanowski, Adam" Date: Thu, 16 Aug 2018 11:18:05 +0200 Subject: [PATCH] Decouple memory manager and device Change-Id: Ia64cc955e1d290cad4c50b6a2a41052d9acf0eec --- .../command_stream_receiver_hw.h | 6 +- .../command_stream_receiver_hw.inl | 28 ++++---- .../command_stream/submissions_aggregator.cpp | 2 +- .../command_stream/submissions_aggregator.h | 6 +- runtime/device/device.cpp | 1 - runtime/memory_manager/memory_manager.h | 1 - ...mmand_stream_receiver_flush_task_tests.cpp | 17 +++-- .../command_stream_receiver_hw_tests.cpp | 14 ++-- .../submissions_aggregator_tests.cpp | 67 ++++++++++++------- unit_tests/device/device_tests.cpp | 5 -- .../command_stream_receiver_hw_tests_gen9.cpp | 8 +-- unit_tests/mem_obj/mem_obj_tests.cpp | 9 +-- unit_tests/mocks/mock_csr.h | 5 +- unit_tests/mocks/mock_device.cpp | 1 - unit_tests/mocks/mock_memory_manager.cpp | 4 -- unit_tests/mocks/mock_memory_manager.h | 1 - .../linux/drm_command_stream_tests.cpp | 8 +-- .../linux/drm_memory_manager_tests.cpp | 3 +- .../windows/device_command_stream_tests.cpp | 25 ++++--- 19 files changed, 106 insertions(+), 105 deletions(-) diff --git a/runtime/command_stream/command_stream_receiver_hw.h b/runtime/command_stream/command_stream_receiver_hw.h index f4a3c370b1..5bd101b81a 100644 --- a/runtime/command_stream/command_stream_receiver_hw.h +++ b/runtime/command_stream/command_stream_receiver_hw.h @@ -60,7 +60,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { size_t getRequiredCmdStreamSize(const DispatchFlags &dispatchFlags, Device &device); size_t getRequiredCmdStreamSizeAligned(const DispatchFlags &dispatchFlags, Device &device); - size_t getRequiredCmdSizeForPreamble() const; + size_t getRequiredCmdSizeForPreamble(Device &device) const; size_t getCmdSizeForPreemption(const DispatchFlags &dispatchFlags) const; size_t getCmdSizeForL3Config() const; size_t getCmdSizeForPipelineSelect() const; @@ -86,9 +86,9 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { } protected: - void programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags); + void programPreemption(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags); void programL3(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t &newL3Config); - void programPreamble(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t &newL3Config); + void programPreamble(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags, uint32_t &newL3Config); void programPipelineSelect(LinearStream &csr, DispatchFlags &dispatchFlags); void programMediaSampler(LinearStream &csr, DispatchFlags &dispatchFlags); virtual void programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags); diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 676a17098c..46b9ba38d5 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -88,14 +88,14 @@ inline void CommandStreamReceiverHw::alignToCacheLine(LinearStream &c } template -inline size_t CommandStreamReceiverHw::getRequiredCmdSizeForPreamble() const { +inline size_t CommandStreamReceiverHw::getRequiredCmdSizeForPreamble(Device &device) const { size_t size = 0; if (mediaVfeStateDirty) { size += sizeof(typename GfxFamily::PIPE_CONTROL) + sizeof(typename GfxFamily::MEDIA_VFE_STATE); } if (!this->isPreambleSent) { - size += PreambleHelper::getAdditionalCommandsSize(*memoryManager->device); + size += PreambleHelper::getAdditionalCommandsSize(device); } if (!this->isPreambleSent || this->lastSentThreadArbitrationPolicy != this->requiredThreadArbitrationPolicy) { size += PreambleHelper::getThreadArbitrationCommandsSize(); @@ -254,11 +254,11 @@ CompletionStamp CommandStreamReceiverHw::flushTask( auto commandStreamStartCSR = commandStreamCSR.getUsed(); initPageTableManagerRegisters(commandStreamCSR); - programPreemption(commandStreamCSR, dispatchFlags); + programPreemption(commandStreamCSR, device, dispatchFlags); programCoherency(commandStreamCSR, dispatchFlags); programL3(commandStreamCSR, dispatchFlags, newL3Config); programPipelineSelect(commandStreamCSR, dispatchFlags); - programPreamble(commandStreamCSR, dispatchFlags, newL3Config); + programPreamble(commandStreamCSR, device, dispatchFlags, newL3Config); programMediaSampler(commandStreamCSR, dispatchFlags); if (this->lastSentThreadArbitrationPolicy != this->requiredThreadArbitrationPolicy) { @@ -428,7 +428,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( this->latestFlushedTaskCount = this->taskCount + 1; this->makeSurfacePackNonResident(nullptr); } else { - auto commandBuffer = new CommandBuffer; + auto commandBuffer = new CommandBuffer(device); commandBuffer->batchBuffer = batchBuffer; commandBuffer->surfaces.swap(getMemoryManager()->getResidencyAllocations()); commandBuffer->batchBufferEndLocation = bbEndLocation; @@ -480,12 +480,13 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { } typedef typename GfxFamily::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; typedef typename GfxFamily::PIPE_CONTROL PIPE_CONTROL; - Device *device = this->getMemoryManager()->device; std::unique_lock lockGuard(ownershipMutex); - EngineType engineType = device->getEngineType(); auto &commandBufferList = this->submissionAggregator->peekCmdBufferList(); if (!commandBufferList.peekIsEmpty()) { + auto &device = commandBufferList.peekHead()->device; + EngineType engineType = device.getEngineType(); + ResidencyContainer surfacesForSubmit; ResourcePackage resourcePackage; auto pipeControlLocationSize = getRequiredPipeControlSize(); @@ -494,7 +495,7 @@ inline void CommandStreamReceiverHw::flushBatchedSubmissions() { while (!commandBufferList.peekIsEmpty()) { size_t totalUsedSize = 0u; - this->submissionAggregator->aggregateCommandBuffers(resourcePackage, totalUsedSize, (size_t)device->getDeviceInfo().globalMemSize * 5 / 10); + this->submissionAggregator->aggregateCommandBuffers(resourcePackage, totalUsedSize, (size_t)device.getDeviceInfo().globalMemSize * 5 / 10); auto primaryCmdBuffer = commandBufferList.removeFrontOne(); auto nextCommandBuffer = commandBufferList.peekHead(); auto currentBBendLocation = primaryCmdBuffer->batchBufferEndLocation; @@ -609,7 +610,7 @@ size_t CommandStreamReceiverHw::getRequiredCmdStreamSizeAligned(const template size_t CommandStreamReceiverHw::getRequiredCmdStreamSize(const DispatchFlags &dispatchFlags, Device &device) { - size_t size = getRequiredCmdSizeForPreamble(); + size_t size = getRequiredCmdSizeForPreamble(device); size += sizeof(typename GfxFamily::STATE_BASE_ADDRESS) + sizeof(PIPE_CONTROL); size += getRequiredPipeControlSize(); size += sizeof(typename GfxFamily::MI_BATCH_BUFFER_START); @@ -658,9 +659,8 @@ inline void CommandStreamReceiverHw::waitForTaskCountWithKmdNotifyFal } template -inline void CommandStreamReceiverHw::programPreemption(LinearStream &csr, DispatchFlags &dispatchFlags) { - PreemptionHelper::programCmdStream(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, preemptionCsrAllocation, - *memoryManager->device); +inline void CommandStreamReceiverHw::programPreemption(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags) { + PreemptionHelper::programCmdStream(csr, dispatchFlags.preemptionMode, this->lastPreemptionMode, preemptionCsrAllocation, device); this->lastPreemptionMode = dispatchFlags.preemptionMode; } @@ -696,9 +696,9 @@ inline size_t CommandStreamReceiverHw::getCmdSizeForL3Config() const } template -inline void CommandStreamReceiverHw::programPreamble(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t &newL3Config) { +inline void CommandStreamReceiverHw::programPreamble(LinearStream &csr, Device &device, DispatchFlags &dispatchFlags, uint32_t &newL3Config) { if (!this->isPreambleSent) { - PreambleHelper::programPreamble(&csr, *memoryManager->device, newL3Config, this->requiredThreadArbitrationPolicy, this->preemptionCsrAllocation); + PreambleHelper::programPreamble(&csr, device, newL3Config, this->requiredThreadArbitrationPolicy, this->preemptionCsrAllocation); this->isPreambleSent = true; this->lastSentL3Config = newL3Config; this->lastSentThreadArbitrationPolicy = this->requiredThreadArbitrationPolicy; diff --git a/runtime/command_stream/submissions_aggregator.cpp b/runtime/command_stream/submissions_aggregator.cpp index cfc64828f6..205965ad2d 100644 --- a/runtime/command_stream/submissions_aggregator.cpp +++ b/runtime/command_stream/submissions_aggregator.cpp @@ -110,6 +110,6 @@ void OCLRT::SubmissionAggregator::aggregateCommandBuffers(ResourcePackage &resou OCLRT::BatchBuffer::BatchBuffer(GraphicsAllocation *commandBufferAllocation, size_t startOffset, size_t chainedBatchBufferStartOffset, GraphicsAllocation *chainedBatchBuffer, bool requiresCoherency, bool lowPriority, QueueThrottle throttle, size_t usedSize, LinearStream *stream) : commandBufferAllocation(commandBufferAllocation), startOffset(startOffset), chainedBatchBufferStartOffset(chainedBatchBufferStartOffset), chainedBatchBuffer(chainedBatchBuffer), requiresCoherency(requiresCoherency), low_priority(lowPriority), throttle(throttle), usedSize(usedSize), stream(stream) { } -OCLRT::CommandBuffer::CommandBuffer() { +OCLRT::CommandBuffer::CommandBuffer(Device &device) : device(device) { flushStamp.reset(new FlushStampTracker(false)); } diff --git a/runtime/command_stream/submissions_aggregator.h b/runtime/command_stream/submissions_aggregator.h index 9100523d8a..f95daa0ec7 100644 --- a/runtime/command_stream/submissions_aggregator.h +++ b/runtime/command_stream/submissions_aggregator.h @@ -27,6 +27,7 @@ #include "runtime/memory_manager/residency_container.h" #include namespace OCLRT { +class Device; class Event; class FlushStampTracker; class GraphicsAllocation; @@ -56,7 +57,7 @@ struct BatchBuffer { }; struct CommandBuffer : public IDNode { - CommandBuffer(); + CommandBuffer(Device &); ResidencyContainer surfaces; BatchBuffer batchBuffer; void *batchBufferEndLocation = nullptr; @@ -65,6 +66,7 @@ struct CommandBuffer : public IDNode { void *pipeControlThatMayBeErasedLocation = nullptr; void *epiloguePipeControlLocation = nullptr; std::unique_ptr flushStamp; + Device &device; }; struct CommandBufferList : public IDList {}; @@ -81,4 +83,4 @@ class SubmissionAggregator { CommandBufferList cmdBuffers; uint32_t inspectionId = 1; }; -} // namespace OCLRT \ No newline at end of file +} // namespace OCLRT diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 2bc3681c17..1b0772883b 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -166,7 +166,6 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { } outDevice.executionEnvironment->memoryManager->setForce32BitAllocations(pDevice->getDeviceInfo().force32BitAddressess); - outDevice.executionEnvironment->memoryManager->device = pDevice; if (pDevice->preemptionMode == PreemptionMode::MidThread || pDevice->isSourceLevelDebuggerActive()) { size_t requiredSize = pHwInfo->capabilityTable.requiredPreemptionSurfaceSize; diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index 3b2217dbc8..57842fe5d7 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -202,7 +202,6 @@ class MemoryManager { AllocationsList allocationsForReuse; CommandStreamReceiver *csr = nullptr; - Device *device = nullptr; HostPtrManager hostPtrManager; virtual GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) = 0; 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 11e82e3978..cbfde33059 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 @@ -673,7 +673,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithOnlyEnoughMemoryForPr commandStreamReceiver.lastSentL3Config = l3Config; auto &csrCS = commandStreamReceiver.getCS(); - size_t sizeNeededForPreamble = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + size_t sizeNeededForPreamble = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); size_t sizeNeeded = commandStreamReceiver.getRequiredCmdStreamSize(flushTaskFlags, *pDevice); sizeNeeded -= sizeof(MI_BATCH_BUFFER_START); // no task to submit sizeNeeded += sizeof(MI_BATCH_BUFFER_END); // no task to submit, add BBE to CSR stream @@ -704,7 +704,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithOnlyEnoughMemoryForPr commandStreamReceiver.lastSentL3Config = l3Config; auto &csrCS = commandStreamReceiver.getCS(); - size_t sizeNeededForPreamble = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + size_t sizeNeededForPreamble = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); size_t sizeNeededForStateBaseAddress = sizeof(STATE_BASE_ADDRESS) + sizeof(PIPE_CONTROL); size_t sizeNeeded = commandStreamReceiver.getRequiredCmdStreamSize(flushTaskFlags, *pDevice); sizeNeeded -= sizeof(MI_BATCH_BUFFER_START); // no task to submit @@ -2136,7 +2136,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeAndThreeReco auto mockedSubmissionsAggregator = new mockSubmissionsAggregator(); mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator); - auto memorySize = (size_t)mockCsr->getMemoryManager()->device->getDeviceInfo().globalMemSize; + auto memorySize = (size_t)pDevice->getDeviceInfo().globalMemSize; GraphicsAllocation largeAllocation(nullptr, memorySize); DispatchFlags dispatchFlags; @@ -2319,10 +2319,10 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenRecorded mockCsr->flushBatchedSubmissions(); - EXPECT_FALSE(mockCsr->recordedCommandBuffer.batchBuffer.low_priority); - EXPECT_TRUE(mockCsr->recordedCommandBuffer.batchBuffer.requiresCoherency); - EXPECT_EQ(mockCsr->recordedCommandBuffer.batchBuffer.commandBufferAllocation, commandStream.getGraphicsAllocation()); - EXPECT_EQ(4u, mockCsr->recordedCommandBuffer.batchBuffer.startOffset); + EXPECT_FALSE(mockCsr->recordedCommandBuffer->batchBuffer.low_priority); + EXPECT_TRUE(mockCsr->recordedCommandBuffer->batchBuffer.requiresCoherency); + EXPECT_EQ(mockCsr->recordedCommandBuffer->batchBuffer.commandBufferAllocation, commandStream.getGraphicsAllocation()); + EXPECT_EQ(4u, mockCsr->recordedCommandBuffer->batchBuffer.startOffset); EXPECT_EQ(1, mockCsr->flushCalledCount); EXPECT_TRUE(mockedSubmissionsAggregator->peekCommandBuffers().peekIsEmpty()); @@ -2594,7 +2594,6 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes std::unique_ptr mockedMemoryManager(new MockedMemoryManager()); std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment)); - mockedMemoryManager->device = pDevice; mockCsr->setMemoryManager(mockedMemoryManager.get()); mockCsr->initializeTagAllocation(); mockCsr->setPreemptionCsrAllocation(pDevice->getPreemptionAllocation()); @@ -2627,7 +2626,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes EXPECT_EQ(expectedUsed, mockCsr->peekTotalMemoryUsed()); - auto budgetSize = (size_t)mockCsr->getMemoryManager()->device->getDeviceInfo().globalMemSize; + auto budgetSize = (size_t)pDevice->getDeviceInfo().globalMemSize; GraphicsAllocation hugeAllocation(nullptr, budgetSize / 4); mockCsr->makeResident(hugeAllocation); diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index c0cf8da103..2ea7d0d6d8 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -62,7 +62,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, UltCommandStreamReceiverTest, givenPreambleSentAndTh commandStreamReceiver.isPreambleSent = true; commandStreamReceiver.requiredThreadArbitrationPolicy = commandStreamReceiver.lastSentThreadArbitrationPolicy; auto expectedCmdSize = sizeof(typename FamilyType::PIPE_CONTROL) + sizeof(typename FamilyType::MEDIA_VFE_STATE); - EXPECT_EQ(expectedCmdSize, commandStreamReceiver.getRequiredCmdSizeForPreamble()); + EXPECT_EQ(expectedCmdSize, commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice)); } HWTEST_F(UltCommandStreamReceiverTest, givenPreambleSentAndThreadArbitrationPolicyChangedWhenEstimatingPreambleCmdSizeThenResultDependsOnPolicyProgrammingCmdSize) { @@ -70,10 +70,10 @@ HWTEST_F(UltCommandStreamReceiverTest, givenPreambleSentAndThreadArbitrationPoli commandStreamReceiver.isPreambleSent = true; commandStreamReceiver.requiredThreadArbitrationPolicy = commandStreamReceiver.lastSentThreadArbitrationPolicy; - auto policyNotChanged = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto policyNotChanged = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); commandStreamReceiver.requiredThreadArbitrationPolicy = commandStreamReceiver.lastSentThreadArbitrationPolicy + 1; - auto policyChanged = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto policyChanged = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); auto actualDifference = policyChanged - policyNotChanged; auto expectedDifference = PreambleHelper::getThreadArbitrationCommandsSize(); @@ -85,10 +85,10 @@ HWTEST_F(UltCommandStreamReceiverTest, givenPreambleSentWhenEstimatingPreambleCm commandStreamReceiver.requiredThreadArbitrationPolicy = commandStreamReceiver.lastSentThreadArbitrationPolicy; commandStreamReceiver.isPreambleSent = false; - auto preambleNotSent = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto preambleNotSent = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); commandStreamReceiver.isPreambleSent = true; - auto preambleSent = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto preambleSent = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); auto actualDifference = preambleNotSent - preambleSent; auto expectedDifference = PreambleHelper::getThreadArbitrationCommandsSize() + PreambleHelper::getAdditionalCommandsSize(*pDevice); @@ -102,10 +102,10 @@ HWCMDTEST_F(IGFX_GEN8_CORE, UltCommandStreamReceiverTest, givenMediaVfeStateDirt auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); commandStreamReceiver.overrideMediaVFEStateDirty(false); - auto notDirty = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto notDirty = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); commandStreamReceiver.overrideMediaVFEStateDirty(true); - auto dirty = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto dirty = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); auto actualDifference = dirty - notDirty; auto expectedDifference = sizeof(PIPE_CONTROL) + sizeof(MEDIA_VFE_STATE); diff --git a/unit_tests/command_stream/submissions_aggregator_tests.cpp b/unit_tests/command_stream/submissions_aggregator_tests.cpp index e7b69f4e33..db80a3e9bd 100644 --- a/unit_tests/command_stream/submissions_aggregator_tests.cpp +++ b/unit_tests/command_stream/submissions_aggregator_tests.cpp @@ -44,7 +44,9 @@ TEST(SubmissionsAggregator, givenDefaultSubmissionsAggregatorWhenItIsCreatedThen TEST(SubmissionsAggregator, givenCommandBufferWhenItIsPassedToSubmissionsAggregatorThenItIsRecorded) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); submissionsAggregator.recordCommandBuffer(cmdBuffer); EXPECT_FALSE(submissionsAggregator.peekCommandBuffersList().peekIsEmpty()); @@ -56,8 +58,10 @@ TEST(SubmissionsAggregator, givenCommandBufferWhenItIsPassedToSubmissionsAggrega TEST(SubmissionsAggregator, givenTwoCommandBuffersWhenMergeResourcesIsCalledThenDuplicatesAreEliminated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc2(nullptr, 2); @@ -113,9 +117,11 @@ TEST(SubmissionsAggregator, givenTwoCommandBuffersWhenMergeResourcesIsCalledThen TEST(SubmissionsAggregator, givenSubmissionAggregatorWhenThreeCommandBuffersAreSubmittedThenTheyAreAggregated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; - CommandBuffer *cmdBuffer3 = new CommandBuffer; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); + CommandBuffer *cmdBuffer3 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc2(nullptr, 2); @@ -175,9 +181,11 @@ TEST(SubmissionsAggregator, givenSubmissionAggregatorWhenThreeCommandBuffersAreS TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenTheyAreAggreagateWithCertainMemoryLimitThenOnlyThatFitAreAggregated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; - CommandBuffer *cmdBuffer3 = new CommandBuffer; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); + CommandBuffer *cmdBuffer3 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc2(nullptr, 2); @@ -229,9 +237,11 @@ TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenTheyAreAggreagateWith TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenAggregateIsCalledMultipleTimesThenFurtherInspectionAreHandledCorrectly) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; - CommandBuffer *cmdBuffer3 = new CommandBuffer; + + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); + CommandBuffer *cmdBuffer3 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc2(nullptr, 2); @@ -292,8 +302,9 @@ TEST(SubmissionsAggregator, givenMultipleCommandBuffersWhenAggregateIsCalledMult TEST(SubmissionsAggregator, givenMultipleCommandBuffersWithDifferentGraphicsAllocationsWhenAggregateIsCalledThenResourcePackContainSecondBatchBuffer) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc2(nullptr, 2); @@ -324,8 +335,9 @@ TEST(SubmissionsAggregator, givenMultipleCommandBuffersWithDifferentGraphicsAllo TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsFirstOnResourceListWhenItIsAggregatedThenResourcePackDoesntContainPrimaryBatch) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation cmdBufferAllocation1(nullptr, 1); GraphicsAllocation cmdBufferAllocation2(nullptr, 2); @@ -358,8 +370,9 @@ TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsFirstOnResou TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsTheFirstCommandBufferGraphicsAllocaitonWhenItIsAggregatedThenResourcePackDoesntContainPrimaryBatch) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation cmdBufferAllocation1(nullptr, 1); GraphicsAllocation alloc5(nullptr, 5); @@ -389,8 +402,9 @@ TEST(SubmissionsAggregator, givenTwoCommandBufferWhereSecondContainsTheFirstComm TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentCoherencySettingWhenAggregateIsCalledThenTheyAreNotAgggregated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc7(nullptr, 7); @@ -417,8 +431,9 @@ TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentCoherencySettin TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentThrottleSettingWhenAggregateIsCalledThenTheyAreNotAgggregated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc7(nullptr, 7); @@ -445,8 +460,9 @@ TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentThrottleSetting TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentPrioritySettingWhenAggregateIsCalledThenTheyAreNotAgggregated) { MockSubmissionAggregator submissionsAggregator; - CommandBuffer *cmdBuffer = new CommandBuffer; - CommandBuffer *cmdBuffer2 = new CommandBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer *cmdBuffer = new CommandBuffer(*device); + CommandBuffer *cmdBuffer2 = new CommandBuffer(*device); GraphicsAllocation alloc1(nullptr, 1); GraphicsAllocation alloc7(nullptr, 7); @@ -471,7 +487,8 @@ TEST(SubmissionsAggregator, givenCommandBuffersRequiringDifferentPrioritySetting } TEST(SubmissionsAggregator, dontAllocateFlushStamp) { - CommandBuffer cmdBuffer; + std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + CommandBuffer cmdBuffer(*device); EXPECT_EQ(nullptr, cmdBuffer.flushStamp->getStampReference()); } diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index e4497f373e..5bfd35e0a4 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -99,11 +99,6 @@ TEST_F(DeviceTest, retainAndRelease) { ASSERT_EQ(1, pDevice->getReference()); } -TEST_F(DeviceTest, givenMemoryManagerWhenDeviceIsCreatedThenItHasAccessToDevice) { - auto memoryManager = pDevice->getMemoryManager(); - EXPECT_EQ(memoryManager->device, pDevice); -} - TEST_F(DeviceTest, getEngineTypeDefault) { auto pTestDevice = std::unique_ptr(createWithUsDeviceId(0)); diff --git a/unit_tests/gen9/command_stream_receiver_hw_tests_gen9.cpp b/unit_tests/gen9/command_stream_receiver_hw_tests_gen9.cpp index 0f7f666784..0a5d858371 100644 --- a/unit_tests/gen9/command_stream_receiver_hw_tests_gen9.cpp +++ b/unit_tests/gen9/command_stream_receiver_hw_tests_gen9.cpp @@ -58,12 +58,12 @@ GEN9TEST_F(UltCommandStreamReceiverTest, givenNotSentPreambleAndMidThreadPreempt uint32_t newL3Config; DispatchFlags dispatchFlags; - auto cmdSizePreambleMidThread = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto cmdSizePreambleMidThread = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); StackVec preemptionBuffer; preemptionBuffer.resize(cmdSizePreambleMidThread); LinearStream preambleStream(&*preemptionBuffer.begin(), preemptionBuffer.size()); auto sipAllocation = BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, *pDevice).getSipAllocation(); - commandStreamReceiver.programPreamble(preambleStream, dispatchFlags, newL3Config); + commandStreamReceiver.programPreamble(preambleStream, *pDevice, dispatchFlags, newL3Config); this->parseCommands(preambleStream); auto itorStateSip = find(this->cmdList.begin(), this->cmdList.end()); @@ -88,7 +88,7 @@ GEN9TEST_F(UltCommandStreamReceiverTest, givenNotSentPreambleAndKernelDebuggingA uint32_t newL3Config; DispatchFlags dispatchFlags; - auto cmdSizePreambleMidThread = commandStreamReceiver.getRequiredCmdSizeForPreamble(); + auto cmdSizePreambleMidThread = commandStreamReceiver.getRequiredCmdSizeForPreamble(*pDevice); StackVec preemptionBuffer; preemptionBuffer.resize(cmdSizePreambleMidThread); LinearStream preambleStream(&*preemptionBuffer.begin(), preemptionBuffer.size()); @@ -99,7 +99,7 @@ GEN9TEST_F(UltCommandStreamReceiverTest, givenNotSentPreambleAndKernelDebuggingA ASSERT_NE(dbgLocalSipAllocation, nullptr); ASSERT_NE(sipAllocation, nullptr); - commandStreamReceiver.programPreamble(preambleStream, dispatchFlags, newL3Config); + commandStreamReceiver.programPreamble(preambleStream, *pDevice, dispatchFlags, newL3Config); this->parseCommands(preambleStream); auto itorStateSip = find(this->cmdList.begin(), this->cmdList.end()); diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index c374d354a1..873b93b568 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -174,7 +174,6 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe MockContext context; context.setMemoryManager(&memoryManager); - memoryManager.setDevice(context.getDevice(0)); auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = 2; @@ -194,11 +193,10 @@ TEST(MemObj, givenReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThenAl MockContext context; context.setMemoryManager(&memoryManager); - memoryManager.setDevice(context.getDevice(0)); auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = 1; - *memoryManager.device->getTagAddress() = 1; + *context.getDevice(0)->getTagAddress() = 1; MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); @@ -213,7 +211,6 @@ TEST(MemObj, givenNotUsedGraphicsAllocationWhenMemObjDestroysAllocationAsyncThen MockContext context; context.setMemoryManager(&memoryManager); - memoryManager.setDevice(context.getDevice(0)); auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = ObjectNotUsed; @@ -252,13 +249,9 @@ TEST(MemObj, givenMemObjWhenItDoesntHaveGraphicsAllocationThenWaitForCsrCompleti MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); - EXPECT_EQ(nullptr, memoryManager.device); EXPECT_EQ(nullptr, memObj.getGraphicsAllocation()); memObj.waitForCsrCompletion(); - memoryManager.setDevice(context.getDevice(0)); - - EXPECT_NE(nullptr, memoryManager.device); EXPECT_EQ(nullptr, memObj.getGraphicsAllocation()); memObj.waitForCsrCompletion(); } diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index cbb2d3b6ea..7722b876ef 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -181,7 +181,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw { FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override { flushCalledCount++; - recordedCommandBuffer.batchBuffer = batchBuffer; + recordedCommandBuffer->batchBuffer = batchBuffer; copyOfAllocations.clear(); if (allocationsForResidency) { @@ -197,12 +197,13 @@ class MockCsrHw2 : public CommandStreamReceiverHw { const IndirectHeap &dsh, const IndirectHeap &ioh, const IndirectHeap &ssh, uint32_t taskLevel, DispatchFlags &dispatchFlags, Device &device) override { passedDispatchFlags = dispatchFlags; + recordedCommandBuffer = std::unique_ptr(new CommandBuffer(device)); return CommandStreamReceiverHw::flushTask(commandStream, commandStreamStart, dsh, ioh, ssh, taskLevel, dispatchFlags, device); } int flushCalledCount = 0; - CommandBuffer recordedCommandBuffer; + std::unique_ptr recordedCommandBuffer = nullptr; ResidencyContainer copyOfAllocations; DispatchFlags passedDispatchFlags = {}; }; diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index c151ef521f..9bb512404f 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -68,7 +68,6 @@ void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { memoryManager->setCommandStreamReceiver(executionEnvironment->commandStreamReceiver.get()); executionEnvironment->commandStreamReceiver->setMemoryManager(memoryManager); setMemoryManager(memoryManager); - memoryManager->setDevice(this); } void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { diff --git a/unit_tests/mocks/mock_memory_manager.cpp b/unit_tests/mocks/mock_memory_manager.cpp index 8f6a9a4bbc..3c330eb43b 100644 --- a/unit_tests/mocks/mock_memory_manager.cpp +++ b/unit_tests/mocks/mock_memory_manager.cpp @@ -52,10 +52,6 @@ void MockMemoryManager::setCommandStreamReceiver(CommandStreamReceiver *csr) { this->csr = csr; } -void MockMemoryManager::setDevice(Device *device) { - this->device = device; -} - 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 693ab41942..a21c92f816 100644 --- a/unit_tests/mocks/mock_memory_manager.h +++ b/unit_tests/mocks/mock_memory_manager.h @@ -41,7 +41,6 @@ class MockMemoryManager : public OsAgnosticMemoryManager { GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override; int redundancyRatio = 1; void setCommandStreamReceiver(CommandStreamReceiver *csr); - void setDevice(Device *device); bool isAllocationListEmpty(); GraphicsAllocation *peekAllocationListHead(); 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 c0c5a966e2..a0d8775a48 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -687,7 +687,6 @@ class DrmCommandStreamEnhancedFixture executionEnvironment->memoryManager.reset(mm); device = Device::create(platformDevices[0], executionEnvironment); ASSERT_NE(nullptr, device); - mm->device = device; } void TearDown() { @@ -993,8 +992,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - tCsr->getMemoryManager()->device = device.get(); - tCsr->setTagAllocation(tagAllocation); tCsr->setPreemptionCsrAllocation(preemptionAllocation); DispatchFlags dispatchFlags; @@ -1007,7 +1004,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenCsrWhenDispatchPolicyIsSetToBatchingT EXPECT_NE(nullptr, cmdBuffers.peekHead()); //preemption allocation - size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; + size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; //preemption allocation + sipKernel int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; @@ -1048,7 +1045,6 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte IndirectHeap cs(commandBuffer); std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); - tCsr->getMemoryManager()->device = device.get(); tCsr->setTagAllocation(tagAllocation); tCsr->setPreemptionCsrAllocation(preemptionAllocation); auto &submittedCommandBuffer = tCsr->getCS(1024); @@ -1074,7 +1070,7 @@ TEST_F(DrmCommandStreamBatchingTests, givenRecordedCommandBufferWhenItIsSubmitte EXPECT_FALSE(commandBufferGraphicsAllocation->isResident()); //preemption allocation - size_t csrSurfaceCount = (tCsr->getMemoryManager()->device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; + size_t csrSurfaceCount = (device->getPreemptionMode() == PreemptionMode::MidThread) ? 2 : 0; //preemption allocation +sip Kernel int ioctlExtraCnt = (PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]) == PreemptionMode::MidThread) ? 2 : 0; 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 f4ca681929..ee342be6fa 100644 --- a/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp +++ b/unit_tests/os_interface/linux/drm_memory_manager_tests.cpp @@ -1056,7 +1056,6 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs DebugManager.flags.Force32bitAddressing.set(true); memoryManager->setForce32BitAllocations(true); std::unique_ptr pDevice(MockDevice::createWithNewExecutionEnvironment(nullptr)); - memoryManager->device = pDevice.get(); auto allocator = memoryManager->getDrmInternal32BitAllocator(); size_t size = getSizeToMap(); @@ -1066,7 +1065,7 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs size_t allocationSize = 4096 * 3; auto graphicsAllocation = memoryManager->allocate32BitGraphicsMemory(allocationSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION); EXPECT_EQ(nullptr, graphicsAllocation); - EXPECT_TRUE(memoryManager->device->getDeviceInfo().force32BitAddressess); + EXPECT_TRUE(pDevice->getDeviceInfo().force32BitAddressess); } TEST_F(DrmMemoryManagerTest, GivenMemoryManagerWhenAllocateGraphicsMemoryForImageIsCalledThenProperIoctlsAreCalledAndUnmapSizeIsNonZero) { 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 3d6279979d..e65fc09374 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -79,8 +79,6 @@ class WddmCommandStreamFixture { memManager.reset(mockWddmMM); csr->setMemoryManager(memManager.get()); - memManager->device = device.get(); - ASSERT_NE(nullptr, memManager); } @@ -93,6 +91,7 @@ class WddmCommandStreamFixture { template struct MockWddmCsr : public WddmCommandStreamReceiver { MockWddmCsr(const HardwareInfo &hwInfoIn, Wddm *wddm, ExecutionEnvironment &executionEnvironment) : WddmCommandStreamReceiver(hwInfoIn, wddm, executionEnvironment){}; + using CommandStreamReceiver::commandStream; using CommandStreamReceiver::dispatchMode; using CommandStreamReceiver::getCS; @@ -111,8 +110,12 @@ struct MockWddmCsr : public WddmCommandStreamReceiver { this->submissionAggregator.reset(newSubmissionsAggregator); } + void overrideRecorededCommandBuffer(Device &device) { + recordedCommandBuffer = std::unique_ptr(new CommandBuffer(device)); + } + int flushCalledCount = 0; - CommandBuffer recordedCommandBuffer; + std::unique_ptr recordedCommandBuffer = nullptr; }; class WddmCommandStreamWithMockGdiFixture { @@ -140,6 +143,7 @@ class WddmCommandStreamWithMockGdiFixture { executionEnvironment->memoryManager.reset(memManager); device = Device::create(platformDevices[0], executionEnvironment); ASSERT_NE(nullptr, device); + this->csr->overrideRecorededCommandBuffer(*device); if (device->getPreemptionMode() == PreemptionMode::MidThread) { preemptionAllocation = memManager->allocateGraphicsMemory(1024); } @@ -779,9 +783,10 @@ using WddmSimpleTest = ::testing::Test; HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) { DebugManager.flags.CsrDispatchMode.set(0); - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment)); auto wddm = Wddm::createWddm(); - std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], wddm, executionEnvironment)); + std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], wddm, *executionEnvironment)); EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); } @@ -819,11 +824,12 @@ struct WddmCsrCompressionTests : ::testing::Test { HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) { bool compressionEnabled[2][2] = {{true, false}, {false, true}}; for (size_t i = 0; i < 2; i++) { - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment)); setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]); createMockWddm(); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); - MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, executionEnvironment); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); auto mockMngr = reinterpret_cast(myMockWddm->getPageTableManager()); @@ -863,10 +869,11 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCrea } HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDontCreatePagetableMngr) { - ExecutionEnvironment executionEnvironment; + ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; + std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment)); setCompressionEnabled(false, false); createMockWddm(); - MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, executionEnvironment); + MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); }