diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 9edc183921..4666d4295a 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -378,6 +378,7 @@ FlushStamp AUBCommandStreamReceiverHw::flush(BatchBuffer &batchBuffer if (this->standalone) { pollForCompletion(engineType); + *this->tagAddress = this->peekLatestSentTaskCount(); } return 0; } diff --git a/runtime/command_stream/create_command_stream_impl.cpp b/runtime/command_stream/create_command_stream_impl.cpp index 50e0f320fa..4d5f93a04a 100644 --- a/runtime/command_stream/create_command_stream_impl.cpp +++ b/runtime/command_stream/create_command_stream_impl.cpp @@ -46,7 +46,6 @@ CommandStreamReceiver *createCommandStreamImpl(const HardwareInfo *pHwInfo) { pHwInfo->pWaTable, pHwInfo->pSysInfo); commandStreamReceiver = AUBCommandStreamReceiver::create(*pHwInfo, "aubfile", true); - initialHardwareTag = -1; break; case CSR_TBX: Gmm::initContext(pHwInfo->pPlatform, 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 37cd2418d5..916c82ebe1 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -55,6 +55,14 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { return this->dispatchMode; } + GraphicsAllocation *getTagAllocation() const { + return this->tagAllocation; + } + + void setLatestSentTaskCount(uint32_t latestSentTaskCount) { + this->latestSentTaskCount = latestSentTaskCount; + } + MOCK_METHOD2(flattenBatchBuffer, void *(BatchBuffer &batchBuffer, size_t &sizeBatchBuffer)); }; @@ -125,9 +133,12 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentC HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldLeaveProperRingTailAlignment) { std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -150,11 +161,42 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIs 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, 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->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + EXPECT_EQ(initialHardwareTag, *aubCsr->getTagAddress()); + + aubCsr->setLatestSentTaskCount(aubCsr->peekTaskCount() + 1); + + EXPECT_NE(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); + + aubCsr->flush(batchBuffer, engineType, &allocationsForResidency); + + EXPECT_EQ(aubCsr->peekLatestSentTaskCount(), *aubCsr->getTagAddress()); + + memoryManager->freeGraphicsMemory(commandBuffer); +} + HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldCallMakeResidentOnCommandBufferAllocation) { std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -201,10 +243,14 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInNoneStand HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInStandaloneModeWhenFlushIsCalledThenItShouldCallMakeResidentOnResidencyAllocations) { std::unique_ptr memoryManager(nullptr); - std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], true)); + std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + 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, 4096); ASSERT_NE(nullptr, commandBuffer); @@ -387,11 +433,14 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedB memoryManager->freeGraphicsMemory(commandBuffer); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefaultDebugConfigThenExpectxpectFlattenBatchBufferIsNotCalled) { +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDefaultDebugConfigThenExpectFlattenBatchBufferIsNotCalled) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -415,6 +464,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -436,7 +488,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF memoryManager->freeGraphicsMemory(chainedBatchBuffer); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndImmediateDispatchModeAndTheresNoChainedBatchBufferThenExpectFlattenBatchBufferIsCalledAnyway) { +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedFlattenBatchBufferAndImmediateDispatchModeAndThereIsNoChainedBatchBufferThenExpectFlattenBatchBufferIsCalledAnyway) { DebugManagerStateRestore dbgRestore; DebugManager.flags.FlattenBatchBufferForAUBDump.set(true); DebugManager.flags.CsrDispatchMode.set(CommandStreamReceiver::DispatchMode::ImmediateDispatch); @@ -445,6 +497,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenForcedF std::unique_ptr> aubCsr(new MockAubCsr(*platformDevices[0], true)); memoryManager.reset(aubCsr->createMemoryManager(false)); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer); @@ -467,6 +522,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenDispatc memoryManager.reset(aubCsr->createMemoryManager(false)); aubCsr->overrideDispatchPolicy(CommandStreamReceiver::DispatchMode::BatchedDispatch); + aubCsr->setTagAllocation(pDevice->getTagAllocation()); + ASSERT_NE(nullptr, aubCsr->getTagAllocation()); + GraphicsAllocation *commandBuffer = memoryManager->allocateGraphicsMemory(4096, 4096); ASSERT_NE(nullptr, commandBuffer); LinearStream cs(commandBuffer);