From 38ace23f722b6a8a62259cea6a5793ca37dcc658 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Mon, 20 Dec 2021 14:32:06 +0000 Subject: [PATCH] When terminate task do not pass timestamps Signed-off-by: Lukasz Jobczyk --- opencl/source/helpers/task_information.cpp | 25 +++++++- opencl/source/helpers/task_information.h | 1 + .../command_queue/blit_enqueue_tests.cpp | 63 +++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/opencl/source/helpers/task_information.cpp b/opencl/source/helpers/task_information.cpp index 048d630e31..69fd2b27f1 100644 --- a/opencl/source/helpers/task_information.cpp +++ b/opencl/source/helpers/task_information.cpp @@ -40,6 +40,7 @@ CommandMapUnmap::CommandMapUnmap(MapOperationType operationType, MemObj &memObj, CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) { if (terminated) { + this->terminated = true; memObj.decRefInternal(); return completionStamp; } @@ -131,6 +132,7 @@ CommandComputeKernel::~CommandComputeKernel() { CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminated) { if (terminated) { + this->terminated = true; for (auto surface : surfaces) { delete surface; } @@ -348,6 +350,7 @@ void CommandWithoutKernel::dispatchBlitOperation() { CompletionStamp &CommandWithoutKernel::submit(uint32_t taskLevel, bool terminated) { if (terminated) { + this->terminated = true; return completionStamp; } @@ -472,8 +475,26 @@ void Command::setTimestampPacketNode(TimestampPacketContainer ¤t, Timestam } Command::~Command() { - if (commandQueue.getDeferredTimestampPackets() && timestampPacketDependencies.get()) { - timestampPacketDependencies->moveNodesToNewContainer(*commandQueue.getDeferredTimestampPackets()); + if (terminated) { + if (commandQueue.getTimestampPacketContainer()) { + std::array timestampData; + timestampData.fill(std::numeric_limits::max()); + if (currentTimestampPacketNodes.get()) { + for (auto &node : currentTimestampPacketNodes->peekNodes()) { + for (const auto &cmdQueueNode : commandQueue.getTimestampPacketContainer()->peekNodes()) { + if (node == cmdQueueNode) { + for (uint32_t i = 0; i < node->getPacketsUsed(); i++) { + node->assignDataToAllTimestamps(i, timestampData.data()); + } + } + } + } + } + } + } else { + if (commandQueue.getDeferredTimestampPackets() && timestampPacketDependencies.get()) { + timestampPacketDependencies->moveNodesToNewContainer(*commandQueue.getDeferredTimestampPackets()); + } } for (cl_event &eventFromWaitList : eventsWaitlist) { diff --git a/opencl/source/helpers/task_information.h b/opencl/source/helpers/task_information.h index f9e77a9288..39aa9a6806 100644 --- a/opencl/source/helpers/task_information.h +++ b/opencl/source/helpers/task_information.h @@ -104,6 +104,7 @@ class Command : public IFNode { CompletionStamp completionStamp = {}; protected: + bool terminated = false; CommandQueue &commandQueue; std::unique_ptr kernelOperation; std::unique_ptr currentTimestampPacketNodes; diff --git a/opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp b/opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp index 3825c80843..01e8c42452 100644 --- a/opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp +++ b/opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp @@ -943,6 +943,69 @@ HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenCacheFlushRequiredWhenHandlingD device->getMemoryManager()->freeGraphicsMemory(gfxAllocation); } +HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenTerminatedLatestEnqueuedTaskWhenHandlingDependenciesForBlockedEnqueueThenDoNotPutAllNodesToDeferredListAndSetTimestampData) { + DebugManager.flags.ForceCacheFlushForBcs.set(1); + + auto gfxAllocation = createGfxAllocation(1, true); + setMockKernelArgs(std::array{{gfxAllocation}}); + + TimestampPacketContainer *deferredTimestampPackets = static_cast *>(commandQueue.get())->deferredTimestampPackets.get(); + TimestampPacketContainer *timestampPacketContainer = static_cast *>(commandQueue.get())->timestampPacketContainer.get(); + + UserEvent userEvent; + cl_event waitlist[] = {&userEvent}; + + commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist, nullptr); + + EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size()); + + userEvent.setStatus(-1); + + EXPECT_FALSE(commandQueue->isQueueBlocked()); + + EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size()); + EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 0xffffffff); + + device->getMemoryManager()->freeGraphicsMemory(gfxAllocation); +} + +HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenTerminatedTaskWhenHandlingDependenciesForBlockedEnqueueThenDoNotPutAllNodesToDeferredListAndDoNotSetTimestampData) { + DebugManager.flags.ForceCacheFlushForBcs.set(1); + + auto gfxAllocation = createGfxAllocation(1, true); + setMockKernelArgs(std::array{{gfxAllocation}}); + + TimestampPacketContainer *deferredTimestampPackets = static_cast *>(commandQueue.get())->deferredTimestampPackets.get(); + TimestampPacketContainer *timestampPacketContainer = static_cast *>(commandQueue.get())->timestampPacketContainer.get(); + + UserEvent userEvent; + [[maybe_unused]] UserEvent *ue = &userEvent; + cl_event waitlist[] = {&userEvent}; + UserEvent userEvent1; + [[maybe_unused]] UserEvent *ue1 = &userEvent1; + cl_event waitlist1[] = {&userEvent1}; + + commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist, nullptr); + commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist1, nullptr); + + EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size()); + + userEvent.setStatus(-1); + + EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size()); + EXPECT_EQ(1u, timestampPacketContainer->peekNodes().size()); + EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 1u); + + userEvent1.setStatus(-1); + + EXPECT_FALSE(commandQueue->isQueueBlocked()); + EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size()); + EXPECT_EQ(1u, timestampPacketContainer->peekNodes().size()); + EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 0xffffffff); + + device->getMemoryManager()->freeGraphicsMemory(gfxAllocation); +} + using BlitEnqueueWithNoTimestampPacketTests = BlitEnqueueTests<0>; HWTEST_TEMPLATED_F(BlitEnqueueWithNoTimestampPacketTests, givenNoTimestampPacketsWritewhenEnqueueingBlitOperationThenEnginesAreSynchronized) {