diff --git a/runtime/built_ins/builtins_dispatch_builder.h b/runtime/built_ins/builtins_dispatch_builder.h index 67b0385212..d86b309508 100644 --- a/runtime/built_ins/builtins_dispatch_builder.h +++ b/runtime/built_ins/builtins_dispatch_builder.h @@ -80,9 +80,12 @@ class BuiltinDispatchInfoBuilder { protected: template void grabKernels(KernelNameT &&kernelName, Kernel *&kernelDst, KernelsDescArgsT &&... kernelsDesc) { - const KernelInfo *ki = prog->getKernelInfo(kernelName); + const KernelInfo *kernelInfo = prog->getKernelInfo(kernelName); + if (!kernelInfo) { + return; + } cl_int err = 0; - kernelDst = Kernel::create(prog.get(), *ki, &err); + kernelDst = Kernel::create(prog.get(), *kernelInfo, &err); kernelDst->isBuiltIn = true; usedKernels.push_back(std::unique_ptr(kernelDst)); grabKernels(std::forward(kernelsDesc)...); diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index 55b733e94f..cf2573541c 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -69,9 +69,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwmemoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true, this->executionEnvironment); - this->flatBatchBufferHelper->setMemoryManager(this->memoryManager); - return this->memoryManager; + return new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true, this->executionEnvironment); } static const AubMemDump::LrcaHelper &getCsTraits(EngineType engineType); diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index f950fd91f5..40e5f9aca1 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -43,7 +43,7 @@ CommandStreamReceiver::~CommandStreamReceiver() { if (indirectHeap[i] != nullptr) { auto allocation = indirectHeap[i]->getGraphicsAllocation(); if (allocation != nullptr) { - memoryManager->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); + getMemoryManager()->storeAllocation(std::unique_ptr(allocation), REUSABLE_ALLOCATION); } delete indirectHeap[i]; } @@ -119,7 +119,7 @@ void CommandStreamReceiver::makeResidentHostPtrAllocation(GraphicsAllocation *gf void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requiredTaskCount, uint32_t allocationType) { auto address = getTagAddress(); - if (address && requiredTaskCount != (unsigned int)-1) { + if (address && requiredTaskCount != ObjectNotUsed) { while (*address < requiredTaskCount) ; } @@ -131,21 +131,12 @@ void CommandStreamReceiver::waitForTaskCountAndCleanAllocationList(uint32_t requ getMemoryManager()->freeAllocationsList(requiredTaskCount, allocationList); } -MemoryManager *CommandStreamReceiver::getMemoryManager() { - return memoryManager; -} - -void CommandStreamReceiver::setMemoryManager(MemoryManager *mm) { - memoryManager = mm; - if (flatBatchBufferHelper) { - flatBatchBufferHelper->setMemoryManager(mm); - } +MemoryManager *CommandStreamReceiver::getMemoryManager() const { + DEBUG_BREAK_IF(!executionEnvironment.memoryManager); + return executionEnvironment.memoryManager.get(); } LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { - auto memoryManager = this->getMemoryManager(); - DEBUG_BREAK_IF(nullptr == memoryManager); - if (commandStream.getAvailableSpace() < minRequiredSize) { // Make sure we have enough room for a MI_BATCH_BUFFER_END and any padding. // Currently reserving 64bytes (cacheline) which should be more than enough. @@ -156,16 +147,16 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { auto requiredSize = minRequiredSize + CSRequirements::csOverfetchSize; - auto allocation = memoryManager->obtainReusableAllocation(requiredSize, false).release(); + auto allocation = getMemoryManager()->obtainReusableAllocation(requiredSize, false).release(); if (!allocation) { - allocation = memoryManager->allocateGraphicsMemory(requiredSize); + allocation = getMemoryManager()->allocateGraphicsMemory(requiredSize); } allocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM); //pass current allocation to reusable list if (commandStream.getCpuBase()) { - memoryManager->storeAllocation(std::unique_ptr(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION); + getMemoryManager()->storeAllocation(std::unique_ptr(commandStream.getGraphicsAllocation()), REUSABLE_ALLOCATION); } commandStream.replaceBuffer(allocation->getUnderlyingBuffer(), minRequiredSize - sizeForSubmission); @@ -176,30 +167,30 @@ LinearStream &CommandStreamReceiver::getCS(size_t minRequiredSize) { } void CommandStreamReceiver::cleanupResources() { - if (!memoryManager) + if (!getMemoryManager()) return; waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, TEMPORARY_ALLOCATION); waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, REUSABLE_ALLOCATION); if (scratchAllocation) { - memoryManager->freeGraphicsMemory(scratchAllocation); + getMemoryManager()->freeGraphicsMemory(scratchAllocation); scratchAllocation = nullptr; } if (debugSurface) { - memoryManager->freeGraphicsMemory(debugSurface); + getMemoryManager()->freeGraphicsMemory(debugSurface); debugSurface = nullptr; } if (commandStream.getCpuBase()) { - memoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation()); + getMemoryManager()->freeGraphicsMemory(commandStream.getGraphicsAllocation()); commandStream.replaceGraphicsAllocation(nullptr); commandStream.replaceBuffer(nullptr, 0); } if (tagAllocation) { - memoryManager->freeGraphicsMemory(tagAllocation); + getMemoryManager()->freeGraphicsMemory(tagAllocation); tagAllocation = nullptr; tagAddress = nullptr; } @@ -267,7 +258,7 @@ void CommandStreamReceiver::activateAubSubCapture(const MultiDispatchInfo &dispa GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { UNRECOVERABLE_IF(debugSurface != nullptr); - debugSurface = memoryManager->allocateGraphicsMemory(size); + debugSurface = getMemoryManager()->allocateGraphicsMemory(size); return debugSurface; } @@ -281,7 +272,7 @@ IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType heapMemory = heap->getGraphicsAllocation(); if (heap && heap->getAvailableSpace() < minRequiredSize && heapMemory) { - memoryManager->storeAllocation(std::unique_ptr(heapMemory), REUSABLE_ALLOCATION); + getMemoryManager()->storeAllocation(std::unique_ptr(heapMemory), REUSABLE_ALLOCATION); heapMemory = nullptr; } @@ -309,13 +300,13 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType, finalHeapSize = alignUp(std::max(finalHeapSize, minRequiredSize), MemoryConstants::pageSize); - auto heapMemory = memoryManager->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release(); + auto heapMemory = getMemoryManager()->obtainReusableAllocation(finalHeapSize, requireInternalHeap).release(); if (!heapMemory) { if (requireInternalHeap) { - heapMemory = memoryManager->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION); + heapMemory = getMemoryManager()->allocate32BitGraphicsMemory(finalHeapSize, nullptr, AllocationOrigin::INTERNAL_ALLOCATION); } else { - heapMemory = memoryManager->allocateGraphicsMemory(finalHeapSize); + heapMemory = getMemoryManager()->allocateGraphicsMemory(finalHeapSize); } } else { finalHeapSize = std::max(heapMemory->getUnderlyingBufferSize(), finalHeapSize); @@ -344,7 +335,7 @@ void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) { if (heap) { auto heapMemory = heap->getGraphicsAllocation(); if (heapMemory != nullptr) - memoryManager->storeAllocation(std::unique_ptr(heapMemory), REUSABLE_ALLOCATION); + getMemoryManager()->storeAllocation(std::unique_ptr(heapMemory), REUSABLE_ALLOCATION); heap->replaceBuffer(nullptr, 0); heap->replaceGraphicsAllocation(nullptr); } @@ -355,7 +346,7 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptrallocateGraphicsMemory(sizeof(uint32_t)); + auto tagAllocation = getMemoryManager()->allocateGraphicsMemory(sizeof(uint32_t)); if (!tagAllocation) { return false; } diff --git a/runtime/command_stream/command_stream_receiver.h b/runtime/command_stream/command_stream_receiver.h index 466f176d7e..6980584860 100644 --- a/runtime/command_stream/command_stream_receiver.h +++ b/runtime/command_stream/command_stream_receiver.h @@ -72,9 +72,8 @@ class CommandStreamReceiver { virtual void addPipeControl(LinearStream &commandStream, bool dcFlush) = 0; - MemoryManager *getMemoryManager(); + MemoryManager *getMemoryManager() const; virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { return nullptr; } - void setMemoryManager(MemoryManager *mm); ResidencyContainer &getResidencyAllocations(); ResidencyContainer &getEvictionAllocations(); @@ -193,8 +192,6 @@ class CommandStreamReceiver { GraphicsAllocation *scratchAllocation = nullptr; GraphicsAllocation *preemptionCsrAllocation = nullptr; GraphicsAllocation *debugSurface = nullptr; - - MemoryManager *memoryManager = nullptr; OSInterface *osInterface = nullptr; std::unique_ptr submissionAggregator; diff --git a/runtime/command_stream/command_stream_receiver_hw.inl b/runtime/command_stream/command_stream_receiver_hw.inl index 8d3adbd4ab..d3963530c8 100644 --- a/runtime/command_stream/command_stream_receiver_hw.inl +++ b/runtime/command_stream/command_stream_receiver_hw.inl @@ -38,7 +38,7 @@ CommandStreamReceiverHw::CommandStreamReceiverHw(const HardwareInfo & localMemoryEnabled(HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily).isLocalMemoryEnabled(hwInfo)) { requiredThreadArbitrationPolicy = PreambleHelper::getDefaultThreadArbitrationPolicy(); resetKmdNotifyHelper(new KmdNotifyHelper(&(hwInfoIn.capabilityTable.kmdNotifyProperties))); - flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw(this->memoryManager)); + flatBatchBufferHelper.reset(new FlatBatchBufferHelperHw(executionEnvironment)); defaultSshSize = getSshHeapSize(); } @@ -303,7 +303,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( if (is64bit && scratchAllocation && !force32BitAllocations) { newGSHbase = (uint64_t)scratchAllocation->getUnderlyingBuffer() - PreambleHelper::getScratchSpaceOffsetFor64bit(); } else if (is64bit && force32BitAllocations && dispatchFlags.GSBA32BitRequired) { - newGSHbase = memoryManager->allocator32Bit->getBase(); + newGSHbase = getMemoryManager()->allocator32Bit->getBase(); GSBAFor32BitProgrammed = true; } @@ -316,7 +316,7 @@ CompletionStamp CommandStreamReceiverHw::flushTask( ssh, newGSHbase, requiredL3Index, - memoryManager->getInternalHeapBaseAddress(), + getMemoryManager()->getInternalHeapBaseAddress(), device.getGmmHelper()); if (sshDirty) { diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.h b/runtime/command_stream/command_stream_receiver_with_aub_dump.h index db5d20b5fa..0a1e963f3e 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.h +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.h @@ -13,6 +13,7 @@ namespace OCLRT { template class CommandStreamReceiverWithAUBDump : public BaseCSR { public: + using BaseCSR::createMemoryManager; CommandStreamReceiverWithAUBDump(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment); ~CommandStreamReceiverWithAUBDump() override; @@ -24,8 +25,6 @@ class CommandStreamReceiverWithAUBDump : public BaseCSR { void activateAubSubCapture(const MultiDispatchInfo &dispatchInfo) override; - MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override; - CommandStreamReceiver *aubCSR = nullptr; }; diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl index dda9bc4a7a..0a49766bb5 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl @@ -50,13 +50,4 @@ void CommandStreamReceiverWithAUBDump::activateAubSubCapture(const Mult } } -template -MemoryManager *CommandStreamReceiverWithAUBDump::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - auto memoryManager = BaseCSR::createMemoryManager(enable64kbPages, enableLocalMemory); - if (aubCSR) { - aubCSR->setMemoryManager(memoryManager); - } - return memoryManager; -} - } // namespace OCLRT diff --git a/runtime/command_stream/experimental_command_buffer.cpp b/runtime/command_stream/experimental_command_buffer.cpp index 8ec39fa367..a0b9610eaf 100644 --- a/runtime/command_stream/experimental_command_buffer.cpp +++ b/runtime/command_stream/experimental_command_buffer.cpp @@ -37,14 +37,12 @@ ExperimentalCommandBuffer::~ExperimentalCommandBuffer() { timestamp += 2; } MemoryManager *memoryManager = commandStreamReceiver->getMemoryManager(); - if (memoryManager) { - memoryManager->freeGraphicsMemory(timestamps); - memoryManager->freeGraphicsMemory(experimentalAllocation); + memoryManager->freeGraphicsMemory(timestamps); + memoryManager->freeGraphicsMemory(experimentalAllocation); - if (currentStream.get()) { - memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation()); - currentStream->replaceGraphicsAllocation(nullptr); - } + if (currentStream.get()) { + memoryManager->freeGraphicsMemory(currentStream->getGraphicsAllocation()); + currentStream->replaceGraphicsAllocation(nullptr); } } diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index 9a91ea9daa..7e07fe68ff 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -28,7 +28,6 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw BaseClass; typedef typename OCLRT::AUBFamilyMapper::AUB AUB; typedef typename AUB::MiContextDescriptorReg MiContextDescriptorReg; - using CommandStreamReceiverHw::memoryManager; public: FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer &allocationsForResidency, OsContext &osContext) override; @@ -65,8 +64,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHwexecutionEnvironment); - return memoryManager; + return new TbxMemoryManager(enable64kbPages, enableLocalMemory, this->executionEnvironment); } TbxMemoryManager *getMemoryManager() { return (TbxMemoryManager *)CommandStreamReceiver::getMemoryManager(); diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index ac4699252b..2df9da85e8 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -54,12 +54,10 @@ bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *p } void ExecutionEnvironment::initializeMemoryManager(bool enable64KBpages, bool enableLocalMemory, uint32_t deviceIndex) { if (this->memoryManager) { - commandStreamReceivers[deviceIndex]->setMemoryManager(this->memoryManager.get()); return; } memoryManager.reset(commandStreamReceivers[deviceIndex]->createMemoryManager(enable64KBpages, enableLocalMemory)); - commandStreamReceivers[deviceIndex]->setMemoryManager(memoryManager.get()); DEBUG_BREAK_IF(!this->memoryManager); } void ExecutionEnvironment::initSourceLevelDebugger(const HardwareInfo &hwInfo) { diff --git a/runtime/helpers/flat_batch_buffer_helper.cpp b/runtime/helpers/flat_batch_buffer_helper.cpp index f1885db672..1f85b8c8a6 100644 --- a/runtime/helpers/flat_batch_buffer_helper.cpp +++ b/runtime/helpers/flat_batch_buffer_helper.cpp @@ -5,6 +5,7 @@ * */ +#include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/flat_batch_buffer_helper.h" #include "runtime/memory_manager/graphics_allocation.h" @@ -61,4 +62,8 @@ void FlatBatchBufferHelper::fixCrossThreadDataInfo(std::vector &d } } } + +MemoryManager *FlatBatchBufferHelper::getMemoryManager() const { + return executionEnvironemnt.memoryManager.get(); +} }; // namespace OCLRT \ No newline at end of file diff --git a/runtime/helpers/flat_batch_buffer_helper.h b/runtime/helpers/flat_batch_buffer_helper.h index b3a391b466..f467b4d394 100644 --- a/runtime/helpers/flat_batch_buffer_helper.h +++ b/runtime/helpers/flat_batch_buffer_helper.h @@ -16,10 +16,11 @@ namespace OCLRT { enum class DispatchMode; class MemoryManager; +class ExecutionEnvironment; class FlatBatchBufferHelper { public: - FlatBatchBufferHelper(MemoryManager *memoryManager) : memoryManager(memoryManager) {} + FlatBatchBufferHelper(ExecutionEnvironment &executionEnvironemnt) : executionEnvironemnt(executionEnvironemnt) {} virtual ~FlatBatchBufferHelper(){}; MOCKABLE_VIRTUAL bool setPatchInfoData(const PatchInfoData &data); MOCKABLE_VIRTUAL bool removePatchInfoData(uint64_t targetLocation); @@ -30,7 +31,6 @@ class FlatBatchBufferHelper { virtual GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) = 0; virtual char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) = 0; virtual void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) = 0; - void setMemoryManager(MemoryManager *memoryManager) { this->memoryManager = memoryManager; } static void fixCrossThreadDataInfo(std::vector &data, size_t offsetCrossThreadData, uint64_t gpuAddress); std::vector &getCommandChunkList() { return commandChunkList; } @@ -38,7 +38,8 @@ class FlatBatchBufferHelper { std::map &getBatchBufferStartAddressSequence() { return batchBufferStartAddressSequence; } protected: - MemoryManager *memoryManager = nullptr; + MemoryManager *getMemoryManager() const; + ExecutionEnvironment &executionEnvironemnt; std::vector patchInfoCollection; std::vector commandChunkList; diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.h b/runtime/helpers/flat_batch_buffer_helper_hw.h index 51d91df5d6..99d7cb3918 100644 --- a/runtime/helpers/flat_batch_buffer_helper_hw.h +++ b/runtime/helpers/flat_batch_buffer_helper_hw.h @@ -14,7 +14,7 @@ namespace OCLRT { template class FlatBatchBufferHelperHw : public FlatBatchBufferHelper { public: - FlatBatchBufferHelperHw(MemoryManager *memoryManager) : FlatBatchBufferHelper(memoryManager) {} + using FlatBatchBufferHelper::FlatBatchBufferHelper; GraphicsAllocation *flattenBatchBuffer(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer, DispatchMode dispatchMode) override; char *getIndirectPatchCommands(size_t &indirectPatchCommandsSize, std::vector &indirectPatchInfo) override; void removePipeControlData(size_t pipeControlLocationSize, void *pipeControlForNooping) override; diff --git a/runtime/helpers/flat_batch_buffer_helper_hw.inl b/runtime/helpers/flat_batch_buffer_helper_hw.inl index 7c94095424..1027f29e82 100644 --- a/runtime/helpers/flat_batch_buffer_helper_hw.inl +++ b/runtime/helpers/flat_batch_buffer_helper_hw.inl @@ -33,7 +33,7 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch auto flatBatchBufferSize = alignUp(sizeMainBatchBuffer + indirectPatchCommandsSize + batchBuffer.chainedBatchBuffer->getUnderlyingBufferSize(), MemoryConstants::pageSize); flatBatchBuffer = - this->memoryManager->allocateGraphicsMemory(flatBatchBufferSize, MemoryConstants::pageSize, false, false); + getMemoryManager()->allocateGraphicsMemory(flatBatchBufferSize, MemoryConstants::pageSize, false, false); UNRECOVERABLE_IF(flatBatchBuffer == nullptr); // Copy main batchbuffer memcpy_s(flatBatchBuffer->getUnderlyingBuffer(), sizeMainBatchBuffer, @@ -108,8 +108,8 @@ GraphicsAllocation *FlatBatchBufferHelperHw::flattenBatchBuffer(Batch flatBatchBufferSize = alignUp(flatBatchBufferSize, MemoryConstants::pageSize); flatBatchBufferSize += CSRequirements::csOverfetchSize; - flatBatchBuffer = this->memoryManager->allocateGraphicsMemory(static_cast(flatBatchBufferSize), - MemoryConstants::pageSize, false, false); + flatBatchBuffer = getMemoryManager()->allocateGraphicsMemory(static_cast(flatBatchBufferSize), + MemoryConstants::pageSize, false, false); UNRECOVERABLE_IF(flatBatchBuffer == nullptr); char *ptr = reinterpret_cast(flatBatchBuffer->getUnderlyingBuffer()); diff --git a/runtime/os_interface/linux/drm_command_stream.h b/runtime/os_interface/linux/drm_command_stream.h index 4f9e2b5ad6..deaca8a132 100644 --- a/runtime/os_interface/linux/drm_command_stream.h +++ b/runtime/os_interface/linux/drm_command_stream.h @@ -22,7 +22,6 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { protected: typedef DeviceCommandStreamReceiver BaseClass; using CommandStreamReceiverHw::CommandStreamReceiver::getTagAddress; - using CommandStreamReceiverHw::CommandStreamReceiver::memoryManager; using BaseClass::getScratchPatchAddress; using BaseClass::hwInfo; using BaseClass::makeNonResident; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 0ba7d789d8..f852d1dc3c 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -152,8 +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, this->executionEnvironment); - return memoryManager; + return new DrmMemoryManager(this->drm, this->gemCloseWorkerOperationMode, DebugManager.flags.EnableForcePin.get(), true, this->executionEnvironment); } template diff --git a/runtime/os_interface/windows/wddm_device_command_stream.h b/runtime/os_interface/windows/wddm_device_command_stream.h index 1e2f491803..f3248148f9 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.h +++ b/runtime/os_interface/windows/wddm_device_command_stream.h @@ -19,7 +19,6 @@ class Wddm; template class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver { typedef DeviceCommandStreamReceiver BaseClass; - using CommandStreamReceiverHw::CommandStreamReceiver::memoryManager; public: WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment); diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index c3cffe03a4..d3cb010ea9 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -150,12 +150,12 @@ void WddmCommandStreamReceiver::processEviction(OsContext &osContext) template WddmMemoryManager *WddmCommandStreamReceiver::getMemoryManager() { - return (WddmMemoryManager *)CommandStreamReceiver::getMemoryManager(); + return static_cast(CommandStreamReceiver::getMemoryManager()); } template MemoryManager *WddmCommandStreamReceiver::createMemoryManager(bool enable64kbPages, bool enableLocalMemory) { - return memoryManager = new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment); + return new WddmMemoryManager(enable64kbPages, enableLocalMemory, this->wddm, executionEnvironment); } template diff --git a/unit_tests/command_queue/command_enqueue_fixture.h b/unit_tests/command_queue/command_enqueue_fixture.h index e0d80a64b0..56a527d68e 100644 --- a/unit_tests/command_queue/command_enqueue_fixture.h +++ b/unit_tests/command_queue/command_enqueue_fixture.h @@ -63,19 +63,19 @@ struct CommandEnqueueFixture : public CommandEnqueueBaseFixture, struct NegativeFailAllocationCommandEnqueueBaseFixture : public CommandEnqueueBaseFixture { void SetUp() override { CommandEnqueueBaseFixture::SetUp(); - failMemManager.reset(new FailMemoryManager()); + failMemManager.reset(new FailMemoryManager(*pDevice->getExecutionEnvironment())); BufferDefaults::context = context; Image2dDefaults::context = context; buffer.reset(BufferHelper<>::create()); image.reset(ImageHelper::create()); ptr = static_cast(array); - oldMemManager = pDevice->getMemoryManager(); - pDevice->getCommandStreamReceiver().setMemoryManager(failMemManager.get()); + oldMemManager = pDevice->getExecutionEnvironment()->memoryManager.release(); + pDevice->injectMemoryManager(failMemManager.release()); } void TearDown() override { - pDevice->getCommandStreamReceiver().setMemoryManager(oldMemManager); + pDevice->injectMemoryManager(oldMemManager); buffer.reset(nullptr); image.reset(nullptr); BufferDefaults::context = nullptr; diff --git a/unit_tests/command_queue/drm_requirements_tests.cpp b/unit_tests/command_queue/drm_requirements_tests.cpp index ad1b75eed7..bde046afd1 100644 --- a/unit_tests/command_queue/drm_requirements_tests.cpp +++ b/unit_tests/command_queue/drm_requirements_tests.cpp @@ -132,7 +132,6 @@ HWTEST_F(DrmRequirementsTests, enqueueKernelFinish) { HWTEST_F(DrmRequirementsTests, csrNewCS) { CommandStreamReceiver *pCSR = new UltCommandStreamReceiver(*platformDevices[0], *pDevice->executionEnvironment); ASSERT_NE(nullptr, pCSR); - pCSR->setMemoryManager(pDevice->getMemoryManager()); auto memoryManager = pCSR->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); { @@ -158,7 +157,6 @@ HWTEST_F(DrmRequirementsTests, csrNewCS) { HWTEST_F(DrmRequirementsTests, csrNewCSSized) { CommandStreamReceiver *pCSR = new UltCommandStreamReceiver(*platformDevices[0], *pDevice->executionEnvironment); ASSERT_NE(nullptr, pCSR); - pCSR->setMemoryManager(pDevice->getMemoryManager()); auto memoryManager = pCSR->getMemoryManager(); ASSERT_NE(nullptr, memoryManager); { diff --git a/unit_tests/command_queue/enqueue_handler_tests.cpp b/unit_tests/command_queue/enqueue_handler_tests.cpp index 5e03398303..1e409d7566 100644 --- a/unit_tests/command_queue/enqueue_handler_tests.cpp +++ b/unit_tests/command_queue/enqueue_handler_tests.cpp @@ -219,7 +219,7 @@ HWTEST_F(EnqueueHandlerTest, enqueueWithOutputEventRegistersEvent) { HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDumpIsNotSetThenPatchInfoDataIsNotTransferredToCSR) { auto csr = new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment); - auto mockHelper = new MockFlatBatchBufferHelper(csr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); csr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(csr); @@ -241,7 +241,7 @@ HWTEST_F(EnqueueHandlerTest, givenEnqueueHandlerWhenAddPatchInfoCommentsForAUBDu DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); auto csr = new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment); - auto mockHelper = new MockFlatBatchBufferHelper(csr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); csr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(csr); 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 e88bd406b1..d2b768a6d3 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -103,7 +103,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenItIsCre std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(**platformDevices, "", true, *pDevice->executionEnvironment)); std::unique_ptr memoryManager(aubCsr->createMemoryManager(false, false)); EXPECT_NE(nullptr, memoryManager.get()); - aubCsr->setMemoryManager(nullptr); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyOperateOnSingleFileStream) { @@ -987,7 +986,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); @@ -1017,7 +1016,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); @@ -1041,7 +1040,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); memoryManager.reset(aubCsr->createMemoryManager(false, false)); - auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(memoryManager.get()); + auto flatBatchBufferHelper = new FlatBatchBufferHelperHw(*pDevice->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(flatBatchBufferHelper); auto chainedBatchBuffer = memoryManager->allocateGraphicsMemory(128u, 64u, false, false); @@ -1197,7 +1196,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefault auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); - auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -1218,7 +1217,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto allocationsForResidency = aubCsr->getResidencyAllocations(); LinearStream cs(aubExecutionEnvironment->commandBuffer); - auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); auto chainedBatchBuffer = aubExecutionEnvironment->executionEnvironment->memoryManager->allocateGraphicsMemory(128u, 64u, false, false); @@ -1252,7 +1251,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto allocationsForResidency = aubCsr->getResidencyAllocations(); LinearStream cs(aubExecutionEnvironment->commandBuffer); - auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -1271,7 +1270,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); - auto mockHelper = new MockFlatBatchBufferHelper(aubCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*aubExecutionEnvironment->executionEnvironment); aubCsr->overwriteFlatBatchBufferHelper(mockHelper); ResidencyContainer allocationsForResidency; @@ -1411,9 +1410,11 @@ class OsAgnosticMemoryManagerForImagesWithNoHostPtr : public OsAgnosticMemoryMan }; HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMemoryIsCalledOnImageWithNoHostPtrThenResourceShouldBeLockedToGetCpuAddress) { - auto memoryManager = std::make_unique(*pDevice->executionEnvironment); + auto memoryManager = new OsAgnosticMemoryManagerForImagesWithNoHostPtr(*pDevice->executionEnvironment); + std::unique_ptr oldMemoryManager(pDevice->executionEnvironment->memoryManager.release()); + pDevice->executionEnvironment->memoryManager.reset(memoryManager); + std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); - aubCsr->setMemoryManager(memoryManager.get()); cl_image_desc imgDesc = {}; imgDesc.image_width = 512; @@ -1437,6 +1438,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe queryGmm.release(); memoryManager->freeGraphicsMemory(imageAllocation); + pDevice->executionEnvironment->memoryManager.reset(oldMemoryManager.release()); } HWTEST_F(AubCommandStreamReceiverTests, givenNoDbgDeviceIdFlagWhenAubCsrIsCreatedThenUseDefaultDeviceId) { diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp index 7dce5d1c36..ed48af7bab 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_gmock_tests.cpp @@ -60,7 +60,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenCsrInBatchingModeThreeRe auto &commandStream = commandQueue.getCS(4096u); auto mockCsr = new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment); - auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); mockCsr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(mockCsr); @@ -126,7 +126,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenMockCommandStreamerWhenA auto &commandStream = commandQueue.getCS(4096u); auto mockCsr = new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment); - auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); mockCsr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(mockCsr); @@ -153,7 +153,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenMockCommandStreamerWhenA auto &commandStream = commandQueue.getCS(4096u); auto mockCsr = new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment); - auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); mockCsr->overwriteFlatBatchBufferHelper(mockHelper); pDevice->resetCommandStreamReceiver(mockCsr); @@ -205,7 +205,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskGmockTests, givenMockCsrWhenCollectStateB typedef typename FamilyType::STATE_BASE_ADDRESS STATE_BASE_ADDRESS; std::unique_ptr> mockCsr(new MockCsrHw2(*platformDevices[0], *pDevice->executionEnvironment)); - auto mockHelper = new MockFlatBatchBufferHelper(mockCsr->getMemoryManager()); + auto mockHelper = new MockFlatBatchBufferHelper(*pDevice->executionEnvironment); mockCsr->overwriteFlatBatchBufferHelper(mockHelper); std::vector patchInfoDataVector; 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 53fe5e76a2..a706fced60 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 @@ -768,7 +768,6 @@ struct CommandStreamReceiverHwLog : public UltCommandStreamReceiver HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithBothCSCallsFlushOnce) { CommandStreamReceiverHwLog commandStreamReceiver(*platformDevices[0], *pDevice->executionEnvironment); - commandStreamReceiver.setMemoryManager(pDevice->getMemoryManager()); commandStreamReceiver.initializeTagAllocation(); commandStream.getSpace(sizeof(typename FamilyType::MI_NOOP)); @@ -2595,7 +2594,6 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes 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); diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index dddb1a22f9..eb0782d8e7 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -283,7 +283,8 @@ HWTEST_F(CommandStreamReceiverTest, givenCsrWhenAllocateHeapMemoryIsCalledThenHe } TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllocationIsCalledThenNullptrIsReturned) { - MockCommandStreamReceiver csr; + ExecutionEnvironment executionEnvironment; + MockCommandStreamReceiver csr(executionEnvironment); EXPECT_EQ(nullptr, csr.getTagAllocation()); } @@ -291,16 +292,18 @@ TEST(CommandStreamReceiverSimpleTest, givenDebugVariableEnabledWhenCreatingCsrTh DebugManagerStateRestore restore; DebugManager.flags.EnableTimestampPacket.set(true); - MockCommandStreamReceiver csr1; + ExecutionEnvironment executionEnvironment; + MockCommandStreamReceiver csr1(executionEnvironment); EXPECT_TRUE(csr1.peekTimestampPacketWriteEnabled()); DebugManager.flags.EnableTimestampPacket.set(false); - MockCommandStreamReceiver csr2; + MockCommandStreamReceiver csr2(executionEnvironment); EXPECT_FALSE(csr2.peekTimestampPacketWriteEnabled()); } TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllocationIsCalledThenCorrectAllocationIsReturned) { - MockCommandStreamReceiver csr; + ExecutionEnvironment executionEnvironment; + MockCommandStreamReceiver csr(executionEnvironment); GraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); csr.setTagAllocation(&allocation); EXPECT_EQ(&allocation, csr.getTagAllocation()); @@ -318,10 +321,9 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye auto mockGraphicsAllocation = new MockGraphicsAllocation(nullptr, 1u); mockGraphicsAllocation->destructorCalled = &destructorCalled; ExecutionEnvironment executionEnvironment; - executionEnvironment.commandStreamReceivers.push_back(std::make_unique()); + executionEnvironment.commandStreamReceivers.push_back(std::make_unique(executionEnvironment)); auto csr = executionEnvironment.commandStreamReceivers[0].get(); - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, executionEnvironment)); - csr->setMemoryManager(memoryManager.get()); + executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(false, false, executionEnvironment)); csr->setTagAllocation(mockGraphicsAllocation); EXPECT_FALSE(destructorCalled); executionEnvironment.commandStreamReceivers[0].reset(nullptr); @@ -329,39 +331,36 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye } TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocated) { - 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()); + ExecutionEnvironment executionEnvironment; + auto csr = new MockCommandStreamReceiver(executionEnvironment); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(csr)); + executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(false, false, executionEnvironment)); 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); - 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()); + ExecutionEnvironment executionEnvironment; + auto csr = new MockCommandStreamReceiver(executionEnvironment); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(csr)); + executionEnvironment.memoryManager.reset(new OsAgnosticMemoryManager(false, false, executionEnvironment)); 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(), static_cast(-1)); - csr->mockExecutionEnvironment.reset(); } TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) { - MockCommandStreamReceiver csr; + ExecutionEnvironment executionEnvironment; + MockCommandStreamReceiver csr(executionEnvironment); uint32_t tag = 0; GraphicsAllocation allocation(&tag, sizeof(tag)); csr.latestFlushedTaskCount = 3; diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index 38655fb63e..84f6d9d0b8 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -106,14 +106,13 @@ struct CommandStreamReceiverWithAubDumpTest : public ::testing::TestWithParam(DEFAULT_TEST_PLATFORM::hwInfo, createAubCSR, executionEnvironment); ASSERT_NE(nullptr, csrWithAubDump); - memoryManager = csrWithAubDump->createMemoryManager(false, false); + executionEnvironment.memoryManager.reset(memoryManager); ASSERT_NE(nullptr, memoryManager); } void TearDown() override { delete csrWithAubDump; - delete memoryManager; } ExecutionEnvironment executionEnvironment; MyMockCsrWithAubDump *csrWithAubDump; diff --git a/unit_tests/command_stream/experimental_command_buffer_tests.cpp b/unit_tests/command_stream/experimental_command_buffer_tests.cpp index 40045ce63d..79789eac13 100644 --- a/unit_tests/command_stream/experimental_command_buffer_tests.cpp +++ b/unit_tests/command_stream/experimental_command_buffer_tests.cpp @@ -160,26 +160,6 @@ HWTEST_F(MockExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhe EXPECT_EQ(expectedExOffset, mockExCmdBuffer->experimentalAllocationOffset); } -HWTEST_F(MockExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhenMemoryManagerIsNotAvailableThenExperimentalBufferAllocationsRemainAllocated) { - auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - MockExperimentalCommandBuffer *mockExCmdBuffer = static_cast(commandStreamReceiver.experimentalCmdBuffer.get()); - - EXPECT_NE(nullptr, mockExCmdBuffer->experimentalAllocation); - EXPECT_NE(nullptr, mockExCmdBuffer->timestamps); - - auto experimentalAllocation = mockExCmdBuffer->experimentalAllocation; - auto timestamps = mockExCmdBuffer->timestamps; - auto memoryManager = commandStreamReceiver.getMemoryManager(); - - //null memManager - commandStreamReceiver.setMemoryManager(nullptr); - //delete experimental cmd buffer and verify its allocations remain intact - commandStreamReceiver.setExperimentalCmdBuffer(std::move(std::unique_ptr(nullptr))); - memoryManager->freeGraphicsMemory(experimentalAllocation); - memoryManager->freeGraphicsMemory(timestamps); - commandStreamReceiver.setMemoryManager(memoryManager); -} - HWTEST_F(MockExperimentalCommandBufferTest, givenEnabledExperimentalCmdBufferWhenCsrIsFlushedTwiceThenExpectProperlyFilledExperimentalCmdBufferAndTimestampOffset) { using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; using MI_BATCH_BUFFER_END = typename FamilyType::MI_BATCH_BUFFER_END; diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 14f10e1f67..ec8ed08af8 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -307,8 +307,8 @@ HWTEST_F(TbxCommandStreamTests, givenDbgDeviceIdFlagIsSetWhenTbxCsrIsCreatedThen HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenWaitBeforeMakeNonResidentWhenRequiredIsCalledWithBlockingFlagTrueThenFunctionStallsUntilMakeCoherentUpdatesTagAddress) { uint32_t tag = 0; MockTbxCsr tbxCsr(*platformDevices[0], *pDevice->executionEnvironment); - GraphicsAllocation graphicsAllocation(&tag, sizeof(tag)); - tbxCsr.setTagAllocation(&graphicsAllocation); + + tbxCsr.setTagAllocation(pDevice->getMemoryManager()->allocateGraphicsMemory(sizeof(tag), &tag)); EXPECT_FALSE(tbxCsr.makeCoherentCalled); diff --git a/unit_tests/context/context_tests.cpp b/unit_tests/context/context_tests.cpp index 209c614fe7..f19763628e 100644 --- a/unit_tests/context/context_tests.cpp +++ b/unit_tests/context/context_tests.cpp @@ -305,7 +305,7 @@ class ContextWithAsyncDeleterTest : public ::testing::WithParamInterface, memoryManager = new MockMemoryManager(); device = new MockDevice(*platformDevices[0]); deleter = new MockDeferredDeleter(); - device->setMemoryManager(memoryManager); + device->injectMemoryManager(memoryManager); memoryManager->setDeferredDeleter(deleter); } void TearDown() override { diff --git a/unit_tests/device/device_tests.cpp b/unit_tests/device/device_tests.cpp index e07d2c430e..1095dc27b5 100644 --- a/unit_tests/device/device_tests.cpp +++ b/unit_tests/device/device_tests.cpp @@ -105,7 +105,7 @@ TEST_F(DeviceTest, givenDebugVariableOverrideEngineTypeWhenDeviceIsCreatedThenUs TEST(DeviceCleanup, givenDeviceWhenItIsDestroyedThenFlushBatchedSubmissionsIsCalled) { auto mockDevice = std::unique_ptr(MockDevice::createWithNewExecutionEnvironment(nullptr)); - MockCommandStreamReceiver *csr = new MockCommandStreamReceiver; + MockCommandStreamReceiver *csr = new MockCommandStreamReceiver(*mockDevice->getExecutionEnvironment()); mockDevice->resetCommandStreamReceiver(csr); int flushedBatchedSubmissionsCalledCount = 0; csr->flushBatchedSubmissionsCallCounter = &flushedBatchedSubmissionsCalledCount; diff --git a/unit_tests/event/event_tests.cpp b/unit_tests/event/event_tests.cpp index c8720c33f7..f29d1976d6 100644 --- a/unit_tests/event/event_tests.cpp +++ b/unit_tests/event/event_tests.cpp @@ -880,7 +880,6 @@ HWTEST_F(InternalsEventTest, GivenBufferWithoutZeroCopyOnCommandMapOrUnmapFlushe CommandQueue *pCmdQ = new CommandQueue(mockContext, pDevice, props); MockNonZeroCopyBuff buffer(executionStamp); MockCsr csr(executionStamp, *pDevice->executionEnvironment); - csr.setMemoryManager(pDevice->getMemoryManager()); csr.setTagAllocation(pDevice->getTagAllocation()); MemObjSizeArray size = {{4, 1, 1}}; diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 5586222317..954e977f60 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -164,7 +164,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe AubCenterMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} }; struct CommandStreamReceiverMock : public DestructorCounted { - CommandStreamReceiverMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} + CommandStreamReceiverMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} }; struct BuiltinsMock : public DestructorCounted { BuiltinsMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} @@ -181,7 +181,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe executionEnvironment->osInterface = std::make_unique(destructorId); executionEnvironment->memoryManager = std::make_unique(destructorId); executionEnvironment->aubCenter = std::make_unique(destructorId); - executionEnvironment->commandStreamReceivers.push_back(std::make_unique(destructorId)); + executionEnvironment->commandStreamReceivers.push_back(std::make_unique(destructorId, *executionEnvironment)); executionEnvironment->builtins = std::make_unique(destructorId); executionEnvironment->compilerInterface = std::make_unique(destructorId); executionEnvironment->sourceLevelDebugger = std::make_unique(destructorId); diff --git a/unit_tests/fixtures/memory_allocator_fixture.h b/unit_tests/fixtures/memory_allocator_fixture.h index 05e4bba74e..44f586bb50 100644 --- a/unit_tests/fixtures/memory_allocator_fixture.h +++ b/unit_tests/fixtures/memory_allocator_fixture.h @@ -23,7 +23,6 @@ class MemoryAllocatorFixture : public MemoryManagementFixture { memoryManager = new OsAgnosticMemoryManager(false, false, *executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); csr = memoryManager->getCommandStreamReceiver(0); - csr->setMemoryManager(memoryManager); } void TearDown() override { diff --git a/unit_tests/fixtures/memory_manager_fixture.cpp b/unit_tests/fixtures/memory_manager_fixture.cpp index a75e97372a..37cbcde30d 100644 --- a/unit_tests/fixtures/memory_manager_fixture.cpp +++ b/unit_tests/fixtures/memory_manager_fixture.cpp @@ -16,7 +16,6 @@ void MemoryManagerWithCsrFixture::SetUp() { csr = new MockCommandStreamReceiver(this->executionEnvironment); gmockMemoryManager = new NiceMock(executionEnvironment); memoryManager = gmockMemoryManager; - csr->setMemoryManager(memoryManager); executionEnvironment.memoryManager.reset(memoryManager); ON_CALL(*gmockMemoryManager, cleanAllocationList(::testing::_, ::testing::_)).WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManager::MemoryManagerCleanAllocationList)); diff --git a/unit_tests/helpers/task_information_tests.cpp b/unit_tests/helpers/task_information_tests.cpp index 93d33a53eb..cb539d339d 100644 --- a/unit_tests/helpers/task_information_tests.cpp +++ b/unit_tests/helpers/task_information_tests.cpp @@ -20,8 +20,7 @@ using namespace OCLRT; TEST(CommandTest, mapUnmapSubmitWithoutTerminateFlagFlushesCsr) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); std::unique_ptr cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr)); - MockCommandStreamReceiver csr; - csr.setMemoryManager(device->getMemoryManager()); + MockCommandStreamReceiver csr(*device->getExecutionEnvironment()); MockBuffer buffer; auto initialTaskCount = csr.peekTaskCount(); @@ -38,8 +37,7 @@ TEST(CommandTest, mapUnmapSubmitWithoutTerminateFlagFlushesCsr) { TEST(CommandTest, mapUnmapSubmitWithTerminateFlagAbortsFlush) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); std::unique_ptr cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr)); - MockCommandStreamReceiver csr; - csr.setMemoryManager(device->getMemoryManager()); + MockCommandStreamReceiver csr(*device->getExecutionEnvironment()); MockBuffer buffer; auto initialTaskCount = csr.peekTaskCount(); @@ -59,8 +57,7 @@ TEST(CommandTest, mapUnmapSubmitWithTerminateFlagAbortsFlush) { TEST(CommandTest, markerSubmitWithoutTerminateFlagFlushesCsr) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); std::unique_ptr cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr)); - MockCommandStreamReceiver csr; - csr.setMemoryManager(device->getMemoryManager()); + MockCommandStreamReceiver csr(*device->getExecutionEnvironment()); MockBuffer buffer; auto initialTaskCount = csr.peekTaskCount(); @@ -74,7 +71,7 @@ TEST(CommandTest, markerSubmitWithoutTerminateFlagFlushesCsr) { TEST(CommandTest, markerSubmitWithTerminateFlagAbortsFlush) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); std::unique_ptr cmdQ(new MockCommandQueue(nullptr, device.get(), nullptr)); - MockCommandStreamReceiver csr; + MockCommandStreamReceiver csr(*device->getExecutionEnvironment()); MockBuffer buffer; auto initialTaskCount = csr.peekTaskCount(); diff --git a/unit_tests/kernel/kernel_image_arg_tests.cpp b/unit_tests/kernel/kernel_image_arg_tests.cpp index d85c34852d..2bc775de4b 100644 --- a/unit_tests/kernel/kernel_image_arg_tests.cpp +++ b/unit_tests/kernel/kernel_image_arg_tests.cpp @@ -190,9 +190,7 @@ HWTEST_F(KernelImageArgTest, givenImgWithMcsAllocWhenMakeResidentThenMakeMcsAllo cl_mem memObj = img; pKernel->setArg(0, sizeof(memObj), &memObj); - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *pDevice->executionEnvironment)); std::unique_ptr> csr(new MockCsr(execStamp, *pDevice->executionEnvironment)); - csr->setMemoryManager(memoryManager.get()); pKernel->makeResident(*csr.get()); EXPECT_TRUE(csr->isMadeResident(mcsAlloc)); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index d100ca9057..1f73d4f5d4 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -407,6 +407,7 @@ class CommandStreamReceiverMock : public CommandStreamReceiver { typedef CommandStreamReceiver BaseClass; public: + using BaseClass::CommandStreamReceiver; CommandStreamReceiverMock() : BaseClass(*(new ExecutionEnvironment)) { this->mockExecutionEnvironment.reset(&this->executionEnvironment); } @@ -485,9 +486,9 @@ TEST_F(KernelPrivateSurfaceTest, testPrivateSurface) { ASSERT_EQ(CL_SUCCESS, pKernel->initialize()); // Test it - std::unique_ptr memoryManager(new OsAgnosticMemoryManager(false, false, *context.getDevice(0)->getExecutionEnvironment())); - std::unique_ptr csr(new CommandStreamReceiverMock()); - csr->setMemoryManager(memoryManager.get()); + auto executionEnvironment = pDevice->getExecutionEnvironment(); + executionEnvironment->memoryManager = std::make_unique(false, false, *executionEnvironment); + std::unique_ptr csr(new CommandStreamReceiverMock(*executionEnvironment)); csr->residency.clear(); EXPECT_EQ(0u, csr->residency.size()); diff --git a/unit_tests/libult/ult_command_stream_receiver.h b/unit_tests/libult/ult_command_stream_receiver.h index 4d681998c3..bebe33d8cb 100644 --- a/unit_tests/libult/ult_command_stream_receiver.h +++ b/unit_tests/libult/ult_command_stream_receiver.h @@ -69,8 +69,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { } virtual MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override { - memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment); - return memoryManager; + return new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, executionEnvironment); } virtual GmmPageTableMngr *createPageTableManager() override { @@ -137,7 +136,6 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw { bool initProgrammingFlagsCalled = false; protected: - using BaseClass::CommandStreamReceiver::memoryManager; using BaseClass::CommandStreamReceiver::tagAddress; using BaseClass::CommandStreamReceiver::tagAllocation; diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index d328a510bd..a6ac379fe1 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -91,7 +91,6 @@ std::unique_ptr getEnvironment(bool createTagAllocation std::unique_ptr executionEnvironment(new ExecutionEnvironment); executionEnvironment->commandStreamReceivers.push_back(std::make_unique(*platformDevices[0], "", standalone, *executionEnvironment)); executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0u]->createMemoryManager(false, false)); - executionEnvironment->commandStreamReceivers[0u]->setMemoryManager(executionEnvironment->memoryManager.get()); if (createTagAllocation) { executionEnvironment->commandStreamReceivers[0u]->initializeTagAllocation(); } diff --git a/unit_tests/mocks/mock_csr.h b/unit_tests/mocks/mock_csr.h index ed18d4b7a9..aeaf22ec40 100644 --- a/unit_tests/mocks/mock_csr.h +++ b/unit_tests/mocks/mock_csr.h @@ -197,7 +197,7 @@ class MockCsrHw2 : public CommandStreamReceiverHw { template class MockFlatBatchBufferHelper : public FlatBatchBufferHelperHw { public: - MockFlatBatchBufferHelper(MemoryManager *memoryManager) : FlatBatchBufferHelperHw(memoryManager) {} + using FlatBatchBufferHelperHw::FlatBatchBufferHelperHw; MOCK_METHOD1(setPatchInfoData, bool(const PatchInfoData &)); MOCK_METHOD1(removePatchInfoData, bool(uint64_t)); MOCK_METHOD1(registerCommandChunk, bool(CommandChunk &)); @@ -215,12 +215,6 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { std::vector instructionHeapReserveredData; int *flushBatchedSubmissionsCallCounter = nullptr; - std::unique_ptr mockExecutionEnvironment; - - MockCommandStreamReceiver() : CommandStreamReceiver(*(new ExecutionEnvironment)) { - mockExecutionEnvironment.reset(&this->executionEnvironment); - } - ~MockCommandStreamReceiver() { } diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index b952d7b84a..9196a82c87 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -21,7 +21,6 @@ MockDevice::MockDevice(const HardwareInfo &hwInfo) CommandStreamReceiver *commandStreamReceiver = createCommandStream(&hwInfo, *this->executionEnvironment); executionEnvironment->commandStreamReceivers.resize(getDeviceIndex() + 1); executionEnvironment->commandStreamReceivers[getDeviceIndex()].reset(commandStreamReceiver); - commandStreamReceiver->setMemoryManager(this->mockMemoryManager.get()); this->executionEnvironment->memoryManager = std::move(this->mockMemoryManager); this->commandStreamReceiver = commandStreamReceiver; } @@ -33,15 +32,6 @@ OCLRT::MockDevice::MockDevice(const HardwareInfo &hwInfo, ExecutionEnvironment * mockWaTable = *hwInfo.pWaTable; } -void MockDevice::setMemoryManager(MemoryManager *memoryManager) { - executionEnvironment->memoryManager.reset(memoryManager); - for (auto &commandStreamReceiver : executionEnvironment->commandStreamReceivers) { - if (commandStreamReceiver) { - commandStreamReceiver->setMemoryManager(memoryManager); - } - } -} - void MockDevice::setOSTime(OSTime *osTime) { this->osTime.reset(osTime); }; @@ -55,13 +45,11 @@ bool MockDevice::hasDriverInfo() { }; void MockDevice::injectMemoryManager(MemoryManager *memoryManager) { - executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(memoryManager); - setMemoryManager(memoryManager); + executionEnvironment->memoryManager.reset(memoryManager); } void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { executionEnvironment->commandStreamReceivers[getDeviceIndex()].reset(newCsr); - executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setMemoryManager(executionEnvironment->memoryManager.get()); executionEnvironment->commandStreamReceivers[getDeviceIndex()]->initializeTagAllocation(); executionEnvironment->commandStreamReceivers[getDeviceIndex()]->setPreemptionCsrAllocation(preemptionAllocation); this->commandStreamReceiver = newCsr; @@ -69,11 +57,6 @@ void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { this->tagAddress = executionEnvironment->commandStreamReceivers[getDeviceIndex()]->getTagAddress(); } -OCLRT::FailMemoryManager::FailMemoryManager() { - agnostic = nullptr; - fail = 0; -} - OCLRT::FailMemoryManager::FailMemoryManager(int32_t fail) { allocations.reserve(fail); agnostic = new OsAgnosticMemoryManager(false, false, executionEnvironment); diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 7c88dbc78c..3ea7ea0293 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -70,7 +70,6 @@ class MockDevice : public Device { void setPerfCounters(PerformanceCounters *perfCounters) { performanceCounters = std::unique_ptr(perfCounters); } - void setMemoryManager(MemoryManager *memoryManager); template UltCommandStreamReceiver &getUltCommandStreamReceiver() { @@ -124,7 +123,7 @@ inline Device *MockDevice::createWithNewExecutionEnvironment(const Hardw class FailMemoryManager : public MockMemoryManager { public: - FailMemoryManager(); + using MockMemoryManager::MockMemoryManager; FailMemoryManager(int32_t fail); virtual ~FailMemoryManager() override { if (agnostic) { @@ -182,8 +181,8 @@ class FailMemoryManager : public MockMemoryManager { GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override { return nullptr; } - int32_t fail; - OsAgnosticMemoryManager *agnostic; + int32_t fail = 0; + OsAgnosticMemoryManager *agnostic = nullptr; std::vector allocations; }; @@ -191,7 +190,7 @@ class FailDevice : public MockDevice { public: FailDevice(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment, uint32_t deviceIndex) : MockDevice(hwInfo, executionEnvironment, deviceIndex) { - this->mockMemoryManager.reset(new FailMemoryManager); + this->mockMemoryManager.reset(new FailMemoryManager(*executionEnvironment)); } }; diff --git a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp index 43c4de4c74..9928474b3b 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp @@ -20,49 +20,38 @@ class DrmCommandStreamMMTest : public ::testing::Test { HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) { DebugManagerStateRestore dbgRestorer; - { - ExecutionEnvironment executionEnvironment; - DebugManager.flags.EnableForcePin.set(true); + DebugManager.flags.EnableForcePin.set(true); - std::unique_ptr mock(new DrmMockCustom()); - ASSERT_NE(nullptr, mock); + DrmMockCustom mock; + ExecutionEnvironment executionEnvironment; - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setDrm(&mock); - DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, - gemCloseWorkerMode::gemCloseWorkerInactive); + DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive); - auto mm = (DrmMemoryManager *)csr.createMemoryManager(false, false); - ASSERT_NE(nullptr, mm); - EXPECT_NE(nullptr, mm->getPinBB()); - csr.setMemoryManager(nullptr); - - delete mm; - } + auto memoryManager = static_cast(csr.createMemoryManager(false, false)); + executionEnvironment.memoryManager.reset(memoryManager); + ASSERT_NE(nullptr, memoryManager); + EXPECT_NE(nullptr, memoryManager->getPinBB()); } HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreatedThenPinBBIsCreated) { DebugManagerStateRestore dbgRestorer; - { - ExecutionEnvironment executionEnvironment; - DebugManager.flags.EnableForcePin.set(false); + DebugManager.flags.EnableForcePin.set(false); - std::unique_ptr mock(new DrmMockCustom()); - ASSERT_NE(nullptr, mock); + DrmMockCustom mock; + ExecutionEnvironment executionEnvironment; - executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(mock.get()); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setDrm(&mock); - DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, - gemCloseWorkerMode::gemCloseWorkerInactive); + DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive); - auto mm = (DrmMemoryManager *)csr.createMemoryManager(false, false); - csr.setMemoryManager(nullptr); - - ASSERT_NE(nullptr, mm); - EXPECT_NE(nullptr, mm->getPinBB()); - - delete mm; - } + auto memoryManager = static_cast(csr.createMemoryManager(false, false)); + executionEnvironment.memoryManager.reset(memoryManager); + ASSERT_NE(nullptr, memoryManager); + EXPECT_NE(nullptr, memoryManager->getPinBB()); } 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 015a8a26f5..2667e7e672 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -36,53 +36,48 @@ using namespace OCLRT; class DrmCommandStreamFixture { public: - DeviceCommandStreamReceiver *csr = nullptr; - DrmMemoryManager *mm = nullptr; - DrmMockImpl *mock; - const int mockFd = 33; - void SetUp() { osContext = std::make_unique(nullptr, 0u); - this->dbgState = new DebugManagerStateRestore(); //make sure this is disabled, we don't want test this now DebugManager.flags.EnableForcePin.set(false); - this->mock = new DrmMockImpl(mockFd); + mock = std::make_unique(mockFd); executionEnvironment.osInterface = std::make_unique(); - executionEnvironment.osInterface->get()->setDrm(mock); + executionEnvironment.osInterface->get()->setDrm(mock.get()); csr = new DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, gemCloseWorkerMode::gemCloseWorkerActive); ASSERT_NE(nullptr, csr); - executionEnvironment.commandStreamReceivers.resize(1); - executionEnvironment.commandStreamReceivers[0].reset(csr); + executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr(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)); - ::testing::Mock::VerifyAndClearExpectations(mock); + memoryManager = static_cast(csr->createMemoryManager(false, false)); + executionEnvironment.memoryManager.reset(memoryManager); + ::testing::Mock::VerifyAndClearExpectations(mock.get()); //assert we have memory manager - ASSERT_NE(nullptr, mm); + ASSERT_NE(nullptr, memoryManager); } void TearDown() { - mm->waitForDeletions(); - mm->peekGemCloseWorker()->close(true); + memoryManager->waitForDeletions(); + memoryManager->peekGemCloseWorker()->close(true); executionEnvironment.commandStreamReceivers.clear(); - ::testing::Mock::VerifyAndClearExpectations(mock); + ::testing::Mock::VerifyAndClearExpectations(mock.get()); // Memory manager closes pinBB with ioctl, expect one call EXPECT_CALL(*mock, ioctl(::testing::_, ::testing::_)) .Times(::testing::AtLeast(1)); - delete mm; - delete this->mock; - this->mock = 0; - delete dbgState; } + + DeviceCommandStreamReceiver *csr = nullptr; + DrmMemoryManager *memoryManager = nullptr; + std::unique_ptr mock; + const int mockFd = 33; static const uint64_t alignment = MemoryConstants::allocationAlignment; - DebugManagerStateRestore *dbgState; + DebugManagerStateRestore dbgState; ExecutionEnvironment executionEnvironment; std::unique_ptr osContext; }; diff --git a/unit_tests/os_interface/windows/driver_info_tests.cpp b/unit_tests/os_interface/windows/driver_info_tests.cpp index 99a995fed9..9372c178c0 100644 --- a/unit_tests/os_interface/windows/driver_info_tests.cpp +++ b/unit_tests/os_interface/windows/driver_info_tests.cpp @@ -39,7 +39,7 @@ class DriverInfoDeviceTest : public ::testing::Test { }; CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment) { - auto csr = new MockCommandStreamReceiver(); + auto csr = new MockCommandStreamReceiver(executionEnvironment); OSInterface *osInterface = new OSInterface(); executionEnvironment.osInterface.reset(osInterface); auto wddm = new WddmMock(); 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 78489e2c79..520d3aa341 100644 --- a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp +++ b/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp @@ -64,7 +64,7 @@ struct GlArbSyncEventTest : public ::testing::Test { void SetUp() override { executionEnvironment = new ExecutionEnvironment; - auto mockCsr = new MockCommandStreamReceiver(); + auto mockCsr = new MockCommandStreamReceiver(*executionEnvironment); executionEnvironment->commandStreamReceivers.push_back(std::unique_ptr(mockCsr)); executionEnvironment->memoryManager = std::make_unique(false, false, *executionEnvironment); device.reset(MockDevice::create(nullptr, executionEnvironment, 0u)); diff --git a/unit_tests/utilities/destructor_counted.h b/unit_tests/utilities/destructor_counted.h index 302060d735..c5ff9af447 100644 --- a/unit_tests/utilities/destructor_counted.h +++ b/unit_tests/utilities/destructor_counted.h @@ -13,8 +13,8 @@ namespace OCLRT { template struct DestructorCounted : public BaseType { template - DestructorCounted(uint32_t &destructorId, Args... args) : BaseType(args...), - destructorId(destructorId) {} + DestructorCounted(uint32_t &destructorId, Args &&... args) : BaseType(std::forward(args)...), + destructorId(destructorId) {} ~DestructorCounted() override { EXPECT_EQ(ordinal, destructorId);