diff --git a/opencl/source/command_queue/command_queue.h b/opencl/source/command_queue/command_queue.h index d9b469c5c7..5d781fbaaa 100644 --- a/opencl/source/command_queue/command_queue.h +++ b/opencl/source/command_queue/command_queue.h @@ -348,7 +348,12 @@ class CommandQueue : public BaseObject<_cl_command_queue> { void fillCsrDependenciesWithLastBcsPackets(CsrDependencies &csrDeps); void clearLastBcsPackets(); - void setStallingCommandsOnNextFlush(const bool isStallingCommandsOnNextFlushRequired) { stallingCommandsOnNextFlushRequired = isStallingCommandsOnNextFlushRequired; } + void setStallingCommandsOnNextFlush(const bool isStallingCommandsOnNextFlushRequired) { + stallingCommandsOnNextFlushRequired = isStallingCommandsOnNextFlushRequired; + if (!isStallingCommandsOnNextFlushRequired) { + dcFlushRequiredOnStallingCommandsOnNextFlush = false; + } + } bool isStallingCommandsOnNextFlushRequired() const { return stallingCommandsOnNextFlushRequired; } void setDcFlushRequiredOnStallingCommandsOnNextFlush(const bool isDcFlushRequiredOnStallingCommandsOnNextFlush) { dcFlushRequiredOnStallingCommandsOnNextFlush = isDcFlushRequiredOnStallingCommandsOnNextFlush; } diff --git a/opencl/source/command_queue/enqueue_common.h b/opencl/source/command_queue/enqueue_common.h index 1284b5e54f..d4274a1faf 100644 --- a/opencl/source/command_queue/enqueue_common.h +++ b/opencl/source/command_queue/enqueue_common.h @@ -272,11 +272,10 @@ cl_int CommandQueueHw::enqueueHandler(Surface **surfacesForResidency, } else if (computeCommandStreamReceiver.peekTimestampPacketWriteEnabled()) { if (CL_COMMAND_BARRIER == commandType && !isNonStallingIoqBarrier) { setStallingCommandsOnNextFlush(true); - if (NEO::DebugManager.flags.SkipDcFlushOnBarrierWithoutEvents.get() == 0 || event) { - setDcFlushRequiredOnStallingCommandsOnNextFlush(true); - } - this->splitBarrierRequired = true; + const bool isDcFlushRequiredOnBarrier = NEO::DebugManager.flags.SkipDcFlushOnBarrierWithoutEvents.get() == 0 || event; + setDcFlushRequiredOnStallingCommandsOnNextFlush(isDcFlushRequiredOnBarrier); } + this->splitBarrierRequired = true; for (size_t i = 0; i < eventsRequest.numEventsInWaitList; i++) { auto waitlistEvent = castToObjectOrAbort(eventsRequest.eventWaitList[i]); @@ -778,6 +777,18 @@ CompletionStamp CommandQueueHw::enqueueNonBlocked( UNRECOVERABLE_IF(multiDispatchInfo.empty()); + if (!relaxedOrderingEnabled && !getGpgpuCommandStreamReceiver().isMultiTileOperationEnabled() && isStallingCommandsOnNextFlushRequired() && !isBlitAuxTranslationRequired(multiDispatchInfo)) { + CsrDependencies csrDeps{}; + fillCsrDependenciesWithLastBcsPackets(csrDeps); + TimestampPacketHelper::programCsrDependenciesForTimestampPacketContainer(commandStream, csrDeps, false); + + setupBarrierTimestampForBcsEngines(getGpgpuCommandStreamReceiver().getOsContext().getEngineType(), timestampPacketDependencies); + getGpgpuCommandStreamReceiver().programStallingCommandsForBarrier(commandStream, ×tampPacketDependencies.barrierNodes, isDcFlushRequiredOnStallingCommandsOnNextFlush()); + + clearLastBcsPackets(); + setStallingCommandsOnNextFlush(false); + } + auto implicitFlush = false; if (printfHandler) { @@ -964,7 +975,6 @@ CompletionStamp CommandQueueHw::enqueueNonBlocked( if (isHandlingBarrier) { clearLastBcsPackets(); setStallingCommandsOnNextFlush(false); - setDcFlushRequiredOnStallingCommandsOnNextFlush(false); } if (gtpinIsGTPinInitialized()) { @@ -1185,7 +1195,6 @@ CompletionStamp CommandQueueHw::enqueueCommandWithoutKernel( if (isHandlingBarrier) { clearLastBcsPackets(); setStallingCommandsOnNextFlush(false); - setDcFlushRequiredOnStallingCommandsOnNextFlush(false); } } diff --git a/opencl/source/helpers/task_information.cpp b/opencl/source/helpers/task_information.cpp index 830ef3ade8..4a2023c6d9 100644 --- a/opencl/source/helpers/task_information.cpp +++ b/opencl/source/helpers/task_information.cpp @@ -273,7 +273,6 @@ CompletionStamp &CommandComputeKernel::submit(TaskCountType taskLevel, bool term if (isHandlingBarrier) { commandQueue.clearLastBcsPackets(); commandQueue.setStallingCommandsOnNextFlush(false); - commandQueue.setDcFlushRequiredOnStallingCommandsOnNextFlush(false); } if (kernelOperation->blitPropertiesContainer.size() > 0) { @@ -434,7 +433,6 @@ CompletionStamp &CommandWithoutKernel::submit(TaskCountType taskLevel, bool term if (isHandlingBarrier) { commandQueue.clearLastBcsPackets(); commandQueue.setStallingCommandsOnNextFlush(false); - commandQueue.setDcFlushRequiredOnStallingCommandsOnNextFlush(false); } if (kernelOperation->blitEnqueue) { diff --git a/opencl/test/unit_test/command_queue/command_queue_hw_2_tests.cpp b/opencl/test/unit_test/command_queue/command_queue_hw_2_tests.cpp index d4785bf50a..3b78b39e6c 100644 --- a/opencl/test/unit_test/command_queue/command_queue_hw_2_tests.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_hw_2_tests.cpp @@ -1186,23 +1186,20 @@ HWTEST_F(OoqCommandQueueHwBlitTest, givenBlitBeforeBarrierWhenEnqueueingCommandT EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); uint64_t lastBlitNodeAddress = TimestampPacketHelper::getContextEndGpuAddress(*pCmdQ->getTimestampPacketContainer()->peekNodes()[0]); EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueKernel(kernel, 1, &offset, &gws, nullptr, 0, nullptr, nullptr)); - auto ccsStart = pCmdQ->getGpgpuCommandStreamReceiver().getCS().getUsed(); + auto bcsStart = pCmdQ->getBcsCommandStreamReceiver(aub_stream::ENGINE_BCS)->getCS(0).getUsed(); EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueBarrierWithWaitList(0, nullptr, nullptr)); EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueKernel(kernel, 1, &offset, &gws, nullptr, 0, nullptr, nullptr)); - EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); - EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); - uint64_t barrierNodeAddress = 0u; { - HardwareParse ccsHwParser; - ccsHwParser.parseCommands(pCmdQ->getGpgpuCommandStreamReceiver().getCS(0), ccsStart); + HardwareParse queueHwParser; + queueHwParser.parseCommands(*pDevice->getUltCommandStreamReceiver().lastFlushedCommandStream, 0); - const auto semaphoreItor = find(ccsHwParser.cmdList.begin(), ccsHwParser.cmdList.end()); + const auto semaphoreItor = find(queueHwParser.cmdList.begin(), queueHwParser.cmdList.end()); const auto semaphore = genCmdCast(*semaphoreItor); EXPECT_EQ(lastBlitNodeAddress, semaphore->getSemaphoreGraphicsAddress()); - const auto pipeControlItor = find(semaphoreItor, ccsHwParser.cmdList.end()); + const auto pipeControlItor = find(semaphoreItor, queueHwParser.cmdList.end()); const auto pipeControl = genCmdCast(*pipeControlItor); EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, pipeControl->getPostSyncOperation()); barrierNodeAddress = pipeControl->getAddress() | (static_cast(pipeControl->getAddressHigh()) << 32); @@ -1211,6 +1208,9 @@ HWTEST_F(OoqCommandQueueHwBlitTest, givenBlitBeforeBarrierWhenEnqueueingCommandT EXPECT_EQ(pipeControlItor, find(std::next(semaphoreItor), pipeControlItor)); } + EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); + EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); + { HardwareParse bcsHwParser; bcsHwParser.parseCommands(pCmdQ->getBcsCommandStreamReceiver(aub_stream::ENGINE_BCS)->getCS(0), bcsStart); diff --git a/opencl/test/unit_test/command_queue/command_queue_tests_pvc_and_later.cpp b/opencl/test/unit_test/command_queue/command_queue_tests_pvc_and_later.cpp index 350f8d8068..3a67c91f55 100644 --- a/opencl/test/unit_test/command_queue/command_queue_tests_pvc_and_later.cpp +++ b/opencl/test/unit_test/command_queue/command_queue_tests_pvc_and_later.cpp @@ -820,16 +820,18 @@ HWTEST2_F(OoqCommandQueueHwBlitTest, givenBarrierBeforeFirstKernelWhenEnqueueNDR EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueReadBuffer(buffer.get(), CL_FALSE, 0, 1u, ptr, nullptr, 0, nullptr, nullptr)); - EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueBarrierWithWaitList(0, nullptr, nullptr)); auto ccsStart = pCmdQ->getGpgpuCommandStreamReceiver().getCS().getUsed(); - + EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueBarrierWithWaitList(0, nullptr, nullptr)); EXPECT_EQ(CL_SUCCESS, pCmdQ->enqueueKernel(kernel, 1, &offset, &gws, nullptr, 0, nullptr, nullptr)); + HardwareParse queueHwParser; + queueHwParser.parseCommands(*pDevice->getUltCommandStreamReceiver().lastFlushedCommandStream, 0u); + const auto memFenceItor = find(queueHwParser.cmdList.begin(), queueHwParser.cmdList.end()); + EXPECT_NE(queueHwParser.cmdList.end(), memFenceItor); + HardwareParse ccsHwParser; ccsHwParser.parseCommands(pCmdQ->getGpgpuCommandStreamReceiver().getCS(0), ccsStart); const auto memFenceStateItor = find(ccsHwParser.cmdList.begin(), ccsHwParser.cmdList.end()); - const auto memFenceItor = find(memFenceStateItor, ccsHwParser.cmdList.end()); - EXPECT_NE(ccsHwParser.cmdList.end(), memFenceItor); EXPECT_NE(ccsHwParser.cmdList.end(), memFenceStateItor); } diff --git a/opencl/test/unit_test/command_queue/enqueue_barrier_tests.cpp b/opencl/test/unit_test/command_queue/enqueue_barrier_tests.cpp index 9197fc4345..5ca412e01a 100644 --- a/opencl/test/unit_test/command_queue/enqueue_barrier_tests.cpp +++ b/opencl/test/unit_test/command_queue/enqueue_barrier_tests.cpp @@ -26,7 +26,9 @@ using BarrierTest = Test; HWTEST_F(BarrierTest, givenCsrWithHigherLevelThenCommandQueueWhenEnqueueBarrierIsCalledThenCommandQueueAlignsToCsrWithoutSendingAnyCommands) { auto pCmdQ = this->pCmdQ; auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - + if (commandStreamReceiver.peekTimestampPacketWriteEnabled()) { + GTEST_SKIP(); + } // Set task levels to known values. uint32_t originalCSRLevel = 2; commandStreamReceiver.taskLevel = originalCSRLevel; @@ -69,7 +71,9 @@ HWTEST_F(BarrierTest, GivenCsrTaskLevelGreaterThenCmdqTaskLevelWhenEnqueingBarri auto pCmdQ = this->pCmdQ; auto pCmdBuffer = this->pCmdBuffer; auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); - + if (commandStreamReceiver.peekTimestampPacketWriteEnabled()) { + GTEST_SKIP(); + } commandStreamReceiver.setMediaVFEStateDirty(false); // Set task levels to known values. @@ -202,7 +206,7 @@ HWTEST_F(BarrierTest, WhenEnqueingBarrierWithWaitListThenDependenciesShouldSync) auto pEvent = castToObject(event); auto &csr = pCmdQ->getGpgpuCommandStreamReceiver(); - // in this case only cmdQ raises the taskLevel why csr stay intact + // in this case only cmdQ raises the taskLevel while csr stays intact EXPECT_EQ(8u, pCmdQ->taskLevel); if (csr.peekTimestampPacketWriteEnabled()) { EXPECT_EQ(pCmdQ->taskLevel + 1, commandStreamReceiver.peekTaskLevel()); diff --git a/opencl/test/unit_test/command_queue/ooq_task_tests.cpp b/opencl/test/unit_test/command_queue/ooq_task_tests.cpp index 172b5192ec..bd450f20da 100644 --- a/opencl/test/unit_test/command_queue/ooq_task_tests.cpp +++ b/opencl/test/unit_test/command_queue/ooq_task_tests.cpp @@ -5,7 +5,9 @@ * */ +#include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_csr.h" #include "shared/test/common/test_macros/test_checks_shared.h" #include "shared/test/common/utilities/base_object_utils.h" @@ -368,7 +370,7 @@ HWTEST_F(OOQTaskTests, givenSkipDcFlushOnBarrierWithEventsEnabledWhenEnqueingBar outEvent->release(); } -HWTEST_F(OOQTaskTests, givenSkipDcFlushOnBarrierWithoutEventsDisableddWhenEnqueingBarrierWithWaitListThenDcFlushSet) { +HWTEST_F(OOQTaskTests, givenSkipDcFlushOnBarrierWithoutEventsDisabledWhenEnqueingBarrierWithWaitListThenDcFlushSet) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); if (false == commandStreamReceiver.peekTimestampPacketWriteEnabled()) { GTEST_SKIP(); @@ -388,7 +390,7 @@ HWTEST_F(OOQTaskTests, givenSkipDcFlushOnBarrierWithoutEventsDisableddWhenEnquei EXPECT_TRUE(pCmdQ->isDcFlushRequiredOnStallingCommandsOnNextFlush()); } -HWTEST_F(OOQTaskTests, givenEnqueueMarkerWithWaitListWhenIsMarkerWithPostSyncWriteThenBcsTimestapLastBarrierToWaitForIsNotEmpty) { +HWTEST_F(OOQTaskTests, givenEnqueueMarkerWithWaitListWhenIsMarkerWithPostSyncWriteThenBcsTimestampLastBarrierToWaitForIsNotEmpty) { auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver(); if (false == commandStreamReceiver.peekTimestampPacketWriteEnabled()) { GTEST_SKIP(); diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp index c82246b064..3e356ed0f6 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_1_tests.cpp @@ -1755,7 +1755,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, UltCommandStreamReceiverTest, givenBarrierNodeSetWhe size_t estimatedCmdSize = commandStreamReceiver->getCmdSizeForStallingCommands(dispatchFlags); EXPECT_EQ(expectedCmdSize, estimatedCmdSize); - commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags); + commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags.barrierTimestampPacketNodes, false); EXPECT_EQ(estimatedCmdSize, commandStreamCSR.getUsed()); parseCommands(commandStreamCSR, 0); diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests_xehp_and_later.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests_xehp_and_later.cpp index b62046e7e8..851f54d265 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests_xehp_and_later.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_hw_tests_xehp_and_later.cpp @@ -945,7 +945,7 @@ HWTEST2_F(CommandStreamReceiverHwTestXeHPAndLater, givenStaticPartitionEnabledWh size_t estimatedCmdSize = commandStreamReceiver->getCmdSizeForStallingCommands(dispatchFlags); EXPECT_EQ(expectedCmdSize, estimatedCmdSize); - commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags); + commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags.barrierTimestampPacketNodes, false); EXPECT_EQ(estimatedCmdSize, commandStreamCSR.getUsed()); parseCommands(commandStreamCSR, 0); @@ -992,7 +992,7 @@ HWTEST2_F(CommandStreamReceiverHwTestXeHPAndLater, givenStaticPartitionDisabledW size_t estimatedCmdSize = commandStreamReceiver->getCmdSizeForStallingCommands(dispatchFlags); EXPECT_EQ(expectedCmdSize, estimatedCmdSize); - commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags); + commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags.barrierTimestampPacketNodes, false); EXPECT_EQ(estimatedCmdSize, commandStreamCSR.getUsed()); parseCommands(commandStreamCSR, 0); @@ -1045,7 +1045,7 @@ HWTEST2_F(CommandStreamReceiverHwTestXeHPAndLater, givenStaticPartitionEnabledWh size_t estimatedCmdSize = commandStreamReceiver->getCmdSizeForStallingCommands(dispatchFlags); EXPECT_EQ(expectedSize, estimatedCmdSize); - commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags); + commandStreamReceiver->programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags.barrierTimestampPacketNodes, false); EXPECT_EQ(estimatedCmdSize, commandStreamCSR.getUsed()); EXPECT_EQ(2u, tagNode->getPacketsUsed()); diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index db47acc412..feaf6b02e3 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -591,6 +591,8 @@ class CommandStreamReceiverMock : public CommandStreamReceiver { size_t getCmdsSizeForComputeBarrierCommand() const override { return 0; } + void programStallingCommandsForBarrier(LinearStream &cmdStream, TimestampPacketContainer *barrierTimestampPacketNodes, const bool isDcFlushRequired) override { + } GraphicsAllocation *getClearColorAllocation() override { return nullptr; } bool createPreemptionAllocation() override { diff --git a/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp index 34a14ed241..6c2b137c04 100644 --- a/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_bcs_tests.cpp @@ -811,7 +811,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenPipeControlRequestWhenDispatchingBlitEnq } } -HWTEST_TEMPLATED_F(BcsBufferTests, givenBarrierWithEmptyWaitlistWhenReleasingMultipleBlockedEnqueuesThenProgramBarrierOnce) { +HWTEST_TEMPLATED_F(BcsBufferTests, givenStallingCommandsOnNextFlushWhenReleasingMultipleBlockedEnqueuesThenProgramBarrierOnce) { DebugManager.flags.OptimizeIoqBarriersHandling.set(0); using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; @@ -827,7 +827,7 @@ HWTEST_TEMPLATED_F(BcsBufferTests, givenBarrierWithEmptyWaitlistWhenReleasingMul cl_event waitlist0[] = {&userEvent0}; cl_event waitlist1[] = {&userEvent1}; - cmdQ->enqueueBarrierWithWaitList(0, nullptr, nullptr); + cmdQ->setStallingCommandsOnNextFlush(true); cmdQ->enqueueWriteBuffer(buffer.get(), false, 0, 1, hostPtr, nullptr, 1, waitlist0, nullptr); cmdQ->enqueueWriteBuffer(buffer.get(), false, 0, 1, hostPtr, nullptr, 1, waitlist1, nullptr); diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index 690fecbcf2..519507bf76 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -359,6 +359,8 @@ class CommandStreamReceiver { virtual void programComputeBarrierCommand(LinearStream &cmdStream) = 0; virtual size_t getCmdsSizeForComputeBarrierCommand() const = 0; + virtual void programStallingCommandsForBarrier(LinearStream &cmdStream, TimestampPacketContainer *barrierTimestampPacketNodes, const bool isDcFlushRequired) = 0; + const HardwareInfo &peekHwInfo() const; const RootDeviceEnvironment &peekRootDeviceEnvironment() const; diff --git a/shared/source/command_stream/command_stream_receiver_hw.h b/shared/source/command_stream/command_stream_receiver_hw.h index 3aacfcc8ed..bcc0a698b6 100644 --- a/shared/source/command_stream/command_stream_receiver_hw.h +++ b/shared/source/command_stream/command_stream_receiver_hw.h @@ -162,6 +162,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { size_t getCmdsSizeForComputeBarrierCommand() const override { return getCmdSizeForStallingNoPostSyncCommands(); } + void programStallingCommandsForBarrier(LinearStream &cmdStream, TimestampPacketContainer *barrierTimestampPacketNodes, const bool isDcFlushRequired) override; SubmissionStatus initializeDeviceWithFirstSubmission() override; HeapDirtyState &getDshState() { @@ -187,7 +188,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver { void programPerDssBackedBuffer(LinearStream &scr, Device &device, DispatchFlags &dispatchFlags); void programStateSip(LinearStream &cmdStream, Device &device); void programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags, uint32_t maxFrontEndThreads); - void programStallingCommandsForBarrier(LinearStream &cmdStream, DispatchFlags &dispatchFlags); void programStallingNoPostSyncCommandsForBarrier(LinearStream &cmdStream); void programStallingPostSyncCommandsForBarrier(LinearStream &cmdStream, TagNodeBase &tagNode, bool dcFlushRequired); void programEngineModeCommands(LinearStream &csr, const DispatchFlags &dispatchFlags); diff --git a/shared/source/command_stream/command_stream_receiver_hw_base.inl b/shared/source/command_stream/command_stream_receiver_hw_base.inl index 65ca4e4ae7..6bee42ecff 100644 --- a/shared/source/command_stream/command_stream_receiver_hw_base.inl +++ b/shared/source/command_stream/command_stream_receiver_hw_base.inl @@ -508,9 +508,9 @@ CompletionStamp CommandStreamReceiverHw::flushTask( if (dispatchFlags.isStallingCommandsOnNextFlushRequired) { if (DebugManager.flags.ProgramBarrierInCommandStreamTask.get() == 1) { - programStallingCommandsForBarrier(commandStreamTask, dispatchFlags); + programStallingCommandsForBarrier(commandStreamTask, dispatchFlags.barrierTimestampPacketNodes, dispatchFlags.isDcFlushRequiredOnStallingCommandsOnNextFlush); } else { - programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags); + programStallingCommandsForBarrier(commandStreamCSR, dispatchFlags.barrierTimestampPacketNodes, dispatchFlags.isDcFlushRequiredOnStallingCommandsOnNextFlush); } } @@ -744,12 +744,9 @@ void CommandStreamReceiverHw::programComputeMode(LinearStream &stream } template -inline void CommandStreamReceiverHw::programStallingCommandsForBarrier(LinearStream &cmdStream, DispatchFlags &dispatchFlags) { - - auto barrierTimestampPacketNodes = dispatchFlags.barrierTimestampPacketNodes; - +inline void CommandStreamReceiverHw::programStallingCommandsForBarrier(LinearStream &cmdStream, TimestampPacketContainer *barrierTimestampPacketNodes, const bool isDcFlushRequired) { if (barrierTimestampPacketNodes && barrierTimestampPacketNodes->peekNodes().size() != 0) { - programStallingPostSyncCommandsForBarrier(cmdStream, *barrierTimestampPacketNodes->peekNodes()[0], dispatchFlags.isDcFlushRequiredOnStallingCommandsOnNextFlush); + programStallingPostSyncCommandsForBarrier(cmdStream, *barrierTimestampPacketNodes->peekNodes()[0], isDcFlushRequired); barrierTimestampPacketNodes->makeResident(*this); } else { programStallingNoPostSyncCommandsForBarrier(cmdStream); diff --git a/shared/test/common/mocks/mock_command_stream_receiver.h b/shared/test/common/mocks/mock_command_stream_receiver.h index 005dc4d5df..99c6fb41ff 100644 --- a/shared/test/common/mocks/mock_command_stream_receiver.h +++ b/shared/test/common/mocks/mock_command_stream_receiver.h @@ -166,6 +166,9 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { size_t getCmdsSizeForComputeBarrierCommand() const override { return 0; } + void programStallingCommandsForBarrier(LinearStream &cmdStream, TimestampPacketContainer *barrierTimestampPacketNodes, const bool isDcFlushRequired) override { + programStallingCommandsForBarrierCalled = true; + } bool createPreemptionAllocation() override { if (createPreemptionAllocationParentCall) { @@ -214,6 +217,7 @@ class MockCommandStreamReceiver : public CommandStreamReceiver { bool createPreemptionAllocationReturn = true; bool createPreemptionAllocationParentCall = false; bool programComputeBarrierCommandCalled = false; + bool programStallingCommandsForBarrierCalled = false; std::optional isGpuHangDetectedReturnValue{}; std::optional testTaskCountReadyReturnValue{}; WaitStatus waitForCompletionWithTimeoutReturnValue{WaitStatus::Ready}; diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_simulated_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_simulated_tests.cpp index d1f6a21c71..ad0b55995e 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_simulated_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_simulated_tests.cpp @@ -9,11 +9,14 @@ #include "shared/source/command_stream/command_stream_receiver_simulated_hw.h" #include "shared/source/helpers/array_count.h" #include "shared/source/helpers/hardware_context_controller.h" +#include "shared/source/helpers/timestamp_packet.h" #include "shared/source/memory_manager/memory_pool.h" #include "shared/source/os_interface/os_context.h" +#include "shared/test/common/cmd_parse/hw_parse.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/helpers/gfx_core_helper_tests.h" +#include "shared/test/common/helpers/unit_test_helper.h" #include "shared/test/common/mocks/mock_aub_manager.h" #include "shared/test/common/mocks/mock_gmm.h" #include "shared/test/common/mocks/mock_graphics_allocation.h" @@ -595,3 +598,98 @@ HWTEST_F(CommandStreamSimulatedTests, givenSpecificMemoryPoolAllocationWhenWrite } } } + +HWTEST_F(CommandStreamSimulatedTests, givenBarrierNodesWhenProgramStallingCommandsForBarrierCalledThenPostSyncWritePipeControlIsProgrammed) { + using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; + auto csr = std::make_unique>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); + MockOsContext osContext(0, EngineDescriptorHelper::getDefaultDescriptor()); + csr->setupContext(osContext); + + TagAllocatorBase *allocator = pDevice->getGpgpuCommandStreamReceiver().getTimestampPacketAllocator(); + auto barrierNode = allocator->getTag(); + const auto barrierNodeAddress = TimestampPacketHelper::getContextEndGpuAddress(*barrierNode); + TimestampPacketContainer barrierNodes{}; + barrierNodes.add(barrierNode); + + { + MockGraphicsAllocation streamAllocation{}; + uint32_t streamBuffer[100] = {}; + LinearStream linearStream(&streamAllocation, streamBuffer, sizeof(streamBuffer)); + + csr->programStallingCommandsForBarrier(linearStream, &barrierNodes, false); + + HardwareParse hwParser; + hwParser.parseCommands(linearStream); + auto pipeControlItor = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + auto pipeControl = genCmdCast(*pipeControlItor); + if (UnitTestHelper::isPipeControlWArequired(hardwareInfo)) { + auto nextPipeControlItor = find(++pipeControlItor, hwParser.cmdList.end()); + pipeControl = genCmdCast(*nextPipeControlItor); + } + ASSERT_NE(nullptr, pipeControl); + EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, pipeControl->getPostSyncOperation()); + EXPECT_FALSE(pipeControl->getDcFlushEnable()); + EXPECT_EQ(barrierNodeAddress, UnitTestHelper::getPipeControlPostSyncAddress(*pipeControl)); + } + { + MockGraphicsAllocation streamAllocation{}; + uint32_t streamBuffer[100] = {}; + LinearStream linearStream(&streamAllocation, streamBuffer, sizeof(streamBuffer)); + + csr->programStallingCommandsForBarrier(linearStream, &barrierNodes, true); + + HardwareParse hwParser; + hwParser.parseCommands(linearStream); + auto pipeControlItor = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + auto pipeControl = genCmdCast(*pipeControlItor); + if (UnitTestHelper::isPipeControlWArequired(hardwareInfo)) { + auto nextPipeControlItor = find(++pipeControlItor, hwParser.cmdList.end()); + pipeControl = genCmdCast(*nextPipeControlItor); + } + ASSERT_NE(nullptr, pipeControl); + EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, pipeControl->getPostSyncOperation()); + EXPECT_EQ(csr->getDcFlushSupport(), pipeControl->getDcFlushEnable()); + EXPECT_EQ(barrierNodeAddress, UnitTestHelper::getPipeControlPostSyncAddress(*pipeControl)); + } +} + +HWTEST_F(CommandStreamSimulatedTests, givenEmptyBarrierNodesWhenProgramStallingCommandsForBarrierCalledThenNoWritePipeControlIsProgrammed) { + using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; + auto csr = std::make_unique>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield()); + MockOsContext osContext(0, EngineDescriptorHelper::getDefaultDescriptor()); + csr->setupContext(osContext); + + { + TimestampPacketContainer barrierNodes{}; + + MockGraphicsAllocation streamAllocation{}; + uint32_t streamBuffer[100] = {}; + LinearStream linearStream(&streamAllocation, streamBuffer, sizeof(streamBuffer)); + + csr->programStallingCommandsForBarrier(linearStream, &barrierNodes, false); + + HardwareParse hwParser; + hwParser.parseCommands(linearStream); + const auto pipeControlItor = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + const auto pipeControl = genCmdCast(*pipeControlItor); + ASSERT_NE(nullptr, pipeControl); + EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_NO_WRITE, pipeControl->getPostSyncOperation()); + EXPECT_EQ(0u, UnitTestHelper::getPipeControlPostSyncAddress(*pipeControl)); + } + + { + MockGraphicsAllocation streamAllocation{}; + uint32_t streamBuffer[100] = {}; + LinearStream linearStream(&streamAllocation, streamBuffer, sizeof(streamBuffer)); + + csr->programStallingCommandsForBarrier(linearStream, nullptr, false); + + HardwareParse hwParser; + hwParser.parseCommands(linearStream); + const auto pipeControlItor = find(hwParser.cmdList.begin(), hwParser.cmdList.end()); + const auto pipeControl = genCmdCast(*pipeControlItor); + ASSERT_NE(nullptr, pipeControl); + EXPECT_EQ(PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_NO_WRITE, pipeControl->getPostSyncOperation()); + EXPECT_EQ(0u, UnitTestHelper::getPipeControlPostSyncAddress(*pipeControl)); + } +} \ No newline at end of file