From 1807ea651c1bd23212cbda69576bbfea7c3730a3 Mon Sep 17 00:00:00 2001 From: "Mrozek, Michal" Date: Tue, 31 Jul 2018 14:27:26 +0200 Subject: [PATCH] Initialize tag value in init function. - remove not needed method in mock device. - remove duplication from aub tests. - tag allocation now have desired value Change-Id: Ib3161cce6753eae27c60fddb63054fd2e12f7dac --- Jenkinsfile | 2 +- .../command_stream_receiver.cpp | 2 + runtime/device/device.cpp | 3 - runtime/mem_obj/mem_obj.cpp | 4 +- .../aub_command_stream_receiver_tests.cpp | 208 ++++++------------ ...mmand_stream_receiver_flush_task_tests.cpp | 4 +- .../command_stream_receiver_tests.cpp | 16 ++ unit_tests/helpers/kmd_notify_tests.cpp | 6 +- unit_tests/mem_obj/mem_obj_tests.cpp | 4 +- unit_tests/mocks/mock_device.cpp | 4 +- unit_tests/mocks/mock_device.h | 5 - 11 files changed, 99 insertions(+), 159 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 084be6726f..be4b4cfed4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,4 @@ #!groovy neoDependenciesRev='787198-1060' strategy='EQUAL' -allowedCD=295 +allowedCD=294 diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 4c31c5968a..5920aa811a 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -358,6 +358,8 @@ bool CommandStreamReceiver::initializeTagAllocation() { } this->setTagAllocation(tagAllocation); + *this->tagAddress = DebugManager.flags.EnableNullHardware.get() ? -1 : initialHardwareTag; + return true; } diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index d52cfd825c..a786197e9f 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -145,9 +145,6 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { pDevice->driverInfo.reset(DriverInfo::create(commandStreamReceiver->getOSInterface())); pDevice->tagAddress = reinterpret_cast(commandStreamReceiver->getTagAllocation()->getUnderlyingBuffer()); - // Initialize HW tag to a known value - *pDevice->tagAddress = DebugManager.flags.EnableNullHardware.get() ? -1 : initialHardwareTag; - pDevice->initializeCaps(); if (pDevice->osTime->getOSInterface()) { diff --git a/runtime/mem_obj/mem_obj.cpp b/runtime/mem_obj/mem_obj.cpp index c18ad93c80..2bafc4ff71 100644 --- a/runtime/mem_obj/mem_obj.cpp +++ b/runtime/mem_obj/mem_obj.cpp @@ -308,8 +308,8 @@ void MemObj::waitForCsrCompletion() { } void MemObj::destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy) { - if (asyncDestroy && memoryManager->device && allocation->taskCount != ObjectNotUsed) { - auto currentTag = *memoryManager->device->getTagAddress(); + if (asyncDestroy && memoryManager->csr && allocation->taskCount != ObjectNotUsed) { + auto currentTag = *memoryManager->csr->getTagAddress(); if (currentTag < allocation->taskCount) { memoryManager->storeAllocation(std::unique_ptr(allocation), TEMPORARY_ALLOCATION); return; 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 04ba0a69a6..3faa74e118 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -134,9 +134,9 @@ struct AubExecutionEnvironment { }; template -std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer) { +std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) { std::unique_ptr executionEnvironment(new ExecutionEnvironment); - executionEnvironment->commandStreamReceiver.reset(new CsrType(*platformDevices[0], "", true)); + executionEnvironment->commandStreamReceiver.reset(new CsrType(*platformDevices[0], "", standalone)); executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceiver->createMemoryManager(false)); executionEnvironment->commandStreamReceiver->setMemoryManager(executionEnvironment->memoryManager.get()); if (createTagAllocation) { @@ -296,7 +296,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentC } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldInitializeEngineInfoTable) { - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -311,7 +311,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldntInitializeEngineInfoTable) { - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -332,7 +332,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldLeaveProperRingTailAlignment) { - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -353,20 +353,14 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStandaloneModeWhenFlushIsCalledThenItShouldNotUpdateHwTagWithLatestSentTaskCount) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", false)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - - auto commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); + auto aubExecutionEnvironment = getEnvironment>(true, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); aubCsr->setLatestSentTaskCount(aubCsr->peekTaskCount() + 1); @@ -377,25 +371,17 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldUpdateHwTagWithLatestSentTaskCount) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - - auto commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); aubCsr->setLatestSentTaskCount(aubCsr->peekTaskCount() + 1); @@ -405,15 +391,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); EXPECT_EQ(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneAndSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldUpdateHwTagWithLatestSentTaskCount) { DebugManagerStateRestore stateRestore; - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); auto aubSubCaptureManagerMock = new AubSubCaptureManagerMock(""); aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle; @@ -421,18 +405,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - auto commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); - EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); - aubCsr->setLatestSentTaskCount(aubCsr->peekTaskCount() + 1); EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); @@ -440,15 +416,13 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); EXPECT_EQ(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStandaloneAndSubCaptureModeWhenFlushIsCalledButSubCaptureIsDisabledThenItShouldNotUpdateHwTagWithLatestSentTaskCount) { DebugManagerStateRestore stateRestore; - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", false)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + auto aubExecutionEnvironment = getEnvironment>(true, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); auto aubSubCaptureManagerMock = new AubSubCaptureManagerMock(""); aubSubCaptureManagerMock->subCaptureMode = AubSubCaptureManager::SubCaptureMode::Toggle; @@ -456,18 +430,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - auto commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); - EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); - aubCsr->setLatestSentTaskCount(aubCsr->peekTaskCount() + 1); EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); @@ -476,15 +442,14 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNonStanda EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenFlushIsCalledAndSubCaptureIsEnabledThenItShouldDeactivateSubCapture) { DebugManagerStateRestore stateRestore; - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", false)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + + auto aubExecutionEnvironment = getEnvironment>(true, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); const DispatchInfo dispatchInfo; auto aubSubCaptureManagerMock = new AubSubCaptureManagerMock(""); @@ -494,10 +459,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - auto commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {}; @@ -505,20 +466,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); EXPECT_FALSE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldCallMakeResidentOnCommandBufferAllocation) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); - - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; @@ -535,47 +488,33 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->makeSurfacePackNonResident(nullptr, false); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - - memoryManager->freeGraphicsMemory(commandBuffer); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStandaloneModeWhenFlushIsCalledThenItShouldNotCallMakeResidentOnCommandBufferAllocation) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", false)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); + auto aubExecutionEnvironment = getEnvironment>(false, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; - EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); + EXPECT_EQ(ObjectNotResident, aubExecutionEnvironment->commandBuffer->residencyTaskCount); aubCsr->flush(batchBuffer, engineType, nullptr); - EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - - memoryManager->freeGraphicsMemory(commandBuffer); - aubCsr->setMemoryManager(nullptr); + EXPECT_EQ(ObjectNotResident, aubExecutionEnvironment->commandBuffer->residencyTaskCount); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldCallMakeResidentOnResidencyAllocations) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); + auto commandBuffer = aubExecutionEnvironment->commandBuffer; + LinearStream cs(commandBuffer); auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, gfxAllocation); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {gfxAllocation}; @@ -597,20 +536,18 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - memoryManager->freeGraphicsMemory(commandBuffer); memoryManager->freeGraphicsMemory(gfxAllocation); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStandaloneModeWhenFlushIsCalledThenItShouldNotCallMakeResidentOnResidencyAllocations) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", false)); - memoryManager.reset(aubCsr->createMemoryManager(false)); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); - - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); + auto aubExecutionEnvironment = getEnvironment>(true, true, false); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); + auto commandBuffer = aubExecutionEnvironment->commandBuffer; LinearStream cs(commandBuffer); + auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {gfxAllocation}; @@ -623,15 +560,16 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStand EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - memoryManager->freeGraphicsMemoryImpl(commandBuffer); memoryManager->freeGraphicsMemoryImpl(gfxAllocation); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneAndSubCaptureModeWhenFlushIsCalledAndSubCaptureIsEnabledThenItShouldCallMakeResidentOnCommandBufferAndResidencyAllocations) { DebugManagerStateRestore stateRestore; - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); + auto commandBuffer = aubExecutionEnvironment->commandBuffer; + LinearStream cs(commandBuffer); const DispatchInfo dispatchInfo; auto aubSubCaptureManagerMock = new AubSubCaptureManagerMock(""); @@ -641,16 +579,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon aubCsr->subCaptureManager.reset(aubSubCaptureManagerMock); ASSERT_TRUE(aubCsr->subCaptureManager->isSubCaptureEnabled()); - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); - ASSERT_NE(nullptr, aubCsr->getTagAllocation()); - auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); ASSERT_NE(nullptr, gfxAllocation); - GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096); - ASSERT_NE(nullptr, commandBuffer); - LinearStream cs(commandBuffer); - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency = {gfxAllocation}; @@ -672,14 +603,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandalon EXPECT_EQ(ObjectNotResident, gfxAllocation->residencyTaskCount); EXPECT_EQ(ObjectNotResident, commandBuffer->residencyTaskCount); - memoryManager->freeGraphicsMemory(commandBuffer); memoryManager->freeGraphicsMemory(gfxAllocation); } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphicsAllocationIsCreatedThenItDoesntHaveTypeNonAubWritable) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + auto aubExecutionEnvironment = getEnvironment>(false, false, true); + auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); auto gfxAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); @@ -689,9 +618,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGraphic } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcessResidencyIsCalledOnDefaultAllocationThenAllocationTypeShouldNotBeMadeNonAubWritable) { - std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true)); - memoryManager.reset(aubCsr->createMemoryManager(false)); + auto aubExecutionEnvironment = getEnvironment>(false, false, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); auto gfxDefaultAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t), sizeof(uint32_t), false, false); @@ -1164,7 +1093,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenRegisterCommandChunkIsCalledThenNewChunkIsAddedToTheList) { typedef typename FamilyType::MI_BATCH_BUFFER_START MI_BATCH_BUFFER_START; - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1183,7 +1112,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenRegiste } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenRemovePatchInfoDataIsCalledThenElementIsRemovedFromPatchInfoList) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); PatchInfoData patchInfoData(0xA000, 0x0, PatchInfoAllocationType::KernelArg, 0xB000, 0x0, PatchInfoAllocationType::Default); @@ -1201,7 +1130,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddGucS DebugManagerStateRestore dbgRestore; DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); - auto aubExecutionEnvironment = getEnvironment>(false, false); + auto aubExecutionEnvironment = getEnvironment>(false, false, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1220,7 +1149,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); auto memoryManager = aubExecutionEnvironment->executionEnvironment->memoryManager.get(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1285,7 +1214,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefaultDebugConfigThenExpectFlattenBatchBufferIsNotCalled) { - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1305,7 +1234,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1333,7 +1262,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1352,7 +1281,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::BatchedDispatch)); - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1371,7 +1300,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc DebugManagerStateRestore dbgRestore; DebugManager.flags.AddPatchInfoCommentsForAUBDump.set(true); - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1384,21 +1313,20 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatchInfoCommentsForAUBDumpIsNotSetThenAddPatchInfoCommentsIsNotCalled) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; auto engineType = OCLRT::ENGINE_RCS; ResidencyContainer allocationsForResidency; - aubCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); EXPECT_CALL(*aubCsr, addPatchInfoComments()).Times(0); aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPatchInfoDataObjectsThenCommentsAreEmpty) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1427,7 +1355,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPat } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) { - auto aubExecutionEnvironment = getEnvironment>(true, true); + auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1447,7 +1375,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenFirstAddCommentsFailsThenFunctionReturnsFalse) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1466,7 +1394,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenFirst } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSecondAddCommentsFailsThenFunctionReturnsFalse) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1485,7 +1413,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSecon } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatchInfoDataObjectsAddedThenCommentsAreNotEmpty) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1559,7 +1487,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatch } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourceAllocationIsNullThenDoNotAddToAllocationsList) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1615,7 +1543,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourc } HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTargetAllocationIsNullThenDoNotAddToAllocationsList) { - auto aubExecutionEnvironment = getEnvironment>(false, true); + auto aubExecutionEnvironment = getEnvironment>(false, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); LinearStream cs(aubExecutionEnvironment->commandBuffer); @@ -1671,7 +1599,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTarge } HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForEmptyPatchInfoListThenIndirectPatchCommandBufferIsNotCreated) { - auto aubExecutionEnvironment = getEnvironment>(false, false); + auto aubExecutionEnvironment = getEnvironment>(false, false, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); size_t indirectPatchCommandsSize = 0u; 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 9505bacf36..3d95058d75 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 @@ -775,7 +775,7 @@ struct CommandStreamReceiverHwLog : public UltCommandStreamReceiver HWTEST_F(CommandStreamReceiverFlushTaskTests, flushTaskWithBothCSCallsFlushOnce) { CommandStreamReceiverHwLog commandStreamReceiver(*platformDevices[0]); commandStreamReceiver.setMemoryManager(pDevice->getMemoryManager()); - commandStreamReceiver.setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); + commandStreamReceiver.initializeTagAllocation(); commandStream.getSpace(sizeof(typename FamilyType::MI_NOOP)); flushTask(commandStreamReceiver); @@ -2602,7 +2602,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenTotalRes mockedMemoryManager->device = pDevice; mockCsr->setMemoryManager(mockedMemoryManager.get()); - mockCsr->setTagAllocation(pDevice->disconnectCurrentTagAllocationAndReturnIt()); + 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 4583f62b68..fef8548ea1 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -29,6 +29,7 @@ #include "runtime/memory_manager/memory_manager.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/mocks/mock_buffer.h" #include "unit_tests/mocks/mock_builtins.h" #include "unit_tests/mocks/mock_context.h" @@ -338,6 +339,21 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTa csr->initializeTagAllocation(); EXPECT_NE(nullptr, csr->getTagAllocation()); EXPECT_TRUE(csr->getTagAddress() != nullptr); + EXPECT_EQ(*csr->getTagAddress(), initialHardwareTag); +} + +TEST(CommandStreamReceiverSimpleTest, givenNullHardwareDebugModeWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocatedAndinitialValueIsMinusOne) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.EnableNullHardware.set(true); + std::unique_ptr memoryManager(new OsAgnosticMemoryManager); + std::unique_ptr csr(new MockCommandStreamReceiver); + csr->setMemoryManager(memoryManager.get()); + EXPECT_EQ(nullptr, csr->getTagAllocation()); + EXPECT_TRUE(csr->getTagAddress() == nullptr); + csr->initializeTagAllocation(); + EXPECT_NE(nullptr, csr->getTagAllocation()); + EXPECT_TRUE(csr->getTagAddress() != nullptr); + EXPECT_EQ(*csr->getTagAddress(), static_cast(-1)); } TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) { diff --git a/unit_tests/helpers/kmd_notify_tests.cpp b/unit_tests/helpers/kmd_notify_tests.cpp index 7dfa832cef..aa4f51c704 100644 --- a/unit_tests/helpers/kmd_notify_tests.cpp +++ b/unit_tests/helpers/kmd_notify_tests.cpp @@ -127,7 +127,7 @@ HWTEST_F(KmdNotifyTests, givenTaskCountAndKmdNotifyDisabledWhenWaitUntilCompleti HWTEST_F(KmdNotifyTests, givenNotReadyTaskCountWhenWaitUntilCompletionCalledThenTryCpuPollingAndKmdWait) { auto csr = createMockCsr(); - *device->getTagAddress() = taskCountToWait - 1; + *csr->getTagAddress() = taskCountToWait - 1; ::testing::InSequence is; EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(false)); @@ -227,7 +227,7 @@ HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIs HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultiplyTimeout) { auto csr = createMockCsr(); - *device->getTagAddress() = taskCountToWait; + *csr->getTagAddress() = taskCountToWait; auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; @@ -238,7 +238,7 @@ HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultipl HWTEST_F(KmdNotifyTests, givenTaskCountLowerThanHwTagWhenWaitCalledThenDontMultiplyTimeout) { auto csr = createMockCsr(); - *device->getTagAddress() = taskCountToWait + 5; + *csr->getTagAddress() = taskCountToWait + 5; auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index 8aff1b1588..c374d354a1 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/command_stream/command_stream_receiver.h" #include "runtime/mem_obj/mem_obj.h" #include "runtime/device/device.h" #include "runtime/gmm_helper/gmm.h" @@ -177,7 +178,8 @@ TEST(MemObj, givenNotReadyGraphicsAllocationWhenMemObjDestroysAllocationAsyncThe auto allocation = memoryManager.allocateGraphicsMemory(MemoryConstants::pageSize); allocation->taskCount = 2; - *memoryManager.device->getTagAddress() = 1; + memoryManager.csr = &context.getDevice(0)->getCommandStreamReceiver(); + *(memoryManager.csr->getTagAddress()) = 1; MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, MemoryConstants::pageSize, nullptr, nullptr, nullptr, true, false, false); diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 703da08068..071f6a88ff 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -72,12 +72,12 @@ void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { } void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { - auto tagAllocation = this->disconnectCurrentTagAllocationAndReturnIt(); executionEnvironment->commandStreamReceiver.reset(newCsr); executionEnvironment->commandStreamReceiver->setMemoryManager(executionEnvironment->memoryManager.get()); - executionEnvironment->commandStreamReceiver->setTagAllocation(tagAllocation); + executionEnvironment->commandStreamReceiver->initializeTagAllocation(); executionEnvironment->commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); executionEnvironment->memoryManager->csr = executionEnvironment->commandStreamReceiver.get(); + this->tagAddress = executionEnvironment->commandStreamReceiver->getTagAddress(); } OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() { diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 33b764bd4a..d6447d7c43 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -96,11 +96,6 @@ class MockDevice : public Device { void resetCommandStreamReceiver(CommandStreamReceiver *newCsr); GraphicsAllocation *getTagAllocation() { return this->getCommandStreamReceiver().getTagAllocation(); } - GraphicsAllocation *disconnectCurrentTagAllocationAndReturnIt() { - auto currentTagAllocation = getTagAllocation(); - this->getCommandStreamReceiver().setTagAllocation(nullptr); - return currentTagAllocation; - } void setSourceLevelDebuggerActive(bool active) { this->deviceInfo.sourceLevelDebuggerActive = active;