Skip to content

Commit 38ace23

Browse files
When terminate task do not pass timestamps
Signed-off-by: Lukasz Jobczyk <[email protected]>
1 parent 7364288 commit 38ace23

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed

opencl/source/helpers/task_information.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CommandMapUnmap::CommandMapUnmap(MapOperationType operationType, MemObj &memObj,
4040

4141
CompletionStamp &CommandMapUnmap::submit(uint32_t taskLevel, bool terminated) {
4242
if (terminated) {
43+
this->terminated = true;
4344
memObj.decRefInternal();
4445
return completionStamp;
4546
}
@@ -131,6 +132,7 @@ CommandComputeKernel::~CommandComputeKernel() {
131132

132133
CompletionStamp &CommandComputeKernel::submit(uint32_t taskLevel, bool terminated) {
133134
if (terminated) {
135+
this->terminated = true;
134136
for (auto surface : surfaces) {
135137
delete surface;
136138
}
@@ -348,6 +350,7 @@ void CommandWithoutKernel::dispatchBlitOperation() {
348350

349351
CompletionStamp &CommandWithoutKernel::submit(uint32_t taskLevel, bool terminated) {
350352
if (terminated) {
353+
this->terminated = true;
351354
return completionStamp;
352355
}
353356

@@ -472,8 +475,26 @@ void Command::setTimestampPacketNode(TimestampPacketContainer &current, Timestam
472475
}
473476

474477
Command::~Command() {
475-
if (commandQueue.getDeferredTimestampPackets() && timestampPacketDependencies.get()) {
476-
timestampPacketDependencies->moveNodesToNewContainer(*commandQueue.getDeferredTimestampPackets());
478+
if (terminated) {
479+
if (commandQueue.getTimestampPacketContainer()) {
480+
std::array<uint32_t, 8u> timestampData;
481+
timestampData.fill(std::numeric_limits<uint32_t>::max());
482+
if (currentTimestampPacketNodes.get()) {
483+
for (auto &node : currentTimestampPacketNodes->peekNodes()) {
484+
for (const auto &cmdQueueNode : commandQueue.getTimestampPacketContainer()->peekNodes()) {
485+
if (node == cmdQueueNode) {
486+
for (uint32_t i = 0; i < node->getPacketsUsed(); i++) {
487+
node->assignDataToAllTimestamps(i, timestampData.data());
488+
}
489+
}
490+
}
491+
}
492+
}
493+
}
494+
} else {
495+
if (commandQueue.getDeferredTimestampPackets() && timestampPacketDependencies.get()) {
496+
timestampPacketDependencies->moveNodesToNewContainer(*commandQueue.getDeferredTimestampPackets());
497+
}
477498
}
478499

479500
for (cl_event &eventFromWaitList : eventsWaitlist) {

opencl/source/helpers/task_information.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class Command : public IFNode<Command> {
104104
CompletionStamp completionStamp = {};
105105

106106
protected:
107+
bool terminated = false;
107108
CommandQueue &commandQueue;
108109
std::unique_ptr<KernelOperation> kernelOperation;
109110
std::unique_ptr<TimestampPacketContainer> currentTimestampPacketNodes;

opencl/test/unit_test/command_queue/blit_enqueue_tests.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,69 @@ HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenCacheFlushRequiredWhenHandlingD
943943
device->getMemoryManager()->freeGraphicsMemory(gfxAllocation);
944944
}
945945

946+
HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenTerminatedLatestEnqueuedTaskWhenHandlingDependenciesForBlockedEnqueueThenDoNotPutAllNodesToDeferredListAndSetTimestampData) {
947+
DebugManager.flags.ForceCacheFlushForBcs.set(1);
948+
949+
auto gfxAllocation = createGfxAllocation(1, true);
950+
setMockKernelArgs(std::array<GraphicsAllocation *, 1>{{gfxAllocation}});
951+
952+
TimestampPacketContainer *deferredTimestampPackets = static_cast<MockCommandQueueHw<FamilyType> *>(commandQueue.get())->deferredTimestampPackets.get();
953+
TimestampPacketContainer *timestampPacketContainer = static_cast<MockCommandQueueHw<FamilyType> *>(commandQueue.get())->timestampPacketContainer.get();
954+
955+
UserEvent userEvent;
956+
cl_event waitlist[] = {&userEvent};
957+
958+
commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist, nullptr);
959+
960+
EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size());
961+
962+
userEvent.setStatus(-1);
963+
964+
EXPECT_FALSE(commandQueue->isQueueBlocked());
965+
966+
EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size());
967+
EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 0xffffffff);
968+
969+
device->getMemoryManager()->freeGraphicsMemory(gfxAllocation);
970+
}
971+
972+
HWTEST_TEMPLATED_F(BlitAuxTranslationTests, givenTerminatedTaskWhenHandlingDependenciesForBlockedEnqueueThenDoNotPutAllNodesToDeferredListAndDoNotSetTimestampData) {
973+
DebugManager.flags.ForceCacheFlushForBcs.set(1);
974+
975+
auto gfxAllocation = createGfxAllocation(1, true);
976+
setMockKernelArgs(std::array<GraphicsAllocation *, 1>{{gfxAllocation}});
977+
978+
TimestampPacketContainer *deferredTimestampPackets = static_cast<MockCommandQueueHw<FamilyType> *>(commandQueue.get())->deferredTimestampPackets.get();
979+
TimestampPacketContainer *timestampPacketContainer = static_cast<MockCommandQueueHw<FamilyType> *>(commandQueue.get())->timestampPacketContainer.get();
980+
981+
UserEvent userEvent;
982+
[[maybe_unused]] UserEvent *ue = &userEvent;
983+
cl_event waitlist[] = {&userEvent};
984+
UserEvent userEvent1;
985+
[[maybe_unused]] UserEvent *ue1 = &userEvent1;
986+
cl_event waitlist1[] = {&userEvent1};
987+
988+
commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist, nullptr);
989+
commandQueue->enqueueKernel(mockKernel->mockKernel, 1, nullptr, gws, nullptr, 1, waitlist1, nullptr);
990+
991+
EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size());
992+
993+
userEvent.setStatus(-1);
994+
995+
EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size());
996+
EXPECT_EQ(1u, timestampPacketContainer->peekNodes().size());
997+
EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 1u);
998+
999+
userEvent1.setStatus(-1);
1000+
1001+
EXPECT_FALSE(commandQueue->isQueueBlocked());
1002+
EXPECT_EQ(0u, deferredTimestampPackets->peekNodes().size());
1003+
EXPECT_EQ(1u, timestampPacketContainer->peekNodes().size());
1004+
EXPECT_EQ(timestampPacketContainer->peekNodes()[0]->getContextEndValue(0u), 0xffffffff);
1005+
1006+
device->getMemoryManager()->freeGraphicsMemory(gfxAllocation);
1007+
}
1008+
9461009
using BlitEnqueueWithNoTimestampPacketTests = BlitEnqueueTests<0>;
9471010

9481011
HWTEST_TEMPLATED_F(BlitEnqueueWithNoTimestampPacketTests, givenNoTimestampPacketsWritewhenEnqueueingBlitOperationThenEnginesAreSynchronized) {

0 commit comments

Comments
 (0)